0001 /*
0002 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
0003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004 *
0005 * This code is free software; you can redistribute it and/or modify it
0006 * under the terms of the GNU General Public License version 2 only, as
0007 * published by the Free Software Foundation. Sun designates this
0008 * particular file as subject to the "Classpath" exception as provided
0009 * by Sun in the LICENSE file that accompanied this code.
0010 *
0011 * This code is distributed in the hope that it will be useful, but WITHOUT
0012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0014 * version 2 for more details (a copy is included in the LICENSE file that
0015 * accompanied this code).
0016 *
0017 * You should have received a copy of the GNU General Public License version
0018 * 2 along with this work; if not, write to the Free Software Foundation,
0019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020 *
0021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022 * CA 95054 USA or visit www.sun.com if you need additional information or
0023 * have any questions.
0024 */
0025 package javax.swing;
0026
0027 import java.awt.*;
0028 import java.awt.event.*;
0029 import java.beans.PropertyChangeListener;
0030 import java.util.Locale;
0031 import java.util.Vector;
0032 import java.io.Serializable;
0033 import javax.accessibility.*;
0034 import java.applet.Applet;
0035
0036 /**
0037 * The main class for creating a dialog window. You can use this class
0038 * to create a custom dialog, or invoke the many class methods
0039 * in {@link JOptionPane} to create a variety of standard dialogs.
0040 * For information about creating dialogs, see
0041 * <em>The Java Tutorial</em> section
0042 * <a
0043 href="http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html">How
0044 * to Make Dialogs</a>.
0045 *
0046 * <p>
0047 *
0048 * The <code>JDialog</code> component contains a <code>JRootPane</code>
0049 * as its only child.
0050 * The <code>contentPane</code> should be the parent of any children of the
0051 * <code>JDialog</code>.
0052 * As a convenience <code>add</code> and its variants, <code>remove</code> and
0053 * <code>setLayout</code> have been overridden to forward to the
0054 * <code>contentPane</code> as necessary. This means you can write:
0055 * <pre>
0056 * dialog.add(child);
0057 * </pre>
0058 * And the child will be added to the contentPane.
0059 * The <code>contentPane</code> is always non-<code>null</code>.
0060 * Attempting to set it to <code>null</code> generates an exception.
0061 * The default <code>contentPane</code> has a <code>BorderLayout</code>
0062 * manager set on it.
0063 * Refer to {@link javax.swing.RootPaneContainer}
0064 * for details on adding, removing and setting the <code>LayoutManager</code>
0065 * of a <code>JDialog</code>.
0066 * <p>
0067 * Please see the <code>JRootPane</code> documentation for a complete
0068 * description of the <code>contentPane</code>, <code>glassPane</code>,
0069 * and <code>layeredPane</code> components.
0070 * <p>
0071 * In a multi-screen environment, you can create a <code>JDialog</code>
0072 * on a different screen device than its owner. See {@link java.awt.Frame} for
0073 * more information.
0074 * <p>
0075 * <strong>Warning:</strong> Swing is not thread safe. For more
0076 * information see <a
0077 * href="package-summary.html#threading">Swing's Threading
0078 * Policy</a>.
0079 * <p>
0080 * <strong>Warning:</strong>
0081 * Serialized objects of this class will not be compatible with
0082 * future Swing releases. The current serialization support is
0083 * appropriate for short term storage or RMI between applications running
0084 * the same version of Swing. As of 1.4, support for long term storage
0085 * of all JavaBeans<sup><font size="-2">TM</font></sup>
0086 * has been added to the <code>java.beans</code> package.
0087 * Please see {@link java.beans.XMLEncoder}.
0088 *
0089 * @see JOptionPane
0090 * @see JRootPane
0091 * @see javax.swing.RootPaneContainer
0092 *
0093 * @beaninfo
0094 * attribute: isContainer true
0095 * attribute: containerDelegate getContentPane
0096 * description: A toplevel window for creating dialog boxes.
0097 *
0098 * @version 1.99 05/05/07
0099 * @author David Kloba
0100 * @author James Gosling
0101 * @author Scott Violet
0102 */
0103 public class JDialog extends Dialog implements WindowConstants,
0104 Accessible, RootPaneContainer,
0105 TransferHandler.HasGetTransferHandler {
0106 /**
0107 * Key into the AppContext, used to check if should provide decorations
0108 * by default.
0109 */
0110 private static final Object defaultLookAndFeelDecoratedKey = new StringBuffer(
0111 "JDialog.defaultLookAndFeelDecorated");
0112
0113 private int defaultCloseOperation = HIDE_ON_CLOSE;
0114
0115 /**
0116 * @see #getRootPane
0117 * @see #setRootPane
0118 */
0119 protected JRootPane rootPane;
0120
0121 /**
0122 * If true then calls to <code>add</code> and <code>setLayout</code>
0123 * will be forwarded to the <code>contentPane</code>. This is initially
0124 * false, but is set to true when the <code>JDialog</code> is constructed.
0125 *
0126 * @see #isRootPaneCheckingEnabled
0127 * @see #setRootPaneCheckingEnabled
0128 * @see javax.swing.RootPaneContainer
0129 */
0130 protected boolean rootPaneCheckingEnabled = false;
0131
0132 /**
0133 * The <code>TransferHandler</code> for this dialog.
0134 */
0135 private TransferHandler transferHandler;
0136
0137 /**
0138 * Creates a modeless dialog without a title and without a specified
0139 * <code>Frame</code> owner. A shared, hidden frame will be
0140 * set as the owner of the dialog.
0141 * <p>
0142 * This constructor sets the component's locale property to the value
0143 * returned by <code>JComponent.getDefaultLocale</code>.
0144 * <p>
0145 * NOTE: This constructor does not allow you to create an unowned
0146 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0147 * you must use either the <code>JDialog(Window)</code> or
0148 * <code>JDialog(Dialog)</code> constructor with an argument of
0149 * <code>null</code>.
0150 *
0151 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0152 * returns <code>true</code>.
0153 * @see java.awt.GraphicsEnvironment#isHeadless
0154 * @see JComponent#getDefaultLocale
0155 */
0156 public JDialog() {
0157 this ((Frame) null, false);
0158 }
0159
0160 /**
0161 * Creates a modeless dialog without a title with the
0162 * specified <code>Frame</code> as its owner. If <code>owner</code>
0163 * is <code>null</code>, a shared, hidden frame will be set as the
0164 * owner of the dialog.
0165 * <p>
0166 * This constructor sets the component's locale property to the value
0167 * returned by <code>JComponent.getDefaultLocale</code>.
0168 * <p>
0169 * NOTE: This constructor does not allow you to create an unowned
0170 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0171 * you must use either the <code>JDialog(Window)</code> or
0172 * <code>JDialog(Dialog)</code> constructor with an argument of
0173 * <code>null</code>.
0174 *
0175 * @param owner the <code>Frame</code> from which the dialog is displayed
0176 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0177 * returns <code>true</code>.
0178 * @see java.awt.GraphicsEnvironment#isHeadless
0179 * @see JComponent#getDefaultLocale
0180 */
0181 public JDialog(Frame owner) {
0182 this (owner, false);
0183 }
0184
0185 /**
0186 * Creates a dialog with the specified owner <code>Frame</code>, modality
0187 * and an empty title. If <code>owner</code> is <code>null</code>,
0188 * a shared, hidden frame will be set as the owner of the dialog.
0189 * <p>
0190 * This constructor sets the component's locale property to the value
0191 * returned by <code>JComponent.getDefaultLocale</code>.
0192 * <p>
0193 * NOTE: This constructor does not allow you to create an unowned
0194 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0195 * you must use either the <code>JDialog(Window)</code> or
0196 * <code>JDialog(Dialog)</code> constructor with an argument of
0197 * <code>null</code>.
0198 *
0199 * @param owner the <code>Frame</code> from which the dialog is displayed
0200 * @param modal specifies whether dialog blocks user input to other top-level
0201 * windows when shown. If <code>true</code>, the modality type property is set to
0202 * <code>DEFAULT_MODALITY_TYPE</code>, otherwise the dialog is modeless.
0203 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0204 * returns <code>true</code>.
0205 * @see java.awt.GraphicsEnvironment#isHeadless
0206 * @see JComponent#getDefaultLocale
0207 */
0208 public JDialog(Frame owner, boolean modal) {
0209 this (owner, null, modal);
0210 }
0211
0212 /**
0213 * Creates a modeless dialog with the specified title and
0214 * with the specified owner frame. If <code>owner</code>
0215 * is <code>null</code>, a shared, hidden frame will be set as the
0216 * owner of the dialog.
0217 * <p>
0218 * This constructor sets the component's locale property to the value
0219 * returned by <code>JComponent.getDefaultLocale</code>.
0220 * <p>
0221 * NOTE: This constructor does not allow you to create an unowned
0222 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0223 * you must use either the <code>JDialog(Window)</code> or
0224 * <code>JDialog(Dialog)</code> constructor with an argument of
0225 * <code>null</code>.
0226 *
0227 * @param owner the <code>Frame</code> from which the dialog is displayed
0228 * @param title the <code>String</code> to display in the dialog's
0229 * title bar
0230 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0231 * returns <code>true</code>.
0232 * @see java.awt.GraphicsEnvironment#isHeadless
0233 * @see JComponent#getDefaultLocale
0234 */
0235 public JDialog(Frame owner, String title) {
0236 this (owner, title, false);
0237 }
0238
0239 /**
0240 * Creates a dialog with the specified title, owner <code>Frame</code>
0241 * and modality. If <code>owner</code> is <code>null</code>,
0242 * a shared, hidden frame will be set as the owner of this dialog.
0243 * <p>
0244 * This constructor sets the component's locale property to the value
0245 * returned by <code>JComponent.getDefaultLocale</code>.
0246 * <p>
0247 * NOTE: Any popup components (<code>JComboBox</code>,
0248 * <code>JPopupMenu</code>, <code>JMenuBar</code>)
0249 * created within a modal dialog will be forced to be lightweight.
0250 * <p>
0251 * NOTE: This constructor does not allow you to create an unowned
0252 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0253 * you must use either the <code>JDialog(Window)</code> or
0254 * <code>JDialog(Dialog)</code> constructor with an argument of
0255 * <code>null</code>.
0256 *
0257 * @param owner the <code>Frame</code> from which the dialog is displayed
0258 * @param title the <code>String</code> to display in the dialog's
0259 * title bar
0260 * @param modal specifies whether dialog blocks user input to other top-level
0261 * windows when shown. If <code>true</code>, the modality type property is set to
0262 * <code>DEFAULT_MODALITY_TYPE</code> otherwise the dialog is modeless
0263 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0264 * returns <code>true</code>.
0265 *
0266 * @see java.awt.Dialog.ModalityType
0267 * @see java.awt.Dialog.ModalityType#MODELESS
0268 * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0269 * @see java.awt.Dialog#setModal
0270 * @see java.awt.Dialog#setModalityType
0271 * @see java.awt.GraphicsEnvironment#isHeadless
0272 * @see JComponent#getDefaultLocale
0273 */
0274 public JDialog(Frame owner, String title, boolean modal) {
0275 super (owner == null ? SwingUtilities.getSharedOwnerFrame()
0276 : owner, title, modal);
0277 if (owner == null) {
0278 WindowListener ownerShutdownListener = (WindowListener) SwingUtilities
0279 .getSharedOwnerFrameShutdownListener();
0280 addWindowListener(ownerShutdownListener);
0281 }
0282 dialogInit();
0283 }
0284
0285 /**
0286 * Creates a dialog with the specified title,
0287 * owner <code>Frame</code>, modality and <code>GraphicsConfiguration</code>.
0288 * If <code>owner</code> is <code>null</code>,
0289 * a shared, hidden frame will be set as the owner of this dialog.
0290 * <p>
0291 * This constructor sets the component's locale property to the value
0292 * returned by <code>JComponent.getDefaultLocale</code>.
0293 * <p>
0294 * NOTE: Any popup components (<code>JComboBox</code>,
0295 * <code>JPopupMenu</code>, <code>JMenuBar</code>)
0296 * created within a modal dialog will be forced to be lightweight.
0297 * <p>
0298 * NOTE: This constructor does not allow you to create an unowned
0299 * <code>JDialog</code>. To create an unowned <code>JDialog</code>
0300 * you must use either the <code>JDialog(Window)</code> or
0301 * <code>JDialog(Dialog)</code> constructor with an argument of
0302 * <code>null</code>.
0303 *
0304 * @param owner the <code>Frame</code> from which the dialog is displayed
0305 * @param title the <code>String</code> to display in the dialog's
0306 * title bar
0307 * @param modal specifies whether dialog blocks user input to other top-level
0308 * windows when shown. If <code>true</code>, the modality type property is set to
0309 * <code>DEFAULT_MODALITY_TYPE</code>, otherwise the dialog is modeless.
0310 * @param gc the <code>GraphicsConfiguration</code>
0311 * of the target screen device. If <code>gc</code> is
0312 * <code>null</code>, the same
0313 * <code>GraphicsConfiguration</code> as the owning Frame is used.
0314 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0315 * returns <code>true</code>.
0316 * @see java.awt.Dialog.ModalityType
0317 * @see java.awt.Dialog.ModalityType#MODELESS
0318 * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0319 * @see java.awt.Dialog#setModal
0320 * @see java.awt.Dialog#setModalityType
0321 * @see java.awt.GraphicsEnvironment#isHeadless
0322 * @see JComponent#getDefaultLocale
0323 * @since 1.4
0324 */
0325 public JDialog(Frame owner, String title, boolean modal,
0326 GraphicsConfiguration gc) {
0327 super (owner == null ? SwingUtilities.getSharedOwnerFrame()
0328 : owner, title, modal, gc);
0329 if (owner == null) {
0330 WindowListener ownerShutdownListener = (WindowListener) SwingUtilities
0331 .getSharedOwnerFrameShutdownListener();
0332 addWindowListener(ownerShutdownListener);
0333 }
0334 dialogInit();
0335 }
0336
0337 /**
0338 * Creates a modeless dialog without a title with the
0339 * specified <code>Dialog</code> as its owner.
0340 * <p>
0341 * This constructor sets the component's locale property to the value
0342 * returned by <code>JComponent.getDefaultLocale</code>.
0343 *
0344 * @param owner the owner <code>Dialog</code> from which the dialog is displayed
0345 * or <code>null</code> if this dialog has no owner
0346 * @exception HeadlessException <code>if GraphicsEnvironment.isHeadless()</code>
0347 * returns <code>true</code>.
0348 * @see java.awt.GraphicsEnvironment#isHeadless
0349 * @see JComponent#getDefaultLocale
0350 */
0351 public JDialog(Dialog owner) {
0352 this (owner, false);
0353 }
0354
0355 /**
0356 * Creates a dialog with the specified owner <code>Dialog</code> and modality.
0357 * <p>
0358 * This constructor sets the component's locale property to the value
0359 * returned by <code>JComponent.getDefaultLocale</code>.
0360 *
0361 * @param owner the owner <code>Dialog</code> from which the dialog is displayed
0362 * or <code>null</code> if this dialog has no owner
0363 * @param modal specifies whether dialog blocks user input to other top-level
0364 * windows when shown. If <code>true</code>, the modality type property is set to
0365 * <code>DEFAULT_MODALITY_TYPE</code>, otherwise the dialog is modeless.
0366 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0367 * returns <code>true</code>.
0368 * @see java.awt.Dialog.ModalityType
0369 * @see java.awt.Dialog.ModalityType#MODELESS
0370 * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0371 * @see java.awt.Dialog#setModal
0372 * @see java.awt.Dialog#setModalityType
0373 * @see java.awt.GraphicsEnvironment#isHeadless
0374 * @see JComponent#getDefaultLocale
0375 */
0376 public JDialog(Dialog owner, boolean modal) {
0377 this (owner, null, modal);
0378 }
0379
0380 /**
0381 * Creates a modeless dialog with the specified title and
0382 * with the specified owner dialog.
0383 * <p>
0384 * This constructor sets the component's locale property to the value
0385 * returned by <code>JComponent.getDefaultLocale</code>.
0386 *
0387 * @param owner the owner <code>Dialog</code> from which the dialog is displayed
0388 * or <code>null</code> if this dialog has no owner
0389 * @param title the <code>String</code> to display in the dialog's
0390 * title bar
0391 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0392 * returns <code>true</code>.
0393 * @see java.awt.GraphicsEnvironment#isHeadless
0394 * @see JComponent#getDefaultLocale
0395 */
0396 public JDialog(Dialog owner, String title) {
0397 this (owner, title, false);
0398 }
0399
0400 /**
0401 * Creates a dialog with the specified title, modality
0402 * and the specified owner <code>Dialog</code>.
0403 * <p>
0404 * This constructor sets the component's locale property to the value
0405 * returned by <code>JComponent.getDefaultLocale</code>.
0406 *
0407 * @param owner the owner <code>Dialog</code> from which the dialog is displayed
0408 * or <code>null</code> if this dialog has no owner
0409 * @param title the <code>String</code> to display in the dialog's
0410 * title bar
0411 * @param modal specifies whether dialog blocks user input to other top-level
0412 * windows when shown. If <code>true</code>, the modality type property is set to
0413 * <code>DEFAULT_MODALITY_TYPE</code>, otherwise the dialog is modeless
0414 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0415 * returns <code>true</code>.
0416 * @see java.awt.Dialog.ModalityType
0417 * @see java.awt.Dialog.ModalityType#MODELESS
0418 * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0419 * @see java.awt.Dialog#setModal
0420 * @see java.awt.Dialog#setModalityType
0421 * @see java.awt.GraphicsEnvironment#isHeadless
0422 * @see JComponent#getDefaultLocale
0423 */
0424 public JDialog(Dialog owner, String title, boolean modal) {
0425 super (owner, title, modal);
0426 dialogInit();
0427 }
0428
0429 /**
0430 * Creates a dialog with the specified title, owner <code>Dialog</code>,
0431 * modality and <code>GraphicsConfiguration</code>.
0432 *
0433 * <p>
0434 * NOTE: Any popup components (<code>JComboBox</code>,
0435 * <code>JPopupMenu</code>, <code>JMenuBar</code>)
0436 * created within a modal dialog will be forced to be lightweight.
0437 * <p>
0438 * This constructor sets the component's locale property to the value
0439 * returned by <code>JComponent.getDefaultLocale</code>.
0440 *
0441 * @param owner the owner <code>Dialog</code> from which the dialog is displayed
0442 * or <code>null</code> if this dialog has no owner
0443 * @param title the <code>String</code> to display in the dialog's
0444 * title bar
0445 * @param modal specifies whether dialog blocks user input to other top-level
0446 * windows when shown. If <code>true</code>, the modality type property is set to
0447 * <code>DEFAULT_MODALITY_TYPE</code>, otherwise the dialog is modeless
0448 * @param gc the <code>GraphicsConfiguration</code>
0449 * of the target screen device. If <code>gc</code> is
0450 * <code>null</code>, the same
0451 * <code>GraphicsConfiguration</code> as the owning Dialog is used.
0452 * @exception HeadlessException if <code>GraphicsEnvironment.isHeadless()</code>
0453 * returns <code>true</code>.
0454 * @see java.awt.Dialog.ModalityType
0455 * @see java.awt.Dialog.ModalityType#MODELESS
0456 * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0457 * @see java.awt.Dialog#setModal
0458 * @see java.awt.Dialog#setModalityType
0459 * @see java.awt.GraphicsEnvironment#isHeadless
0460 * @see JComponent#getDefaultLocale
0461 * @since 1.4
0462 */
0463 public JDialog(Dialog owner, String title, boolean modal,
0464 GraphicsConfiguration gc) {
0465 super (owner, title, modal, gc);
0466 dialogInit();
0467 }
0468
0469 /**
0470 * Creates a modeless dialog with the specified owner <code>Window</code> and
0471 * an empty title.
0472 * <p>
0473 * This constructor sets the component's locale property to the value
0474 * returned by <code>JComponent.getDefaultLocale</code>.
0475 *
0476 * @param owner the <code>Window</code> from which the dialog is displayed or
0477 * <code>null</code> if this dialog has no owner
0478 * @exception HeadlessException when
0479 * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0480 *
0481 * @see java.awt.GraphicsEnvironment#isHeadless
0482 * @see JComponent#getDefaultLocale
0483 *
0484 * @since 1.6
0485 */
0486 public JDialog(Window owner) {
0487 this (owner, Dialog.ModalityType.MODELESS);
0488 }
0489
0490 /**
0491 * Creates a dialog with the specified owner <code>Window</code>, modality
0492 * and an empty title.
0493 * <p>
0494 * This constructor sets the component's locale property to the value
0495 * returned by <code>JComponent.getDefaultLocale</code>.
0496 *
0497 * @param owner the <code>Window</code> from which the dialog is displayed or
0498 * <code>null</code> if this dialog has no owner
0499 * @param modalityType specifies whether dialog blocks input to other
0500 * windows when shown. <code>null</code> value and unsupported modality
0501 * types are equivalent to <code>MODELESS</code>
0502 * @exception HeadlessException when
0503 * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0504 *
0505 * @see java.awt.Dialog.ModalityType
0506 * @see java.awt.Dialog#setModal
0507 * @see java.awt.Dialog#setModalityType
0508 * @see java.awt.GraphicsEnvironment#isHeadless
0509 * @see JComponent#getDefaultLocale
0510 *
0511 * @since 1.6
0512 */
0513 public JDialog(Window owner, ModalityType modalityType) {
0514 this (owner, null, modalityType);
0515 }
0516
0517 /**
0518 * Creates a modeless dialog with the specified title and owner
0519 * <code>Window</code>.
0520 * <p>
0521 * This constructor sets the component's locale property to the value
0522 * returned by <code>JComponent.getDefaultLocale</code>.
0523 *
0524 * @param owner the <code>Window</code> from which the dialog is displayed or
0525 * <code>null</code> if this dialog has no owner
0526 * @param title the <code>String</code> to display in the dialog's
0527 * title bar or <code>null</code> if the dialog has no title
0528 * @exception java.awt.HeadlessException when
0529 * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0530 *
0531 * @see java.awt.GraphicsEnvironment#isHeadless
0532 * @see JComponent#getDefaultLocale
0533 *
0534 * @since 1.6
0535 */
0536 public JDialog(Window owner, String title) {
0537 this (owner, title, Dialog.ModalityType.MODELESS);
0538 }
0539
0540 /**
0541 * Creates a dialog with the specified title, owner <code>Window</code> and
0542 * modality.
0543 * <p>
0544 * This constructor sets the component's locale property to the value
0545 * returned by <code>JComponent.getDefaultLocale</code>.
0546 *
0547 * @param owner the <code>Window</code> from which the dialog is displayed or
0548 * <code>null</code> if this dialog has no owner
0549 * @param title the <code>String</code> to display in the dialog's
0550 * title bar or <code>null</code> if the dialog has no title
0551 * @param modalityType specifies whether dialog blocks input to other
0552 * windows when shown. <code>null</code> value and unsupported modality
0553 * types are equivalent to <code>MODELESS</code>
0554 * @exception java.awt.HeadlessException when
0555 * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0556 *
0557 * @see java.awt.Dialog.ModalityType
0558 * @see java.awt.Dialog#setModal
0559 * @see java.awt.Dialog#setModalityType
0560 * @see java.awt.GraphicsEnvironment#isHeadless
0561 * @see JComponent#getDefaultLocale
0562 *
0563 * @since 1.6
0564 */
0565 public JDialog(Window owner, String title,
0566 Dialog.ModalityType modalityType) {
0567 super (owner, title, modalityType);
0568 dialogInit();
0569 }
0570
0571 /**
0572 * Creates a dialog with the specified title, owner <code>Window</code>,
0573 * modality and <code>GraphicsConfiguration</code>.
0574 * <p>
0575 * NOTE: Any popup components (<code>JComboBox</code>,
0576 * <code>JPopupMenu</code>, <code>JMenuBar</code>)
0577 * created within a modal dialog will be forced to be lightweight.
0578 * <p>
0579 * This constructor sets the component's locale property to the value
0580 * returned by <code>JComponent.getDefaultLocale</code>.
0581 *
0582 * @param owner the <code>Window</code> from which the dialog is displayed or
0583 * <code>null</code> if this dialog has no owner
0584 * @param title the <code>String</code> to display in the dialog's
0585 * title bar or <code>null</code> if the dialog has no title
0586 * @param modalityType specifies whether dialog blocks input to other
0587 * windows when shown. <code>null</code> value and unsupported modality
0588 * types are equivalent to <code>MODELESS</code>
0589 * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
0590 * if <code>null</code>, the <code>GraphicsConfiguration</code> from the owning
0591 * window is used; if <code>owner</code> is also <code>null</code>, the
0592 * system default <code>GraphicsConfiguration</code> is assumed
0593 * @exception java.awt.HeadlessException when
0594 * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0595 *
0596 * @see java.awt.Dialog.ModalityType
0597 * @see java.awt.Dialog#setModal
0598 * @see java.awt.Dialog#setModalityType
0599 * @see java.awt.GraphicsEnvironment#isHeadless
0600 * @see JComponent#getDefaultLocale
0601 *
0602 * @since 1.6
0603 */
0604 public JDialog(Window owner, String title,
0605 Dialog.ModalityType modalityType, GraphicsConfiguration gc) {
0606 super (owner, title, modalityType, gc);
0607 dialogInit();
0608 }
0609
0610 /**
0611 * Called by the constructors to init the <code>JDialog</code> properly.
0612 */
0613 protected void dialogInit() {
0614 enableEvents(AWTEvent.KEY_EVENT_MASK
0615 | AWTEvent.WINDOW_EVENT_MASK);
0616 setLocale(JComponent.getDefaultLocale());
0617 setRootPane(createRootPane());
0618 setRootPaneCheckingEnabled(true);
0619 if (JDialog.isDefaultLookAndFeelDecorated()) {
0620 boolean supportsWindowDecorations = UIManager
0621 .getLookAndFeel().getSupportsWindowDecorations();
0622 if (supportsWindowDecorations) {
0623 setUndecorated(true);
0624 getRootPane().setWindowDecorationStyle(
0625 JRootPane.PLAIN_DIALOG);
0626 }
0627 }
0628 sun.awt.SunToolkit.checkAndSetPolicy(this , true);
0629 }
0630
0631 /**
0632 * Called by the constructor methods to create the default
0633 * <code>rootPane</code>.
0634 */
0635 protected JRootPane createRootPane() {
0636 JRootPane rp = new JRootPane();
0637 // NOTE: this uses setOpaque vs LookAndFeel.installProperty as there
0638 // is NO reason for the RootPane not to be opaque. For painting to
0639 // work the contentPane must be opaque, therefor the RootPane can
0640 // also be opaque.
0641 rp.setOpaque(true);
0642 return rp;
0643 }
0644
0645 /**
0646 * Handles window events depending on the state of the
0647 * <code>defaultCloseOperation</code> property.
0648 *
0649 * @see #setDefaultCloseOperation
0650 */
0651 protected void processWindowEvent(WindowEvent e) {
0652 super .processWindowEvent(e);
0653
0654 if (e.getID() == WindowEvent.WINDOW_CLOSING) {
0655 switch (defaultCloseOperation) {
0656 case HIDE_ON_CLOSE:
0657 setVisible(false);
0658 break;
0659 case DISPOSE_ON_CLOSE:
0660 dispose();
0661 break;
0662 case DO_NOTHING_ON_CLOSE:
0663 default:
0664 break;
0665 }
0666 }
0667 }
0668
0669 /**
0670 * Sets the operation that will happen by default when
0671 * the user initiates a "close" on this dialog.
0672 * You must specify one of the following choices:
0673 * <p>
0674 * <ul>
0675 * <li><code>DO_NOTHING_ON_CLOSE</code>
0676 * (defined in <code>WindowConstants</code>):
0677 * Don't do anything; require the
0678 * program to handle the operation in the <code>windowClosing</code>
0679 * method of a registered <code>WindowListener</code> object.
0680 *
0681 * <li><code>HIDE_ON_CLOSE</code>
0682 * (defined in <code>WindowConstants</code>):
0683 * Automatically hide the dialog after
0684 * invoking any registered <code>WindowListener</code>
0685 * objects.
0686 *
0687 * <li><code>DISPOSE_ON_CLOSE</code>
0688 * (defined in <code>WindowConstants</code>):
0689 * Automatically hide and dispose the
0690 * dialog after invoking any registered <code>WindowListener</code>
0691 * objects.
0692 * </ul>
0693 * <p>
0694 * The value is set to <code>HIDE_ON_CLOSE</code> by default. Changes
0695 * to the value of this property cause the firing of a property
0696 * change event, with property name "defaultCloseOperation".
0697 * <p>
0698 * <b>Note</b>: When the last displayable window within the
0699 * Java virtual machine (VM) is disposed of, the VM may
0700 * terminate. See <a href="../../java/awt/doc-files/AWTThreadIssues.html">
0701 * AWT Threading Issues</a> for more information.
0702 *
0703 * @param operation the operation which should be performed when the
0704 * user closes the dialog
0705 * @throws IllegalArgumentException if defaultCloseOperation value
0706 * isn't one of the above valid values
0707 * @see #addWindowListener
0708 * @see #getDefaultCloseOperation
0709 * @see WindowConstants
0710 *
0711 * @beaninfo
0712 * preferred: true
0713 * bound: true
0714 * enum: DO_NOTHING_ON_CLOSE WindowConstants.DO_NOTHING_ON_CLOSE
0715 * HIDE_ON_CLOSE WindowConstants.HIDE_ON_CLOSE
0716 * DISPOSE_ON_CLOSE WindowConstants.DISPOSE_ON_CLOSE
0717 * description: The dialog's default close operation.
0718 */
0719 public void setDefaultCloseOperation(int operation) {
0720 if (operation != DO_NOTHING_ON_CLOSE
0721 && operation != HIDE_ON_CLOSE
0722 && operation != DISPOSE_ON_CLOSE) {
0723 throw new IllegalArgumentException(
0724 "defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE, or DISPOSE_ON_CLOSE");
0725 }
0726
0727 int oldValue = this .defaultCloseOperation;
0728 this .defaultCloseOperation = operation;
0729 firePropertyChange("defaultCloseOperation", oldValue, operation);
0730 }
0731
0732 /**
0733 * Returns the operation which occurs when the user
0734 * initiates a "close" on this dialog.
0735 *
0736 * @return an integer indicating the window-close operation
0737 * @see #setDefaultCloseOperation
0738 */
0739 public int getDefaultCloseOperation() {
0740 return defaultCloseOperation;
0741 }
0742
0743 /**
0744 * Sets the {@code transferHandler} property, which is a mechanism to
0745 * support transfer of data into this component. Use {@code null}
0746 * if the component does not support data transfer operations.
0747 * <p>
0748 * If the system property {@code suppressSwingDropSupport} is {@code false}
0749 * (the default) and the current drop target on this component is either
0750 * {@code null} or not a user-set drop target, this method will change the
0751 * drop target as follows: If {@code newHandler} is {@code null} it will
0752 * clear the drop target. If not {@code null} it will install a new
0753 * {@code DropTarget}.
0754 * <p>
0755 * Note: When used with {@code JDialog}, {@code TransferHandler} only
0756 * provides data import capability, as the data export related methods
0757 * are currently typed to {@code JComponent}.
0758 * <p>
0759 * Please see
0760 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html">
0761 * How to Use Drag and Drop and Data Transfer</a>, a section in
0762 * <em>The Java Tutorial</em>, for more information.
0763 *
0764 * @param newHandler the new {@code TransferHandler}
0765 *
0766 * @see TransferHandler
0767 * @see #getTransferHandler
0768 * @see java.awt.Component#setDropTarget
0769 * @since 1.6
0770 *
0771 * @beaninfo
0772 * bound: true
0773 * hidden: true
0774 * description: Mechanism for transfer of data into the component
0775 */
0776 public void setTransferHandler(TransferHandler newHandler) {
0777 TransferHandler oldHandler = transferHandler;
0778 transferHandler = newHandler;
0779 SwingUtilities.installSwingDropTargetAsNecessary(this ,
0780 transferHandler);
0781 firePropertyChange("transferHandler", oldHandler, newHandler);
0782 }
0783
0784 /**
0785 * Gets the <code>transferHandler</code> property.
0786 *
0787 * @return the value of the <code>transferHandler</code> property
0788 *
0789 * @see TransferHandler
0790 * @see #setTransferHandler
0791 * @since 1.6
0792 */
0793 public TransferHandler getTransferHandler() {
0794 return transferHandler;
0795 }
0796
0797 /**
0798 * Calls <code>paint(g)</code>. This method was overridden to
0799 * prevent an unnecessary call to clear the background.
0800 *
0801 * @param g the <code>Graphics</code> context in which to paint
0802 */
0803 public void update(Graphics g) {
0804 paint(g);
0805 }
0806
0807 /**
0808 * Sets the menubar for this dialog.
0809 *
0810 * @param menu the menubar being placed in the dialog
0811 *
0812 * @see #getJMenuBar
0813 *
0814 * @beaninfo
0815 * hidden: true
0816 * description: The menubar for accessing pulldown menus from this dialog.
0817 */
0818 public void setJMenuBar(JMenuBar menu) {
0819 getRootPane().setMenuBar(menu);
0820 }
0821
0822 /**
0823 * Returns the menubar set on this dialog.
0824 *
0825 * @see #setJMenuBar
0826 */
0827 public JMenuBar getJMenuBar() {
0828 return getRootPane().getMenuBar();
0829 }
0830
0831 /**
0832 * Returns whether calls to <code>add</code> and
0833 * <code>setLayout</code> are forwarded to the <code>contentPane</code>.
0834 *
0835 * @return true if <code>add</code> and <code>setLayout</code>
0836 * are fowarded; false otherwise
0837 *
0838 * @see #addImpl
0839 * @see #setLayout
0840 * @see #setRootPaneCheckingEnabled
0841 * @see javax.swing.RootPaneContainer
0842 */
0843 protected boolean isRootPaneCheckingEnabled() {
0844 return rootPaneCheckingEnabled;
0845 }
0846
0847 /**
0848 * Sets whether calls to <code>add</code> and
0849 * <code>setLayout</code> are forwarded to the <code>contentPane</code>.
0850 *
0851 * @param enabled true if <code>add</code> and <code>setLayout</code>
0852 * are forwarded, false if they should operate directly on the
0853 * <code>JDialog</code>.
0854 *
0855 * @see #addImpl
0856 * @see #setLayout
0857 * @see #isRootPaneCheckingEnabled
0858 * @see javax.swing.RootPaneContainer
0859 * @beaninfo
0860 * hidden: true
0861 * description: Whether the add and setLayout methods are forwarded
0862 */
0863 protected void setRootPaneCheckingEnabled(boolean enabled) {
0864 rootPaneCheckingEnabled = enabled;
0865 }
0866
0867 /**
0868 * Adds the specified child <code>Component</code>.
0869 * This method is overridden to conditionally forward calls to the
0870 * <code>contentPane</code>.
0871 * By default, children are added to the <code>contentPane</code> instead
0872 * of the frame, refer to {@link javax.swing.RootPaneContainer} for
0873 * details.
0874 *
0875 * @param comp the component to be enhanced
0876 * @param constraints the constraints to be respected
0877 * @param index the index
0878 * @exception IllegalArgumentException if <code>index</code> is invalid
0879 * @exception IllegalArgumentException if adding the container's parent
0880 * to itself
0881 * @exception IllegalArgumentException if adding a window to a container
0882 *
0883 * @see #setRootPaneCheckingEnabled
0884 * @see javax.swing.RootPaneContainer
0885 */
0886 protected void addImpl(Component comp, Object constraints, int index) {
0887 if (isRootPaneCheckingEnabled()) {
0888 getContentPane().add(comp, constraints, index);
0889 } else {
0890 super .addImpl(comp, constraints, index);
0891 }
0892 }
0893
0894 /**
0895 * Removes the specified component from the container. If
0896 * <code>comp</code> is not the <code>rootPane</code>, this will forward
0897 * the call to the <code>contentPane</code>. This will do nothing if
0898 * <code>comp</code> is not a child of the <code>JDialog</code> or
0899 * <code>contentPane</code>.
0900 *
0901 * @param comp the component to be removed
0902 * @throws NullPointerException if <code>comp</code> is null
0903 * @see #add
0904 * @see javax.swing.RootPaneContainer
0905 */
0906 public void remove(Component comp) {
0907 if (comp == rootPane) {
0908 super .remove(comp);
0909 } else {
0910 getContentPane().remove(comp);
0911 }
0912 }
0913
0914 /**
0915 * Sets the <code>LayoutManager</code>.
0916 * Overridden to conditionally forward the call to the
0917 * <code>contentPane</code>.
0918 * Refer to {@link javax.swing.RootPaneContainer} for
0919 * more information.
0920 *
0921 * @param manager the <code>LayoutManager</code>
0922 * @see #setRootPaneCheckingEnabled
0923 * @see javax.swing.RootPaneContainer
0924 */
0925 public void setLayout(LayoutManager manager) {
0926 if (isRootPaneCheckingEnabled()) {
0927 getContentPane().setLayout(manager);
0928 } else {
0929 super .setLayout(manager);
0930 }
0931 }
0932
0933 /**
0934 * Returns the <code>rootPane</code> object for this dialog.
0935 *
0936 * @see #setRootPane
0937 * @see RootPaneContainer#getRootPane
0938 */
0939 public JRootPane getRootPane() {
0940 return rootPane;
0941 }
0942
0943 /**
0944 * Sets the <code>rootPane</code> property.
0945 * This method is called by the constructor.
0946 *
0947 * @param root the <code>rootPane</code> object for this dialog
0948 *
0949 * @see #getRootPane
0950 *
0951 * @beaninfo
0952 * hidden: true
0953 * description: the RootPane object for this dialog.
0954 */
0955 protected void setRootPane(JRootPane root) {
0956 if (rootPane != null) {
0957 remove(rootPane);
0958 }
0959 rootPane = root;
0960 if (rootPane != null) {
0961 boolean checkingEnabled = isRootPaneCheckingEnabled();
0962 try {
0963 setRootPaneCheckingEnabled(false);
0964 add(rootPane, BorderLayout.CENTER);
0965 } finally {
0966 setRootPaneCheckingEnabled(checkingEnabled);
0967 }
0968 }
0969 }
0970
0971 /**
0972 * Returns the <code>contentPane</code> object for this dialog.
0973 *
0974 * @return the <code>contentPane</code> property
0975 *
0976 * @see #setContentPane
0977 * @see RootPaneContainer#getContentPane
0978 */
0979 public Container getContentPane() {
0980 return getRootPane().getContentPane();
0981 }
0982
0983 /**
0984 * Sets the <code>contentPane</code> property.
0985 * This method is called by the constructor.
0986 * <p>
0987 * Swing's painting architecture requires an opaque <code>JComponent</code>
0988 * in the containment hiearchy. This is typically provided by the
0989 * content pane. If you replace the content pane it is recommended you
0990 * replace it with an opaque <code>JComponent</code>.
0991 * @see JRootPane
0992 *
0993 * @param contentPane the <code>contentPane</code> object for this dialog
0994 *
0995 * @exception java.awt.IllegalComponentStateException (a runtime
0996 * exception) if the content pane parameter is <code>null</code>
0997 * @see #getContentPane
0998 * @see RootPaneContainer#setContentPane
0999 *
1000 * @beaninfo
1001 * hidden: true
1002 * description: The client area of the dialog where child
1003 * components are normally inserted.
1004 */
1005 public void setContentPane(Container contentPane) {
1006 getRootPane().setContentPane(contentPane);
1007 }
1008
1009 /**
1010 * Returns the <code>layeredPane</code> object for this dialog.
1011 *
1012 * @return the <code>layeredPane</code> property
1013 *
1014 * @see #setLayeredPane
1015 * @see RootPaneContainer#getLayeredPane
1016 */
1017 public JLayeredPane getLayeredPane() {
1018 return getRootPane().getLayeredPane();
1019 }
1020
1021 /**
1022 * Sets the <code>layeredPane</code> property.
1023 * This method is called by the constructor.
1024 *
1025 * @param layeredPane the new <code>layeredPane</code> property
1026 *
1027 * @exception java.awt.IllegalComponentStateException (a runtime
1028 * exception) if the layered pane parameter is null
1029 * @see #getLayeredPane
1030 * @see RootPaneContainer#setLayeredPane
1031 *
1032 * @beaninfo
1033 * hidden: true
1034 * description: The pane which holds the various dialog layers.
1035 */
1036 public void setLayeredPane(JLayeredPane layeredPane) {
1037 getRootPane().setLayeredPane(layeredPane);
1038 }
1039
1040 /**
1041 * Returns the <code>glassPane</code> object for this dialog.
1042 *
1043 * @return the <code>glassPane</code> property
1044 *
1045 * @see #setGlassPane
1046 * @see RootPaneContainer#getGlassPane
1047 */
1048 public Component getGlassPane() {
1049 return getRootPane().getGlassPane();
1050 }
1051
1052 /**
1053 * Sets the <code>glassPane</code> property.
1054 * This method is called by the constructor.
1055 *
1056 * @param glassPane the <code>glassPane</code> object for this dialog
1057 * @see #getGlassPane
1058 * @see RootPaneContainer#setGlassPane
1059 *
1060 * @beaninfo
1061 * hidden: true
1062 * description: A transparent pane used for menu rendering.
1063 */
1064 public void setGlassPane(Component glassPane) {
1065 getRootPane().setGlassPane(glassPane);
1066 }
1067
1068 /**
1069 * {@inheritDoc}
1070 *
1071 * @since 1.6
1072 */
1073 public Graphics getGraphics() {
1074 JComponent.getGraphicsInvoked(this );
1075 return super .getGraphics();
1076 }
1077
1078 /**
1079 * Repaints the specified rectangle of this component within
1080 * <code>time</code> milliseconds. Refer to <code>RepaintManager</code>
1081 * for details on how the repaint is handled.
1082 *
1083 * @param time maximum time in milliseconds before update
1084 * @param x the <i>x</i> coordinate
1085 * @param y the <i>y</i> coordinate
1086 * @param width the width
1087 * @param height the height
1088 * @see RepaintManager
1089 * @since 1.6
1090 */
1091 public void repaint(long time, int x, int y, int width, int height) {
1092 if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
1093 RepaintManager.currentManager(this ).addDirtyRegion(this , x,
1094 y, width, height);
1095 } else {
1096 super .repaint(time, x, y, width, height);
1097 }
1098 }
1099
1100 /**
1101 * Provides a hint as to whether or not newly created <code>JDialog</code>s
1102 * should have their Window decorations (such as borders, widgets to
1103 * close the window, title...) provided by the current look
1104 * and feel. If <code>defaultLookAndFeelDecorated</code> is true,
1105 * the current <code>LookAndFeel</code> supports providing window
1106 * decorations, and the current window manager supports undecorated
1107 * windows, then newly created <code>JDialog</code>s will have their
1108 * Window decorations provided by the current <code>LookAndFeel</code>.
1109 * Otherwise, newly created <code>JDialog</code>s will have their
1110 * Window decorations provided by the current window manager.
1111 * <p>
1112 * You can get the same effect on a single JDialog by doing the following:
1113 * <pre>
1114 * JDialog dialog = new JDialog();
1115 * dialog.setUndecorated(true);
1116 * dialog.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
1117 * </pre>
1118 *
1119 * @param defaultLookAndFeelDecorated A hint as to whether or not current
1120 * look and feel should provide window decorations
1121 * @see javax.swing.LookAndFeel#getSupportsWindowDecorations
1122 * @since 1.4
1123 */
1124 public static void setDefaultLookAndFeelDecorated(
1125 boolean defaultLookAndFeelDecorated) {
1126 if (defaultLookAndFeelDecorated) {
1127 SwingUtilities.appContextPut(
1128 defaultLookAndFeelDecoratedKey, Boolean.TRUE);
1129 } else {
1130 SwingUtilities.appContextPut(
1131 defaultLookAndFeelDecoratedKey, Boolean.FALSE);
1132 }
1133 }
1134
1135 /**
1136 * Returns true if newly created <code>JDialog</code>s should have their
1137 * Window decorations provided by the current look and feel. This is only
1138 * a hint, as certain look and feels may not support this feature.
1139 *
1140 * @return true if look and feel should provide Window decorations.
1141 * @since 1.4
1142 */
1143 public static boolean isDefaultLookAndFeelDecorated() {
1144 Boolean defaultLookAndFeelDecorated = (Boolean) SwingUtilities
1145 .appContextGet(defaultLookAndFeelDecoratedKey);
1146 if (defaultLookAndFeelDecorated == null) {
1147 defaultLookAndFeelDecorated = Boolean.FALSE;
1148 }
1149 return defaultLookAndFeelDecorated.booleanValue();
1150 }
1151
1152 /**
1153 * Returns a string representation of this <code>JDialog</code>.
1154 * This method
1155 * is intended to be used only for debugging purposes, and the
1156 * content and format of the returned string may vary between
1157 * implementations. The returned string may be empty but may not
1158 * be <code>null</code>.
1159 *
1160 * @return a string representation of this <code>JDialog</code>.
1161 */
1162 protected String paramString() {
1163 String defaultCloseOperationString;
1164 if (defaultCloseOperation == HIDE_ON_CLOSE) {
1165 defaultCloseOperationString = "HIDE_ON_CLOSE";
1166 } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
1167 defaultCloseOperationString = "DISPOSE_ON_CLOSE";
1168 } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
1169 defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
1170 } else
1171 defaultCloseOperationString = "";
1172 String rootPaneString = (rootPane != null ? rootPane.toString()
1173 : "");
1174 String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ? "true"
1175 : "false");
1176
1177 return super .paramString() + ",defaultCloseOperation="
1178 + defaultCloseOperationString + ",rootPane="
1179 + rootPaneString + ",rootPaneCheckingEnabled="
1180 + rootPaneCheckingEnabledString;
1181 }
1182
1183 /////////////////
1184 // Accessibility support
1185 ////////////////
1186
1187 protected AccessibleContext accessibleContext = null;
1188
1189 /**
1190 * Gets the AccessibleContext associated with this JDialog.
1191 * For JDialogs, the AccessibleContext takes the form of an
1192 * AccessibleJDialog.
1193 * A new AccessibleJDialog instance is created if necessary.
1194 *
1195 * @return an AccessibleJDialog that serves as the
1196 * AccessibleContext of this JDialog
1197 */
1198 public AccessibleContext getAccessibleContext() {
1199 if (accessibleContext == null) {
1200 accessibleContext = new AccessibleJDialog();
1201 }
1202 return accessibleContext;
1203 }
1204
1205 /**
1206 * This class implements accessibility support for the
1207 * <code>JDialog</code> class. It provides an implementation of the
1208 * Java Accessibility API appropriate to dialog user-interface
1209 * elements.
1210 */
1211 protected class AccessibleJDialog extends AccessibleAWTDialog {
1212
1213 // AccessibleContext methods
1214 //
1215 /**
1216 * Get the accessible name of this object.
1217 *
1218 * @return the localized name of the object -- can be null if this
1219 * object does not have a name
1220 */
1221 public String getAccessibleName() {
1222 if (accessibleName != null) {
1223 return accessibleName;
1224 } else {
1225 if (getTitle() == null) {
1226 return super .getAccessibleName();
1227 } else {
1228 return getTitle();
1229 }
1230 }
1231 }
1232
1233 /**
1234 * Get the state of this object.
1235 *
1236 * @return an instance of AccessibleStateSet containing the current
1237 * state set of the object
1238 * @see AccessibleState
1239 */
1240 public AccessibleStateSet getAccessibleStateSet() {
1241 AccessibleStateSet states = super .getAccessibleStateSet();
1242
1243 if (isResizable()) {
1244 states.add(AccessibleState.RESIZABLE);
1245 }
1246 if (getFocusOwner() != null) {
1247 states.add(AccessibleState.ACTIVE);
1248 }
1249 if (isModal()) {
1250 states.add(AccessibleState.MODAL);
1251 }
1252 return states;
1253 }
1254
1255 } // inner class AccessibleJDialog
1256 }
|