KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > JOptionPane


1 /*
2  * @(#)JOptionPane.java 1.91 04/03/04
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing;
9
10 import java.awt.BorderLayout JavaDoc;
11 import java.awt.Component JavaDoc;
12 import java.awt.Container JavaDoc;
13 import java.awt.Dialog JavaDoc;
14 import java.awt.Dimension JavaDoc;
15 import java.awt.KeyboardFocusManager JavaDoc;
16 import java.awt.Frame JavaDoc;
17 import java.awt.Point JavaDoc;
18 import java.awt.HeadlessException JavaDoc;
19 import java.awt.Toolkit JavaDoc;
20 import java.awt.Window JavaDoc;
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.awt.event.WindowListener JavaDoc;
24 import java.awt.event.WindowAdapter JavaDoc;
25 import java.awt.event.WindowEvent JavaDoc;
26 import java.awt.event.ComponentAdapter JavaDoc;
27 import java.awt.event.ComponentEvent JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.io.ObjectInputStream JavaDoc;
30 import java.io.ObjectOutputStream JavaDoc;
31 import java.io.Serializable JavaDoc;
32 import java.lang.reflect.Method JavaDoc;
33 import java.lang.reflect.InvocationTargetException JavaDoc;
34 import java.security.AccessController JavaDoc;
35 import java.security.PrivilegedAction JavaDoc;
36 import java.util.Vector JavaDoc;
37 import javax.swing.plaf.OptionPaneUI JavaDoc;
38 import javax.swing.event.InternalFrameEvent JavaDoc;
39 import javax.swing.event.InternalFrameAdapter JavaDoc;
40 import javax.accessibility.*;
41
42 /**
43  * <code>JOptionPane</code> makes it easy to pop up a standard dialog box that
44  * prompts users for a value or informs them of something.
45  * For information about using <code>JOptionPane</code>, see
46  * <a
47  href="http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html">How to Make Dialogs</a>,
48  * a section in <em>The Java Tutorial</em>.
49  *
50  * <p>
51  *
52  * While the <code>JOptionPane</code>
53  * class may appear complex because of the large number of methods, almost
54  * all uses of this class are one-line calls to one of the static
55  * <code>showXxxDialog</code> methods shown below:
56  * <blockquote>
57  *
58  *
59  * <table border=1 summary="Common JOptionPane method names and their descriptions">
60  * <tr>
61  * <th>Method Name</th>
62  * <th>Description</th>
63  * </tr>
64  * <tr>
65  * <td>showConfirmDialog</td>
66  * <td>Asks a confirming question, like yes/no/cancel.</td>
67  * </tr>
68  * <tr>
69  * <td>showInputDialog</td>
70  * <td>Prompt for some input.</td>
71  * </tr>
72  * <tr>
73  * <td>showMessageDialog</td>
74  * <td>Tell the user about something that has happened.</td>
75  * </tr>
76  * <tr>
77  * <td>showOptionDialog</td>
78  * <td>The Grand Unification of the above three.</td>
79  * </tr>
80  * </table>
81  *
82  * </blockquote>
83  * Each of these methods also comes in a <code>showInternalXXX</code>
84  * flavor, which uses an internal frame to hold the dialog box (see
85  * {@link JInternalFrame}).
86  * Multiple convenience methods have also been defined -- overloaded
87  * versions of the basic methods that use different parameter lists.
88  * <p>
89  * All dialogs are modal. Each <code>showXxxDialog</code> method blocks
90  * the current thread until the user's interaction is complete.
91  * <p>
92  *
93  * <table cellspacing=6 cellpadding=4 border=0 align=right summary="layout">
94  * <tr>
95  * <td bgcolor=#FFe0d0 rowspan=2>icon</td>
96  * <td bgcolor=#FFe0d0>message</td>
97  * </tr>
98  * <tr>
99  * <td bgcolor=#FFe0d0>input value</td>
100  * </tr>
101  * <tr>
102  * <td bgcolor=#FFe0d0 colspan=2>option buttons</td>
103  * </tr>
104  * </table>
105  *
106  * The basic appearance of one of these dialog boxes is generally
107  * similar to the picture at the right, although the various
108  * look-and-feels are
109  * ultimately responsible for the final result. In particular, the
110  * look-and-feels will adjust the layout to accommodate the option pane's
111  * <code>ComponentOrientation</code> property.
112  * <br clear=all>
113  * <p>
114  * <b>Parameters:</b><br>
115  * The parameters to these methods follow consistent patterns:
116  * <blockquote>
117  * <dl compact>
118  * <dt>parentComponent<dd>
119  * Defines the <code>Component</code> that is to be the parent of this
120  * dialog box.
121  * It is used in two ways: the <code>Frame</code> that contains
122  * it is used as the <code>Frame</code>
123  * parent for the dialog box, and its screen coordinates are used in
124  * the placement of the dialog box. In general, the dialog box is placed
125  * just below the component. This parameter may be <code>null</code>,
126  * in which case a default <code>Frame</code> is used as the parent,
127  * and the dialog will be
128  * centered on the screen (depending on the L&F).
129  * <dt><a name=message>message</a><dd>
130  * A descriptive message to be placed in the dialog box.
131  * In the most common usage, message is just a <code>String</code> or
132  * <code>String</code> constant.
133  * However, the type of this parameter is actually <code>Object</code>. Its
134  * interpretation depends on its type:
135  * <dl compact>
136  * <dt>Object[]<dd>An array of objects is interpreted as a series of
137  * messages (one per object) arranged in a vertical stack.
138  * The interpretation is recursive -- each object in the
139  * array is interpreted according to its type.
140  * <dt>Component<dd>The <code>Component</code> is displayed in the dialog.
141  * <dt>Icon<dd>The <code>Icon</code> is wrapped in a <code>JLabel</code>
142  * and displayed in the dialog.
143  * <dt>others<dd>The object is converted to a <code>String</code> by calling
144  * its <code>toString</code> method. The result is wrapped in a
145  * <code>JLabel</code> and displayed.
146  * </dl>
147  * <dt>messageType<dd>Defines the style of the message. The Look and Feel
148  * manager may lay out the dialog differently depending on this value, and
149  * will often provide a default icon. The possible values are:
150  * <ul>
151  * <li><code>ERROR_MESSAGE</code>
152  * <li><code>INFORMATION_MESSAGE</code>
153  * <li><code>WARNING_MESSAGE</code>
154  * <li><code>QUESTION_MESSAGE</code>
155  * <li><code>PLAIN_MESSAGE</code>
156  * </ul>
157  * <dt>optionType<dd>Defines the set of option buttons that appear at
158  * the bottom of the dialog box:
159  * <ul>
160  * <li><code>DEFAULT_OPTION</code>
161  * <li><code>YES_NO_OPTION</code>
162  * <li><code>YES_NO_CANCEL_OPTION</code>
163  * <li><code>OK_CANCEL_OPTION</code>
164  * </ul>
165  * You aren't limited to this set of option buttons. You can provide any
166  * buttons you want using the options parameter.
167  * <dt>options<dd>A more detailed description of the set of option buttons
168  * that will appear at the bottom of the dialog box.
169  * The usual value for the options parameter is an array of
170  * <code>String</code>s. But
171  * the parameter type is an array of <code>Objects</code>.
172  * A button is created for each object depending on its type:
173  * <dl compact>
174  * <dt>Component<dd>The component is added to the button row directly.
175  * <dt>Icon<dd>A <code>JButton</code> is created with this as its label.
176  * <dt>other<dd>The <code>Object</code> is converted to a string using its
177  * <code>toString</code> method and the result is used to
178  * label a <code>JButton</code>.
179  * </dl>
180  * <dt>icon<dd>A decorative icon to be placed in the dialog box. A default
181  * value for this is determined by the <code>messageType</code> parameter.
182  * <dt>title<dd>The title for the dialog box.
183  * <dt>initialValue<dd>The default selection (input value).
184  * </dl>
185  * </blockquote>
186  * <p>
187  * When the selection is changed, <code>setValue</code> is invoked,
188  * which generates a <code>PropertyChangeEvent</code>.
189  * <p>
190  * If a <code>JOptionPane</code> has configured to all input
191  * <code>setWantsInput</code>
192  * the bound property <code>JOptionPane.INPUT_VALUE_PROPERTY</code>
193  * can also be listened
194  * to, to determine when the user has input or selected a value.
195  * <p>
196  * When one of the <code>showXxxDialog</code> methods returns an integer,
197  * the possible values are:
198  * <ul>
199  * <li><code>YES_OPTION</code>
200  * <li><code>NO_OPTION</code>
201  * <li><code>CANCEL_OPTION</code>
202  * <li><code>OK_OPTION</code>
203  * <li><code>CLOSED_OPTION</code>
204  * </ul>
205  * <b>Examples:</b>
206  * <dl>
207  * <dt>Show an error dialog that displays the message, 'alert':
208  * <dd><code>
209  * JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
210  * </code><p>
211  * <dt>Show an internal information dialog with the message, 'information':
212  * <dd><code>
213  * JOptionPane.showInternalMessageDialog(frame, "information",<br>
214  * <ul><ul>"information", JOptionPane.INFORMATION_MESSAGE);</ul></ul>
215  * </code><p>
216  * <dt>Show an information panel with the options yes/no and message 'choose one':
217  * <dd><code>JOptionPane.showConfirmDialog(null,
218  * <ul><ul>"choose one", "choose one", JOptionPane.YES_NO_OPTION);</ul></ul>
219  * </code><p>
220  * <dt>Show an internal information dialog with the options yes/no/cancel and
221  * message 'please choose one' and title information:
222  * <dd><code>JOptionPane.showInternalConfirmDialog(frame,
223  * <ul><ul>"please choose one", "information",</ul></ul>
224  * <ul><ul>JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);</ul></ul>
225  * </code><p>
226  * <dt>Show a warning dialog with the options OK, CANCEL, title 'Warning', and
227  * message 'Click OK to continue':
228  * <dd><code>
229  * Object[] options = { "OK", "CANCEL" };<br>
230  * JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
231  * <ul><ul>JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,</ul></ul>
232  * <ul><ul>null, options, options[0]);</ul></ul>
233  * </code><p>
234  * <dt>Show a dialog asking the user to type in a String:
235  * <dd><code>
236  * String inputValue = JOptionPane.showInputDialog("Please input a value");
237  * </code><p>
238  * <dt>Show a dialog asking the user to select a String:
239  * <dd><code>
240  * Object[] possibleValues = { "First", "Second", "Third" };<br>
241  * Object selectedValue = JOptionPane.showInputDialog(null,
242  * <ul><ul>"Choose one", "Input",</ul></ul>
243  * <ul><ul>JOptionPane.INFORMATION_MESSAGE, null,</ul></ul>
244  * <ul><ul>possibleValues, possibleValues[0]);</ul></ul>
245  * </code><p>
246  * </dl>
247  * <b>Direct Use:</b><br>
248  * To create and use an <code>JOptionPane</code> directly, the
249  * standard pattern is roughly as follows:
250  * <pre>
251  * JOptionPane pane = new JOptionPane(<i>arguments</i>);
252  * pane.set<i>.Xxxx(...); // Configure</i>
253  * JDialog dialog = pane.createDialog(<i>parentComponent, title</i>);
254  * dialog.show();
255  * Object selectedValue = pane.getValue();
256  * if(selectedValue == null)
257  * return CLOSED_OPTION;
258  * <i>//If there is <b>not</b> an array of option buttons:</i>
259  * if(options == null) {
260  * if(selectedValue instanceof Integer)
261  * return ((Integer)selectedValue).intValue();
262  * return CLOSED_OPTION;
263  * }
264  * <i>//If there is an array of option buttons:</i>
265  * for(int counter = 0, maxCounter = options.length;
266  * counter < maxCounter; counter++) {
267  * if(options[counter].equals(selectedValue))
268  * return counter;
269  * }
270  * return CLOSED_OPTION;
271  * </pre>
272  * <p>
273  * <strong>Warning:</strong>
274  * Serialized objects of this class will not be compatible with
275  * future Swing releases. The current serialization support is
276  * appropriate for short term storage or RMI between applications running
277  * the same version of Swing. As of 1.4, support for long term storage
278  * of all JavaBeans<sup><font size="-2">TM</font></sup>
279  * has been added to the <code>java.beans</code> package.
280  * Please see {@link java.beans.XMLEncoder}.
281  *
282  * @see JInternalFrame
283  *
284  * @beaninfo
285  * attribute: isContainer true
286  * description: A component which implements standard dialog box controls.
287  *
288  * @version 1.91 03/04/04
289  * @author James Gosling
290  * @author Scott Violet
291  */

