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