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: 52: import javax.accessibility.Accessible; 53: import javax.accessibility.AccessibleContext; 54: import javax.accessibility.AccessibleRole; 55: import javax.swing.plaf.OptionPaneUI; 56: 57: /** 58: * This class creates different types of JDialogs and JInternalFrames that can 59: * ask users for input or pass on information. JOptionPane can be used by 60: * calling one of the show static methods or by creating an instance of 61: * JOptionPane and calling createDialog or createInternalFrame. 62: */ 63: public class JOptionPane extends JComponent implements Accessible 64: { 65: /** 66: * Provides the accessibility features for the <code>JOptionPane</code> 67: * component. 68: */ 69: protected class AccessibleJOptionPane extends JComponent.AccessibleJComponent 70: { 71: private static final long serialVersionUID = 686071432213084821L; 72: 73: /** 74: * Creates a new <code>AccessibleJOptionPane</code> instance. 75: */ 76: protected AccessibleJOptionPane() 77: { 78: // Nothing to do here. 79: } 80: 81: /** 82: * Returns the accessible role of this object, which is always 83: * {@link AccessibleRole#OPTION_PANE}. 84: * 85: * @return the accessible role of this object 86: */ 87: public AccessibleRole getAccessibleRole() 88: { 89: return AccessibleRole.OPTION_PANE; 90: } 91: } 92: 93: private static final long serialVersionUID = 5231143276678566796L; 94: 95: /** The value returned when cancel option is selected. */ 96: public static final int CANCEL_OPTION = 2; 97: 98: /** The value returned when the dialog is closed without a selection. */ 99: public static final int CLOSED_OPTION = -1; 100: 101: /** An option used in confirmation dialog methods. */ 102: public static final int DEFAULT_OPTION = -1; 103: 104: /** The value returned when the no option is selected. */ 105: public static final int NO_OPTION = 1; 106: 107: /** An option used in confirmation dialog methods. */ 108: public static final int OK_CANCEL_OPTION = 2; 109: 110: /** The value returned when the ok option is selected. */ 111: public static final int OK_OPTION = 0; 112: 113: /** An option used in confirmation dialog methods. */ 114: public static final int YES_NO_CANCEL_OPTION = 1; 115: 116: /** An option used in confirmation dialog methods. */ 117: public static final int YES_NO_OPTION = 0; 118: 119: /** The value returned when the yes option is selected. */ 120: public static final int YES_OPTION = 0; 121: 122: /** Identifier for the error message type. */ 123: public static final int ERROR_MESSAGE = 0; 124: 125: /** Identifier for the information message type. */ 126: public static final int INFORMATION_MESSAGE = 1; 127: 128: /** Identifier for the plain message type. */ 129: public static final int PLAIN_MESSAGE = -1; 130: 131: /** Identifier for the question message type. */ 132: public static final int QUESTION_MESSAGE = 3; 133: 134: /** Identifier for the warning message type. */ 135: public static final int WARNING_MESSAGE = 2; 136: 137: /** 138: * The identifier for the propertyChangeEvent when the icon property 139: * changes. 140: */ 141: public static final String ICON_PROPERTY = "icon"; 142: 143: /** 144: * The identifier for the propertyChangeEvent when the initialSelectionValue 145: * property changes. 146: */ 147: public static final String INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue"; 148: 149: /** 150: * The identifier for the propertyChangeEvent when the initialValue property 151: * changes. 152: */ 153: public static final String INITIAL_VALUE_PROPERTY = "initialValue"; 154: 155: /** 156: * The identifier for the propertyChangeEvent when the inputValue property 157: * changes. 158: */ 159: public static final String INPUT_VALUE_PROPERTY = "inputValue"; 160: 161: /** 162: * The identifier for the propertyChangeEvent when the message property 163: * changes. 164: */ 165: public static final String MESSAGE_PROPERTY = "message"; 166: 167: /** 168: * The identifier for the propertyChangeEvent when the messageType property 169: * changes. 170: */ 171: public static final String MESSAGE_TYPE_PROPERTY = "messageType"; 172: 173: /** 174: * The identifier for the propertyChangeEvent when the optionType property 175: * changes. 176: */ 177: public static final String OPTION_TYPE_PROPERTY = "optionType"; 178: 179: /** 180: * The identifier for the propertyChangeEvent when the options property 181: * changes. 182: */ 183: public static final String OPTIONS_PROPERTY = "options"; 184: 185: /** 186: * The identifier for the propertyChangeEvent when the selectionValues 187: * property changes. 188: */ 189: public static final String SELECTION_VALUES_PROPERTY = "selectionValues"; 190: 191: /** 192: * The identifier for the propertyChangeEvent when the value property 193: * changes. 194: */ 195: public static final String VALUE_PROPERTY = "value"; 196: 197: /** 198: * The identifier for the propertyChangeEvent when the wantsInput property 199: * changes. 200: */ 201: public static final String WANTS_INPUT_PROPERTY = "wantsInput"; 202: 203: /** The value returned when the inputValue is uninitialized. */ 204: public static final Object UNINITIALIZED_VALUE = "uninitializedValue"; 205: 206: /** The icon displayed in the dialog/internal frame. */ 207: protected Icon icon; 208: 209: /** The initial selected value in the input component. */ 210: protected Object initialSelectionValue; 211: 212: /** The object that is initially selected for options. */ 213: protected Object initialValue; 214: 215: /** The value the user inputs. */ 216: protected Object inputValue = UNINITIALIZED_VALUE; 217: 218: /** The message displayed in the dialog/internal frame. */ 219: protected Object message; 220: 221: /** The type of message displayed. */ 222: protected int messageType = PLAIN_MESSAGE; 223: 224: /** 225: * The options (usually buttons) aligned at the bottom for the user to 226: * select. 227: */ 228: protected Object[] options; 229: 230: /** The type of options to display. */ 231: protected int optionType = DEFAULT_OPTION; 232: 233: /** The input values the user can select. */ 234: protected Object[] selectionValues; 235: 236: /** The value returned by selecting an option. */ 237: protected Object value = UNINITIALIZED_VALUE; 238: 239: /** Whether the Dialog/InternalFrame needs input. */ 240: protected boolean wantsInput; 241: 242: /** The common frame used when no parent is provided. */ 243: private static Frame privFrame = (Frame) SwingUtilities.getOwnerFrame(null); 244: 245: /** 246: * Creates a new JOptionPane object using a message of "JOptionPane 247: * message", using the PLAIN_MESSAGE type and DEFAULT_OPTION. 248: */ 249: public JOptionPane() 250: { 251: this("JOptionPane message", PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null); 252: } 253: 254: /** 255: * Creates a new JOptionPane object using the given message using the 256: * PLAIN_MESSAGE type and DEFAULT_OPTION. 257: * 258: * @param message The message to display. 259: */ 260: public JOptionPane(Object message) 261: { 262: this(message, PLAIN_MESSAGE, DEFAULT_OPTION, null, null, null); 263: } 264: 265: /** 266: * Creates a new JOptionPane object using the given message and messageType 267: * and DEFAULT_OPTION. 268: * 269: * @param message The message to display. 270: * @param messageType The type of message. 271: */ 272: public JOptionPane(Object message, int messageType) 273: { 274: this(message, messageType, DEFAULT_OPTION, null, null, null); 275: } 276: 277: /** 278: * Creates a new JOptionPane object using the given message, messageType and 279: * optionType. 280: * 281: * @param message The message to display. 282: * @param messageType The type of message. 283: * @param optionType The type of options. 284: */ 285: public JOptionPane(Object message, int messageType, int optionType) 286: { 287: this(message, messageType, optionType, null, null, null); 288: } 289: 290: /** 291: * Creates a new JOptionPane object using the given message, messageType, 292: * optionType and icon. 293: * 294: * @param message The message to display. 295: * @param messageType The type of message. 296: * @param optionType The type of options. 297: * @param icon The icon to display. 298: */ 299: public JOptionPane(Object message, int messageType, int optionType, Icon icon) 300: { 301: this(message, messageType, optionType, icon, null, null); 302: } 303: 304: /** 305: * Creates a new JOptionPane object using the given message, messageType, 306: * optionType, icon and options. 307: * 308: * @param message The message to display. 309: * @param messageType The type of message. 310: * @param optionType The type of options. 311: * @param icon The icon to display. 312: * @param options The options given. 313: */ 314: public JOptionPane(Object message, int messageType, int optionType, 315: Icon icon, Object[] options) 316: { 317: this(message, messageType, optionType, icon, options, null); 318: } 319: 320: /** 321: * Creates a new JOptionPane object using the given message, messageType, 322: * optionType, icon, options and initialValue. The initialValue will be 323: * focused initially. 324: * 325: * @param message The message to display. 326: * @param messageType The type of message. 327: * @param optionType The type of options. 328: * @param icon The icon to display. 329: * @param options The options given. 330: * @param initialValue The component to focus on initially. 331: * 332: * @throws IllegalArgumentException If the messageType or optionType are not 333: * legal values. 334: */ 335: public JOptionPane(Object message, int messageType, int optionType, 336: Icon icon, Object[] options, Object initialValue) 337: { 338: this.message = message; 339: if (! validMessageType(messageType)) 340: throw new IllegalArgumentException("Message Type not legal value."); 341: this.messageType = messageType; 342: if (! validOptionType(optionType)) 343: throw new IllegalArgumentException("Option Type not legal value."); 344: this.optionType = optionType; 345: this.icon = icon; 346: this.options = options; 347: this.initialValue = initialValue; 348: 349: setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 350: 351: updateUI(); 352: } 353: 354: /** 355: * This method creates a new JDialog that is either centered around the 356: * parent's frame or centered on the screen (if the parent is null). The 357: * JDialog will not be resizable and will be modal. Once the JDialog is 358: * disposed, the inputValue and value properties will be set by the 359: * optionPane. 360: * 361: * @param parentComponent The parent of the Dialog. 362: * @param title The title in the bar of the JDialog. 363: * 364: * @return A new JDialog based on the JOptionPane configuration. 365: */ 366: public JDialog createDialog(Component parentComponent, String title) 367: { 368: Frame toUse = getFrameForComponent(parentComponent); 369: if (toUse == null) 370: toUse = getRootFrame(); 371: 372: JDialog dialog = new JDialog(toUse, title); 373: inputValue = UNINITIALIZED_VALUE; 374: value = UNINITIALIZED_VALUE; 375: 376: dialog.getContentPane().add(this); 377: dialog.setModal(true); 378: dialog.setResizable(false); 379: dialog.pack(); 380: dialog.setLocationRelativeTo(parentComponent); 381: 382: return dialog; 383: } 384: 385: /** 386: * This method creates a new JInternalFrame that is in the JLayeredPane 387: * which contains the parentComponent given. If no suitable JLayeredPane 388: * can be found from the parentComponent given, a RuntimeException will be 389: * thrown. 390: * 391: * @param parentComponent The parent to find a JDesktopPane from. 392: * @param title The title of the JInternalFrame. 393: * 394: * @return A new JInternalFrame based on the JOptionPane configuration. 395: * 396: * @throws RuntimeException If no suitable JDesktopPane is found. 397: * 398: * @specnote The specification says that the internal frame is placed 399: * in the nearest <code>JDesktopPane</code> that is found in 400: * <code>parent</code>'s ancestors. The behaviour of the JDK 401: * is that it actually looks up the nearest 402: * <code>JLayeredPane</code> in <code>parent</code>'s ancestors. 403: * So do we. 404: */ 405: public JInternalFrame createInternalFrame(Component parentComponent, 406: String title) 407: throws RuntimeException 408: { 409: // Try to find a JDesktopPane. 410: JLayeredPane toUse = getDesktopPaneForComponent(parentComponent); 411: // If we don't have a JDesktopPane, we try to find a JLayeredPane. 412: if (toUse == null) 413: toUse = JLayeredPane.getLayeredPaneAbove(parentComponent); 414: // If this still fails, we throw a RuntimeException. 415: if (toUse == null) 416: throw new RuntimeException 417: ("parentComponent does not have a valid parent"); 418: 419: JInternalFrame frame = new JInternalFrame(title); 420: 421: inputValue = UNINITIALIZED_VALUE; 422: value = UNINITIALIZED_VALUE; 423: 424: frame.setContentPane(this); 425: frame.setClosable(true); 426: 427: toUse.add(frame); 428: frame.setLayer(JLayeredPane.MODAL_LAYER); 429: 430: frame.pack(); 431: frame.setVisible(true); 432: 433: return frame; 434: } 435: 436: /** 437: * Returns the object that provides accessibility features for this 438: * <code>JOptionPane</code> component. 439: * 440: * @return The accessible context (an instance of 441: * {@link AccessibleJOptionPane}). 442: */ 443: public AccessibleContext getAccessibleContext() 444: { 445: if (accessibleContext == null) 446: accessibleContext = new AccessibleJOptionPane(); 447: return accessibleContext; 448: } 449: 450: /** 451: * This method returns the JDesktopPane for the given parentComponent or 452: * null if none can be found. 453: * 454: * @param parentComponent The component to look in. 455: * 456: * @return The JDesktopPane for the given component or null if none can be 457: * found. 458: */ 459: public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) 460: { 461: return (JDesktopPane) SwingUtilities.getAncestorOfClass(JDesktopPane.class, 462: parentComponent); 463: } 464: 465: /** 466: * This method returns the Frame for the given parentComponent or null if 467: * none can be found. 468: * 469: * @param parentComponent The component to look in. 470: * 471: * @return The Frame for the given component or null if none can be found. 472: */ 473: public static Frame getFrameForComponent(Component parentComponent) 474: { 475: return (Frame) SwingUtilities.getAncestorOfClass(Frame.class, 476: parentComponent); 477: } 478: 479: /** 480: * This method returns the icon displayed. 481: * 482: * @return The icon displayed. 483: */ 484: public Icon getIcon() 485: { 486: return icon; 487: } 488: 489: /** 490: * This method returns the value initially selected from the list of values 491: * the user can input. 492: * 493: * @return The initial selection value. 494: */ 495: public Object getInitialSelectionValue() 496: { 497: return initialSelectionValue; 498: } 499: 500: /** 501: * This method returns the value that is focused from the list of options. 502: * 503: * @return The initial value from options. 504: */ 505: public Object getInitialValue() 506: { 507: return initialValue; 508: } 509: 510: /** 511: * This method returns the value that the user input. 512: * 513: * @return The user's input value. 514: */ 515: public Object getInputValue() 516: { 517: if (getValue().equals(new Integer(CANCEL_OPTION))) 518: setInputValue(null); 519: return inputValue; 520: } 521: 522: /** 523: * This method returns the maximum characters per line. By default, this is 524: * Integer.MAX_VALUE. 525: * 526: * @return The maximum characters per line. 527: */ 528: public int getMaxCharactersPerLineCount() 529: { 530: return Integer.MAX_VALUE; 531: } 532: 533: /** 534: * This method returns the message displayed. 535: * 536: * @return The message displayed. 537: */ 538: public Object getMessage() 539: { 540: return message; 541: } 542: 543: /** 544: * This method returns the message type. 545: * 546: * @return The message type. 547: */ 548: public int getMessageType() 549: { 550: return messageType; 551: } 552: 553: /** 554: * This method returns the options. 555: * 556: * @return The options. 557: */ 558: public Object[] getOptions() 559: { 560: return options; 561: } 562: 563: /** 564: * This method returns the option type. 565: * 566: * @return The option type. 567: */ 568: public int getOptionType() 569: { 570: return optionType; 571: } 572: 573: /** 574: * This method returns the Frame used by JOptionPane dialog's that have no 575: * parent. 576: * 577: * @return The Frame used by dialogs that have no parent. 578: */ 579: public static Frame getRootFrame() 580: { 581: return privFrame; 582: } 583: 584: /** 585: * This method returns the selection values. 586: * 587: * @return The selection values. 588: */ 589: public Object[] getSelectionValues() 590: { 591: return selectionValues; 592: } 593: 594: /** 595: * This method returns the UI used by the JOptionPane. 596: * 597: * @return The UI used by the JOptionPane. 598: */ 599: public OptionPaneUI getUI() 600: { 601: return (OptionPaneUI) ui; 602: } 603: 604: /** 605: * This method returns an identifier to determine which UI class will act as 606: * the UI. 607: * 608: * @return The UI identifier. 609: */ 610: public String getUIClassID() 611: { 612: return "OptionPaneUI"; 613: } 614: 615: /** 616: * This method returns the value that the user selected out of options. 617: * 618: * @return The value that the user selected out of options. 619: */ 620: public Object getValue() 621: { 622: return value; 623: } 624: 625: /** 626: * This method returns whether this JOptionPane wants input. 627: * 628: * @return Whether this JOptionPane wants input. 629: */ 630: public boolean getWantsInput() 631: { 632: return wantsInput; 633: } 634: 635: /** 636: * This method returns a String that describes this JOptionPane. 637: * 638: * @return A String that describes this JOptionPane. 639: */ 640: protected String paramString() 641: { 642: return "JOptionPane"; 643: } 644: 645: /** 646: * This method requests focus for the initial value. 647: */ 648: public void selectInitialValue() 649: { 650: if (ui != null) 651: ((OptionPaneUI) ui).selectInitialValue(this); 652: } 653: 654: /** 655: * This method changes the icon property. 656: * 657: * @param newIcon The new icon to use. 658: */ 659: public void setIcon(Icon newIcon) 660: { 661: if (icon != newIcon) 662: { 663: Icon old = icon; 664: icon = newIcon; 665: firePropertyChange(ICON_PROPERTY, old, icon); 666: } 667: } 668: 669: /** 670: * This method changes the initial selection property. 671: * 672: * @param newValue The new initial selection. 673: */ 674: public void setInitialSelectionValue(Object newValue) 675: { 676: if (initialSelectionValue != newValue) 677: { 678: Object old = initialSelectionValue; 679: initialSelectionValue = newValue; 680: firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, old, 681: initialSelectionValue); 682: } 683: } 684: 685: /** 686: * This method changes the initial value property. 687: * 688: * @param newValue The new initial value. 689: */ 690: public void setInitialValue(Object newValue) 691: { 692: if (initialValue != newValue) 693: { 694: Object old = initialValue; 695: initialValue = newValue; 696: firePropertyChange(INITIAL_VALUE_PROPERTY, old, initialValue); 697: } 698: } 699: 700: /** 701: * This method changes the inputValue property. 702: * 703: * @param newValue The new inputValue. 704: */ 705: public void setInputValue(Object newValue) 706: { 707: if (inputValue != newValue) 708: { 709: Object old = inputValue; 710: inputValue = newValue; 711: firePropertyChange(INPUT_VALUE_PROPERTY, old, inputValue); 712: } 713: } 714: 715: /** 716: * This method changes the message property. 717: * 718: * @param newMessage The new message. 719: */ 720: public void setMessage(Object newMessage) 721: { 722: if (message != newMessage) 723: { 724: Object old = message; 725: message = newMessage; 726: firePropertyChange(MESSAGE_PROPERTY, old, message); 727: } 728: } 729: 730: /** 731: * This method changes the messageType property. 732: * 733: * @param newType The new messageType. 734: * 735: * @throws IllegalArgumentException If the messageType is not valid. 736: */ 737: public void setMessageType(int newType) 738: { 739: if (! validMessageType(newType)) 740: throw new IllegalArgumentException("Message Type not legal value."); 741: if (newType != messageType) 742: { 743: int old = messageType; 744: messageType = newType; 745: firePropertyChange(MESSAGE_TYPE_PROPERTY, old, messageType); 746: } 747: } 748: 749: /** 750: * This method changes the options property. 751: * 752: * @param newOptions The new options. 753: */ 754: public void setOptions(Object[] newOptions) 755: { 756: if (options != newOptions) 757: { 758: Object[] old = options; 759: options = newOptions; 760: firePropertyChange(OPTIONS_PROPERTY, old, options); 761: } 762: } 763: 764: /** 765: * This method changes the optionType property. 766: * 767: * @param newType The new optionType. 768: * 769: * @throws IllegalArgumentException If the optionType is not valid. 770: */ 771: public void setOptionType(int newType) 772: { 773: if (! validOptionType(newType)) 774: throw new IllegalArgumentException("Option Type not legal value."); 775: if (newType != optionType) 776: { 777: int old = optionType; 778: optionType = newType; 779: firePropertyChange(OPTION_TYPE_PROPERTY, old, optionType); 780: } 781: } 782: 783: /** 784: * This method changes the Frame used for JOptionPane dialogs that have no 785: * parent. 786: * 787: * @param newRootFrame The Frame to use for dialogs that have no parent. 788: */ 789: public static void setRootFrame(Frame newRootFrame) 790: { 791: privFrame = newRootFrame; 792: } 793: 794: /** 795: * This method changes the selectionValues property. 796: * 797: * @param newValues The new selectionValues. 798: */ 799: public void setSelectionValues(Object[] newValues) 800: { 801: if (newValues != selectionValues) 802: { 803: if (newValues != null) 804: wantsInput = true; 805: Object[] old = selectionValues; 806: selectionValues = newValues; 807: firePropertyChange(SELECTION_VALUES_PROPERTY, old, selectionValues); 808: } 809: } 810: 811: /** 812: * This method sets the UI used with the JOptionPane. 813: * 814: * @param ui The UI used with the JOptionPane. 815: */ 816: public void setUI(OptionPaneUI ui) 817: { 818: super.setUI(ui); 819: } 820: 821: /** 822: * This method sets the value has been selected out of options. 823: * 824: * @param newValue The value that has been selected out of options. 825: */ 826: public void setValue(Object newValue) 827: { 828: if (value != newValue) 829: { 830: Object old = value; 831: value = newValue; 832: firePropertyChange(VALUE_PROPERTY, old, value); 833: } 834: } 835: 836: /** 837: * This method changes the wantsInput property. 838: * 839: * @param newValue Whether this JOptionPane requires input. 840: */ 841: public void setWantsInput(boolean newValue) 842: { 843: if (wantsInput != newValue) 844: { 845: boolean old = wantsInput; 846: wantsInput = newValue; 847: firePropertyChange(WANTS_INPUT_PROPERTY, old, wantsInput); 848: } 849: } 850: 851: /** 852: * This method shows a confirmation dialog with the title "Select an Option" 853: * and displays the given message. The parent frame will be the same as the 854: * parent frame of the given parentComponent. This method returns the 855: * option chosen by the user. 856: * 857: * @param parentComponent The parentComponent to find a frame in. 858: * @param message The message to display. 859: * 860: * @return The option that was selected. 861: */ 862: public static int showConfirmDialog(Component parentComponent, Object message) 863: { 864: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 865: JDialog dialog = pane.createDialog(parentComponent, "Select an Option"); 866: dialog.show(); 867: 868: if (pane.getValue() instanceof Integer) 869: return ((Integer) pane.getValue()).intValue(); 870: return -1; 871: } 872: 873: /** 874: * This method shows a confirmation dialog with the given message, 875: * optionType and title. The frame that owns the dialog will be the same 876: * frame that holds the given parentComponent. This method returns the 877: * option that was chosen. 878: * 879: * @param parentComponent The component to find a frame in. 880: * @param message The message displayed. 881: * @param title The title of the dialog. 882: * @param optionType The optionType. 883: * 884: * @return The option that was chosen. 885: */ 886: public static int showConfirmDialog(Component parentComponent, 887: Object message, String title, 888: int optionType) 889: { 890: JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); 891: JDialog dialog = pane.createDialog(parentComponent, title); 892: dialog.show(); 893: 894: if (pane.getValue() instanceof Integer) 895: return ((Integer) pane.getValue()).intValue(); 896: return -1; 897: } 898: 899: /** 900: * This method shows a confirmation dialog with the given message, title, 901: * messageType and optionType. The frame owner will be the same frame as 902: * the one that holds the given parentComponent. This method returns the 903: * option selected by the user. 904: * 905: * @param parentComponent The component to find a frame in. 906: * @param message The message displayed. 907: * @param title The title of the dialog. 908: * @param optionType The optionType. 909: * @param messageType The messageType. 910: * 911: * @return The selected option. 912: */ 913: public static int showConfirmDialog(Component parentComponent, 914: Object message, String title, 915: int optionType, int messageType) 916: { 917: JOptionPane pane = new JOptionPane(message, messageType, optionType); 918: JDialog dialog = pane.createDialog(parentComponent, title); 919: dialog.show(); 920: 921: if (pane.getValue() instanceof Integer) 922: return ((Integer) pane.getValue()).intValue(); 923: return -1; 924: } 925: 926: /** 927: * This method shows a confirmation dialog with the given message, title, 928: * optionType, messageType and icon. The frame owner will be the same as 929: * the one that holds the given parentComponent. This method returns the 930: * option selected by the user. 931: * 932: * @param parentComponent The component to find a frame in. 933: * @param message The message displayed. 934: * @param title The title of the dialog. 935: * @param optionType The optionType. 936: * @param messageType The messsageType. 937: * @param icon The icon displayed. 938: * 939: * @return The selected option. 940: */ 941: public static int showConfirmDialog(Component parentComponent, 942: Object message, String title, 943: int optionType, int messageType, 944: Icon icon) 945: { 946: JOptionPane pane = new JOptionPane(message, messageType, optionType, icon); 947: JDialog dialog = pane.createDialog(parentComponent, title); 948: dialog.show(); 949: 950: if (pane.getValue() instanceof Integer) 951: return ((Integer) pane.getValue()).intValue(); 952: return -1; 953: } 954: 955: /** 956: * This method will show a QUESTION_MESSAGE input dialog with the given 957: * message. No selectionValues is set so the Look and Feel will usually 958: * give the user a TextField to fill out. The frame owner will be the same 959: * frame that holds the given parentComponent. This method will return the 960: * value entered by the user. 961: * 962: * @param parentComponent The component to find a frame in. 963: * @param message The message displayed. 964: * 965: * @return The value entered by the user. 966: */ 967: public static String showInputDialog(Component parentComponent, 968: Object message) 969: { 970: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 971: pane.setWantsInput(true); 972: JDialog dialog = pane.createDialog(parentComponent, null); 973: dialog.show(); 974: 975: return (String) pane.getInputValue(); 976: } 977: 978: /** 979: * This method will show a QUESTION_MESSAGE type input dialog with the given 980: * message and initialSelectionValue. Since there is no selectionValues 981: * set, the Look and Feel will usually give a TextField to fill out. The 982: * frame owner will be the same as the one that holds the given 983: * parentComponent. This method will return the value entered by the user. 984: * 985: * @param parentComponent The component to find a frame in. 986: * @param message The message to display. 987: * @param initialSelectionValue The initially selected value. 988: * 989: * @return The value the user input. 990: */ 991: public static String showInputDialog(Component parentComponent, 992: Object message, 993: Object initialSelectionValue) 994: { 995: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 996: pane.setInitialSelectionValue(initialSelectionValue); 997: pane.setWantsInput(true); 998: JDialog dialog = pane.createDialog(parentComponent, null); 999: dialog.show(); 1000: 1001: return (String) pane.getInputValue(); 1002: } 1003: 1004: /** 1005: * This method displays a new input dialog with the given message, title and 1006: * messageType. Since no selectionValues value is given, the Look and Feel 1007: * will usually give the user a TextField to input data to. This method 1008: * returns the value the user inputs. 1009: * 1010: * @param parentComponent The component to find a frame in. 1011: * @param message The message to display. 1012: * @param title The title of the dialog. 1013: * @param messageType The messageType. 1014: * 1015: * @return The value the user input. 1016: */ 1017: public static String showInputDialog(Component parentComponent, 1018: Object message, String title, 1019: int messageType) 1020: { 1021: JOptionPane pane = new JOptionPane(message, messageType); 1022: pane.setWantsInput(true); 1023: JDialog dialog = pane.createDialog(parentComponent, title); 1024: dialog.show(); 1025: 1026: return (String) pane.getInputValue(); 1027: } 1028: 1029: /** 1030: * This method shows an input dialog with the given message, title, 1031: * messageType, icon, selectionValues, and initialSelectionValue. This 1032: * method returns the value that the user selects. 1033: * 1034: * @param parentComponent The component to find a frame in. 1035: * @param message The message displayed. 1036: * @param title The title of the dialog. 1037: * @param messageType The messageType. 1038: * @param icon The icon displayed. 1039: * @param selectionValues The list of values to select from. 1040: * @param initialSelectionValue The initially selected value. 1041: * 1042: * @return The user selected value. 1043: */ 1044: public static Object showInputDialog(Component parentComponent, 1045: Object message, String title, 1046: int messageType, Icon icon, 1047: Object[] selectionValues, 1048: Object initialSelectionValue) 1049: { 1050: JOptionPane pane = new JOptionPane(message, messageType); 1051: pane.setWantsInput(true); 1052: pane.setIcon(icon); 1053: pane.setSelectionValues(selectionValues); 1054: pane.setInitialSelectionValue(initialSelectionValue); 1055: JDialog dialog = pane.createDialog(parentComponent, title); 1056: dialog.show(); 1057: 1058: return pane.getInputValue(); 1059: } 1060: 1061: /** 1062: * This method shows a QUESTION_MESSAGE type input dialog. Since no 1063: * selectionValues is set, the Look and Feel will usually give the user a 1064: * TextField to input data to. This method returns the value the user 1065: * inputs. 1066: * 1067: * @param message The message to display. 1068: * 1069: * @return The user selected value. 1070: */ 1071: public static String showInputDialog(Object message) 1072: { 1073: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 1074: pane.setWantsInput(true); 1075: JDialog dialog = pane.createDialog(null, null); 1076: dialog.show(); 1077: 1078: return (String) pane.getInputValue(); 1079: } 1080: 1081: /** 1082: * This method shows a QUESTION_MESSAGE type input dialog. Since no 1083: * selectionValues is set, the Look and Feel will usually give the user a 1084: * TextField to input data to. The input component will be initialized with 1085: * the initialSelectionValue. This method returns the value the user 1086: * inputs. 1087: * 1088: * @param message The message to display. 1089: * @param initialSelectionValue The initialSelectionValue. 1090: * 1091: * @return The user selected value. 1092: */ 1093: public static String showInputDialog(Object message, 1094: Object initialSelectionValue) 1095: { 1096: JOptionPane pane = new JOptionPane(message, QUESTION_MESSAGE); 1097: pane.setWantsInput(true); 1098: pane.setInitialSelectionValue(initialSelectionValue); 1099: JDialog dialog = pane.createDialog(null, null); 1100: dialog.show(); 1101: 1102: return (String) pane.getInputValue(); 1103: } 1104: 1105: /** 1106: * This method shows an internal confirmation dialog with the given message. 1107: * The internal frame dialog will be placed in the first JDesktopPane 1108: * ancestor of the given parentComponent. This method will return the value 1109: * selected. 1110: * 1111: * @param parentComponent The parent to find a JDesktopPane in. 1112: * @param message The message to display. 1113: * 1114: * @return The value selected. 1115: */ 1116: public static int showInternalConfirmDialog(Component parentComponent, 1117: Object message) 1118: { 1119: JOptionPane pane = new JOptionPane(message); 1120: JInternalFrame frame = pane.createInternalFrame(parentComponent, null); 1121: 1122: startModal(frame); 1123: 1124: if (pane.getValue() instanceof Integer) 1125: return ((Integer) pane.getValue()).intValue(); 1126: return -1; 1127: } 1128: 1129: /** 1130: * This method shows an internal confirmation dialog with the given message, 1131: * optionType and title. The internal frame dialog will be placed in the 1132: * first JDesktopPane ancestor of the given parentComponent. This method 1133: * will return the selected value. 1134: * 1135: * @param parentComponent The parent to find a JDesktopPane in. 1136: * @param message The message to display. 1137: * @param title The title to display. 1138: * @param optionType The option type. 1139: * 1140: * @return The selected value. 1141: */ 1142: public static int showInternalConfirmDialog(Component parentComponent, 1143: Object message, String title, 1144: int optionType) 1145: { 1146: JOptionPane pane = new JOptionPane(message, PLAIN_MESSAGE, optionType); 1147: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1148: 1149: startModal(frame); 1150: 1151: if (pane.getValue() instanceof Integer) 1152: return ((Integer) pane.getValue()).intValue(); 1153: return -1; 1154: } 1155: 1156: /** 1157: * This method shows an internal confirmation dialog with the given message, 1158: * title, optionTypes and icon for the given message type. The internal 1159: * confirmation dialog will be placed in the first instance of 1160: * JDesktopPane ancestor of the given parentComponent. 1161: * 1162: * @param parentComponent The component to find a JDesktopPane in. 1163: * @param message The message to display. 1164: * @param title The title of the dialog. 1165: * @param optionType The option type. 1166: * @param messageType The message type. 1167: * 1168: * @return The selected value. 1169: */ 1170: public static int showInternalConfirmDialog(Component parentComponent, 1171: Object message, String title, 1172: int optionType, int messageType) 1173: { 1174: JOptionPane pane = new JOptionPane(message, messageType, optionType); 1175: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1176: 1177: startModal(frame); 1178: 1179: if (pane.getValue() instanceof Integer) 1180: return ((Integer) pane.getValue()).intValue(); 1181: return -1; 1182: } 1183: 1184: /** 1185: * This method shows an internal confirmation dialog with the given message, 1186: * title, option type, message type, and icon. The internal frame dialog 1187: * will be placed in the first JDesktopPane ancestor that is found in the 1188: * given parentComponent. This method returns the selected value. 1189: * 1190: * @param parentComponent The parent to find a JDesktopPane in. 1191: * @param message The message to display. 1192: * @param title The title to display. 1193: * @param optionType The option type. 1194: * @param messageType The message type. 1195: * @param icon The icon to display. 1196: * 1197: * @return The selected value. 1198: */ 1199: public static int showInternalConfirmDialog(Component parentComponent, 1200: Object message, String title, 1201: int optionType, int messageType, 1202: Icon icon) 1203: { 1204: JOptionPane pane = new JOptionPane(message, messageType, optionType, icon); 1205: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1206: 1207: startModal(frame); 1208: 1209: if (pane.getValue() instanceof Integer) 1210: return ((Integer) pane.getValue()).intValue(); 1211: return -1; 1212: } 1213: 1214: /** 1215: * This method shows an internal input dialog with the given message. The 1216: * internal frame dialog will be placed in the first JDesktopPane ancestor 1217: * of the given parent component. This method returns the value input by 1218: * the user. 1219: * 1220: * @param parentComponent The parent to find a JDesktopPane in. 1221: * @param message The message to display. 1222: * 1223: * @return The user selected value. 1224: */ 1225: public static String showInternalInputDialog(Component parentComponent, 1226: Object message) 1227: { 1228: JOptionPane pane = new JOptionPane(message); 1229: pane.setWantsInput(true); 1230: JInternalFrame frame = pane.createInternalFrame(parentComponent, null); 1231: 1232: startModal(frame); 1233: 1234: return (String) pane.getInputValue(); 1235: } 1236: 1237: /** 1238: * This method shows an internal input dialog with the given message, title 1239: * and message type. The internal input dialog will be placed in the first 1240: * JDesktopPane ancestor found in the given parent component. This method 1241: * will return the input value given by the user. 1242: * 1243: * @param parentComponent The component to find a JDesktopPane in. 1244: * @param message The message to display. 1245: * @param title The title to display. 1246: * @param messageType The message type. 1247: * 1248: * @return The user input value. 1249: */ 1250: public static String showInternalInputDialog(Component parentComponent, 1251: Object message, String title, 1252: int messageType) 1253: { 1254: JOptionPane pane = new JOptionPane(message, messageType); 1255: pane.setWantsInput(true); 1256: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1257: 1258: startModal(frame); 1259: 1260: return (String) pane.getInputValue(); 1261: } 1262: 1263: /** 1264: * This method shows an internal input dialog with the given message, title 1265: * message type, icon, selection value list and initial selection value. 1266: * The internal frame dialog will be placed in the first JDesktopPane 1267: * ancestor found in the given parent component. This method returns the 1268: * input value from the user. 1269: * 1270: * @param parentComponent The parent to find a JDesktopPane in. 1271: * @param message The message to display. 1272: * @param title The title to display. 1273: * @param messageType The message type. 1274: * @param icon The icon to display. 1275: * @param selectionValues The selection value list. 1276: * @param initialSelectionValue The initial selection value. 1277: * 1278: * @return The user input value. 1279: */ 1280: public static Object showInternalInputDialog(Component parentComponent, 1281: Object message, String title, 1282: int messageType, Icon icon, 1283: Object[] selectionValues, 1284: Object initialSelectionValue) 1285: { 1286: JOptionPane pane = new JOptionPane(message, messageType); 1287: pane.setWantsInput(true); 1288: pane.setIcon(icon); 1289: pane.setSelectionValues(selectionValues); 1290: pane.setInitialSelectionValue(initialSelectionValue); 1291: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1292: 1293: startModal(frame); 1294: 1295: return pane.getInputValue(); 1296: } 1297: 1298: /** 1299: * This method shows an internal message dialog with the given message. The 1300: * internal frame dialog will be placed in the first JDesktopPane ancestor 1301: * found in the given parent component. 1302: * 1303: * @param parentComponent The component to find a JDesktopPane in. 1304: * @param message The message to display. 1305: */ 1306: public static void showInternalMessageDialog(Component parentComponent, 1307: Object message) 1308: { 1309: JOptionPane pane = new JOptionPane(message); 1310: JInternalFrame frame = pane.createInternalFrame(parentComponent, null); 1311: 1312: startModal(frame); 1313: } 1314: 1315: /** 1316: * This method shows an internal message dialog with the given message, 1317: * title and message type. The internal message dialog is placed in the 1318: * first JDesktopPane ancestor found in the given parent component. 1319: * 1320: * @param parentComponent The parent component to find a JDesktopPane in. 1321: * @param message The message to display. 1322: * @param title The title to display. 1323: * @param messageType The message type. 1324: */ 1325: public static void showInternalMessageDialog(Component parentComponent, 1326: Object message, String title, 1327: int messageType) 1328: { 1329: JOptionPane pane = new JOptionPane(message, messageType); 1330: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1331: 1332: startModal(frame); 1333: } 1334: 1335: /** 1336: * This method shows an internal message dialog with the given message, 1337: * title, message type and icon. The internal message dialog is placed in 1338: * the first JDesktopPane ancestor found in the given parent component. 1339: * 1340: * @param parentComponent The component to find a JDesktopPane in. 1341: * @param message The message to display. 1342: * @param title The title to display. 1343: * @param messageType The message type. 1344: * @param icon The icon to display. 1345: */ 1346: public static void showInternalMessageDialog(Component parentComponent, 1347: Object message, String title, 1348: int messageType, Icon icon) 1349: { 1350: JOptionPane pane = new JOptionPane(message, messageType); 1351: pane.setIcon(icon); 1352: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1353: 1354: startModal(frame); 1355: } 1356: 1357: /** 1358: * This method displays an internal option dialog with the given message, 1359: * title, option type, message type, icon, option list, and initial option 1360: * value. The internal option dialog is placed in the first JDesktopPane 1361: * ancestor found in the parent component. This method returns the option 1362: * selected. 1363: * 1364: * @param parentComponent The parent to find a JDesktopPane in. 1365: * @param message The message displayed. 1366: * @param title The title displayed. 1367: * @param optionType The option type. 1368: * @param messageType The message type. 1369: * @param icon The icon to display. 1370: * @param options The array of options. 1371: * @param initialValue The initial value selected. 1372: * 1373: * @return The option that was selected. 1374: */ 1375: public static int showInternalOptionDialog(Component parentComponent, 1376: Object message, String title, 1377: int optionType, int messageType, 1378: Icon icon, Object[] options, 1379: Object initialValue) 1380: { 1381: JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, 1382: options, initialValue); 1383: 1384: JInternalFrame frame = pane.createInternalFrame(parentComponent, title); 1385: 1386: startModal(frame); 1387: 1388: if (pane.getValue() instanceof Integer) 1389: return ((Integer) pane.getValue()).intValue(); 1390: return -1; 1391: } 1392: 1393: /** 1394: * This method shows an INFORMATION_MESSAGE type message dialog. 1395: * 1396: * @param parentComponent The component to find a frame in. 1397: * @param message The message displayed. 1398: */ 1399: public static void showMessageDialog(Component parentComponent, 1400: Object message) 1401: { 1402: JOptionPane pane = new JOptionPane(message, INFORMATION_MESSAGE); 1403: JDialog dialog = pane.createDialog(parentComponent, null); 1404: dialog.show(); 1405: } 1406: 1407: /** 1408: * This method shows a message dialog with the given message, title and 1409: * messageType. 1410: * 1411: * @param parentComponent The component to find a frame in. 1412: * @param message The message displayed. 1413: * @param title The title of the dialog. 1414: * @param messageType The messageType. 1415: */ 1416: public static void showMessageDialog(Component parentComponent, 1417: Object message, String title, 1418: int messageType) 1419: { 1420: JOptionPane pane = new JOptionPane(message, messageType); 1421: JDialog dialog = pane.createDialog(parentComponent, title); 1422: dialog.show(); 1423: } 1424: 1425: /** 1426: * This method shows a message dialog with the given message, title, 1427: * messageType and icon. 1428: * 1429: * @param parentComponent The component to find a frame in. 1430: * @param message The message displayed. 1431: * @param title The title of the dialog. 1432: * @param messageType The messageType. 1433: * @param icon The icon displayed. 1434: */ 1435: public static void showMessageDialog(Component parentComponent, 1436: Object message, String title, 1437: int messageType, Icon icon) 1438: { 1439: JOptionPane pane = new JOptionPane(message, messageType); 1440: pane.setIcon(icon); 1441: JDialog dialog = pane.createDialog(parentComponent, title); 1442: dialog.show(); 1443: } 1444: 1445: /** 1446: * This method shows an option dialog with the given message, title, 1447: * optionType, messageType, icon, options and initialValue. This method 1448: * returns the option that was selected. 1449: * 1450: * @param parentComponent The component to find a frame in. 1451: * @param message The message displayed. 1452: * @param title The title of the dialog. 1453: * @param optionType The optionType. 1454: * @param messageType The messageType. 1455: * @param icon The icon displayed. 1456: * @param options The options to choose from. 1457: * @param initialValue The initial value. 1458: * 1459: * @return The selected option. 1460: */ 1461: public static int showOptionDialog(Component parentComponent, 1462: Object message, String title, 1463: int optionType, int messageType, 1464: Icon icon, Object[] options, 1465: Object initialValue) 1466: { 1467: JOptionPane pane = new JOptionPane(message, messageType, optionType, icon, 1468: options, initialValue); 1469: 1470: JDialog dialog = pane.createDialog(parentComponent, title); 1471: dialog.show(); 1472: 1473: if (pane.getValue() instanceof Integer) 1474: return ((Integer) pane.getValue()).intValue(); 1475: return -1; 1476: } 1477: 1478: /** 1479: * This method resets the UI to the Look and Feel default. 1480: */ 1481: public void updateUI() 1482: { 1483: setUI((OptionPaneUI) UIManager.getUI(this)); 1484: } 1485: 1486: /** 1487: * This method returns true if the key is a valid messageType. 1488: * 1489: * @param key The key to check. 1490: * 1491: * @return True if key is valid. 1492: */ 1493: private boolean validMessageType(int key) 1494: { 1495: switch (key) 1496: { 1497: case ERROR_MESSAGE: 1498: case INFORMATION_MESSAGE: 1499: case PLAIN_MESSAGE: 1500: case QUESTION_MESSAGE: 1501: case WARNING_MESSAGE: 1502: return true; 1503: } 1504: return false; 1505: } 1506: 1507: /** 1508: * This method returns true if the key is a valid optionType. 1509: * 1510: * @param key The key to check. 1511: * 1512: * @return True if key is valid. 1513: */ 1514: private boolean validOptionType(int key) 1515: { 1516: switch (key) 1517: { 1518: case DEFAULT_OPTION: 1519: case OK_CANCEL_OPTION: 1520: case YES_NO_CANCEL_OPTION: 1521: case YES_NO_OPTION: 1522: return true; 1523: } 1524: return false; 1525: } 1526: 1527: /** 1528: * This helper method makes the JInternalFrame wait until it is notified by 1529: * an InternalFrameClosing event. This method also adds the given 1530: * JOptionPane to the JInternalFrame and sizes it according to the 1531: * JInternalFrame's preferred size. 1532: * 1533: * @param f The JInternalFrame to make modal. 1534: */ 1535: private static void startModal(JInternalFrame f) 1536: { 1537: // We need to add an additional glasspane-like component directly 1538: // below the frame, which intercepts all mouse events that are not 1539: // directed at the frame itself. 1540: JPanel modalInterceptor = new JPanel(); 1541: modalInterceptor.setOpaque(false); 1542: JLayeredPane lp = JLayeredPane.getLayeredPaneAbove(f); 1543: lp.setLayer(modalInterceptor, JLayeredPane.MODAL_LAYER.intValue()); 1544: modalInterceptor.setBounds(0, 0, lp.getWidth(), lp.getHeight()); 1545: modalInterceptor.addMouseListener(new MouseAdapter(){}); 1546: modalInterceptor.addMouseMotionListener(new MouseMotionAdapter(){}); 1547: lp.add(modalInterceptor); 1548: f.toFront(); 1549: 1550: // We need to explicitly dispatch events when we are blocking the event 1551: // dispatch thread. 1552: EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); 1553: try 1554: { 1555: while (! f.isClosed()) 1556: { 1557: if (EventQueue.isDispatchThread()) 1558: { 1559: // The getNextEventMethod() issues wait() when no 1560: // event is available, so we don't need do explicitly wait(). 1561: AWTEvent ev = queue.getNextEvent(); 1562: // This mimics EventQueue.dispatchEvent(). We can't use 1563: // EventQueue.dispatchEvent() directly, because it is 1564: // protected, unfortunately. 1565: if (ev instanceof ActiveEvent) 1566: ((ActiveEvent) ev).dispatch(); 1567: else if (ev.getSource() instanceof Component) 1568: ((Component) ev.getSource()).dispatchEvent(ev); 1569: else if (ev.getSource() instanceof MenuComponent) 1570: ((MenuComponent) ev.getSource()).dispatchEvent(ev); 1571: // Other events are ignored as per spec in 1572: // EventQueue.dispatchEvent 1573: } 1574: else 1575: { 1576: // Give other threads a chance to become active. 1577: Thread.yield(); 1578: } 1579: } 1580: } 1581: catch (InterruptedException ex) 1582: { 1583: // If we get interrupted, then leave the modal state. 1584: } 1585: finally 1586: { 1587: // Clean up the modal interceptor. 1588: lp.remove(modalInterceptor); 1589: 1590: // Remove the internal frame from its parent, so it is no longer 1591: // lurking around and clogging memory. 1592: Container parent = f.getParent(); 1593: if (parent != null) 1594: parent.remove(f); 1595: } 1596: } 1597: }