292 public class JOptionPane extends JComponent JavaDoc implements Accessible
293 {
294     /**
295      * @see #getUIClassID
296      * @see #readObject
297      */

298     private static final String JavaDoc uiClassID = "OptionPaneUI";
299
300     /**
301      * Indicates that the user has not yet selected a value.
302      */

303     public static final Object JavaDoc UNINITIALIZED_VALUE = "uninitializedValue";
304
305     //
306
// Option types
307
//
308
/**
309      * Type meaning Look and Feel should not supply any options -- only
310      * use the options from the <code>JOptionPane</code>.
311      */

312     /** Type used for <code>showConfirmDialog</code>. */
313     public static final int DEFAULT_OPTION = -1;
314     /** Type used for <code>showConfirmDialog</code>. */
315     public static final int YES_NO_OPTION = 0;
316     /** Type used for <code>showConfirmDialog</code>. */
317     public static final int YES_NO_CANCEL_OPTION = 1;
318     /** Type used for <code>showConfirmDialog</code>. */
319     public static final int OK_CANCEL_OPTION = 2;
320
321     //
322
// Return values.
323
//
324
/** Return value from class method if YES is chosen. */
325     public static final int YES_OPTION = 0;
326     /** Return value from class method if NO is chosen. */
327     public static final int NO_OPTION = 1;
328     /** Return value from class method if CANCEL is chosen. */
329     public static final int CANCEL_OPTION = 2;
330     /** Return value form class method if OK is chosen. */
331     public static final int OK_OPTION = 0;
332     /** Return value from class method if user closes window without selecting
333      * anything, more than likely this should be treated as either a
334      * <code>CANCEL_OPTION</code> or <code>NO_OPTION</code>. */

335     public static final int CLOSED_OPTION = -1;
336
337     //
338
// Message types. Used by the UI to determine what icon to display,
339
// and possibly what behavior to give based on the type.
340
//
341
/** Used for error messages. */
342     public static final int ERROR_MESSAGE = 0;
343     /** Used for information messages. */
344     public static final int INFORMATION_MESSAGE = 1;
345     /** Used for warning messages. */
346     public static final int WARNING_MESSAGE = 2;
347     /** Used for questions. */
348     public static final int QUESTION_MESSAGE = 3;
349     /** No icon is used. */
350     public static final int PLAIN_MESSAGE = -1;
351
352     /** Bound property name for <code>icon</code>. */
353     public static final String JavaDoc ICON_PROPERTY = "icon";
354     /** Bound property name for <code>message</code>. */
355     public static final String JavaDoc MESSAGE_PROPERTY = "message";
356     /** Bound property name for <code>value</code>. */
357     public static final String JavaDoc VALUE_PROPERTY = "value";
358     /** Bound property name for <code>option</code>. */
359     public static final String JavaDoc OPTIONS_PROPERTY = "options";
360     /** Bound property name for <code>initialValue</code>. */
361     public static final String JavaDoc INITIAL_VALUE_PROPERTY = "initialValue";
362     /** Bound property name for <code>type</code>. */
363     public static final String JavaDoc MESSAGE_TYPE_PROPERTY = "messageType";
364     /** Bound property name for <code>optionType</code>. */
365     public static final String JavaDoc OPTION_TYPE_PROPERTY = "optionType";
366     /** Bound property name for <code>selectionValues</code>. */
367     public static final String JavaDoc SELECTION_VALUES_PROPERTY = "selectionValues";
368     /** Bound property name for <code>initialSelectionValue</code>. */
369     public static final String JavaDoc INITIAL_SELECTION_VALUE_PROPERTY = "initialSelectionValue";
370     /** Bound property name for <code>inputValue</code>. */
371     public static final String JavaDoc INPUT_VALUE_PROPERTY = "inputValue";
372     /** Bound property name for <code>wantsInput</code>. */
373     public static final String JavaDoc WANTS_INPUT_PROPERTY = "wantsInput";
374
375     /** Icon used in pane. */
376     transient protected Icon JavaDoc icon;
377     /** Message to display. */
378     transient protected Object JavaDoc message;
379     /** Options to display to the user. */
380     transient protected Object JavaDoc[] options;
381     /** Value that should be initially selected in <code>options</code>. */
382     transient protected Object JavaDoc initialValue;
383     /** Message type. */
384     protected int messageType;
385     /**
386      * Option type, one of <code>DEFAULT_OPTION</code>,
387      * <code>YES_NO_OPTION</code>,
388      * <code>YES_NO_CANCEL_OPTION</code> or
389      * <code>OK_CANCEL_OPTION</code>.
390      */

391     protected int optionType;
392     /** Currently selected value, will be a valid option, or
393      * <code>UNINITIALIZED_VALUE</code> or <code>null</code>. */

394     transient protected Object JavaDoc value;
395     /** Array of values the user can choose from. Look and feel will
396      * provide the UI component to choose this from. */

397     protected transient Object JavaDoc[] selectionValues;
398     /** Value the user has input. */
399     protected transient Object JavaDoc inputValue;
400     /** Initial value to select in <code>selectionValues</code>. */
401     protected transient Object JavaDoc initialSelectionValue;
402     /** If true, a UI widget will be provided to the user to get input. */
403     protected boolean wantsInput;
404
405
406     /**
407      * Shows a question-message dialog requesting input from the user. The
408      * dialog uses the default frame, which usually means it is centered on
409      * the screen.
410      *
411      * @param message the <code>Object</code> to display
412      * @exception HeadlessException if
413      * <code>GraphicsEnvironment.isHeadless</code> returns
414      * <code>true</code>
415      * @see java.awt.GraphicsEnvironment#isHeadless
416      */

417     public static String JavaDoc showInputDialog(Object JavaDoc message)
418         throws HeadlessException JavaDoc {
419         return showInputDialog(null, message);
420     }
421
422     /**
423      * Shows a question-message dialog requesting input from the user, with
424      * the input value initialized to <code>initialSelectionValue</code>. The
425      * dialog uses the default frame, which usually means it is centered on
426      * the screen.
427      *
428      * @param message the <code>Object</code> to display
429      * @param initialSelectionValue the value used to initialize the input
430      * field
431      * @since 1.4
432      */

433     public static String JavaDoc showInputDialog(Object JavaDoc message, Object JavaDoc initialSelectionValue) {
434         return showInputDialog(null, message, initialSelectionValue);
435     }
436
437     /**
438      * Shows a question-message dialog requesting input from the user
439      * parented to <code>parentComponent</code>.
440      * The dialog is displayed on top of the <code>Component</code>'s
441      * frame, and is usually positioned below the <code>Component</code>.
442      *
443      * @param parentComponent the parent <code>Component</code> for the
444      * dialog
445      * @param message the <code>Object</code> to display
446      * @exception HeadlessException if
447      * <code>GraphicsEnvironment.isHeadless</code> returns
448      * <code>true</code>
449      * @see java.awt.GraphicsEnvironment#isHeadless
450      */

451     public static String JavaDoc showInputDialog(Component JavaDoc parentComponent,
452         Object JavaDoc message) throws HeadlessException JavaDoc {
453         return showInputDialog(parentComponent, message, UIManager.getString(
454             "OptionPane.inputDialogTitle", parentComponent), QUESTION_MESSAGE);
455     }
456
457     /**
458      * Shows a question-message dialog requesting input from the user and
459      * parented to <code>parentComponent</code>. The input value will be
460      * initialized to <code>initialSelectionValue</code>.
461      * The dialog is displayed on top of the <code>Component</code>'s
462      * frame, and is usually positioned below the <code>Component</code>.
463      *
464      * @param parentComponent the parent <code>Component</code> for the
465      * dialog
466      * @param message the <code>Object</code> to display
467      * @param initialSelectionValue the value used to initialize the input
468      * field
469      * @since 1.4
470      */

471     public static String JavaDoc showInputDialog(Component JavaDoc parentComponent, Object JavaDoc message,
472                      Object JavaDoc initialSelectionValue) {
473         return (String JavaDoc)showInputDialog(parentComponent, message,
474                       UIManager.getString("OptionPane.inputDialogTitle",
475                       parentComponent), QUESTION_MESSAGE, null, null,
476                       initialSelectionValue);
477     }
478
479     /**
480      * Shows a dialog requesting input from the user parented to
481      * <code>parentComponent</code> with the dialog having the title
482      * <code>title</code> and message type <code>messageType</code>.
483      *
484      * @param parentComponent the parent <code>Component</code> for the
485      * dialog
486      * @param message the <code>Object</code> to display
487      * @param title the <code>String</code> to display in the dialog
488      * title bar
489      * @param messageType the type of message that is to be displayed:
490      * <code>ERROR_MESSAGE</code>,
491      * <code>INFORMATION_MESSAGE</code>,
492      * <code>WARNING_MESSAGE</code>,
493      * <code>QUESTION_MESSAGE</code>,
494      * or <code>PLAIN_MESSAGE</code>
495      * @exception HeadlessException if
496      * <code>GraphicsEnvironment.isHeadless</code> returns
497      * <code>true</code>
498      * @see java.awt.GraphicsEnvironment#isHeadless
499      */

500     public static String JavaDoc showInputDialog(Component JavaDoc parentComponent,
501         Object JavaDoc message, String JavaDoc title, int messageType)
502         throws HeadlessException JavaDoc {
503         return (String JavaDoc)showInputDialog(parentComponent, message, title,
504                                        messageType, null, null, null);
505     }
506
507     /**
508      * Prompts the user for input in a blocking dialog where the
509      * initial selection, possible selections, and all other options can
510      * be specified. The user will able to choose from
511      * <code>selectionValues</code>, where <code>null</code> implies the
512      * user can input
513      * whatever they wish, usually by means of a <code>JTextField</code>.
514      * <code>initialSelectionValue</code> is the initial value to prompt
515      * the user with. It is up to the UI to decide how best to represent
516      * the <code>selectionValues</code>, but usually a
517      * <code>JComboBox</code>, <code>JList</code>, or
518      * <code>JTextField</code> will be used.
519      *
520      * @param parentComponent the parent <code>Component</code> for the
521      * dialog
522      * @param message the <code>Object</code> to display
523      * @param title the <code>String</code> to display in the
524      * dialog title bar
525      * @param messageType the type of message to be displayed:
526      * <code>ERROR_MESSAGE</code>,
527      * <code>INFORMATION_MESSAGE</code>,
528      * <code>WARNING_MESSAGE</code>,
529      * <code>QUESTION_MESSAGE</code>,
530      * or <code>PLAIN_MESSAGE</code>
531      * @param icon the <code>Icon</code> image to display
532      * @param selectionValues an array of <code>Object</code>s that
533      * gives the possible selections
534      * @param initialSelectionValue the value used to initialize the input
535      * field
536      * @return user's input, or <code>null</code> meaning the user
537      * canceled the input
538      * @exception HeadlessException if
539      * <code>GraphicsEnvironment.isHeadless</code> returns
540      * <code>true</code>
541      * @see java.awt.GraphicsEnvironment#isHeadless
542      */

543     public static Object JavaDoc showInputDialog(Component JavaDoc parentComponent,
544         Object JavaDoc message, String JavaDoc title, int messageType, Icon JavaDoc icon,
545         Object JavaDoc[] selectionValues, Object JavaDoc initialSelectionValue)
546         throws HeadlessException JavaDoc {
547         JOptionPane JavaDoc pane = new JOptionPane JavaDoc(message, messageType,
548                                               OK_CANCEL_OPTION, icon,
549                                               null, null);
550
551         pane.setWantsInput(true);
552         pane.setSelectionValues(selectionValues);
553         pane.setInitialSelectionValue(initialSelectionValue);
554         pane.setComponentOrientation(((parentComponent == null) ?
555         getRootFrame() : parentComponent).getComponentOrientation());
556
557         int style = styleFromMessageType(messageType);
558         JDialog JavaDoc dialog = pane.createDialog(parentComponent, title, style);
559
560         pane.selectInitialValue();
561         dialog.show();
562         dialog.dispose();
563
564         Object JavaDoc value = pane.getInputValue();
565
566         if (value == UNINITIALIZED_VALUE) {
567             return null;
568         }
569         return value;
570     }
571
572     /**
573      * Brings up an information-message dialog titled "Message".
574      *
575      * @param parentComponent determines the <code>Frame</code> in
576      * which the dialog is displayed; if <code>null</code>,
577      * or if the <code>parentComponent</code> has no
578      * <code>Frame</code>, a default <code>Frame</code> is used
579      * @param message the <code>Object</code> to display
580      * @exception HeadlessException if
581      * <code>GraphicsEnvironment.isHeadless</code> returns
582      * <code>true</code>
583      * @see java.awt.GraphicsEnvironment#isHeadless
584      */

585     public static void showMessageDialog(Component JavaDoc parentComponent,
586         Object JavaDoc message) throws HeadlessException JavaDoc {
587         showMessageDialog(parentComponent, message, UIManager.getString(
588                     "OptionPane.messageDialogTitle", parentComponent),
589                     INFORMATION_MESSAGE);
590     }
591
592     /**
593      * Brings up a dialog that displays a message using a default
594      * icon determined by the <code>messageType</code> parameter.
595      *
596      * @param parentComponent determines the <code>Frame</code>
597      * in which the dialog is displayed; if <code>null</code>,
598      * or if the <code>parentComponent</code> has no
599      * <code>Frame</code>, a default <code>Frame</code> is used
600      * @param message the <code>Object</code> to display
601      * @param title the title string for the dialog
602      * @param messageType the type of message to be displayed:
603      * <code>ERROR_MESSAGE</code>,
604      * <code>INFORMATION_MESSAGE</code>,
605      * <code>WARNING_MESSAGE</code>,
606      * <code>QUESTION_MESSAGE</code>,
607      * or <code>PLAIN_MESSAGE</code>
608      * @exception HeadlessException if
609      * <code>GraphicsEnvironment.isHeadless</code> returns
610      * <code>true</code>
611      * @see java.awt.GraphicsEnvironment#isHeadless
612      */

613     public static void showMessageDialog(Component JavaDoc parentComponent,
614         Object JavaDoc message, String JavaDoc title, int messageType)
615         throws HeadlessException JavaDoc {
616         showMessageDialog(parentComponent, message, title, messageType, null);
617     }
618
619     /**
620      * Brings up a dialog displaying a message, specifying all parameters.
621      *
622      * @param parentComponent determines the <code>Frame</code> in which the
623      * dialog is displayed; if <code>null</code>,
624      * or if the <code>parentComponent</code> has no
625      * <code>Frame</code>, a
626      * default <code>Frame</code> is used
627      * @param message the <code>Object</code> to display
628      * @param title the title string for the dialog
629      * @param messageType the type of message to be displayed:
630      * <code>ERROR_MESSAGE</code>,
631      * <code>INFORMATION_MESSAGE</code>,
632      * <code>WARNING_MESSAGE</code>,
633      * <code>QUESTION_MESSAGE</code>,
634      * or <code>PLAIN_MESSAGE</code>
635      * @param icon an icon to display in the dialog that helps the user
636      * identify the kind of message that is being displayed
637      * @exception HeadlessException if
638      * <code>GraphicsEnvironment.isHeadless</code> returns
639      * <code>true</code>
640      * @see java.awt.GraphicsEnvironment#isHeadless
641      */

642     public static void showMessageDialog(Component JavaDoc parentComponent,
643         Object JavaDoc message, String JavaDoc title, int messageType, Icon JavaDoc icon)
644         throws HeadlessException JavaDoc {
645         showOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
646                          messageType, icon, null, null);
647     }
648
649     /**
650      * Brings up a dialog with the options <i>Yes</i>,
651      * <i>No</i> and <i>Cancel</i>; with the
652      * title, <b>Select an Option</b>.
653      *
654      * @param parentComponent determines the <code>Frame</code> in which the
655      * dialog is displayed; if <code>null</code>,
656      * or if the <code>parentComponent</code> has no
657      * <code>Frame</code>, a
658      * default <code>Frame</code> is used
659      * @param message the <code>Object</code> to display
660      * @return an integer indicating the option selected by the user
661      * @exception HeadlessException if
662      * <code>GraphicsEnvironment.isHeadless</code> returns
663      * <code>true</code>
664      * @see java.awt.GraphicsEnvironment#isHeadless
665      */

