Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/awt/Dialog.java
38829 views
/*1* Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package java.awt;2526import java.awt.peer.DialogPeer;27import java.awt.event.*;28import java.io.ObjectInputStream;29import java.io.IOException;30import java.util.Iterator;31import java.util.concurrent.atomic.AtomicLong;32import java.security.AccessController;33import java.security.PrivilegedAction;34import javax.accessibility.*;35import sun.awt.AppContext;36import sun.awt.SunToolkit;37import sun.awt.PeerEvent;38import sun.awt.util.IdentityArrayList;39import sun.awt.util.IdentityLinkedList;40import sun.security.util.SecurityConstants;41import java.security.AccessControlException;4243/**44* A Dialog is a top-level window with a title and a border45* that is typically used to take some form of input from the user.46*47* The size of the dialog includes any area designated for the48* border. The dimensions of the border area can be obtained49* using the <code>getInsets</code> method, however, since50* these dimensions are platform-dependent, a valid insets51* value cannot be obtained until the dialog is made displayable52* by either calling <code>pack</code> or <code>show</code>.53* Since the border area is included in the overall size of the54* dialog, the border effectively obscures a portion of the dialog,55* constraining the area available for rendering and/or displaying56* subcomponents to the rectangle which has an upper-left corner57* location of <code>(insets.left, insets.top)</code>, and has a size of58* <code>width - (insets.left + insets.right)</code> by59* <code>height - (insets.top + insets.bottom)</code>.60* <p>61* The default layout for a dialog is <code>BorderLayout</code>.62* <p>63* A dialog may have its native decorations (i.e. Frame & Titlebar) turned off64* with <code>setUndecorated</code>. This can only be done while the dialog65* is not {@link Component#isDisplayable() displayable}.66* <p>67* A dialog may have another window as its owner when it's constructed. When68* the owner window of a visible dialog is minimized, the dialog will69* automatically be hidden from the user. When the owner window is subsequently70* restored, the dialog is made visible to the user again.71* <p>72* In a multi-screen environment, you can create a <code>Dialog</code>73* on a different screen device than its owner. See {@link java.awt.Frame} for74* more information.75* <p>76* A dialog can be either modeless (the default) or modal. A modal77* dialog is one which blocks input to some other top-level windows78* in the application, except for any windows created with the dialog79* as their owner. See <a href="doc-files/Modality.html">AWT Modality</a>80* specification for details.81* <p>82* Dialogs are capable of generating the following83* <code>WindowEvents</code>:84* <code>WindowOpened</code>, <code>WindowClosing</code>,85* <code>WindowClosed</code>, <code>WindowActivated</code>,86* <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>,87* <code>WindowLostFocus</code>.88*89* @see WindowEvent90* @see Window#addWindowListener91*92* @author Sami Shaio93* @author Arthur van Hoff94* @since JDK1.095*/96public class Dialog extends Window {9798static {99/* ensure that the necessary native libraries are loaded */100Toolkit.loadLibraries();101if (!GraphicsEnvironment.isHeadless()) {102initIDs();103}104}105106/**107* A dialog's resizable property. Will be true108* if the Dialog is to be resizable, otherwise109* it will be false.110*111* @serial112* @see #setResizable(boolean)113*/114boolean resizable = true;115116117/**118* This field indicates whether the dialog is undecorated.119* This property can only be changed while the dialog is not displayable.120* <code>undecorated</code> will be true if the dialog is121* undecorated, otherwise it will be false.122*123* @serial124* @see #setUndecorated(boolean)125* @see #isUndecorated()126* @see Component#isDisplayable()127* @since 1.4128*/129boolean undecorated = false;130131private transient boolean initialized = false;132133/**134* Modal dialogs block all input to some top-level windows.135* Whether a particular window is blocked depends on dialog's type136* of modality; this is called the "scope of blocking". The137* <code>ModalityType</code> enum specifies modal types and their138* associated scopes.139*140* @see Dialog#getModalityType141* @see Dialog#setModalityType142* @see Toolkit#isModalityTypeSupported143*144* @since 1.6145*/146public static enum ModalityType {147/**148* <code>MODELESS</code> dialog doesn't block any top-level windows.149*/150MODELESS,151/**152* A <code>DOCUMENT_MODAL</code> dialog blocks input to all top-level windows153* from the same document except those from its own child hierarchy.154* A document is a top-level window without an owner. It may contain child155* windows that, together with the top-level window are treated as a single156* solid document. Since every top-level window must belong to some157* document, its root can be found as the top-nearest window without an owner.158*/159DOCUMENT_MODAL,160/**161* An <code>APPLICATION_MODAL</code> dialog blocks all top-level windows162* from the same Java application except those from its own child hierarchy.163* If there are several applets launched in a browser, they can be164* treated either as separate applications or a single one. This behavior165* is implementation-dependent.166*/167APPLICATION_MODAL,168/**169* A <code>TOOLKIT_MODAL</code> dialog blocks all top-level windows run170* from the same toolkit except those from its own child hierarchy. If there171* are several applets launched in a browser, all of them run with the same172* toolkit; thus, a toolkit-modal dialog displayed by an applet may affect173* other applets and all windows of the browser instance which embeds the174* Java runtime environment for this toolkit.175* Special <code>AWTPermission</code> "toolkitModality" must be granted to use176* toolkit-modal dialogs. If a <code>TOOLKIT_MODAL</code> dialog is being created177* and this permission is not granted, a <code>SecurityException</code> will be178* thrown, and no dialog will be created. If a modality type is being changed179* to <code>TOOLKIT_MODAL</code> and this permission is not granted, a180* <code>SecurityException</code> will be thrown, and the modality type will181* be left unchanged.182*/183TOOLKIT_MODAL184};185186/**187* Default modality type for modal dialogs. The default modality type is188* <code>APPLICATION_MODAL</code>. Calling the oldstyle <code>setModal(true)</code>189* is equal to <code>setModalityType(DEFAULT_MODALITY_TYPE)</code>.190*191* @see java.awt.Dialog.ModalityType192* @see java.awt.Dialog#setModal193*194* @since 1.6195*/196public final static ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL;197198/**199* True if this dialog is modal, false is the dialog is modeless.200* A modal dialog blocks user input to some application top-level201* windows. This field is kept only for backwards compatibility. Use the202* {@link Dialog.ModalityType ModalityType} enum instead.203*204* @serial205*206* @see #isModal207* @see #setModal208* @see #getModalityType209* @see #setModalityType210* @see ModalityType211* @see ModalityType#MODELESS212* @see #DEFAULT_MODALITY_TYPE213*/214boolean modal;215216/**217* Modality type of this dialog. If the dialog's modality type is not218* {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all219* user input to some application top-level windows.220*221* @serial222*223* @see ModalityType224* @see #getModalityType225* @see #setModalityType226*227* @since 1.6228*/229ModalityType modalityType;230231/**232* Any top-level window can be marked not to be blocked by modal233* dialogs. This is called "modal exclusion". This enum specifies234* the possible modal exclusion types.235*236* @see Window#getModalExclusionType237* @see Window#setModalExclusionType238* @see Toolkit#isModalExclusionTypeSupported239*240* @since 1.6241*/242public static enum ModalExclusionType {243/**244* No modal exclusion.245*/246NO_EXCLUDE,247/**248* <code>APPLICATION_EXCLUDE</code> indicates that a top-level window249* won't be blocked by any application-modal dialogs. Also, it isn't250* blocked by document-modal dialogs from outside of its child hierarchy.251*/252APPLICATION_EXCLUDE,253/**254* <code>TOOLKIT_EXCLUDE</code> indicates that a top-level window255* won't be blocked by application-modal or toolkit-modal dialogs. Also,256* it isn't blocked by document-modal dialogs from outside of its257* child hierarchy.258* The "toolkitModality" <code>AWTPermission</code> must be granted259* for this exclusion. If an exclusion property is being changed to260* <code>TOOLKIT_EXCLUDE</code> and this permission is not granted, a261* <code>SecurityEcxeption</code> will be thrown, and the exclusion262* property will be left unchanged.263*/264TOOLKIT_EXCLUDE265};266267/* operations with this list should be synchronized on tree lock*/268transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>();269270transient IdentityArrayList<Window> blockedWindows = new IdentityArrayList<Window>();271272/**273* Specifies the title of the Dialog.274* This field can be null.275*276* @serial277* @see #getTitle()278* @see #setTitle(String)279*/280String title;281282private transient ModalEventFilter modalFilter;283private transient volatile SecondaryLoop secondaryLoop;284285/*286* Indicates that this dialog is being hidden. This flag is set to true at287* the beginning of hide() and to false at the end of hide().288*289* @see #hide()290* @see #hideAndDisposePreHandler()291* @see #hideAndDisposeHandler()292* @see #shouldBlock()293*/294transient volatile boolean isInHide = false;295296/*297* Indicates that this dialog is being disposed. This flag is set to true at298* the beginning of doDispose() and to false at the end of doDispose().299*300* @see #hide()301* @see #hideAndDisposePreHandler()302* @see #hideAndDisposeHandler()303* @see #doDispose()304*/305transient volatile boolean isInDispose = false;306307private static final String base = "dialog";308private static int nameCounter = 0;309310/*311* JDK 1.1 serialVersionUID312*/313private static final long serialVersionUID = 5920926903803293709L;314315/**316* Constructs an initially invisible, modeless <code>Dialog</code> with317* the specified owner <code>Frame</code> and an empty title.318*319* @param owner the owner of the dialog or <code>null</code> if320* this dialog has no owner321* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s322* <code>GraphicsConfiguration</code> is not from a screen device323* @exception HeadlessException when324* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>325*326* @see java.awt.GraphicsEnvironment#isHeadless327* @see Component#setSize328* @see Component#setVisible329*/330public Dialog(Frame owner) {331this(owner, "", false);332}333334/**335* Constructs an initially invisible <code>Dialog</code> with the specified336* owner <code>Frame</code> and modality and an empty title.337*338* @param owner the owner of the dialog or <code>null</code> if339* this dialog has no owner340* @param modal specifies whether dialog blocks user input to other top-level341* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;342* if <code>true</code>, the modality type property is set to343* <code>DEFAULT_MODALITY_TYPE</code>344* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s345* <code>GraphicsConfiguration</code> is not from a screen device346* @exception HeadlessException when347* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>348*349* @see java.awt.Dialog.ModalityType350* @see java.awt.Dialog.ModalityType#MODELESS351* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE352* @see java.awt.Dialog#setModal353* @see java.awt.Dialog#setModalityType354* @see java.awt.GraphicsEnvironment#isHeadless355*/356public Dialog(Frame owner, boolean modal) {357this(owner, "", modal);358}359360/**361* Constructs an initially invisible, modeless <code>Dialog</code> with362* the specified owner <code>Frame</code> and title.363*364* @param owner the owner of the dialog or <code>null</code> if365* this dialog has no owner366* @param title the title of the dialog or <code>null</code> if this dialog367* has no title368* @exception IllegalArgumentException if the <code>owner</code>'s369* <code>GraphicsConfiguration</code> is not from a screen device370* @exception HeadlessException when371* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>372*373* @see java.awt.GraphicsEnvironment#isHeadless374* @see Component#setSize375* @see Component#setVisible376*/377public Dialog(Frame owner, String title) {378this(owner, title, false);379}380381/**382* Constructs an initially invisible <code>Dialog</code> with the383* specified owner <code>Frame</code>, title and modality.384*385* @param owner the owner of the dialog or <code>null</code> if386* this dialog has no owner387* @param title the title of the dialog or <code>null</code> if this dialog388* has no title389* @param modal specifies whether dialog blocks user input to other top-level390* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;391* if <code>true</code>, the modality type property is set to392* <code>DEFAULT_MODALITY_TYPE</code>393* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s394* <code>GraphicsConfiguration</code> is not from a screen device395* @exception HeadlessException when396* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>397*398* @see java.awt.Dialog.ModalityType399* @see java.awt.Dialog.ModalityType#MODELESS400* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE401* @see java.awt.Dialog#setModal402* @see java.awt.Dialog#setModalityType403* @see java.awt.GraphicsEnvironment#isHeadless404* @see Component#setSize405* @see Component#setVisible406*/407public Dialog(Frame owner, String title, boolean modal) {408this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);409}410411/**412* Constructs an initially invisible <code>Dialog</code> with the specified owner413* <code>Frame</code>, title, modality, and <code>GraphicsConfiguration</code>.414* @param owner the owner of the dialog or <code>null</code> if this dialog415* has no owner416* @param title the title of the dialog or <code>null</code> if this dialog417* has no title418* @param modal specifies whether dialog blocks user input to other top-level419* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;420* if <code>true</code>, the modality type property is set to421* <code>DEFAULT_MODALITY_TYPE</code>422* @param gc the <code>GraphicsConfiguration</code> of the target screen device;423* if <code>null</code>, the default system <code>GraphicsConfiguration</code>424* is assumed425* @exception java.lang.IllegalArgumentException if <code>gc</code>426* is not from a screen device427* @exception HeadlessException when428* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>429*430* @see java.awt.Dialog.ModalityType431* @see java.awt.Dialog.ModalityType#MODELESS432* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE433* @see java.awt.Dialog#setModal434* @see java.awt.Dialog#setModalityType435* @see java.awt.GraphicsEnvironment#isHeadless436* @see Component#setSize437* @see Component#setVisible438* @since 1.4439*/440public Dialog(Frame owner, String title, boolean modal,441GraphicsConfiguration gc) {442this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);443}444445/**446* Constructs an initially invisible, modeless <code>Dialog</code> with447* the specified owner <code>Dialog</code> and an empty title.448*449* @param owner the owner of the dialog or <code>null</code> if this450* dialog has no owner451* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s452* <code>GraphicsConfiguration</code> is not from a screen device453* @exception HeadlessException when454* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>455* @see java.awt.GraphicsEnvironment#isHeadless456* @since 1.2457*/458public Dialog(Dialog owner) {459this(owner, "", false);460}461462/**463* Constructs an initially invisible, modeless <code>Dialog</code>464* with the specified owner <code>Dialog</code> and title.465*466* @param owner the owner of the dialog or <code>null</code> if this467* has no owner468* @param title the title of the dialog or <code>null</code> if this dialog469* has no title470* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s471* <code>GraphicsConfiguration</code> is not from a screen device472* @exception HeadlessException when473* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>474*475* @see java.awt.GraphicsEnvironment#isHeadless476* @since 1.2477*/478public Dialog(Dialog owner, String title) {479this(owner, title, false);480}481482/**483* Constructs an initially invisible <code>Dialog</code> with the484* specified owner <code>Dialog</code>, title, and modality.485*486* @param owner the owner of the dialog or <code>null</code> if this487* dialog has no owner488* @param title the title of the dialog or <code>null</code> if this489* dialog has no title490* @param modal specifies whether dialog blocks user input to other top-level491* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;492* if <code>true</code>, the modality type property is set to493* <code>DEFAULT_MODALITY_TYPE</code>494* @exception IllegalArgumentException if the <code>owner</code>'s495* <code>GraphicsConfiguration</code> is not from a screen device496* @exception HeadlessException when497* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>498*499* @see java.awt.Dialog.ModalityType500* @see java.awt.Dialog.ModalityType#MODELESS501* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE502* @see java.awt.Dialog#setModal503* @see java.awt.Dialog#setModalityType504* @see java.awt.GraphicsEnvironment#isHeadless505*506* @since 1.2507*/508public Dialog(Dialog owner, String title, boolean modal) {509this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);510}511512/**513* Constructs an initially invisible <code>Dialog</code> with the514* specified owner <code>Dialog</code>, title, modality and515* <code>GraphicsConfiguration</code>.516*517* @param owner the owner of the dialog or <code>null</code> if this518* dialog has no owner519* @param title the title of the dialog or <code>null</code> if this520* dialog has no title521* @param modal specifies whether dialog blocks user input to other top-level522* windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;523* if <code>true</code>, the modality type property is set to524* <code>DEFAULT_MODALITY_TYPE</code>525* @param gc the <code>GraphicsConfiguration</code> of the target screen device;526* if <code>null</code>, the default system <code>GraphicsConfiguration</code>527* is assumed528* @exception java.lang.IllegalArgumentException if <code>gc</code>529* is not from a screen device530* @exception HeadlessException when531* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>532*533* @see java.awt.Dialog.ModalityType534* @see java.awt.Dialog.ModalityType#MODELESS535* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE536* @see java.awt.Dialog#setModal537* @see java.awt.Dialog#setModalityType538* @see java.awt.GraphicsEnvironment#isHeadless539* @see Component#setSize540* @see Component#setVisible541*542* @since 1.4543*/544public Dialog(Dialog owner, String title, boolean modal,545GraphicsConfiguration gc) {546this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);547}548549/**550* Constructs an initially invisible, modeless <code>Dialog</code> with the551* specified owner <code>Window</code> and an empty title.552*553* @param owner the owner of the dialog. The owner must be an instance of554* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any555* of their descendents or <code>null</code>556*557* @exception java.lang.IllegalArgumentException if the <code>owner</code>558* is not an instance of {@link java.awt.Dialog Dialog} or {@link559* java.awt.Frame Frame}560* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s561* <code>GraphicsConfiguration</code> is not from a screen device562* @exception HeadlessException when563* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>564*565* @see java.awt.GraphicsEnvironment#isHeadless566*567* @since 1.6568*/569public Dialog(Window owner) {570this(owner, "", ModalityType.MODELESS);571}572573/**574* Constructs an initially invisible, modeless <code>Dialog</code> with575* the specified owner <code>Window</code> and title.576*577* @param owner the owner of the dialog. The owner must be an instance of578* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any579* of their descendents or <code>null</code>580* @param title the title of the dialog or <code>null</code> if this dialog581* has no title582*583* @exception java.lang.IllegalArgumentException if the <code>owner</code>584* is not an instance of {@link java.awt.Dialog Dialog} or {@link585* java.awt.Frame Frame}586* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s587* <code>GraphicsConfiguration</code> is not from a screen device588* @exception HeadlessException when589* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>590*591* @see java.awt.GraphicsEnvironment#isHeadless592*593* @since 1.6594*/595public Dialog(Window owner, String title) {596this(owner, title, ModalityType.MODELESS);597}598599/**600* Constructs an initially invisible <code>Dialog</code> with the601* specified owner <code>Window</code> and modality and an empty title.602*603* @param owner the owner of the dialog. The owner must be an instance of604* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any605* of their descendents or <code>null</code>606* @param modalityType specifies whether dialog blocks input to other607* windows when shown. <code>null</code> value and unsupported modality608* types are equivalent to <code>MODELESS</code>609*610* @exception java.lang.IllegalArgumentException if the <code>owner</code>611* is not an instance of {@link java.awt.Dialog Dialog} or {@link612* java.awt.Frame Frame}613* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s614* <code>GraphicsConfiguration</code> is not from a screen device615* @exception HeadlessException when616* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>617* @exception SecurityException if the calling thread does not have permission618* to create modal dialogs with the given <code>modalityType</code>619*620* @see java.awt.Dialog.ModalityType621* @see java.awt.Dialog#setModal622* @see java.awt.Dialog#setModalityType623* @see java.awt.GraphicsEnvironment#isHeadless624* @see java.awt.Toolkit#isModalityTypeSupported625*626* @since 1.6627*/628public Dialog(Window owner, ModalityType modalityType) {629this(owner, "", modalityType);630}631632/**633* Constructs an initially invisible <code>Dialog</code> with the634* specified owner <code>Window</code>, title and modality.635*636* @param owner the owner of the dialog. The owner must be an instance of637* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any638* of their descendents or <code>null</code>639* @param title the title of the dialog or <code>null</code> if this dialog640* has no title641* @param modalityType specifies whether dialog blocks input to other642* windows when shown. <code>null</code> value and unsupported modality643* types are equivalent to <code>MODELESS</code>644*645* @exception java.lang.IllegalArgumentException if the <code>owner</code>646* is not an instance of {@link java.awt.Dialog Dialog} or {@link647* java.awt.Frame Frame}648* @exception java.lang.IllegalArgumentException if the <code>owner</code>'s649* <code>GraphicsConfiguration</code> is not from a screen device650* @exception HeadlessException when651* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>652* @exception SecurityException if the calling thread does not have permission653* to create modal dialogs with the given <code>modalityType</code>654*655* @see java.awt.Dialog.ModalityType656* @see java.awt.Dialog#setModal657* @see java.awt.Dialog#setModalityType658* @see java.awt.GraphicsEnvironment#isHeadless659* @see java.awt.Toolkit#isModalityTypeSupported660*661* @since 1.6662*/663public Dialog(Window owner, String title, ModalityType modalityType) {664super(owner);665666if ((owner != null) &&667!(owner instanceof Frame) &&668!(owner instanceof Dialog))669{670throw new IllegalArgumentException("Wrong parent window");671}672673this.title = title;674setModalityType(modalityType);675SunToolkit.checkAndSetPolicy(this);676initialized = true;677}678679/**680* Constructs an initially invisible <code>Dialog</code> with the681* specified owner <code>Window</code>, title, modality and682* <code>GraphicsConfiguration</code>.683*684* @param owner the owner of the dialog. The owner must be an instance of685* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any686* of their descendents or <code>null</code>687* @param title the title of the dialog or <code>null</code> if this dialog688* has no title689* @param modalityType specifies whether dialog blocks input to other690* windows when shown. <code>null</code> value and unsupported modality691* types are equivalent to <code>MODELESS</code>692* @param gc the <code>GraphicsConfiguration</code> of the target screen device;693* if <code>null</code>, the default system <code>GraphicsConfiguration</code>694* is assumed695*696* @exception java.lang.IllegalArgumentException if the <code>owner</code>697* is not an instance of {@link java.awt.Dialog Dialog} or {@link698* java.awt.Frame Frame}699* @exception java.lang.IllegalArgumentException if <code>gc</code>700* is not from a screen device701* @exception HeadlessException when702* <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>703* @exception SecurityException if the calling thread does not have permission704* to create modal dialogs with the given <code>modalityType</code>705*706* @see java.awt.Dialog.ModalityType707* @see java.awt.Dialog#setModal708* @see java.awt.Dialog#setModalityType709* @see java.awt.GraphicsEnvironment#isHeadless710* @see java.awt.Toolkit#isModalityTypeSupported711*712* @since 1.6713*/714public Dialog(Window owner, String title, ModalityType modalityType,715GraphicsConfiguration gc) {716super(owner, gc);717718if ((owner != null) &&719!(owner instanceof Frame) &&720!(owner instanceof Dialog))721{722throw new IllegalArgumentException("wrong owner window");723}724725this.title = title;726setModalityType(modalityType);727SunToolkit.checkAndSetPolicy(this);728initialized = true;729}730731/**732* Construct a name for this component. Called by getName() when the733* name is null.734*/735String constructComponentName() {736synchronized (Dialog.class) {737return base + nameCounter++;738}739}740741/**742* Makes this Dialog displayable by connecting it to743* a native screen resource. Making a dialog displayable will744* cause any of its children to be made displayable.745* This method is called internally by the toolkit and should746* not be called directly by programs.747* @see Component#isDisplayable748* @see #removeNotify749*/750public void addNotify() {751synchronized (getTreeLock()) {752if (parent != null && parent.getPeer() == null) {753parent.addNotify();754}755756if (peer == null) {757peer = getToolkit().createDialog(this);758}759super.addNotify();760}761}762763/**764* Indicates whether the dialog is modal.765* <p>766* This method is obsolete and is kept for backwards compatibility only.767* Use {@link #getModalityType getModalityType()} instead.768*769* @return <code>true</code> if this dialog window is modal;770* <code>false</code> otherwise771*772* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE773* @see java.awt.Dialog.ModalityType#MODELESS774* @see java.awt.Dialog#setModal775* @see java.awt.Dialog#getModalityType776* @see java.awt.Dialog#setModalityType777*/778public boolean isModal() {779return isModal_NoClientCode();780}781final boolean isModal_NoClientCode() {782return modalityType != ModalityType.MODELESS;783}784785/**786* Specifies whether this dialog should be modal.787* <p>788* This method is obsolete and is kept for backwards compatibility only.789* Use {@link #setModalityType setModalityType()} instead.790* <p>791* Note: changing modality of the visible dialog may have no effect792* until it is hidden and then shown again.793*794* @param modal specifies whether dialog blocks input to other windows795* when shown; calling to <code>setModal(true)</code> is equivalent to796* <code>setModalityType(Dialog.DEFAULT_MODALITY_TYPE)</code>, and797* calling to <code>setModal(false)</code> is equvivalent to798* <code>setModalityType(Dialog.ModalityType.MODELESS)</code>799*800* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE801* @see java.awt.Dialog.ModalityType#MODELESS802* @see java.awt.Dialog#isModal803* @see java.awt.Dialog#getModalityType804* @see java.awt.Dialog#setModalityType805*806* @since 1.1807*/808public void setModal(boolean modal) {809this.modal = modal;810setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);811}812813/**814* Returns the modality type of this dialog.815*816* @return modality type of this dialog817*818* @see java.awt.Dialog#setModalityType819*820* @since 1.6821*/822public ModalityType getModalityType() {823return modalityType;824}825826/**827* Sets the modality type for this dialog. See {@link828* java.awt.Dialog.ModalityType ModalityType} for possible modality types.829* <p>830* If the given modality type is not supported, <code>MODELESS</code>831* is used. You may want to call <code>getModalityType()</code> after calling832* this method to ensure that the modality type has been set.833* <p>834* Note: changing modality of the visible dialog may have no effect835* until it is hidden and then shown again.836*837* @param type specifies whether dialog blocks input to other838* windows when shown. <code>null</code> value and unsupported modality839* types are equivalent to <code>MODELESS</code>840* @exception SecurityException if the calling thread does not have permission841* to create modal dialogs with the given <code>modalityType</code>842*843* @see java.awt.Dialog#getModalityType844* @see java.awt.Toolkit#isModalityTypeSupported845*846* @since 1.6847*/848public void setModalityType(ModalityType type) {849if (type == null) {850type = Dialog.ModalityType.MODELESS;851}852if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) {853type = Dialog.ModalityType.MODELESS;854}855if (modalityType == type) {856return;857}858859checkModalityPermission(type);860861modalityType = type;862modal = (modalityType != ModalityType.MODELESS);863}864865/**866* Gets the title of the dialog. The title is displayed in the867* dialog's border.868* @return the title of this dialog window. The title may be869* <code>null</code>.870* @see java.awt.Dialog#setTitle871*/872public String getTitle() {873return title;874}875876/**877* Sets the title of the Dialog.878* @param title the title displayed in the dialog's border;879* a null value results in an empty title880* @see #getTitle881*/882public void setTitle(String title) {883String oldTitle = this.title;884885synchronized(this) {886this.title = title;887DialogPeer peer = (DialogPeer)this.peer;888if (peer != null) {889peer.setTitle(title);890}891}892firePropertyChange("title", oldTitle, title);893}894895/**896* @return true if we actually showed, false if we just called toFront()897*/898private boolean conditionalShow(Component toFocus, AtomicLong time) {899boolean retval;900901closeSplashScreen();902903synchronized (getTreeLock()) {904if (peer == null) {905addNotify();906}907validateUnconditionally();908if (visible) {909toFront();910retval = false;911} else {912visible = retval = true;913914// check if this dialog should be modal blocked BEFORE calling peer.show(),915// otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly916// generated for the dialog917if (!isModal()) {918checkShouldBeBlocked(this);919} else {920modalDialogs.add(this);921modalShow();922}923924if (toFocus != null && time != null && isFocusable() &&925isEnabled() && !isModalBlocked()) {926// keep the KeyEvents from being dispatched927// until the focus has been transfered928time.set(Toolkit.getEventQueue().getMostRecentKeyEventTime());929KeyboardFocusManager.getCurrentKeyboardFocusManager().930enqueueKeyEvents(time.get(), toFocus);931}932933// This call is required as the show() method of the Dialog class934// does not invoke the super.show(). So wried... :(935mixOnShowing();936937peer.setVisible(true); // now guaranteed never to block938if (isModalBlocked()) {939modalBlocker.toFront();940}941942setLocationByPlatform(false);943for (int i = 0; i < ownedWindowList.size(); i++) {944Window child = ownedWindowList.elementAt(i).get();945if ((child != null) && child.showWithParent) {946child.show();947child.showWithParent = false;948} // endif949} // endfor950Window.updateChildFocusableWindowState(this);951952createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,953this, parent,954HierarchyEvent.SHOWING_CHANGED,955Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));956if (componentListener != null ||957(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||958Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {959ComponentEvent e =960new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);961Toolkit.getEventQueue().postEvent(e);962}963}964}965966if (retval && (state & OPENED) == 0) {967postWindowEvent(WindowEvent.WINDOW_OPENED);968state |= OPENED;969}970971return retval;972}973974/**975* Shows or hides this {@code Dialog} depending on the value of parameter976* {@code b}.977* @param b if {@code true}, makes the {@code Dialog} visible,978* otherwise hides the {@code Dialog}.979* If the dialog and/or its owner980* are not yet displayable, both are made displayable. The981* dialog will be validated prior to being made visible.982* If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)}983* to return if it is currently blocked.984* <p>985* <b>Notes for modal dialogs</b>.986* <ul>987* <li>{@code setVisible(true)}: If the dialog is not already988* visible, this call will not return until the dialog is989* hidden by calling {@code setVisible(false)} or990* {@code dispose}.991* <li>{@code setVisible(false)}: Hides the dialog and then992* returns on {@code setVisible(true)} if it is currently blocked.993* <li>It is OK to call this method from the event dispatching994* thread because the toolkit ensures that other events are995* not blocked while this method is blocked.996* </ul>997* @see java.awt.Window#setVisible998* @see java.awt.Window#dispose999* @see java.awt.Component#isDisplayable1000* @see java.awt.Component#validate1001* @see java.awt.Dialog#isModal1002*/1003public void setVisible(boolean b) {1004super.setVisible(b);1005}10061007/**1008* Makes the {@code Dialog} visible. If the dialog and/or its owner1009* are not yet displayable, both are made displayable. The1010* dialog will be validated prior to being made visible.1011* If the dialog is already visible, this will bring the dialog1012* to the front.1013* <p>1014* If the dialog is modal and is not already visible, this call1015* will not return until the dialog is hidden by calling hide or1016* dispose. It is permissible to show modal dialogs from the event1017* dispatching thread because the toolkit will ensure that another1018* event pump runs while the one which invoked this method is blocked.1019* @see Component#hide1020* @see Component#isDisplayable1021* @see Component#validate1022* @see #isModal1023* @see Window#setVisible(boolean)1024* @deprecated As of JDK version 1.5, replaced by1025* {@link #setVisible(boolean) setVisible(boolean)}.1026*/1027@Deprecated1028public void show() {1029if (!initialized) {1030throw new IllegalStateException("The dialog component " +1031"has not been initialized properly");1032}10331034beforeFirstShow = false;1035if (!isModal()) {1036conditionalShow(null, null);1037} else {1038AppContext showAppContext = AppContext.getAppContext();10391040AtomicLong time = new AtomicLong();1041Component predictedFocusOwner = null;1042try {1043predictedFocusOwner = getMostRecentFocusOwner();1044if (conditionalShow(predictedFocusOwner, time)) {1045modalFilter = ModalEventFilter.createFilterForDialog(this);1046final Conditional cond = new Conditional() {1047@Override1048public boolean evaluate() {1049return windowClosingException == null;1050}1051};10521053// if this dialog is toolkit-modal, the filter should be added1054// to all EDTs (for all AppContexts)1055if (modalityType == ModalityType.TOOLKIT_MODAL) {1056Iterator<AppContext> it = AppContext.getAppContexts().iterator();1057while (it.hasNext()) {1058AppContext appContext = it.next();1059if (appContext == showAppContext) {1060continue;1061}1062EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);1063// it may occur that EDT for appContext hasn't been started yet, so1064// we post an empty invocation event to trigger EDT initialization1065Runnable createEDT = new Runnable() {1066public void run() {};1067};1068eventQueue.postEvent(new InvocationEvent(this, createEDT));1069EventDispatchThread edt = eventQueue.getDispatchThread();1070edt.addEventFilter(modalFilter);1071}1072}10731074modalityPushed();1075try {1076final EventQueue eventQueue = AccessController.doPrivileged(1077new PrivilegedAction<EventQueue>() {1078public EventQueue run() {1079return Toolkit.getDefaultToolkit().getSystemEventQueue();1080}1081});1082secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);1083if (!secondaryLoop.enter()) {1084secondaryLoop = null;1085}1086} finally {1087modalityPopped();1088}10891090// if this dialog is toolkit-modal, its filter must be removed1091// from all EDTs (for all AppContexts)1092if (modalityType == ModalityType.TOOLKIT_MODAL) {1093Iterator<AppContext> it = AppContext.getAppContexts().iterator();1094while (it.hasNext()) {1095AppContext appContext = it.next();1096if (appContext == showAppContext) {1097continue;1098}1099EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);1100EventDispatchThread edt = eventQueue.getDispatchThread();1101edt.removeEventFilter(modalFilter);1102}1103}11041105if (windowClosingException != null) {1106windowClosingException.fillInStackTrace();1107throw windowClosingException;1108}1109}1110} finally {1111if (predictedFocusOwner != null) {1112// Restore normal key event dispatching1113KeyboardFocusManager.getCurrentKeyboardFocusManager().1114dequeueKeyEvents(time.get(), predictedFocusOwner);1115}1116}1117}1118}11191120final void modalityPushed() {1121Toolkit tk = Toolkit.getDefaultToolkit();1122if (tk instanceof SunToolkit) {1123SunToolkit stk = (SunToolkit)tk;1124stk.notifyModalityPushed(this);1125}1126}11271128final void modalityPopped() {1129Toolkit tk = Toolkit.getDefaultToolkit();1130if (tk instanceof SunToolkit) {1131SunToolkit stk = (SunToolkit)tk;1132stk.notifyModalityPopped(this);1133}1134}11351136void interruptBlocking() {1137if (isModal()) {1138disposeImpl();1139} else if (windowClosingException != null) {1140windowClosingException.fillInStackTrace();1141windowClosingException.printStackTrace();1142windowClosingException = null;1143}1144}11451146private void hideAndDisposePreHandler() {1147isInHide = true;1148synchronized (getTreeLock()) {1149if (secondaryLoop != null) {1150modalHide();1151// dialog can be shown and then disposed before its1152// modal filter is created1153if (modalFilter != null) {1154modalFilter.disable();1155}1156modalDialogs.remove(this);1157}1158}1159}1160private void hideAndDisposeHandler() {1161if (secondaryLoop != null) {1162secondaryLoop.exit();1163secondaryLoop = null;1164}1165isInHide = false;1166}11671168/**1169* Hides the Dialog and then causes {@code show} to return if it is currently1170* blocked.1171* @see Window#show1172* @see Window#dispose1173* @see Window#setVisible(boolean)1174* @deprecated As of JDK version 1.5, replaced by1175* {@link #setVisible(boolean) setVisible(boolean)}.1176*/1177@Deprecated1178public void hide() {1179hideAndDisposePreHandler();1180super.hide();1181// fix for 5048370: if hide() is called from super.doDispose(), then1182// hideAndDisposeHandler() should not be called here as it will be called1183// at the end of doDispose()1184if (!isInDispose) {1185hideAndDisposeHandler();1186}1187}11881189/**1190* Disposes the Dialog and then causes show() to return if it is currently1191* blocked.1192*/1193void doDispose() {1194// fix for 5048370: set isInDispose flag to true to prevent calling1195// to hideAndDisposeHandler() from hide()1196isInDispose = true;1197super.doDispose();1198hideAndDisposeHandler();1199isInDispose = false;1200}12011202/**1203* {@inheritDoc}1204* <p>1205* If this dialog is modal and blocks some windows, then all of them are1206* also sent to the back to keep them below the blocking dialog.1207*1208* @see java.awt.Window#toBack1209*/1210public void toBack() {1211super.toBack();1212if (visible) {1213synchronized (getTreeLock()) {1214for (Window w : blockedWindows) {1215w.toBack_NoClientCode();1216}1217}1218}1219}12201221/**1222* Indicates whether this dialog is resizable by the user.1223* By default, all dialogs are initially resizable.1224* @return <code>true</code> if the user can resize the dialog;1225* <code>false</code> otherwise.1226* @see java.awt.Dialog#setResizable1227*/1228public boolean isResizable() {1229return resizable;1230}12311232/**1233* Sets whether this dialog is resizable by the user.1234* @param resizable <code>true</code> if the user can1235* resize this dialog; <code>false</code> otherwise.1236* @see java.awt.Dialog#isResizable1237*/1238public void setResizable(boolean resizable) {1239boolean testvalid = false;12401241synchronized (this) {1242this.resizable = resizable;1243DialogPeer peer = (DialogPeer)this.peer;1244if (peer != null) {1245peer.setResizable(resizable);1246testvalid = true;1247}1248}12491250// On some platforms, changing the resizable state affects1251// the insets of the Dialog. If we could, we'd call invalidate()1252// from the peer, but we need to guarantee that we're not holding1253// the Dialog lock when we call invalidate().1254if (testvalid) {1255invalidateIfValid();1256}1257}125812591260/**1261* Disables or enables decorations for this dialog.1262* <p>1263* This method can only be called while the dialog is not displayable. To1264* make this dialog decorated, it must be opaque and have the default shape,1265* otherwise the {@code IllegalComponentStateException} will be thrown.1266* Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link1267* Window#setBackground} for details1268*1269* @param undecorated {@code true} if no dialog decorations are to be1270* enabled; {@code false} if dialog decorations are to be enabled1271*1272* @throws IllegalComponentStateException if the dialog is displayable1273* @throws IllegalComponentStateException if {@code undecorated} is1274* {@code false}, and this dialog does not have the default shape1275* @throws IllegalComponentStateException if {@code undecorated} is1276* {@code false}, and this dialog opacity is less than {@code 1.0f}1277* @throws IllegalComponentStateException if {@code undecorated} is1278* {@code false}, and the alpha value of this dialog background1279* color is less than {@code 1.0f}1280*1281* @see #isUndecorated1282* @see Component#isDisplayable1283* @see Window#getShape1284* @see Window#getOpacity1285* @see Window#getBackground1286*1287* @since 1.41288*/1289public void setUndecorated(boolean undecorated) {1290/* Make sure we don't run in the middle of peer creation.*/1291synchronized (getTreeLock()) {1292if (isDisplayable()) {1293throw new IllegalComponentStateException("The dialog is displayable.");1294}1295if (!undecorated) {1296if (getOpacity() < 1.0f) {1297throw new IllegalComponentStateException("The dialog is not opaque");1298}1299if (getShape() != null) {1300throw new IllegalComponentStateException("The dialog does not have a default shape");1301}1302Color bg = getBackground();1303if ((bg != null) && (bg.getAlpha() < 255)) {1304throw new IllegalComponentStateException("The dialog background color is not opaque");1305}1306}1307this.undecorated = undecorated;1308}1309}13101311/**1312* Indicates whether this dialog is undecorated.1313* By default, all dialogs are initially decorated.1314* @return <code>true</code> if dialog is undecorated;1315* <code>false</code> otherwise.1316* @see java.awt.Dialog#setUndecorated1317* @since 1.41318*/1319public boolean isUndecorated() {1320return undecorated;1321}13221323/**1324* {@inheritDoc}1325*/1326@Override1327public void setOpacity(float opacity) {1328synchronized (getTreeLock()) {1329if ((opacity < 1.0f) && !isUndecorated()) {1330throw new IllegalComponentStateException("The dialog is decorated");1331}1332super.setOpacity(opacity);1333}1334}13351336/**1337* {@inheritDoc}1338*/1339@Override1340public void setShape(Shape shape) {1341synchronized (getTreeLock()) {1342if ((shape != null) && !isUndecorated()) {1343throw new IllegalComponentStateException("The dialog is decorated");1344}1345super.setShape(shape);1346}1347}13481349/**1350* {@inheritDoc}1351*/1352@Override1353public void setBackground(Color bgColor) {1354synchronized (getTreeLock()) {1355if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {1356throw new IllegalComponentStateException("The dialog is decorated");1357}1358super.setBackground(bgColor);1359}1360}13611362/**1363* Returns a string representing the state of this dialog. This1364* method is intended to be used only for debugging purposes, and the1365* content and format of the returned string may vary between1366* implementations. The returned string may be empty but may not be1367* <code>null</code>.1368*1369* @return the parameter string of this dialog window.1370*/1371protected String paramString() {1372String str = super.paramString() + "," + modalityType;1373if (title != null) {1374str += ",title=" + title;1375}1376return str;1377}13781379/**1380* Initialize JNI field and method IDs1381*/1382private static native void initIDs();13831384/*1385* --- Modality support ---1386*1387*/13881389/*1390* This method is called only for modal dialogs.1391*1392* Goes through the list of all visible top-level windows and1393* divide them into three distinct groups: blockers of this dialog,1394* blocked by this dialog and all others. Then blocks this dialog1395* by first met dialog from the first group (if any) and blocks all1396* the windows from the second group.1397*/1398void modalShow() {1399// find all the dialogs that block this one1400IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>();1401for (Dialog d : modalDialogs) {1402if (d.shouldBlock(this)) {1403Window w = d;1404while ((w != null) && (w != this)) {1405w = w.getOwner_NoClientCode();1406}1407if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {1408blockers.add(d);1409}1410}1411}14121413// add all blockers' blockers to blockers :)1414for (int i = 0; i < blockers.size(); i++) {1415Dialog blocker = blockers.get(i);1416if (blocker.isModalBlocked()) {1417Dialog blockerBlocker = blocker.getModalBlocker();1418if (!blockers.contains(blockerBlocker)) {1419blockers.add(i + 1, blockerBlocker);1420}1421}1422}14231424if (blockers.size() > 0) {1425blockers.get(0).blockWindow(this);1426}14271428// find all windows from blockers' hierarchies1429IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers);1430int k = 0;1431while (k < blockersHierarchies.size()) {1432Window w = blockersHierarchies.get(k);1433Window[] ownedWindows = w.getOwnedWindows_NoClientCode();1434for (Window win : ownedWindows) {1435blockersHierarchies.add(win);1436}1437k++;1438}14391440java.util.List<Window> toBlock = new IdentityLinkedList<Window>();1441// block all windows from scope of blocking except from blockers' hierarchies1442IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows();1443for (Window w : unblockedWindows) {1444if (shouldBlock(w) && !blockersHierarchies.contains(w)) {1445if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {1446Dialog wd = (Dialog)w;1447if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) {1448continue;1449}1450}1451toBlock.add(w);1452}1453}1454blockWindows(toBlock);14551456if (!isModalBlocked()) {1457updateChildrenBlocking();1458}1459}14601461/*1462* This method is called only for modal dialogs.1463*1464* Unblocks all the windows blocked by this modal dialog. After1465* each of them has been unblocked, it is checked to be blocked by1466* any other modal dialogs.1467*/1468void modalHide() {1469// we should unblock all the windows first...1470IdentityArrayList<Window> save = new IdentityArrayList<Window>();1471int blockedWindowsCount = blockedWindows.size();1472for (int i = 0; i < blockedWindowsCount; i++) {1473Window w = blockedWindows.get(0);1474save.add(w);1475unblockWindow(w); // also removes w from blockedWindows1476}1477// ... and only after that check if they should be blocked1478// by another dialogs1479for (int i = 0; i < blockedWindowsCount; i++) {1480Window w = save.get(i);1481if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {1482Dialog d = (Dialog)w;1483d.modalShow();1484} else {1485checkShouldBeBlocked(w);1486}1487}1488}14891490/*1491* Returns whether the given top-level window should be blocked by1492* this dialog. Note, that the given window can be also a modal dialog1493* and it should block this dialog, but this method do not take such1494* situations into consideration (such checks are performed in the1495* modalShow() and modalHide() methods).1496*1497* This method should be called on the getTreeLock() lock.1498*/1499boolean shouldBlock(Window w) {1500if (!isVisible_NoClientCode() ||1501(!w.isVisible_NoClientCode() && !w.isInShow) ||1502isInHide ||1503(w == this) ||1504!isModal_NoClientCode())1505{1506return false;1507}1508if ((w instanceof Dialog) && ((Dialog)w).isInHide) {1509return false;1510}1511// check if w is from children hierarchy1512// fix for 6271546: we should also take into consideration child hierarchies1513// of this dialog's blockers1514Window blockerToCheck = this;1515while (blockerToCheck != null) {1516Component c = w;1517while ((c != null) && (c != blockerToCheck)) {1518c = c.getParent_NoClientCode();1519}1520if (c == blockerToCheck) {1521return false;1522}1523blockerToCheck = blockerToCheck.getModalBlocker();1524}1525switch (modalityType) {1526case MODELESS:1527return false;1528case DOCUMENT_MODAL:1529if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) {1530// application- and toolkit-excluded windows are not blocked by1531// document-modal dialogs from outside their children hierarchy1532Component c = this;1533while ((c != null) && (c != w)) {1534c = c.getParent_NoClientCode();1535}1536return c == w;1537} else {1538return getDocumentRoot() == w.getDocumentRoot();1539}1540case APPLICATION_MODAL:1541return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) &&1542(appContext == w.appContext);1543case TOOLKIT_MODAL:1544return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE);1545}15461547return false;1548}15491550/*1551* Adds the given top-level window to the list of blocked1552* windows for this dialog and marks it as modal blocked.1553* If the window is already blocked by some modal dialog,1554* does nothing.1555*/1556void blockWindow(Window w) {1557if (!w.isModalBlocked()) {1558w.setModalBlocked(this, true, true);1559blockedWindows.add(w);1560}1561}15621563void blockWindows(java.util.List<Window> toBlock) {1564DialogPeer dpeer = (DialogPeer)peer;1565if (dpeer == null) {1566return;1567}1568Iterator<Window> it = toBlock.iterator();1569while (it.hasNext()) {1570Window w = it.next();1571if (!w.isModalBlocked()) {1572w.setModalBlocked(this, true, false);1573} else {1574it.remove();1575}1576}1577dpeer.blockWindows(toBlock);1578blockedWindows.addAll(toBlock);1579}15801581/*1582* Removes the given top-level window from the list of blocked1583* windows for this dialog and marks it as unblocked. If the1584* window is not modal blocked, does nothing.1585*/1586void unblockWindow(Window w) {1587if (w.isModalBlocked() && blockedWindows.contains(w)) {1588blockedWindows.remove(w);1589w.setModalBlocked(this, false, true);1590}1591}15921593/*1594* Checks if any other modal dialog D blocks the given window.1595* If such D exists, mark the window as blocked by D.1596*/1597static void checkShouldBeBlocked(Window w) {1598synchronized (w.getTreeLock()) {1599for (int i = 0; i < modalDialogs.size(); i++) {1600Dialog modalDialog = modalDialogs.get(i);1601if (modalDialog.shouldBlock(w)) {1602modalDialog.blockWindow(w);1603break;1604}1605}1606}1607}16081609private void checkModalityPermission(ModalityType mt) {1610if (mt == ModalityType.TOOLKIT_MODAL) {1611SecurityManager sm = System.getSecurityManager();1612if (sm != null) {1613sm.checkPermission(1614SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION1615);1616}1617}1618}16191620private void readObject(ObjectInputStream s)1621throws ClassNotFoundException, IOException, HeadlessException1622{1623GraphicsEnvironment.checkHeadless();16241625java.io.ObjectInputStream.GetField fields =1626s.readFields();16271628ModalityType localModalityType = (ModalityType)fields.get("modalityType", null);16291630try {1631checkModalityPermission(localModalityType);1632} catch (AccessControlException ace) {1633localModalityType = DEFAULT_MODALITY_TYPE;1634}16351636// in 1.5 or earlier modalityType was absent, so use "modal" instead1637if (localModalityType == null) {1638this.modal = fields.get("modal", false);1639setModal(modal);1640} else {1641this.modalityType = localModalityType;1642}16431644this.resizable = fields.get("resizable", true);1645this.undecorated = fields.get("undecorated", false);1646this.title = (String)fields.get("title", "");16471648blockedWindows = new IdentityArrayList<>();16491650SunToolkit.checkAndSetPolicy(this);16511652initialized = true;16531654}16551656/*1657* --- Accessibility Support ---1658*1659*/16601661/**1662* Gets the AccessibleContext associated with this Dialog.1663* For dialogs, the AccessibleContext takes the form of an1664* AccessibleAWTDialog.1665* A new AccessibleAWTDialog instance is created if necessary.1666*1667* @return an AccessibleAWTDialog that serves as the1668* AccessibleContext of this Dialog1669* @since 1.31670*/1671public AccessibleContext getAccessibleContext() {1672if (accessibleContext == null) {1673accessibleContext = new AccessibleAWTDialog();1674}1675return accessibleContext;1676}16771678/**1679* This class implements accessibility support for the1680* <code>Dialog</code> class. It provides an implementation of the1681* Java Accessibility API appropriate to dialog user-interface elements.1682* @since 1.31683*/1684protected class AccessibleAWTDialog extends AccessibleAWTWindow1685{1686/*1687* JDK 1.3 serialVersionUID1688*/1689private static final long serialVersionUID = 4837230331833941201L;16901691/**1692* Get the role of this object.1693*1694* @return an instance of AccessibleRole describing the role of the1695* object1696* @see AccessibleRole1697*/1698public AccessibleRole getAccessibleRole() {1699return AccessibleRole.DIALOG;1700}17011702/**1703* Get the state of this object.1704*1705* @return an instance of AccessibleStateSet containing the current1706* state set of the object1707* @see AccessibleState1708*/1709public AccessibleStateSet getAccessibleStateSet() {1710AccessibleStateSet states = super.getAccessibleStateSet();1711if (getFocusOwner() != null) {1712states.add(AccessibleState.ACTIVE);1713}1714if (isModal()) {1715states.add(AccessibleState.MODAL);1716}1717if (isResizable()) {1718states.add(AccessibleState.RESIZABLE);1719}1720return states;1721}17221723} // inner class AccessibleAWTDialog1724}172517261727