/*
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt;
import java.awt.peer.DialogPeer;
import java.awt.event.*;
import java.io.ObjectInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import java.security.AccessController;
import java.security.PrivilegedAction;
import javax.accessibility.*;
import sun.awt.AppContext;
import sun.awt.AWTPermissions;
import sun.awt.SunToolkit;
import sun.awt.util.IdentityArrayList;
import sun.awt.util.IdentityLinkedList;
import java.security.AccessControlException;
/**
* A Dialog is a top-level window with a title and a border
* that is typically used to take some form of input from the user.
*
* The size of the dialog includes any area designated for the
* border. The dimensions of the border area can be obtained
* using the {@code getInsets} method, however, since
* these dimensions are platform-dependent, a valid insets
* value cannot be obtained until the dialog is made displayable
* by either calling {@code pack} or {@code show}.
* Since the border area is included in the overall size of the
* dialog, the border effectively obscures a portion of the dialog,
* constraining the area available for rendering and/or displaying
* subcomponents to the rectangle which has an upper-left corner
* location of {@code (insets.left, insets.top)}, and has a size of
* {@code width - (insets.left + insets.right)} by
* {@code height - (insets.top + insets.bottom)}.
*
* The default layout for a dialog is {@code BorderLayout}.
*
* A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
* with {@code setUndecorated}. This can only be done while the dialog
* is not {@link Component#isDisplayable() displayable}.
*
* A dialog may have another window as its owner when it's constructed. When
* the owner window of a visible dialog is minimized, the dialog will
* automatically be hidden from the user. When the owner window is subsequently
* restored, the dialog is made visible to the user again.
*
* In a multi-screen environment, you can create a {@code Dialog}
* on a different screen device than its owner. See {@link java.awt.Frame} for
* more information.
*
* A dialog can be either modeless (the default) or modal. A modal
* dialog is one which blocks input to some other top-level windows
* in the application, except for any windows created with the dialog
* as their owner. See AWT Modality
* specification for details.
*
* Dialogs are capable of generating the following
* {@code WindowEvents}:
* {@code WindowOpened}, {@code WindowClosing},
* {@code WindowClosed}, {@code WindowActivated},
* {@code WindowDeactivated}, {@code WindowGainedFocus},
* {@code WindowLostFocus}.
*
* @see WindowEvent
* @see Window#addWindowListener
*
* @author Sami Shaio
* @author Arthur van Hoff
* @since 1.0
*/
public class Dialog extends Window {
static {
/* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries();
if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
}
/**
* A dialog's resizable property. Will be true
* if the Dialog is to be resizable, otherwise
* it will be false.
*
* @serial
* @see #setResizable(boolean)
*/
boolean resizable = true;
/**
* This field indicates whether the dialog is undecorated.
* This property can only be changed while the dialog is not displayable.
* {@code undecorated} will be true if the dialog is
* undecorated, otherwise it will be false.
*
* @serial
* @see #setUndecorated(boolean)
* @see #isUndecorated()
* @see Component#isDisplayable()
* @since 1.4
*/
boolean undecorated = false;
private transient boolean initialized = false;
/**
* Modal dialogs block all input to some top-level windows.
* Whether a particular window is blocked depends on dialog's type
* of modality; this is called the "scope of blocking". The
* {@code ModalityType} enum specifies modal types and their
* associated scopes.
*
* @see Dialog#getModalityType
* @see Dialog#setModalityType
* @see Toolkit#isModalityTypeSupported
*
* @since 1.6
*/
public static enum ModalityType {
/**
* {@code MODELESS} dialog doesn't block any top-level windows.
*/
MODELESS,
/**
* A {@code DOCUMENT_MODAL} dialog blocks input to all top-level windows
* from the same document except those from its own child hierarchy.
* A document is a top-level window without an owner. It may contain child
* windows that, together with the top-level window are treated as a single
* solid document. Since every top-level window must belong to some
* document, its root can be found as the top-nearest window without an owner.
*/
DOCUMENT_MODAL,
/**
* An {@code APPLICATION_MODAL} dialog blocks all top-level windows
* from the same Java application except those from its own child hierarchy.
* If there are several applets launched in a browser, they can be
* treated either as separate applications or a single one. This behavior
* is implementation-dependent.
*/
APPLICATION_MODAL,
/**
* A {@code TOOLKIT_MODAL} dialog blocks all top-level windows run
* from the same toolkit except those from its own child hierarchy. If there
* are several applets launched in a browser, all of them run with the same
* toolkit; thus, a toolkit-modal dialog displayed by an applet may affect
* other applets and all windows of the browser instance which embeds the
* Java runtime environment for this toolkit.
* Special {@code AWTPermission} "toolkitModality" must be granted to use
* toolkit-modal dialogs. If a {@code TOOLKIT_MODAL} dialog is being created
* and this permission is not granted, a {@code SecurityException} will be
* thrown, and no dialog will be created. If a modality type is being changed
* to {@code TOOLKIT_MODAL} and this permission is not granted, a
* {@code SecurityException} will be thrown, and the modality type will
* be left unchanged.
*/
TOOLKIT_MODAL
};
/**
* Default modality type for modal dialogs. The default modality type is
* {@code APPLICATION_MODAL}. Calling the oldstyle {@code setModal(true)}
* is equal to {@code setModalityType(DEFAULT_MODALITY_TYPE)}.
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog#setModal
*
* @since 1.6
*/
public static final ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL;
/**
* True if this dialog is modal, false is the dialog is modeless.
* A modal dialog blocks user input to some application top-level
* windows. This field is kept only for backwards compatibility. Use the
* {@link Dialog.ModalityType ModalityType} enum instead.
*
* @serial
*
* @see #isModal
* @see #setModal
* @see #getModalityType
* @see #setModalityType
* @see ModalityType
* @see ModalityType#MODELESS
* @see #DEFAULT_MODALITY_TYPE
*/
boolean modal;
/**
* Modality type of this dialog. If the dialog's modality type is not
* {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all
* user input to some application top-level windows.
*
* @serial
*
* @see ModalityType
* @see #getModalityType
* @see #setModalityType
*
* @since 1.6
*/
ModalityType modalityType;
/**
* Any top-level window can be marked not to be blocked by modal
* dialogs. This is called "modal exclusion". This enum specifies
* the possible modal exclusion types.
*
* @see Window#getModalExclusionType
* @see Window#setModalExclusionType
* @see Toolkit#isModalExclusionTypeSupported
*
* @since 1.6
*/
public static enum ModalExclusionType {
/**
* No modal exclusion.
*/
NO_EXCLUDE,
/**
* {@code APPLICATION_EXCLUDE} indicates that a top-level window
* won't be blocked by any application-modal dialogs. Also, it isn't
* blocked by document-modal dialogs from outside of its child hierarchy.
*/
APPLICATION_EXCLUDE,
/**
* {@code TOOLKIT_EXCLUDE} indicates that a top-level window
* won't be blocked by application-modal or toolkit-modal dialogs. Also,
* it isn't blocked by document-modal dialogs from outside of its
* child hierarchy.
* The "toolkitModality" {@code AWTPermission} must be granted
* for this exclusion. If an exclusion property is being changed to
* {@code TOOLKIT_EXCLUDE} and this permission is not granted, a
* {@code SecurityException} will be thrown, and the exclusion
* property will be left unchanged.
*/
TOOLKIT_EXCLUDE
};
/* operations with this list should be synchronized on tree lock*/
static transient IdentityArrayList