666     public static int showConfirmDialog(Component JavaDoc parentComponent,
667         Object JavaDoc message) throws HeadlessException JavaDoc {
668         return showConfirmDialog(parentComponent, message,
669                                  UIManager.getString("OptionPane.titleText"),
670                                  YES_NO_CANCEL_OPTION);
671     }
672
673     /**
674      * Brings up a dialog where the number of choices is determined
675      * by the <code>optionType</code> parameter.
676      *
677      * @param parentComponent determines the <code>Frame</code> in which the
678      * dialog is displayed; if <code>null</code>,
679      * or if the <code>parentComponent</code> has no
680      * <code>Frame</code>, a
681      * default <code>Frame</code> is used
682      * @param message the <code>Object</code> to display
683      * @param title the title string for the dialog
684      * @param optionType an int designating the options available on the dialog:
685      * <code>YES_NO_OPTION</code>, or
686      * <code>YES_NO_CANCEL_OPTION</code>
687      * @return an int indicating the option selected by the user
688      * @exception HeadlessException if
689      * <code>GraphicsEnvironment.isHeadless</code> returns
690      * <code>true</code>
691      * @see java.awt.GraphicsEnvironment#isHeadless
692      */

693     public static int showConfirmDialog(Component JavaDoc parentComponent,
694         Object JavaDoc message, String JavaDoc title, int optionType)
695         throws HeadlessException JavaDoc {
696         return showConfirmDialog(parentComponent, message, title, optionType,
697                                  QUESTION_MESSAGE);
698     }
699
700     /**
701      * Brings up a dialog where the number of choices is determined
702      * by the <code>optionType</code> parameter, where the
703      * <code>messageType</code>
704      * parameter determines the icon to display.
705      * The <code>messageType</code> parameter is primarily used to supply
706      * a default icon from the Look and Feel.
707      *
708      * @param parentComponent determines the <code>Frame</code> in
709      * which the dialog is displayed; if <code>null</code>,
710      * or if the <code>parentComponent</code> has no
711      * <code>Frame</code>, a
712      * default <code>Frame</code> is used.
713      * @param message the <code>Object</code> to display
714      * @param title the title string for the dialog
715      * @param optionType an integer designating the options available
716      * on the dialog: <code>YES_NO_OPTION</code>,
717      * or <code>YES_NO_CANCEL_OPTION</code>
718      * @param messageType an integer designating the kind of message this is;
719      * primarily used to determine the icon from the pluggable
720      * Look and Feel: <code>ERROR_MESSAGE</code>,
721      * <code>INFORMATION_MESSAGE</code>,
722      * <code>WARNING_MESSAGE</code>,
723      * <code>QUESTION_MESSAGE</code>,
724      * or <code>PLAIN_MESSAGE</code>
725      * @return an integer indicating the option selected by the user
726      * @exception HeadlessException if
727      * <code>GraphicsEnvironment.isHeadless</code> returns
728      * <code>true</code>
729      * @see java.awt.GraphicsEnvironment#isHeadless
730      */

731     public static int showConfirmDialog(Component JavaDoc parentComponent,
732         Object JavaDoc message, String JavaDoc title, int optionType, int messageType)
733         throws HeadlessException JavaDoc {
734         return showConfirmDialog(parentComponent, message, title, optionType,
735                                 messageType, null);
736     }
737
738     /**
739      * Brings up a dialog with a specified icon, where the number of
740      * choices is determined by the <code>optionType</code> parameter.
741      * The <code>messageType</code> parameter is primarily used to supply
742      * a default icon from the look and feel.
743      *
744      * @param parentComponent determines the <code>Frame</code> in which the
745      * dialog is displayed; if <code>null</code>,
746      * or if the <code>parentComponent</code> has no
747      * <code>Frame</code>, a
748      * default <code>Frame</code> is used
749      * @param message the Object to display
750      * @param title the title string for the dialog
751      * @param optionType an int designating the options available on the dialog:
752      * <code>YES_NO_OPTION</code>,
753      * or <code>YES_NO_CANCEL_OPTION</code>
754      * @param messageType an int designating the kind of message this is,
755      * primarily used to determine the icon from the pluggable
756      * Look and Feel: <code>ERROR_MESSAGE</code>,
757      * <code>INFORMATION_MESSAGE</code>,
758      * <code>WARNING_MESSAGE</code>,
759      * <code>QUESTION_MESSAGE</code>,
760      * or <code>PLAIN_MESSAGE</code>
761      * @param icon the icon to display in the dialog
762      * @return an int indicating the option selected by the user
763      * @exception HeadlessException if
764      * <code>GraphicsEnvironment.isHeadless</code> returns
765      * <code>true</code>
766      * @see java.awt.GraphicsEnvironment#isHeadless
767      */

768     public static int showConfirmDialog(Component JavaDoc parentComponent,
769         Object JavaDoc message, String JavaDoc title, int optionType,
770         int messageType, Icon JavaDoc icon) throws HeadlessException JavaDoc {
771         return showOptionDialog(parentComponent, message, title, optionType,
772                                 messageType, icon, null, null);
773     }
774
775     /**
776      * Brings up a dialog with a specified icon, where the initial
777      * choice is determined by the <code>initialValue</code> parameter and
778      * the number of choices is determined by the <code>optionType</code>
779      * parameter.
780      * <p>
781      * If <code>optionType</code> is <code>YES_NO_OPTION</code>,
782      * or <code>YES_NO_CANCEL_OPTION</code>
783      * and the <code>options</code> parameter is <code>null</code>,
784      * then the options are
785      * supplied by the look and feel.
786      * <p>
787      * The <code>messageType</code> parameter is primarily used to supply
788      * a default icon from the look and feel.
789      *
790      * @param parentComponent determines the <code>Frame</code>
791      * in which the dialog is displayed; if
792      * <code>null</code>, or if the
793      * <code>parentComponent</code> has no
794      * <code>Frame</code>, a
795      * default <code>Frame</code> is used
796      * @param message the <code>Object</code> to display
797      * @param title the title string for the dialog
798      * @param optionType an integer designating the options available on the
799      * dialog: <code>YES_NO_OPTION</code>,
800      * or <code>YES_NO_CANCEL_OPTION</code>
801      * @param messageType an integer designating the kind of message this is,
802      * primarily used to determine the icon from the
803      * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
804      * <code>INFORMATION_MESSAGE</code>,
805      * <code>WARNING_MESSAGE</code>,
806      * <code>QUESTION_MESSAGE</code>,
807      * or <code>PLAIN_MESSAGE</code>
808      * @param icon the icon to display in the dialog
809      * @param options an array of objects indicating the possible choices
810      * the user can make; if the objects are components, they
811      * are rendered properly; non-<code>String</code>
812      * objects are
813      * rendered using their <code>toString</code> methods;
814      * if this parameter is <code>null</code>,
815      * the options are determined by the Look and Feel
816      * @param initialValue the object that represents the default selection
817      * for the dialog; only meaningful if <code>options</code>
818      * is used; can be <code>null</code>
819      * @return an integer indicating the option chosen by the user,
820      * or <code>CLOSED_OPTION</code> if the user closed
821      * the dialog
822      * @exception HeadlessException if
823      * <code>GraphicsEnvironment.isHeadless</code> returns
824      * <code>true</code>
825      * @see java.awt.GraphicsEnvironment#isHeadless
826      */

827     public static int showOptionDialog(Component JavaDoc parentComponent,
828         Object JavaDoc message, String JavaDoc title, int optionType, int messageType,
829         Icon JavaDoc icon, Object JavaDoc[] options, Object JavaDoc initialValue)
830         throws HeadlessException JavaDoc {
831         JOptionPane JavaDoc pane = new JOptionPane JavaDoc(message, messageType,
832                                                        optionType, icon,
833                                                        options, initialValue);
834
835         pane.setInitialValue(initialValue);
836         pane.setComponentOrientation(((parentComponent == null) ?
837         getRootFrame() : parentComponent).getComponentOrientation());
838
839         int style = styleFromMessageType(messageType);
840         JDialog JavaDoc dialog = pane.createDialog(parentComponent, title, style);
841
842         pane.selectInitialValue();
843         dialog.show();
844         dialog.dispose();
845
846         Object JavaDoc selectedValue = pane.getValue();
847
848         if(selectedValue == null)
849             return CLOSED_OPTION;
850         if(options == null) {
851             if(selectedValue instanceof Integer JavaDoc)
852                 return ((Integer JavaDoc)selectedValue).intValue();
853             return CLOSED_OPTION;
854         }
855         for(int counter = 0, maxCounter = options.length;
856             counter < maxCounter; counter++) {
857             if(options[counter].equals(selectedValue))
858                 return counter;
859         }
860         return CLOSED_OPTION;
861     }
862
863     /**
864      * Creates and returns a new <code>JDialog</code> wrapping
865      * <code>this</code> centered on the <code>parentComponent</code>
866      * in the <code>parentComponent</code>'s frame.
867      * <code>title</code> is the title of the returned dialog.
868      * The returned <code>JDialog</code> will not be resizable by the
869      * user, however programs can invoke <code>setResizable</code> on
870      * the <code>JDialog</code> instance to change this property.
871      * The returned <code>JDialog</code> will be set up such that
872      * once it is closed, or the user clicks on one of the buttons,
873      * the optionpane's value property will be set accordingly and
874      * the dialog will be closed. Each time the dialog is made visible,
875      * it will reset the option pane's value property to
876      * <code>JOptionPane.UNINITIALIZED_VALUE</code> to ensure the
877      * user's subsequent action closes the dialog properly.
878      *
879      * @param parentComponent determines the frame in which the dialog
880      * is displayed; if the <code>parentComponent</code> has
881      * no <code>Frame</code>, a default <code>Frame</code> is used
882      * @param title the title string for the dialog
883      * @return a new <code>JDialog</code> containing this instance
884      * @exception HeadlessException if
885      * <code>GraphicsEnvironment.isHeadless</code> returns
886      * <code>true</code>
887      * @see java.awt.GraphicsEnvironment#isHeadless
888      */

