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