home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / JOptionPane.java < prev    next >
Text File  |  1998-02-26  |  77KB  |  1,824 lines

  1. /*
  2.  * @(#)JOptionPane.java    1.28 98/02/04
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import java.awt.BorderLayout;
  24. import java.awt.Component;
  25. import java.awt.Container;
  26. import java.awt.Dialog;
  27. import java.awt.Dimension;
  28. import java.awt.Frame;
  29. import java.awt.Toolkit;
  30. import java.beans.PropertyChangeEvent;
  31. import java.beans.PropertyChangeListener;
  32. import java.awt.event.WindowAdapter;
  33. import java.awt.event.WindowEvent;
  34. import java.io.IOException;
  35. import java.io.ObjectInputStream;
  36. import java.io.ObjectOutputStream;
  37. import java.io.Serializable;
  38. import java.util.Vector;
  39. import com.sun.java.swing.plaf.OptionPaneUI;
  40.  
  41. /**
  42.  * JOptionPane makes it easy to pop up a standard dialog box that
  43.  * prompts users for a value or informs them of something. While the 
  44.  * class may appear complex because of the large number of methods, almost
  45.  * all uses of this class are one-line calls to one of the static 
  46.  * <code>showXxxDialog</code> methods shown below:
  47.  * <blockquote>
  48.  * <table>
  49.  * <tr align=top><td>showConfirmDialog<td>Asks a confirming question, 
  50.  *                   like yes/no/cancel.
  51.  * <tr align=top><td>showInputDialog<td>Prompt for some input.
  52.  * <tr align=top><td>showMessageDialog<td>Tell the user about something 
  53.  *                                        that has happened.
  54.  * <tr align=top><td>showOptionDialog<td>The Grand Unification of the above three.
  55.  * </table>
  56.  * </blockquote>
  57.  * Each of these methods also comes in a <code>showInternalXXX</code>
  58.  * flavor, which uses an internal frame to hold the dialog box (see
  59.  * <a href=com.sun.java.swing.JInternalFrame.html>JInternalFrame</a>).
  60.  * Multiple convenience methods have also been defined -- overloaded 
  61.  * versions of the basic methods that use different parameter lists.
  62.  * <p>
  63.  * All dialogs are modal. Each <code>showXxxDialog</code> method blocks 
  64.  * the current thread until the user's interaction is complete.
  65.  * <p>
  66.  * <table cellspacing=6 cellpadding=4 border=0 align=right>
  67.  * <tr>
  68.  * <td bgcolor=#FFe0d0 rowspan=2>
  69.  * icon
  70.  * <td bgcolor=#FFe0d0>
  71.  * message
  72.  * <tr>
  73.  * <td bgcolor=#FFe0d0>
  74.  * input value
  75.  * <tr>
  76.  * <td bgcolor=#FFe0d0 colspan=2>
  77.  * option buttons
  78.  * </table>
  79.  * The basic appearance of one of these dialog boxes is generally
  80.  * similar to the picture at the right, although the various look-and-feels are
  81.  * ultimatly responsible for the final result.
  82.  * <br clear=all>
  83.  * <p>
  84.  * <b>Parameters:</b><br>
  85.  * The parameters to these methods follow consistent patterns:
  86.  * <blockquote>
  87.  * <dl compact>
  88.  * <dt>parentComponent<dd>
  89.  * Defines the Component that is to be the parent of this dialog box.
  90.  * It is used in two ways: the Frame that contains it is used as the Frame
  91.  * parent for the dialog box, and its screen coordinates are used in
  92.  * the placement of the dialog box. In general, the dialog box is placed
  93.  * just below the component. This parameter may be null, in which case
  94.  * a default Frame is used as the parent, and the dialog will be
  95.  * centered on the screen (depending on the L&F).
  96.  * <dt><a name=message>message</a><dd>
  97.  * A descriptive message to be placed in the dialog box.
  98.  * In the most common usage, message is just a String or String constant.
  99.  * However, the type of this parameter is actually Object. It's 
  100.  * interpretation depends on its type:
  101.  * <dl compact>
  102.  * <dt>Object[]<dd>An array of objects is interpreted as a series of
  103.  *                 messages (one per object) arranged in a vertical stack.
  104.  *                 The interpretation is recursive -- each object in the
  105.  *                 array is interpreted according to its type. 
  106.  * <dt>Component<dd>The Component is displayed in the dialog.
  107.  * <dt>Icon<dd>The Icon is wrapped in a JLabel and displayed in the dialog.
  108.  * <dt>others<dd>The object is converted to a String by calling its 
  109.  *               <code>toString</code> method. The result is wrapped in a
  110.  *               JLabel and displayed.
  111.  * </dl>
  112.  * <dt>messageType<dd>Defines the style of the message. The look&feel
  113.  * manager may lay out the dialog differently depending on this value, and
  114.  * will often provide a default icon. The possible values are:
  115.  * <ul>
  116.  * <li>ERROR_MESSAGE
  117.  * <li>INFORMATION_MESSAGE
  118.  * <li>WARNING_MESSAGE
  119.  * <li>QUESTION_MESSAGE
  120.  * <li>PLAIN_MESSAGE
  121.  * </ul>
  122.  * <dt>optionType<dd>Defines the set of option buttons that appear at
  123.  * the bottom of the dialog box:
  124.  * <ul>
  125.  * <li>DEFAULT_OPTION
  126.  * <li>YES_NO_OPTION
  127.  * <li>YES_NO_CANCEL_OPTION
  128.  * <li>OK_CANCEL_OPTION
  129.  * </ul>
  130.  * You aren't limited to this set of option buttons.  You can provide any
  131.  * buttons you want using the options parameter.
  132.  * <dt>options<dd>A more detailed description of the set of option buttons
  133.  * that will appear at the bottom of the dialog box. 
  134.  * The usual value for the options parameter is an array of Strings. But 
  135.  * the parameter type is an array of Objects. A button is created for each
  136.  * object depending on it's type:
  137.  * <dl compact>
  138.  * <dt>Component<dd>The component is added to the button row directly.
  139.  * <dt>Icon<dd>A JButton is created with this as its label.
  140.  * <dt>other<dd>The Object is converted to a string using its
  141.  *              <code>toString</code> method and the result is used to
  142.  *              label a JButton.
  143.  * </dl>
  144.  * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
  145.  * value for this is determined by the messageType parameter.
  146.  * <dt>title<dd>The title for the dialog box.
  147.  * <dt>initialValue<dd>The default selection (input value).
  148.  * </dl>
  149.  * </blockquote>
  150.  * <p>
  151.  * When the selection is changed, <code>setValue</code> is invoked,
  152.  * which generates a PropertyChangeEvent.
  153.  * <p>
  154.  * If a JOptionPane has configured to all input <code>setWantsInput</code>
  155.  * the bound property JOptionPane.INPUT_VALUE_PROPERTY can also be listened
  156.  * to, to determine when the user has input or selected a value.
  157.  * <p>
  158.  * When one of the <code>showXxxDialog</code> methods returns an integer, 
  159.  * the possible values are:<pre>
  160.  *     YES_OPTION,
  161.  *     NO_OPTION,
  162.  *     CANCEL_OPTION,
  163.  *     OK_OPTION, or
  164.  *     CLOSED_OPTION.
  165.  * </pre>
  166.  * <b>Examples:</b>
  167.  * <dl>
  168.  * <dt>Show an error dialog that displays the message, 'alert':
  169.  * <dd><code>
  170.  * JOptionPane.showMessageDialog(null, "alert", "alert", ERROR_MESSAGE);
  171.  * </code><p>
  172.  * <dt>Show an internal information dialog with the message, 'information':
  173.  * <dd><code>
  174.  * JOptionPane.showInternalMessageDialog(frame, INFORMATION_MESSAGE,<br>
  175.  *             <ul><ul>"information", "information");</ul></ul>
  176.  * </code><p>
  177.  * <dt>Show an information panel with the options yes/no and message 'choose one':
  178.  * <dd><code>JOptionPane.showConfirmDialog(null,
  179.  *             <ul><ul>"choose one", "choose one", YES_NO);</ul></ul>
  180.  * </code><p>
  181.  * <dt>Show an internal information dialog with the options yes/no/cancel and
  182.  * message 'please choose one' and title information:
  183.  * <dd><code>JOptionPane.showInternalConfirmDialog(frame,
  184.  *             <ul><ul>"please choose one", "information",</ul></ul>
  185.  *             <ul><ul>YES_NO_CANCEL, INFORMATION_MESSAGE);</ul></ul>
  186.  * </code><p>
  187.  * <dt>Show a warning dialog with the options OK, CANCEL, title 'Warning', and
  188.  * message 'Click OK to continue':
  189.  * <dd><code>
  190.  * Object[] options = { "OK", "CANCEL" };<br>
  191.  * JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
  192.  *             <ul><ul>DEFAULT_OPTION, WARNING_MESSAGE,</ul></ul>
  193.  *             <ul><ul>null, options, options[0]);</ul></ul>
  194.  * </code><p>
  195.  * <dt>Show a dialog asking the user to type in a String:
  196.  * <dd><code>
  197.  * String inputValue = JOptionPane.showInputDialog("Please input a value");
  198.  * </code><p>
  199.  * <dt>Show a dialog asking the user to select a String:
  200.  * <dd><code>
  201.  * Object[] possibleValues = { "First", "Second", "Third" };<br>
  202.  * Object selectedValue = JOptionDialog.showInputDialog(null,
  203.  *             <ul><ul>"Choose one", "Input",</ul></ul>
  204.  *             <ul><ul>JOptionPane.INFORMATION_DIALOG, null,</ul></ul>
  205.  *             <ul><ul>possibleValues, possibleValues[0]);</ul></ul>
  206.  * </code><p>
  207.  * </dl>
  208.  * <b>Direct Use:</b><br>
  209.  * To create and use an JOptionPane directly, the
  210.  * standard pattern is roughly as follows:
  211.  * <pre>
  212.  *     JOptionPane pane = new JOptionPane(<i>arguments</i>);
  213.  *     pane.set<i>.Xxxx(...); // Configure</i>
  214.  *     JDialog dialog = pane.createDialog(<i>parentComponent, title</i>);
  215.  *     dialog.show();
  216.  *     Object selectedValue = pane.getValue();
  217.  *     if(selectedValue == null)
  218.  *       return CLOSED_OPTION;
  219.  *     <i>//If there is <b>not</b> an array of option buttons:</i>
  220.  *     if(options == null) {
  221.  *       if(selectedValue instanceof Integer)
  222.  *          return ((Integer)selectedValue).intValue();
  223.  *       return CLOSED_OPTION;
  224.  *     }
  225.  *     <i>//If there is an array of option buttons:</i>
  226.  *     for(int counter = 0, maxCounter = options.length;
  227.  *        counter < maxCounter; counter++) {
  228.  *        if(options[counter].equals(selectedValue))
  229.  *        return counter;
  230.  *     }
  231.  *     return CLOSED_OPTION;
  232.  * <pre>
  233.  * <p>
  234.  * Warning: serialized objects of this class will not be compatible with
  235.  * future swing releases.  The current serialization support is appropriate 
  236.  * for short term storage or RMI between Swing1.0 applications.  It will
  237.  * not be possible to load serialized Swing1.0 objects with future releases
  238.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  239.  * baseline for the serialized form of Swing objects.
  240.  *
  241.  * @see JInternalFrame
  242.  *
  243.  * @beaninfo
  244.  *      attribute: isContainer true
  245.  *    description: A component which implements standard dialog box controls.
  246.  *
  247.  * @version 1.28 02/04/98
  248.  * @author James Gosling
  249.  * @author Scott Violet
  250.  */
  251. public class JOptionPane extends JComponent
  252. {
  253.     /**
  254.      * Indicates that the user has not yet selected a value.
  255.      */
  256.     public static final Object      UNINITIALIZED_VALUE = "uninitializedValue";
  257.  
  258.     //
  259.     // Option types
  260.     //
  261.     /** 
  262.      * Type meaning look and feel should not supply any options -- only
  263.      * use the options from the JOptionPane.
  264.      */
  265.     public static final int         DEFAULT_OPTION = -1;
  266.     /** Type used for showConfirmDialog. */
  267.     public static final int         YES_NO_OPTION = 0;
  268.     /** Type used for showConfirmDialog. */
  269.     public static final int         YES_NO_CANCEL_OPTION = 1;
  270.     /** Type used for showConfirmDialog. */
  271.     public static final int         OK_CANCEL_OPTION = 2;
  272.  
  273.     //
  274.     // Return values.
  275.     //
  276.     /** Return value from class method if YES is chosen. */
  277.     public static final int         YES_OPTION = 0;
  278.     /** Return value from class method if NO is chosen. */
  279.     public static final int         NO_OPTION = 1;
  280.     /** Return value from class method if CANCEL is chosen. */
  281.     public static final int         CANCEL_OPTION = 2;
  282.     /** Return value form class method if OK is chosen. */
  283.     public static final int         OK_OPTION = 0;
  284.     /** Return value from class method if user closes window without selecting
  285.      * anything, more than likely this should be treated as either a
  286.      * CANCEL_OPTION or NO_OPTION. */
  287.     public static final int         CLOSED_OPTION = -1;
  288.  
  289.     //
  290.     // Message types. Used by the UI to determine what icon to display,
  291.     // and possibly what behavior to give based on the type.
  292.     //
  293.     /** Used for error messages. */
  294.     public static final int  ERROR_MESSAGE = 0;
  295.     /** Used for information messages. */
  296.     public static final int  INFORMATION_MESSAGE = 1;
  297.     /** Used for warning messages. */
  298.     public static final int  WARNING_MESSAGE = 2;
  299.     /** Used for questions. */
  300.     public static final int  QUESTION_MESSAGE = 3;
  301.     /** No icon is used. */
  302.     public static final int   PLAIN_MESSAGE = -1;
  303.  
  304.     /** Bound property name for icon. */
  305.     public static final String      ICON_PROPERTY = "icon";
  306.     /** Bound property name for message. */
  307.     public static final String      MESSAGE_PROPERTY = "message";
  308.     /** Bounds property name for value. */
  309.     public static final String      VALUE_PROPERTY = "value";
  310.     /** Bounds property namer for option. */
  311.     public static final String      OPTIONS_PROPERTY = "options";
  312.     /** Bounds property name for initialValue. */
  313.     public static final String      INITIAL_VALUE_PROPERTY = "initialValue";
  314.     /** Bounds property name for type. */
  315.     public static final String      MESSAGE_TYPE_PROPERTY = "messageType";
  316.     /** Bound property name for optionType. */
  317.     public static final String      OPTION_TYPE_PROPERTY = "optionType";
  318.     /** Bound property name for selectionValues. */
  319.     public static final String      SELECTION_VALUES_PROPERTY = "selectionValues";
  320.     /** Bound property name for initialSelectionValue. */
  321.     public static final String      INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
  322.     /** Bound property name for inputValue. */
  323.     public static final String      INPUT_VALUE_PROPERTY = "inputValue";
  324.     /** Bound property name for wantsInput. */
  325.     public static final String      WANTS_INPUT_PROPERTY = "wantsInput";
  326.  
  327.     /** Icon used in pane. */
  328.     transient protected Icon                  icon;
  329.     /** Message to display. */
  330.     transient protected Object                message;
  331.     /** Options to display to the user. */
  332.     transient protected Object[]              options;
  333.     /** Value that should be initialy selected in options. */
  334.     transient protected Object                initialValue;
  335.     /** Message type. */
  336.     protected int                   messageType;
  337.     /** Option type, one of DEFAULT_OPTION, YES_NO_OPTION,
  338.      * YES_NO_CANCEL_OPTION or OK_CANCEL_OPTION. */
  339.     protected int                   optionType;
  340.     /** Currently selected value, will be a valid option, or
  341.      * UNINITIALIZED_VALUE or null. */
  342.     transient protected Object                value;
  343.     /** Array of values the user can choose from. Look and feel will
  344.      * provide the UI component to choose this from. */
  345.     protected transient Object[]              selectionValues;
  346.     /** Value the user has input. */
  347.     protected transient Object                inputValue;
  348.     /** Initial value to select in selectionValues. */
  349.     protected transient Object                initialSelectionValue;
  350.     /** If true, a UI widget will be provided to the user to get input. */
  351.     protected boolean                         wantsInput;
  352.  
  353.  
  354.     /**
  355.      * Shows a question-message dialog requesting input from the user. The 
  356.      * dialog uses the default frame, which usually means it is centered on 
  357.      * the screen. 
  358.      *
  359.      * @param message the Object to display
  360.      */
  361.     public static String showInputDialog(Object message) {
  362.         return showInputDialog(null, message);
  363.     }
  364.  
  365.     /**
  366.      * Shows a question-message dialog requesting input from the user parented to
  367.      * <code>parentComponent</code>. The dialog is displayed in the Component's
  368.      * frame, and is usually positioned below the Component. 
  369.      *
  370.      * @param parentComponent  the parent Component for the dialog
  371.      * @param message  the Object to display
  372.      */
  373.     public static String showInputDialog(Component parentComponent, Object message){
  374.         return showInputDialog(parentComponent, message, "Input", QUESTION_MESSAGE);
  375.     }
  376.  
  377.     /**
  378.      * Shows a dialog requesting input from the user parented to
  379.      * <code>parentComponent</code> with the dialog having the title
  380.      * <code>title</code> and message type <code>messageType</code>.
  381.      *
  382.      * @param parentComponent  the parent Component for the dialog
  383.      * @param message  the Object to display
  384.      * @param title    the String to display in the dialog title bar
  385.      * @param messageType the type of message that is to be displayed:
  386.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  387.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  388.      */
  389.     public static String showInputDialog(Component parentComponent, Object message,
  390.                                          String title, int messageType) {
  391.         return (String)showInputDialog(parentComponent, message, title,
  392.                                        messageType, null, null, null);
  393.     }
  394.  
  395.     /**
  396.      * Prompts the user for input in a blocking dialog where the
  397.      * initial selection, possible selections, and all other options can
  398.      * be specified. The user will able to choose from
  399.      * <code>selectionValues</code>, where null implies the user can input
  400.      * whatever they wish, usually by means of a JTextField. 
  401.      * <code>initialSelectionValue</code> is the initial value to prompt
  402.      * the user with. It is up to the UI to decide how best to represent
  403.      * the <code>selectionValues</code>, but usually a JComboBox, JList, or
  404.      * JTextField will be used.
  405.      *
  406.      * @param parentComponent  the parent Component for the dialog
  407.      * @param message  the Object to display
  408.      * @param title    the String to display in the dialog title bar
  409.      * @param messageType the type of message to be displayed:
  410.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  411.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  412.      * @param icon     the Icon image to display
  413.      * @param selectionValues an array of Objects that gives the possible
  414.      *                        selections
  415.      * @param initialSelectionValue the value used to initialize the input
  416.      *                              field
  417.      * @return users input, or null meaning the user canceled the input
  418.      */
  419.     public static Object showInputDialog(Component parentComponent, Object message,
  420.                       String title, int messageType, Icon icon,
  421.                       Object[] selectionValues, Object initialSelectionValue) {
  422.         JOptionPane    pane = new JOptionPane(message, messageType,
  423.                                               OK_CANCEL_OPTION, icon,
  424.                                               null, null);
  425.  
  426.         pane.setWantsInput(true);
  427.         pane.setSelectionValues(selectionValues);
  428.         pane.setInitialSelectionValue(initialSelectionValue);
  429.  
  430.         JDialog        dialog = pane.createDialog(parentComponent, title);
  431.  
  432.         pane.selectInitialValue();
  433.         dialog.show();
  434.  
  435.         Object value = pane.getInputValue();
  436.  
  437.         if(value == UNINITIALIZED_VALUE)
  438.             return null;
  439.         return value;
  440.     }
  441.  
  442.     /**
  443.      * Brings up a confirmation dialog -- a modal information-message dialog
  444.      * titled "Confirm".
  445.      *
  446.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  447.      *                  If null, or if the parentComponent has no Frame, a 
  448.      *                  default Frame is used.
  449.      * @param message   The Object to display
  450.      */
  451.     public static void showMessageDialog(Component parentComponent, Object message) {
  452.         showMessageDialog(parentComponent, message, "Message", INFORMATION_MESSAGE);
  453.     }
  454.  
  455.     /**
  456.      * Brings up a dialog that displays a message using a default
  457.      * icon determined by the messageType parameter.
  458.      *
  459.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  460.      *                  If null, or if the parentComponent has no Frame, a 
  461.      *                  default Frame is used.
  462.      * @param message   The Object to display
  463.      * @param title     the title string for the dialog
  464.      * @param messageType the type of message to be displayed:
  465.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  466.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  467.      */
  468.     public static void showMessageDialog(Component parentComponent, Object message,
  469.                                          String title, int messageType) {
  470.         showMessageDialog(parentComponent, message, title, messageType, null);
  471.     }
  472.  
  473.     /**
  474.      * Brings up a dialog displaying a message, specifying all parameters.
  475.      *
  476.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  477.      *                  If null, or if the parentComponent has no Frame, a 
  478.      *                  default Frame is used.
  479.      * @param message   The Object to display
  480.      * @param title     the title string for the dialog
  481.      * @param messageType the type of message to be displayed:
  482.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  483.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  484.      * @param icon      an icon to display in the dialog that helps the user
  485.      *                  identify the kind of message that is being displayed.
  486.      */
  487.     public static void showMessageDialog(Component parentComponent, Object message,
  488.                                          String title, int messageType,
  489.                                          Icon icon){
  490.         showOptionDialog(parentComponent, message, title, DEFAULT_OPTION, 
  491.                          messageType, icon, null, null);
  492.     }
  493.  
  494.     /**
  495.      * Brings up a modal dialog with the options Yes, No and Cancel; with the
  496.      * title, "Select an Option".
  497.      *
  498.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  499.      *                  If null, or if the parentComponent has no Frame, a 
  500.      *                  default Frame is used.
  501.      * @param message   The Object to display
  502.      * @return an int indicating the option selected by the user
  503.      */
  504.     public static int showConfirmDialog(Component parentComponent, Object message) {
  505.         return showConfirmDialog(parentComponent, message, "Select an Option",
  506.                                  YES_NO_CANCEL_OPTION);
  507.     }
  508.  
  509.     /**
  510.      * Brings up a modal dialog where the number of choices is determined
  511.      * by the <code>optionType</code> parameter.
  512.      * 
  513.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  514.      *                  If null, or if the parentComponent has no Frame, a 
  515.      *                  default Frame is used.
  516.      * @param message   The Object to display
  517.      * @param title     the title string for the dialog
  518.      * @param optionType an int designating the options available on the dialog:
  519.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  520.      * @return an int indicating the option selected by the user
  521.      */
  522.     public static int showConfirmDialog(Component parentComponent, Object message,
  523.                                         String title, int optionType) {
  524.         return showConfirmDialog(parentComponent, message, title, optionType,
  525.                                  QUESTION_MESSAGE);
  526.     }
  527.  
  528.     /**
  529.      * Brings up a modal dialog where the number of choices is determined
  530.      * by the <code>optionType</code> parameter, where the <code>messageType</code>
  531.      * parameter determines the icon to display.
  532.      * The <code>messageType</code> parameter is primarily used to supply
  533.      * a default icon from the look and feel.
  534.      *
  535.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  536.      *                  If null, or if the parentComponent has no Frame, a 
  537.      *                  default Frame is used.
  538.      * @param message   The Object to display
  539.      * @param title     the title string for the dialog
  540.      * @param optionType an int designating the options available on the dialog:
  541.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  542.      * @param messageType an int designating the kind of message this is, 
  543.      *                    primarily used to determine the icon from the pluggable
  544.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  545.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  546.      * @return an int indicating the option selected by the user
  547.      */
  548.     public static int showConfirmDialog(Component parentComponent, Object message,
  549.                                         String title, int optionType,
  550.                                         int messageType) {
  551.         return showConfirmDialog(parentComponent, message, title, optionType,
  552.                                 messageType, null);
  553.     }
  554.  
  555.     /**
  556.      * Brings up a modal dialog with a specified icon, where the number of 
  557.      * choices is determined by the <code>optionType</code> parameter.
  558.      * The <code>messageType</code> parameter is primarily used to supply
  559.      * a default icon from the look and feel.
  560.      *
  561.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  562.      *                  If null, or if the parentComponent has no Frame, a 
  563.      *                  default Frame is used.
  564.      * @param message   The Object to display
  565.      * @param title     the title string for the dialog
  566.      * @param optionType an int designating the options available on the dialog:
  567.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  568.      * @param messageType an int designating the kind of message this is, 
  569.      *                    primarily used to determine the icon from the pluggable
  570.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  571.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  572.      * @param icon      the icon to display in the dialog
  573.      * @return an int indicating the option selected by the user
  574.      */
  575.     public static int showConfirmDialog(Component parentComponent, Object message,
  576.                                         String title, int optionType,
  577.                                         int messageType, Icon icon) {
  578.         return showOptionDialog(parentComponent, message, title, optionType,
  579.                                 messageType, icon, null, null);
  580.     }
  581.  
  582.     /**
  583.      * Brings up a modal dialog with a specified icon, where the initial
  584.      * choice is dermined by the <code>initialValue</code> parameter and
  585.      * the number of choices is determined by the <code>optionType</code> 
  586.      * parameter.
  587.      * <p>
  588.      * If <code>optionType</code> is YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  589.      * and the <code>options</code> parameter is null, then the options are
  590.      * supplied by the look and feel. 
  591.      * <p>
  592.      * The <code>messageType</code> parameter is primarily used to supply
  593.      * a default icon from the look and feel.
  594.      *
  595.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  596.      *                  If null, or if the parentComponent has no Frame, a 
  597.      *                  default Frame is used.
  598.      * @param message   The Object to display
  599.      * @param title     the title string for the dialog
  600.      * @param optionType an int designating the options available on the dialog:
  601.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  602.      * @param messageType an int designating the kind of message this is, 
  603.      *                    primarily used to determine the icon from the pluggable
  604.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  605.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  606.      * @param icon      the icon to display in the dialog
  607.      * @param options   an array of objects indicating the possible choices
  608.      *                  the user can make. If the objects are components, they
  609.      *                  are rendered properly. Non-String objects are
  610.      *                  rendered using their <code>toString</code> methods.
  611.      *                  If this parameter is null, the options are determined
  612.      *                  by the look and feel.
  613.      * @param initialValue the object that represents the default selection
  614.      *                     for the dialog
  615.      * @return an int indicating the option chosen by the user, 
  616.      *         or CLOSED_OPTION if the user closed the Dialog
  617.      */
  618.     public static int showOptionDialog(Component parentComponent, Object message,
  619.                                        String title, int optionType,
  620.                                        int messageType, Icon icon,
  621.                                        Object[] options, Object initialValue) {
  622.         JOptionPane             pane = new JOptionPane(message, messageType,
  623.                                                        optionType, icon,
  624.                                                        options, initialValue);
  625.  
  626.         pane.setInitialValue(initialValue);
  627.  
  628.         JDialog         dialog = pane.createDialog(parentComponent, title);
  629.  
  630.         pane.selectInitialValue();
  631.         dialog.show();
  632.  
  633.         Object        selectedValue = pane.getValue();
  634.  
  635.         if(selectedValue == null)
  636.             return CLOSED_OPTION;
  637.         if(options == null) {
  638.             if(selectedValue instanceof Integer)
  639.                 return ((Integer)selectedValue).intValue();
  640.             return CLOSED_OPTION;
  641.         }
  642.         for(int counter = 0, maxCounter = options.length;
  643.             counter < maxCounter; counter++) {
  644.             if(options[counter].equals(selectedValue))
  645.                 return counter;
  646.         }
  647.         return CLOSED_OPTION;
  648.     }
  649.  
  650.     /**
  651.      * Creates and returns a new JDialog wrapping <code>this</code>
  652.      * centered on the <code>parentComponent</code> in the 
  653.      * <code>parentComponent</code>'s frame.
  654.      * <code>title</code> is the title of the returned dialog.
  655.      * The returned JDialog will be set up such that once it is closed,
  656.      * or the user clicks on the OK button, the dialog will be disposed
  657.      * and closed.
  658.      *Re if the parentComponent has no Frame, a 
  659.      *                  default Frame is used.
  660.      * @param title     the title string for the dialog
  661.      * @return a new JDialog containing this instance
  662.      */
  663.     public JDialog createDialog(Component parentComponent, String title) {
  664.         Frame                 frame = JOptionPane.getFrameForComponent(parentComponent);
  665.         // Workaround for bug in Solaris where modal dialog
  666.         // disposal causes segv
  667.         //final JDialog         dialog = new JDialog(frame, title, true);
  668.         final JDialog         dialog = SwingUtilities.getRecycledModalDialog(frame, title);
  669.         Container             contentPane = dialog.getContentPane();
  670.  
  671.         contentPane.setLayout(new BorderLayout());
  672.         contentPane.add(this, BorderLayout.CENTER);
  673.         dialog.pack();
  674.         dialog.setLocationRelativeTo(parentComponent);
  675.         dialog.addWindowListener(new WindowAdapter() {
  676.         boolean gotFocus = false;
  677.             public void windowClosing(WindowEvent we) {
  678.                 setValue(null);
  679.             }
  680.             public void windowActivated(WindowEvent we) {
  681.                 // Once window gets focus, set initial focus
  682.             if (!gotFocus) {
  683.                     selectInitialValue();
  684.                 gotFocus = true;
  685.                 }
  686.             }
  687.         });
  688.         addPropertyChangeListener(new PropertyChangeListener() {
  689.             public void propertyChange(PropertyChangeEvent event) {
  690.                 if(dialog.isVisible() && event.getSource() == JOptionPane.this &&
  691.                    (event.getPropertyName().equals(VALUE_PROPERTY) ||
  692.                     event.getPropertyName().equals(INPUT_VALUE_PROPERTY))) {
  693.                     dialog.setVisible(false);
  694.                     // Workaround for bug in Solaris where modal dialog
  695.                     // disposal causes segv
  696.                     //dialog.dispose();
  697.                     SwingUtilities.recycleModalDialog(dialog);
  698.                 }
  699.             }
  700.         });
  701.         return dialog;
  702.     }
  703.         
  704.  
  705.     /**
  706.      * Brings up an internal confirmation dialog panel. The dialog
  707.      * is a modal information-message dialog titled "Message".
  708.      *
  709.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  710.      *                  If null, or if the parentComponent has no Frame, a 
  711.      *                  default Frame is used.
  712.      * @param message   The object to display
  713.      */
  714.     public static void showInternalMessageDialog(Component parentComponent,
  715.                                                  Object message) {
  716.         showInternalMessageDialog(parentComponent, message, "Message",
  717.                                   INFORMATION_MESSAGE);
  718.     }
  719.  
  720.     /** 
  721.      * Brings up an internal dialog panel that displays a message 
  722.      * using a default icon determined by the messageType parameter.
  723.      *
  724.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  725.      *                  If null, or if the parentComponent has no Frame, a 
  726.      *                  default Frame is used.
  727.      * @param message   The Object to display
  728.      * @param title     the title string for the dialog
  729.      * @param messageType the type of message to be displayed:
  730.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  731.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  732.      */
  733.     public static void showInternalMessageDialog(Component parentComponent,
  734.                                                  Object message, String title,
  735.                                                  int messageType) {
  736.         showInternalMessageDialog(parentComponent, message, title, messageType,null);
  737.     }
  738.  
  739.     /**
  740.      * Brings up an internal dialog panel displaying a message, 
  741.      * specifying all parameters.
  742.      *
  743.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  744.      *                  If null, or if the parentComponent has no Frame, a 
  745.      *                  default Frame is used.
  746.      * @param message   The Object to display
  747.      * @param title     the title string for the dialog
  748.      * @param messageType the type of message to be displayed:
  749.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  750.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  751.      * @param icon      an icon to display in the dialog that helps the user
  752.      *                  identify the kind of message that is being displayed.
  753.      */
  754.     public static void showInternalMessageDialog(Component parentComponent,
  755.                                          Object message,
  756.                                          String title, int messageType,
  757.                                          Icon icon){
  758.         showInternalOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
  759.                                  messageType, icon, null, null);
  760.     }
  761.  
  762.     /**
  763.      * Brings up an internal dialog panel with the options Yes, No 
  764.      * and Cancel; with the title, "Select an Option".
  765.      *
  766.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  767.      *                  If null, or if the parentComponent has no Frame, a 
  768.      *                  default Frame is used.
  769.      * @param message   The Object to display
  770.      * @return an int indicating the option selected by the user
  771.      */
  772.     public static int showInternalConfirmDialog(Component parentComponent,
  773.                                                 Object message) {
  774.         return showInternalConfirmDialog(parentComponent, message,
  775.                                   "Select an Option", YES_NO_CANCEL_OPTION);
  776.     }
  777.  
  778.     /**
  779.      * Brings up a internal dialog panel where the number of choices 
  780.      * is determined by the <code>optionType</code> parameter.
  781.      * 
  782.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  783.      *                  If null, or if the parentComponent has no Frame, a 
  784.      *                  default Frame is used.
  785.      * @param message   The object to display in the dialog. A Component object
  786.      *                  is rendered as a Component. A String object is rendered
  787.      *                  as a string. Other objects are converted to a String
  788.      *                  using the <code>toString</code> method.
  789.      * @param title     the title string for the dialog
  790.      * @param optionType an int designating the options available on the dialog:
  791.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  792.      * @return an int indicating the option selected by the user
  793.      */
  794.     public static int showInternalConfirmDialog(Component parentComponent,
  795.                                                 Object message, String title,
  796.                                                 int optionType) {
  797.         return showInternalConfirmDialog(parentComponent, message, title, optionType,
  798.                                          QUESTION_MESSAGE);
  799.     }
  800.  
  801.     /**
  802.      * Brings up an internal dialog panel where the number of choices
  803.      * is determined by the <code>optionType</code> parameter, where
  804.      * the <code>messageType</code> parameter determines the icon to display.
  805.      * The <code>messageType</code> parameter is primarily used to supply
  806.      * a default icon from the look and feel.
  807.      *
  808.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  809.      *                  If null, or if the parentComponent has no Frame, a 
  810.      *                  default Frame is used.
  811.      * @param message   The object to display in the dialog. A Component object
  812.      *                  is rendered as a Component. A String object is rendered
  813.      *                  as a string. Other objects are converted to a String
  814.      *                  using the <code>toString</code> method.
  815.      * @param title     the title string for the dialog
  816.      * @param optionType an int designating the options available on the dialog:
  817.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  818.      * @param messageType an int designating the kind of message this is, 
  819.      *                    primarily used to determine the icon from the pluggable
  820.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  821.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  822.      * @return an int indicating the option selected by the user
  823.      */
  824.     public static int showInternalConfirmDialog(Component parentComponent, 
  825.                                         Object message,
  826.                                         String title, int optionType,
  827.                                         int messageType) {
  828.         return showInternalConfirmDialog(parentComponent, message, title, optionType,
  829.                                          messageType, null);
  830.     }
  831.  
  832.     /**
  833.      * Brings up an internal dialog panel with a specified icon, where
  834.      * the number of choices is determined by the <code>optionType</code>
  835.      * parameter. 
  836.      * The <code>messageType</code> parameter is primarily used to supply
  837.      * a default icon from the look and feel.
  838.      *
  839.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  840.      *                  If null, or if the parentComponent has no Frame, a 
  841.      *                  default Frame is used.
  842.      * @param message   The object to display in the dialog. A Component object
  843.      *                  is rendered as a Component. A String object is rendered
  844.      *                  as a string. Other objects are converted to a String
  845.      *                  using the <code>toString</code> method.
  846.      * @param title     the title string for the dialog
  847.      * @param optionType an int designating the options available on the dialog:
  848.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  849.      * @param messageType an int designating the kind of message this is, 
  850.      *                    primarily used to determine the icon from the pluggable
  851.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  852.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  853.      * @param icon      the icon to display in the dialog
  854.      * @return an int indicating the option selected by the user
  855.      */
  856.     public static int showInternalConfirmDialog(Component parentComponent,
  857.                                         Object message,
  858.                                         String title, int optionType,
  859.                                         int messageType, Icon icon) {
  860.         return showInternalOptionDialog(parentComponent, message, title, optionType,
  861.                                         messageType, icon, null, null);
  862.     }
  863.  
  864.     /**
  865.      * Brings up an internal dialog panel with a specified icon, where
  866.      * the initial choice is dermined by the <code>initialValue</code>
  867.      * parameter and the number of choices is determined by the 
  868.      * <code>optionType</code> parameter.
  869.      * <p>
  870.      * If <code>optionType</code> is YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  871.      * and the <code>options</code> parameter is null, then the options are
  872.      * supplied by the look and feel. 
  873.      * <p>
  874.      * The <code>messageType</code> parameter is primarily used to supply
  875.      * a default icon from the look and feel.
  876.      *
  877.      * @param parentComponent Determines the Frame in which the dialog is displayed. 
  878.      *                  If null, or if the parentComponent has no Frame, a 
  879.      *                  default Frame is used.
  880.      * @param message   The object to display in the dialog. A Component object
  881.      *                  is rendered as a Component. A String object is rendered
  882.      *                  as a string. Other objects are converted to a String
  883.      *                  using the <code>toString</code> method.
  884.      * @param title     the title string for the dialog
  885.      * @param optionType an int designating the options available on the dialog:
  886.      *                   YES_NO_OPTION, or YES_NO_CANCEL_OPTION
  887.      * @param messageType an int designating the kind of message this is, 
  888.      *                    primarily used to determine the icon from the pluggable
  889.      *                    look and feel: ERROR_MESSAGE, INFORMATION_MESSAGE, 
  890.      *                    WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE.
  891.      * @param icon      the icon to display in the dialog
  892.      * @param options   an array of objects indicating the possible choices
  893.      *                  the user can make. If the objects are components, they
  894.      *                  are rendered properly. Non-String objects are
  895.      *                  rendered using their <code>toString</code> methods.
  896.      *                  If this parameter is null, the options are determined
  897.      *                  by the look and feel.
  898.      * @param initialValue the object that represents the default selection
  899.      *                     for the dialog
  900.      * @return an int indicating the option chosen by the user, 
  901.      *         or CLOSED_OPTION if the user closed the Dialog
  902.      */
  903.     public static int showInternalOptionDialog(Component parentComponent,
  904.                                        Object message,
  905.                                        String title, int optionType,
  906.                                        int messageType, Icon icon,
  907.                                        Object[] options, Object initialValue) {
  908.         JOptionPane             pane = new JOptionPane(message, messageType,
  909.                                                        optionType, icon,
  910.                                                        options, initialValue);
  911.  
  912.         pane.setInitialValue(initialValue);
  913.  
  914.         JInternalFrame   dialog = pane.createInternalFrame(parentComponent, title);
  915.  
  916.         pane.selectInitialValue();
  917.         dialog.startModal();
  918.  
  919.         Object        selectedValue = pane.getValue();
  920.  
  921.         if(selectedValue == null)
  922.             return CLOSED_OPTION;
  923.         if(options == null) {
  924.             if(selectedValue instanceof Integer)
  925.                 return ((Integer)selectedValue).intValue();
  926.             return CLOSED_OPTION;
  927.         }
  928.         for(int counter = 0, maxCounter = options.length;
  929.             counter < maxCounter; counter++) {
  930.             if(options[counter].equals(selectedValue))
  931.                 return counter;
  932.         }
  933.         return CLOSED_OPTION;
  934.     }
  935.  
  936.     /**
  937.      * Shows an internal question-message dialog requesting input from
  938.      * the user parented to  <code>parentComponent</code>. The dialog
  939.      * is displayed in the Component's frame, and is usually positioned
  940.      * below the Component. 
  941.      *
  942.      * @param parentComponent  the parent Component for the dialog
  943.      * @param message  the Object to display
  944.      */
  945.     public static String showInternalInputDialog(Component parentComponent,
  946.                                                  Object message) {
  947.         return showInternalInputDialog(parentComponent, message, "Input",
  948.                                        QUESTION_MESSAGE);
  949.     }
  950.  
  951.     /**
  952.      * Shows an internal dialog requesting input from the user parented
  953.      * to <code>parentComponent</code> with the dialog having the title
  954.      * <code>title</code> and message type <code>messageType</code>.
  955.      *
  956.      * @param parentComponent  the parent Component for the dialog
  957.      * @param message  the Object to display
  958.      * @param title    the String to display in the dialog title bar
  959.      * @param messageType the type of message that is to be displayed:
  960.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  961.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  962.      */
  963.     public static String showInternalInputDialog(Component parentComponent,
  964.                              Object message, String title, int messageType) {
  965.         return (String)showInternalInputDialog(parentComponent, message, title,
  966.                                        messageType, null, null, null);
  967.     }
  968.  
  969.     /**
  970.      * Prompts the user for input in a blocking internal dialog where
  971.      * the initial selection, possible selections, and all other 
  972.      * options can be specified. The user will able to choose from
  973.      * <code>selectionValues</code>, where null implies the user can input
  974.      * whatever they wish, usually by means of a JTextField. 
  975.      * <code>initialSelectionValue</code> is the initial value to prompt
  976.      * the user with. It is up to the UI to decide how best to represent
  977.      * the <code>selectionValues</code>, but usually a JComboBox, JList, or
  978.      * JTextField will be used.
  979.      *
  980.      * @param parentComponent  the parent Component for the dialog
  981.      * @param message  the Object to display
  982.      * @param title    the String to display in the dialog title bar
  983.      * @param messageType the type of message to be displayed:
  984.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  985.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  986.      * @param icon     the Icon image to display
  987.      * @param selectionValues an array of Objects that gives the possible
  988.      *                        selections
  989.      * @param initialSelectionValue the value used to initialize the input
  990.      *                              field
  991.      * @return users input, or null meaning the user canceled the input
  992.      */
  993.     public static Object showInternalInputDialog(Component parentComponent,
  994.                       Object message, String title, int messageType, Icon icon,
  995.                       Object[] selectionValues, Object initialSelectionValue) {
  996.         JOptionPane             pane = new JOptionPane(message, messageType,
  997.                                                        OK_CANCEL_OPTION, icon,
  998.                                                        null, null);
  999.  
  1000.         pane.setWantsInput(true);
  1001.         pane.setSelectionValues(selectionValues);
  1002.         pane.setInitialSelectionValue(initialSelectionValue);
  1003.  
  1004.         JInternalFrame   dialog = pane.createInternalFrame(parentComponent, title);
  1005.  
  1006.         pane.selectInitialValue();
  1007.         dialog.startModal();
  1008.  
  1009.         Object value = pane.getInputValue();
  1010.  
  1011.         if(value == UNINITIALIZED_VALUE)
  1012.             return null;
  1013.         return (String)value;
  1014.     }
  1015.  
  1016.     /**
  1017.      * Creates and returns an instance of JInternalFrame. 
  1018.      * The internal frame is created with the specified title,
  1019.      * and wrapping the JOptionPane. The returned JInternalFrame is
  1020.      * added to the JDesktopPane ancestor of parentComponent, or components
  1021.      * parent if one its ancestors isn't a JDesktopPane, or if parentComponent
  1022.      * doesn't have a parent then a <code>RuntimeException</code> is thrown.
  1023.      *
  1024.      * @param parentComponent  the parent Component for the internal frame
  1025.      * @param title    the String to display in the frame's title bar
  1026.      * @return a JInternalFrame containing a JOptionPane
  1027.      */
  1028.     public JInternalFrame createInternalFrame(Component parentComponent,
  1029.                                  String title) {
  1030.         Container          parent = JOptionPane.
  1031.                                     getDesktopPaneForComponent(parentComponent);
  1032.  
  1033.         if(parent == null && (parentComponent == null || 
  1034.                               (parent = parentComponent.getParent()) == null))
  1035.             throw new RuntimeException("JOptionPane: parentComponent does not have a valid parent");
  1036.  
  1037.         final JInternalFrame  iFrame = new JInternalFrame(title, false, false,
  1038.                                                            false, false);
  1039.         addPropertyChangeListener(new PropertyChangeListener() {
  1040.             public void propertyChange(PropertyChangeEvent event) {
  1041.                 if(iFrame.isVisible() && event.getSource() == JOptionPane.this &&
  1042.                    (event.getPropertyName().equals(VALUE_PROPERTY) ||
  1043.                     event.getPropertyName().equals(INPUT_VALUE_PROPERTY))) {
  1044.                     try {
  1045.                         iFrame.setClosed(true);
  1046.                     } catch (java.beans.PropertyVetoException e) {}
  1047.                     iFrame.setVisible(false);
  1048.                     iFrame.stopModal();
  1049.                 }
  1050.             }
  1051.         });
  1052.         iFrame.getContentPane().add(this, BorderLayout.CENTER);
  1053.  
  1054.         if(parent instanceof JDesktopPane) {
  1055.             parent.add(iFrame, JLayeredPane.MODAL_LAYER);
  1056.         } else {
  1057.             parent.add(iFrame, BorderLayout.CENTER);
  1058.         }
  1059.  
  1060.         Dimension            iFrameSize = iFrame.getPreferredSize();
  1061.         Dimension            rootSize = parent.getSize();
  1062.  
  1063.         iFrame.setBounds((rootSize.width - iFrameSize.width) / 2,
  1064.                          (rootSize.height - iFrameSize.height) / 2,
  1065.                          iFrameSize.width, iFrameSize.height);
  1066.         parent.validate();
  1067.         try {
  1068.             iFrame.setSelected(true);
  1069.         } catch (java.beans.PropertyVetoException e) {}
  1070.         return iFrame;
  1071.     }
  1072.  
  1073.     /**
  1074.      * Returns the specified component's Frame.
  1075.      * 
  1076.      * @param parentComponent the Component to check for a Frame
  1077.      * @return the Frame that contains the component, or the default
  1078.      *         frame if the component is null, or does not have a valid 
  1079.      *         Frame parent
  1080.      */
  1081.     public static Frame getFrameForComponent(Component parentComponent) {
  1082.         if (parentComponent == null)
  1083.             return getRootFrame();
  1084.         if (parentComponent instanceof Frame)
  1085.             return (Frame)parentComponent;
  1086.         return JOptionPane.getFrameForComponent(parentComponent.getParent());
  1087.     }
  1088.  
  1089.     /**
  1090.      * Returns the specified component's desktop pane.
  1091.      * 
  1092.      * @param parentComponent the Component to check for a desktop
  1093.      * @return the JDesktopPane that contains the component, or null
  1094.      *         if the component is null or does not have an ancestor 
  1095.      *         that is a JInternalFrame
  1096.      */
  1097.     public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) {
  1098.         if(parentComponent == null)
  1099.             return null;
  1100.         if(parentComponent instanceof JDesktopPane)
  1101.             return (JDesktopPane)parentComponent;
  1102.         return getDesktopPaneForComponent(parentComponent.getParent());
  1103.     }
  1104.  
  1105.     private static final Object sharedFrameKey = JOptionPane.class;
  1106.  
  1107.     /**
  1108.      * Sets the frame to use for class methods in which a frame is
  1109.      * not provided.
  1110.      *
  1111.      * @param newRootFrame the default Frame to use
  1112.      */
  1113.     public static void setRootFrame(Frame newRootFrame) {
  1114.         if (newRootFrame != null) {
  1115.             SwingUtilities.appContextPut(sharedFrameKey, newRootFrame);
  1116.         } else {
  1117.             SwingUtilities.appContextRemove(sharedFrameKey);
  1118.         }
  1119.     }
  1120.  
  1121.     /**
  1122.      * Returns the Frame to use for the class methods in which a frame
  1123.      * is not provided.
  1124.      *
  1125.      * @return the default Frame to use
  1126.      */
  1127.     public static Frame getRootFrame() {
  1128.         Frame sharedFrame = 
  1129.             (Frame)SwingUtilities.appContextGet(sharedFrameKey);
  1130.         if (sharedFrame == null) {
  1131.             sharedFrame = SwingUtilities.getSharedOwnerFrame();
  1132.             SwingUtilities.appContextPut(sharedFrameKey, sharedFrame);
  1133.         }
  1134.         return sharedFrame;
  1135.     }
  1136.  
  1137.     /**
  1138.      * Creates a JOptionPane with a test message.
  1139.      */
  1140.     public JOptionPane() {
  1141.         this("JOptionPane message");
  1142.     }
  1143.  
  1144.     /**
  1145.      * Creates a instance of JOptionPane to display a message using the 
  1146.      * plain-message message type and the default options delivered by
  1147.      * the UI.
  1148.      *
  1149.      * @param message the Object to display
  1150.      */
  1151.     public JOptionPane(Object message) {
  1152.         this(message, PLAIN_MESSAGE);
  1153.     }
  1154.  
  1155.     /**
  1156.      * Creates an instance of JOptionPane to display a message
  1157.      * with the specified message type and the default options,
  1158.      *
  1159.      * @param message the Object to display
  1160.      * @param messageType the type of message to be displayed:
  1161.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1162.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  1163.      */
  1164.     public JOptionPane(Object message, int messageType) {
  1165.         this(message, messageType, DEFAULT_OPTION);
  1166.     }
  1167.  
  1168.     /**
  1169.      * Creates an instance of JOptionPane to display a message
  1170.      * with the specified message type and options.
  1171.      *
  1172.      * @param message the Object to display
  1173.      * @param messageType the type of message to be displayed:
  1174.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1175.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  1176.      * @param optionType the options to display in the pane:
  1177.      *                   DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION
  1178.      *                   OK_CANCEL_OPTION
  1179.      */
  1180.     public JOptionPane(Object message, int messageType, int optionType) {
  1181.         this(message, messageType, optionType, null);
  1182.     }
  1183.  
  1184.     /**
  1185.      * Creates an instance of JOptionPane to display a message
  1186.      * with the specified message type, options, and icon.
  1187.      *
  1188.      * @param message the Object to display
  1189.      * @param messageType the type of message to be displayed:
  1190.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1191.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  1192.      * @param optionType the options to display in the pane:
  1193.      *                   DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION
  1194.      *                   OK_CANCEL_OPTION
  1195.      * @param icon the Icon image to display
  1196.      */
  1197.     public JOptionPane(Object message, int messageType, int optionType,
  1198.                        Icon icon) {
  1199.         this(message, messageType, optionType, icon, null);
  1200.     }
  1201.  
  1202.     /**
  1203.      * Creates an instance of JOptionPane to display a message
  1204.      * with the specified message type, icon, and options.
  1205.      * None of the options is initially selected.
  1206.      * <p>
  1207.      * The options objects should contain either instances of Components,
  1208.      * (which are added directly) or Strings (which are wrapped in a 
  1209.      * JButton). If you provide Components, you must ensure that when the
  1210.      * Component is clicked it messages <code>setValue</code> in the
  1211.      * created JOptionPane.
  1212.      *
  1213.      * @param message the Object to display
  1214.      * @param messageType the type of message to be displayed:
  1215.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1216.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  1217.      * @param optionType the options to display in the pane:
  1218.      *                   DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION
  1219.      *                   OK_CANCEL_OPTION. Only meaningful if the 
  1220.      *                   <code>options</code> parameter is null.
  1221.      * @param icon the Icon image to display
  1222.      * @param options  the choices the user can select
  1223.      */
  1224.     public JOptionPane(Object message, int messageType, int optionType,
  1225.                        Icon icon, Object[] options) {
  1226.         this(message, messageType, optionType, icon, options, null);
  1227.     }
  1228.  
  1229.     /**
  1230.      * Creates an instance of JOptionPane to display a message
  1231.      * with the specified message type, icon, and options, with the 
  1232.      * inititially-selected option specified.
  1233.      *
  1234.      * @param message the Object to display
  1235.      * @param messageType the type of message to be displayed:
  1236.      *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1237.      *                    QUESTION_MESSAGE, or PLAIN_MESSAGE.
  1238.      * @param optionType the options to display in the pane:
  1239.      *                   DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION
  1240.      *                   OK_CANCEL_OPTION. Only meaningful if the
  1241.      *                   <code>options</code> parameter is null.
  1242.      * @param icon the Icon image to display
  1243.      * @param options  the choices the user can select
  1244.      * @param initialValue the choice that is initially selected
  1245.      */
  1246.     public JOptionPane(Object message, int messageType, int optionType,
  1247.                        Icon icon, Object[] options, Object initialValue) {
  1248.         this.message = message;
  1249.         this.options = options;
  1250.         this.initialValue = initialValue;
  1251.         this.icon = icon;
  1252.         setMessageType(messageType);
  1253.         setOptionType(optionType);
  1254.         value = UNINITIALIZED_VALUE;
  1255.         inputValue = UNINITIALIZED_VALUE;
  1256.         updateUI();
  1257.     }
  1258.  
  1259.     /**
  1260.      * Sets the UI object which implements the L&F for this component.
  1261.      *
  1262.      * @param ui  the OptionPaneUI L&F object
  1263.      * @see UIDefaults#getUI
  1264.      * @beaninfo
  1265.      *       bound: true
  1266.      *      hidden: true
  1267.      * description: The UI object that implements the optionpane's LookAndFeel
  1268.      */
  1269.     public void setUI(OptionPaneUI ui) {
  1270.         if ((OptionPaneUI)this.ui != ui) {
  1271.             super.setUI(ui);
  1272.             invalidate();
  1273.         }
  1274.     }
  1275.  
  1276.     /**
  1277.      * Returns the UI object which implements the L&F for this component.
  1278.      *
  1279.      * @return the OptionPaneUI object
  1280.      */
  1281.     public OptionPaneUI getUI() {
  1282.         return (OptionPaneUI)ui;
  1283.     }
  1284.  
  1285.     /**
  1286.      * Notification from the UIManager that the L&F has changed. 
  1287.      * Replaces the current UI object with the latest version from the 
  1288.      * UIManager.
  1289.      *
  1290.      * @see JComponent#updateUI
  1291.      */
  1292.     public void updateUI() {
  1293.         setUI((OptionPaneUI)UIManager.getUI(this));
  1294.     }
  1295.  
  1296.  
  1297.     /**
  1298.      * Returns the name of the UI class that implements the
  1299.      * L&F for this component.
  1300.      *
  1301.      * @return "OptionPaneUI"
  1302.      * @see JComponent#getUIClassID
  1303.      * @see UIDefaults#getUI
  1304.      */
  1305.     public String getUIClassID() {
  1306.         return "OptionPaneUI";
  1307.     }
  1308.  
  1309.  
  1310.     /**
  1311.      * Sets the option pane's message-object.
  1312.      * @param newMessage the Object to display
  1313.      * @see #getMessage
  1314.      *
  1315.      * @beaninfo
  1316.      *   preferred: true
  1317.      *   bound: true
  1318.      * description: The optionpane's message object.
  1319.      */
  1320.     public void setMessage(Object newMessage) {
  1321.         Object           oldMessage = message;
  1322.  
  1323.         message = newMessage;
  1324.         firePropertyChange(MESSAGE_PROPERTY, oldMessage, message);
  1325.     }
  1326.  
  1327.     /**
  1328.      * Returns the message-object this pane displays.
  1329.      * @see #setMessage
  1330.      *
  1331.      * @return the Object that is displayed
  1332.      */
  1333.     public Object getMessage() {
  1334.         return message;
  1335.     }
  1336.  
  1337.     /**
  1338.      * Sets the icon to display. If non-null, the look and feel 
  1339.      * does not provide an icon.
  1340.      * @param icon the Icon to display
  1341.      *
  1342.      * @see #getIcon
  1343.      * @beaninfo
  1344.      *   preferred: true
  1345.      *       bound: true
  1346.      * description: The option pane's type icon.
  1347.      */
  1348.     public void setIcon(Icon newIcon) {
  1349.         Object              oldIcon = icon;
  1350.  
  1351.         icon = newIcon;
  1352.         firePropertyChange(ICON_PROPERTY, oldIcon, icon);
  1353.     }
  1354.  
  1355.     /**
  1356.      * Returns the icon this pane displays.
  1357.      * @return the Icon that is displayed
  1358.      *
  1359.      * @see #setIcon
  1360.      */
  1361.     public Icon getIcon() {
  1362.         return icon;
  1363.     }
  1364.  
  1365.     /**
  1366.      * Sets the value the user has chosen. 
  1367.      * @param newValue  the chosen value
  1368.      *
  1369.      * @see #getValue
  1370.      * @beaninfo
  1371.      *   preferred: true
  1372.      *       bound: true
  1373.      * description: The option pane's value object.
  1374.      */
  1375.     public void setValue(Object newValue) {
  1376.         Object               oldValue = value;
  1377.  
  1378.         value = newValue;
  1379.         firePropertyChange(VALUE_PROPERTY, oldValue, value);
  1380.     }
  1381.  
  1382.     /**
  1383.      * Returns the value the user has selected. UNINITIALIZED_VALUE
  1384.      * implies the user has not yet made a choice, null means the
  1385.      * user closed the window with out chosing anything. Otherwise
  1386.      * the returned value will be one of the options defined in this
  1387.      * object.
  1388.      *
  1389.      * @return the Object chosen by the user, UNINITIALIZED_VALUE
  1390.      *         if the user has not yet made a choice, or null if
  1391.      *         the user closed the window without making a choice.
  1392.      *
  1393.      * @see #setValue
  1394.      */
  1395.     public Object getValue() {
  1396.         return value;
  1397.     }
  1398.  
  1399.     /**
  1400.      * Sets the options this pane displays. If an element in
  1401.      * newOptions is a Comonent it is added directly to the pane,
  1402.      * Otherwise a button is created for the element.
  1403.      * @param newOptions an array of Objects that create the buttons
  1404.      *        the user can click on, or arbitrary Components to add
  1405.      *        to the pane
  1406.      *
  1407.      * @see #getOptions
  1408.      * @beaninfo
  1409.      *       bound: true
  1410.      * description: The option pane's options objects.
  1411.      */
  1412.     public void setOptions(Object[] newOptions) {
  1413.         Object[]           oldOptions = options;
  1414.  
  1415.         options = newOptions;
  1416.         firePropertyChange(OPTIONS_PROPERTY, oldOptions, options);
  1417.     }
  1418.  
  1419.     /**
  1420.      * Returns the choices the user can make.
  1421.      * @param the array of Objects that give the user's choices
  1422.      *
  1423.      * @see #setOptions
  1424.      */
  1425.     public Object[] getOptions() {
  1426.         if(options != null) {
  1427.             int             optionCount = options.length;
  1428.             Object[]        retOptions = new Object[optionCount];
  1429.  
  1430.             System.arraycopy(options, 0, retOptions, 0, optionCount);
  1431.             return retOptions;
  1432.         }
  1433.         return options;
  1434.     }
  1435.  
  1436.     /**
  1437.      * Sets the initial value that is to be enabled -- the Component
  1438.      * that has the focus when the pane is initially displayed.
  1439.      *
  1440.      * @param newInitialValue the Object that gets the initial 
  1441.      *                         keyboard focus
  1442.      *
  1443.      * @see #getInitialValue
  1444.      * @beaninfo
  1445.      *   preferred: true
  1446.      *       bound: true
  1447.      * description: The option pane's initial value object.
  1448.      */
  1449.     public void setInitialValue(Object newInitialValue) {
  1450.         Object            oldIV = initialValue;
  1451.  
  1452.         initialValue = newInitialValue;
  1453.         firePropertyChange(INITIAL_VALUE_PROPERTY, oldIV, initialValue);
  1454.     }
  1455.  
  1456.     /**
  1457.      * Returns the initial value.
  1458.      *
  1459.      * @return the Object that gets the initial keyboard focus
  1460.      *
  1461.      * @see #setInitialValue
  1462.      */
  1463.     public Object getInitialValue() {
  1464.         return initialValue;
  1465.     }
  1466.  
  1467.     /**
  1468.      * Sets the option pane's message type.
  1469.      * The message type is used by the look and feel to determine the
  1470.      * icon to display (if not supplied) as well as potentially how to
  1471.      * lay out the parentComponent.
  1472.      * @param newType an int specifying the kind of message to display:
  1473.      *                ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
  1474.      *                QUESTION_MESSAGE, or PLAIN_MESSAGE. Otherwise, 
  1475.      *                a RuntimeEception is thrown.
  1476.  
  1477.      * @see #getMessageType
  1478.      * @beaninfo
  1479.      *   preferred: true
  1480.      *       bound: true
  1481.      * description: The option pane's message type.
  1482.      */
  1483.     public void setMessageType(int newType) {
  1484.         if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
  1485.            newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
  1486.            newType != PLAIN_MESSAGE)
  1487.             throw new RuntimeException("JOptionPane: type must be one of JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE or JOptionPane.PLAIN_MESSAGE");
  1488.  
  1489.         int           oldType = messageType;
  1490.  
  1491.         messageType = newType;
  1492.         firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
  1493.     }
  1494.  
  1495.     /**
  1496.      * Returns the message type.
  1497.      *
  1498.      * @return an int specifying the message type
  1499.      *
  1500.      * @see #setMessageType
  1501.      */
  1502.     public int getMessageType() {
  1503.         return messageType;
  1504.     }
  1505.  
  1506.     /**
  1507.      * Sets the options to display. 
  1508.      * The option type is used by the look and feel to
  1509.      * determine what buttons to show (unless options are supplied).
  1510.      * @param newType an int specifying the options the L&F is to display:
  1511.      *                DEFAULT_OPTION, YES_NO_OPTION, YES_NO_CANCEL_OPTION,
  1512.      *                or OK_CANCEL_OPTION. Otherwise, a RuntimeException
  1513.      *                is thrown.
  1514.      *
  1515.      * @see #getOptionType
  1516.      * @see #setOptions
  1517.      * @beaninfo
  1518.      *   preferred: true
  1519.      *       bound: true
  1520.      * description: The option pane's option type.
  1521.       */
  1522.     public void setOptionType(int newType) {
  1523.         if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION &&
  1524.            newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION)
  1525.             throw new RuntimeException("JOptionPane: option type must be one of JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION or JOptionPane.OK_CANCEL_OPTION");
  1526.  
  1527.         int            oldType = optionType;
  1528.  
  1529.         optionType = newType;
  1530.         firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
  1531.     }
  1532.  
  1533.     /**
  1534.      * Returns the type of options that are displayed.
  1535.      *
  1536.      * @return an int specifying the user-selectable options
  1537.      *
  1538.      * @see #setOptionType
  1539.      */
  1540.     public int getOptionType() {
  1541.         return optionType;
  1542.     }
  1543.  
  1544.     /** 
  1545.      * Sets the selection values for a pane that provides the user
  1546.      * with a list of items to choose from. (The UI provides a widget 
  1547.      * for choosing one of the values.) 
  1548.      * <p>
  1549.      * Sets <code>wantsInput</code> to true. Use
  1550.      * <code>setInitialSelectionValue</code> to specify the initially-chosen
  1551.      * value. After the pane as been enabled, inputValue is 
  1552.      * set to the value the user has selected.
  1553.      * @param newValues an array of Objects the user to be displayed
  1554.      *                  (usually in a list or combo-box) from which
  1555.      *                  the user can make a selection
  1556.      * @see #setWantsInput
  1557.      * @see #setInitialSelectionValue
  1558.      * @see #getSelectionValues
  1559.      * @beaninfo
  1560.      *       bound: true
  1561.      * description: The option pane's selection values.
  1562.      */
  1563.     public void setSelectionValues(Object[] newValues) {
  1564.         Object[]           oldValues = selectionValues;
  1565.  
  1566.         selectionValues = newValues;
  1567.         firePropertyChange(SELECTION_VALUES_PROPERTY, oldValues, newValues);
  1568.         if(selectionValues != null)
  1569.             setWantsInput(true);
  1570.     }
  1571.  
  1572.     /**
  1573.      * Returns the selection values.
  1574.      *
  1575.      * @param return the array of Objects the user can select
  1576.      * @see #setSelectionValues
  1577.      */
  1578.     public Object[] getSelectionValues() {
  1579.         return selectionValues;
  1580.     }
  1581.  
  1582.     /**
  1583.      * Sets the initial selection value. Only used if <code>wantsInput</code>
  1584.      * is true.
  1585.      * @param newValue the initially selected value
  1586.      * @see #setSelectionValues
  1587.      * @see #getInitialSelectionValue
  1588.      * @beaninfo
  1589.      *       bound: true
  1590.      * description: The option pane's initial selection value object.
  1591.      */
  1592.     public void setInitialSelectionValue(Object newValue) {
  1593.         Object          oldValue = initialSelectionValue;
  1594.  
  1595.         initialSelectionValue = newValue;
  1596.         firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, oldValue,
  1597.                            newValue);
  1598.     }
  1599.  
  1600.     /**
  1601.      * Returns the initial-selection value..
  1602.      *
  1603.      * @return the initially selected value
  1604.      * @see #setInitialSelectionValue
  1605.      * @see #setSelectionValues
  1606.      */
  1607.     public Object getInitialSelectionValue() {
  1608.         return initialSelectionValue;
  1609.     }
  1610.  
  1611.     /**
  1612.      * Sets the user's input-value.
  1613.      *
  1614.      * @param newValue the Object used to initialized the value that
  1615.      *        the user specified (usually in a text field)
  1616.      * @see #setSelectionValues
  1617.      * @see #setWantsInput
  1618.      * @see #getInputValue
  1619.      * @beaninfo
  1620.      *   preferred: true
  1621.      *       bound: true
  1622.      * description: The option pane's input value object.
  1623.      */
  1624.     public void setInputValue(Object newValue) {
  1625.         Object              oldValue = inputValue;
  1626.  
  1627.         inputValue = newValue;
  1628.         firePropertyChange(INPUT_VALUE_PROPERTY, oldValue, newValue);
  1629.     }
  1630.  
  1631.     /**
  1632.      * Returns the value the user has input, if <code>wantsInput</code>
  1633.      * is true.
  1634.      *
  1635.      * @return the Object the user specified, if it was one of the
  1636.      *         objects, or a String if it was a value typed into a
  1637.      *         field.
  1638.      * @see #setSelectionValues
  1639.      * @see #setWantsInput
  1640.      * @see #setInputValue
  1641.      */
  1642.     public Object getInputValue() {
  1643.         return inputValue;
  1644.     }
  1645.  
  1646.     /**
  1647.      * Returns the maximum number of characters to place on a line in a
  1648.      * message. Default is to return Integer.MAX_VALUE. The value can be 
  1649.      * changed by overriding this method in a subclasse.
  1650.      *
  1651.      * @return an int giving the maximum number of characters on a line
  1652.      */
  1653.     public int getMaxCharactersPerLineCount() {
  1654.         return Integer.MAX_VALUE;
  1655.     }
  1656.  
  1657.     /**
  1658.      * If <code>newValue</code> is true, a parentComponent is provided to
  1659.      * allow the user to input a value. If <code>getSelectionValues</code>
  1660.      * returns a non-null the input value is one of the objects in that 
  1661.      * array. Otherwise the input value is whatever the user inputs.
  1662.      * <p>
  1663.      * This is a bound property.
  1664.      *
  1665.      * @see #setSelectionValues
  1666.      * @see #setInputValue
  1667.      */
  1668.     public void setWantsInput(boolean newValue) {
  1669.         boolean            oldValue = wantsInput;
  1670.  
  1671.         wantsInput = newValue;
  1672.         firePropertyChange(WANTS_INPUT_PROPERTY, oldValue, newValue);
  1673.     }
  1674.  
  1675.     /**
  1676.      * Returns true if a parentComponent will be provided for the user to
  1677.      * input.
  1678.      *
  1679.      * @return true if a parentComponent will be provided
  1680.      * @see #setWantsInput
  1681.      */
  1682.     public boolean getWantsInput() {
  1683.         return wantsInput;
  1684.     }
  1685.  
  1686.     /**
  1687.      * Requests that the initial value be selected, which will set
  1688.      * focus to the initial value. This method
  1689.      * should be invoked after the window containing the option pane
  1690.      * is made visible.
  1691.      */
  1692.     public void selectInitialValue() {
  1693.         OptionPaneUI         ui = getUI();
  1694.  
  1695.         if(ui != null)
  1696.             ui.selectInitialValue();
  1697.     }
  1698.  
  1699.     
  1700.     // Serialization support.  
  1701.     private void writeObject(ObjectOutputStream s) throws IOException {
  1702.         Vector      values = new Vector();
  1703.  
  1704.         s.defaultWriteObject();
  1705.         // Save the icon, if its Serializable.
  1706.         if(icon != null && icon instanceof Serializable) {
  1707.             values.addElement("icon");
  1708.             values.addElement(icon);
  1709.         }
  1710.         // Save the message, if its Serializable.
  1711.         if(message != null && message instanceof Serializable) {
  1712.             values.addElement("message");
  1713.             values.addElement(message);
  1714.         }
  1715.         // Save the treeModel, if its Serializable.
  1716.         if(options != null) {
  1717.             Vector           serOptions = new Vector();
  1718.  
  1719.             for(int counter = 0, maxCounter = options.length;
  1720.                 counter < maxCounter; counter++)
  1721.                 if(options[counter] instanceof Serializable)
  1722.                     serOptions.addElement(options[counter]);
  1723.             if(serOptions.size() > 0) {
  1724.                 int             optionCount = serOptions.size();
  1725.                 Object[]        arrayOptions = new Object[optionCount];
  1726.  
  1727.                 serOptions.copyInto(arrayOptions);
  1728.                 values.addElement("options");
  1729.                 values.addElement(arrayOptions);
  1730.             }
  1731.         }
  1732.         // Save the initialValue, if its Serializable.
  1733.         if(initialValue != null && initialValue instanceof Serializable) {
  1734.             values.addElement("initialValue");
  1735.             values.addElement(initialValue);
  1736.         }
  1737.         // Save the value, if its Serializable.
  1738.         if(value != null && value instanceof Serializable) {
  1739.             values.addElement("value");
  1740.             values.addElement(value);
  1741.         }
  1742.         // Save the selectionValues, if its Serializable.
  1743.         if(selectionValues != null) {
  1744.             boolean            serialize = true;
  1745.  
  1746.             for(int counter = 0, maxCounter = selectionValues.length;
  1747.                 counter < maxCounter; counter++) {
  1748.                 if(selectionValues[counter] != null &&
  1749.                    !(selectionValues[counter] instanceof Serializable)) {
  1750.                     serialize = false;
  1751.                     break;
  1752.                 }
  1753.             }
  1754.             if(serialize) {
  1755.                 values.addElement("selectionValues");
  1756.                 values.addElement(selectionValues);
  1757.             }
  1758.         }
  1759.         // Save the inputValue, if its Serializable.
  1760.         if(inputValue != null && inputValue instanceof Serializable) {
  1761.             values.addElement("inputValue");
  1762.             values.addElement(inputValue);
  1763.         }
  1764.         // Save the initialSelectionValue, if its Serializable.
  1765.         if(initialSelectionValue != null &&
  1766.            initialSelectionValue instanceof Serializable) {
  1767.             values.addElement("initialSelectionValue");
  1768.             values.addElement(initialSelectionValue);
  1769.         }
  1770.         s.writeObject(values);
  1771.     }
  1772.  
  1773.     private void readObject(ObjectInputStream s) 
  1774.         throws IOException, ClassNotFoundException {
  1775.         s.defaultReadObject();
  1776.  
  1777.         Vector          values = (Vector)s.readObject();
  1778.         int             indexCounter = 0;
  1779.         int             maxCounter = values.size();
  1780.  
  1781.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1782.            equals("icon")) {
  1783.             icon = (Icon)values.elementAt(++indexCounter);
  1784.             indexCounter++;
  1785.         }
  1786.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1787.            equals("message")) {
  1788.             message = values.elementAt(++indexCounter);
  1789.             indexCounter++;
  1790.         }
  1791.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1792.            equals("options")) {
  1793.             options = (Object[])values.elementAt(++indexCounter);
  1794.             indexCounter++;
  1795.         }
  1796.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1797.            equals("initialValue")) {
  1798.             initialValue = values.elementAt(++indexCounter);
  1799.             indexCounter++;
  1800.         }
  1801.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1802.            equals("value")) {
  1803.             value = values.elementAt(++indexCounter);
  1804.             indexCounter++;
  1805.         }
  1806.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1807.            equals("selectionValues")) {
  1808.             selectionValues = (Object[])values.elementAt(++indexCounter);
  1809.             indexCounter++;
  1810.         }
  1811.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1812.            equals("inputValue")) {
  1813.             inputValue = values.elementAt(++indexCounter);
  1814.             indexCounter++;
  1815.         }
  1816.         if(indexCounter < maxCounter && values.elementAt(indexCounter).
  1817.            equals("initialSelectionValue")) {
  1818.             initialSelectionValue = values.elementAt(++indexCounter);
  1819.             indexCounter++;
  1820.         }
  1821.     }
  1822.  
  1823. }
  1824.