889     public JDialog JavaDoc createDialog(Component JavaDoc parentComponent, String JavaDoc title)
890         throws HeadlessException JavaDoc {
891             int style = styleFromMessageType(getMessageType());
892             return createDialog(parentComponent, title, style);
893     }
894
895     private JDialog JavaDoc createDialog(Component JavaDoc parentComponent, String JavaDoc title,
896             int style)
897             throws HeadlessException JavaDoc {
898
899         final JDialog JavaDoc dialog;
900
901         Window JavaDoc window = JOptionPane.getWindowForComponent(parentComponent);
902         if (window instanceof Frame JavaDoc) {
903             dialog = new JDialog JavaDoc((Frame JavaDoc)window, title, true);
904         } else {
905             dialog = new JDialog JavaDoc((Dialog JavaDoc)window, title, true);
906         }
907         dialog.setComponentOrientation(this.getComponentOrientation());
908     if (window instanceof SwingUtilities.SharedOwnerFrame JavaDoc) {
909         WindowListener JavaDoc ownerShutdownListener =
910         (WindowListener JavaDoc)SwingUtilities.getSharedOwnerFrameShutdownListener();
911         dialog.addWindowListener(ownerShutdownListener);
912     }
913         Container JavaDoc contentPane = dialog.getContentPane();
914
915         contentPane.setLayout(new BorderLayout JavaDoc());
916         contentPane.add(this, BorderLayout.CENTER);
917         dialog.setResizable(false);
918         if (JDialog.isDefaultLookAndFeelDecorated()) {
919             boolean supportsWindowDecorations =
920             UIManager.getLookAndFeel().getSupportsWindowDecorations();
921             if (supportsWindowDecorations) {
922                 dialog.setUndecorated(true);
923                 getRootPane().setWindowDecorationStyle(style);
924             }
925         }
926         dialog.pack();
927         dialog.setLocationRelativeTo(parentComponent);
928         WindowAdapter JavaDoc adapter = new WindowAdapter JavaDoc() {
929             private boolean gotFocus = false;
930             public void windowClosing(WindowEvent JavaDoc we) {
931                 setValue(null);
932             }
933             public void windowGainedFocus(WindowEvent JavaDoc we) {
934                 // Once window gets focus, set initial focus
935
if (!gotFocus) {
936                     selectInitialValue();
937                     gotFocus = true;
938                 }
939             }
940         };
941         dialog.addWindowListener(adapter);
942         dialog.addWindowFocusListener(adapter);
943     dialog.addComponentListener(new ComponentAdapter JavaDoc() {
944             public void componentShown(ComponentEvent JavaDoc ce) {
945             // reset value to ensure closing works properly
946
setValue(JOptionPane.UNINITIALIZED_VALUE);
947             }
948     });
949         addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
950             public void propertyChange(PropertyChangeEvent JavaDoc event) {
951                 // Let the defaultCloseOperation handle the closing
952
// if the user closed the window without selecting a button
953
// (newValue = null in that case). Otherwise, close the dialog.
954
if(dialog.isVisible() && event.getSource() == JOptionPane.this &&
955                    (event.getPropertyName().equals(VALUE_PROPERTY)) &&
956                     event.getNewValue() != null &&
957             event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
958                     dialog.setVisible(false);
959                 }
960             }
961         });
962         return dialog;
963     }
964         
965
966     /**
967      * Brings up an internal confirmation dialog panel. The dialog
968      * is a information-message dialog titled "Message".
969      *
970      * @param parentComponent determines the <code>Frame</code>
971      * in which the dialog is displayed; if <code>null</code>,
972      * or if the <code>parentComponent</code> has no
973      * <code>Frame</code>, a default <code>Frame</code> is used
974      * @param message the object to display
975      */

976     public static void showInternalMessageDialog(Component JavaDoc parentComponent,
977                                                  Object JavaDoc message) {
978         showInternalMessageDialog(parentComponent, message, UIManager.
979                                  getString("OptionPane.messageDialogTitle",
980                                  parentComponent), INFORMATION_MESSAGE);
981     }
982
983     /**
984      * Brings up an internal dialog panel that displays a message
985      * using a default icon determined by the <code>messageType</code>
986      * parameter.
987      *
988      * @param parentComponent determines the <code>Frame</code>
989      * in which the dialog is displayed; if <code>null</code>,
990      * or if the <code>parentComponent</code> has no
991      * <code>Frame</code>, a default <code>Frame</code> is used
992      * @param message the <code>Object</code> to display
993      * @param title the title string for the dialog
994      * @param messageType the type of message to be displayed:
995      * <code>ERROR_MESSAGE</code>,
996      * <code>INFORMATION_MESSAGE</code>,
997      * <code>WARNING_MESSAGE</code>,
998      * <code>QUESTION_MESSAGE</code>,
999      * or <code>PLAIN_MESSAGE</code>
1000     */

1001    public static void showInternalMessageDialog(Component JavaDoc parentComponent,
1002                                                 Object JavaDoc message, String JavaDoc title,
1003                                                 int messageType) {
1004        showInternalMessageDialog(parentComponent, message, title, messageType,null);
1005    }
1006
1007    /**
1008     * Brings up an internal dialog panel displaying a message,
1009     * specifying all parameters.
1010     *
1011     * @param parentComponent determines the <code>Frame</code>
1012     * in which the dialog is displayed; if <code>null</code>,
1013     * or if the <code>parentComponent</code> has no
1014     * <code>Frame</code>, a default <code>Frame</code> is used
1015     * @param message the <code>Object</code> to display
1016     * @param title the title string for the dialog
1017     * @param messageType the type of message to be displayed:
1018     * <code>ERROR_MESSAGE</code>,
1019     * <code>INFORMATION_MESSAGE</code>,
1020     * <code>WARNING_MESSAGE</code>,
1021     * <code>QUESTION_MESSAGE</code>,
1022     * or <code>PLAIN_MESSAGE</code>
1023     * @param icon an icon to display in the dialog that helps the user
1024     * identify the kind of message that is being displayed
1025     */

1026    public static void showInternalMessageDialog(Component JavaDoc parentComponent,
1027                                         Object JavaDoc message,
1028                                         String JavaDoc title, int messageType,
1029                                         Icon JavaDoc icon){
1030        showInternalOptionDialog(parentComponent, message, title, DEFAULT_OPTION,
1031                                 messageType, icon, null, null);
1032    }
1033
1034    /**
1035     * Brings up an internal dialog panel with the options <i>Yes</i>, <i>No</i>
1036     * and <i>Cancel</i>; with the title, <b>Select an Option</b>.
1037     *
1038     * @param parentComponent determines the <code>Frame</code> in
1039     * which the dialog is displayed; if <code>null</code>,
1040     * or if the <code>parentComponent</code> has no
1041     * <code>Frame</code>, a default <code>Frame</code> is used
1042     * @param message the <code>Object</code> to display
1043     * @return an integer indicating the option selected by the user
1044     */

1045    public static int showInternalConfirmDialog(Component JavaDoc parentComponent,
1046                                                Object JavaDoc message) {
1047        return showInternalConfirmDialog(parentComponent, message,
1048                                 UIManager.getString("OptionPane.titleText"),
1049                                 YES_NO_CANCEL_OPTION);
1050    }
1051
1052    /**
1053     * Brings up a internal dialog panel where the number of choices
1054     * is determined by the <code>optionType</code> parameter.
1055     *
1056     * @param parentComponent determines the <code>Frame</code>
1057     * in which the dialog is displayed; if <code>null</code>,
1058     * or if the <code>parentComponent</code> has no
1059     * <code>Frame</code>, a default <code>Frame</code> is used
1060     * @param message the object to display in the dialog; a
1061     * <code>Component</code> object is rendered as a
1062     * <code>Component</code>; a <code>String</code>
1063     * object is rendered as a string; other objects
1064     * are converted to a <code>String</code> using the
1065     * <code>toString</code> method
1066     * @param title the title string for the dialog
1067     * @param optionType an integer designating the options
1068     * available on the dialog: <code>YES_NO_OPTION</code>,
1069     * or <code>YES_NO_CANCEL_OPTION</code>
1070     * @return an integer indicating the option selected by the user
1071     */

1072    public static int showInternalConfirmDialog(Component JavaDoc parentComponent,
1073                                                Object JavaDoc message, String JavaDoc title,
1074                                                int optionType) {
1075        return showInternalConfirmDialog(parentComponent, message, title, optionType,
1076                                         QUESTION_MESSAGE);
1077    }
1078
1079    /**
1080     * Brings up an internal dialog panel where the number of choices
1081     * is determined by the <code>optionType</code> parameter, where
1082     * the <code>messageType</code> parameter determines the icon to display.
1083     * The <code>messageType</code> parameter is primarily used to supply
1084     * a default icon from the Look and Feel.
1085     *
1086     * @param parentComponent determines the <code>Frame</code> in
1087     * which the dialog is displayed; if <code>null</code>,
1088     * or if the <code>parentComponent</code> has no
1089     * <code>Frame</code>, a default <code>Frame</code> is used
1090     * @param message the object to display in the dialog; a
1091     * <code>Component</code> object is rendered as a
1092     * <code>Component</code>; a <code>String</code>
1093     * object is rendered as a string; other objects are
1094     * converted to a <code>String</code> using the
1095     * <code>toString</code> method
1096     * @param title the title string for the dialog
1097     * @param optionType an integer designating the options
1098     * available on the dialog:
1099     * <code>YES_NO_OPTION</code>, or <code>YES_NO_CANCEL_OPTION</code>
1100     * @param messageType an integer designating the kind of message this is,
1101     * primarily used to determine the icon from the
1102     * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
1103     * <code>INFORMATION_MESSAGE</code>,
1104     * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
1105     * or <code>PLAIN_MESSAGE</code>
1106     * @return an integer indicating the option selected by the user
1107     */

1108    public static int showInternalConfirmDialog(Component JavaDoc parentComponent,
1109                                        Object JavaDoc message,
1110                                        String JavaDoc title, int optionType,
1111                                        int messageType) {
1112        return showInternalConfirmDialog(parentComponent, message, title, optionType,
1113                                         messageType, null);
1114    }
1115
1116    /**
1117     * Brings up an internal dialog panel with a specified icon, where
1118     * the number of choices is determined by the <code>optionType</code>
1119     * parameter.
1120     * The <code>messageType</code> parameter is primarily used to supply
1121     * a default icon from the look and feel.
1122     *
1123     * @param parentComponent determines the <code>Frame</code>
1124     * in which the dialog is displayed; if <code>null</code>,
1125     * or if the parentComponent has no Frame, a
1126     * default <code>Frame</code> is used
1127     * @param message the object to display in the dialog; a
1128     * <code>Component</code> object is rendered as a
1129     * <code>Component</code>; a <code>String</code>
1130     * object is rendered as a string; other objects are
1131     * converted to a <code>String</code> using the
1132     * <code>toString</code> method
1133     * @param title the title string for the dialog
1134     * @param optionType an integer designating the options available
1135     * on the dialog:
1136     * <code>YES_NO_OPTION</code>, or
1137     * <code>YES_NO_CANCEL_OPTION</code>.
1138     * @param messageType an integer designating the kind of message this is,
1139     * primarily used to determine the icon from the pluggable
1140     * Look and Feel: <code>ERROR_MESSAGE</code>,
1141     * <code>INFORMATION_MESSAGE</code>,
1142     * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
1143     * or <code>PLAIN_MESSAGE</code>
1144     * @param icon the icon to display in the dialog
1145     * @return an integer indicating the option selected by the user
1146     */

1147    public static int showInternalConfirmDialog(Component JavaDoc parentComponent,
1148                                        Object JavaDoc message,
1149                                        String JavaDoc title, int optionType,
1150                                        int messageType, Icon JavaDoc icon) {
1151        return showInternalOptionDialog(parentComponent, message, title, optionType,
1152                                        messageType, icon, null, null);
1153    }
1154
1155    /**
1156     * Brings up an internal dialog panel with a specified icon, where
1157     * the initial choice is determined by the <code>initialValue</code>
1158     * parameter and the number of choices is determined by the
1159     * <code>optionType</code> parameter.
1160     * <p>
1161     * If <code>optionType</code> is <code>YES_NO_OPTION</code>, or
1162     * <code>YES_NO_CANCEL_OPTION</code>
1163     * and the <code>options</code> parameter is <code>null</code>,
1164     * then the options are supplied by the Look and Feel.
1165     * <p>
1166     * The <code>messageType</code> parameter is primarily used to supply
1167     * a default icon from the look and feel.
1168     *
1169     * @param parentComponent determines the <code>Frame</code>
1170     * in which the dialog is displayed; if <code>null</code>,
1171     * or if the <code>parentComponent</code> has no
1172     * <code>Frame</code>, a default <code>Frame</code> is used
1173     * @param message the object to display in the dialog; a
1174     * <code>Component</code> object is rendered as a
1175     * <code>Component</code>; a <code>String</code>
1176     * object is rendered as a string. Other objects are
1177     * converted to a <code>String</code> using the
1178     * <code>toString</code> method
1179     * @param title the title string for the dialog
1180     * @param optionType an integer designating the options available
1181     * on the dialog: <code>YES_NO_OPTION</code>,
1182     * or <code>YES_NO_CANCEL_OPTION</code>
1183     * @param messageType an integer designating the kind of message this is;
1184     * primarily used to determine the icon from the
1185     * pluggable Look and Feel: <code>ERROR_MESSAGE</code>,
1186     * <code>INFORMATION_MESSAGE</code>,
1187     * <code>WARNING_MESSAGE</code>, <code>QUESTION_MESSAGE</code>,
1188     * or <code>PLAIN_MESSAGE</code>
1189     * @param icon the icon to display in the dialog
1190     * @param options an array of objects indicating the possible choices
1191     * the user can make; if the objects are components, they
1192     * are rendered properly; non-<code>String</code>
1193     * objects are rendered using their <code>toString</code>
1194     * methods; if this parameter is <code>null</code>,
1195     * the options are determined by the Look and Feel
1196     * @param initialValue the object that represents the default selection
1197     * for the dialog; only meaningful if <code>options</code>
1198     * is used; can be <code>null</code>
1199     * @return an integer indicating the option chosen by the user,
1200     * or <code>CLOSED_OPTION</code> if the user closed the Dialog
1201     */

