/*
* Copyright 1995-2008 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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.SunToolkit;
import sun.awt.PeerEvent;
import sun.awt.util.IdentityArrayList;
import sun.awt.util.IdentityLinkedList;
import sun.security.util.SecurityConstants;
/**
* 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 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 pack
or 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 (insets.left, insets.top)
, and has a size of
* width - (insets.left + insets.right)
by
* height - (insets.top + insets.bottom)
.
*
* The default layout for a dialog is BorderLayout
.
*
* A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
* with 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 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
* WindowEvents
:
* WindowOpened
, WindowClosing
,
* WindowClosed
, WindowActivated
,
* WindowDeactivated
, WindowGainedFocus
,
* WindowLostFocus
.
*
* @see WindowEvent
* @see Window#addWindowListener
*
* @author Sami Shaio
* @author Arthur van Hoff
* @since JDK1.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.
* 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;
/**
* 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
* 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 {
/**
* MODELESS
dialog doesn't block any top-level windows.
*/
MODELESS,
/**
* A 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 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 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 AWTPermission
"toolkitModality" must be granted to use
* toolkit-modal dialogs. If a TOOLKIT_MODAL
dialog is being created
* and this permission is not granted, a SecurityException
will be
* thrown, and no dialog will be created. If a modality type is being changed
* to TOOLKIT_MODAL
and this permission is not granted, a
* 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
* APPLICATION_MODAL
. Calling the oldstyle setModal(true)
* is equal to setModalityType(DEFAULT_MODALITY_TYPE)
.
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog#setModal
*
* @since 1.6
*/
public final static 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,
/**
* 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,
/**
* 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" AWTPermission
must be granted
* for this exclusion. If an exclusion property is being changed to
* TOOLKIT_EXCLUDE
and this permission is not granted, a
* SecurityEcxeption
will be thrown, and the exclusion
* property will be left unchanged.
*/
TOOLKIT_EXCLUDE
};
/* operations with this list should be synchronized on tree lock*/
transient static IdentityArrayList