0N/A/*
3261N/A * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage java.awt;
0N/A
0N/Aimport java.awt.peer.DialogPeer;
0N/Aimport java.awt.event.*;
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.concurrent.atomic.AtomicLong;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport javax.accessibility.*;
0N/Aimport sun.awt.AppContext;
0N/Aimport sun.awt.SunToolkit;
0N/Aimport sun.awt.PeerEvent;
0N/Aimport sun.awt.util.IdentityArrayList;
0N/Aimport sun.awt.util.IdentityLinkedList;
0N/Aimport sun.security.util.SecurityConstants;
5719N/Aimport java.security.AccessControlException;
0N/A
0N/A/**
0N/A * A Dialog is a top-level window with a title and a border
0N/A * that is typically used to take some form of input from the user.
0N/A *
0N/A * The size of the dialog includes any area designated for the
0N/A * border. The dimensions of the border area can be obtained
0N/A * using the <code>getInsets</code> method, however, since
0N/A * these dimensions are platform-dependent, a valid insets
0N/A * value cannot be obtained until the dialog is made displayable
0N/A * by either calling <code>pack</code> or <code>show</code>.
0N/A * Since the border area is included in the overall size of the
0N/A * dialog, the border effectively obscures a portion of the dialog,
0N/A * constraining the area available for rendering and/or displaying
0N/A * subcomponents to the rectangle which has an upper-left corner
0N/A * location of <code>(insets.left, insets.top)</code>, and has a size of
0N/A * <code>width - (insets.left + insets.right)</code> by
0N/A * <code>height - (insets.top + insets.bottom)</code>.
0N/A * <p>
0N/A * The default layout for a dialog is <code>BorderLayout</code>.
0N/A * <p>
0N/A * A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
0N/A * with <code>setUndecorated</code>. This can only be done while the dialog
0N/A * is not {@link Component#isDisplayable() displayable}.
0N/A * <p>
0N/A * A dialog may have another window as its owner when it's constructed. When
0N/A * the owner window of a visible dialog is minimized, the dialog will
0N/A * automatically be hidden from the user. When the owner window is subsequently
0N/A * restored, the dialog is made visible to the user again.
0N/A * <p>
0N/A * In a multi-screen environment, you can create a <code>Dialog</code>
0N/A * on a different screen device than its owner. See {@link java.awt.Frame} for
0N/A * more information.
0N/A * <p>
0N/A * A dialog can be either modeless (the default) or modal. A modal
0N/A * dialog is one which blocks input to some other top-level windows
0N/A * in the application, except for any windows created with the dialog
0N/A * as their owner. See <a href="doc-files/Modality.html">AWT Modality</a>
0N/A * specification for details.
0N/A * <p>
0N/A * Dialogs are capable of generating the following
0N/A * <code>WindowEvents</code>:
0N/A * <code>WindowOpened</code>, <code>WindowClosing</code>,
0N/A * <code>WindowClosed</code>, <code>WindowActivated</code>,
0N/A * <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>,
0N/A * <code>WindowLostFocus</code>.
0N/A *
0N/A * @see WindowEvent
0N/A * @see Window#addWindowListener
0N/A *
0N/A * @author Sami Shaio
0N/A * @author Arthur van Hoff
0N/A * @since JDK1.0
0N/A */
0N/Apublic class Dialog extends Window {
0N/A
0N/A static {
0N/A /* ensure that the necessary native libraries are loaded */
0N/A Toolkit.loadLibraries();
0N/A if (!GraphicsEnvironment.isHeadless()) {
0N/A initIDs();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * A dialog's resizable property. Will be true
0N/A * if the Dialog is to be resizable, otherwise
0N/A * it will be false.
0N/A *
0N/A * @serial
0N/A * @see #setResizable(boolean)
0N/A */
0N/A boolean resizable = true;
0N/A
0N/A
0N/A /**
0N/A * This field indicates whether the dialog is undecorated.
0N/A * This property can only be changed while the dialog is not displayable.
0N/A * <code>undecorated</code> will be true if the dialog is
0N/A * undecorated, otherwise it will be false.
0N/A *
0N/A * @serial
0N/A * @see #setUndecorated(boolean)
0N/A * @see #isUndecorated()
0N/A * @see Component#isDisplayable()
0N/A * @since 1.4
0N/A */
0N/A boolean undecorated = false;
0N/A
5719N/A private transient boolean initialized = false;
5719N/A
0N/A /**
0N/A * Modal dialogs block all input to some top-level windows.
0N/A * Whether a particular window is blocked depends on dialog's type
0N/A * of modality; this is called the "scope of blocking". The
0N/A * <code>ModalityType</code> enum specifies modal types and their
0N/A * associated scopes.
0N/A *
0N/A * @see Dialog#getModalityType
0N/A * @see Dialog#setModalityType
0N/A * @see Toolkit#isModalityTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static enum ModalityType {
0N/A /**
0N/A * <code>MODELESS</code> dialog doesn't block any top-level windows.
0N/A */
0N/A MODELESS,
0N/A /**
0N/A * A <code>DOCUMENT_MODAL</code> dialog blocks input to all top-level windows
0N/A * from the same document except those from its own child hierarchy.
0N/A * A document is a top-level window without an owner. It may contain child
0N/A * windows that, together with the top-level window are treated as a single
0N/A * solid document. Since every top-level window must belong to some
0N/A * document, its root can be found as the top-nearest window without an owner.
0N/A */
0N/A DOCUMENT_MODAL,
0N/A /**
0N/A * An <code>APPLICATION_MODAL</code> dialog blocks all top-level windows
0N/A * from the same Java application except those from its own child hierarchy.
0N/A * If there are several applets launched in a browser, they can be
0N/A * treated either as separate applications or a single one. This behavior
0N/A * is implementation-dependent.
0N/A */
0N/A APPLICATION_MODAL,
0N/A /**
0N/A * A <code>TOOLKIT_MODAL</code> dialog blocks all top-level windows run
0N/A * from the same toolkit except those from its own child hierarchy. If there
0N/A * are several applets launched in a browser, all of them run with the same
0N/A * toolkit; thus, a toolkit-modal dialog displayed by an applet may affect
0N/A * other applets and all windows of the browser instance which embeds the
0N/A * Java runtime environment for this toolkit.
0N/A * Special <code>AWTPermission</code> "toolkitModality" must be granted to use
0N/A * toolkit-modal dialogs. If a <code>TOOLKIT_MODAL</code> dialog is being created
0N/A * and this permission is not granted, a <code>SecurityException</code> will be
0N/A * thrown, and no dialog will be created. If a modality type is being changed
0N/A * to <code>TOOLKIT_MODAL</code> and this permission is not granted, a
0N/A * <code>SecurityException</code> will be thrown, and the modality type will
0N/A * be left unchanged.
0N/A */
0N/A TOOLKIT_MODAL
0N/A };
0N/A
0N/A /**
0N/A * Default modality type for modal dialogs. The default modality type is
0N/A * <code>APPLICATION_MODAL</code>. Calling the oldstyle <code>setModal(true)</code>
0N/A * is equal to <code>setModalityType(DEFAULT_MODALITY_TYPE)</code>.
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog#setModal
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public final static ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL;
0N/A
0N/A /**
0N/A * True if this dialog is modal, false is the dialog is modeless.
0N/A * A modal dialog blocks user input to some application top-level
0N/A * windows. This field is kept only for backwards compatibility. Use the
0N/A * {@link Dialog.ModalityType ModalityType} enum instead.
0N/A *
0N/A * @serial
0N/A *
0N/A * @see #isModal
0N/A * @see #setModal
0N/A * @see #getModalityType
0N/A * @see #setModalityType
0N/A * @see ModalityType
0N/A * @see ModalityType#MODELESS
0N/A * @see #DEFAULT_MODALITY_TYPE
0N/A */
0N/A boolean modal;
0N/A
0N/A /**
0N/A * Modality type of this dialog. If the dialog's modality type is not
0N/A * {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all
0N/A * user input to some application top-level windows.
0N/A *
0N/A * @serial
0N/A *
0N/A * @see ModalityType
0N/A * @see #getModalityType
0N/A * @see #setModalityType
0N/A *
0N/A * @since 1.6
0N/A */
0N/A ModalityType modalityType;
0N/A
0N/A /**
0N/A * Any top-level window can be marked not to be blocked by modal
0N/A * dialogs. This is called "modal exclusion". This enum specifies
0N/A * the possible modal exclusion types.
0N/A *
0N/A * @see Window#getModalExclusionType
0N/A * @see Window#setModalExclusionType
0N/A * @see Toolkit#isModalExclusionTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static enum ModalExclusionType {
0N/A /**
0N/A * No modal exclusion.
0N/A */
0N/A NO_EXCLUDE,
0N/A /**
0N/A * <code>APPLICATION_EXCLUDE</code> indicates that a top-level window
0N/A * won't be blocked by any application-modal dialogs. Also, it isn't
0N/A * blocked by document-modal dialogs from outside of its child hierarchy.
0N/A */
0N/A APPLICATION_EXCLUDE,
0N/A /**
0N/A * <code>TOOLKIT_EXCLUDE</code> indicates that a top-level window
0N/A * won't be blocked by application-modal or toolkit-modal dialogs. Also,
0N/A * it isn't blocked by document-modal dialogs from outside of its
0N/A * child hierarchy.
0N/A * The "toolkitModality" <code>AWTPermission</code> must be granted
0N/A * for this exclusion. If an exclusion property is being changed to
0N/A * <code>TOOLKIT_EXCLUDE</code> and this permission is not granted, a
0N/A * <code>SecurityEcxeption</code> will be thrown, and the exclusion
0N/A * property will be left unchanged.
0N/A */
0N/A TOOLKIT_EXCLUDE
0N/A };
0N/A
0N/A /* operations with this list should be synchronized on tree lock*/
0N/A transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>();
0N/A
0N/A transient IdentityArrayList<Window> blockedWindows = new IdentityArrayList<Window>();
0N/A
0N/A /**
0N/A * Specifies the title of the Dialog.
0N/A * This field can be null.
0N/A *
0N/A * @serial
0N/A * @see #getTitle()
0N/A * @see #setTitle(String)
0N/A */
0N/A String title;
0N/A
0N/A private transient ModalEventFilter modalFilter;
2695N/A private transient volatile SecondaryLoop secondaryLoop;
0N/A
0N/A /*
0N/A * Indicates that this dialog is being hidden. This flag is set to true at
0N/A * the beginning of hide() and to false at the end of hide().
0N/A *
0N/A * @see #hide()
0N/A * @see #hideAndDisposePreHandler()
0N/A * @see #hideAndDisposeHandler()
0N/A * @see #shouldBlock()
0N/A */
0N/A transient volatile boolean isInHide = false;
0N/A
0N/A /*
0N/A * Indicates that this dialog is being disposed. This flag is set to true at
0N/A * the beginning of doDispose() and to false at the end of doDispose().
0N/A *
0N/A * @see #hide()
0N/A * @see #hideAndDisposePreHandler()
0N/A * @see #hideAndDisposeHandler()
0N/A * @see #doDispose()
0N/A */
0N/A transient volatile boolean isInDispose = false;
0N/A
0N/A private static final String base = "dialog";
0N/A private static int nameCounter = 0;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 5920926903803293709L;
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code> with
0N/A * the specified owner <code>Frame</code> and an empty title.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if
0N/A * this dialog has no owner
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see Component#setSize
0N/A * @see Component#setVisible
0N/A */
0N/A public Dialog(Frame owner) {
0N/A this(owner, "", false);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the specified
0N/A * owner <code>Frame</code> and modality and an empty title.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if
0N/A * this dialog has no owner
0N/A * @param modal specifes whether dialog blocks user input to other top-level
0N/A * windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
0N/A * if <code>true</code>, the modality type property is set to
0N/A * <code>DEFAULT_MODALITY_TYPE</code>
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public Dialog(Frame owner, boolean modal) {
0N/A this(owner, "", modal);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code> with
0N/A * the specified owner <code>Frame</code> and title.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if
0N/A * this dialog has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @exception IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see Component#setSize
0N/A * @see Component#setVisible
0N/A */
0N/A public Dialog(Frame owner, String title) {
0N/A this(owner, title, false);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Frame</code>, title and modality.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if
0N/A * this dialog has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @param modal specifes whether dialog blocks user input to other top-level
0N/A * windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
0N/A * if <code>true</code>, the modality type property is set to
0N/A * <code>DEFAULT_MODALITY_TYPE</code>
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see Component#setSize
0N/A * @see Component#setVisible
0N/A */
0N/A public Dialog(Frame owner, String title, boolean modal) {
0N/A this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the specified owner
0N/A * <code>Frame</code>, title, modality, and <code>GraphicsConfiguration</code>.
0N/A * @param owner the owner of the dialog or <code>null</code> if this dialog
0N/A * has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @param modal specifes whether dialog blocks user input to other top-level
0N/A * windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
0N/A * if <code>true</code>, the modality type property is set to
0N/A * <code>DEFAULT_MODALITY_TYPE</code>
0N/A * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
0N/A * if <code>null</code>, the default system <code>GraphicsConfiguration</code>
0N/A * is assumed
0N/A * @exception java.lang.IllegalArgumentException if <code>gc</code>
0N/A * is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see Component#setSize
0N/A * @see Component#setVisible
0N/A * @since 1.4
0N/A */
0N/A public Dialog(Frame owner, String title, boolean modal,
0N/A GraphicsConfiguration gc) {
0N/A this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code> with
0N/A * the specified owner <code>Dialog</code> and an empty title.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if this
0N/A * dialog has no owner
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.2
0N/A */
0N/A public Dialog(Dialog owner) {
0N/A this(owner, "", false);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code>
0N/A * with the specified owner <code>Dialog</code> and title.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if this
0N/A * has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.2
0N/A */
0N/A public Dialog(Dialog owner, String title) {
0N/A this(owner, title, false);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Dialog</code>, title, and modality.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if this
0N/A * dialog has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this
0N/A * dialog has no title
0N/A * @param modal specifes whether dialog blocks user input to other top-level
0N/A * windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
0N/A * if <code>true</code>, the modality type property is set to
0N/A * <code>DEFAULT_MODALITY_TYPE</code>
0N/A * @exception IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A *
0N/A * @since 1.2
0N/A */
0N/A public Dialog(Dialog owner, String title, boolean modal) {
0N/A this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Dialog</code>, title, modality and
0N/A * <code>GraphicsConfiguration</code>.
0N/A *
0N/A * @param owner the owner of the dialog or <code>null</code> if this
0N/A * dialog has no owner
0N/A * @param title the title of the dialog or <code>null</code> if this
0N/A * dialog has no title
0N/A * @param modal specifes whether dialog blocks user input to other top-level
0N/A * windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
0N/A * if <code>true</code>, the modality type property is set to
0N/A * <code>DEFAULT_MODALITY_TYPE</code>
0N/A * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
0N/A * if <code>null</code>, the default system <code>GraphicsConfiguration</code>
0N/A * is assumed
0N/A * @exception java.lang.IllegalArgumentException if <code>gc</code>
0N/A * is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see Component#setSize
0N/A * @see Component#setVisible
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public Dialog(Dialog owner, String title, boolean modal,
0N/A GraphicsConfiguration gc) {
0N/A this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code> with the
0N/A * specified owner <code>Window</code> and an empty title.
0N/A *
0N/A * @param owner the owner of the dialog. The owner must be an instance of
0N/A * {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
0N/A * of their descendents or <code>null</code>
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>
0N/A * is not an instance of {@link java.awt.Dialog Dialog} or {@link
0N/A * java.awt.Frame Frame}
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Dialog(Window owner) {
3185N/A this(owner, "", ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible, modeless <code>Dialog</code> with
0N/A * the specified owner <code>Window</code> and title.
0N/A *
0N/A * @param owner the owner of the dialog. The owner must be an instance of
0N/A * {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
0N/A * of their descendents or <code>null</code>
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>
0N/A * is not an instance of {@link java.awt.Dialog Dialog} or {@link
0N/A * java.awt.Frame Frame}
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A *
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Dialog(Window owner, String title) {
0N/A this(owner, title, ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Window</code> and modality and an empty title.
0N/A *
0N/A * @param owner the owner of the dialog. The owner must be an instance of
0N/A * {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
0N/A * of their descendents or <code>null</code>
0N/A * @param modalityType specifies whether dialog blocks input to other
0N/A * windows when shown. <code>null</code> value and unsupported modality
0N/A * types are equivalent to <code>MODELESS</code>
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>
0N/A * is not an instance of {@link java.awt.Dialog Dialog} or {@link
0N/A * java.awt.Frame Frame}
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A * @exception SecurityException if the calling thread does not have permission
0N/A * to create modal dialogs with the given <code>modalityType</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Toolkit#isModalityTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Dialog(Window owner, ModalityType modalityType) {
3185N/A this(owner, "", modalityType);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Window</code>, title and modality.
0N/A *
0N/A * @param owner the owner of the dialog. The owner must be an instance of
0N/A * {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
0N/A * of their descendents or <code>null</code>
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @param modalityType specifies whether dialog blocks input to other
0N/A * windows when shown. <code>null</code> value and unsupported modality
0N/A * types are equivalent to <code>MODELESS</code>
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>
0N/A * is not an instance of {@link java.awt.Dialog Dialog} or {@link
0N/A * java.awt.Frame Frame}
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
0N/A * <code>GraphicsConfiguration</code> is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A * @exception SecurityException if the calling thread does not have permission
0N/A * to create modal dialogs with the given <code>modalityType</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Toolkit#isModalityTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Dialog(Window owner, String title, ModalityType modalityType) {
0N/A super(owner);
0N/A
0N/A if ((owner != null) &&
0N/A !(owner instanceof Frame) &&
0N/A !(owner instanceof Dialog))
0N/A {
0N/A throw new IllegalArgumentException("Wrong parent window");
0N/A }
0N/A
0N/A this.title = title;
0N/A setModalityType(modalityType);
4875N/A SunToolkit.checkAndSetPolicy(this);
5719N/A initialized = true;
0N/A }
0N/A
0N/A /**
0N/A * Constructs an initially invisible <code>Dialog</code> with the
0N/A * specified owner <code>Window</code>, title, modality and
0N/A * <code>GraphicsConfiguration</code>.
0N/A *
0N/A * @param owner the owner of the dialog. The owner must be an instance of
0N/A * {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
0N/A * of their descendents or <code>null</code>
0N/A * @param title the title of the dialog or <code>null</code> if this dialog
0N/A * has no title
0N/A * @param modalityType specifies whether dialog blocks input to other
0N/A * windows when shown. <code>null</code> value and unsupported modality
0N/A * types are equivalent to <code>MODELESS</code>
0N/A * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
0N/A * if <code>null</code>, the default system <code>GraphicsConfiguration</code>
0N/A * is assumed
0N/A *
0N/A * @exception java.lang.IllegalArgumentException if the <code>owner</code>
0N/A * is not an instance of {@link java.awt.Dialog Dialog} or {@link
0N/A * java.awt.Frame Frame}
0N/A * @exception java.lang.IllegalArgumentException if <code>gc</code>
0N/A * is not from a screen device
0N/A * @exception HeadlessException when
0N/A * <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
0N/A * @exception SecurityException if the calling thread does not have permission
0N/A * to create modal dialogs with the given <code>modalityType</code>
0N/A *
0N/A * @see java.awt.Dialog.ModalityType
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#setModalityType
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see java.awt.Toolkit#isModalityTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public Dialog(Window owner, String title, ModalityType modalityType,
0N/A GraphicsConfiguration gc) {
0N/A super(owner, gc);
0N/A
0N/A if ((owner != null) &&
0N/A !(owner instanceof Frame) &&
0N/A !(owner instanceof Dialog))
0N/A {
0N/A throw new IllegalArgumentException("wrong owner window");
0N/A }
0N/A
0N/A this.title = title;
0N/A setModalityType(modalityType);
4875N/A SunToolkit.checkAndSetPolicy(this);
5719N/A initialized = true;
0N/A }
0N/A
0N/A /**
0N/A * Construct a name for this component. Called by getName() when the
0N/A * name is null.
0N/A */
0N/A String constructComponentName() {
0N/A synchronized (Dialog.class) {
0N/A return base + nameCounter++;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Makes this Dialog displayable by connecting it to
0N/A * a native screen resource. Making a dialog displayable will
0N/A * cause any of its children to be made displayable.
0N/A * This method is called internally by the toolkit and should
0N/A * not be called directly by programs.
0N/A * @see Component#isDisplayable
0N/A * @see #removeNotify
0N/A */
0N/A public void addNotify() {
0N/A synchronized (getTreeLock()) {
0N/A if (parent != null && parent.getPeer() == null) {
0N/A parent.addNotify();
0N/A }
0N/A
0N/A if (peer == null) {
0N/A peer = getToolkit().createDialog(this);
0N/A }
0N/A super.addNotify();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether the dialog is modal.
0N/A * <p>
0N/A * This method is obsolete and is kept for backwards compatiblity only.
0N/A * Use {@link #getModalityType getModalityType()} instead.
0N/A *
0N/A * @return <code>true</code> if this dialog window is modal;
0N/A * <code>false</code> otherwise
0N/A *
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#setModal
0N/A * @see java.awt.Dialog#getModalityType
0N/A * @see java.awt.Dialog#setModalityType
0N/A */
0N/A public boolean isModal() {
0N/A return isModal_NoClientCode();
0N/A }
0N/A final boolean isModal_NoClientCode() {
0N/A return modalityType != ModalityType.MODELESS;
0N/A }
0N/A
0N/A /**
0N/A * Specifies whether this dialog should be modal.
0N/A * <p>
0N/A * This method is obsolete and is kept for backwards compatibility only.
0N/A * Use {@link #setModalityType setModalityType()} instead.
0N/A * <p>
0N/A * Note: changing modality of the visible dialog may have no effect
0N/A * until it is hidden and then shown again.
0N/A *
0N/A * @param modal specifies whether dialog blocks input to other windows
0N/A * when shown; calling to <code>setModal(true)</code> is equivalent to
0N/A * <code>setModalityType(Dialog.DEFAULT_MODALITY_TYPE)</code>, and
0N/A * calling to <code>setModal(false)</code> is equvivalent to
0N/A * <code>setModalityType(Dialog.ModalityType.MODELESS)</code>
0N/A *
0N/A * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
0N/A * @see java.awt.Dialog.ModalityType#MODELESS
0N/A * @see java.awt.Dialog#isModal
0N/A * @see java.awt.Dialog#getModalityType
0N/A * @see java.awt.Dialog#setModalityType
0N/A *
0N/A * @since 1.1
0N/A */
0N/A public void setModal(boolean modal) {
0N/A this.modal = modal;
0N/A setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Returns the modality type of this dialog.
0N/A *
0N/A * @return modality type of this dialog
0N/A *
0N/A * @see java.awt.Dialog#setModalityType
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public ModalityType getModalityType() {
0N/A return modalityType;
0N/A }
0N/A
0N/A /**
0N/A * Sets the modality type for this dialog. See {@link
0N/A * java.awt.Dialog.ModalityType ModalityType} for possible modality types.
0N/A * <p>
0N/A * If the given modality type is not supported, <code>MODELESS</code>
0N/A * is used. You may want to call <code>getModalityType()</code> after calling
0N/A * this method to ensure that the modality type has been set.
0N/A * <p>
0N/A * Note: changing modality of the visible dialog may have no effect
0N/A * until it is hidden and then shown again.
0N/A *
0N/A * @param type specifies whether dialog blocks input to other
0N/A * windows when shown. <code>null</code> value and unsupported modality
0N/A * types are equivalent to <code>MODELESS</code>
0N/A * @exception SecurityException if the calling thread does not have permission
0N/A * to create modal dialogs with the given <code>modalityType</code>
0N/A *
0N/A * @see java.awt.Dialog#getModalityType
0N/A * @see java.awt.Toolkit#isModalityTypeSupported
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public void setModalityType(ModalityType type) {
0N/A if (type == null) {
0N/A type = Dialog.ModalityType.MODELESS;
0N/A }
0N/A if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) {
0N/A type = Dialog.ModalityType.MODELESS;
0N/A }
0N/A if (modalityType == type) {
0N/A return;
0N/A }
5719N/A
5719N/A checkModalityPermission(type);
5719N/A
0N/A modalityType = type;
0N/A modal = (modalityType != ModalityType.MODELESS);
0N/A }
0N/A
0N/A /**
0N/A * Gets the title of the dialog. The title is displayed in the
0N/A * dialog's border.
0N/A * @return the title of this dialog window. The title may be
0N/A * <code>null</code>.
0N/A * @see java.awt.Dialog#setTitle
0N/A */
0N/A public String getTitle() {
0N/A return title;
0N/A }
0N/A
0N/A /**
0N/A * Sets the title of the Dialog.
0N/A * @param title the title displayed in the dialog's border;
0N/A * a null value results in an empty title
0N/A * @see #getTitle
0N/A */
0N/A public void setTitle(String title) {
0N/A String oldTitle = this.title;
0N/A
0N/A synchronized(this) {
0N/A this.title = title;
0N/A DialogPeer peer = (DialogPeer)this.peer;
0N/A if (peer != null) {
0N/A peer.setTitle(title);
0N/A }
0N/A }
0N/A firePropertyChange("title", oldTitle, title);
0N/A }
0N/A
0N/A /**
0N/A * @return true if we actually showed, false if we just called toFront()
0N/A */
0N/A private boolean conditionalShow(Component toFocus, AtomicLong time) {
0N/A boolean retval;
0N/A
0N/A closeSplashScreen();
0N/A
0N/A synchronized (getTreeLock()) {
0N/A if (peer == null) {
0N/A addNotify();
0N/A }
3944N/A validateUnconditionally();
0N/A if (visible) {
0N/A toFront();
0N/A retval = false;
0N/A } else {
0N/A visible = retval = true;
0N/A
0N/A // check if this dialog should be modal blocked BEFORE calling peer.show(),
0N/A // otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly
0N/A // generated for the dialog
0N/A if (!isModal()) {
0N/A checkShouldBeBlocked(this);
0N/A } else {
0N/A modalDialogs.add(this);
0N/A modalShow();
0N/A }
0N/A
0N/A if (toFocus != null && time != null && isFocusable() &&
0N/A isEnabled() && !isModalBlocked()) {
0N/A // keep the KeyEvents from being dispatched
0N/A // until the focus has been transfered
0N/A time.set(Toolkit.getEventQueue().getMostRecentEventTimeEx());
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A enqueueKeyEvents(time.get(), toFocus);
0N/A }
0N/A
0N/A // This call is required as the show() method of the Dialog class
0N/A // does not invoke the super.show(). So wried... :(
0N/A mixOnShowing();
0N/A
872N/A peer.setVisible(true); // now guaranteed never to block
0N/A if (isModalBlocked()) {
0N/A modalBlocker.toFront();
0N/A }
0N/A
0N/A setLocationByPlatform(false);
0N/A for (int i = 0; i < ownedWindowList.size(); i++) {
0N/A Window child = ownedWindowList.elementAt(i).get();
0N/A if ((child != null) && child.showWithParent) {
0N/A child.show();
0N/A child.showWithParent = false;
0N/A } // endif
0N/A } // endfor
0N/A Window.updateChildFocusableWindowState(this);
0N/A
0N/A createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
0N/A this, parent,
0N/A HierarchyEvent.SHOWING_CHANGED,
0N/A Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
0N/A if (componentListener != null ||
0N/A (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
0N/A Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
0N/A ComponentEvent e =
0N/A new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
0N/A Toolkit.getEventQueue().postEvent(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (retval && (state & OPENED) == 0) {
0N/A postWindowEvent(WindowEvent.WINDOW_OPENED);
0N/A state |= OPENED;
0N/A }
0N/A
0N/A return retval;
0N/A }
0N/A
0N/A /**
0N/A * Shows or hides this {@code Dialog} depending on the value of parameter
0N/A * {@code b}.
0N/A * @param b if {@code true}, makes the {@code Dialog} visible,
0N/A * otherwise hides the {@code Dialog}.
0N/A * If the dialog and/or its owner
0N/A * are not yet displayable, both are made displayable. The
0N/A * dialog will be validated prior to being made visible.
0N/A * If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)}
0N/A * to return if it is currently blocked.
0N/A * <p>
0N/A * <b>Notes for modal dialogs</b>.
0N/A * <ul>
0N/A * <li>{@code setVisible(true)}: If the dialog is not already
0N/A * visible, this call will not return until the dialog is
0N/A * hidden by calling {@code setVisible(false)} or
0N/A * {@code dispose}.
0N/A * <li>{@code setVisible(false)}: Hides the dialog and then
0N/A * returns on {@code setVisible(true)} if it is currently blocked.
0N/A * <li>It is OK to call this method from the event dispatching
0N/A * thread because the toolkit ensures that other events are
0N/A * not blocked while this method is blocked.
0N/A * </ul>
0N/A * @see java.awt.Window#setVisible
0N/A * @see java.awt.Window#dispose
0N/A * @see java.awt.Component#isDisplayable
0N/A * @see java.awt.Component#validate
0N/A * @see java.awt.Dialog#isModal
0N/A */
0N/A public void setVisible(boolean b) {
0N/A super.setVisible(b);
0N/A }
0N/A
0N/A /**
0N/A * Makes the {@code Dialog} visible. If the dialog and/or its owner
0N/A * are not yet displayable, both are made displayable. The
0N/A * dialog will be validated prior to being made visible.
0N/A * If the dialog is already visible, this will bring the dialog
0N/A * to the front.
0N/A * <p>
0N/A * If the dialog is modal and is not already visible, this call
0N/A * will not return until the dialog is hidden by calling hide or
0N/A * dispose. It is permissible to show modal dialogs from the event
0N/A * dispatching thread because the toolkit will ensure that another
0N/A * event pump runs while the one which invoked this method is blocked.
0N/A * @see Component#hide
0N/A * @see Component#isDisplayable
0N/A * @see Component#validate
0N/A * @see #isModal
0N/A * @see Window#setVisible(boolean)
0N/A * @deprecated As of JDK version 1.5, replaced by
0N/A * {@link #setVisible(boolean) setVisible(boolean)}.
0N/A */
0N/A @Deprecated
0N/A public void show() {
5719N/A if (!initialized) throw new IllegalStateException(
5719N/A "The dialog component has not been initialized properly");
5719N/A
0N/A beforeFirstShow = false;
0N/A if (!isModal()) {
0N/A conditionalShow(null, null);
0N/A } else {
2695N/A AppContext showAppContext = AppContext.getAppContext();
0N/A
0N/A AtomicLong time = new AtomicLong();
0N/A Component predictedFocusOwner = null;
0N/A try {
0N/A predictedFocusOwner = getMostRecentFocusOwner();
0N/A if (conditionalShow(predictedFocusOwner, time)) {
0N/A modalFilter = ModalEventFilter.createFilterForDialog(this);
5133N/A final Conditional cond = new Conditional() {
2695N/A @Override
2695N/A public boolean evaluate() {
2695N/A return windowClosingException == null;
0N/A }
0N/A };
0N/A
0N/A // if this dialog is toolkit-modal, the filter should be added
0N/A // to all EDTs (for all AppContexts)
0N/A if (modalityType == ModalityType.TOOLKIT_MODAL) {
0N/A Iterator it = AppContext.getAppContexts().iterator();
0N/A while (it.hasNext()) {
0N/A AppContext appContext = (AppContext)it.next();
0N/A if (appContext == showAppContext) {
0N/A continue;
0N/A }
0N/A EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
0N/A // it may occur that EDT for appContext hasn't been started yet, so
0N/A // we post an empty invocation event to trigger EDT initialization
0N/A Runnable createEDT = new Runnable() {
0N/A public void run() {};
0N/A };
0N/A eventQueue.postEvent(new InvocationEvent(this, createEDT));
0N/A EventDispatchThread edt = eventQueue.getDispatchThread();
0N/A edt.addEventFilter(modalFilter);
0N/A }
0N/A }
0N/A
0N/A modalityPushed();
0N/A try {
5133N/A final EventQueue eventQueue = AccessController.doPrivileged(
5133N/A new PrivilegedAction<EventQueue>() {
5133N/A public EventQueue run() {
5133N/A return Toolkit.getDefaultToolkit().getSystemEventQueue();
5133N/A }
5133N/A });
2767N/A secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
2695N/A if (!secondaryLoop.enter()) {
2695N/A secondaryLoop = null;
0N/A }
0N/A } finally {
0N/A modalityPopped();
0N/A }
0N/A
0N/A // if this dialog is toolkit-modal, its filter must be removed
0N/A // from all EDTs (for all AppContexts)
0N/A if (modalityType == ModalityType.TOOLKIT_MODAL) {
0N/A Iterator it = AppContext.getAppContexts().iterator();
0N/A while (it.hasNext()) {
0N/A AppContext appContext = (AppContext)it.next();
0N/A if (appContext == showAppContext) {
0N/A continue;
0N/A }
0N/A EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
0N/A EventDispatchThread edt = eventQueue.getDispatchThread();
0N/A edt.removeEventFilter(modalFilter);
0N/A }
0N/A }
0N/A
0N/A if (windowClosingException != null) {
0N/A windowClosingException.fillInStackTrace();
0N/A throw windowClosingException;
0N/A }
0N/A }
0N/A } finally {
0N/A if (predictedFocusOwner != null) {
0N/A // Restore normal key event dispatching
0N/A KeyboardFocusManager.getCurrentKeyboardFocusManager().
0N/A dequeueKeyEvents(time.get(), predictedFocusOwner);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A final void modalityPushed() {
0N/A Toolkit tk = Toolkit.getDefaultToolkit();
0N/A if (tk instanceof SunToolkit) {
0N/A SunToolkit stk = (SunToolkit)tk;
0N/A stk.notifyModalityPushed(this);
0N/A }
0N/A }
0N/A
0N/A final void modalityPopped() {
0N/A Toolkit tk = Toolkit.getDefaultToolkit();
0N/A if (tk instanceof SunToolkit) {
0N/A SunToolkit stk = (SunToolkit)tk;
0N/A stk.notifyModalityPopped(this);
0N/A }
0N/A }
0N/A
0N/A void interruptBlocking() {
0N/A if (isModal()) {
0N/A disposeImpl();
0N/A } else if (windowClosingException != null) {
0N/A windowClosingException.fillInStackTrace();
0N/A windowClosingException.printStackTrace();
0N/A windowClosingException = null;
0N/A }
0N/A }
2695N/A
0N/A private void hideAndDisposePreHandler() {
0N/A isInHide = true;
0N/A synchronized (getTreeLock()) {
2695N/A if (secondaryLoop != null) {
0N/A modalHide();
0N/A // dialog can be shown and then disposed before its
0N/A // modal filter is created
0N/A if (modalFilter != null) {
0N/A modalFilter.disable();
0N/A }
0N/A modalDialogs.remove(this);
0N/A }
0N/A }
0N/A }
0N/A private void hideAndDisposeHandler() {
2695N/A if (secondaryLoop != null) {
2695N/A secondaryLoop.exit();
2695N/A secondaryLoop = null;
0N/A }
0N/A isInHide = false;
0N/A }
0N/A
0N/A /**
0N/A * Hides the Dialog and then causes {@code show} to return if it is currently
0N/A * blocked.
0N/A * @see Window#show
0N/A * @see Window#dispose
0N/A * @see Window#setVisible(boolean)
0N/A * @deprecated As of JDK version 1.5, replaced by
0N/A * {@link #setVisible(boolean) setVisible(boolean)}.
0N/A */
0N/A @Deprecated
0N/A public void hide() {
0N/A hideAndDisposePreHandler();
0N/A super.hide();
0N/A // fix for 5048370: if hide() is called from super.doDispose(), then
0N/A // hideAndDisposeHandler() should not be called here as it will be called
0N/A // at the end of doDispose()
0N/A if (!isInDispose) {
0N/A hideAndDisposeHandler();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Disposes the Dialog and then causes show() to return if it is currently
0N/A * blocked.
0N/A */
0N/A void doDispose() {
0N/A // fix for 5048370: set isInDispose flag to true to prevent calling
0N/A // to hideAndDisposeHandler() from hide()
0N/A isInDispose = true;
0N/A super.doDispose();
0N/A hideAndDisposeHandler();
0N/A isInDispose = false;
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * <p>
0N/A * If this dialog is modal and blocks some windows, then all of them are
0N/A * also sent to the back to keep them below the blocking dialog.
0N/A *
0N/A * @see java.awt.Window#toBack
0N/A */
0N/A public void toBack() {
0N/A super.toBack();
0N/A if (visible) {
0N/A synchronized (getTreeLock()) {
0N/A for (Window w : blockedWindows) {
0N/A w.toBack_NoClientCode();
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether this dialog is resizable by the user.
0N/A * By default, all dialogs are initially resizable.
0N/A * @return <code>true</code> if the user can resize the dialog;
0N/A * <code>false</code> otherwise.
0N/A * @see java.awt.Dialog#setResizable
0N/A */
0N/A public boolean isResizable() {
0N/A return resizable;
0N/A }
0N/A
0N/A /**
0N/A * Sets whether this dialog is resizable by the user.
0N/A * @param resizable <code>true</code> if the user can
0N/A * resize this dialog; <code>false</code> otherwise.
0N/A * @see java.awt.Dialog#isResizable
0N/A */
0N/A public void setResizable(boolean resizable) {
0N/A boolean testvalid = false;
0N/A
0N/A synchronized (this) {
0N/A this.resizable = resizable;
0N/A DialogPeer peer = (DialogPeer)this.peer;
0N/A if (peer != null) {
0N/A peer.setResizable(resizable);
0N/A testvalid = true;
0N/A }
0N/A }
0N/A
0N/A // On some platforms, changing the resizable state affects
0N/A // the insets of the Dialog. If we could, we'd call invalidate()
0N/A // from the peer, but we need to guarantee that we're not holding
0N/A // the Dialog lock when we call invalidate().
555N/A if (testvalid) {
555N/A invalidateIfValid();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Disables or enables decorations for this dialog.
3070N/A * <p>
3070N/A * This method can only be called while the dialog is not displayable. To
3070N/A * make this dialog decorated, it must be opaque and have the default shape,
3070N/A * otherwise the {@code IllegalComponentStateException} will be thrown.
3070N/A * Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link
3070N/A * Window#setBackground} for details
3070N/A *
3070N/A * @param undecorated {@code true} if no dialog decorations are to be
3070N/A * enabled; {@code false} if dialog decorations are to be enabled
3070N/A *
3070N/A * @throws IllegalComponentStateException if the dialog is displayable
3070N/A * @throws IllegalComponentStateException if {@code undecorated} is
3070N/A * {@code false}, and this dialog does not have the default shape
3070N/A * @throws IllegalComponentStateException if {@code undecorated} is
3070N/A * {@code false}, and this dialog opacity is less than {@code 1.0f}
3070N/A * @throws IllegalComponentStateException if {@code undecorated} is
3070N/A * {@code false}, and the alpha value of this dialog background
3070N/A * color is less than {@code 1.0f}
3070N/A *
0N/A * @see #isUndecorated
0N/A * @see Component#isDisplayable
3070N/A * @see Window#getShape
3070N/A * @see Window#getOpacity
3070N/A * @see Window#getBackground
3070N/A *
0N/A * @since 1.4
0N/A */
0N/A public void setUndecorated(boolean undecorated) {
0N/A /* Make sure we don't run in the middle of peer creation.*/
0N/A synchronized (getTreeLock()) {
0N/A if (isDisplayable()) {
0N/A throw new IllegalComponentStateException("The dialog is displayable.");
0N/A }
3070N/A if (!undecorated) {
3070N/A if (getOpacity() < 1.0f) {
3070N/A throw new IllegalComponentStateException("The dialog is not opaque");
3070N/A }
3070N/A if (getShape() != null) {
3070N/A throw new IllegalComponentStateException("The dialog does not have a default shape");
3070N/A }
3070N/A Color bg = getBackground();
3070N/A if ((bg != null) && (bg.getAlpha() < 255)) {
3070N/A throw new IllegalComponentStateException("The dialog background color is not opaque");
3070N/A }
3070N/A }
0N/A this.undecorated = undecorated;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Indicates whether this dialog is undecorated.
0N/A * By default, all dialogs are initially decorated.
0N/A * @return <code>true</code> if dialog is undecorated;
0N/A * <code>false</code> otherwise.
0N/A * @see java.awt.Dialog#setUndecorated
0N/A * @since 1.4
0N/A */
0N/A public boolean isUndecorated() {
0N/A return undecorated;
0N/A }
0N/A
0N/A /**
3070N/A * {@inheritDoc}
3070N/A */
3070N/A @Override
3070N/A public void setOpacity(float opacity) {
3070N/A synchronized (getTreeLock()) {
3070N/A if ((opacity < 1.0f) && !isUndecorated()) {
3070N/A throw new IllegalComponentStateException("The dialog is decorated");
3070N/A }
3070N/A super.setOpacity(opacity);
3070N/A }
3070N/A }
3070N/A
3070N/A /**
3070N/A * {@inheritDoc}
3070N/A */
3070N/A @Override
3070N/A public void setShape(Shape shape) {
3070N/A synchronized (getTreeLock()) {
3070N/A if ((shape != null) && !isUndecorated()) {
3070N/A throw new IllegalComponentStateException("The dialog is decorated");
3070N/A }
3070N/A super.setShape(shape);
3070N/A }
3070N/A }
3070N/A
3070N/A /**
3070N/A * {@inheritDoc}
3070N/A */
3070N/A @Override
3070N/A public void setBackground(Color bgColor) {
3070N/A synchronized (getTreeLock()) {
3070N/A if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {
3070N/A throw new IllegalComponentStateException("The dialog is decorated");
3070N/A }
3070N/A super.setBackground(bgColor);
3070N/A }
3070N/A }
3070N/A
3070N/A /**
0N/A * Returns a string representing the state of this dialog. This
0N/A * method is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not be
0N/A * <code>null</code>.
0N/A *
0N/A * @return the parameter string of this dialog window.
0N/A */
0N/A protected String paramString() {
0N/A String str = super.paramString() + "," + modalityType;
0N/A if (title != null) {
0N/A str += ",title=" + title;
0N/A }
0N/A return str;
0N/A }
0N/A
0N/A /**
0N/A * Initialize JNI field and method IDs
0N/A */
0N/A private static native void initIDs();
0N/A
0N/A /*
0N/A * --- Modality support ---
0N/A *
0N/A */
0N/A
0N/A /*
0N/A * This method is called only for modal dialogs.
0N/A *
0N/A * Goes through the list of all visible top-level windows and
0N/A * divide them into three distinct groups: blockers of this dialog,
0N/A * blocked by this dialog and all others. Then blocks this dialog
0N/A * by first met dialog from the first group (if any) and blocks all
0N/A * the windows from the second group.
0N/A */
0N/A void modalShow() {
0N/A // find all the dialogs that block this one
0N/A IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>();
0N/A for (Dialog d : modalDialogs) {
0N/A if (d.shouldBlock(this)) {
0N/A Window w = d;
0N/A while ((w != null) && (w != this)) {
0N/A w = (Window)(w.getOwner_NoClientCode());
0N/A }
0N/A if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {
0N/A blockers.add(d);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // add all blockers' blockers to blockers :)
0N/A for (int i = 0; i < blockers.size(); i++) {
0N/A Dialog blocker = blockers.get(i);
0N/A if (blocker.isModalBlocked()) {
0N/A Dialog blockerBlocker = blocker.getModalBlocker();
0N/A if (!blockers.contains(blockerBlocker)) {
0N/A blockers.add(i + 1, blockerBlocker);
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (blockers.size() > 0) {
0N/A blockers.get(0).blockWindow(this);
0N/A }
0N/A
0N/A // find all windows from blockers' hierarchies
0N/A IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers);
0N/A int k = 0;
0N/A while (k < blockersHierarchies.size()) {
0N/A Window w = blockersHierarchies.get(k);
0N/A Window[] ownedWindows = w.getOwnedWindows_NoClientCode();
0N/A for (Window win : ownedWindows) {
0N/A blockersHierarchies.add(win);
0N/A }
0N/A k++;
0N/A }
0N/A
0N/A java.util.List<Window> toBlock = new IdentityLinkedList<Window>();
0N/A // block all windows from scope of blocking except from blockers' hierarchies
0N/A IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows();
0N/A for (Window w : unblockedWindows) {
0N/A if (shouldBlock(w) && !blockersHierarchies.contains(w)) {
0N/A if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
0N/A Dialog wd = (Dialog)w;
0N/A if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) {
0N/A continue;
0N/A }
0N/A }
0N/A toBlock.add(w);
0N/A }
0N/A }
0N/A blockWindows(toBlock);
0N/A
0N/A if (!isModalBlocked()) {
0N/A updateChildrenBlocking();
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * This method is called only for modal dialogs.
0N/A *
0N/A * Unblocks all the windows blocked by this modal dialog. After
0N/A * each of them has been unblocked, it is checked to be blocked by
0N/A * any other modal dialogs.
0N/A */
0N/A void modalHide() {
0N/A // we should unblock all the windows first...
0N/A IdentityArrayList<Window> save = new IdentityArrayList<Window>();
0N/A int blockedWindowsCount = blockedWindows.size();
0N/A for (int i = 0; i < blockedWindowsCount; i++) {
0N/A Window w = blockedWindows.get(0);
0N/A save.add(w);
0N/A unblockWindow(w); // also removes w from blockedWindows
0N/A }
0N/A // ... and only after that check if they should be blocked
0N/A // by another dialogs
0N/A for (int i = 0; i < blockedWindowsCount; i++) {
0N/A Window w = save.get(i);
0N/A if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
0N/A Dialog d = (Dialog)w;
0N/A d.modalShow();
0N/A } else {
0N/A checkShouldBeBlocked(w);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Returns whether the given top-level window should be blocked by
0N/A * this dialog. Note, that the given window can be also a modal dialog
0N/A * and it should block this dialog, but this method do not take such
0N/A * situations into consideration (such checks are performed in the
0N/A * modalShow() and modalHide() methods).
0N/A *
0N/A * This method should be called on the getTreeLock() lock.
0N/A */
0N/A boolean shouldBlock(Window w) {
0N/A if (!isVisible_NoClientCode() ||
0N/A (!w.isVisible_NoClientCode() && !w.isInShow) ||
0N/A isInHide ||
0N/A (w == this) ||
0N/A !isModal_NoClientCode())
0N/A {
0N/A return false;
0N/A }
0N/A if ((w instanceof Dialog) && ((Dialog)w).isInHide) {
0N/A return false;
0N/A }
0N/A // check if w is from children hierarchy
0N/A // fix for 6271546: we should also take into consideration child hierarchies
0N/A // of this dialog's blockers
0N/A Window blockerToCheck = this;
0N/A while (blockerToCheck != null) {
0N/A Component c = w;
0N/A while ((c != null) && (c != blockerToCheck)) {
0N/A c = c.getParent_NoClientCode();
0N/A }
0N/A if (c == blockerToCheck) {
0N/A return false;
0N/A }
0N/A blockerToCheck = blockerToCheck.getModalBlocker();
0N/A }
0N/A switch (modalityType) {
0N/A case MODELESS:
0N/A return false;
0N/A case DOCUMENT_MODAL:
0N/A if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) {
0N/A // application- and toolkit-excluded windows are not blocked by
0N/A // document-modal dialogs from outside their children hierarchy
0N/A Component c = this;
0N/A while ((c != null) && (c != w)) {
0N/A c = c.getParent_NoClientCode();
0N/A }
0N/A return c == w;
0N/A } else {
0N/A return getDocumentRoot() == w.getDocumentRoot();
0N/A }
0N/A case APPLICATION_MODAL:
0N/A return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) &&
0N/A (appContext == w.appContext);
0N/A case TOOLKIT_MODAL:
0N/A return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE);
0N/A }
0N/A
0N/A return false;
0N/A }
0N/A
0N/A /*
0N/A * Adds the given top-level window to the list of blocked
0N/A * windows for this dialog and marks it as modal blocked.
0N/A * If the window is already blocked by some modal dialog,
0N/A * does nothing.
0N/A */
0N/A void blockWindow(Window w) {
0N/A if (!w.isModalBlocked()) {
0N/A w.setModalBlocked(this, true, true);
0N/A blockedWindows.add(w);
0N/A }
0N/A }
0N/A
0N/A void blockWindows(java.util.List<Window> toBlock) {
0N/A DialogPeer dpeer = (DialogPeer)peer;
0N/A if (dpeer == null) {
0N/A return;
0N/A }
0N/A Iterator<Window> it = toBlock.iterator();
0N/A while (it.hasNext()) {
0N/A Window w = it.next();
0N/A if (!w.isModalBlocked()) {
0N/A w.setModalBlocked(this, true, false);
0N/A } else {
0N/A it.remove();
0N/A }
0N/A }
0N/A dpeer.blockWindows(toBlock);
0N/A blockedWindows.addAll(toBlock);
0N/A }
0N/A
0N/A /*
0N/A * Removes the given top-level window from the list of blocked
0N/A * windows for this dialog and marks it as unblocked. If the
0N/A * window is not modal blocked, does nothing.
0N/A */
0N/A void unblockWindow(Window w) {
0N/A if (w.isModalBlocked() && blockedWindows.contains(w)) {
0N/A blockedWindows.remove(w);
0N/A w.setModalBlocked(this, false, true);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Checks if any other modal dialog D blocks the given window.
0N/A * If such D exists, mark the window as blocked by D.
0N/A */
0N/A static void checkShouldBeBlocked(Window w) {
0N/A synchronized (w.getTreeLock()) {
0N/A for (int i = 0; i < modalDialogs.size(); i++) {
0N/A Dialog modalDialog = modalDialogs.get(i);
0N/A if (modalDialog.shouldBlock(w)) {
0N/A modalDialog.blockWindow(w);
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
5719N/A private void checkModalityPermission(ModalityType mt) {
5719N/A if (mt == ModalityType.TOOLKIT_MODAL) {
5719N/A SecurityManager sm = System.getSecurityManager();
5719N/A if (sm != null) {
5719N/A sm.checkPermission(
5719N/A SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION
5719N/A );
5719N/A }
5719N/A }
5719N/A }
5719N/A
0N/A private void readObject(ObjectInputStream s)
0N/A throws ClassNotFoundException, IOException, HeadlessException
0N/A {
0N/A GraphicsEnvironment.checkHeadless();
5719N/A
5719N/A java.io.ObjectInputStream.GetField fields =
5719N/A s.readFields();
5719N/A
5719N/A ModalityType localModalityType = (ModalityType)fields.get("modalityType", null);
5719N/A
5719N/A try {
5719N/A checkModalityPermission(localModalityType);
5719N/A } catch (AccessControlException ace) {
5719N/A localModalityType = DEFAULT_MODALITY_TYPE;
5719N/A }
0N/A
0N/A // in 1.5 or earlier modalityType was absent, so use "modal" instead
5719N/A if (localModalityType == null) {
5719N/A this.modal = fields.get("modal", false);
0N/A setModal(modal);
5728N/A } else {
5728N/A this.modalityType = localModalityType;
0N/A }
0N/A
5719N/A this.resizable = fields.get("resizable", true);
5719N/A this.undecorated = fields.get("undecorated", false);
5719N/A this.title = (String)fields.get("title", "");
5719N/A
0N/A blockedWindows = new IdentityArrayList();
5719N/A
5719N/A SunToolkit.checkAndSetPolicy(this);
5719N/A
5719N/A initialized = true;
5719N/A
0N/A }
0N/A
0N/A /*
0N/A * --- Accessibility Support ---
0N/A *
0N/A */
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this Dialog.
0N/A * For dialogs, the AccessibleContext takes the form of an
0N/A * AccessibleAWTDialog.
0N/A * A new AccessibleAWTDialog instance is created if necessary.
0N/A *
0N/A * @return an AccessibleAWTDialog that serves as the
0N/A * AccessibleContext of this Dialog
0N/A * @since 1.3
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleAWTDialog();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>Dialog</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to dialog user-interface elements.
0N/A * @since 1.3
0N/A */
0N/A protected class AccessibleAWTDialog extends AccessibleAWTWindow
0N/A {
0N/A /*
0N/A * JDK 1.3 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = 4837230331833941201L;
0N/A
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.DIALOG;
0N/A }
0N/A
0N/A /**
0N/A * Get the state of this object.
0N/A *
0N/A * @return an instance of AccessibleStateSet containing the current
0N/A * state set of the object
0N/A * @see AccessibleState
0N/A */
0N/A public AccessibleStateSet getAccessibleStateSet() {
0N/A AccessibleStateSet states = super.getAccessibleStateSet();
0N/A if (getFocusOwner() != null) {
0N/A states.add(AccessibleState.ACTIVE);
0N/A }
0N/A if (isModal()) {
0N/A states.add(AccessibleState.MODAL);
0N/A }
0N/A if (isResizable()) {
0N/A states.add(AccessibleState.RESIZABLE);
0N/A }
0N/A return states;
0N/A }
0N/A
0N/A } // inner class AccessibleAWTDialog
0N/A}