1202    public static int showInternalOptionDialog(Component JavaDoc parentComponent,
1203                                       Object JavaDoc message,
1204                                       String JavaDoc title, int optionType,
1205                                       int messageType, Icon JavaDoc icon,
1206                                       Object JavaDoc[] options, Object JavaDoc initialValue) {
1207        JOptionPane JavaDoc pane = new JOptionPane JavaDoc(message, messageType,
1208                optionType, icon, options, initialValue);
1209        pane.putClientProperty(PopupFactory.forceHeavyWeightPopupKey,
1210                Boolean.TRUE);
1211        Component JavaDoc fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
1212                getFocusOwner();
1213
1214        pane.setInitialValue(initialValue);
1215
1216        JInternalFrame JavaDoc dialog =
1217            pane.createInternalFrame(parentComponent, title);
1218        pane.selectInitialValue();
1219        dialog.setVisible(true);
1220
1221    /* Since all input will be blocked until this dialog is dismissed,
1222     * make sure its parent containers are visible first (this component
1223     * is tested below). This is necessary for JApplets, because
1224     * because an applet normally isn't made visible until after its
1225     * start() method returns -- if this method is called from start(),
1226     * the applet will appear to hang while an invisible modal frame
1227     * waits for input.
1228     */

1229    if (dialog.isVisible() && !dialog.isShowing()) {
1230        Container JavaDoc parent = dialog.getParent();
1231        while (parent != null) {
1232        if (parent.isVisible() == false) {
1233            parent.setVisible(true);
1234        }
1235        parent = parent.getParent();
1236        }
1237    }
1238
1239        // Use reflection to get Container.startLWModal.
1240
try {
1241            Object JavaDoc obj;
1242            obj = AccessController.doPrivileged(new ModalPrivilegedAction(
1243                    Container JavaDoc.class, "startLWModal"));
1244            if (obj != null) {
1245                ((Method JavaDoc)obj).invoke(dialog, null);
1246            }
1247        } catch (IllegalAccessException JavaDoc ex) {
1248        } catch (IllegalArgumentException JavaDoc ex) {
1249        } catch (InvocationTargetException JavaDoc ex) {
1250        }
1251
1252        if (parentComponent instanceof JInternalFrame JavaDoc) {
1253            try {
1254                ((JInternalFrame JavaDoc)parentComponent).setSelected(true);
1255            } catch (java.beans.PropertyVetoException JavaDoc e) {
1256            }
1257        }
1258
1259        Object JavaDoc selectedValue = pane.getValue();
1260
1261        if (fo != null && fo.isShowing()) {
1262            fo.requestFocus();
1263        }
1264        if (selectedValue == null) {
1265            return CLOSED_OPTION;
1266        }
1267        if (options == null) {
1268            if (selectedValue instanceof Integer JavaDoc) {
1269                return ((Integer JavaDoc)selectedValue).intValue();
1270            }
1271            return CLOSED_OPTION;
1272        }
1273        for(int counter = 0, maxCounter = options.length;
1274            counter < maxCounter; counter++) {
1275            if (options[counter].equals(selectedValue)) {
1276                return counter;
1277            }
1278        }
1279        return CLOSED_OPTION;
1280    }
1281
1282    /**
1283     * Shows an internal question-message dialog requesting input from
1284     * the user parented to <code>parentComponent</code>. The dialog
1285     * is displayed in the <code>Component</code>'s frame,
1286     * and is usually positioned below the <code>Component</code>.
1287     *
1288     * @param parentComponent the parent <code>Component</code>
1289     * for the dialog
1290     * @param message the <code>Object</code> to display
1291     */

1292    public static String JavaDoc showInternalInputDialog(Component JavaDoc parentComponent,
1293                                                 Object JavaDoc message) {
1294        return showInternalInputDialog(parentComponent, message, UIManager.
1295               getString("OptionPane.inputDialogTitle", parentComponent),
1296               QUESTION_MESSAGE);
1297    }
1298
1299    /**
1300     * Shows an internal dialog requesting input from the user parented
1301     * to <code>parentComponent</code> with the dialog having the title
1302     * <code>title</code> and message type <code>messageType</code>.
1303     *
1304     * @param parentComponent the parent <code>Component</code> for the dialog
1305     * @param message the <code>Object</code> to display
1306     * @param title the <code>String</code> to display in the
1307     * dialog title bar
1308     * @param messageType the type of message that is to be displayed:
1309     * ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
1310     * QUESTION_MESSAGE, or PLAIN_MESSAGE
1311     */

1312    public static String JavaDoc showInternalInputDialog(Component JavaDoc parentComponent,
1313                             Object JavaDoc message, String JavaDoc title, int messageType) {
1314        return (String JavaDoc)showInternalInputDialog(parentComponent, message, title,
1315                                       messageType, null, null, null);
1316    }
1317
1318    /**
1319     * Prompts the user for input in a blocking internal dialog where
1320     * the initial selection, possible selections, and all other
1321     * options can be specified. The user will able to choose from
1322     * <code>selectionValues</code>, where <code>null</code>
1323     * implies the user can input
1324     * whatever they wish, usually by means of a <code>JTextField</code>.
1325     * <code>initialSelectionValue</code> is the initial value to prompt
1326     * the user with. It is up to the UI to decide how best to represent
1327     * the <code>selectionValues</code>, but usually a
1328     * <code>JComboBox</code>, <code>JList</code>, or
1329     * <code>JTextField</code> will be used.
1330     *
1331     * @param parentComponent the parent <code>Component</code> for the dialog
1332     * @param message the <code>Object</code> to display
1333     * @param title the <code>String</code> to display in the dialog
1334     * title bar
1335     * @param messageType the type of message to be displayed:
1336     * <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
1337     * <code>WARNING_MESSAGE</code>,
1338     * <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
1339     * @param icon the <code>Icon</code> image to display
1340     * @param selectionValues an array of <code>Objects</code> that
1341     * gives the possible selections
1342     * @param initialSelectionValue the value used to initialize the input
1343     * field
1344     * @return user's input, or <code>null</code> meaning the user
1345     * canceled the input
1346     */

1347    public static Object JavaDoc showInternalInputDialog(Component JavaDoc parentComponent,
1348            Object JavaDoc message, String JavaDoc title, int messageType, Icon JavaDoc icon,
1349            Object JavaDoc[] selectionValues, Object JavaDoc initialSelectionValue) {
1350        JOptionPane JavaDoc pane = new JOptionPane JavaDoc(message, messageType,
1351                OK_CANCEL_OPTION, icon, null, null);
1352        pane.putClientProperty(PopupFactory.forceHeavyWeightPopupKey,
1353                Boolean.TRUE);
1354        Component JavaDoc fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
1355                getFocusOwner();
1356
1357        pane.setWantsInput(true);
1358        pane.setSelectionValues(selectionValues);
1359        pane.setInitialSelectionValue(initialSelectionValue);
1360
1361        JInternalFrame JavaDoc dialog =
1362            pane.createInternalFrame(parentComponent, title);
1363
1364        pane.selectInitialValue();
1365        dialog.setVisible(true);
1366
1367    /* Since all input will be blocked until this dialog is dismissed,
1368     * make sure its parent containers are visible first (this component
1369     * is tested below). This is necessary for JApplets, because
1370     * because an applet normally isn't made visible until after its
1371     * start() method returns -- if this method is called from start(),
1372     * the applet will appear to hang while an invisible modal frame
1373     * waits for input.
1374     */

1375    if (dialog.isVisible() && !dialog.isShowing()) {
1376        Container JavaDoc parent = dialog.getParent();
1377        while (parent != null) {
1378        if (parent.isVisible() == false) {
1379            parent.setVisible(true);
1380        }
1381        parent = parent.getParent();
1382        }
1383    }
1384
1385        // Use reflection to get Container.startLWModal.
1386
try {
1387            Object JavaDoc obj;
1388            obj = AccessController.doPrivileged(new ModalPrivilegedAction(
1389                    Container JavaDoc.class, "startLWModal"));
1390            if (obj != null) {
1391                ((Method JavaDoc)obj).invoke(dialog, null);
1392            }
1393        } catch (IllegalAccessException JavaDoc ex) {
1394        } catch (IllegalArgumentException JavaDoc ex) {
1395        } catch (InvocationTargetException JavaDoc ex) {
1396        }
1397
1398        if (parentComponent instanceof JInternalFrame JavaDoc) {
1399            try {
1400                ((JInternalFrame JavaDoc)parentComponent).setSelected(true);
1401            } catch (java.beans.PropertyVetoException JavaDoc e) {
1402            }
1403        }
1404
1405        if (fo != null && fo.isShowing()) {
1406            fo.requestFocus();
1407        }
1408        Object JavaDoc value = pane.getInputValue();
1409
1410        if (value == UNINITIALIZED_VALUE) {
1411            return null;
1412        }
1413        return value;
1414    }
1415
1416    /**
1417     * Creates and returns an instance of <code>JInternalFrame</code>.
1418     * The internal frame is created with the specified title,
1419     * and wrapping the <code>JOptionPane</code>.
1420     * The returned <code>JInternalFrame</code> is
1421     * added to the <code>JDesktopPane</code> ancestor of
1422     * <code>parentComponent</code>, or components
1423     * parent if one its ancestors isn't a <code>JDesktopPane</code>,
1424     * or if <code>parentComponent</code>
1425     * doesn't have a parent then a <code>RuntimeException</code> is thrown.
1426     *
1427     * @param parentComponent the parent <code>Component</code> for
1428     * the internal frame
1429     * @param title the <code>String</code> to display in the
1430     * frame's title bar
1431     * @return a <code>JInternalFrame</code> containing a
1432     * <code>JOptionPane</code>
1433     * @exception RuntimeException if <code>parentComponent</code> does
1434     * not have a valid parent
1435     */

