0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport java.awt.BorderLayout;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Container;
0N/Aimport java.awt.Dialog;
0N/Aimport java.awt.Dimension;
0N/Aimport java.awt.KeyboardFocusManager;
0N/Aimport java.awt.Frame;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.HeadlessException;
0N/Aimport java.awt.Window;
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.awt.event.WindowListener;
0N/Aimport java.awt.event.WindowAdapter;
0N/Aimport java.awt.event.WindowEvent;
0N/Aimport java.awt.event.ComponentAdapter;
0N/Aimport java.awt.event.ComponentEvent;
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.Serializable;
0N/Aimport java.lang.reflect.Method;
0N/Aimport java.lang.reflect.InvocationTargetException;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport java.util.Vector;
0N/Aimport javax.swing.plaf.OptionPaneUI;
0N/Aimport javax.swing.event.InternalFrameEvent;
0N/Aimport javax.swing.event.InternalFrameAdapter;
0N/Aimport javax.accessibility.*;
0N/Aimport static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
0N/A
0N/A/**
0N/A * <code>JOptionPane</code> makes it easy to pop up a standard dialog box that
0N/A * prompts users for a value or informs them of something.
0N/A * For information about using <code>JOptionPane</code>, see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html">How to Make Dialogs</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * <p>
0N/A *
0N/A * While the <code>JOptionPane</code>
0N/A * class may appear complex because of the large number of methods, almost
0N/A * all uses of this class are one-line calls to one of the static
0N/A * <code>showXxxDialog</code> methods shown below:
0N/A * <blockquote>
0N/A *
0N/A *
0N/A * <table border=1 summary="Common JOptionPane method names and their descriptions">
0N/A * <tr>
0N/A * <th>Method Name</th>
0N/A * <th>Description</th>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>showConfirmDialog</td>
0N/A * <td>Asks a confirming question, like yes/no/cancel.</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>showInputDialog</td>
0N/A * <td>Prompt for some input.</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>showMessageDialog</td>
0N/A * <td>Tell the user about something that has happened.</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td>showOptionDialog</td>
0N/A * <td>The Grand Unification of the above three.</td>
0N/A * </tr>
0N/A * </table>
0N/A *
0N/A * </blockquote>
0N/A * Each of these methods also comes in a <code>showInternalXXX</code>
0N/A * flavor, which uses an internal frame to hold the dialog box (see
0N/A * {@link JInternalFrame}).
0N/A * Multiple convenience methods have also been defined -- overloaded
0N/A * versions of the basic methods that use different parameter lists.
0N/A * <p>
0N/A * All dialogs are modal. Each <code>showXxxDialog</code> method blocks
0N/A * the caller until the user's interaction is complete.
0N/A * <p>
0N/A *
0N/A * <table cellspacing=6 cellpadding=4 border=0 align=right summary="layout">
0N/A * <tr>
0N/A * <td bgcolor=#FFe0d0 rowspan=2>icon</td>
0N/A * <td bgcolor=#FFe0d0>message</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td bgcolor=#FFe0d0>input value</td>
0N/A * </tr>
0N/A * <tr>
0N/A * <td bgcolor=#FFe0d0 colspan=2>option buttons</td>
0N/A * </tr>
0N/A * </table>
0N/A *
0N/A * The basic appearance of one of these dialog boxes is generally
0N/A * similar to the picture at the right, although the various
0N/A * look-and-feels are
0N/A * ultimately responsible for the final result. In particular, the
0N/A * look-and-feels will adjust the layout to accommodate the option pane's
0N/A * <code>ComponentOrientation</code> property.
0N/A * <br clear=all>
0N/A * <p>
0N/A * <b>Parameters:</b><br>
0N/A * The parameters to these methods follow consistent patterns:
0N/A * <blockquote>
0N/A * <dl compact>
0N/A * <dt>parentComponent<dd>
0N/A * Defines the <code>Component</code> that is to be the parent of this
0N/A * dialog box.
0N/A * It is used in two ways: the <code>Frame</code> that contains
0N/A * it is used as the <code>Frame</code>
0N/A * parent for the dialog box, and its screen coordinates are used in
0N/A * the placement of the dialog box. In general, the dialog box is placed
0N/A * just below the component. This parameter may be <code>null</code>,
0N/A * in which case a default <code>Frame</code> is used as the parent,
0N/A * and the dialog will be
0N/A * centered on the screen (depending on the L&F).
0N/A * <dt><a name=message>message</a><dd>
0N/A * A descriptive message to be placed in the dialog box.
0N/A * In the most common usage, message is just a <code>String</code> or
0N/A * <code>String</code> constant.
0N/A * However, the type of this parameter is actually <code>Object</code>. Its
0N/A * interpretation depends on its type:
0N/A * <dl compact>
0N/A * <dt>Object[]<dd>An array of objects is interpreted as a series of
0N/A * messages (one per object) arranged in a vertical stack.
0N/A * The interpretation is recursive -- each object in the
0N/A * array is interpreted according to its type.
0N/A * <dt>Component<dd>The <code>Component</code> is displayed in the dialog.
0N/A * <dt>Icon<dd>The <code>Icon</code> is wrapped in a <code>JLabel</code>
0N/A * and displayed in the dialog.
0N/A * <dt>others<dd>The object is converted to a <code>String</code> by calling
0N/A * its <code>toString</code> method. The result is wrapped in a
0N/A * <code>JLabel</code> and displayed.
0N/A * </dl>
0N/A * <dt>messageType<dd>Defines the style of the message. The Look and Feel
0N/A * manager may lay out the dialog differently depending on this value, and
0N/A * will often provide a default icon. The possible values are:
0N/A * <ul>
0N/A * <li><code>ERROR_MESSAGE</code>
0N/A * <li><code>INFORMATION_MESSAGE</code>
0N/A * <li><code>WARNING_MESSAGE</code>
0N/A * <li><code>QUESTION_MESSAGE</code>
0N/A * <li><code>PLAIN_MESSAGE</code>
0N/A * </ul>
0N/A * <dt>optionType<dd>Defines the set of option buttons that appear at
0N/A * the bottom of the dialog box:
0N/A * <ul>
0N/A * <li><code>DEFAULT_OPTION</code>
0N/A * <li><code>YES_NO_OPTION</code>
0N/A * <li><code>YES_NO_CANCEL_OPTION</code>
0N/A * <li><code>OK_CANCEL_OPTION</code>
0N/A * </ul>
0N/A * You aren't limited to this set of option buttons. You can provide any
0N/A * buttons you want using the options parameter.
0N/A * <dt>options<dd>A more detailed description of the set of option buttons
0N/A * that will appear at the bottom of the dialog box.
0N/A * The usual value for the options parameter is an array of
0N/A * <code>String</code>s. But
0N/A * the parameter type is an array of <code>Objects</code>.
0N/A * A button is created for each object depending on its type:
0N/A * <dl compact>
0N/A * <dt>Component<dd>The component is added to the button row directly.
0N/A * <dt>Icon<dd>A <code>JButton</code> is created with this as its label.
0N/A * <dt>other<dd>The <code>Object</code> is converted to a string using its
0N/A * <code>toString</code> method and the result is used to
0N/A * label a <code>JButton</code>.
0N/A * </dl>
0N/A * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
0N/A * value for this is determined by the <code>messageType</code> parameter.
0N/A * <dt>title<dd>The title for the dialog box.
0N/A * <dt>initialValue<dd>The default selection (input value).
0N/A * </dl>
0N/A * </blockquote>
0N/A * <p>
0N/A * When the selection is changed, <code>setValue</code> is invoked,
0N/A * which generates a <code>PropertyChangeEvent</code>.
0N/A * <p>
0N/A * If a <code>JOptionPane</code> has configured to all input
0N/A * <code>setWantsInput</code>
0N/A * the bound property <code>JOptionPane.INPUT_VALUE_PROPERTY</code>
0N/A * can also be listened
0N/A * to, to determine when the user has input or selected a value.
0N/A * <p>
0N/A * When one of the <code>showXxxDialog</code> methods returns an integer,
0N/A * the possible values are:
0N/A * <ul>
0N/A * <li><code>YES_OPTION</code>
0N/A * <li><code>NO_OPTION</code>
0N/A * <li><code>CANCEL_OPTION</code>
0N/A * <li><code>OK_OPTION</code>
0N/A * <li><code>CLOSED_OPTION</code>
0N/A * </ul>
0N/A * <b>Examples:</b>
0N/A * <dl>
0N/A * <dt>Show an error dialog that displays the message, 'alert':
0N/A * <dd><code>
0N/A * JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
0N/A * </code><p>
0N/A * <dt>Show an internal information dialog with the message, 'information':
0N/A * <dd><code>
0N/A * JOptionPane.showInternalMessageDialog(frame, "information",<br>
0N/A * <ul><ul>"information", JOptionPane.INFORMATION_MESSAGE);</ul></ul>
0N/A * </code><p>
0N/A * <dt>Show an information panel with the options yes/no and message 'choose one':
0N/A * <dd><code>JOptionPane.showConfirmDialog(null,
0N/A * <ul><ul>"choose one", "choose one", JOptionPane.YES_NO_OPTION);</ul></ul>
0N/A * </code><p>
0N/A * <dt>Show an internal information dialog with the options yes/no/cancel and
0N/A * message 'please choose one' and title information:
0N/A * <dd><code>JOptionPane.showInternalConfirmDialog(frame,
0N/A * <ul><ul>"please choose one", "information",</ul></ul>
0N/A * <ul><ul>JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);</ul></ul>
0N/A * </code><p>
0N/A * <dt>Show a warning dialog with the options OK, CANCEL, title 'Warning', and
0N/A * message 'Click OK to continue':
0N/A * <dd><code>
0N/A * Object[] options = { "OK", "CANCEL" };<br>
0N/A * JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
0N/A * <ul><ul>JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,</ul></ul>
0N/A * <ul><ul>null, options, options[0]);</ul></ul>
0N/A * </code><p>
0N/A * <dt>Show a dialog asking the user to type in a String:
0N/A * <dd><code>
0N/A * String inputValue = JOptionPane.showInputDialog("Please input a value");
0N/A * </code><p>
0N/A * <dt>Show a dialog asking the user to select a String:
0N/A * <dd><code>
0N/A * Object[] possibleValues = { "First", "Second", "Third" };<br>
0N/A * Object selectedValue = JOptionPane.showInputDialog(null,
0N/A * <ul><ul>"Choose one", "Input",</ul></ul>
0N/A * <ul><ul>JOptionPane.INFORMATION_MESSAGE, null,</ul></ul>
0N/A * <ul><ul>possibleValues, possibleValues[0]);</ul></ul>
0N/A * </code><p>
0N/A * </dl>
0N/A * <b>Direct Use:</b><br>
0N/A * To create and use an <code>JOptionPane</code> directly, the
0N/A * standard pattern is roughly as follows:
0N/A * <pre>
0N/A * JOptionPane pane = new JOptionPane(<i>arguments</i>);
0N/A * pane.set<i>.Xxxx(...); // Configure</i>
0N/A * JDialog dialog = pane.createDialog(<i>parentComponent, title</i>);
0N/A * dialog.show();
0N/A * Object selectedValue = pane.getValue();
0N/A * if(selectedValue == null)
0N/A * return CLOSED_OPTION;
0N/A * <i>//If there is <b>not</b> an array of option buttons:</i>
0N/A * if(options == null) {
0N/A * if(selectedValue instanceof Integer)
0N/A * return ((Integer)selectedValue).intValue();
0N/A * return CLOSED_OPTION;
0N/A * }
0N/A * <i>//If there is an array of option buttons:</i>
0N/A * for(int counter = 0, maxCounter = options.length;
0N/A * counter < maxCounter; counter++) {
0N/A * if(options[counter].equals(selectedValue))
0N/A * return counter;
0N/A * }
0N/A * return CLOSED_OPTION;
0N/A * </pre>
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @see JInternalFrame
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer true
0N/A * description: A component which implements standard dialog box controls.
0N/A *
0N/A * @author James Gosling
0N/A * @author Scott Violet
0N/A */
0N/Apublic class JOptionPane extends JComponent implements Accessible
0N/A{
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "OptionPaneUI";
0N/A
0N/A /**
0N/A * Indicates that the user has not yet selected a value.
0N/A */
0N/A public static final Object UNINITIALIZED_VALUE = "uninitializedValue";
0N/A
0N/A //
0N/A // Option types
0N/A //
0N/A
0N/A /**
0N/A * Type meaning Look and Feel should not supply any options -- only
0N/A * use the options from the <code>JOptionPane</code>.
0N/A */
0N/A public static final int DEFAULT_OPTION = -1;
0N/A /** Type used for <code>showConfirmDialog</code>. */
0N/A public static final int YES_NO_OPTION = 0;
0N/A /** Type used for <code>showConfirmDialog</code>. */
0N/A public static final int YES_NO_CANCEL_OPTION = 1;
0N/A /** Type used for <code>showConfirmDialog</code>. */
0N/A public static final int OK_CANCEL_OPTION = 2;
0N/A
0N/A //
0N/A // Return values.
0N/A //
0N/A /** Return value from class method if YES is chosen. */
0N/A public static final int YES_OPTION = 0;
0N/A /** Return value from class method if NO is chosen. */
0N/A public static final int NO_OPTION = 1;
0N/A /** Return value from class method if CANCEL is chosen. */
0N/A public static final int CANCEL_OPTION = 2;
0N/A /** Return value form class method if OK is chosen. */
0N/A public static final int OK_OPTION = 0;
0N/A /** Return value from class method if user closes window without selecting
0N/A * anything, more than likely this should be treated as either a
0N/A * <code>CANCEL_OPTION</code> or <code>NO_OPTION</code>. */
0N/A public static final int CLOSED_OPTION = -1;
0N/A
0N/A //
0N/A // Message types. Used by the UI to determine what icon to display,
0N/A // and possibly what behavior to give based on the type.
0N/A //
0N/A /** Used for error messages. */
0N/A public static final int ERROR_MESSAGE = 0;
0N/A /** Used for information messages. */
0N/A public static final int INFORMATION_MESSAGE = 1;
0N/A /** Used for warning messages. */
0N/A public static final int WARNING_MESSAGE = 2;
0N/A /** Used for questions. */
0N/A public static final int QUESTION_MESSAGE = 3;
0N/A /** No icon is used. */
0N/A public static final int PLAIN_MESSAGE = -1;
0N/A
0N/A /** Bound property name for <code>icon</code>. */
0N/A public static final String ICON_PROPERTY = "icon";
0N/A /** Bound property name for <code>message</code>. */
0N/A public static final String MESSAGE_PROPERTY = "message";
0N/A /** Bound property name for <code>value</code>. */
0N/A public static final String VALUE_PROPERTY = "value";
0N/A /** Bound property name for <code>option</code>. */
0N/A public static final String OPTIONS_PROPERTY = "options";
0N/A /** Bound property name for <code>initialValue</code>. */
0N/A public static final String INITIAL_VALUE_PROPERTY = "initialValue";
0N/A /** Bound property name for <code>type</code>. */
0N/A public static final String MESSAGE_TYPE_PROPERTY = "messageType";
0N/A /** Bound property name for <code>optionType</code>. */
0N/A public static final String OPTION_TYPE_PROPERTY = "optionType";
0N/A /** Bound property name for <code>selectionValues</code>. */
0N/A public static final String SELECTION_VALUES_PROPERTY = "selectionValues";
0N/A /** Bound property name for <code>initialSelectionValue</code>. */
0N/A public static final String INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
0N/A /** Bound property name for <code>inputValue</code>. */
0N/A public static final String INPUT_VALUE_PROPERTY = "inputValue";
0N/A /** Bound property name for <code>wantsInput</code>. */
0N/A public static final String WANTS_INPUT_PROPERTY = "wantsInput";
0N/A
0N/A /** Icon used in pane. */
0N/A transient protected Icon icon;
0N/A /** Message to display. */
0N/A transient protected Object message;
0N/A /** Options to display to the user. */
0N/A transient protected Object[] options;
0N/A /** Value that should be initially selected in <code>options</code>. */
0N/A transient protected Object initialValue;
0N/A /** Message type. */
0N/A protected int messageType;
0N/A /**
0N/A * Option type, one of <code>DEFAULT_OPTION</code>,
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code> or
0N/A * <code>OK_CANCEL_OPTION</code>.
0N/A */
0N/A protected int optionType;
0N/A /** Currently selected value, will be a valid option, or
0N/A * <code>UNINITIALIZED_VALUE</code> or <code>null</code>. */
0N/A transient protected Object value;
0N/A /** Array of values the user can choose from. Look and feel will
0N/A * provide the UI component to choose this from. */
0N/A protected transient Object[] selectionValues;
0N/A /** Value the user has input. */
0N/A protected transient Object inputValue;
0N/A /** Initial value to select in <code>selectionValues</code>. */
0N/A protected transient Object initialSelectionValue;
0N/A /** If true, a UI widget will be provided to the user to get input. */
0N/A protected boolean wantsInput;
0N/A
0N/A
0N/A /**
0N/A * Shows a question-message dialog requesting input from the user. The
0N/A * dialog uses the default frame, which usually means it is centered on
0N/A * the screen.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static String showInputDialog(Object message)
0N/A throws HeadlessException {
0N/A return showInputDialog(null, message);
0N/A }
0N/A
0N/A /**
0N/A * Shows a question-message dialog requesting input from the user, with
0N/A * the input value initialized to <code>initialSelectionValue</code>. The
0N/A * dialog uses the default frame, which usually means it is centered on
0N/A * the screen.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param initialSelectionValue the value used to initialize the input
0N/A * field
0N/A * @since 1.4
0N/A */
0N/A public static String showInputDialog(Object message, Object initialSelectionValue) {
0N/A return showInputDialog(null, message, initialSelectionValue);
0N/A }
0N/A
0N/A /**
0N/A * Shows a question-message dialog requesting input from the user
0N/A * parented to <code>parentComponent</code>.
0N/A * The dialog is displayed on top of the <code>Component</code>'s
0N/A * frame, and is usually positioned below the <code>Component</code>.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the
0N/A * dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static String showInputDialog(Component parentComponent,
0N/A Object message) throws HeadlessException {
0N/A return showInputDialog(parentComponent, message, UIManager.getString(
0N/A "OptionPane.inputDialogTitle", parentComponent), QUESTION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Shows a question-message dialog requesting input from the user and
0N/A * parented to <code>parentComponent</code>. The input value will be
0N/A * initialized to <code>initialSelectionValue</code>.
0N/A * The dialog is displayed on top of the <code>Component</code>'s
0N/A * frame, and is usually positioned below the <code>Component</code>.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the
0N/A * dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @param initialSelectionValue the value used to initialize the input
0N/A * field
0N/A * @since 1.4
0N/A */
0N/A public static String showInputDialog(Component parentComponent, Object message,
0N/A Object initialSelectionValue) {
0N/A return (String)showInputDialog(parentComponent, message,
0N/A UIManager.getString("OptionPane.inputDialogTitle",
0N/A parentComponent), QUESTION_MESSAGE, null, null,
0N/A initialSelectionValue);
0N/A }
0N/A
0N/A /**
0N/A * Shows a dialog requesting input from the user parented to
0N/A * <code>parentComponent</code> with the dialog having the title
0N/A * <code>title</code> and message type <code>messageType</code>.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the
0N/A * dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the <code>String</code> to display in the dialog
0N/A * title bar
0N/A * @param messageType the type of message that is to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static String showInputDialog(Component parentComponent,
0N/A Object message, String title, int messageType)
0N/A throws HeadlessException {
0N/A return (String)showInputDialog(parentComponent, message, title,
0N/A messageType, null, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Prompts the user for input in a blocking dialog where the
0N/A * initial selection, possible selections, and all other options can
0N/A * be specified. The user will able to choose from
0N/A * <code>selectionValues</code>, where <code>null</code> implies the
0N/A * user can input
0N/A * whatever they wish, usually by means of a <code>JTextField</code>.
0N/A * <code>initialSelectionValue</code> is the initial value to prompt
0N/A * the user with. It is up to the UI to decide how best to represent
0N/A * the <code>selectionValues</code>, but usually a
0N/A * <code>JComboBox</code>, <code>JList</code>, or
0N/A * <code>JTextField</code> will be used.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the
0N/A * dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the <code>String</code> to display in the
0N/A * dialog title bar
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the <code>Icon</code> image to display
0N/A * @param selectionValues an array of <code>Object</code>s that
0N/A * gives the possible selections
0N/A * @param initialSelectionValue the value used to initialize the input
0N/A * field
0N/A * @return user's input, or <code>null</code> meaning the user
0N/A * canceled the input
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static Object showInputDialog(Component parentComponent,
0N/A Object message, String title, int messageType, Icon icon,
0N/A Object[] selectionValues, Object initialSelectionValue)
0N/A throws HeadlessException {
0N/A JOptionPane pane = new JOptionPane(message, messageType,
0N/A OK_CANCEL_OPTION, icon,
0N/A null, null);
0N/A
0N/A pane.setWantsInput(true);
0N/A pane.setSelectionValues(selectionValues);
0N/A pane.setInitialSelectionValue(initialSelectionValue);
0N/A pane.setComponentOrientation(((parentComponent == null) ?
0N/A getRootFrame() : parentComponent).getComponentOrientation());
0N/A
0N/A int style = styleFromMessageType(messageType);
0N/A JDialog dialog = pane.createDialog(parentComponent, title, style);
0N/A
0N/A pane.selectInitialValue();
0N/A dialog.show();
0N/A dialog.dispose();
0N/A
0N/A Object value = pane.getInputValue();
0N/A
0N/A if (value == UNINITIALIZED_VALUE) {
0N/A return null;
0N/A }
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Brings up an information-message dialog titled "Message".
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in
0N/A * which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static void showMessageDialog(Component parentComponent,
0N/A Object message) throws HeadlessException {
0N/A showMessageDialog(parentComponent, message, UIManager.getString(
0N/A "OptionPane.messageDialogTitle", parentComponent),
0N/A INFORMATION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog that displays a message using a default
0N/A * icon determined by the <code>messageType</code> parameter.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static void showMessageDialog(Component parentComponent,
0N/A Object message, String title, int messageType)
0N/A throws HeadlessException {
0N/A showMessageDialog(parentComponent, message, title, messageType, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog displaying a message, specifying all parameters.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in which the
0N/A * dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon an icon to display in the dialog that helps the user
0N/A * identify the kind of message that is being displayed
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static void showMessageDialog(Component parentComponent,
0N/A Object message, String title, int messageType, Icon icon)
0N/A throws HeadlessException {
0N/A showOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
0N/A messageType, icon, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog with the options <i>Yes</i>,
0N/A * <i>No</i> and <i>Cancel</i>; with the
0N/A * title, <b>Select an Option</b>.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in which the
0N/A * dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @return an integer indicating the option selected by the user
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static int showConfirmDialog(Component parentComponent,
0N/A Object message) throws HeadlessException {
0N/A return showConfirmDialog(parentComponent, message,
0N/A UIManager.getString("OptionPane.titleText"),
0N/A YES_NO_CANCEL_OPTION);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog where the number of choices is determined
0N/A * by the <code>optionType</code> parameter.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in which the
0N/A * dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param optionType an int designating the options available on the dialog:
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * or <code>OK_CANCEL_OPTION</code>
0N/A * @return an int indicating the option selected by the user
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static int showConfirmDialog(Component parentComponent,
0N/A Object message, String title, int optionType)
0N/A throws HeadlessException {
0N/A return showConfirmDialog(parentComponent, message, title, optionType,
0N/A QUESTION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog where the number of choices is determined
0N/A * by the <code>optionType</code> parameter, where the
0N/A * <code>messageType</code>
0N/A * parameter determines the icon to display.
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the Look and Feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in
0N/A * which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used.
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options available
0N/A * on the dialog: <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * or <code>OK_CANCEL_OPTION</code>
0N/A * @param messageType an integer designating the kind of message this is;
0N/A * primarily used to determine the icon from the pluggable
0N/A * Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @return an integer indicating the option selected by the user
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static int showConfirmDialog(Component parentComponent,
0N/A Object message, String title, int optionType, int messageType)
0N/A throws HeadlessException {
0N/A return showConfirmDialog(parentComponent, message, title, optionType,
0N/A messageType, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog with a specified icon, where the number of
0N/A * choices is determined by the <code>optionType</code> parameter.
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the look and feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in which the
0N/A * dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the Object to display
0N/A * @param title the title string for the dialog
0N/A * @param optionType an int designating the options available on the dialog:
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * or <code>OK_CANCEL_OPTION</code>
0N/A * @param messageType an int designating the kind of message this is,
0N/A * primarily used to determine the icon from the pluggable
0N/A * Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the icon to display in the dialog
0N/A * @return an int indicating the option selected by the user
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static int showConfirmDialog(Component parentComponent,
0N/A Object message, String title, int optionType,
0N/A int messageType, Icon icon) throws HeadlessException {
0N/A return showOptionDialog(parentComponent, message, title, optionType,
0N/A messageType, icon, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a dialog with a specified icon, where the initial
0N/A * choice is determined by the <code>initialValue</code> parameter and
0N/A * the number of choices is determined by the <code>optionType</code>
0N/A * parameter.
0N/A * <p>
0N/A * If <code>optionType</code> is <code>YES_NO_OPTION</code>,
0N/A * or <code>YES_NO_CANCEL_OPTION</code>
0N/A * and the <code>options</code> parameter is <code>null</code>,
0N/A * then the options are
0N/A * supplied by the look and feel.
0N/A * <p>
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the look and feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if
0N/A * <code>null</code>, or if the
0N/A * <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options available on the
0N/A * dialog: <code>DEFAULT_OPTION</code>,
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * or <code>OK_CANCEL_OPTION</code>
0N/A * @param messageType an integer designating the kind of message this is,
0N/A * primarily used to determine the icon from the
0N/A * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the icon to display in the dialog
0N/A * @param options an array of objects indicating the possible choices
0N/A * the user can make; if the objects are components, they
0N/A * are rendered properly; non-<code>String</code>
0N/A * objects are
0N/A * rendered using their <code>toString</code> methods;
0N/A * if this parameter is <code>null</code>,
0N/A * the options are determined by the Look and Feel
0N/A * @param initialValue the object that represents the default selection
0N/A * for the dialog; only meaningful if <code>options</code>
0N/A * is used; can be <code>null</code>
0N/A * @return an integer indicating the option chosen by the user,
0N/A * or <code>CLOSED_OPTION</code> if the user closed
0N/A * the dialog
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static int showOptionDialog(Component parentComponent,
0N/A Object message, String title, int optionType, int messageType,
0N/A Icon icon, Object[] options, Object initialValue)
0N/A throws HeadlessException {
0N/A JOptionPane pane = new JOptionPane(message, messageType,
0N/A optionType, icon,
0N/A options, initialValue);
0N/A
0N/A pane.setInitialValue(initialValue);
0N/A pane.setComponentOrientation(((parentComponent == null) ?
0N/A getRootFrame() : parentComponent).getComponentOrientation());
0N/A
0N/A int style = styleFromMessageType(messageType);
0N/A JDialog dialog = pane.createDialog(parentComponent, title, style);
0N/A
0N/A pane.selectInitialValue();
0N/A dialog.show();
0N/A dialog.dispose();
0N/A
0N/A Object selectedValue = pane.getValue();
0N/A
0N/A if(selectedValue == null)
0N/A return CLOSED_OPTION;
0N/A if(options == null) {
0N/A if(selectedValue instanceof Integer)
0N/A return ((Integer)selectedValue).intValue();
0N/A return CLOSED_OPTION;
0N/A }
0N/A for(int counter = 0, maxCounter = options.length;
0N/A counter < maxCounter; counter++) {
0N/A if(options[counter].equals(selectedValue))
0N/A return counter;
0N/A }
0N/A return CLOSED_OPTION;
0N/A }
0N/A
0N/A /**
0N/A * Creates and returns a new <code>JDialog</code> wrapping
0N/A * <code>this</code> centered on the <code>parentComponent</code>
0N/A * in the <code>parentComponent</code>'s frame.
0N/A * <code>title</code> is the title of the returned dialog.
0N/A * The returned <code>JDialog</code> will not be resizable by the
0N/A * user, however programs can invoke <code>setResizable</code> on
0N/A * the <code>JDialog</code> instance to change this property.
0N/A * The returned <code>JDialog</code> will be set up such that
0N/A * once it is closed, or the user clicks on one of the buttons,
0N/A * the optionpane's value property will be set accordingly and
0N/A * the dialog will be closed. Each time the dialog is made visible,
0N/A * it will reset the option pane's value property to
0N/A * <code>JOptionPane.UNINITIALIZED_VALUE</code> to ensure the
0N/A * user's subsequent action closes the dialog properly.
0N/A *
0N/A * @param parentComponent determines the frame in which the dialog
0N/A * is displayed; if the <code>parentComponent</code> has
0N/A * no <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param title the title string for the dialog
0N/A * @return a new <code>JDialog</code> containing this instance
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public JDialog createDialog(Component parentComponent, String title)
0N/A throws HeadlessException {
0N/A int style = styleFromMessageType(getMessageType());
0N/A return createDialog(parentComponent, title, style);
0N/A }
0N/A
0N/A /**
0N/A * Creates and returns a new parentless <code>JDialog</code>
0N/A * with the specified title.
0N/A * The returned <code>JDialog</code> will not be resizable by the
0N/A * user, however programs can invoke <code>setResizable</code> on
0N/A * the <code>JDialog</code> instance to change this property.
0N/A * The returned <code>JDialog</code> will be set up such that
0N/A * once it is closed, or the user clicks on one of the buttons,
0N/A * the optionpane's value property will be set accordingly and
0N/A * the dialog will be closed. Each time the dialog is made visible,
0N/A * it will reset the option pane's value property to
0N/A * <code>JOptionPane.UNINITIALIZED_VALUE</code> to ensure the
0N/A * user's subsequent action closes the dialog properly.
0N/A *
0N/A * @param title the title string for the dialog
0N/A * @return a new <code>JDialog</code> containing this instance
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.6
0N/A */
0N/A public JDialog createDialog(String title) throws HeadlessException {
0N/A int style = styleFromMessageType(getMessageType());
0N/A JDialog dialog = new JDialog((Dialog) null, title, true);
0N/A initDialog(dialog, style, null);
0N/A return dialog;
0N/A }
0N/A
0N/A private JDialog createDialog(Component parentComponent, String title,
0N/A int style)
0N/A throws HeadlessException {
0N/A
0N/A final JDialog dialog;
0N/A
0N/A Window window = JOptionPane.getWindowForComponent(parentComponent);
0N/A if (window instanceof Frame) {
0N/A dialog = new JDialog((Frame)window, title, true);
0N/A } else {
0N/A dialog = new JDialog((Dialog)window, title, true);
0N/A }
0N/A if (window instanceof SwingUtilities.SharedOwnerFrame) {
0N/A WindowListener ownerShutdownListener =
625N/A SwingUtilities.getSharedOwnerFrameShutdownListener();
0N/A dialog.addWindowListener(ownerShutdownListener);
0N/A }
0N/A initDialog(dialog, style, parentComponent);
0N/A return dialog;
0N/A }
0N/A
0N/A private void initDialog(final JDialog dialog, int style, Component parentComponent) {
0N/A dialog.setComponentOrientation(this.getComponentOrientation());
0N/A Container contentPane = dialog.getContentPane();
0N/A
0N/A contentPane.setLayout(new BorderLayout());
0N/A contentPane.add(this, BorderLayout.CENTER);
0N/A dialog.setResizable(false);
0N/A if (JDialog.isDefaultLookAndFeelDecorated()) {
0N/A boolean supportsWindowDecorations =
0N/A UIManager.getLookAndFeel().getSupportsWindowDecorations();
0N/A if (supportsWindowDecorations) {
0N/A dialog.setUndecorated(true);
0N/A getRootPane().setWindowDecorationStyle(style);
0N/A }
0N/A }
0N/A dialog.pack();
0N/A dialog.setLocationRelativeTo(parentComponent);
3728N/A
3728N/A final PropertyChangeListener listener = new PropertyChangeListener() {
3728N/A public void propertyChange(PropertyChangeEvent event) {
3728N/A // Let the defaultCloseOperation handle the closing
3728N/A // if the user closed the window without selecting a button
3728N/A // (newValue = null in that case). Otherwise, close the dialog.
3728N/A if (dialog.isVisible() && event.getSource() == JOptionPane.this &&
4780N/A (event.getPropertyName().equals(VALUE_PROPERTY)) &&
3728N/A event.getNewValue() != null &&
3728N/A event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
3728N/A dialog.setVisible(false);
3728N/A }
3728N/A }
3728N/A };
3728N/A
0N/A WindowAdapter adapter = new WindowAdapter() {
0N/A private boolean gotFocus = false;
0N/A public void windowClosing(WindowEvent we) {
0N/A setValue(null);
0N/A }
3728N/A
3728N/A public void windowClosed(WindowEvent e) {
3728N/A removePropertyChangeListener(listener);
3728N/A dialog.getContentPane().removeAll();
3728N/A }
3728N/A
0N/A public void windowGainedFocus(WindowEvent we) {
0N/A // Once window gets focus, set initial focus
0N/A if (!gotFocus) {
0N/A selectInitialValue();
0N/A gotFocus = true;
0N/A }
0N/A }
0N/A };
0N/A dialog.addWindowListener(adapter);
0N/A dialog.addWindowFocusListener(adapter);
0N/A dialog.addComponentListener(new ComponentAdapter() {
0N/A public void componentShown(ComponentEvent ce) {
0N/A // reset value to ensure closing works properly
0N/A setValue(JOptionPane.UNINITIALIZED_VALUE);
0N/A }
0N/A });
3728N/A
3728N/A addPropertyChangeListener(listener);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Brings up an internal confirmation dialog panel. The dialog
0N/A * is a information-message dialog titled "Message".
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the object to display
0N/A */
0N/A public static void showInternalMessageDialog(Component parentComponent,
0N/A Object message) {
0N/A showInternalMessageDialog(parentComponent, message, UIManager.
0N/A getString("OptionPane.messageDialogTitle",
0N/A parentComponent), INFORMATION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel that displays a message
0N/A * using a default icon determined by the <code>messageType</code>
0N/A * parameter.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A */
0N/A public static void showInternalMessageDialog(Component parentComponent,
0N/A Object message, String title,
0N/A int messageType) {
0N/A showInternalMessageDialog(parentComponent, message, title, messageType,null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel displaying a message,
0N/A * specifying all parameters.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the title string for the dialog
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon an icon to display in the dialog that helps the user
0N/A * identify the kind of message that is being displayed
0N/A */
0N/A public static void showInternalMessageDialog(Component parentComponent,
0N/A Object message,
0N/A String title, int messageType,
0N/A Icon icon){
0N/A showInternalOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
0N/A messageType, icon, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel with the options <i>Yes</i>, <i>No</i>
0N/A * and <i>Cancel</i>; with the title, <b>Select an Option</b>.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in
0N/A * which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the <code>Object</code> to display
0N/A * @return an integer indicating the option selected by the user
0N/A */
0N/A public static int showInternalConfirmDialog(Component parentComponent,
0N/A Object message) {
0N/A return showInternalConfirmDialog(parentComponent, message,
0N/A UIManager.getString("OptionPane.titleText"),
0N/A YES_NO_CANCEL_OPTION);
0N/A }
0N/A
0N/A /**
0N/A * Brings up a internal dialog panel where the number of choices
0N/A * is determined by the <code>optionType</code> parameter.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the object to display in the dialog; a
0N/A * <code>Component</code> object is rendered as a
0N/A * <code>Component</code>; a <code>String</code>
0N/A * object is rendered as a string; other objects
0N/A * are converted to a <code>String</code> using the
0N/A * <code>toString</code> method
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options
0N/A * available on the dialog: <code>YES_NO_OPTION</code>,
0N/A * or <code>YES_NO_CANCEL_OPTION</code>
0N/A * @return an integer indicating the option selected by the user
0N/A */
0N/A public static int showInternalConfirmDialog(Component parentComponent,
0N/A Object message, String title,
0N/A int optionType) {
0N/A return showInternalConfirmDialog(parentComponent, message, title, optionType,
0N/A QUESTION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel where the number of choices
0N/A * is determined by the <code>optionType</code> parameter, where
0N/A * the <code>messageType</code> parameter determines the icon to display.
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the Look and Feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code> in
0N/A * which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the object to display in the dialog; a
0N/A * <code>Component</code> object is rendered as a
0N/A * <code>Component</code>; a <code>String</code>
0N/A * object is rendered as a string; other objects are
0N/A * converted to a <code>String</code> using the
0N/A * <code>toString</code> method
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options
0N/A * available on the dialog:
0N/A * <code>YES_NO_OPTION</code>, or <code>YES_NO_CANCEL_OPTION</code>
0N/A * @param messageType an integer designating the kind of message this is,
0N/A * primarily used to determine the icon from the
0N/A * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @return an integer indicating the option selected by the user
0N/A */
0N/A public static int showInternalConfirmDialog(Component parentComponent,
0N/A Object message,
0N/A String title, int optionType,
0N/A int messageType) {
0N/A return showInternalConfirmDialog(parentComponent, message, title, optionType,
0N/A messageType, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel with a specified icon, where
0N/A * the number of choices is determined by the <code>optionType</code>
0N/A * parameter.
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the look and feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the parentComponent has no Frame, a
0N/A * default <code>Frame</code> is used
0N/A * @param message the object to display in the dialog; a
0N/A * <code>Component</code> object is rendered as a
0N/A * <code>Component</code>; a <code>String</code>
0N/A * object is rendered as a string; other objects are
0N/A * converted to a <code>String</code> using the
0N/A * <code>toString</code> method
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options available
0N/A * on the dialog:
0N/A * <code>YES_NO_OPTION</code>, or
0N/A * <code>YES_NO_CANCEL_OPTION</code>.
0N/A * @param messageType an integer designating the kind of message this is,
0N/A * primarily used to determine the icon from the pluggable
0N/A * Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the icon to display in the dialog
0N/A * @return an integer indicating the option selected by the user
0N/A */
0N/A public static int showInternalConfirmDialog(Component parentComponent,
0N/A Object message,
0N/A String title, int optionType,
0N/A int messageType, Icon icon) {
0N/A return showInternalOptionDialog(parentComponent, message, title, optionType,
0N/A messageType, icon, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Brings up an internal dialog panel with a specified icon, where
0N/A * the initial choice is determined by the <code>initialValue</code>
0N/A * parameter and the number of choices is determined by the
0N/A * <code>optionType</code> parameter.
0N/A * <p>
0N/A * If <code>optionType</code> is <code>YES_NO_OPTION</code>, or
0N/A * <code>YES_NO_CANCEL_OPTION</code>
0N/A * and the <code>options</code> parameter is <code>null</code>,
0N/A * then the options are supplied by the Look and Feel.
0N/A * <p>
0N/A * The <code>messageType</code> parameter is primarily used to supply
0N/A * a default icon from the look and feel.
0N/A *
0N/A * @param parentComponent determines the <code>Frame</code>
0N/A * in which the dialog is displayed; if <code>null</code>,
0N/A * or if the <code>parentComponent</code> has no
0N/A * <code>Frame</code>, a default <code>Frame</code> is used
0N/A * @param message the object to display in the dialog; a
0N/A * <code>Component</code> object is rendered as a
0N/A * <code>Component</code>; a <code>String</code>
0N/A * object is rendered as a string. Other objects are
0N/A * converted to a <code>String</code> using the
0N/A * <code>toString</code> method
0N/A * @param title the title string for the dialog
0N/A * @param optionType an integer designating the options available
0N/A * on the dialog: <code>YES_NO_OPTION</code>,
0N/A * or <code>YES_NO_CANCEL_OPTION</code>
0N/A * @param messageType an integer designating the kind of message this is;
0N/A * primarily used to determine the icon from the
0N/A * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the icon to display in the dialog
0N/A * @param options an array of objects indicating the possible choices
0N/A * the user can make; if the objects are components, they
0N/A * are rendered properly; non-<code>String</code>
0N/A * objects are rendered using their <code>toString</code>
0N/A * methods; if this parameter is <code>null</code>,
0N/A * the options are determined by the Look and Feel
0N/A * @param initialValue the object that represents the default selection
0N/A * for the dialog; only meaningful if <code>options</code>
0N/A * is used; can be <code>null</code>
0N/A * @return an integer indicating the option chosen by the user,
0N/A * or <code>CLOSED_OPTION</code> if the user closed the Dialog
0N/A */
0N/A public static int showInternalOptionDialog(Component parentComponent,
0N/A Object message,
0N/A String title, int optionType,
0N/A int messageType, Icon icon,
0N/A Object[] options, Object initialValue) {
0N/A JOptionPane pane = new JOptionPane(message, messageType,
0N/A optionType, icon, options, initialValue);
0N/A pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
0N/A Boolean.TRUE);
0N/A Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A getFocusOwner();
0N/A
0N/A pane.setInitialValue(initialValue);
0N/A
0N/A JInternalFrame dialog =
0N/A pane.createInternalFrame(parentComponent, title);
0N/A pane.selectInitialValue();
0N/A dialog.setVisible(true);
0N/A
0N/A /* Since all input will be blocked until this dialog is dismissed,
0N/A * make sure its parent containers are visible first (this component
0N/A * is tested below). This is necessary for JApplets, because
0N/A * because an applet normally isn't made visible until after its
0N/A * start() method returns -- if this method is called from start(),
0N/A * the applet will appear to hang while an invisible modal frame
0N/A * waits for input.
0N/A */
0N/A if (dialog.isVisible() && !dialog.isShowing()) {
0N/A Container parent = dialog.getParent();
0N/A while (parent != null) {
0N/A if (parent.isVisible() == false) {
0N/A parent.setVisible(true);
0N/A }
0N/A parent = parent.getParent();
0N/A }
0N/A }
0N/A
0N/A // Use reflection to get Container.startLWModal.
0N/A try {
625N/A Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
0N/A Container.class, "startLWModal"));
625N/A if (method != null) {
625N/A method.invoke(dialog, (Object[])null);
0N/A }
0N/A } catch (IllegalAccessException ex) {
0N/A } catch (IllegalArgumentException ex) {
0N/A } catch (InvocationTargetException ex) {
0N/A }
0N/A
0N/A if (parentComponent instanceof JInternalFrame) {
0N/A try {
0N/A ((JInternalFrame)parentComponent).setSelected(true);
0N/A } catch (java.beans.PropertyVetoException e) {
0N/A }
0N/A }
0N/A
0N/A Object selectedValue = pane.getValue();
0N/A
0N/A if (fo != null && fo.isShowing()) {
0N/A fo.requestFocus();
0N/A }
0N/A if (selectedValue == null) {
0N/A return CLOSED_OPTION;
0N/A }
0N/A if (options == null) {
0N/A if (selectedValue instanceof Integer) {
0N/A return ((Integer)selectedValue).intValue();
0N/A }
0N/A return CLOSED_OPTION;
0N/A }
0N/A for(int counter = 0, maxCounter = options.length;
0N/A counter < maxCounter; counter++) {
0N/A if (options[counter].equals(selectedValue)) {
0N/A return counter;
0N/A }
0N/A }
0N/A return CLOSED_OPTION;
0N/A }
0N/A
0N/A /**
0N/A * Shows an internal question-message dialog requesting input from
0N/A * the user parented to <code>parentComponent</code>. The dialog
0N/A * is displayed in the <code>Component</code>'s frame,
0N/A * and is usually positioned below the <code>Component</code>.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code>
0N/A * for the dialog
0N/A * @param message the <code>Object</code> to display
0N/A */
0N/A public static String showInternalInputDialog(Component parentComponent,
0N/A Object message) {
0N/A return showInternalInputDialog(parentComponent, message, UIManager.
0N/A getString("OptionPane.inputDialogTitle", parentComponent),
0N/A QUESTION_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Shows an internal dialog requesting input from the user parented
0N/A * to <code>parentComponent</code> with the dialog having the title
0N/A * <code>title</code> and message type <code>messageType</code>.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the <code>String</code> to display in the
0N/A * dialog title bar
0N/A * @param messageType the type of message that is to be displayed:
0N/A * ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
0N/A * QUESTION_MESSAGE, or PLAIN_MESSAGE
0N/A */
0N/A public static String showInternalInputDialog(Component parentComponent,
0N/A Object message, String title, int messageType) {
0N/A return (String)showInternalInputDialog(parentComponent, message, title,
0N/A messageType, null, null, null);
0N/A }
0N/A
0N/A /**
0N/A * Prompts the user for input in a blocking internal dialog where
0N/A * the initial selection, possible selections, and all other
0N/A * options can be specified. The user will able to choose from
0N/A * <code>selectionValues</code>, where <code>null</code>
0N/A * implies the user can input
0N/A * whatever they wish, usually by means of a <code>JTextField</code>.
0N/A * <code>initialSelectionValue</code> is the initial value to prompt
0N/A * the user with. It is up to the UI to decide how best to represent
0N/A * the <code>selectionValues</code>, but usually a
0N/A * <code>JComboBox</code>, <code>JList</code>, or
0N/A * <code>JTextField</code> will be used.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for the dialog
0N/A * @param message the <code>Object</code> to display
0N/A * @param title the <code>String</code> to display in the dialog
0N/A * title bar
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
0N/A * @param icon the <code>Icon</code> image to display
0N/A * @param selectionValues an array of <code>Objects</code> that
0N/A * gives the possible selections
0N/A * @param initialSelectionValue the value used to initialize the input
0N/A * field
0N/A * @return user's input, or <code>null</code> meaning the user
0N/A * canceled the input
0N/A */
0N/A public static Object showInternalInputDialog(Component parentComponent,
0N/A Object message, String title, int messageType, Icon icon,
0N/A Object[] selectionValues, Object initialSelectionValue) {
0N/A JOptionPane pane = new JOptionPane(message, messageType,
0N/A OK_CANCEL_OPTION, icon, null, null);
0N/A pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
0N/A Boolean.TRUE);
0N/A Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A getFocusOwner();
0N/A
0N/A pane.setWantsInput(true);
0N/A pane.setSelectionValues(selectionValues);
0N/A pane.setInitialSelectionValue(initialSelectionValue);
0N/A
0N/A JInternalFrame dialog =
0N/A pane.createInternalFrame(parentComponent, title);
0N/A
0N/A pane.selectInitialValue();
0N/A dialog.setVisible(true);
0N/A
0N/A /* Since all input will be blocked until this dialog is dismissed,
0N/A * make sure its parent containers are visible first (this component
0N/A * is tested below). This is necessary for JApplets, because
0N/A * because an applet normally isn't made visible until after its
0N/A * start() method returns -- if this method is called from start(),
0N/A * the applet will appear to hang while an invisible modal frame
0N/A * waits for input.
0N/A */
0N/A if (dialog.isVisible() && !dialog.isShowing()) {
0N/A Container parent = dialog.getParent();
0N/A while (parent != null) {
0N/A if (parent.isVisible() == false) {
0N/A parent.setVisible(true);
0N/A }
0N/A parent = parent.getParent();
0N/A }
0N/A }
0N/A
0N/A // Use reflection to get Container.startLWModal.
0N/A try {
625N/A Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
0N/A Container.class, "startLWModal"));
625N/A if (method != null) {
625N/A method.invoke(dialog, (Object[])null);
0N/A }
0N/A } catch (IllegalAccessException ex) {
0N/A } catch (IllegalArgumentException ex) {
0N/A } catch (InvocationTargetException ex) {
0N/A }
0N/A
0N/A if (parentComponent instanceof JInternalFrame) {
0N/A try {
0N/A ((JInternalFrame)parentComponent).setSelected(true);
0N/A } catch (java.beans.PropertyVetoException e) {
0N/A }
0N/A }
0N/A
0N/A if (fo != null && fo.isShowing()) {
0N/A fo.requestFocus();
0N/A }
0N/A Object value = pane.getInputValue();
0N/A
0N/A if (value == UNINITIALIZED_VALUE) {
0N/A return null;
0N/A }
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Creates and returns an instance of <code>JInternalFrame</code>.
0N/A * The internal frame is created with the specified title,
0N/A * and wrapping the <code>JOptionPane</code>.
0N/A * The returned <code>JInternalFrame</code> is
0N/A * added to the <code>JDesktopPane</code> ancestor of
0N/A * <code>parentComponent</code>, or components
0N/A * parent if one its ancestors isn't a <code>JDesktopPane</code>,
0N/A * or if <code>parentComponent</code>
0N/A * doesn't have a parent then a <code>RuntimeException</code> is thrown.
0N/A *
0N/A * @param parentComponent the parent <code>Component</code> for
0N/A * the internal frame
0N/A * @param title the <code>String</code> to display in the
0N/A * frame's title bar
0N/A * @return a <code>JInternalFrame</code> containing a
0N/A * <code>JOptionPane</code>
0N/A * @exception RuntimeException if <code>parentComponent</code> does
0N/A * not have a valid parent
0N/A */
0N/A public JInternalFrame createInternalFrame(Component parentComponent,
0N/A String title) {
0N/A Container parent =
0N/A JOptionPane.getDesktopPaneForComponent(parentComponent);
0N/A
0N/A if (parent == null && (parentComponent == null ||
0N/A (parent = parentComponent.getParent()) == null)) {
0N/A throw new RuntimeException("JOptionPane: parentComponent does " +
0N/A "not have a valid parent");
0N/A }
0N/A
0N/A // Option dialogs should be closable only
0N/A final JInternalFrame iFrame = new JInternalFrame(title, false, true,
0N/A false, false);
0N/A
0N/A iFrame.putClientProperty("JInternalFrame.frameType", "optionDialog");
0N/A iFrame.putClientProperty("JInternalFrame.messageType",
215N/A Integer.valueOf(getMessageType()));
0N/A
0N/A iFrame.addInternalFrameListener(new InternalFrameAdapter() {
0N/A public void internalFrameClosing(InternalFrameEvent e) {
0N/A if (getValue() == UNINITIALIZED_VALUE) {
0N/A setValue(null);
0N/A }
0N/A }
0N/A });
0N/A addPropertyChangeListener(new PropertyChangeListener() {
0N/A public void propertyChange(PropertyChangeEvent event) {
0N/A // Let the defaultCloseOperation handle the closing
0N/A // if the user closed the iframe without selecting a button
0N/A // (newValue = null in that case). Otherwise, close the dialog.
0N/A if (iFrame.isVisible() &&
0N/A event.getSource() == JOptionPane.this &&
0N/A event.getPropertyName().equals(VALUE_PROPERTY)) {
0N/A // Use reflection to get Container.stopLWModal().
0N/A try {
625N/A Method method = AccessController.doPrivileged(
0N/A new ModalPrivilegedAction(
0N/A Container.class, "stopLWModal"));
625N/A if (method != null) {
625N/A method.invoke(iFrame, (Object[])null);
0N/A }
0N/A } catch (IllegalAccessException ex) {
0N/A } catch (IllegalArgumentException ex) {
0N/A } catch (InvocationTargetException ex) {
0N/A }
0N/A
0N/A try {
0N/A iFrame.setClosed(true);
0N/A }
0N/A catch (java.beans.PropertyVetoException e) {
0N/A }
0N/A
0N/A iFrame.setVisible(false);
0N/A }
0N/A }
0N/A });
0N/A iFrame.getContentPane().add(this, BorderLayout.CENTER);
0N/A if (parent instanceof JDesktopPane) {
0N/A parent.add(iFrame, JLayeredPane.MODAL_LAYER);
0N/A } else {
0N/A parent.add(iFrame, BorderLayout.CENTER);
0N/A }
0N/A Dimension iFrameSize = iFrame.getPreferredSize();
0N/A Dimension rootSize = parent.getSize();
0N/A Dimension parentSize = parentComponent.getSize();
0N/A
0N/A iFrame.setBounds((rootSize.width - iFrameSize.width) / 2,
0N/A (rootSize.height - iFrameSize.height) / 2,
0N/A iFrameSize.width, iFrameSize.height);
0N/A // We want dialog centered relative to its parent component
0N/A Point iFrameCoord =
0N/A SwingUtilities.convertPoint(parentComponent, 0, 0, parent);
0N/A int x = (parentSize.width - iFrameSize.width) / 2 + iFrameCoord.x;
0N/A int y = (parentSize.height - iFrameSize.height) / 2 + iFrameCoord.y;
0N/A
0N/A // If possible, dialog should be fully visible
0N/A int ovrx = x + iFrameSize.width - rootSize.width;
0N/A int ovry = y + iFrameSize.height - rootSize.height;
0N/A x = Math.max((ovrx > 0? x - ovrx: x), 0);
0N/A y = Math.max((ovry > 0? y - ovry: y), 0);
0N/A iFrame.setBounds(x, y, iFrameSize.width, iFrameSize.height);
0N/A
0N/A parent.validate();
0N/A try {
0N/A iFrame.setSelected(true);
0N/A } catch (java.beans.PropertyVetoException e) {}
0N/A
0N/A return iFrame;
0N/A }
0N/A
0N/A /**
0N/A * Returns the specified component's <code>Frame</code>.
0N/A *
0N/A * @param parentComponent the <code>Component</code> to check for a
0N/A * <code>Frame</code>
0N/A * @return the <code>Frame</code> that contains the component,
0N/A * or <code>getRootFrame</code>
0N/A * if the component is <code>null</code>,
0N/A * or does not have a valid <code>Frame</code> parent
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see #getRootFrame
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static Frame getFrameForComponent(Component parentComponent)
0N/A throws HeadlessException {
0N/A if (parentComponent == null)
0N/A return getRootFrame();
0N/A if (parentComponent instanceof Frame)
0N/A return (Frame)parentComponent;
0N/A return JOptionPane.getFrameForComponent(parentComponent.getParent());
0N/A }
0N/A
0N/A /**
0N/A * Returns the specified component's toplevel <code>Frame</code> or
0N/A * <code>Dialog</code>.
0N/A *
0N/A * @param parentComponent the <code>Component</code> to check for a
0N/A * <code>Frame</code> or <code>Dialog</code>
0N/A * @return the <code>Frame</code> or <code>Dialog</code> that
0N/A * contains the component, or the default
0N/A * frame if the component is <code>null</code>,
0N/A * or does not have a valid
0N/A * <code>Frame</code> or <code>Dialog</code> parent
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A static Window getWindowForComponent(Component parentComponent)
0N/A throws HeadlessException {
0N/A if (parentComponent == null)
0N/A return getRootFrame();
0N/A if (parentComponent instanceof Frame || parentComponent instanceof Dialog)
0N/A return (Window)parentComponent;
0N/A return JOptionPane.getWindowForComponent(parentComponent.getParent());
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the specified component's desktop pane.
0N/A *
0N/A * @param parentComponent the <code>Component</code> to check for a
0N/A * desktop
0N/A * @return the <code>JDesktopPane</code> that contains the component,
0N/A * or <code>null</code> if the component is <code>null</code>
0N/A * or does not have an ancestor that is a
0N/A * <code>JInternalFrame</code>
0N/A */
0N/A public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) {
0N/A if(parentComponent == null)
0N/A return null;
0N/A if(parentComponent instanceof JDesktopPane)
0N/A return (JDesktopPane)parentComponent;
0N/A return getDesktopPaneForComponent(parentComponent.getParent());
0N/A }
0N/A
0N/A private static final Object sharedFrameKey = JOptionPane.class;
0N/A
0N/A /**
0N/A * Sets the frame to use for class methods in which a frame is
0N/A * not provided.
0N/A * <p>
0N/A * <strong>Note:</strong>
0N/A * It is recommended that rather than using this method you supply a valid parent.
0N/A *
0N/A * @param newRootFrame the default <code>Frame</code> to use
0N/A */
0N/A public static void setRootFrame(Frame newRootFrame) {
0N/A if (newRootFrame != null) {
0N/A SwingUtilities.appContextPut(sharedFrameKey, newRootFrame);
0N/A } else {
0N/A SwingUtilities.appContextRemove(sharedFrameKey);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>Frame</code> to use for the class methods in
0N/A * which a frame is not provided.
0N/A *
0N/A * @return the default <code>Frame</code> to use
0N/A * @exception HeadlessException if
0N/A * <code>GraphicsEnvironment.isHeadless</code> returns
0N/A * <code>true</code>
0N/A * @see #setRootFrame
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public static Frame getRootFrame() throws HeadlessException {
0N/A Frame sharedFrame =
0N/A (Frame)SwingUtilities.appContextGet(sharedFrameKey);
0N/A if (sharedFrame == null) {
0N/A sharedFrame = SwingUtilities.getSharedOwnerFrame();
0N/A SwingUtilities.appContextPut(sharedFrameKey, sharedFrame);
0N/A }
0N/A return sharedFrame;
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>JOptionPane</code> with a test message.
0N/A */
0N/A public JOptionPane() {
0N/A this("JOptionPane message");
0N/A }
0N/A
0N/A /**
0N/A * Creates a instance of <code>JOptionPane</code> to display a
0N/A * message using the
0N/A * plain-message message type and the default options delivered by
0N/A * the UI.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A */
0N/A public JOptionPane(Object message) {
0N/A this(message, PLAIN_MESSAGE);
0N/A }
0N/A
0N/A /**
0N/A * Creates an instance of <code>JOptionPane</code> to display a message
0N/A * with the specified message type and the default options,
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A */
0N/A public JOptionPane(Object message, int messageType) {
0N/A this(message, messageType, DEFAULT_OPTION);
0N/A }
0N/A
0N/A /**
0N/A * Creates an instance of <code>JOptionPane</code> to display a message
0N/A * with the specified message type and options.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param optionType the options to display in the pane:
0N/A * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * <code>OK_CANCEL_OPTION</code>
0N/A */
0N/A public JOptionPane(Object message, int messageType, int optionType) {
0N/A this(message, messageType, optionType, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates an instance of <code>JOptionPane</code> to display a message
0N/A * with the specified message type, options, and icon.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param optionType the options to display in the pane:
0N/A * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * <code>OK_CANCEL_OPTION</code>
0N/A * @param icon the <code>Icon</code> image to display
0N/A */
0N/A public JOptionPane(Object message, int messageType, int optionType,
0N/A Icon icon) {
0N/A this(message, messageType, optionType, icon, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates an instance of <code>JOptionPane</code> to display a message
0N/A * with the specified message type, icon, and options.
0N/A * None of the options is initially selected.
0N/A * <p>
0N/A * The options objects should contain either instances of
0N/A * <code>Component</code>s, (which are added directly) or
0N/A * <code>Strings</code> (which are wrapped in a <code>JButton</code>).
0N/A * If you provide <code>Component</code>s, you must ensure that when the
0N/A * <code>Component</code> is clicked it messages <code>setValue</code>
0N/A * in the created <code>JOptionPane</code>.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param optionType the options to display in the pane:
0N/A * <code>DEFAULT_OPTION</code>,
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * <code>OK_CANCEL_OPTION</code>
0N/A * @param icon the <code>Icon</code> image to display
0N/A * @param options the choices the user can select
0N/A */
0N/A public JOptionPane(Object message, int messageType, int optionType,
0N/A Icon icon, Object[] options) {
0N/A this(message, messageType, optionType, icon, options, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates an instance of <code>JOptionPane</code> to display a message
0N/A * with the specified message type, icon, and options, with the
0N/A * initially-selected option specified.
0N/A *
0N/A * @param message the <code>Object</code> to display
0N/A * @param messageType the type of message to be displayed:
0N/A * <code>ERROR_MESSAGE</code>,
0N/A * <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>,
0N/A * or <code>PLAIN_MESSAGE</code>
0N/A * @param optionType the options to display in the pane:
0N/A * <code>DEFAULT_OPTION</code>,
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * <code>OK_CANCEL_OPTION</code>
0N/A * @param icon the Icon image to display
0N/A * @param options the choices the user can select
0N/A * @param initialValue the choice that is initially selected; if
0N/A * <code>null</code>, then nothing will be initially selected;
0N/A * only meaningful if <code>options</code> is used
0N/A */
0N/A public JOptionPane(Object message, int messageType, int optionType,
0N/A Icon icon, Object[] options, Object initialValue) {
0N/A
0N/A this.message = message;
0N/A this.options = options;
0N/A this.initialValue = initialValue;
0N/A this.icon = icon;
0N/A setMessageType(messageType);
0N/A setOptionType(optionType);
0N/A value = UNINITIALIZED_VALUE;
0N/A inputValue = UNINITIALIZED_VALUE;
0N/A updateUI();
0N/A }
0N/A
0N/A /**
0N/A * Sets the UI object which implements the L&F for this component.
0N/A *
0N/A * @param ui the <code>OptionPaneUI</code> L&F object
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * description: The UI object that implements the optionpane's LookAndFeel
0N/A */
0N/A public void setUI(OptionPaneUI ui) {
625N/A if (this.ui != ui) {
0N/A super.setUI(ui);
0N/A invalidate();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the UI object which implements the L&F for this component.
0N/A *
0N/A * @return the <code>OptionPaneUI</code> object
0N/A */
0N/A public OptionPaneUI getUI() {
0N/A return (OptionPaneUI)ui;
0N/A }
0N/A
0N/A /**
0N/A * Notification from the <code>UIManager</code> that the L&F has changed.
0N/A * Replaces the current UI object with the latest version from the
0N/A * <code>UIManager</code>.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((OptionPaneUI)UIManager.getUI(this));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the name of the UI class that implements the
0N/A * L&F for this component.
0N/A *
0N/A * @return the string "OptionPaneUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the option pane's message-object.
0N/A * @param newMessage the <code>Object</code> to display
0N/A * @see #getMessage
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The optionpane's message object.
0N/A */
0N/A public void setMessage(Object newMessage) {
0N/A Object oldMessage = message;
0N/A
0N/A message = newMessage;
0N/A firePropertyChange(MESSAGE_PROPERTY, oldMessage, message);
0N/A }
0N/A
0N/A /**
0N/A * Returns the message-object this pane displays.
0N/A * @see #setMessage
0N/A *
0N/A * @return the <code>Object</code> that is displayed
0N/A */
0N/A public Object getMessage() {
0N/A return message;
0N/A }
0N/A
0N/A /**
0N/A * Sets the icon to display. If non-<code>null</code>, the look and feel
0N/A * does not provide an icon.
0N/A * @param newIcon the <code>Icon</code> to display
0N/A *
0N/A * @see #getIcon
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's type icon.
0N/A */
0N/A public void setIcon(Icon newIcon) {
0N/A Object oldIcon = icon;
0N/A
0N/A icon = newIcon;
0N/A firePropertyChange(ICON_PROPERTY, oldIcon, icon);
0N/A }
0N/A
0N/A /**
0N/A * Returns the icon this pane displays.
0N/A * @return the <code>Icon</code> that is displayed
0N/A *
0N/A * @see #setIcon
0N/A */
0N/A public Icon getIcon() {
0N/A return icon;
0N/A }
0N/A
0N/A /**
0N/A * Sets the value the user has chosen.
0N/A * @param newValue the chosen value
0N/A *
0N/A * @see #getValue
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's value object.
0N/A */
0N/A public void setValue(Object newValue) {
0N/A Object oldValue = value;
0N/A
0N/A value = newValue;
0N/A firePropertyChange(VALUE_PROPERTY, oldValue, value);
0N/A }
0N/A
0N/A /**
0N/A * Returns the value the user has selected. <code>UNINITIALIZED_VALUE</code>
0N/A * implies the user has not yet made a choice, <code>null</code> means the
0N/A * user closed the window with out choosing anything. Otherwise
0N/A * the returned value will be one of the options defined in this
0N/A * object.
0N/A *
0N/A * @return the <code>Object</code> chosen by the user,
0N/A * <code>UNINITIALIZED_VALUE</code>
0N/A * if the user has not yet made a choice, or <code>null</code> if
0N/A * the user closed the window without making a choice
0N/A *
0N/A * @see #setValue
0N/A */
0N/A public Object getValue() {
0N/A return value;
0N/A }
0N/A
0N/A /**
0N/A * Sets the options this pane displays. If an element in
0N/A * <code>newOptions</code> is a <code>Component</code>
0N/A * it is added directly to the pane,
0N/A * otherwise a button is created for the element.
0N/A *
0N/A * @param newOptions an array of <code>Objects</code> that create the
0N/A * buttons the user can click on, or arbitrary
0N/A * <code>Components</code> to add to the pane
0N/A *
0N/A * @see #getOptions
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The option pane's options objects.
0N/A */
0N/A public void setOptions(Object[] newOptions) {
0N/A Object[] oldOptions = options;
0N/A
0N/A options = newOptions;
0N/A firePropertyChange(OPTIONS_PROPERTY, oldOptions, options);
0N/A }
0N/A
0N/A /**
0N/A * Returns the choices the user can make.
0N/A * @return the array of <code>Objects</code> that give the user's choices
0N/A *
0N/A * @see #setOptions
0N/A */
0N/A public Object[] getOptions() {
0N/A if(options != null) {
0N/A int optionCount = options.length;
0N/A Object[] retOptions = new Object[optionCount];
0N/A
0N/A System.arraycopy(options, 0, retOptions, 0, optionCount);
0N/A return retOptions;
0N/A }
0N/A return options;
0N/A }
0N/A
0N/A /**
0N/A * Sets the initial value that is to be enabled -- the
0N/A * <code>Component</code>
0N/A * that has the focus when the pane is initially displayed.
0N/A *
0N/A * @param newInitialValue the <code>Object</code> that gets the initial
0N/A * keyboard focus
0N/A *
0N/A * @see #getInitialValue
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's initial value object.
0N/A */
0N/A public void setInitialValue(Object newInitialValue) {
0N/A Object oldIV = initialValue;
0N/A
0N/A initialValue = newInitialValue;
0N/A firePropertyChange(INITIAL_VALUE_PROPERTY, oldIV, initialValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the initial value.
0N/A *
0N/A * @return the <code>Object</code> that gets the initial keyboard focus
0N/A *
0N/A * @see #setInitialValue
0N/A */
0N/A public Object getInitialValue() {
0N/A return initialValue;
0N/A }
0N/A
0N/A /**
0N/A * Sets the option pane's message type.
0N/A * The message type is used by the Look and Feel to determine the
0N/A * icon to display (if not supplied) as well as potentially how to
0N/A * lay out the <code>parentComponent</code>.
0N/A * @param newType an integer specifying the kind of message to display:
0N/A * <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
0N/A * <code>WARNING_MESSAGE</code>,
0N/A * <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
0N/A * @exception RuntimeException if <code>newType</code> is not one of the
0N/A * legal values listed above
0N/A
0N/A * @see #getMessageType
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's message type.
0N/A */
0N/A public void setMessageType(int newType) {
0N/A if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
0N/A newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
0N/A newType != PLAIN_MESSAGE)
0N/A 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");
0N/A
0N/A int oldType = messageType;
0N/A
0N/A messageType = newType;
0N/A firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
0N/A }
0N/A
0N/A /**
0N/A * Returns the message type.
0N/A *
0N/A * @return an integer specifying the message type
0N/A *
0N/A * @see #setMessageType
0N/A */
0N/A public int getMessageType() {
0N/A return messageType;
0N/A }
0N/A
0N/A /**
0N/A * Sets the options to display.
0N/A * The option type is used by the Look and Feel to
0N/A * determine what buttons to show (unless options are supplied).
0N/A * @param newType an integer specifying the options the L&F is to display:
0N/A * <code>DEFAULT_OPTION</code>,
0N/A * <code>YES_NO_OPTION</code>,
0N/A * <code>YES_NO_CANCEL_OPTION</code>,
0N/A * or <code>OK_CANCEL_OPTION</code>
0N/A * @exception RuntimeException if <code>newType</code> is not one of
0N/A * the legal values listed above
0N/A *
0N/A * @see #getOptionType
0N/A * @see #setOptions
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's option type.
0N/A */
0N/A public void setOptionType(int newType) {
0N/A if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION &&
0N/A newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION)
0N/A 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");
0N/A
0N/A int oldType = optionType;
0N/A
0N/A optionType = newType;
0N/A firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
0N/A }
0N/A
0N/A /**
0N/A * Returns the type of options that are displayed.
0N/A *
0N/A * @return an integer specifying the user-selectable options
0N/A *
0N/A * @see #setOptionType
0N/A */
0N/A public int getOptionType() {
0N/A return optionType;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input selection values for a pane that provides the user
0N/A * with a list of items to choose from. (The UI provides a widget
0N/A * for choosing one of the values.) A <code>null</code> value
0N/A * implies the user can input whatever they wish, usually by means
0N/A * of a <code>JTextField</code>.
0N/A * <p>
0N/A * Sets <code>wantsInput</code> to true. Use
0N/A * <code>setInitialSelectionValue</code> to specify the initially-chosen
0N/A * value. After the pane as been enabled, <code>inputValue</code> is
0N/A * set to the value the user has selected.
0N/A * @param newValues an array of <code>Objects</code> the user to be
0N/A * displayed
0N/A * (usually in a list or combo-box) from which
0N/A * the user can make a selection
0N/A * @see #setWantsInput
0N/A * @see #setInitialSelectionValue
0N/A * @see #getSelectionValues
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The option pane's selection values.
0N/A */
0N/A public void setSelectionValues(Object[] newValues) {
0N/A Object[] oldValues = selectionValues;
0N/A
0N/A selectionValues = newValues;
0N/A firePropertyChange(SELECTION_VALUES_PROPERTY, oldValues, newValues);
0N/A if(selectionValues != null)
0N/A setWantsInput(true);
0N/A }
0N/A
0N/A /**
0N/A * Returns the input selection values.
0N/A *
0N/A * @return the array of <code>Objects</code> the user can select
0N/A * @see #setSelectionValues
0N/A */
0N/A public Object[] getSelectionValues() {
0N/A return selectionValues;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input value that is initially displayed as selected to the user.
0N/A * Only used if <code>wantsInput</code> is true.
0N/A * @param newValue the initially selected value
0N/A * @see #setSelectionValues
0N/A * @see #getInitialSelectionValue
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The option pane's initial selection value object.
0N/A */
0N/A public void setInitialSelectionValue(Object newValue) {
0N/A Object oldValue = initialSelectionValue;
0N/A
0N/A initialSelectionValue = newValue;
0N/A firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, oldValue,
0N/A newValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the input value that is displayed as initially selected to the user.
0N/A *
0N/A * @return the initially selected value
0N/A * @see #setInitialSelectionValue
0N/A * @see #setSelectionValues
0N/A */
0N/A public Object getInitialSelectionValue() {
0N/A return initialSelectionValue;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input value that was selected or input by the user.
0N/A * Only used if <code>wantsInput</code> is true. Note that this method
0N/A * is invoked internally by the option pane (in response to user action)
0N/A * and should generally not be called by client programs. To set the
0N/A * input value initially displayed as selected to the user, use
0N/A * <code>setInitialSelectionValue</code>.
0N/A *
0N/A * @param newValue the <code>Object</code> used to set the
0N/A * value that the user specified (usually in a text field)
0N/A * @see #setSelectionValues
0N/A * @see #setInitialSelectionValue
0N/A * @see #setWantsInput
0N/A * @see #getInputValue
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The option pane's input value object.
0N/A */
0N/A public void setInputValue(Object newValue) {
0N/A Object oldValue = inputValue;
0N/A
0N/A inputValue = newValue;
0N/A firePropertyChange(INPUT_VALUE_PROPERTY, oldValue, newValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the value the user has input, if <code>wantsInput</code>
0N/A * is true.
0N/A *
0N/A * @return the <code>Object</code> the user specified,
0N/A * if it was one of the objects, or a
0N/A * <code>String</code> if it was a value typed into a
0N/A * field
0N/A * @see #setSelectionValues
0N/A * @see #setWantsInput
0N/A * @see #setInputValue
0N/A */
0N/A public Object getInputValue() {
0N/A return inputValue;
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum number of characters to place on a line in a
0N/A * message. Default is to return <code>Integer.MAX_VALUE</code>.
0N/A * The value can be
0N/A * changed by overriding this method in a subclass.
0N/A *
0N/A * @return an integer giving the maximum number of characters on a line
0N/A */
0N/A public int getMaxCharactersPerLineCount() {
0N/A return Integer.MAX_VALUE;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>wantsInput</code> property.
0N/A * If <code>newValue</code> is true, an input component
0N/A * (such as a text field or combo box) whose parent is
0N/A * <code>parentComponent</code> is provided to
0N/A * allow the user to input a value. If <code>getSelectionValues</code>
0N/A * returns a non-<code>null</code> array, the input value is one of the
0N/A * objects in that array. Otherwise the input value is whatever
0N/A * the user inputs.
0N/A * <p>
0N/A * This is a bound property.
0N/A *
0N/A * @see #setSelectionValues
0N/A * @see #setInputValue
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Flag which allows the user to input a value.
0N/A */
0N/A public void setWantsInput(boolean newValue) {
0N/A boolean oldValue = wantsInput;
0N/A
0N/A wantsInput = newValue;
0N/A firePropertyChange(WANTS_INPUT_PROPERTY, oldValue, newValue);
0N/A }
0N/A
0N/A /**
0N/A * Returns the value of the <code>wantsInput</code> property.
0N/A *
0N/A * @return true if an input component will be provided
0N/A * @see #setWantsInput
0N/A */
0N/A public boolean getWantsInput() {
0N/A return wantsInput;
0N/A }
0N/A
0N/A /**
0N/A * Requests that the initial value be selected, which will set
0N/A * focus to the initial value. This method
0N/A * should be invoked after the window containing the option pane
0N/A * is made visible.
0N/A */
0N/A public void selectInitialValue() {
0N/A OptionPaneUI ui = getUI();
0N/A if (ui != null) {
0N/A ui.selectInitialValue(this);
0N/A }
0N/A }
0N/A
0N/A
0N/A private static int styleFromMessageType(int messageType) {
0N/A switch (messageType) {
0N/A case ERROR_MESSAGE:
0N/A return JRootPane.ERROR_DIALOG;
0N/A case QUESTION_MESSAGE:
0N/A return JRootPane.QUESTION_DIALOG;
0N/A case WARNING_MESSAGE:
0N/A return JRootPane.WARNING_DIALOG;
0N/A case INFORMATION_MESSAGE:
0N/A return JRootPane.INFORMATION_DIALOG;
0N/A case PLAIN_MESSAGE:
0N/A default:
0N/A return JRootPane.PLAIN_DIALOG;
0N/A }
0N/A }
0N/A
0N/A // Serialization support.
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
625N/A Vector<Object> values = new Vector<Object>();
0N/A
0N/A s.defaultWriteObject();
0N/A // Save the icon, if its Serializable.
0N/A if(icon != null && icon instanceof Serializable) {
0N/A values.addElement("icon");
0N/A values.addElement(icon);
0N/A }
0N/A // Save the message, if its Serializable.
0N/A if(message != null && message instanceof Serializable) {
0N/A values.addElement("message");
0N/A values.addElement(message);
0N/A }
0N/A // Save the treeModel, if its Serializable.
0N/A if(options != null) {
625N/A Vector<Object> serOptions = new Vector<Object>();
0N/A
0N/A for(int counter = 0, maxCounter = options.length;
0N/A counter < maxCounter; counter++)
0N/A if(options[counter] instanceof Serializable)
0N/A serOptions.addElement(options[counter]);
0N/A if(serOptions.size() > 0) {
0N/A int optionCount = serOptions.size();
0N/A Object[] arrayOptions = new Object[optionCount];
0N/A
0N/A serOptions.copyInto(arrayOptions);
0N/A values.addElement("options");
0N/A values.addElement(arrayOptions);
0N/A }
0N/A }
0N/A // Save the initialValue, if its Serializable.
0N/A if(initialValue != null && initialValue instanceof Serializable) {
0N/A values.addElement("initialValue");
0N/A values.addElement(initialValue);
0N/A }
0N/A // Save the value, if its Serializable.
0N/A if(value != null && value instanceof Serializable) {
0N/A values.addElement("value");
0N/A values.addElement(value);
0N/A }
0N/A // Save the selectionValues, if its Serializable.
0N/A if(selectionValues != null) {
0N/A boolean serialize = true;
0N/A
0N/A for(int counter = 0, maxCounter = selectionValues.length;
0N/A counter < maxCounter; counter++) {
0N/A if(selectionValues[counter] != null &&
0N/A !(selectionValues[counter] instanceof Serializable)) {
0N/A serialize = false;
0N/A break;
0N/A }
0N/A }
0N/A if(serialize) {
0N/A values.addElement("selectionValues");
0N/A values.addElement(selectionValues);
0N/A }
0N/A }
0N/A // Save the inputValue, if its Serializable.
0N/A if(inputValue != null && inputValue instanceof Serializable) {
0N/A values.addElement("inputValue");
0N/A values.addElement(inputValue);
0N/A }
0N/A // Save the initialSelectionValue, if its Serializable.
0N/A if(initialSelectionValue != null &&
0N/A initialSelectionValue instanceof Serializable) {
0N/A values.addElement("initialSelectionValue");
0N/A values.addElement(initialSelectionValue);
0N/A }
0N/A s.writeObject(values);
0N/A }
0N/A
0N/A private void readObject(ObjectInputStream s)
0N/A throws IOException, ClassNotFoundException {
0N/A s.defaultReadObject();
0N/A
0N/A Vector values = (Vector)s.readObject();
0N/A int indexCounter = 0;
0N/A int maxCounter = values.size();
0N/A
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("icon")) {
0N/A icon = (Icon)values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("message")) {
0N/A message = values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("options")) {
0N/A options = (Object[])values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("initialValue")) {
0N/A initialValue = values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("value")) {
0N/A value = values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("selectionValues")) {
0N/A selectionValues = (Object[])values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("inputValue")) {
0N/A inputValue = values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if(indexCounter < maxCounter && values.elementAt(indexCounter).
0N/A equals("initialSelectionValue")) {
0N/A initialSelectionValue = values.elementAt(++indexCounter);
0N/A indexCounter++;
0N/A }
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JOptionPane</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JOptionPane</code>
0N/A */
0N/A protected String paramString() {
0N/A String iconString = (icon != null ?
0N/A icon.toString() : "");
0N/A String initialValueString = (initialValue != null ?
0N/A initialValue.toString() : "");
0N/A String messageString = (message != null ?
0N/A message.toString() : "");
0N/A String messageTypeString;
0N/A if (messageType == ERROR_MESSAGE) {
0N/A messageTypeString = "ERROR_MESSAGE";
0N/A } else if (messageType == INFORMATION_MESSAGE) {
0N/A messageTypeString = "INFORMATION_MESSAGE";
0N/A } else if (messageType == WARNING_MESSAGE) {
0N/A messageTypeString = "WARNING_MESSAGE";
0N/A } else if (messageType == QUESTION_MESSAGE) {
0N/A messageTypeString = "QUESTION_MESSAGE";
0N/A } else if (messageType == PLAIN_MESSAGE) {
0N/A messageTypeString = "PLAIN_MESSAGE";
0N/A } else messageTypeString = "";
0N/A String optionTypeString;
0N/A if (optionType == DEFAULT_OPTION) {
0N/A optionTypeString = "DEFAULT_OPTION";
0N/A } else if (optionType == YES_NO_OPTION) {
0N/A optionTypeString = "YES_NO_OPTION";
0N/A } else if (optionType == YES_NO_CANCEL_OPTION) {
0N/A optionTypeString = "YES_NO_CANCEL_OPTION";
0N/A } else if (optionType == OK_CANCEL_OPTION) {
0N/A optionTypeString = "OK_CANCEL_OPTION";
0N/A } else optionTypeString = "";
0N/A String wantsInputString = (wantsInput ?
0N/A "true" : "false");
0N/A
0N/A return super.paramString() +
0N/A ",icon=" + iconString +
0N/A ",initialValue=" + initialValueString +
0N/A ",message=" + messageString +
0N/A ",messageType=" + messageTypeString +
0N/A ",optionType=" + optionTypeString +
0N/A ",wantsInput=" + wantsInputString;
0N/A }
0N/A
0N/A /**
0N/A * Retrieves a method from the provided class and makes it accessible.
0N/A */
625N/A private static class ModalPrivilegedAction implements PrivilegedAction<Method> {
625N/A private Class<?> clazz;
0N/A private String methodName;
0N/A
625N/A public ModalPrivilegedAction(Class<?> clazz, String methodName) {
0N/A this.clazz = clazz;
0N/A this.methodName = methodName;
0N/A }
0N/A
625N/A public Method run() {
0N/A Method method = null;
0N/A try {
0N/A method = clazz.getDeclaredMethod(methodName, (Class[])null);
0N/A } catch (NoSuchMethodException ex) {
0N/A }
0N/A if (method != null) {
0N/A method.setAccessible(true);
0N/A }
0N/A return method;
0N/A }
0N/A }
0N/A
0N/A
0N/A
0N/A///////////////////
0N/A// Accessibility support
0N/A///////////////////
0N/A
0N/A /**
0N/A * Returns the <code>AccessibleContext</code> associated with this JOptionPane.
0N/A * For option panes, the <code>AccessibleContext</code> takes the form of an
0N/A * <code>AccessibleJOptionPane</code>.
0N/A * A new <code>AccessibleJOptionPane</code> instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJOptionPane that serves as the
0N/A * AccessibleContext of this AccessibleJOptionPane
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: The AccessibleContext associated with this option pane
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJOptionPane();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JOptionPane</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to option pane user-interface
0N/A * elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJOptionPane extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A switch (messageType) {
0N/A case ERROR_MESSAGE:
0N/A case INFORMATION_MESSAGE:
0N/A case WARNING_MESSAGE:
0N/A return AccessibleRole.ALERT;
0N/A
0N/A default:
0N/A return AccessibleRole.OPTION_PANE;
0N/A }
0N/A }
0N/A
0N/A } // inner class AccessibleJOptionPane
0N/A}