jdk/src/share/classes/javax/swing/JOptionPane.java
author cl
Wed, 02 Oct 2013 11:28:07 -0700
changeset 20451 4cedf4e1560a
parent 11809 d65aab67ee8a
child 20455 f6f9a0c2796b
permissions -rw-r--r--
8025409: Fix javadoc comments errors and warning reported by doclint report Reviewed-by: anthony, yan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8757
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1301
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.KeyboardFocusManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.HeadlessException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.event.WindowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.event.WindowAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.ComponentAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.swing.plaf.OptionPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.event.InternalFrameEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.event.InternalFrameAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import static javax.swing.ClientPropertyKey.PopupFactory_FORCE_HEAVYWEIGHT_POPUP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>JOptionPane</code> makes it easy to pop up a standard dialog box that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * prompts users for a value or informs them of something.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * For information about using <code>JOptionPane</code>, see
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 href="http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html">How to Make Dialogs</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * While the <code>JOptionPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * class may appear complex because of the large number of methods, almost
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * all uses of this class are one-line calls to one of the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <code>showXxxDialog</code> methods shown below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <table border=1 summary="Common JOptionPane method names and their descriptions">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *    <th>Method Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *    <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *    <td>showConfirmDialog</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *    <td>Asks a confirming question, like yes/no/cancel.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *    <td>showInputDialog</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *    <td>Prompt for some input.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *   <td>showMessageDialog</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *   <td>Tell the user about something that has happened.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *   <td>showOptionDialog</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   <td>The Grand Unification of the above three.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * Each of these methods also comes in a <code>showInternalXXX</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * flavor, which uses an internal frame to hold the dialog box (see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * {@link JInternalFrame}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * Multiple convenience methods have also been defined -- overloaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * versions of the basic methods that use different parameter lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * All dialogs are modal. Each <code>showXxxDialog</code> method blocks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * the caller until the user's interaction is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   111
 * <table cellspacing=6 cellpadding=4 border=0 style="float:right" summary="layout">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   113
 *  <td style="background-color:#FFe0d0" rowspan=2>icon</td>
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   114
 *  <td style="background-color:#FFe0d0">message</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   117
 *  <td style="background-color:#FFe0d0">input value</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * <tr>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   120
 *   <td style="background-color:#FFe0d0" colspan=2>option buttons</td>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * The basic appearance of one of these dialog boxes is generally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * similar to the picture at the right, although the various
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * look-and-feels are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * ultimately responsible for the final result.  In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * look-and-feels will adjust the layout to accommodate the option pane's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * <code>ComponentOrientation</code> property.
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 11809
diff changeset
   130
 * <br style="clear:all">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * <b>Parameters:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * The parameters to these methods follow consistent patterns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <dl compact>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <dt>parentComponent<dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Defines the <code>Component</code> that is to be the parent of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * dialog box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * It is used in two ways: the <code>Frame</code> that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * it is used as the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * parent for the dialog box, and its screen coordinates are used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * the placement of the dialog box. In general, the dialog box is placed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * just below the component. This parameter may be <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * in which case a default <code>Frame</code> is used as the parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * and the dialog will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * centered on the screen (depending on the L&F).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <dt><a name=message>message</a><dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * A descriptive message to be placed in the dialog box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * In the most common usage, message is just a <code>String</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <code>String</code> constant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * However, the type of this parameter is actually <code>Object</code>. Its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * interpretation depends on its type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <dl compact>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <dt>Object[]<dd>An array of objects is interpreted as a series of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *                 messages (one per object) arranged in a vertical stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *                 The interpretation is recursive -- each object in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *                 array is interpreted according to its type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * <dt>Component<dd>The <code>Component</code> is displayed in the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * <dt>Icon<dd>The <code>Icon</code> is wrapped in a <code>JLabel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *               and displayed in the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <dt>others<dd>The object is converted to a <code>String</code> by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *               its <code>toString</code> method. The result is wrapped in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *               <code>JLabel</code> and displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * <dt>messageType<dd>Defines the style of the message. The Look and Feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * manager may lay out the dialog differently depending on this value, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * will often provide a default icon. The possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <li><code>ERROR_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * <li><code>INFORMATION_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <li><code>WARNING_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <li><code>QUESTION_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * <li><code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <dt>optionType<dd>Defines the set of option buttons that appear at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * the bottom of the dialog box:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * <li><code>DEFAULT_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * <li><code>YES_NO_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * <li><code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <li><code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * You aren't limited to this set of option buttons.  You can provide any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * buttons you want using the options parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * <dt>options<dd>A more detailed description of the set of option buttons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * that will appear at the bottom of the dialog box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * The usual value for the options parameter is an array of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <code>String</code>s. But
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * the parameter type is an array of <code>Objects</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * A button is created for each object depending on its type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * <dl compact>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <dt>Component<dd>The component is added to the button row directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * <dt>Icon<dd>A <code>JButton</code> is created with this as its label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * <dt>other<dd>The <code>Object</code> is converted to a string using its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *              <code>toString</code> method and the result is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 *              label a <code>JButton</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 * value for this is determined by the <code>messageType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <dt>title<dd>The title for the dialog box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * <dt>initialValue<dd>The default selection (input value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * When the selection is changed, <code>setValue</code> is invoked,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * which generates a <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * If a <code>JOptionPane</code> has configured to all input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * <code>setWantsInput</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * the bound property <code>JOptionPane.INPUT_VALUE_PROPERTY</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 *  can also be listened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * to, to determine when the user has input or selected a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 * When one of the <code>showXxxDialog</code> methods returns an integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * the possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 * <li><code>YES_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * <li><code>NO_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * <li><code>CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * <li><code>OK_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * <li><code>CLOSED_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * <b>Examples:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * <dt>Show an error dialog that displays the message, 'alert':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 * <dd><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
 * JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 * <dt>Show an internal information dialog with the message, 'information':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 * <dd><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 * JOptionPane.showInternalMessageDialog(frame, "information",<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *             <ul><ul>"information", JOptionPane.INFORMATION_MESSAGE);</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * <dt>Show an information panel with the options yes/no and message 'choose one':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * <dd><code>JOptionPane.showConfirmDialog(null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 *             <ul><ul>"choose one", "choose one", JOptionPane.YES_NO_OPTION);</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * <dt>Show an internal information dialog with the options yes/no/cancel and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 * message 'please choose one' and title information:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * <dd><code>JOptionPane.showInternalConfirmDialog(frame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 *             <ul><ul>"please choose one", "information",</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 *             <ul><ul>JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * <dt>Show a warning dialog with the options OK, CANCEL, title 'Warning', and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 * message 'Click OK to continue':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 * <dd><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 * Object[] options = { "OK", "CANCEL" };<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 * JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *             <ul><ul>JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *             <ul><ul>null, options, options[0]);</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * <dt>Show a dialog asking the user to type in a String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * <dd><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * String inputValue = JOptionPane.showInputDialog("Please input a value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * <dt>Show a dialog asking the user to select a String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * <dd><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 * Object[] possibleValues = { "First", "Second", "Third" };<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 * Object selectedValue = JOptionPane.showInputDialog(null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *             <ul><ul>"Choose one", "Input",</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *             <ul><ul>JOptionPane.INFORMATION_MESSAGE, null,</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 *             <ul><ul>possibleValues, possibleValues[0]);</ul></ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * </code><p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * <b>Direct Use:</b><br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * To create and use an <code>JOptionPane</code> directly, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * standard pattern is roughly as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 *     JOptionPane pane = new JOptionPane(<i>arguments</i>);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 *     pane.set<i>.Xxxx(...); // Configure</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *     JDialog dialog = pane.createDialog(<i>parentComponent, title</i>);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 *     dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *     Object selectedValue = pane.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 *     if(selectedValue == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 *       return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 *     <i>//If there is <b>not</b> an array of option buttons:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *     if(options == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 *       if(selectedValue instanceof Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
 *          return ((Integer)selectedValue).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
 *       return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
 *     <i>//If there is an array of option buttons:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
 *     for(int counter = 0, maxCounter = options.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
 *        counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
 *        if(options[counter].equals(selectedValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
 *        return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 *     return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
 * @see JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
 * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
 *      attribute: isContainer true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
 *    description: A component which implements standard dialog box controls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
 * @author James Gosling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
public class JOptionPane extends JComponent implements Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    private static final String uiClassID = "OptionPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Indicates that the user has not yet selected a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public static final Object      UNINITIALIZED_VALUE = "uninitializedValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // Option types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Type meaning Look and Feel should not supply any options -- only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * use the options from the <code>JOptionPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public static final int         DEFAULT_OPTION = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /** Type used for <code>showConfirmDialog</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public static final int         YES_NO_OPTION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /** Type used for <code>showConfirmDialog</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public static final int         YES_NO_CANCEL_OPTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /** Type used for <code>showConfirmDialog</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public static final int         OK_CANCEL_OPTION = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    // Return values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /** Return value from class method if YES is chosen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public static final int         YES_OPTION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    /** Return value from class method if NO is chosen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public static final int         NO_OPTION = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /** Return value from class method if CANCEL is chosen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public static final int         CANCEL_OPTION = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /** Return value form class method if OK is chosen. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public static final int         OK_OPTION = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /** Return value from class method if user closes window without selecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * anything, more than likely this should be treated as either a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <code>CANCEL_OPTION</code> or <code>NO_OPTION</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public static final int         CLOSED_OPTION = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    // Message types. Used by the UI to determine what icon to display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    // and possibly what behavior to give based on the type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /** Used for error messages. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public static final int  ERROR_MESSAGE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    /** Used for information messages. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public static final int  INFORMATION_MESSAGE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /** Used for warning messages. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public static final int  WARNING_MESSAGE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /** Used for questions. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public static final int  QUESTION_MESSAGE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    /** No icon is used. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public static final int   PLAIN_MESSAGE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /** Bound property name for <code>icon</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public static final String      ICON_PROPERTY = "icon";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /** Bound property name for <code>message</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public static final String      MESSAGE_PROPERTY = "message";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /** Bound property name for <code>value</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public static final String      VALUE_PROPERTY = "value";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /** Bound property name for <code>option</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public static final String      OPTIONS_PROPERTY = "options";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /** Bound property name for <code>initialValue</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public static final String      INITIAL_VALUE_PROPERTY = "initialValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /** Bound property name for <code>type</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public static final String      MESSAGE_TYPE_PROPERTY = "messageType";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /** Bound property name for <code>optionType</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public static final String      OPTION_TYPE_PROPERTY = "optionType";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /** Bound property name for <code>selectionValues</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public static final String      SELECTION_VALUES_PROPERTY = "selectionValues";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /** Bound property name for <code>initialSelectionValue</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public static final String      INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /** Bound property name for <code>inputValue</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public static final String      INPUT_VALUE_PROPERTY = "inputValue";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /** Bound property name for <code>wantsInput</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public static final String      WANTS_INPUT_PROPERTY = "wantsInput";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /** Icon used in pane. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    transient protected Icon                  icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /** Message to display. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    transient protected Object                message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /** Options to display to the user. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    transient protected Object[]              options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /** Value that should be initially selected in <code>options</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    transient protected Object                initialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /** Message type. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    protected int                   messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Option type, one of <code>DEFAULT_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <code>YES_NO_CANCEL_OPTION</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <code>OK_CANCEL_OPTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    protected int                   optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    /** Currently selected value, will be a valid option, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * <code>UNINITIALIZED_VALUE</code> or <code>null</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    transient protected Object                value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /** Array of values the user can choose from. Look and feel will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * provide the UI component to choose this from. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    protected transient Object[]              selectionValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /** Value the user has input. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    protected transient Object                inputValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /** Initial value to select in <code>selectionValues</code>. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    protected transient Object                initialSelectionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /** If true, a UI widget will be provided to the user to get input. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    protected boolean                         wantsInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Shows a question-message dialog requesting input from the user. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * dialog uses the default frame, which usually means it is centered on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public static String showInputDialog(Object message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return showInputDialog(null, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Shows a question-message dialog requesting input from the user, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * the input value initialized to <code>initialSelectionValue</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * dialog uses the default frame, which usually means it is centered on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @param initialSelectionValue the value used to initialize the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *                 field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public static String showInputDialog(Object message, Object initialSelectionValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return showInputDialog(null, message, initialSelectionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * Shows a question-message dialog requesting input from the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * parented to <code>parentComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * The dialog is displayed on top of the <code>Component</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * frame, and is usually positioned below the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @param parentComponent  the parent <code>Component</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *          dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *    <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *    <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    public static String showInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        Object message) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        return showInputDialog(parentComponent, message, UIManager.getString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            "OptionPane.inputDialogTitle", parentComponent), QUESTION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * Shows a question-message dialog requesting input from the user and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * parented to <code>parentComponent</code>. The input value will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * initialized to <code>initialSelectionValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * The dialog is displayed on top of the <code>Component</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * frame, and is usually positioned below the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param parentComponent  the parent <code>Component</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *          dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @param initialSelectionValue the value used to initialize the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *                 field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    public static String showInputDialog(Component parentComponent, Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                                         Object initialSelectionValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return (String)showInputDialog(parentComponent, message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                      UIManager.getString("OptionPane.inputDialogTitle",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                      parentComponent), QUESTION_MESSAGE, null, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                      initialSelectionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Shows a dialog requesting input from the user parented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * <code>parentComponent</code> with the dialog having the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <code>title</code> and message type <code>messageType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @param parentComponent  the parent <code>Component</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *                  dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @param title    the <code>String</code> to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *                  title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param messageType the type of message that is to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public static String showInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        Object message, String title, int messageType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return (String)showInputDialog(parentComponent, message, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                       messageType, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * Prompts the user for input in a blocking dialog where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * initial selection, possible selections, and all other options can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * be specified. The user will able to choose from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>selectionValues</code>, where <code>null</code> implies the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * user can input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * whatever they wish, usually by means of a <code>JTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <code>initialSelectionValue</code> is the initial value to prompt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * the user with. It is up to the UI to decide how best to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * the <code>selectionValues</code>, but usually a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * <code>JComboBox</code>, <code>JList</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <code>JTextField</code> will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @param parentComponent  the parent <code>Component</code> for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     *                  dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @param title    the <code>String</code> to display in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *                  dialog title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param icon     the <code>Icon</code> image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @param selectionValues an array of <code>Object</code>s that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *                  gives the possible selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param initialSelectionValue the value used to initialize the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *                 field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @return user's input, or <code>null</code> meaning the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *                  canceled the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public static Object showInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        Object message, String title, int messageType, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        Object[] selectionValues, Object initialSelectionValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        JOptionPane    pane = new JOptionPane(message, messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                              OK_CANCEL_OPTION, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        pane.setWantsInput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        pane.setSelectionValues(selectionValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        pane.setInitialSelectionValue(initialSelectionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        pane.setComponentOrientation(((parentComponent == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            getRootFrame() : parentComponent).getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        int style = styleFromMessageType(messageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        JDialog dialog = pane.createDialog(parentComponent, title, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        pane.selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        Object value = pane.getInputValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        if (value == UNINITIALIZED_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Brings up an information-message dialog titled "Message".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @param parentComponent determines the <code>Frame</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *          which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public static void showMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        Object message) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        showMessageDialog(parentComponent, message, UIManager.getString(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    "OptionPane.messageDialogTitle", parentComponent),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    INFORMATION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Brings up a dialog that displays a message using a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * icon determined by the <code>messageType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    public static void showMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        Object message, String title, int messageType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        showMessageDialog(parentComponent, message, title, messageType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Brings up a dialog displaying a message, specifying all parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @param parentComponent determines the <code>Frame</code> in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *                  dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *                  or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *                  default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @param icon      an icon to display in the dialog that helps the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *                  identify the kind of message that is being displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    public static void showMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        Object message, String title, int messageType, Icon icon)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        showOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                         messageType, icon, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Brings up a dialog with the options <i>Yes</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <i>No</i> and <i>Cancel</i>; with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * title, <b>Select an Option</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * @param parentComponent determines the <code>Frame</code> in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *                  dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *                  or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *                  default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    public static int showConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        Object message) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return showConfirmDialog(parentComponent, message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                 UIManager.getString("OptionPane.titleText"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                                 YES_NO_CANCEL_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * Brings up a dialog where the number of choices is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * by the <code>optionType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @param parentComponent determines the <code>Frame</code> in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     *                  dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *                  or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *                  default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param optionType an int designating the options available on the dialog:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *                  or <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @return an int indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    public static int showConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        Object message, String title, int optionType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        return showConfirmDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                 QUESTION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Brings up a dialog where the number of choices is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * by the <code>optionType</code> parameter, where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * <code>messageType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * parameter determines the icon to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * a default icon from the Look and Feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @param parentComponent determines the <code>Frame</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *                  which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *                  or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *                  default <code>Frame</code> is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @param optionType an integer designating the options available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *                   on the dialog: <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *                  or <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @param messageType an integer designating the kind of message this is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *                  primarily used to determine the icon from the pluggable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *                  Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    public static int showConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        Object message, String title, int optionType, int messageType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        return showConfirmDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                                messageType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Brings up a dialog with a specified icon, where the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * choices is determined by the <code>optionType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * a default icon from the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @param parentComponent determines the <code>Frame</code> in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     *                  dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *                  or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *                  default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @param message   the Object to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @param optionType an int designating the options available on the dialog:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *                  or <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param messageType an int designating the kind of message this is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *                  primarily used to determine the icon from the pluggable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *                  Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @param icon      the icon to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @return an int indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    public static int showConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        Object message, String title, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        int messageType, Icon icon) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        return showOptionDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                messageType, icon, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Brings up a dialog with a specified icon, where the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * choice is determined by the <code>initialValue</code> parameter and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * the number of choices is determined by the <code>optionType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * If <code>optionType</code> is <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * or <code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * and the <code>options</code> parameter is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * then the options are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * supplied by the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * a default icon from the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *                  in which the dialog is displayed;  if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *                  <code>null</code>, or if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *                  <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *                  <code>Frame</code>, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *                  default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @param optionType an integer designating the options available on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *                  dialog: <code>DEFAULT_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *                  or <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @param messageType an integer designating the kind of message this is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *                  primarily used to determine the icon from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *                  pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * @param icon      the icon to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @param options   an array of objects indicating the possible choices
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *                  the user can make; if the objects are components, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     *                  are rendered properly; non-<code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *                  objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *                  rendered using their <code>toString</code> methods;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     *                  if this parameter is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *                  the options are determined by the Look and Feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @param initialValue the object that represents the default selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *                  for the dialog; only meaningful if <code>options</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *                  is used; can be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @return an integer indicating the option chosen by the user,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *                  or <code>CLOSED_OPTION</code> if the user closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *                  the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public static int showOptionDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        Object message, String title, int optionType, int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        Icon icon, Object[] options, Object initialValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        JOptionPane             pane = new JOptionPane(message, messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                                       optionType, icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                                                       options, initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        pane.setInitialValue(initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        pane.setComponentOrientation(((parentComponent == null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            getRootFrame() : parentComponent).getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        int style = styleFromMessageType(messageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        JDialog dialog = pane.createDialog(parentComponent, title, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        pane.selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        dialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        Object        selectedValue = pane.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        if(selectedValue == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if(options == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            if(selectedValue instanceof Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                return ((Integer)selectedValue).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        for(int counter = 0, maxCounter = options.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            if(options[counter].equals(selectedValue))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * Creates and returns a new <code>JDialog</code> wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <code>this</code> centered on the <code>parentComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * in the <code>parentComponent</code>'s frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * <code>title</code> is the title of the returned dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * The returned <code>JDialog</code> will not be resizable by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * user, however programs can invoke <code>setResizable</code> on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * the <code>JDialog</code> instance to change this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * The returned <code>JDialog</code> will be set up such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * once it is closed, or the user clicks on one of the buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * the optionpane's value property will be set accordingly and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * the dialog will be closed.  Each time the dialog is made visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * it will reset the option pane's value property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * <code>JOptionPane.UNINITIALIZED_VALUE</code> to ensure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * user's subsequent action closes the dialog properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @param parentComponent determines the frame in which the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *          is displayed; if the <code>parentComponent</code> has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *          no <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @return a new <code>JDialog</code> containing this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    public JDialog createDialog(Component parentComponent, String title)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        int style = styleFromMessageType(getMessageType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        return createDialog(parentComponent, title, style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * Creates and returns a new parentless <code>JDialog</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * with the specified title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * The returned <code>JDialog</code> will not be resizable by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * user, however programs can invoke <code>setResizable</code> on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * the <code>JDialog</code> instance to change this property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * The returned <code>JDialog</code> will be set up such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * once it is closed, or the user clicks on one of the buttons,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * the optionpane's value property will be set accordingly and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * the dialog will be closed.  Each time the dialog is made visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * it will reset the option pane's value property to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * <code>JOptionPane.UNINITIALIZED_VALUE</code> to ensure the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * user's subsequent action closes the dialog properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @return a new <code>JDialog</code> containing this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public JDialog createDialog(String title) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        int style = styleFromMessageType(getMessageType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        JDialog dialog = new JDialog((Dialog) null, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        initDialog(dialog, style, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    private JDialog createDialog(Component parentComponent, String title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            int style)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        final JDialog dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        Window window = JOptionPane.getWindowForComponent(parentComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        if (window instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            dialog = new JDialog((Frame)window, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            dialog = new JDialog((Dialog)window, title, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if (window instanceof SwingUtilities.SharedOwnerFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            WindowListener ownerShutdownListener =
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
   965
                    SwingUtilities.getSharedOwnerFrameShutdownListener();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            dialog.addWindowListener(ownerShutdownListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        initDialog(dialog, style, parentComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        return dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    private void initDialog(final JDialog dialog, int style, Component parentComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        dialog.setComponentOrientation(this.getComponentOrientation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        Container contentPane = dialog.getContentPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        contentPane.setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        contentPane.add(this, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        dialog.setResizable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (JDialog.isDefaultLookAndFeelDecorated()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            boolean supportsWindowDecorations =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
              UIManager.getLookAndFeel().getSupportsWindowDecorations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            if (supportsWindowDecorations) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                dialog.setUndecorated(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                getRootPane().setWindowDecorationStyle(style);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        dialog.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        dialog.setLocationRelativeTo(parentComponent);
8757
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   989
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   990
        final PropertyChangeListener listener = new PropertyChangeListener() {
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   991
            public void propertyChange(PropertyChangeEvent event) {
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   992
                // Let the defaultCloseOperation handle the closing
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   993
                // if the user closed the window without selecting a button
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   994
                // (newValue = null in that case).  Otherwise, close the dialog.
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   995
                if (dialog.isVisible() && event.getSource() == JOptionPane.this &&
11809
d65aab67ee8a 7138665: JOptionPane.getValue() unexpected change between JRE 1.6 and JRE 1.7
rupashka
parents: 9035
diff changeset
   996
                        (event.getPropertyName().equals(VALUE_PROPERTY)) &&
8757
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   997
                        event.getNewValue() != null &&
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   998
                        event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
   999
                    dialog.setVisible(false);
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1000
                }
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1001
            }
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1002
        };
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1003
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        WindowAdapter adapter = new WindowAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            private boolean gotFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            public void windowClosing(WindowEvent we) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                setValue(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }
8757
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1009
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1010
            public void windowClosed(WindowEvent e) {
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1011
                removePropertyChangeListener(listener);
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1012
                dialog.getContentPane().removeAll();
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1013
            }
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1014
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            public void windowGainedFocus(WindowEvent we) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                // Once window gets focus, set initial focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                if (!gotFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                    selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                    gotFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        dialog.addWindowListener(adapter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        dialog.addWindowFocusListener(adapter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        dialog.addComponentListener(new ComponentAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            public void componentShown(ComponentEvent ce) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                // reset value to ensure closing works properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                setValue(JOptionPane.UNINITIALIZED_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        });
8757
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1031
2afba8862932 6464022: Memory leak in JOptionPane.createDialog
rupashka
parents: 5506
diff changeset
  1032
        addPropertyChangeListener(listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * Brings up an internal confirmation dialog panel. The dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * is a information-message dialog titled "Message".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * @param message   the object to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    public static void showInternalMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                                                 Object message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        showInternalMessageDialog(parentComponent, message, UIManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                 getString("OptionPane.messageDialogTitle",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                 parentComponent), INFORMATION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * Brings up an internal dialog panel that displays a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * using a default icon determined by the <code>messageType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
    public static void showInternalMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                                 Object message, String title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                                 int messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        showInternalMessageDialog(parentComponent, message, title, messageType,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * Brings up an internal dialog panel displaying a message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * specifying all parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * @param icon      an icon to display in the dialog that helps the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *                  identify the kind of message that is being displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    public static void showInternalMessageDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                                         Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                         String title, int messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                                         Icon icon){
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        showInternalOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                                 messageType, icon, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * Brings up an internal dialog panel with the options <i>Yes</i>, <i>No</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * and <i>Cancel</i>; with the title, <b>Select an Option</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @param parentComponent determines the <code>Frame</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     *          which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * @param message   the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    public static int showInternalConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                                                Object message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        return showInternalConfirmDialog(parentComponent, message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                                 UIManager.getString("OptionPane.titleText"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                                 YES_NO_CANCEL_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * Brings up a internal dialog panel where the number of choices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * is determined by the <code>optionType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @param message   the object to display in the dialog; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *          <code>Component</code> object is rendered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     *          <code>Component</code>; a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     *          object is rendered as a string; other objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *          are converted to a <code>String</code> using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     *          <code>toString</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @param optionType an integer designating the options
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *          available on the dialog: <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *          or <code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    public static int showInternalConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                                                Object message, String title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                                                int optionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        return showInternalConfirmDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                                         QUESTION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * Brings up an internal dialog panel where the number of choices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * is determined by the <code>optionType</code> parameter, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * the <code>messageType</code> parameter determines the icon to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * a default icon from the Look and Feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @param parentComponent determines the <code>Frame</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     *          which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @param message   the object to display in the dialog; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     *          <code>Component</code> object is rendered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     *          <code>Component</code>; a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *          object is rendered as a string; other objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     *          converted to a <code>String</code> using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *          <code>toString</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * @param optionType an integer designating the options
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *          available on the dialog:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *          <code>YES_NO_OPTION</code>, or <code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * @param messageType an integer designating the kind of message this is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *          primarily used to determine the icon from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *          pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *          <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     *          <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *          or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    public static int showInternalConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                                        Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                        String title, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                                        int messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        return showInternalConfirmDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                                         messageType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * Brings up an internal dialog panel with a specified icon, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * the number of choices is determined by the <code>optionType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * a default icon from the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *          or if the parentComponent has no Frame, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *          default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @param message   the object to display in the dialog; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *          <code>Component</code> object is rendered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *          <code>Component</code>; a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     *          object is rendered as a string; other objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *          converted to a <code>String</code> using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *          <code>toString</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * @param optionType an integer designating the options available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *          on the dialog:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *          <code>YES_NO_OPTION</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *          <code>YES_NO_CANCEL_OPTION</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @param messageType an integer designating the kind of message this is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     *          primarily used to determine the icon from the pluggable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *          Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     *          <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *          <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *          or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @param icon      the icon to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @return an integer indicating the option selected by the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    public static int showInternalConfirmDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                                        Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                                        String title, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                                        int messageType, Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        return showInternalOptionDialog(parentComponent, message, title, optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                        messageType, icon, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     * Brings up an internal dialog panel with a specified icon, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * the initial choice is determined by the <code>initialValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * parameter and the number of choices is determined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * <code>optionType</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * If <code>optionType</code> is <code>YES_NO_OPTION</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * <code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * and the <code>options</code> parameter is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * then the options are supplied by the Look and Feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * The <code>messageType</code> parameter is primarily used to supply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * a default icon from the look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @param parentComponent determines the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     *          in which the dialog is displayed; if <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *          or if the <code>parentComponent</code> has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *          <code>Frame</code>, a default <code>Frame</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @param message   the object to display in the dialog; a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     *          <code>Component</code> object is rendered as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *          <code>Component</code>; a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *          object is rendered as a string. Other objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *          converted to a <code>String</code> using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *          <code>toString</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @param title     the title string for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * @param optionType an integer designating the options available
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     *          on the dialog: <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     *          or <code>YES_NO_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * @param messageType an integer designating the kind of message this is;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     *          primarily used to determine the icon from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     *          pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *          <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     *          <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     *          or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * @param icon      the icon to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * @param options   an array of objects indicating the possible choices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     *          the user can make; if the objects are components, they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *          are rendered properly; non-<code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *          objects are rendered using their <code>toString</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     *          methods; if this parameter is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     *          the options are determined by the Look and Feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * @param initialValue the object that represents the default selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     *          for the dialog; only meaningful if <code>options</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     *          is used; can be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * @return an integer indicating the option chosen by the user,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     *          or <code>CLOSED_OPTION</code> if the user closed the Dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    public static int showInternalOptionDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                                       Object message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                                       String title, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                                       int messageType, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                                       Object[] options, Object initialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        JOptionPane pane = new JOptionPane(message, messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                optionType, icon, options, initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        pane.setInitialValue(initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        JInternalFrame dialog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            pane.createInternalFrame(parentComponent, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        pane.selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        /* Since all input will be blocked until this dialog is dismissed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * make sure its parent containers are visible first (this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         * is tested below).  This is necessary for JApplets, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * because an applet normally isn't made visible until after its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         * start() method returns -- if this method is called from start(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         * the applet will appear to hang while an invisible modal frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         * waits for input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        if (dialog.isVisible() && !dialog.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            Container parent = dialog.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            while (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                if (parent.isVisible() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    parent.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        // Use reflection to get Container.startLWModal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1311
            Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    Container.class, "startLWModal"));
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1313
            if (method != null) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1314
                method.invoke(dialog, (Object[])null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        } catch (IllegalArgumentException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        } catch (InvocationTargetException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if (parentComponent instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                ((JInternalFrame)parentComponent).setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            } catch (java.beans.PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        Object selectedValue = pane.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if (fo != null && fo.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            fo.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        if (selectedValue == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        if (options == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            if (selectedValue instanceof Integer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                return ((Integer)selectedValue).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        for(int counter = 0, maxCounter = options.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            if (options[counter].equals(selectedValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        return CLOSED_OPTION;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * Shows an internal question-message dialog requesting input from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * the user parented to <code>parentComponent</code>. The dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * is displayed in the <code>Component</code>'s frame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * and is usually positioned below the <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * @param parentComponent  the parent <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *          for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    public static String showInternalInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                                                 Object message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        return showInternalInputDialog(parentComponent, message, UIManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
               getString("OptionPane.inputDialogTitle", parentComponent),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
               QUESTION_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * Shows an internal dialog requesting input from the user parented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * to <code>parentComponent</code> with the dialog having the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * <code>title</code> and message type <code>messageType</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * @param parentComponent the parent <code>Component</code> for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * @param title    the <code>String</code> to display in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     *          dialog title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * @param messageType the type of message that is to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     *                    ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     *                    QUESTION_MESSAGE, or PLAIN_MESSAGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    public static String showInternalInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                             Object message, String title, int messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        return (String)showInternalInputDialog(parentComponent, message, title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                                       messageType, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * Prompts the user for input in a blocking internal dialog where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * the initial selection, possible selections, and all other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * options can be specified. The user will able to choose from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * <code>selectionValues</code>, where <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * implies the user can input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * whatever they wish, usually by means of a <code>JTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * <code>initialSelectionValue</code> is the initial value to prompt
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * the user with. It is up to the UI to decide how best to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * the <code>selectionValues</code>, but usually a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * <code>JComboBox</code>, <code>JList</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * <code>JTextField</code> will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * @param parentComponent the parent <code>Component</code> for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * @param message  the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * @param title    the <code>String</code> to display in the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     *          title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *                  <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     *                  <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * @param icon     the <code>Icon</code> image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * @param selectionValues an array of <code>Objects</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     *                  gives the possible selections
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @param initialSelectionValue the value used to initialize the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     *                  field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * @return user's input, or <code>null</code> meaning the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     *          canceled the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    public static Object showInternalInputDialog(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            Object message, String title, int messageType, Icon icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            Object[] selectionValues, Object initialSelectionValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        JOptionPane pane = new JOptionPane(message, messageType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                OK_CANCEL_OPTION, icon, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        pane.setWantsInput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        pane.setSelectionValues(selectionValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        pane.setInitialSelectionValue(initialSelectionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        JInternalFrame dialog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            pane.createInternalFrame(parentComponent, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        pane.selectInitialValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        /* Since all input will be blocked until this dialog is dismissed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
         * make sure its parent containers are visible first (this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
         * is tested below).  This is necessary for JApplets, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
         * because an applet normally isn't made visible until after its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         * start() method returns -- if this method is called from start(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         * the applet will appear to hang while an invisible modal frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
         * waits for input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        if (dialog.isVisible() && !dialog.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            Container parent = dialog.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            while (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                if (parent.isVisible() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                    parent.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        // Use reflection to get Container.startLWModal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1456
            Method method = AccessController.doPrivileged(new ModalPrivilegedAction(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                    Container.class, "startLWModal"));
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1458
            if (method != null) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1459
                method.invoke(dialog, (Object[])null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        } catch (IllegalArgumentException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        } catch (InvocationTargetException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        if (parentComponent instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                ((JInternalFrame)parentComponent).setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            } catch (java.beans.PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        if (fo != null && fo.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            fo.requestFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        Object value = pane.getInputValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        if (value == UNINITIALIZED_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * Creates and returns an instance of <code>JInternalFrame</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * The internal frame is created with the specified title,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * and wrapping the <code>JOptionPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     * The returned <code>JInternalFrame</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * added to the <code>JDesktopPane</code> ancestor of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * <code>parentComponent</code>, or components
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * parent if one its ancestors isn't a <code>JDesktopPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * or if <code>parentComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * doesn't have a parent then a <code>RuntimeException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * @param parentComponent  the parent <code>Component</code> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     *          the internal frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * @param title    the <code>String</code> to display in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     *          frame's title bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * @return a <code>JInternalFrame</code> containing a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *          <code>JOptionPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * @exception RuntimeException if <code>parentComponent</code> does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     *          not have a valid parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
    public JInternalFrame createInternalFrame(Component parentComponent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                                 String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        Container parent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                JOptionPane.getDesktopPaneForComponent(parentComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        if (parent == null && (parentComponent == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                (parent = parentComponent.getParent()) == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            throw new RuntimeException("JOptionPane: parentComponent does " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
                    "not have a valid parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        // Option dialogs should be closable only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        final JInternalFrame  iFrame = new JInternalFrame(title, false, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                                                           false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        iFrame.putClientProperty("JInternalFrame.frameType", "optionDialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        iFrame.putClientProperty("JInternalFrame.messageType",
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1521
                                 Integer.valueOf(getMessageType()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        iFrame.addInternalFrameListener(new InternalFrameAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            public void internalFrameClosing(InternalFrameEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                if (getValue() == UNINITIALIZED_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                    setValue(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        addPropertyChangeListener(new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            public void propertyChange(PropertyChangeEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                // Let the defaultCloseOperation handle the closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                // if the user closed the iframe without selecting a button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                // (newValue = null in that case).  Otherwise, close the dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                if (iFrame.isVisible() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                        event.getSource() == JOptionPane.this &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                        event.getPropertyName().equals(VALUE_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                // Use reflection to get Container.stopLWModal().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                try {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1540
                    Method method = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                        new ModalPrivilegedAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                            Container.class, "stopLWModal"));
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1543
                    if (method != null) {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1544
                        method.invoke(iFrame, (Object[])null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                } catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                } catch (IllegalArgumentException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                } catch (InvocationTargetException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                    iFrame.setClosed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                catch (java.beans.PropertyVetoException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                iFrame.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        iFrame.getContentPane().add(this, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        if (parent instanceof JDesktopPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            parent.add(iFrame, JLayeredPane.MODAL_LAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            parent.add(iFrame, BorderLayout.CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        Dimension iFrameSize = iFrame.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        Dimension rootSize = parent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        Dimension parentSize = parentComponent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        iFrame.setBounds((rootSize.width - iFrameSize.width) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                         (rootSize.height - iFrameSize.height) / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                         iFrameSize.width, iFrameSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        // We want dialog centered relative to its parent component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        Point iFrameCoord =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
          SwingUtilities.convertPoint(parentComponent, 0, 0, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        int x = (parentSize.width - iFrameSize.width) / 2 + iFrameCoord.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
        int y = (parentSize.height - iFrameSize.height) / 2 + iFrameCoord.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        // If possible, dialog should be fully visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
        int ovrx = x + iFrameSize.width - rootSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        int ovry = y + iFrameSize.height - rootSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        x = Math.max((ovrx > 0? x - ovrx: x), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        y = Math.max((ovry > 0? y - ovry: y), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        iFrame.setBounds(x, y, iFrameSize.width, iFrameSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        parent.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            iFrame.setSelected(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        } catch (java.beans.PropertyVetoException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        return iFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * Returns the specified component's <code>Frame</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * @param parentComponent the <code>Component</code> to check for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     *          <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     * @return the <code>Frame</code> that contains the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     *          or <code>getRootFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     *          if the component is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     *          or does not have a valid <code>Frame</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * @see #getRootFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    public static Frame getFrameForComponent(Component parentComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        if (parentComponent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
            return getRootFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
        if (parentComponent instanceof Frame)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            return (Frame)parentComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        return JOptionPane.getFrameForComponent(parentComponent.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * Returns the specified component's toplevel <code>Frame</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * <code>Dialog</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * @param parentComponent the <code>Component</code> to check for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     *          <code>Frame</code> or <code>Dialog</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * @return the <code>Frame</code> or <code>Dialog</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     *          contains the component, or the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     *          frame if the component is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     *          or does not have a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     *          <code>Frame</code> or <code>Dialog</code> parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    static Window getWindowForComponent(Component parentComponent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        if (parentComponent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            return getRootFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        if (parentComponent instanceof Frame || parentComponent instanceof Dialog)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            return (Window)parentComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        return JOptionPane.getWindowForComponent(parentComponent.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
     * Returns the specified component's desktop pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
     * @param parentComponent the <code>Component</code> to check for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
     *          desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
     * @return the <code>JDesktopPane</code> that contains the component,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
     *          or <code>null</code> if the component is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
     *          or does not have an ancestor that is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     *          <code>JInternalFrame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    public static JDesktopPane getDesktopPaneForComponent(Component parentComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        if(parentComponent == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        if(parentComponent instanceof JDesktopPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            return (JDesktopPane)parentComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        return getDesktopPaneForComponent(parentComponent.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    private static final Object sharedFrameKey = JOptionPane.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * Sets the frame to use for class methods in which a frame is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * not provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
     * <strong>Note:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
     * It is recommended that rather than using this method you supply a valid parent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * @param newRootFrame the default <code>Frame</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    public static void setRootFrame(Frame newRootFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        if (newRootFrame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            SwingUtilities.appContextPut(sharedFrameKey, newRootFrame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            SwingUtilities.appContextRemove(sharedFrameKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
     * Returns the <code>Frame</code> to use for the class methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
     * which a frame is not provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
     * @return the default <code>Frame</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * @see #setRootFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    public static Frame getRootFrame() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        Frame sharedFrame =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            (Frame)SwingUtilities.appContextGet(sharedFrameKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        if (sharedFrame == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            sharedFrame = SwingUtilities.getSharedOwnerFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            SwingUtilities.appContextPut(sharedFrameKey, sharedFrame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        return sharedFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * Creates a <code>JOptionPane</code> with a test message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
    public JOptionPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        this("JOptionPane message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * Creates a instance of <code>JOptionPane</code> to display a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * message using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * plain-message message type and the default options delivered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * the UI.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    public JOptionPane(Object message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        this(message, PLAIN_MESSAGE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * Creates an instance of <code>JOptionPane</code> to display a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * with the specified message type and the default options,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
    public JOptionPane(Object message, int messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        this(message, messageType, DEFAULT_OPTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
     * Creates an instance of <code>JOptionPane</code> to display a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
     * with the specified message type and options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * @param optionType the options to display in the pane:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     *                  <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     *                  <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    public JOptionPane(Object message, int messageType, int optionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
        this(message, messageType, optionType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * Creates an instance of <code>JOptionPane</code> to display a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * with the specified message type, options, and icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * @param optionType the options to display in the pane:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     *                  <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     *                  <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * @param icon the <code>Icon</code> image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
    public JOptionPane(Object message, int messageType, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                       Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        this(message, messageType, optionType, icon, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * Creates an instance of <code>JOptionPane</code> to display a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * with the specified message type, icon, and options.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * None of the options is initially selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * The options objects should contain either instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * <code>Component</code>s, (which are added directly) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * <code>Strings</code> (which are wrapped in a <code>JButton</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * If you provide <code>Component</code>s, you must ensure that when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * <code>Component</code> is clicked it messages <code>setValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * in the created <code>JOptionPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @param optionType the options to display in the pane:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     *                  <code>DEFAULT_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     *                  <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * @param icon the <code>Icon</code> image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * @param options  the choices the user can select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    public JOptionPane(Object message, int messageType, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                       Icon icon, Object[] options) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        this(message, messageType, optionType, icon, options, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * Creates an instance of <code>JOptionPane</code> to display a message
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * with the specified message type, icon, and options, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * initially-selected option specified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * @param message the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @param messageType the type of message to be displayed:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     *                  <code>ERROR_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     *                  <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     *                  <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     *                  <code>QUESTION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     *                  or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * @param optionType the options to display in the pane:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     *                  <code>DEFAULT_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     *                  <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * @param icon the Icon image to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @param options  the choices the user can select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * @param initialValue the choice that is initially selected; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     *                  <code>null</code>, then nothing will be initially selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     *                  only meaningful if <code>options</code> is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
    public JOptionPane(Object message, int messageType, int optionType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                       Icon icon, Object[] options, Object initialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        this.message = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        this.options = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        this.initialValue = initialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
        this.icon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        setMessageType(messageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        setOptionType(optionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
        value = UNINITIALIZED_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        inputValue = UNINITIALIZED_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * Sets the UI object which implements the L&F for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * @param ui  the <code>OptionPaneUI</code> L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     *      hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * description: The UI object that implements the optionpane's LookAndFeel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    public void setUI(OptionPaneUI ui) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  1860
        if (this.ui != ui) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * Returns the UI object which implements the L&F for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * @return the <code>OptionPaneUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
    public OptionPaneUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        return (OptionPaneUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * Notification from the <code>UIManager</code> that the L&F has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     * Replaces the current UI object with the latest version from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     * <code>UIManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
        setUI((OptionPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * Returns the name of the UI class that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * L&F for this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * @return the string "OptionPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * Sets the option pane's message-object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @param newMessage the <code>Object</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     * @see #getMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     *   bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * description: The optionpane's message object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
    public void setMessage(Object newMessage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        Object           oldMessage = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        message = newMessage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        firePropertyChange(MESSAGE_PROPERTY, oldMessage, message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * Returns the message-object this pane displays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * @see #setMessage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * @return the <code>Object</code> that is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
    public Object getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * Sets the icon to display. If non-<code>null</code>, the look and feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * does not provide an icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * @param newIcon the <code>Icon</code> to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @see #getIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * description: The option pane's type icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    public void setIcon(Icon newIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        Object              oldIcon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        icon = newIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        firePropertyChange(ICON_PROPERTY, oldIcon, icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * Returns the icon this pane displays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * @return the <code>Icon</code> that is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @see #setIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    public Icon getIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
        return icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * Sets the value the user has chosen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @param newValue  the chosen value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * @see #getValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * description: The option pane's value object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
    public void setValue(Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
        Object               oldValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        value = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        firePropertyChange(VALUE_PROPERTY, oldValue, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
     * Returns the value the user has selected. <code>UNINITIALIZED_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
     * implies the user has not yet made a choice, <code>null</code> means the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
     * user closed the window with out choosing anything. Otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
     * the returned value will be one of the options defined in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
     * @return the <code>Object</code> chosen by the user,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
     *         <code>UNINITIALIZED_VALUE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
     *         if the user has not yet made a choice, or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
     *         the user closed the window without making a choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
     * @see #setValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
    public Object getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * Sets the options this pane displays. If an element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * <code>newOptions</code> is a <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * it is added directly to the pane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     * otherwise a button is created for the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * @param newOptions an array of <code>Objects</code> that create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     *          buttons the user can click on, or arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     *          <code>Components</code> to add to the pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     * @see #getOptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * description: The option pane's options objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    public void setOptions(Object[] newOptions) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        Object[]           oldOptions = options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        options = newOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        firePropertyChange(OPTIONS_PROPERTY, oldOptions, options);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * Returns the choices the user can make.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * @return the array of <code>Objects</code> that give the user's choices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     * @see #setOptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    public Object[] getOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        if(options != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            int             optionCount = options.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            Object[]        retOptions = new Object[optionCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            System.arraycopy(options, 0, retOptions, 0, optionCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
            return retOptions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        return options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * Sets the initial value that is to be enabled -- the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * that has the focus when the pane is initially displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * @param newInitialValue the <code>Object</code> that gets the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     *                         keyboard focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * @see #getInitialValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * description: The option pane's initial value object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
    public void setInitialValue(Object newInitialValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        Object            oldIV = initialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
        initialValue = newInitialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        firePropertyChange(INITIAL_VALUE_PROPERTY, oldIV, initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * Returns the initial value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * @return the <code>Object</code> that gets the initial keyboard focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * @see #setInitialValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    public Object getInitialValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
        return initialValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * Sets the option pane's message type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * The message type is used by the Look and Feel to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * icon to display (if not supplied) as well as potentially how to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * lay out the <code>parentComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * @param newType an integer specifying the kind of message to display:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *                <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *                <code>WARNING_MESSAGE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *                <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     * @exception RuntimeException if <code>newType</code> is not one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     *          legal values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * @see #getMessageType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * description: The option pane's message type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
    public void setMessageType(int newType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
           newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
           newType != PLAIN_MESSAGE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        int           oldType = messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        messageType = newType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     * Returns the message type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * @return an integer specifying the message type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * @see #setMessageType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
    public int getMessageType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        return messageType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     * Sets the options to display.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * The option type is used by the Look and Feel to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * determine what buttons to show (unless options are supplied).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * @param newType an integer specifying the options the L&F is to display:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     *                  <code>DEFAULT_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     *                  <code>YES_NO_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     *                  <code>YES_NO_CANCEL_OPTION</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     *                  or <code>OK_CANCEL_OPTION</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * @exception RuntimeException if <code>newType</code> is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     *          the legal values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @see #getOptionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * @see #setOptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * description: The option pane's option type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
    public void setOptionType(int newType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
           newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
            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");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        int            oldType = optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        optionType = newType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
        firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * Returns the type of options that are displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * @return an integer specifying the user-selectable options
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * @see #setOptionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
    public int getOptionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        return optionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * Sets the input selection values for a pane that provides the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * with a list of items to choose from. (The UI provides a widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     * for choosing one of the values.)  A <code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
     * implies the user can input whatever they wish, usually by means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
     * of a <code>JTextField</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
     * Sets <code>wantsInput</code> to true. Use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
     * <code>setInitialSelectionValue</code> to specify the initially-chosen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
     * value. After the pane as been enabled, <code>inputValue</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
     * set to the value the user has selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
     * @param newValues an array of <code>Objects</code> the user to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
     *                  displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
     *                  (usually in a list or combo-box) from which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
     *                  the user can make a selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
     * @see #setWantsInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
     * @see #setInitialSelectionValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
     * @see #getSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * description: The option pane's selection values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    public void setSelectionValues(Object[] newValues) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
        Object[]           oldValues = selectionValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
        selectionValues = newValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        firePropertyChange(SELECTION_VALUES_PROPERTY, oldValues, newValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        if(selectionValues != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            setWantsInput(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * Returns the input selection values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * @return the array of <code>Objects</code> the user can select
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    public Object[] getSelectionValues() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        return selectionValues;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     * Sets the input value that is initially displayed as selected to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * Only used if <code>wantsInput</code> is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * @param newValue the initially selected value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * @see #getInitialSelectionValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * description: The option pane's initial selection value object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    public void setInitialSelectionValue(Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        Object          oldValue = initialSelectionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        initialSelectionValue = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, oldValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
                           newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * Returns the input value that is displayed as initially selected to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * @return the initially selected value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * @see #setInitialSelectionValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
    public Object getInitialSelectionValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        return initialSelectionValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * Sets the input value that was selected or input by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * Only used if <code>wantsInput</code> is true.  Note that this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * is invoked internally by the option pane (in response to user action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * and should generally not be called by client programs.  To set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * input value initially displayed as selected to the user, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * <code>setInitialSelectionValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * @param newValue the <code>Object</code> used to set the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     *          value that the user specified (usually in a text field)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * @see #setInitialSelectionValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * @see #setWantsInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     * @see #getInputValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     * description: The option pane's input value object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
    public void setInputValue(Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        Object              oldValue = inputValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        inputValue = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        firePropertyChange(INPUT_VALUE_PROPERTY, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     * Returns the value the user has input, if <code>wantsInput</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
     * is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * @return the <code>Object</code> the user specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     *          if it was one of the objects, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     *          <code>String</code> if it was a value typed into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     *          field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * @see #setWantsInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * @see #setInputValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    public Object getInputValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
        return inputValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * Returns the maximum number of characters to place on a line in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * message. Default is to return <code>Integer.MAX_VALUE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * The value can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * changed by overriding this method in a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * @return an integer giving the maximum number of characters on a line
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
    public int getMaxCharactersPerLineCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        return Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     * Sets the <code>wantsInput</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
     * If <code>newValue</code> is true, an input component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     * (such as a text field or combo box) whose parent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
     * <code>parentComponent</code> is provided to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
     * allow the user to input a value. If <code>getSelectionValues</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
     * returns a non-<code>null</code> array, the input value is one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     * objects in that array. Otherwise the input value is whatever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * the user inputs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     * @see #setSelectionValues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * @see #setInputValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     *   preferred: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     *       bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * description: Flag which allows the user to input a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    public void setWantsInput(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        boolean            oldValue = wantsInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        wantsInput = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
        firePropertyChange(WANTS_INPUT_PROPERTY, oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
     * Returns the value of the <code>wantsInput</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
     * @return true if an input component will be provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * @see #setWantsInput
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
    public boolean getWantsInput() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        return wantsInput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
     * Requests that the initial value be selected, which will set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
     * focus to the initial value. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * should be invoked after the window containing the option pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     * is made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    public void selectInitialValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        OptionPaneUI         ui = getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
        if (ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
            ui.selectInitialValue(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    private static int styleFromMessageType(int messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        switch (messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
        case ERROR_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
            return JRootPane.ERROR_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        case QUESTION_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            return JRootPane.QUESTION_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
        case WARNING_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
            return JRootPane.WARNING_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
        case INFORMATION_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
            return JRootPane.INFORMATION_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        case PLAIN_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
            return JRootPane.PLAIN_DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
    // Serialization support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    private void writeObject(ObjectOutputStream s) throws IOException {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2335
        Vector<Object> values = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        // Save the icon, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
        if(icon != null && icon instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
            values.addElement("icon");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            values.addElement(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        // Save the message, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        if(message != null && message instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            values.addElement("message");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            values.addElement(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        // Save the treeModel, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
        if(options != null) {
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2350
            Vector<Object> serOptions = new Vector<Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            for(int counter = 0, maxCounter = options.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
                counter < maxCounter; counter++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
                if(options[counter] instanceof Serializable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                    serOptions.addElement(options[counter]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            if(serOptions.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                int             optionCount = serOptions.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                Object[]        arrayOptions = new Object[optionCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                serOptions.copyInto(arrayOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                values.addElement("options");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                values.addElement(arrayOptions);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        // Save the initialValue, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        if(initialValue != null && initialValue instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            values.addElement("initialValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
            values.addElement(initialValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        // Save the value, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        if(value != null && value instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            values.addElement("value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
            values.addElement(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
        // Save the selectionValues, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        if(selectionValues != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            boolean            serialize = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
            for(int counter = 0, maxCounter = selectionValues.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
                counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                if(selectionValues[counter] != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                   !(selectionValues[counter] instanceof Serializable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                    serialize = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
            if(serialize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
                values.addElement("selectionValues");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                values.addElement(selectionValues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        // Save the inputValue, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        if(inputValue != null && inputValue instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            values.addElement("inputValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            values.addElement(inputValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
        // Save the initialSelectionValue, if its Serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
        if(initialSelectionValue != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
           initialSelectionValue instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            values.addElement("initialSelectionValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            values.addElement(initialSelectionValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        s.writeObject(values);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        Vector          values = (Vector)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
        int             indexCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        int             maxCounter = values.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
           equals("icon")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            icon = (Icon)values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
           equals("message")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
            message = values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
           equals("options")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
            options = (Object[])values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
           equals("initialValue")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
            initialValue = values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
           equals("value")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            value = values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
           equals("selectionValues")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
            selectionValues = (Object[])values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
           equals("inputValue")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            inputValue = values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
        if(indexCounter < maxCounter && values.elementAt(indexCounter).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
           equals("initialSelectionValue")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            initialSelectionValue = values.elementAt(++indexCounter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
            indexCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     * Returns a string representation of this <code>JOptionPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     * This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
     * @return  a string representation of this <code>JOptionPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        String iconString = (icon != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
                             icon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        String initialValueString = (initialValue != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
                                     initialValue.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        String messageString = (message != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
                                message.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        String messageTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        if (messageType == ERROR_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            messageTypeString = "ERROR_MESSAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        } else if (messageType == INFORMATION_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
            messageTypeString = "INFORMATION_MESSAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        } else if (messageType == WARNING_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            messageTypeString = "WARNING_MESSAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        } else if (messageType == QUESTION_MESSAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            messageTypeString = "QUESTION_MESSAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        } else if (messageType == PLAIN_MESSAGE)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            messageTypeString = "PLAIN_MESSAGE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        } else messageTypeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        String optionTypeString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
        if (optionType == DEFAULT_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            optionTypeString = "DEFAULT_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        } else if (optionType == YES_NO_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
            optionTypeString = "YES_NO_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        } else if (optionType == YES_NO_CANCEL_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            optionTypeString = "YES_NO_CANCEL_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        } else if (optionType == OK_CANCEL_OPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            optionTypeString = "OK_CANCEL_OPTION";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
        } else optionTypeString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        String wantsInputString = (wantsInput ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                                   "true" : "false");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
        ",icon=" + iconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        ",initialValue=" + initialValueString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        ",message=" + messageString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        ",messageType=" + messageTypeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        ",optionType=" + optionTypeString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        ",wantsInput=" + wantsInputString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
     * Retrieves a method from the provided class and makes it accessible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     */
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2518
    private static class ModalPrivilegedAction implements PrivilegedAction<Method> {
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2519
        private Class<?> clazz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
        private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2522
        public ModalPrivilegedAction(Class<?> clazz, String methodName) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            this.clazz = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
            this.methodName = methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
1301
15e81207e1f2 6727662: Code improvement and warnings removing from swing packages
rupashka
parents: 715
diff changeset
  2527
        public Method run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            Method method = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                method = clazz.getDeclaredMethod(methodName, (Class[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            } catch (NoSuchMethodException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            if (method != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                method.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
            return method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
///////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * Returns the <code>AccessibleContext</code> associated with this JOptionPane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     * For option panes, the <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     * <code>AccessibleJOptionPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * A new <code>AccessibleJOptionPane</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * @return an AccessibleJOptionPane that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     *         AccessibleContext of this AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     *  description: The AccessibleContext associated with this option pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
            accessibleContext = new AccessibleJOptionPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * <code>JOptionPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * Java Accessibility API appropriate to option pane user-interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    protected class AccessibleJOptionPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
         * @return an instance of AccessibleRole describing the role of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
            switch (messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
            case ERROR_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
            case INFORMATION_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            case WARNING_MESSAGE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
                return AccessibleRole.ALERT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
                return AccessibleRole.OPTION_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    } // inner class AccessibleJOptionPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
}