1436    public JInternalFrame JavaDoc createInternalFrame(Component JavaDoc parentComponent,
1437                                 String JavaDoc title) {
1438        Container JavaDoc parent =
1439                JOptionPane.getDesktopPaneForComponent(parentComponent);
1440
1441        if (parent == null && (parentComponent == null ||
1442                (parent = parentComponent.getParent()) == null)) {
1443            throw new RuntimeException JavaDoc("JOptionPane: parentComponent does " +
1444                    "not have a valid parent");
1445        }
1446
1447        // Option dialogs should be closable only
1448
final JInternalFrame JavaDoc iFrame = new JInternalFrame JavaDoc(title, false, true,
1449                                                           false, false);
1450
1451        iFrame.putClientProperty("JInternalFrame.frameType", "optionDialog");
1452        iFrame.putClientProperty("JInternalFrame.messageType",
1453                                 new Integer JavaDoc(getMessageType()));
1454
1455        iFrame.addInternalFrameListener(new InternalFrameAdapter JavaDoc() {
1456            public void internalFrameClosing(InternalFrameEvent JavaDoc e) {
1457                if (getValue() == UNINITIALIZED_VALUE) {
1458                    setValue(null);
1459                }
1460            }
1461        });
1462        addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
1463            public void propertyChange(PropertyChangeEvent JavaDoc event) {
1464                // Let the defaultCloseOperation handle the closing
1465
// if the user closed the iframe without selecting a button
1466
// (newValue = null in that case). Otherwise, close the dialog.
1467
if (iFrame.isVisible() &&
1468                        event.getSource() == JOptionPane.this &&
1469                        event.getPropertyName().equals(VALUE_PROPERTY)) {
1470                // Use reflection to get Container.stopLWModal().
1471
try {
1472                    Object JavaDoc obj;
1473                    obj = AccessController.doPrivileged(
1474                        new ModalPrivilegedAction(
1475                            Container JavaDoc.class, "stopLWModal"));
1476                    if (obj != null) {
1477                        ((Method JavaDoc)obj).invoke(iFrame, null);
1478                    }
1479                } catch (IllegalAccessException JavaDoc ex) {
1480                } catch (IllegalArgumentException JavaDoc ex) {
1481                } catch (InvocationTargetException JavaDoc ex) {
1482                }
1483
1484                try {
1485                    iFrame.setClosed(true);
1486                }
1487                catch (java.beans.PropertyVetoException JavaDoc e) {
1488                }
1489
1490                iFrame.setVisible(false);
1491                }
1492            }
1493        });
1494        iFrame.getContentPane().add(this, BorderLayout.CENTER);
1495        if (parent instanceof JDesktopPane JavaDoc) {
1496            parent.add(iFrame, JLayeredPane.MODAL_LAYER);
1497        } else {
1498            parent.add(iFrame, BorderLayout.CENTER);
1499        }
1500        Dimension JavaDoc iFrameSize = iFrame.getPreferredSize();
1501        Dimension JavaDoc rootSize = parent.getSize();
1502    Dimension JavaDoc parentSize = parentComponent.getSize();
1503
1504        iFrame.setBounds((rootSize.width - iFrameSize.width) / 2,
1505                         (rootSize.height - iFrameSize.height) / 2,
1506                         iFrameSize.width, iFrameSize.height);
1507    // We want dialog centered relative to its parent component
1508
Point JavaDoc iFrameCoord =
1509      SwingUtilities.convertPoint(parentComponent, 0, 0, parent);
1510    int x = (parentSize.width - iFrameSize.width) / 2 + iFrameCoord.x;
1511    int y = (parentSize.height - iFrameSize.height) / 2 + iFrameCoord.y;
1512
1513    // If possible, dialog should be fully visible
1514
int ovrx = x + iFrameSize.width - rootSize.width;
1515    int ovry = y + iFrameSize.height - rootSize.height;
1516    x = Math.max((ovrx > 0? x - ovrx: x), 0);
1517    y = Math.max((ovry > 0? y - ovry: y), 0);
1518    iFrame.setBounds(x, y, iFrameSize.width, iFrameSize.height);
1519
1520        parent.validate();
1521        try {
1522            iFrame.setSelected(true);
1523        } catch (java.beans.PropertyVetoException JavaDoc e) {}
1524 
1525        return iFrame;
1526    }
1527
1528    /**
1529     * Returns the specified component's <code>Frame</code>.
1530     *
1531     * @param parentComponent the <code>Component</code> to check for a
1532     * <code>Frame</code>
1533     * @return the <code>Frame</code> that contains the component,
1534     * or the default frame if the component is <code>null</code>,
1535     * or does not have a valid <code>Frame</code> parent
1536     * @exception HeadlessException if
1537     * <code>GraphicsEnvironment.isHeadless</code> returns
1538     * <code>true</code>
1539     * @see java.awt.GraphicsEnvironment#isHeadless
1540     */

1541    public static Frame JavaDoc getFrameForComponent(Component JavaDoc parentComponent)
1542        throws HeadlessException JavaDoc {
1543        if (parentComponent == null)
1544            return getRootFrame();
1545        if (parentComponent instanceof Frame JavaDoc)
1546            return (Frame JavaDoc)parentComponent;
1547        return JOptionPane.getFrameForComponent(parentComponent.getParent());
1548    }
1549
1550    /**
1551     * Returns the specified component's toplevel <code>Frame</code> or
1552     * <code>Dialog</code>.
1553     *
1554     * @param parentComponent the <code>Component</code> to check for a
1555     * <code>Frame</code> or <code>Dialog</code>
1556     * @return the <code>Frame</code> or <code>Dialog</code> that
1557     * contains the component, or the default
1558     * frame if the component is <code>null</code>,
1559     * or does not have a valid
1560     * <code>Frame</code> or <code>Dialog</code> parent
1561     * @exception HeadlessException if
1562     * <code>GraphicsEnvironment.isHeadless</code> returns
1563     * <code>true</code>
1564     * @see java.awt.GraphicsEnvironment#isHeadless
1565     */

1566    static Window JavaDoc getWindowForComponent(Component JavaDoc parentComponent)
1567        throws HeadlessException JavaDoc {
1568        if (parentComponent == null)
1569            return getRootFrame();
1570        if (parentComponent instanceof Frame JavaDoc || parentComponent instanceof Dialog JavaDoc)
1571            return (Window JavaDoc)parentComponent;
1572        return JOptionPane.getWindowForComponent(parentComponent.getParent());
1573    }
1574
1575
1576    /**
1577     * Returns the specified component's desktop pane.
1578     *
1579     * @param parentComponent the <code>Component</code> to check for a
1580     * desktop
1581     * @return the <code>JDesktopPane</code> that contains the component,
1582     * or <code>null</code> if the component is <code>null</code>
1583     * or does not have an ancestor that is a
1584     * <code>JInternalFrame</code>
1585     */

1586    public static JDesktopPane JavaDoc getDesktopPaneForComponent(Component JavaDoc parentComponent) {
1587        if(parentComponent == null)
1588            return null;
1589        if(parentComponent instanceof JDesktopPane JavaDoc)
1590            return (JDesktopPane JavaDoc)parentComponent;
1591        return getDesktopPaneForComponent(parentComponent.getParent());
1592    }
1593
1594    private static final Object JavaDoc sharedFrameKey = JOptionPane JavaDoc.class;
1595
1596    /**
1597     * Sets the frame to use for class methods in which a frame is
1598     * not provided.
1599     *
1600     * @param newRootFrame the default <code>Frame</code> to use
1601     */

1602    public static void setRootFrame(Frame JavaDoc newRootFrame) {
1603        if (newRootFrame != null) {
1604            SwingUtilities.appContextPut(sharedFrameKey, newRootFrame);
1605        } else {
1606            SwingUtilities.appContextRemove(sharedFrameKey);
1607        }
1608    }
1609
1610    /**
1611     * Returns the <code>Frame</code> to use for the class methods in
1612     * which a frame is not provided.
1613     *
1614     * @return the default <code>Frame</code> to use
1615     * @exception HeadlessException if
1616     * <code>GraphicsEnvironment.isHeadless</code> returns
1617     * <code>true</code>
1618     * @see java.awt.GraphicsEnvironment#isHeadless
1619     */

1620    public static Frame JavaDoc getRootFrame() throws HeadlessException JavaDoc {
1621        Frame JavaDoc sharedFrame =
1622            (Frame JavaDoc)SwingUtilities.appContextGet(sharedFrameKey);
1623        if (sharedFrame == null) {
1624            sharedFrame = SwingUtilities.getSharedOwnerFrame();
1625            SwingUtilities.appContextPut(sharedFrameKey, sharedFrame);
1626        }
1627        return sharedFrame;
1628    }
1629
1630    /**
1631     * Creates a <code>JOptionPane</code> with a test message.
1632     */

1633    public JOptionPane() {
1634        this("JOptionPane message");
1635    }
1636
1637    /**
1638     * Creates a instance of <code>JOptionPane</code> to display a
1639     * message using the
1640     * plain-message message type and the default options delivered by
1641     * the UI.
1642     *
1643     * @param message the <code>Object</code> to display
1644     */

1645    public JOptionPane(Object JavaDoc message) {
1646        this(message, PLAIN_MESSAGE);
1647    }
1648
1649    /**
1650     * Creates an instance of <code>JOptionPane</code> to display a message
1651     * with the specified message type and the default options,
1652     *
1653     * @param message the <code>Object</code> to display
1654     * @param messageType the type of message to be displayed:
1655     * <code>ERROR_MESSAGE</code>,
1656     * <code>INFORMATION_MESSAGE</code>,
1657     * <code>WARNING_MESSAGE</code>,
1658     * <code>QUESTION_MESSAGE</code>,
1659     * or <code>PLAIN_MESSAGE</code>
1660     */

1661    public JOptionPane(Object JavaDoc message, int messageType) {
1662        this(message, messageType, DEFAULT_OPTION);
1663    }
1664
1665    /**
1666     * Creates an instance of <code>JOptionPane</code> to display a message
1667     * with the specified message type and options.
1668     *
1669     * @param message the <code>Object</code> to display
1670     * @param messageType the type of message to be displayed:
1671     * <code>ERROR_MESSAGE</code>,
1672     * <code>INFORMATION_MESSAGE</code>,
1673     * <code>WARNING_MESSAGE</code>,
1674     * <code>QUESTION_MESSAGE</code>,
1675     * or <code>PLAIN_MESSAGE</code>
1676     * @param optionType the options to display in the pane:
1677     * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
1678     * <code>YES_NO_CANCEL_OPTION</code>,
1679     * <code>OK_CANCEL_OPTION</code>
1680     */

1681    public JOptionPane(Object JavaDoc message, int messageType, int optionType) {
1682        this(message, messageType, optionType, null);
1683    }
1684
1685    /**
1686     * Creates an instance of <code>JOptionPane</code> to display a message
1687     * with the specified message type, options, and icon.
1688     *
1689     * @param message the <code>Object</code> to display
1690     * @param messageType the type of message to be displayed:
1691     * <code>ERROR_MESSAGE</code>,
1692     * <code>INFORMATION_MESSAGE</code>,
1693     * <code>WARNING_MESSAGE</code>,
1694     * <code>QUESTION_MESSAGE</code>,
1695     * or <code>PLAIN_MESSAGE</code>
1696     * @param optionType the options to display in the pane:
1697     * <code>DEFAULT_OPTION</code>, <code>YES_NO_OPTION</code>,
1698     * <code>YES_NO_CANCEL_OPTION</code>,
1699     * <code>OK_CANCEL_OPTION</code>
1700     * @param icon the <code>Icon</code> image to display
1701     */

1702    public JOptionPane(Object JavaDoc message, int messageType, int optionType,
1703                       Icon JavaDoc icon) {
1704        this(message, messageType, optionType, icon, null);
1705    }
1706
1707    /**
1708     * Creates an instance of <code>JOptionPane</code> to display a message
1709     * with the specified message type, icon, and options.
1710     * None of the options is initially selected.
1711     * <p>
1712     * The options objects should contain either instances of
1713     * <code>Component</code>s, (which are added directly) or
1714     * <code>Strings</code> (which are wrapped in a <code>JButton</code>).
1715     * If you provide <code>Component</code>s, you must ensure that when the
1716     * <code>Component</code> is clicked it messages <code>setValue</code>
1717     * in the created <code>JOptionPane</code>.
1718     *
1719     * @param message the <code>Object</code> to display
1720     * @param messageType the type of message to be displayed:
1721     * <code>ERROR_MESSAGE</code>,
1722     * <code>INFORMATION_MESSAGE</code>,
1723     * <code>WARNING_MESSAGE</code>,
1724     * <code>QUESTION_MESSAGE</code>,
1725     * or <code>PLAIN_MESSAGE</code>
1726     * @param optionType the options to display in the pane:
1727     * <code>DEFAULT_OPTION</code>,
1728     * <code>YES_NO_OPTION</code>,
1729     * <code>YES_NO_CANCEL_OPTION</code>,
1730     * <code>OK_CANCEL_OPTION</code>
1731     * @param icon the <code>Icon</code> image to display
1732     * @param options the choices the user can select
1733     */

1734    public JOptionPane(Object JavaDoc message, int messageType, int optionType,
1735                       Icon JavaDoc icon, Object JavaDoc[] options) {
1736        this(message, messageType, optionType, icon, options, null);
1737    }
1738
1739    /**
1740     * Creates an instance of <code>JOptionPane</code> to display a message
1741     * with the specified message type, icon, and options, with the
1742     * initially-selected option specified.
1743     *
1744     * @param message the <code>Object</code> to display
1745     * @param messageType the type of message to be displayed:
1746     * <code>ERROR_MESSAGE</code>,
1747     * <code>INFORMATION_MESSAGE</code>,
1748     * <code>WARNING_MESSAGE</code>,
1749     * <code>QUESTION_MESSAGE</code>,
1750     * or <code>PLAIN_MESSAGE</code>
1751     * @param optionType the options to display in the pane:
1752     * <code>DEFAULT_OPTION</code>,
1753     * <code>YES_NO_OPTION</code>,
1754     * <code>YES_NO_CANCEL_OPTION</code>,
1755     * <code>OK_CANCEL_OPTION</code>
1756     * @param icon the Icon image to display
1757     * @param options the choices the user can select
1758     * @param initialValue the choice that is initially selected; if
1759     * <code>null</code>, then nothing will be initially selected;
1760     * only meaningful if <code>options</code> is used
1761     */

