| GNU Classpath (0.95) | |
| Frames | No Frames |
1: /* JOptionPane.java 2: Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing; 40: 41: import java.awt.AWTEvent; 42: import java.awt.ActiveEvent; 43: import java.awt.Component; 44: import java.awt.Container; 45: import java.awt.EventQueue; 46: import java.awt.Frame; 47: import java.awt.MenuComponent; 48: import java.awt.Toolkit; 49: import java.awt.event.MouseAdapter; 50: import java.awt.event.MouseMotionAdapter; 51: import java.beans.PropertyChangeEvent; 52: import java.beans.PropertyChangeListener; 53: 54: import javax.accessibility.Accessible; 55: import javax.accessibility.AccessibleContext; 56: import javax.accessibility.AccessibleRole; 57: import javax.swing.plaf.OptionPaneUI; 58: 59: /** 60: * This class creates different types of JDialogs and JInternalFrames that can 61: * ask users for input or pass on information. JOptionPane can be used by 62: * calling one of the show static methods or by creating an instance of 63: * JOptionPane and calling createDialog or createInternalFrame. 64: */ 65: public class JOptionPane extends JComponent implements Accessible 66: { 67: /** 68: * Provides the accessibility features for the <code>JOptionPane</code> 69: * component. 70: */ 71: protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent 72: { 73: private static final long serialVersionUID = 686071432213084821L; 74: 75: /** 76: * Creates a new <code>AccessibleJOptionPane</code> instance. 77: */ 78: protected AccessibleJOptionPane() 79: { 80: // Nothing to do here. 81: } 82: 83: /** 84: * Returns the accessible role of this object, which is always 85: * {@link AccessibleRole#OPTION_PANE}. 86: * 87: * @return the accessible role of this object 88: */ 89: public AccessibleRole getAccessibleRole() 90: { 91: return AccessibleRole.OPTION_PANE; 92: } 93: } 94: 95: private static final long serialVersionUID = 5231143276678566796L; 96: 97: /** The value returned when cancel option is selected. */ 98: public static final int CANCEL_OPTION = 2; 99: 100: /** The value returned when the dialog is closed without a selection. */ 101: public static final int CLOSED_OPTION = -1; 102: 103: /** An option used in confirmation dialog methods. */ 104: public static final int DEFAULT_OPTION = -1; 105: 106: /** The value returned when the no option is selected. */ 107: public static final int NO_OPTION = 1; 108: 109: /** An option used in confirmation dialog methods. */ 110: public static final int OK_CANCEL_OPTION = 2; 111: 112: /** The value returned when the ok option is selected. */ 113: public static final int OK_OPTION = 0; 114: 115: /** An option used in confirmation dialog methods. */ 116: public static final int YES_NO_CANCEL_OPTION = 1; 117: 118: /** An option used in confirmation dialog methods. */ 119: public static final int YES_NO_OPTION = 0; 120: 121: /** The value returned when the yes option is selected. */ 122: public static final int YES_OPTION = 0; 123: 124: /** Identifier for the error message type. */ 125: public static final int ERROR_MESSAGE = 0; 126: 127: /** Identifier for the information message type. */ 128: public static final int INFORMATION_MESSAGE = 1; 129: 130: /** Identifier for the plain message type. */ 131: public static final int PLAIN_MESSAGE = -1; 132: 133: /** Identifier for the question message type. */ 134: public static final int QUESTION_MESSAGE = 3; 135: 136: /** Identifier for the warning message type. */ 137: public static final int WARNING_MESSAGE = 2; 138: 139: /** 140: * The identifier for the propertyChangeEvent when the icon property 141: * changes. 142: */ 143: public static final String ICON_PROPERTY = "icon"; 144: 145: /** 146: * The identifier for the propertyChangeEvent when the initialSelectionValue 147: * property changes. 148: */ 149: public static final String INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue"; 150: 151: /** 152: * The identifier for the propertyChangeEvent when the initialValue property 153: * changes. 154: */ 155: public static final String INITIAL_VALUE_PROPERTY = "initialValue"; 156: 157: /** 158: * The identifier for the propertyChangeEvent when the inputValue property 159: * changes. 160: */ 161: public static final String INPUT_VALUE_PROPERTY = "inputValue"; 162: 163: /** 164: * The identifier for the propertyChangeEvent when the message property 165: * changes. 166: */ 167: public static final String MESSAGE_PROPERTY = "message"; 168: 169: /** 170: * The identifier for the propertyChangeEvent when the messageType property 171: * changes. 172: */ 173: public static final String MESSAGE_TYPE_PROPERTY = "messageType"; 174: 175: /** 176: * The identifier for the propertyChangeEvent when the optionType property 177: * changes. 178: */ 179: public static final String OPTION_TYPE_PROPERTY = "optionType"; 180: 181: /** 182: * The identifier for the propertyChangeEvent when the options property 183: * changes. 184: */ 185: public static final String OPTIONS_PROPERTY = "options"; 186: 187: /** 188: * The identifier for the propertyChangeEvent when the selectionValues 189: * property changes. 190: */ 191: public static final String SELECTION_VALUES_PROPERTY = "selectionValues"; 192: 193: /** 194: * The identifier for the propertyChangeEvent when the value property 195: * changes. 196: */ 197: public static final String VALUE_PROPERTY = "value"; 198: 199: /** 200: * The identifier for the propertyChangeEvent when the wantsInput property 201: * changes. 202: */ 203: public static final String WANTS_INPUT_PROPERTY = "wantsInput"; 204: 205: /** The value returned when the inputValue is uninitialized. */ 206: public static final Object UNINITIALIZED_VALUE = "uninitializedValue"; 207: 208: /** The icon displayed in the dialog/internal frame. */ 209: protected Icon icon; 210: 211: /** The initial selected value in the input component. */ 212: protected Object initialSelectionValue; 213: 214: /** The object that is initially selected for options. */ 215: protected Object initialValue; 216: 217: /** The value the user inputs. */ 218: protected Object inputValue = UNINITIALIZED_VALUE; 219: 220: /** The message displayed in the dialog/internal frame. */ 221: protected Object message; 222: 223: /** The type of message displayed. */ 224: protected int messageType = PLAIN_MESSAGE; 225: 226: /** 227: * The options (usually buttons) aligned at the bottom for the user to 228: * select. 229: */ 230: protected Object[] options; 231: 232: /** The type of options to display. */ 233: protected int optionType = DEFAULT_OPTION; 234: 235: /** The input values the user can select. */ 236: protected Object[] selectionValues; 237: 238: /** The value returned by selecting an option. */ 239: protected Object value = UNINITIALIZED_VALUE; 240: 241: /** Whether the Dialog/InternalFrame needs input. */ 242: protected boolean wantsInput; 243: 244: /** The common frame used when no parent is provided. */ 245: private static Frame privFrame = (Frame) SwingUtilities.getOwnerFrame(null); 246: 247: /** 248: * Creates a new JOptionPane object using a message of "JOptionPane 249: * message", using the PLAIN_MESSAGE type and DEFAULT_OPTION. 250: */ 251: public JOptionPane() 252: { 253: this("JOptionPane message", PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null); 254: } 255: 256: /** 257: * Creates a new JOptionPane object using the given message using the 258: * PLAIN_MESSAGE type and DEFAULT_OPTION. 259: * 260: * @param message The message to display. 261: */ 262: public JOptionPane(Object message) 263: { 264: this(message, PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null); 265: } 266: 267: /** 268: * Creates a new JOptionPane object using the given message and messageType 269: * and DEFAULT_OPTION. 270: * 271: * @param message The message to display. 272: * @param messageType The type of message. 273: */ 274: public JOptionPane(Object message, int messageType) 275: { 276: this(message, messageType, DEFAULT_OPTION, null, null, null); 277: } 278: 279: /** 280: * Creates a new JOptionPane object using the given message, messageType and 281: * optionType. 282: * 283: * @param message The message to display. 284: * @param messageType The type of message. 285: * @param optionType The type of options. 286: */ 287: public JOptionPane(Object message, int messageType, int optionType) 288: { 289: this(message, messageType, optionType, null, null, null); 290: } 291: 292: /** 293: * Creates a new JOptionPane object using the given message, messageType, 294: * optionType and icon. 295: * 296: * @param message The message to display. 297: * @param messageType The type of message. 298: * @param optionType The type of options. 299: * @param icon The icon to display. 300: */ 301: public JOptionPane(Object message, int messageType, int optionType, Icon icon) 302: { 303: this(message, messageType, optionType, icon, null, null); 304: } 305: 306: /** 307: * Creates a new JOptionPane object using the given message, messageType, 308: * optionType, icon and options. 309: * 310: * @param message The message to display. 311: * @param messageType The type of message. 312: * @param optionType The type of options. 313: * @param icon The icon to display. 314: * @param options The options given. 315: */ 316: public JOptionPane(Object message, int messageType, int optionType, 317: Icon icon, Object[] options) 318: { 319: this(message, messageType, optionType, icon, options, null); 320: } 321: 322: /** 323: * Creates a new JOptionPane object using the given message, messageType, 324: * optionType, icon, options and initialValue. The initialValue will be 325: * focused initially. 326: * 327: * @param message The message to display. 328: * @param messageType The type of message. 329: * @param optionType The type of options. 330: * @param icon The icon to display. 331: * @param options The options given. 332: * @param initialValue The component to focus on initially. 333: * 334: * @throws IllegalArgumentException If the messageType or optionType are not 335: * legal values. 336: */ 337: public JOptionPane(Object message, int messageType, int optionType, 338: Icon icon, Object[] options, Object initialValue) 339: { 340: this.message = message; 341: if (! validMessageType(messageType)) 342: throw new IllegalArgumentException("Message Type not legal value."); 343: this.messageType = messageType; 344: if (! validOptionType(optionType)) 345: throw new IllegalArgumentException("Option Type not legal value."); 346: this.optionType = optionType; 347: this.icon = icon; 348: this.options = options; 349: this.initialValue = initialValue; 350: 351: setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 352: 353: updateUI(); 354: } 355: 356: /** 357: * This method creates a new JDialog that is either centered around the 358: * parent's frame or centered on the screen (if the parent is null). The 359: * JDialog will not be resizable and will be modal. Once the JDialog is 360: * disposed, the inputValue and value properties will be set by the 361: * optionPane. 362: * 363: * @param parentComponent The parent of the Dialog. 364: * @param title The title in the bar of the JDialog. 365: * 366: * @return A new JDialog based on the JOptionPane configuration. 367: */ 368: public JDialog createDialog(Component parentComponent, String title) 369: { 370: Frame toUse = getFrameForComponent(parentComponent); 371: if (toUse == null) 372: toUse = getRootFrame(); 373: 374: JDialog dialog = new JDialog(toUse, title); 375: inputValue = UNINITIALIZED_VALUE; 376: value = UNINITIALIZED_VALUE; 377: 378: dialog.getContentPane().add(this); 379: dialog.setModal(true); 380: dialog.setResizable(false); 381: dialog.pack(); 382: dialog.setLocationRelativeTo(parentComponent); 383: 384: addPropertyChangeListener(new ValuePropertyHandler(dialog)); 385: return dialog; 386: } 387: 388: /** 389: * Handles changes of the value property. Whenever this property changes, 390: * the JOptionPane dialog should be closed. 391: */ 392: private static class ValuePropertyHandler 393: implements PropertyChangeListener 394: { 395: /** 396: * The dialog to close. 397: */ 398: JDialog dialog; 399: 400: /** 401: * Creates a new instance. 402: * 403: * @param d the dialog to be closed 404: */ 405: ValuePropertyHandler(JDialog d) 406: { 407: dialog = d; 408: } 409: 410: /** 411: * Receives notification when any of the properties change. 412: */ 413: public void propertyChange(PropertyChangeEvent p) 414: { 415: String prop = p.getPropertyName(); 416: Object val = p.getNewValue(); 417: if (prop.equals(VALUE_PROPERTY) && val != null 418: && val != UNINITIALIZED_VALUE) 419: { 420: dialog.setVisible(false); 421: } 422: } 423: } 424: 425: /** 426: * This method creates a new JInternalFrame that is in the JLayeredPane 427: * which contains the parentComponent given. If no suitable JLayeredPane 428: * can be found from the parentComponent given, a RuntimeException will be 429: * thrown. 430: * 431: * @param parentComponent The parent to find a JDesktopPane from. 432: * @param title The title of the JInternalFrame. 433: * 434: * @return A new JInternalFrame based on the JOptionPane configuration. 435: * 436: * @throws RuntimeException If no suitable JDesktopPane is found. 437: * 438: * @specnote The specification says that the internal frame is placed 439: * in the nearest <code>JDesktopPane</code> that is found in 440: * <code>parent</code>'s ancestors. The behaviour of the JDK 441: * is that it actually looks up the nearest 442: * <code>JLayeredPane</code> in <code>parent</code>'s ancestors. 443: * So do we. 444: */ 445: public JInternalFrame createInternalFrame(Component parentComponent, 446: String title) 447: throws RuntimeException 448: { 449: // Try to find a JDesktopPane. 450: JLayeredPane toUse = getDesktopPaneForComponent(parentComponent); 451: // If we don't have a JDesktopPane, we try to find a JLayeredPane. 452: if (toUse == null) 453: toUse = JLayeredPane.getLayeredPaneAbove(parentComponent); 454: // If this still fails, we throw a RuntimeException. 455: if (toUse == null) 456: throw new RuntimeException 457: ("parentComponent does not have a valid parent"); 458: 459: JInternalFrame frame = new JInternalFrame(title); 460: 461: inputValue = UNINITIALIZED_VALUE; 462: value = UNINITIALIZED_VALUE; 463: 464: frame.setContentPane(this); 465: frame.setClosable(true); 466: 467: toUse.add(frame); 468: frame.setLayer(JLayeredPane.MODAL_LAYER); 469: 470: frame.pack(); 471: frame.setVisible(true); 472: 473: return frame; 474: } 475: 476: /** 477: * Returns the object that provides accessibility features for this 478: * <code>JOptionPane</code> component. 479: * 480: * @return The accessible context (an instance of 481: * {@link AccessibleJOptionPane}). 482: */ 483: public AccessibleContext getAccessibleContext() 484: { 485: if (accessibleContext == null) 486: accessibleContext = new AccessibleJOptionPane(); 487: return accessibleContext; 488: } 489: 490: /** 491: * This method returns the JDesktopPane for the given parentComponent or 492: * null if none can be found. 493: * 494: * @param parentComponent The component to look in. 495: * 496: * @return The JDesktopPane for the given component or null if none can be 497: * found. 498: */ 499: public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) 500: { 501: return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, 502: parentComponent); 503: } 504: 505: /** 506: * This method returns the Frame for the given parentComponent or null if 507: * none can be found. 508: * 509: * @param parentComponent The component to look in. 510: * 511: * @return The Frame for the given component or null if none can be found. 512: */ 513: public static Frame getFrameForComponent(Component parentComponent) 514: { 515: return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, 516: parentComponent); 517: } 518: 519: /** 520: * This method returns the icon displayed. 521: * 522: * @return The icon displayed. 523: */ 524: public Icon getIcon() 525: { 526: return icon; 527: } 528: 529: /** 530: * This method returns the value initially selected from the list of values 531: * the user can input. 532: * 533: * @return The initial selection value. 534: */ 535: public Object getInitialSelectionValue() 536: { 537: return initialSelectionValue; 538: } 539: 540: /** 541: * This method returns the value that is focused from the list of options. 542: * 543: * @return The initial value from options. 544: */ 545: public Object getInitialValue() 546: { 547: return initialValue; 548: } 549: 550: /** 551: * This method returns the value that the user input. 552: * 553: * @return The user's input value. 554: */ 555: public Object getInputValue() 556: { 557: if (getValue().equals(new Integer(CANCEL_OPTION))) 558: setInputValue(null); 559: return inputValue; 560: } 561: 562: /** 563: * This method returns the maximum characters per line. By default, this is 564: * Integer.MAX_VALUE. 565: * 566: * @return The maximum characters per line. 567: */ 568: public int getMaxCharactersPerLineCount() 569: { 570: return Integer.MAX_VALUE; 571: } 572: 573: /** 574: * This method returns the message displayed. 575: * 576: * @return The message displayed. 577: */ 578: public Object getMessage() 579: { 580: return message; 581: } 582: 583: /** 584: * This method returns the message type. 585: * 586: * @return The message type. 587: */ 588: public int getMessageType() 589: { 590: return messageType; 591: } 592: 593: /** 594: * This method returns the options. 595: * 596: * @return The options. 597: */ 598: public Object[] getOptions() 599: { 600: return options; 601: } 602: 603: /** 604: * This method returns the option type. 605: * 606: * @return The option type. 607: */ 608: public int getOptionType() 609: { 610: return optionType; 611: } 612: 613: /** 614: * This method returns the Frame used by JOptionPane dialog's that have no 615: * parent. 616: * 617: * @return The Frame used by dialogs that have no parent. 618: */ 619: public static Frame getRootFrame() 620: { 621: return privFrame; 622: } 623: 624: /** 625: * This method returns the selection values. 626: * 627: * @return The selection values. 628: */ 629: public Object[] getSelectionValues() 630: { 631: return selectionValues; 632: } 633: 634: /** 635: * This method returns the UI used by the JOptionPane. 636: * 637: * @return The UI used by the JOptionPane. 638: */ 639: public OptionPaneUI getUI() 640: { 641: return (OptionPaneUI) ui; 642: } 643: 644: /** 645: * This method returns an identifier to determine which UI class will act as 646: * the UI. 647: * 648: * @return The UI identifier. 649: */ 650: public String getUIClassID() 651: { 652: return "OptionPaneUI"; 653: } 654: 655: /** 656: * This method returns the value that the user selected out of options. 657: * 658: * @return The value that the user selected out of options. 659: */ 660: public Object getValue() 661: { 662: return value; 663: } 664: 665: /** 666: * This method returns whether this JOptionPane wants input. 667: * 668: * @return Whether this JOptionPane wants input. 669: */ 670: public boolean getWantsInput() 671: { 672: return wantsInput; 673: } 674: 675: /** 676: * This method returns a String that describes this JOptionPane. 677: * 678: * @return A String that describes this JOptionPane. 679: */ 680: protected String paramString() 681: { 682: return "JOptionPane"; 683: } 684: 685: /** 686: * This method requests focus for the initial value. 687: */ 688: public void selectInitialValue() 689: { 690: if (ui != null) 691: ((OptionPaneUI) ui).selectInitialValue(this); 692: } 693: 694: /** 695: * This method changes the icon property. 696: * 697: * @param newIcon The new icon to use. 698: */ 699: public void setIcon(Icon newIcon) 700: { 701: if (icon != newIcon) 702: { 703: Icon old = icon; 704: icon = newIcon; 705: firePropertyChange(ICON_PROPERTY, old, icon); 706: } 707: } 708: 709: /** 710: * This method changes the initial selection property. 711: * 712: * @param newValue The new initial selection. 713: */ 714: public void setInitialSelectionValue(Object newValue) 715: { 716: if (initialSelectionValue != newValue) 717: { 718: Object old = initialSelectionValue; 719: initialSelectionValue = newValue; 720: firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, old, 721: initialSelectionValue); 722: } 723: } 724: 725: /** 726: * This method changes the initial value property. 727: * 728: * @param newValue The new initial value. 729: */ 730: public void setInitialValue(Object newValue) 731: { 732: if (initialValue != newValue) 733: { 734: Object old = initialValue; 735: initialValue = newValue; 736: firePropertyChange(INITIAL_VALUE_PROPERTY, old, initialValue); 737: } 738: } 739: 740: /** 741: * This method changes the inputValue property. 742: * 743: * @param newValue The new inputValue. 744: */ 745: public void setInputValue(Object newValue) 746: { 747: if (inputValue != newValue) 748: { 749: Object old = inputValue; 750: inputValue = newValue; 751: firePropertyChange(INPUT_VALUE_PROPERTY, old, inputValue); 752: } 753: } 754: 755: /** 756: * This method changes the message property. 757: * 758: * @param newMessage The new message. 759: */ 760: public void setMessage(Object newMessage) 761: { 762: if (message != newMessage) 763: { 764: Object old = message; 765: message = newMessage; 766: firePropertyChange(MESSAGE_PROPERTY, old, message); 767: } 768: } 769: 770: /** 771: * This method changes the messageType property. 772: * 773: * @param newType The new messageType. 774: * 775: * @throws IllegalArgumentException If the messageType is not valid. 776: */ 777: public void setMessageType(int newType) 778: { 779: if (! validMessageType(newType)) 780: throw new IllegalArgumentException("Message Type not legal value."); 781: if (newType != messageType) 782: { 783: int old = messageType; 784: messageType = newType; 785: firePropertyChange(MESSAGE_TYPE_PROPERTY, old, messageType); 786: } 787: } 788: 789: /** 790: * This method changes the options property. 791: * 792: * @param newOptions The new options. 793: */ 794: public void setOptions(Object[] newOptions) 795: { 796: if (options != newOptions) 797: { 798: Object[] old = options; 799: options = newOptions; 800: firePropertyChange(OPTIONS_PROPERTY, old, options); 801: } 802: } 803: 804: /** 805: * This method changes the optionType property. 806: * 807: * @param newType The new optionType. 808: * 809: * @throws IllegalArgumentException If the optionType is not valid. 810: */ 811: public void setOptionType(int newType) 812: { 813: if (! validOptionType(newType)) 814: throw new IllegalArgumentException("Option Type not legal value."); 815: if (newType != optionType) 816: { 817: int old = optionType; 818: optionType = newType; 819: firePropertyChange(OPTION_TYPE_PROPERTY, old, optionType); 820: } 821: } 822: 823: /** 824: * This method changes the Frame used for JOptionPane dialogs that have no 825: * parent. 826: * 827: * @param newRootFrame The Frame to use for dialogs that have no parent. 828: */ 829: public static void setRootFrame(Frame newRootFrame) 830: { 831: privFrame = newRootFrame; 832: } 833: 834: /** 835: * This method changes the selectionValues property. 836: * 837: * @param newValues The new selectionValues. 838: */ 839: public void setSelectionValues(Object[] newValues) 840: { 841: if (newValues != selectionValues) 842: { 843: if (newValues != null) 844: wantsInput = true; 845: Object[] old = selectionValues; 846: selectionValues = newValues; 847: firePropertyChange(SELECTION_VALUES_PROPERTY, old, selectionValues); 848: } 849: } 850: 851: /** 852: * This method sets the UI used with the JOptionPane. 853: * 854: * @param ui The UI used with the JOptionPane. 855: */ 856: public void setUI(OptionPaneUI ui) 857: { 858: super.setUI(ui); 859: } 860: 861: /** 862: * This method sets the value has been selected out of options. 863: * 864: * @param newValue The value that has been selected out of options. 865: */ 866: public void setValue(Object newValue) 867: { 868: if (value != newValue) 869: { 870: Object old = value; 871: value = newValue; 872: firePropertyChange(VALUE_PROPERTY, old, value); 873: } 874: } 875: 876: /** 877: * This method changes the wantsInput property. 878: * 879: * @param newValue Whether this JOptionPane requires input. 880: */ 881: public void setWantsInput(boolean newValue) 882: { 883: if (wantsInput != newValue) 884: { 885: boolean old = wantsInput; 886: wantsInput = newValue; 887: firePropertyChange(WANTS_INPUT_PROPERTY, old, wantsInput); 888: } 889: } 890: 891: /** 892: * This method shows a confirmation dialog with the title "Select an Option" 893: * and displays the given message. The parent frame will be the same as the 894: * parent frame of the given parentComponent. This method returns the 895: * option chosen by the user. 896: * 897: * @param parentComponent The parentComponent to find a frame in. 898: * @param message The message to display. 899: * 900: * @return The option that was selected. 901: */ 902: public static int showConfirmDialog(Component parentComponent, Object message) 903: { 904: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 905: JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); 906: dialog.show(); 907: 908: if (pane.getValue() instanceof Integer) 909: return ((Integer) pane.getValue()).intValue(); 910: return -1; 911: } 912: 913: /** 914: * This method shows a confirmation dialog with the given message, 915: * optionType and title. The frame that owns the dialog will be the same 916: * frame that holds the given parentComponent. This method returns the 917: * option that was chosen. 918: * 919: * @param parentComponent The component to find a frame in. 920: * @param message The message displayed. 921: * @param title The title of the dialog. 922: * @param optionType The optionType. 923: * 924: * @return The option that was chosen. 925: */ 926: public static int showConfirmDialog(Component parentComponent, 927: