Source Code Cross Referenced for JOptionPane.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Alexander T. Simbirtsev
020:         * @version $Revision$
021:         */package javax.swing;
022:
023:        import java.awt.Component;
024:        import java.awt.Container;
025:        import java.awt.Frame;
026:        import java.awt.HeadlessException;
027:        import java.awt.Window;
028:        import java.beans.PropertyChangeEvent;
029:        import java.beans.PropertyChangeListener;
030:
031:        import javax.accessibility.Accessible;
032:        import javax.accessibility.AccessibleContext;
033:        import javax.accessibility.AccessibleRole;
034:        import javax.swing.event.InternalFrameAdapter;
035:        import javax.swing.event.InternalFrameEvent;
036:        import javax.swing.plaf.OptionPaneUI;
037:
038:        import org.apache.harmony.x.swing.Utilities;
039:
040:        import org.apache.harmony.x.swing.internal.nls.Messages;
041:
042:        public class JOptionPane extends JComponent implements  Accessible {
043:
044:            protected class AccessibleJOptionPane extends AccessibleJComponent {
045:                public AccessibleRole getAccessibleRole() {
046:                    return AccessibleRole.OPTION_PANE;
047:                }
048:            };
049:
050:            private static class CloseOwnerListener implements 
051:                    PropertyChangeListener {
052:                private final Object owner;
053:
054:                public CloseOwnerListener(final Object owner) {
055:                    this .owner = owner;
056:                }
057:
058:                public void propertyChange(final PropertyChangeEvent event) {
059:                    if (owner instanceof  Window) {
060:                        ((Window) owner).dispose();
061:                    } else if (owner instanceof  JInternalFrame) {
062:                        ((JInternalFrame) owner).dispose();
063:                    }
064:                }
065:            };
066:
067:            private class ClosingInternalFrameListener extends
068:                    InternalFrameAdapter {
069:                private class Lock {
070:                }
071:
072:                public final Object lock = new Lock();
073:
074:                public void internalFrameClosed(final InternalFrameEvent e) {
075:                    synchronized (lock) {
076:                        lock.notifyAll();
077:                    }
078:                }
079:            };
080:
081:            public static final String INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
082:            public static final String INITIAL_VALUE_PROPERTY = "initialValue";
083:            public static final String INPUT_VALUE_PROPERTY = "inputValue";
084:            public static final String MESSAGE_PROPERTY = "message";
085:            public static final String MESSAGE_TYPE_PROPERTY = "messageType";
086:            public static final String ICON_PROPERTY = "icon";
087:            public static final String OPTION_TYPE_PROPERTY = "optionType";
088:            public static final String OPTIONS_PROPERTY = "options";
089:            public static final String SELECTION_VALUES_PROPERTY = "selectionValues";
090:            public static final String VALUE_PROPERTY = "value";
091:            public static final String WANTS_INPUT_PROPERTY = "wantsInput";
092:
093:            private static final String UI_CLASS_ID = "OptionPaneUI";
094:            private static final String INITIAL_MESSAGE = "JOptionPane message";
095:            private static final String CLOSE_OWNER_PROPERTY_NAME = "closeOwner";
096:
097:            public static final int DEFAULT_OPTION = -1;
098:            public static final int YES_NO_OPTION = 0;
099:            public static final int YES_NO_CANCEL_OPTION = 1;
100:            public static final int OK_CANCEL_OPTION = 2;
101:
102:            public static final int CLOSED_OPTION = -1;
103:            public static final int OK_OPTION = 0;
104:            public static final int YES_OPTION = 0;
105:            public static final int NO_OPTION = 1;
106:            public static final int CANCEL_OPTION = 2;
107:
108:            public static final int PLAIN_MESSAGE = -1;
109:            public static final int ERROR_MESSAGE = 0;
110:            public static final int INFORMATION_MESSAGE = 1;
111:            public static final int WARNING_MESSAGE = 2;
112:            public static final int QUESTION_MESSAGE = 3;
113:
114:            public static final Object UNINITIALIZED_VALUE = "uninitializedValue";
115:
116:            protected Icon icon;
117:            protected Object initialSelectionValue;
118:            protected Object initialValue;
119:            protected Object inputValue = UNINITIALIZED_VALUE;
120:
121:            protected Object message = INITIAL_MESSAGE;
122:            protected int messageType = PLAIN_MESSAGE;
123:
124:            protected Object[] options;
125:            protected int optionType = DEFAULT_OPTION;
126:
127:            protected Object[] selectionValues;
128:            protected Object value = UNINITIALIZED_VALUE;
129:
130:            protected boolean wantsInput;
131:
132:            private static Frame rootFrame;
133:
134:            public JOptionPane() {
135:                updateUI();
136:            }
137:
138:            public JOptionPane(final Object message) {
139:                setMessage(message);
140:                updateUI();
141:            }
142:
143:            public JOptionPane(final Object message, final int messageType) {
144:                setMessage(message);
145:                setMessageType(messageType);
146:                updateUI();
147:            }
148:
149:            public JOptionPane(final Object message, final int messageType,
150:                    final int optionType) {
151:                setMessage(message);
152:                setMessageType(messageType);
153:                setOptionType(optionType);
154:                updateUI();
155:            }
156:
157:            public JOptionPane(final Object message, final int messageType,
158:                    final int optionType, final Icon icon) {
159:                setMessage(message);
160:                setMessageType(messageType);
161:                setOptionType(optionType);
162:                setIcon(icon);
163:                updateUI();
164:            }
165:
166:            public JOptionPane(final Object message, final int messageType,
167:                    final int optionType, final Icon icon,
168:                    final Object[] options) {
169:                setMessage(message);
170:                setMessageType(messageType);
171:                setOptionType(optionType);
172:                setIcon(icon);
173:                setOptions(options);
174:                updateUI();
175:            }
176:
177:            public JOptionPane(final Object message, final int messageType,
178:                    final int optionType, final Icon icon,
179:                    final Object[] options, final Object initialValue) {
180:                setMessage(message);
181:                setMessageType(messageType);
182:                setOptionType(optionType);
183:                setIcon(icon);
184:                setOptions(options);
185:                setInitialValue(initialValue);
186:                updateUI();
187:            }
188:
189:            public static String showInputDialog(final Object message)
190:                    throws HeadlessException {
191:                return (String) showInputDialog(null, message, null,
192:                        QUESTION_MESSAGE, null, null, null);
193:            }
194:
195:            public static String showInputDialog(final Object message,
196:                    final Object initialSelectionValue) {
197:                return (String) showInputDialog(null, message, null,
198:                        QUESTION_MESSAGE, null, null, initialSelectionValue);
199:            }
200:
201:            public static String showInputDialog(
202:                    final Component parentComponent, final Object message)
203:                    throws HeadlessException {
204:                return (String) showInputDialog(parentComponent, message, null,
205:                        QUESTION_MESSAGE, null, null, null);
206:            }
207:
208:            public static String showInputDialog(
209:                    final Component parentComponent, final Object message,
210:                    final Object initialSelectionValue) {
211:                return (String) showInputDialog(parentComponent, message, null,
212:                        QUESTION_MESSAGE, null, null, initialSelectionValue);
213:            }
214:
215:            public static String showInputDialog(
216:                    final Component parentComponent, final Object message,
217:                    final String title, final int messageType)
218:                    throws HeadlessException {
219:                return (String) showInputDialog(parentComponent, message,
220:                        title, messageType, null, null, null);
221:            }
222:
223:            public static Object showInputDialog(
224:                    final Component parentComponent, final Object message,
225:                    final String title, final int messageType, final Icon icon,
226:                    final Object[] selectionValues,
227:                    final Object initialSelectionValue)
228:                    throws HeadlessException {
229:                JOptionPane pane = new JOptionPane(message, messageType,
230:                        OK_CANCEL_OPTION, icon);
231:                pane.setSelectionValues(selectionValues);
232:                pane.setInitialSelectionValue(initialSelectionValue);
233:                pane.setWantsInput(true);
234:
235:                JDialog dialog = pane.createDialog(parentComponent, title);
236:                setDialogDecorations(dialog, messageType);
237:                dialog.setVisible(true);
238:
239:                return pane.getInputValue();
240:            }
241:
242:            public static void showMessageDialog(
243:                    final Component parentComponent, final Object message)
244:                    throws HeadlessException {
245:                showMessageDialog(parentComponent, message, null,
246:                        INFORMATION_MESSAGE, null);
247:            }
248:
249:            public static void showMessageDialog(
250:                    final Component parentComponent, final Object message,
251:                    final String title, final int messageType)
252:                    throws HeadlessException {
253:                showMessageDialog(parentComponent, message, title, messageType,
254:                        null);
255:            }
256:
257:            public static void showMessageDialog(
258:                    final Component parentComponent, final Object message,
259:                    final String title, final int messageType, final Icon icon)
260:                    throws HeadlessException {
261:                JOptionPane pane = new JOptionPane(message, messageType,
262:                        DEFAULT_OPTION, icon);
263:                JDialog dialog = pane.createDialog(parentComponent, title);
264:                setDialogDecorations(dialog, messageType);
265:                dialog.setVisible(true);
266:            }
267:
268:            public static int showConfirmDialog(
269:                    final Component parentComponent, final Object message)
270:                    throws HeadlessException {
271:                return showConfirmDialog(parentComponent, message, null,
272:                        YES_NO_CANCEL_OPTION, QUESTION_MESSAGE, null);
273:            }
274:
275:            public static int showConfirmDialog(
276:                    final Component parentComponent, final Object message,
277:                    final String title, final int optionType)
278:                    throws HeadlessException {
279:                return showConfirmDialog(parentComponent, message, title,
280:                        optionType, QUESTION_MESSAGE, null);
281:            }
282:
283:            public static int showConfirmDialog(
284:                    final Component parentComponent, final Object message,
285:                    final String title, final int optionType,
286:                    final int messageType) throws HeadlessException {
287:                return showConfirmDialog(parentComponent, message, title,
288:                        optionType, messageType, null);
289:            }
290:
291:            public static int showConfirmDialog(
292:                    final Component parentComponent, final Object message,
293:                    final String title, final int optionType,
294:                    final int messageType, final Icon icon)
295:                    throws HeadlessException {
296:                JOptionPane pane = new JOptionPane(message, messageType,
297:                        optionType, icon);
298:                JDialog dialog = pane.createDialog(parentComponent, title);
299:                setDialogDecorations(dialog, messageType);
300:                dialog.setVisible(true);
301:
302:                return getResultedIndex(pane);
303:            }
304:
305:            private ClosingInternalFrameListener createClosingInternalFrameListener() {
306:                return new ClosingInternalFrameListener();
307:            }
308:
309:            private static void showInternalFrameAndWaitTillClosed(
310:                    final JInternalFrame iFrame, final JOptionPane pane,
311:                    final Component parentComponent) {
312:                SwingUtilities.getWindowAncestor(parentComponent).setVisible(
313:                        true);
314:                ClosingInternalFrameListener listener = pane
315:                        .createClosingInternalFrameListener();
316:                iFrame.addInternalFrameListener(listener);
317:                iFrame.setVisible(true);
318:
319:                synchronized (listener.lock) {
320:                    try {
321:                        listener.lock.wait();
322:                    } catch (InterruptedException e) {
323:                    }
324:                }
325:            }
326:
327:            public static int showOptionDialog(final Component parentComponent,
328:                    final Object message, final String title,
329:                    final int optionType, final int messageType,
330:                    final Icon icon, final Object[] options,
331:                    final Object initialValue) throws HeadlessException {
332:                JOptionPane pane = new JOptionPane(message, messageType,
333:                        optionType, icon, options, initialValue);
334:                JDialog dialog = pane.createDialog(parentComponent, title);
335:                setDialogDecorations(dialog, messageType);
336:                dialog.setVisible(true);
337:
338:                return getResultedIndex(pane);
339:            }
340:
341:            public static void showInternalMessageDialog(
342:                    final Component parentComponent, final Object message) {
343:                showInternalMessageDialog(parentComponent, message, "Message",
344:                        INFORMATION_MESSAGE, null);
345:            }
346:
347:            public static void showInternalMessageDialog(
348:                    final Component parentComponent, final Object message,
349:                    final String title, final int messageType) {
350:                showInternalMessageDialog(parentComponent, message, title,
351:                        messageType, null);
352:            }
353:
354:            public static void showInternalMessageDialog(
355:                    final Component parentComponent, final Object message,
356:                    final String title, final int messageType, final Icon icon) {
357:                JOptionPane pane = new JOptionPane(message, messageType,
358:                        DEFAULT_OPTION, icon);
359:                JDialog dialog = pane.createDialog(parentComponent, title);
360:                setDialogDecorations(dialog, messageType);
361:                JInternalFrame internalFrame = pane.createInternalFrame(
362:                        parentComponent, title);
363:                showInternalFrameAndWaitTillClosed(internalFrame, pane,
364:                        parentComponent);
365:            }
366:
367:            public static int showInternalConfirmDialog(
368:                    final Component parentComponent, final Object message) {
369:                return showInternalConfirmDialog(parentComponent, message,
370:                        "Select an Option", YES_NO_CANCEL_OPTION,
371:                        INFORMATION_MESSAGE, null);
372:            }
373:
374:            public static int showInternalConfirmDialog(
375:                    final Component parentComponent, final Object message,
376:                    final String title, final int optionType) {
377:                return showInternalConfirmDialog(parentComponent, message,
378:                        title, optionType, INFORMATION_MESSAGE, null);
379:            }
380:
381:            public static int showInternalConfirmDialog(
382:                    final Component parentComponent, final Object message,
383:                    final String title, final int optionType,
384:                    final int messageType) {
385:                return showInternalConfirmDialog(parentComponent, message,
386:                        title, optionType, messageType, null);
387:            }
388:
389:            public static int showInternalConfirmDialog(
390:                    final Component parentComponent, final Object message,
391:                    final String title, final int optionType,
392:                    final int messageType, final Icon icon) {
393:                JOptionPane pane = new JOptionPane(message, messageType,
394:                        optionType, icon);
395:                JDialog dialog = pane.createDialog(parentComponent, title);
396:                setDialogDecorations(dialog, messageType);
397:                JInternalFrame internalFrame = pane.createInternalFrame(
398:                        parentComponent, title);
399:                showInternalFrameAndWaitTillClosed(internalFrame, pane,
400:                        parentComponent);
401:
402:                return getResultedIndex(pane);
403:            }
404:
405:            public static int showInternalOptionDialog(
406:                    final Component parentComponent, final Object message,
407:                    final String title, final int optionType,
408:                    final int messageType, final Icon icon,
409:                    final Object[] options, final Object initialValue) {
410:                JOptionPane pane = new JOptionPane(message, messageType,
411:                        optionType, icon, options, initialValue);
412:                JDialog dialog = pane.createDialog(parentComponent, title);
413:                setDialogDecorations(dialog, messageType);
414:                JInternalFrame internalFrame = pane.createInternalFrame(
415:                        parentComponent, title);
416:                showInternalFrameAndWaitTillClosed(internalFrame, pane,
417:                        parentComponent);
418:
419:                return getResultedIndex(pane);
420:            }
421:
422:            public static String showInternalInputDialog(
423:                    final Component parentComponent, final Object message) {
424:                return (String) showInternalInputDialog(parentComponent,
425:                        message, null, INFORMATION_MESSAGE, null, null, null);
426:            }
427:
428:            public static String showInternalInputDialog(
429:                    final Component parentComponent, final Object message,
430:                    final String title, final int messageType) {
431:                return (String) showInternalInputDialog(parentComponent,
432:                        message, title, messageType, null, null, null);
433:            }
434:
435:            public static Object showInternalInputDialog(
436:                    final Component parentComponent, final Object message,
437:                    final String title, final int messageType, final Icon icon,
438:                    final Object[] selectionValues,
439:                    final Object initialSelectionValue) {
440:                JOptionPane pane = new JOptionPane(message, messageType,
441:                        OK_CANCEL_OPTION, icon);
442:                pane.setSelectionValues(selectionValues);
443:                if (selectionValues != null) {
444:                    pane.setInitialSelectionValue(initialSelectionValue);
445:                } else {
446:                    pane.setWantsInput(true);
447:                    pane.setInitialSelectionValue(initialSelectionValue);
448:                }
449:                JDialog dialog = pane.createDialog(parentComponent, title);
450:                setDialogDecorations(dialog, messageType);
451:                JInternalFrame internalFrame = pane.createInternalFrame(
452:                        parentComponent, title);
453:                showInternalFrameAndWaitTillClosed(internalFrame, pane,
454:                        parentComponent);
455:
456:                return pane.getInputValue();
457:            }
458:
459:            public JDialog createDialog(final Component parentComponent,
460:                    final String title) throws HeadlessException {
461:
462:                Frame parentFrame = getFrameForComponent(parentComponent);
463:                JDialog dialog = new JDialog(parentFrame,
464:                        (title != null) ? title
465:                                : (String) getClientProperty("defaultTitle"),
466:                        true);
467:                dialog.add(this );
468:                dialog.pack();
469:                dialog.setResizable(false);
470:                dialog.setLocationRelativeTo(parentFrame);
471:                addPropertyChangeListener(CLOSE_OWNER_PROPERTY_NAME,
472:                        new CloseOwnerListener(dialog));
473:
474:                return dialog;
475:            }
476:
477:            public JInternalFrame createInternalFrame(
478:                    final Component parentComponent, final String title) {
479:                JDesktopPane desktop = JOptionPane
480:                        .getDesktopPaneForComponent(parentComponent);
481:                Container parent = (desktop != null) ? desktop
482:                        : parentComponent.getParent();
483:                if (parent == null) {
484:                    throw new RuntimeException(Messages.getString(
485:                            "swing.1E", "JOptionPane")); //$NON-NLS-1$ //$NON-NLS-2$
486:                }
487:
488:                JInternalFrame frame = new JInternalFrame(title);
489:                frame.putClientProperty("JInternalFrame.optionDialog",
490:                        Boolean.TRUE);
491:                parent.add(frame);
492:                frame.add(this );
493:                frame.pack();
494:                addPropertyChangeListener(CLOSE_OWNER_PROPERTY_NAME,
495:                        new CloseOwnerListener(frame));
496:
497:                return frame;
498:            }
499:
500:            public static Frame getFrameForComponent(
501:                    final Component parentComponent) throws HeadlessException {
502:                Frame result = null;
503:                if (parentComponent instanceof  Frame) {
504:                    return (Frame) parentComponent;
505:                }
506:                result = (Frame) SwingUtilities.getAncestorOfClass(Frame.class,
507:                        parentComponent);
508:                return (result != null) ? result : getRootFrame();
509:            }
510:
511:            public static JDesktopPane getDesktopPaneForComponent(
512:                    final Component parentComponent) {
513:                return (JDesktopPane) SwingUtilities.getAncestorOfClass(
514:                        JDesktopPane.class, parentComponent);
515:            }
516:
517:            public static void setRootFrame(final Frame rootFrame) {
518:                JOptionPane.rootFrame = rootFrame;
519:            }
520:
521:            public static Frame getRootFrame() throws HeadlessException {
522:                return (rootFrame != null) ? rootFrame : JFrame
523:                        .getSharedOwner();
524:            }
525:
526:            public void setUI(final OptionPaneUI ui) {
527:                super .setUI(ui);
528:            }
529:
530:            public OptionPaneUI getUI() {
531:                return (OptionPaneUI) ui;
532:            }
533:
534:            public void updateUI() {
535:                setUI((OptionPaneUI) UIManager.getUI(this ));
536:            }
537:
538:            public String getUIClassID() {
539:                return UI_CLASS_ID;
540:            }
541:
542:            public void setMessage(final Object newMessage) {
543:                Object oldValue = message;
544:                message = newMessage;
545:                firePropertyChange(MESSAGE_PROPERTY, oldValue, newMessage);
546:            }
547:
548:            public Object getMessage() {
549:                return message;
550:            }
551:
552:            public void setIcon(final Icon newIcon) {
553:                Icon oldValue = icon;
554:                icon = newIcon;
555:                firePropertyChange(ICON_PROPERTY, oldValue, newIcon);
556:            }
557:
558:            public Icon getIcon() {
559:                return icon;
560:            }
561:
562:            public void setValue(final Object newValue) {
563:                Object oldValue = value;
564:                value = newValue;
565:                firePropertyChange(VALUE_PROPERTY, oldValue, newValue);
566:            }
567:
568:            public Object getValue() {
569:                return value;
570:            }
571:
572:            public void setOptions(final Object[] newOptions) {
573:                Object[] oldValue = options;
574:                options = newOptions;
575:                firePropertyChange(OPTIONS_PROPERTY, oldValue, newOptions);
576:            }
577:
578:            public Object[] getOptions() {
579:                return ((options != null) ? ((Object[]) options.clone()) : null);
580:            }
581:
582:            public void setInitialValue(final Object newValue) {
583:                Object oldValue = initialValue;
584:                initialValue = newValue;
585:                firePropertyChange(INITIAL_VALUE_PROPERTY, oldValue, newValue);
586:            }
587:
588:            public Object getInitialValue() {
589:                return initialValue;
590:            }
591:
592:            public void setMessageType(final int type) {
593:                switch (type) {
594:                case ERROR_MESSAGE:
595:                case INFORMATION_MESSAGE:
596:                case WARNING_MESSAGE:
597:                case QUESTION_MESSAGE:
598:                case PLAIN_MESSAGE:
599:                    int oldValue = messageType;
600:                    messageType = type;
601:                    firePropertyChange(MESSAGE_TYPE_PROPERTY, oldValue, type);
602:                    break;
603:                default:
604:                    throw new RuntimeException(Messages.getString(
605:                            "swing.1F", "JOptionPane") + //$NON-NLS-1$ //$NON-NLS-2$
606:                            "JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, "
607:                            + //$NON-NLS-1$
608:                            "JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE "
609:                            + //$NON-NLS-1$
610:                            "or JOptionPane.PLAIN_MESSAGE"); //$NON-NLS-1$
611:                }
612:            }
613:
614:            public int getMessageType() {
615:                return messageType;
616:            }
617:
618:            public void setOptionType(final int newType) {
619:                switch (newType) {
620:                case DEFAULT_OPTION:
621:                case YES_NO_OPTION:
622:                case YES_NO_CANCEL_OPTION:
623:                case OK_CANCEL_OPTION:
624:                    int oldValue = optionType;
625:                    optionType = newType;
626:                    firePropertyChange(OPTION_TYPE_PROPERTY, oldValue, newType);
627:                    break;
628:                default:
629:                    throw new RuntimeException(Messages.getString("swing.20")); //$NON-NLS-1$
630:                }
631:            }
632:
633:            public int getOptionType() {
634:                return optionType;
635:            }
636:
637:            public void setSelectionValues(final Object[] newValues) {
638:                Object oldSelectionValues = selectionValues;
639:                selectionValues = newValues;
640:                firePropertyChange(SELECTION_VALUES_PROPERTY,
641:                        oldSelectionValues, newValues);
642:                setWantsInput(selectionValues != null);
643:            }
644:
645:            public Object[] getSelectionValues() {
646:                return selectionValues;
647:            }
648:
649:            public void setInitialSelectionValue(final Object newValue) {
650:                Object oldInitialSelectionValue = initialSelectionValue;
651:                initialSelectionValue = newValue;
652:                firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY,
653:                        oldInitialSelectionValue, newValue);
654:            }
655:
656:            public Object getInitialSelectionValue() {
657:                return initialSelectionValue;
658:            }
659:
660:            public void setInputValue(final Object newValue) {
661:                Object oldValue = inputValue;
662:                inputValue = newValue;
663:                firePropertyChange(INPUT_VALUE_PROPERTY, oldValue, newValue);
664:            }
665:
666:            public Object getInputValue() {
667:                return inputValue;
668:            }
669:
670:            public int getMaxCharactersPerLineCount() {
671:                return Integer.MAX_VALUE;
672:            }
673:
674:            public void setWantsInput(final boolean newValue) {
675:                boolean oldValue = wantsInput;
676:                wantsInput = newValue;
677:                firePropertyChange(WANTS_INPUT_PROPERTY, oldValue, newValue);
678:            }
679:
680:            public boolean getWantsInput() {
681:                return wantsInput;
682:            }
683:
684:            public void selectInitialValue() {
685:                getUI().selectInitialValue(this );
686:            }
687:
688:            public AccessibleContext getAccessibleContext() {
689:                return (accessibleContext == null) ? (accessibleContext = new AccessibleJOptionPane())
690:                        : accessibleContext;
691:            }
692:
693:            private static int getResultedIndex(final JOptionPane pane) {
694:                Object value = pane.getValue();
695:                if (value instanceof  Integer) {
696:                    return ((Integer) value).intValue();
697:                }
698:
699:                Object[] options = pane.getOptions();
700:                if (Utilities.isEmptyArray(options)) {
701:                    return -1;
702:                }
703:
704:                for (int i = 0; i < options.length; i++) {
705:                    if (options[i] == value) {
706:                        return i;
707:                    }
708:                }
709:
710:                return -1;
711:            }
712:
713:            private static int messageTypeToRootPaneDecoration(
714:                    final int messageType) {
715:                switch (messageType) {
716:                case ERROR_MESSAGE:
717:                    return JRootPane.ERROR_DIALOG;
718:                case INFORMATION_MESSAGE:
719:                    return JRootPane.INFORMATION_DIALOG;
720:                case QUESTION_MESSAGE:
721:                    return JRootPane.QUESTION_DIALOG;
722:                case WARNING_MESSAGE:
723:                    return JRootPane.WARNING_DIALOG;
724:                default:
725:                    return JRootPane.PLAIN_DIALOG;
726:                }
727:            }
728:
729:            private static void setDialogDecorations(final JDialog dialog,
730:                    final int messageType) {
731:                if (!JDialog.isDefaultLookAndFeelDecorated()) {
732:                    return;
733:                }
734:                dialog.getRootPane().setWindowDecorationStyle(
735:                        messageTypeToRootPaneDecoration(messageType));
736:            }
737:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.