1762    public JOptionPane(Object JavaDoc message, int messageType, int optionType,
1763                       Icon JavaDoc icon, Object JavaDoc[] options, Object JavaDoc initialValue) {
1764
1765        this.message = message;
1766        this.options = options;
1767        this.initialValue = initialValue;
1768        this.icon = icon;
1769        setMessageType(messageType);
1770        setOptionType(optionType);
1771        value = UNINITIALIZED_VALUE;
1772        inputValue = UNINITIALIZED_VALUE;
1773        updateUI();
1774    }
1775
1776    /**
1777     * Sets the UI object which implements the L&F for this component.
1778     *
1779     * @param ui the <code>OptionPaneUI</code> L&F object
1780     * @see UIDefaults#getUI
1781     * @beaninfo
1782     * bound: true
1783     * hidden: true
1784     * description: The UI object that implements the optionpane's LookAndFeel
1785     */

1786    public void setUI(OptionPaneUI JavaDoc ui) {
1787        if ((OptionPaneUI JavaDoc)this.ui != ui) {
1788            super.setUI(ui);
1789            invalidate();
1790        }
1791    }
1792
1793    /**
1794     * Returns the UI object which implements the L&F for this component.
1795     *
1796     * @return the <code>OptionPaneUI</code> object
1797     */

1798    public OptionPaneUI JavaDoc getUI() {
1799        return (OptionPaneUI JavaDoc)ui;
1800    }
1801
1802    /**
1803     * Notification from the <code>UIManager</code> that the L&F has changed.
1804     * Replaces the current UI object with the latest version from the
1805     * <code>UIManager</code>.
1806     *
1807     * @see JComponent#updateUI
1808     */

1809    public void updateUI() {
1810        setUI((OptionPaneUI JavaDoc)UIManager.getUI(this));
1811    }
1812
1813
1814    /**
1815     * Returns the name of the UI class that implements the
1816     * L&F for this component.
1817     *
1818     * @return the string "OptionPaneUI"
1819     * @see JComponent#getUIClassID
1820     * @see UIDefaults#getUI
1821     */

1822    public String JavaDoc getUIClassID() {
1823        return uiClassID;
1824    }
1825
1826
1827    /**
1828     * Sets the option pane's message-object.
1829     * @param newMessage the <code>Object</code> to display
1830     * @see #getMessage
1831     *
1832     * @beaninfo
1833     * preferred: true
1834     * bound: true
1835     * description: The optionpane's message object.
1836     */

1837    public void setMessage(Object JavaDoc newMessage) {
1838        Object JavaDoc oldMessage = message;
1839
1840        message = newMessage;
1841        firePropertyChange(MESSAGE_PROPERTY, oldMessage, message);
1842    }
1843
1844    /**
1845     * Returns the message-object this pane displays.
1846     * @see #setMessage
1847     *
1848     * @return the <code>Object</code> that is displayed
1849     */

1850    public Object JavaDoc getMessage() {
1851        return message;
1852    }
1853
1854    /**
1855     * Sets the icon to display. If non-<code>null</code>, the look and feel
1856     * does not provide an icon.
1857     * @param newIcon the <code>Icon</code> to display
1858     *
1859     * @see #getIcon
1860     * @beaninfo
1861     * preferred: true
1862     * bound: true
1863     * description: The option pane's type icon.
1864     */

1865    public void setIcon(Icon JavaDoc newIcon) {
1866        Object JavaDoc oldIcon = icon;
1867
1868        icon = newIcon;
1869        firePropertyChange(ICON_PROPERTY, oldIcon, icon);
1870    }
1871
1872    /**
1873     * Returns the icon this pane displays.
1874     * @return the <code>Icon</code> that is displayed
1875     *
1876     * @see #setIcon
1877     */

1878    public Icon JavaDoc getIcon() {
1879        return icon;
1880    }
1881
1882    /**
1883     * Sets the value the user has chosen.
1884     * @param newValue the chosen value
1885     *
1886     * @see #getValue
1887     * @beaninfo
1888     * preferred: true
1889     * bound: true
1890     * description: The option pane's value object.
1891     */

1892    public void setValue(Object JavaDoc newValue) {
1893        Object JavaDoc oldValue = value;
1894
1895        value = newValue;
1896        firePropertyChange(VALUE_PROPERTY, oldValue, value);
1897    }
1898
1899    /**
1900     * Returns the value the user has selected. <code>UNINITIALIZED_VALUE</code>
1901     * implies the user has not yet made a choice, <code>null</code> means the
1902     * user closed the window with out choosing anything. Otherwise
1903     * the returned value will be one of the options defined in this
1904     * object.
1905     *
1906     * @return the <code>Object</code> chosen by the user,
1907     * <code>UNINITIALIZED_VALUE</code>
1908     * if the user has not yet made a choice, or <code>null</code> if
1909     * the user closed the window without making a choice
1910     *
1911     * @see #setValue
1912     */

1913    public Object JavaDoc getValue() {
1914        return value;
1915    }
1916
1917    /**
1918     * Sets the options this pane displays. If an element in
1919     * <code>newOptions</code> is a <code>Component</code>
1920     * it is added directly to the pane,
1921     * otherwise a button is created for the element.
1922     *
1923     * @param newOptions an array of <code>Objects</code> that create the
1924     * buttons the user can click on, or arbitrary
1925     * <code>Components</code> to add to the pane
1926     *
1927     * @see #getOptions
1928     * @beaninfo
1929     * bound: true
1930     * description: The option pane's options objects.
1931     */

1932    public void setOptions(Object JavaDoc[] newOptions) {
1933        Object JavaDoc[] oldOptions = options;
1934
1935        options = newOptions;
1936        firePropertyChange(OPTIONS_PROPERTY, oldOptions, options);
1937    }
1938
1939    /**
1940     * Returns the choices the user can make.
1941     * @return the array of <code>Objects</code> that give the user's choices
1942     *
1943     * @see #setOptions
1944     */

1945    public Object JavaDoc[] getOptions() {
1946        if(options != null) {
1947            int optionCount = options.length;
1948            Object JavaDoc[] retOptions = new Object JavaDoc[optionCount];
1949
1950            System.arraycopy(options, 0, retOptions, 0, optionCount);
1951            return retOptions;
1952        }
1953        return options;
1954    }
1955
1956    /**
1957     * Sets the initial value that is to be enabled -- the
1958     * <code>Component</code>
1959     * that has the focus when the pane is initially displayed.
1960     *
1961     * @param newInitialValue the <code>Object</code> that gets the initial
1962     * keyboard focus
1963     *
1964     * @see #getInitialValue
1965     * @beaninfo
1966     * preferred: true
1967     * bound: true
1968     * description: The option pane's initial value object.
1969     */

1970    public void setInitialValue(Object JavaDoc newInitialValue) {
1971        Object JavaDoc oldIV = initialValue;
1972
1973        initialValue = newInitialValue;
1974        firePropertyChange(INITIAL_VALUE_PROPERTY, oldIV, initialValue);
1975    }
1976
1977    /**
1978     * Returns the initial value.
1979     *
1980     * @return the <code>Object</code> that gets the initial keyboard focus
1981     *
1982     * @see #setInitialValue
1983     */

1984    public Object JavaDoc getInitialValue() {
1985        return initialValue;
1986    }
1987
1988    /**
1989     * Sets the option pane's message type.
1990     * The message type is used by the Look and Feel to determine the
1991     * icon to display (if not supplied) as well as potentially how to
1992     * lay out the <code>parentComponent</code>.
1993     * @param newType an integer specifying the kind of message to display:
1994     * <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
1995     * <code>WARNING_MESSAGE</code>,
1996     * <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
1997     * @exception RuntimeException if <code>newType</code> is not one of the
1998     * legal values listed above
1999
2000     * @see #getMessageType
2001     * @beaninfo
2002     * preferred: true
2003     * bound: true
2004     * description: The option pane's message type.
2005     */

2006    public void setMessageType(int newType) {
2007        if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
2008           newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
2009           newType != PLAIN_MESSAGE)
2010            throw new RuntimeException JavaDoc("JOptionPane: type must be one of JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE or JOptionPane.PLAIN_MESSAGE");
2011
2012        int oldType = messageType;
2013
2014        messageType = newType;
2015        firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
2016    }
2017
2018    /**
2019     * Returns the message type.
2020     *
2021     * @return an integer specifying the message type
2022     *
2023     * @see #setMessageType
2024     */

2025    public int getMessageType() {
2026        return messageType;
2027    }
2028
2029    /**
2030     * Sets the options to display.
2031     * The option type is used by the Look and Feel to
2032     * determine what buttons to show (unless options are supplied).
2033     * @param newType an integer specifying the options the L&F is to display:
2034     * <code>DEFAULT_OPTION</code>,
2035     * <code>YES_NO_OPTION</code>,
2036     * <code>YES_NO_CANCEL_OPTION</code>,
2037     * or <code>OK_CANCEL_OPTION</code>
2038     * @exception RuntimeException if <code>newType</code> is not one of
2039     * the legal values listed above
2040     *
2041     * @see #getOptionType
2042     * @see #setOptions
2043     * @beaninfo
2044     * preferred: true
2045     * bound: true
2046     * description: The option pane's option type.
2047      */

2048    public void setOptionType(int newType) {
2049        if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION &&
2050           newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION)
2051            throw new RuntimeException JavaDoc("JOptionPane: option type must be one of JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION or JOptionPane.OK_CANCEL_OPTION");
2052
2053        int oldType = optionType;
2054
2055        optionType = newType;
2056        firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
2057    }
2058
2059    /**
2060     * Returns the type of options that are displayed.
2061     *
2062     * @return an integer specifying the user-selectable options
2063     *
2064     * @see #setOptionType
2065     */

2066    public int getOptionType() {
2067        return optionType;
2068    }
2069
2070    /**
2071     * Sets the input selection values for a pane that provides the user
2072     * with a list of items to choose from. (The UI provides a widget
2073     * for choosing one of the values.) A <code>null</code> value
2074     * implies the user can input whatever they wish, usually by means
2075     * of a <code>JTextField</code>.
2076     * <p>
2077     * Sets <code>wantsInput</code> to true. Use
2078     * <code>setInitialSelectionValue</code> to specify the initially-chosen
2079     * value. After the pane as been enabled, <code>inputValue</code> is
2080     * set to the value the user has selected.
2081     * @param newValues an array of <code>Objects</code> the user to be
2082     * displayed
2083     * (usually in a list or combo-box) from which
2084     * the user can make a selection
2085     * @see #setWantsInput
2086     * @see #setInitialSelectionValue
2087     * @see #getSelectionValues
2088     * @beaninfo
2089     * bound: true
2090     * description: The option pane's selection values.
2091     */

2092    public void setSelectionValues(Object JavaDoc[] newValues) {
2093        Object JavaDoc[] oldValues = selectionValues;
2094
2095        selectionValues = newValues;
2096        firePropertyChange(SELECTION_VALUES_PROPERTY, oldValues, newValues);
2097        if(selectionValues != null)
2098            setWantsInput(true);
2099    }
2100
2101    /**
2102     * Returns the input selection values.
2103     *
2104     * @return the array of <code>Objects</code> the user can select
2105     * @see #setSelectionValues
2106     */

2107    public Object JavaDoc[] getSelectionValues() {
2108        return selectionValues;
2109    }
2110
2111    /**
2112     * Sets the input value that is initially displayed as selected to the user.
2113     * Only used if <code>wantsInput</code> is true.
2114     * @param newValue the initially selected value
2115     * @see #setSelectionValues
2116     * @see #getInitialSelectionValue
2117     * @beaninfo
2118     * bound: true
2119     * description: The option pane's initial selection value object.
2120     */

2121    public void setInitialSelectionValue(Object JavaDoc newValue) {
2122        Object JavaDoc oldValue = initialSelectionValue;
2123
2124        initialSelectionValue = newValue;
2125        firePropertyChange(INITIAL_SELECTION_VALUE_PROPERTY, oldValue,
2126                           newValue);
2127    }
2128
2129    /**
2130     * Returns the input value that is displayed as initially selected to the user.
2131     *
2132     * @return the initially selected value
2133     * @see #setInitialSelectionValue
2134     * @see #setSelectionValues
2135     */

2136    public Object JavaDoc getInitialSelectionValue() {
2137        return initialSelectionValue;
2138    }
2139
2140    /**
2141     * Sets the input value that was selected or input by the user.
2142     * Only used if <code>wantsInput</code> is true. Note that this method
2143     * is invoked internally by the option pane (in response to user action)
2144     * and should generally not be called by client programs. To set the
2145     * input value initially displayed as selected to the user, use
2146     * <code>setInitialSelectionValue</code>.
2147     *
2148     * @param newValue the <code>Object</code> used to set the
2149     * value that the user specified (usually in a text field)
2150     * @see #setSelectionValues
2151     * @see #setInitialSelectionValue
2152     * @see #setWantsInput
2153     * @see #getInputValue
2154     * @beaninfo
2155     * preferred: true
2156     * bound: true
2157     * description: The option pane's input value object.
2158     */

2159    public void setInputValue(Object JavaDoc newValue) {
2160        Object JavaDoc oldValue = inputValue;
2161
2162        inputValue = newValue;
2163        firePropertyChange(INPUT_VALUE_PROPERTY, oldValue, newValue);
2164    }
2165
2166    /**
2167     * Returns the value the user has input, if <code>wantsInput</code>
2168     * is true.
2169     *
2170     * @return the <code>Object</code> the user specified,
2171     * if it was one of the objects, or a
2172     * <code>String</code> if it was a value typed into a
2173     * field
2174     * @see #setSelectionValues
2175     * @see #setWantsInput
2176     * @see #setInputValue
2177     */

2178    public Object JavaDoc getInputValue() {
2179        return inputValue;
2180    }
2181
2182    /**
2183     * Returns the maximum number of characters to place on a line in a
2184     * message. Default is to return <code>Integer.MAX_VALUE</code>.
2185     * The value can be
2186     * changed by overriding this method in a subclass.
2187     *
2188     * @return an integer giving the maximum number of characters on a line
2189     */

2190    public int getMaxCharactersPerLineCount() {
2191        return Integer.MAX_VALUE;
2192    }
2193
2194    /**
2195     * Sets the <code>wantsInput</code> property.
2196     * If <code>newValue</code> is true, an input component
2197     * (such as a text field or combo box) whose parent is
2198     * <code>parentComponent</code> is provided to
2199     * allow the user to input a value. If <code>getSelectionValues</code>
2200     * returns a non-<code>null</code> array, the input value is one of the
2201     * objects in that array. Otherwise the input value is whatever
2202     * the user inputs.
2203     * <p>
2204     * This is a bound property.
2205     *
2206     * @see #setSelectionValues
2207     * @see #setInputValue
2208     * @beaninfo
2209     * preferred: true
2210     * bound: true
2211     * description: Flag which allows the user to input a value.
2212     */

2213    public void setWantsInput(boolean newValue) {
2214        boolean oldValue = wantsInput;
2215
2216        wantsInput = newValue;
2217        firePropertyChange(WANTS_INPUT_PROPERTY, oldValue, newValue);
2218    }
2219
2220    /**
2221     * Returns the value of the <code>wantsInput</code> property.
2222     *
2223     * @return true if an input component will be provided
2224     * @see #setWantsInput
2225     */

2226    public boolean getWantsInput() {
2227        return wantsInput;
2228    }
2229
2230    /**
2231     * Requests that the initial value be selected, which will set
2232     * focus to the initial value. This method
2233     * should be invoked after the window containing the option pane
2234     * is made visible.
2235     */

2236    public void selectInitialValue() {
2237        OptionPaneUI JavaDoc ui = getUI();
2238        if (ui != null) {
2239            ui.selectInitialValue(this);
2240        }
2241    }
2242
2243    
2244    private static int styleFromMessageType(int messageType) {
2245        switch (messageType) {
2246        case ERROR_MESSAGE:
2247            return JRootPane.ERROR_DIALOG;
2248        case QUESTION_MESSAGE:
2249            return JRootPane.QUESTION_DIALOG;
2250        case WARNING_MESSAGE:
2251            return JRootPane.WARNING_DIALOG;
2252        case INFORMATION_MESSAGE:
2253            return JRootPane.INFORMATION_DIALOG;
2254        case PLAIN_MESSAGE:
2255        default:
2256            return JRootPane.PLAIN_DIALOG;
2257        }
2258    }
2259    
2260    // Serialization support.
2261
private void writeObject(ObjectOutputStream JavaDoc s) throws IOException JavaDoc {
2262        Vector JavaDoc values = new Vector JavaDoc();
2263
2264        s.defaultWriteObject();
2265        // Save the icon, if its Serializable.
2266
if(icon != null && icon instanceof Serializable JavaDoc) {
2267            values.addElement("icon");
2268            values.addElement(icon);
2269        }
2270        // Save the message, if its Serializable.
2271
if(message != null && message instanceof Serializable JavaDoc) {
2272            values.addElement("message");
2273            values.addElement(message);
2274        }
2275        // Save the treeModel, if its Serializable.
2276
if(options != null) {
2277            Vector JavaDoc serOptions = new Vector JavaDoc();
2278
2279            for(int counter = 0, maxCounter = options.length;
2280                counter < maxCounter; counter++)
2281                if(options[counter] instanceof Serializable JavaDoc)
2282                    serOptions.addElement(options[counter]);
2283            if(serOptions.size() > 0) {
2284                int optionCount = serOptions.size();
2285                Object JavaDoc[] arrayOptions = new Object JavaDoc[optionCount];
2286
2287                serOptions.copyInto(arrayOptions);
2288                values.addElement("options");
2289                values.addElement(arrayOptions);
2290            }
2291        }
2292        // Save the initialValue, if its Serializable.
2293
if(initialValue != null && initialValue instanceof Serializable JavaDoc) {
2294            values.addElement("initialValue");
2295            values.addElement(initialValue);
2296        }
2297        // Save the value, if its Serializable.
2298
if(value != null && value instanceof Serializable JavaDoc) {
2299            values.addElement("value");
2300            values.addElement(value);
2301        }
2302        // Save the selectionValues, if its Serializable.
2303
if(selectionValues != null) {
2304            boolean serialize = true;
2305
2306            for(int counter = 0, maxCounter = selectionValues.length;
2307                counter < maxCounter; counter++) {
2308                if(selectionValues[counter] != null &&
2309                   !(selectionValues[counter] instanceof Serializable JavaDoc)) {
2310                    serialize = false;
2311                    break;
2312                }
2313            }
2314            if(serialize) {
2315                values.addElement("selectionValues");
2316                values.addElement(selectionValues);
2317            }
2318        }
2319        // Save the inputValue, if its Serializable.
2320
if(inputValue != null && inputValue instanceof Serializable JavaDoc) {
2321            values.addElement("inputValue");
2322            values.addElement(inputValue);
2323        }
2324        // Save the initialSelectionValue, if its Serializable.
2325
if(initialSelectionValue != null &&
2326           initialSelectionValue instanceof Serializable JavaDoc) {
2327            values.addElement("initialSelectionValue");
2328            values.addElement(initialSelectionValue);
2329        }
2330        s.writeObject(values);
2331    }
2332
2333    private void readObject(ObjectInputStream JavaDoc s)
2334        throws IOException JavaDoc, ClassNotFoundException JavaDoc {
2335        s.defaultReadObject();
2336
2337        Vector JavaDoc values = (Vector JavaDoc)s.readObject();
2338        int indexCounter = 0;
2339        int maxCounter = values.size();
2340
2341        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2342           equals("icon")) {
2343            icon = (Icon JavaDoc)values.elementAt(++indexCounter);
2344            indexCounter++;
2345        }
2346        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2347           equals("message")) {
2348            message = values.elementAt(++indexCounter);
2349            indexCounter++;
2350        }
2351        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2352           equals("options")) {
2353            options = (Object JavaDoc[])values.elementAt(++indexCounter);
2354            indexCounter++;
2355        }
2356        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2357           equals("initialValue")) {
2358            initialValue = values.elementAt(++indexCounter);
2359            indexCounter++;
2360        }
2361        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2362           equals("value")) {
2363            value = values.elementAt(++indexCounter);
2364            indexCounter++;
2365        }
2366        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2367           equals("selectionValues")) {
2368            selectionValues = (Object JavaDoc[])values.elementAt(++indexCounter);
2369            indexCounter++;
2370        }
2371        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2372           equals("inputValue")) {
2373            inputValue = values.elementAt(++indexCounter);
2374            indexCounter++;
2375        }
2376        if(indexCounter < maxCounter && values.elementAt(indexCounter).
2377           equals("initialSelectionValue")) {
2378            initialSelectionValue = values.elementAt(++indexCounter);
2379            indexCounter++;
2380        }
2381        if (getUIClassID().equals(uiClassID)) {
2382            byte count = JComponent.getWriteObjCounter(this);
2383            JComponent.setWriteObjCounter(this, --count);
2384            if (count == 0 && ui != null) {
2385                ui.installUI(this);
2386            }
2387        }
2388    }
2389
2390
2391    /**
2392     * Returns a string representation of this <code>JOptionPane</code>.
2393     * This method
2394     * is intended to be used only for debugging purposes, and the
2395     * content and format of the returned string may vary between
2396     * implementations. The returned string may be empty but may not
2397     * be <code>null</code>.
2398     *
2399     * @return a string representation of this <code>JOptionPane</code>
2400     */

2401    protected String JavaDoc paramString() {
2402        String JavaDoc iconString = (icon != null ?
2403                 icon.toString() : "");
2404        String JavaDoc initialValueString = (initialValue != null ?
2405                     initialValue.toString() : "");
2406        String JavaDoc messageString = (message != null ?
2407                message.toString() : "");
2408        String JavaDoc messageTypeString;
2409        if (messageType == ERROR_MESSAGE) {
2410            messageTypeString = "ERROR_MESSAGE";
2411        } else if (messageType == INFORMATION_MESSAGE) {
2412            messageTypeString = "INFORMATION_MESSAGE";
2413        } else if (messageType == WARNING_MESSAGE) {
2414            messageTypeString = "WARNING_MESSAGE";
2415        } else if (messageType == QUESTION_MESSAGE) {
2416            messageTypeString = "QUESTION_MESSAGE";
2417        } else if (messageType == PLAIN_MESSAGE) {
2418            messageTypeString = "PLAIN_MESSAGE";
2419        } else messageTypeString = "";
2420        String JavaDoc optionTypeString;
2421        if (optionType == DEFAULT_OPTION) {
2422            optionTypeString = "DEFAULT_OPTION";
2423        } else if (optionType == YES_NO_OPTION) {
2424            optionTypeString = "YES_NO_OPTION";
2425        } else if (optionType == YES_NO_CANCEL_OPTION) {
2426            optionTypeString = "YES_NO_CANCEL_OPTION";
2427        } else if (optionType == OK_CANCEL_OPTION) {
2428            optionTypeString = "OK_CANCEL_OPTION";
2429        } else optionTypeString = "";
2430        String JavaDoc wantsInputString = (wantsInput ?
2431                   "true" : "false");
2432
2433        return super.paramString() +
2434        ",icon=" + iconString +
2435        ",initialValue=" + initialValueString +
2436        ",message=" + messageString +
2437        ",messageType=" + messageTypeString +
2438        ",optionType=" + optionTypeString +
2439        ",wantsInput=" + wantsInputString;
2440    }
2441
2442    /**
2443     * Retrieves a method from the provided class and makes it accessible.
2444     */

2445    private static class ModalPrivilegedAction implements PrivilegedAction JavaDoc {
2446        private Class JavaDoc clazz;
2447        private String JavaDoc methodName;
2448
2449        public ModalPrivilegedAction(Class JavaDoc clazz, String JavaDoc methodName) {
2450            this.clazz = clazz;
2451            this.methodName = methodName;
2452        }
2453
2454        public Object JavaDoc run() {
2455            Method JavaDoc method = null;
2456            try {
2457                method = clazz.getDeclaredMethod(methodName, null);
2458            } catch (NoSuchMethodException JavaDoc ex) {
2459            }
2460            if (method != null) {
2461                method.setAccessible(true);
2462            }
2463            return method;
2464        }
2465    }
2466
2467
2468
2469///////////////////
2470
// Accessibility support
2471
///////////////////
2472

2473    /**
2474     * Returns the <code>AccessibleContext</code> associated with this JOptionPane.
2475     * For option panes, the <code>AccessibleContext</code> takes the form of an
2476     * <code>AccessibleJOptionPane</code>.
2477     * A new <code>AccessibleJOptionPane</code> instance is created if necessary.
2478     *
2479     * @return an AccessibleJOptionPane that serves as the
2480     * AccessibleContext of this AccessibleJOptionPane
2481     * @beaninfo
2482     * expert: true
2483     * description: The AccessibleContext associated with this option pane
2484     */

2485    public AccessibleContext getAccessibleContext() {
2486        if (accessibleContext == null) {
2487            accessibleContext = new AccessibleJOptionPane();
2488        }
2489        return accessibleContext;
2490    }
2491
2492    /**
2493     * This class implements accessibility support for the
2494     * <code>JOptionPane</code> class. It provides an implementation of the
2495     * Java Accessibility API appropriate to option pane user-interface
2496     * elements.
2497     * <p>
2498     * <strong>Warning:</strong>
2499     * Serialized objects of this class will not be compatible with
2500     * future Swing releases. The current serialization support is
2501     * appropriate for short term storage or RMI between applications running
2502     * the same version of Swing. As of 1.4, support for long term storage
2503     * of all JavaBeans<sup><font size="-2">TM</font></sup>
2504     * has been added to the <code>java.beans</code> package.
2505     * Please see {@link java.beans.XMLEncoder}.
2506     */

2507    protected class AccessibleJOptionPane extends AccessibleJComponent {
2508
2509        /**
2510         * Get the role of this object.
2511         *
2512         * @return an instance of AccessibleRole describing the role of the object
2513         * @see AccessibleRole
2514         */

2515        public AccessibleRole getAccessibleRole() {
2516            return AccessibleRole.OPTION_PANE;
2517        }
2518
2519    } // inner class AccessibleJOptionPane
2520
}
2521
2522
Popular Tags