Path: blob/master/src/java.desktop/share/classes/java/awt/Dialog.java
41152 views
/*1* Copyright (c) 1995, 2021, 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*/2425package java.awt;2627import java.awt.event.ComponentEvent;28import java.awt.event.HierarchyEvent;29import java.awt.event.InvocationEvent;30import java.awt.event.WindowEvent;31import java.awt.peer.DialogPeer;32import java.io.IOException;33import java.io.ObjectInputStream;34import java.io.Serial;35import java.security.AccessControlException;36import java.security.AccessController;37import java.security.PrivilegedAction;38import java.util.Iterator;39import java.util.concurrent.atomic.AtomicLong;4041import javax.accessibility.AccessibleContext;42import javax.accessibility.AccessibleRole;43import javax.accessibility.AccessibleState;44import javax.accessibility.AccessibleStateSet;4546import sun.awt.AWTPermissions;47import sun.awt.AppContext;48import sun.awt.SunToolkit;49import sun.awt.util.IdentityArrayList;50import sun.awt.util.IdentityLinkedList;5152/**53* A Dialog is a top-level window with a title and a border54* that is typically used to take some form of input from the user.55*56* The size of the dialog includes any area designated for the57* border. The dimensions of the border area can be obtained58* using the {@code getInsets} method, however, since59* these dimensions are platform-dependent, a valid insets60* value cannot be obtained until the dialog is made displayable61* by either calling {@code pack} or {@code show}.62* Since the border area is included in the overall size of the63* dialog, the border effectively obscures a portion of the dialog,64* constraining the area available for rendering and/or displaying65* subcomponents to the rectangle which has an upper-left corner66* location of {@code (insets.left, insets.top)}, and has a size of67* {@code width - (insets.left + insets.right)} by68* {@code height - (insets.top + insets.bottom)}.69* <p>70* The default layout for a dialog is {@code BorderLayout}.71* <p>72* A dialog may have its native decorations (i.e. Frame & Titlebar) turned off73* with {@code setUndecorated}. This can only be done while the dialog74* is not {@link Component#isDisplayable() displayable}.75* <p>76* A dialog may have another window as its owner when it's constructed. When77* the owner window of a visible dialog is minimized, the dialog will78* automatically be hidden from the user. When the owner window is subsequently79* restored, the dialog is made visible to the user again.80* <p>81* In a multi-screen environment, you can create a {@code Dialog}82* on a different screen device than its owner. See {@link java.awt.Frame} for83* more information.84* <p>85* A dialog can be either modeless (the default) or modal. A modal86* dialog is one which blocks input to some other top-level windows87* in the application, except for any windows created with the dialog88* as their owner. See <a href="doc-files/Modality.html">AWT Modality</a>89* specification for details.90* <p>91* Dialogs are capable of generating the following92* {@code WindowEvents}:93* {@code WindowOpened}, {@code WindowClosing},94* {@code WindowClosed}, {@code WindowActivated},95* {@code WindowDeactivated}, {@code WindowGainedFocus},96* {@code WindowLostFocus}.97*98* @see WindowEvent99* @see Window#addWindowListener100*101* @author Sami Shaio102* @author Arthur van Hoff103* @since 1.0104*/105public class Dialog extends Window {106107static {108/* ensure that the necessary native libraries are loaded */109Toolkit.loadLibraries();110if (!GraphicsEnvironment.isHeadless()) {111initIDs();112}113}114115/**116* A dialog's resizable property. Will be true117* if the Dialog is to be resizable, otherwise118* it will be false.119*120* @serial121* @see #setResizable(boolean)122*/123boolean resizable = true;124125126/**127* This field indicates whether the dialog is undecorated.128* This property can only be changed while the dialog is not displayable.129* {@code undecorated} will be true if the dialog is130* undecorated, otherwise it will be false.131*132* @serial133* @see #setUndecorated(boolean)134* @see #isUndecorated()135* @see Component#isDisplayable()136* @since 1.4137*/138boolean undecorated = false;139140private transient boolean initialized = false;141142/**143* Modal dialogs block all input to some top-level windows.144* Whether a particular window is blocked depends on dialog's type145* of modality; this is called the "scope of blocking". The146* {@code ModalityType} enum specifies modal types and their147* associated scopes.148*149* @see Dialog#getModalityType150* @see Dialog#setModalityType151* @see Toolkit#isModalityTypeSupported152*153* @since 1.6154*/155public static enum ModalityType {156/**157* {@code MODELESS} dialog doesn't block any top-level windows.158*/159MODELESS,160/**161* A {@code DOCUMENT_MODAL} dialog blocks input to all top-level windows162* from the same document except those from its own child hierarchy.163* A document is a top-level window without an owner. It may contain child164* windows that, together with the top-level window are treated as a single165* solid document. Since every top-level window must belong to some166* document, its root can be found as the top-nearest window without an owner.167*/168DOCUMENT_MODAL,169/**170* An {@code APPLICATION_MODAL} dialog blocks all top-level windows171* from the same Java application except those from its own child hierarchy.172* If there are several applets launched in a browser, they can be173* treated either as separate applications or a single one. This behavior174* is implementation-dependent.175*/176APPLICATION_MODAL,177/**178* A {@code TOOLKIT_MODAL} dialog blocks all top-level windows run179* from the same toolkit except those from its own child hierarchy. If there180* are several applets launched in a browser, all of them run with the same181* toolkit; thus, a toolkit-modal dialog displayed by an applet may affect182* other applets and all windows of the browser instance which embeds the183* Java runtime environment for this toolkit.184* Special {@code AWTPermission} "toolkitModality" must be granted to use185* toolkit-modal dialogs. If a {@code TOOLKIT_MODAL} dialog is being created186* and this permission is not granted, a {@code SecurityException} will be187* thrown, and no dialog will be created. If a modality type is being changed188* to {@code TOOLKIT_MODAL} and this permission is not granted, a189* {@code SecurityException} will be thrown, and the modality type will190* be left unchanged.191*/192TOOLKIT_MODAL193};194195/**196* Default modality type for modal dialogs. The default modality type is197* {@code APPLICATION_MODAL}. Calling the oldstyle {@code setModal(true)}198* is equal to {@code setModalityType(DEFAULT_MODALITY_TYPE)}.199*200* @see java.awt.Dialog.ModalityType201* @see java.awt.Dialog#setModal202*203* @since 1.6204*/205public static final ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL;206207/**208* True if this dialog is modal, false is the dialog is modeless.209* A modal dialog blocks user input to some application top-level210* windows. This field is kept only for backwards compatibility. Use the211* {@link Dialog.ModalityType ModalityType} enum instead.212*213* @serial214*215* @see #isModal216* @see #setModal217* @see #getModalityType218* @see #setModalityType219* @see ModalityType220* @see ModalityType#MODELESS221* @see #DEFAULT_MODALITY_TYPE222*/223boolean modal;224225/**226* Modality type of this dialog. If the dialog's modality type is not227* {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all228* user input to some application top-level windows.229*230* @serial231*232* @see ModalityType233* @see #getModalityType234* @see #setModalityType235*236* @since 1.6237*/238ModalityType modalityType;239240/**241* Any top-level window can be marked not to be blocked by modal242* dialogs. This is called "modal exclusion". This enum specifies243* the possible modal exclusion types.244*245* @see Window#getModalExclusionType246* @see Window#setModalExclusionType247* @see Toolkit#isModalExclusionTypeSupported248*249* @since 1.6250*/251public static enum ModalExclusionType {252/**253* No modal exclusion.254*/255NO_EXCLUDE,256/**257* {@code APPLICATION_EXCLUDE} indicates that a top-level window258* won't be blocked by any application-modal dialogs. Also, it isn't259* blocked by document-modal dialogs from outside of its child hierarchy.260*/261APPLICATION_EXCLUDE,262/**263* {@code TOOLKIT_EXCLUDE} indicates that a top-level window264* won't be blocked by application-modal or toolkit-modal dialogs. Also,265* it isn't blocked by document-modal dialogs from outside of its266* child hierarchy.267* The "toolkitModality" {@code AWTPermission} must be granted268* for this exclusion. If an exclusion property is being changed to269* {@code TOOLKIT_EXCLUDE} and this permission is not granted, a270* {@code SecurityException} will be thrown, and the exclusion271* property will be left unchanged.272*/273TOOLKIT_EXCLUDE274};275276/* operations with this list should be synchronized on tree lock*/277static transient IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>();278279transient IdentityArrayList<Window> blockedWindows = new IdentityArrayList<Window>();280281/**282* Specifies the title of the Dialog.283* This field can be null.284*285* @serial286* @see #getTitle()287* @see #setTitle(String)288*/289String title;290291private transient ModalEventFilter modalFilter;292private transient volatile SecondaryLoop secondaryLoop;293294/*295* Indicates that this dialog is being hidden. This flag is set to true at296* the beginning of hide() and to false at the end of hide().297*298* @see #hide()299* @see #hideAndDisposePreHandler()300* @see #hideAndDisposeHandler()301* @see #shouldBlock()302*/303transient volatile boolean isInHide = false;304305/*306* Indicates that this dialog is being disposed. This flag is set to true at307* the beginning of doDispose() and to false at the end of doDispose().308*309* @see #hide()310* @see #hideAndDisposePreHandler()311* @see #hideAndDisposeHandler()312* @see #doDispose()313*/314transient volatile boolean isInDispose = false;315316private static final String base = "dialog";317private static int nameCounter = 0;318319/**320* Use serialVersionUID from JDK 1.1 for interoperability.321*/322@Serial323private static final long serialVersionUID = 5920926903803293709L;324325/**326* Constructs an initially invisible, modeless {@code Dialog} with327* the specified owner {@code Frame} and an empty title.328*329* @param owner the owner of the dialog or {@code null} if330* this dialog has no owner331* @exception java.lang.IllegalArgumentException if the {@code owner}'s332* {@code GraphicsConfiguration} is not from a screen device333* @exception HeadlessException when334* {@code GraphicsEnvironment.isHeadless()} returns {@code true}335*336* @see java.awt.GraphicsEnvironment#isHeadless337* @see Component#setSize338* @see Component#setVisible339*/340public Dialog(Frame owner) {341this(owner, "", false);342}343344/**345* Constructs an initially invisible {@code Dialog} with the specified346* owner {@code Frame} and modality and an empty title.347*348* @param owner the owner of the dialog or {@code null} if349* this dialog has no owner350* @param modal specifies whether dialog blocks user input to other top-level351* windows when shown. If {@code false}, the dialog is {@code MODELESS};352* if {@code true}, the modality type property is set to353* {@code DEFAULT_MODALITY_TYPE}354* @exception java.lang.IllegalArgumentException if the {@code owner}'s355* {@code GraphicsConfiguration} is not from a screen device356* @exception HeadlessException when357* {@code GraphicsEnvironment.isHeadless()} returns {@code true}358*359* @see java.awt.Dialog.ModalityType360* @see java.awt.Dialog.ModalityType#MODELESS361* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE362* @see java.awt.Dialog#setModal363* @see java.awt.Dialog#setModalityType364* @see java.awt.GraphicsEnvironment#isHeadless365*/366public Dialog(Frame owner, boolean modal) {367this(owner, "", modal);368}369370/**371* Constructs an initially invisible, modeless {@code Dialog} with372* the specified owner {@code Frame} and title.373*374* @param owner the owner of the dialog or {@code null} if375* this dialog has no owner376* @param title the title of the dialog or {@code null} if this dialog377* has no title378* @exception IllegalArgumentException if the {@code owner}'s379* {@code GraphicsConfiguration} is not from a screen device380* @exception HeadlessException when381* {@code GraphicsEnvironment.isHeadless()} returns {@code true}382*383* @see java.awt.GraphicsEnvironment#isHeadless384* @see Component#setSize385* @see Component#setVisible386*/387public Dialog(Frame owner, String title) {388this(owner, title, false);389}390391/**392* Constructs an initially invisible {@code Dialog} with the393* specified owner {@code Frame}, title and modality.394*395* @param owner the owner of the dialog or {@code null} if396* this dialog has no owner397* @param title the title of the dialog or {@code null} if this dialog398* has no title399* @param modal specifies whether dialog blocks user input to other top-level400* windows when shown. If {@code false}, the dialog is {@code MODELESS};401* if {@code true}, the modality type property is set to402* {@code DEFAULT_MODALITY_TYPE}403* @exception java.lang.IllegalArgumentException if the {@code owner}'s404* {@code GraphicsConfiguration} is not from a screen device405* @exception HeadlessException when406* {@code GraphicsEnvironment.isHeadless()} returns {@code true}407*408* @see java.awt.Dialog.ModalityType409* @see java.awt.Dialog.ModalityType#MODELESS410* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE411* @see java.awt.Dialog#setModal412* @see java.awt.Dialog#setModalityType413* @see java.awt.GraphicsEnvironment#isHeadless414* @see Component#setSize415* @see Component#setVisible416*/417public Dialog(Frame owner, String title, boolean modal) {418this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);419}420421/**422* Constructs an initially invisible {@code Dialog} with the specified owner423* {@code Frame}, title, modality, and {@code GraphicsConfiguration}.424* @param owner the owner of the dialog or {@code null} if this dialog425* has no owner426* @param title the title of the dialog or {@code null} if this dialog427* has no title428* @param modal specifies whether dialog blocks user input to other top-level429* windows when shown. If {@code false}, the dialog is {@code MODELESS};430* if {@code true}, the modality type property is set to431* {@code DEFAULT_MODALITY_TYPE}432* @param gc the {@code GraphicsConfiguration} of the target screen device;433* if {@code null}, the default system {@code GraphicsConfiguration}434* is assumed435* @exception java.lang.IllegalArgumentException if {@code gc}436* is not from a screen device437* @exception HeadlessException when438* {@code GraphicsEnvironment.isHeadless()} returns {@code true}439*440* @see java.awt.Dialog.ModalityType441* @see java.awt.Dialog.ModalityType#MODELESS442* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE443* @see java.awt.Dialog#setModal444* @see java.awt.Dialog#setModalityType445* @see java.awt.GraphicsEnvironment#isHeadless446* @see Component#setSize447* @see Component#setVisible448* @since 1.4449*/450public Dialog(Frame owner, String title, boolean modal,451GraphicsConfiguration gc) {452this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);453}454455/**456* Constructs an initially invisible, modeless {@code Dialog} with457* the specified owner {@code Dialog} and an empty title.458*459* @param owner the owner of the dialog or {@code null} if this460* dialog has no owner461* @exception java.lang.IllegalArgumentException if the {@code owner}'s462* {@code GraphicsConfiguration} is not from a screen device463* @exception HeadlessException when464* {@code GraphicsEnvironment.isHeadless()} returns {@code true}465* @see java.awt.GraphicsEnvironment#isHeadless466* @since 1.2467*/468public Dialog(Dialog owner) {469this(owner, "", false);470}471472/**473* Constructs an initially invisible, modeless {@code Dialog}474* with the specified owner {@code Dialog} and title.475*476* @param owner the owner of the dialog or {@code null} if this477* has no owner478* @param title the title of the dialog or {@code null} if this dialog479* has no title480* @exception java.lang.IllegalArgumentException if the {@code owner}'s481* {@code GraphicsConfiguration} is not from a screen device482* @exception HeadlessException when483* {@code GraphicsEnvironment.isHeadless()} returns {@code true}484*485* @see java.awt.GraphicsEnvironment#isHeadless486* @since 1.2487*/488public Dialog(Dialog owner, String title) {489this(owner, title, false);490}491492/**493* Constructs an initially invisible {@code Dialog} with the494* specified owner {@code Dialog}, title, and modality.495*496* @param owner the owner of the dialog or {@code null} if this497* dialog has no owner498* @param title the title of the dialog or {@code null} if this499* dialog has no title500* @param modal specifies whether dialog blocks user input to other top-level501* windows when shown. If {@code false}, the dialog is {@code MODELESS};502* if {@code true}, the modality type property is set to503* {@code DEFAULT_MODALITY_TYPE}504* @exception IllegalArgumentException if the {@code owner}'s505* {@code GraphicsConfiguration} is not from a screen device506* @exception HeadlessException when507* {@code GraphicsEnvironment.isHeadless()} returns {@code true}508*509* @see java.awt.Dialog.ModalityType510* @see java.awt.Dialog.ModalityType#MODELESS511* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE512* @see java.awt.Dialog#setModal513* @see java.awt.Dialog#setModalityType514* @see java.awt.GraphicsEnvironment#isHeadless515*516* @since 1.2517*/518public Dialog(Dialog owner, String title, boolean modal) {519this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);520}521522/**523* Constructs an initially invisible {@code Dialog} with the524* specified owner {@code Dialog}, title, modality and525* {@code GraphicsConfiguration}.526*527* @param owner the owner of the dialog or {@code null} if this528* dialog has no owner529* @param title the title of the dialog or {@code null} if this530* dialog has no title531* @param modal specifies whether dialog blocks user input to other top-level532* windows when shown. If {@code false}, the dialog is {@code MODELESS};533* if {@code true}, the modality type property is set to534* {@code DEFAULT_MODALITY_TYPE}535* @param gc the {@code GraphicsConfiguration} of the target screen device;536* if {@code null}, the default system {@code GraphicsConfiguration}537* is assumed538* @exception java.lang.IllegalArgumentException if {@code gc}539* is not from a screen device540* @exception HeadlessException when541* {@code GraphicsEnvironment.isHeadless()} returns {@code true}542*543* @see java.awt.Dialog.ModalityType544* @see java.awt.Dialog.ModalityType#MODELESS545* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE546* @see java.awt.Dialog#setModal547* @see java.awt.Dialog#setModalityType548* @see java.awt.GraphicsEnvironment#isHeadless549* @see Component#setSize550* @see Component#setVisible551*552* @since 1.4553*/554public Dialog(Dialog owner, String title, boolean modal,555GraphicsConfiguration gc) {556this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);557}558559/**560* Constructs an initially invisible, modeless {@code Dialog} with the561* specified owner {@code Window} and an empty title.562*563* @param owner the owner of the dialog. The owner must be an instance of564* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any565* of their descendants or {@code null}566*567* @exception java.lang.IllegalArgumentException if the {@code owner}568* is not an instance of {@link java.awt.Dialog Dialog} or {@link569* java.awt.Frame Frame}570* @exception java.lang.IllegalArgumentException if the {@code owner}'s571* {@code GraphicsConfiguration} is not from a screen device572* @exception HeadlessException when573* {@code GraphicsEnvironment.isHeadless()} returns {@code true}574*575* @see java.awt.GraphicsEnvironment#isHeadless576*577* @since 1.6578*/579public Dialog(Window owner) {580this(owner, "", ModalityType.MODELESS);581}582583/**584* Constructs an initially invisible, modeless {@code Dialog} with585* the specified owner {@code Window} and title.586*587* @param owner the owner of the dialog. The owner must be an instance of588* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any589* of their descendants or {@code null}590* @param title the title of the dialog or {@code null} if this dialog591* has no title592*593* @exception java.lang.IllegalArgumentException if the {@code owner}594* is not an instance of {@link java.awt.Dialog Dialog} or {@link595* java.awt.Frame Frame}596* @exception java.lang.IllegalArgumentException if the {@code owner}'s597* {@code GraphicsConfiguration} is not from a screen device598* @exception HeadlessException when599* {@code GraphicsEnvironment.isHeadless()} returns {@code true}600*601* @see java.awt.GraphicsEnvironment#isHeadless602*603* @since 1.6604*/605public Dialog(Window owner, String title) {606this(owner, title, ModalityType.MODELESS);607}608609/**610* Constructs an initially invisible {@code Dialog} with the611* specified owner {@code Window} and modality and an empty title.612*613* @param owner the owner of the dialog. The owner must be an instance of614* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any615* of their descendants or {@code null}616* @param modalityType specifies whether dialog blocks input to other617* windows when shown. {@code null} value and unsupported modality618* types are equivalent to {@code MODELESS}619*620* @exception java.lang.IllegalArgumentException if the {@code owner}621* is not an instance of {@link java.awt.Dialog Dialog} or {@link622* java.awt.Frame Frame}623* @exception java.lang.IllegalArgumentException if the {@code owner}'s624* {@code GraphicsConfiguration} is not from a screen device625* @exception HeadlessException when626* {@code GraphicsEnvironment.isHeadless()} returns {@code true}627* @exception SecurityException if the calling thread does not have permission628* to create modal dialogs with the given {@code modalityType}629*630* @see java.awt.Dialog.ModalityType631* @see java.awt.Dialog#setModal632* @see java.awt.Dialog#setModalityType633* @see java.awt.GraphicsEnvironment#isHeadless634* @see java.awt.Toolkit#isModalityTypeSupported635*636* @since 1.6637*/638public Dialog(Window owner, ModalityType modalityType) {639this(owner, "", modalityType);640}641642/**643* Constructs an initially invisible {@code Dialog} with the644* specified owner {@code Window}, title and modality.645*646* @param owner the owner of the dialog. The owner must be an instance of647* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any648* of their descendants or {@code null}649* @param title the title of the dialog or {@code null} if this dialog650* has no title651* @param modalityType specifies whether dialog blocks input to other652* windows when shown. {@code null} value and unsupported modality653* types are equivalent to {@code MODELESS}654*655* @exception java.lang.IllegalArgumentException if the {@code owner}656* is not an instance of {@link java.awt.Dialog Dialog} or {@link657* java.awt.Frame Frame}658* @exception java.lang.IllegalArgumentException if the {@code owner}'s659* {@code GraphicsConfiguration} is not from a screen device660* @exception HeadlessException when661* {@code GraphicsEnvironment.isHeadless()} returns {@code true}662* @exception SecurityException if the calling thread does not have permission663* to create modal dialogs with the given {@code modalityType}664*665* @see java.awt.Dialog.ModalityType666* @see java.awt.Dialog#setModal667* @see java.awt.Dialog#setModalityType668* @see java.awt.GraphicsEnvironment#isHeadless669* @see java.awt.Toolkit#isModalityTypeSupported670*671* @since 1.6672*/673public Dialog(Window owner, String title, ModalityType modalityType) {674super(owner);675676if ((owner != null) &&677!(owner instanceof Frame) &&678!(owner instanceof Dialog))679{680throw new IllegalArgumentException("Wrong parent window");681}682683this.title = title;684setModalityType(modalityType);685SunToolkit.checkAndSetPolicy(this);686initialized = true;687}688689/**690* Constructs an initially invisible {@code Dialog} with the691* specified owner {@code Window}, title, modality and692* {@code GraphicsConfiguration}.693*694* @param owner the owner of the dialog. The owner must be an instance of695* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any696* of their descendants or {@code null}697* @param title the title of the dialog or {@code null} if this dialog698* has no title699* @param modalityType specifies whether dialog blocks input to other700* windows when shown. {@code null} value and unsupported modality701* types are equivalent to {@code MODELESS}702* @param gc the {@code GraphicsConfiguration} of the target screen device;703* if {@code null}, the default system {@code GraphicsConfiguration}704* is assumed705*706* @exception java.lang.IllegalArgumentException if the {@code owner}707* is not an instance of {@link java.awt.Dialog Dialog} or {@link708* java.awt.Frame Frame}709* @exception java.lang.IllegalArgumentException if {@code gc}710* is not from a screen device711* @exception HeadlessException when712* {@code GraphicsEnvironment.isHeadless()} returns {@code true}713* @exception SecurityException if the calling thread does not have permission714* to create modal dialogs with the given {@code modalityType}715*716* @see java.awt.Dialog.ModalityType717* @see java.awt.Dialog#setModal718* @see java.awt.Dialog#setModalityType719* @see java.awt.GraphicsEnvironment#isHeadless720* @see java.awt.Toolkit#isModalityTypeSupported721*722* @since 1.6723*/724public Dialog(Window owner, String title, ModalityType modalityType,725GraphicsConfiguration gc) {726super(owner, gc);727728if ((owner != null) &&729!(owner instanceof Frame) &&730!(owner instanceof Dialog))731{732throw new IllegalArgumentException("wrong owner window");733}734735this.title = title;736setModalityType(modalityType);737SunToolkit.checkAndSetPolicy(this);738initialized = true;739}740741/**742* Construct a name for this component. Called by getName() when the743* name is null.744*/745String constructComponentName() {746synchronized (Dialog.class) {747return base + nameCounter++;748}749}750751/**752* Makes this Dialog displayable by connecting it to753* a native screen resource. Making a dialog displayable will754* cause any of its children to be made displayable.755* This method is called internally by the toolkit and should756* not be called directly by programs.757* @see Component#isDisplayable758* @see #removeNotify759*/760public void addNotify() {761synchronized (getTreeLock()) {762if (parent != null && parent.peer == null) {763parent.addNotify();764}765766if (peer == null) {767peer = getComponentFactory().createDialog(this);768}769super.addNotify();770}771}772773/**774* Indicates whether the dialog is modal.775* <p>776* This method is obsolete and is kept for backwards compatibility only.777* Use {@link #getModalityType getModalityType()} instead.778*779* @return {@code true} if this dialog window is modal;780* {@code false} otherwise781*782* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE783* @see java.awt.Dialog.ModalityType#MODELESS784* @see java.awt.Dialog#setModal785* @see java.awt.Dialog#getModalityType786* @see java.awt.Dialog#setModalityType787*/788public boolean isModal() {789return isModal_NoClientCode();790}791final boolean isModal_NoClientCode() {792return modalityType != ModalityType.MODELESS;793}794795/**796* Specifies whether this dialog should be modal.797* <p>798* This method is obsolete and is kept for backwards compatibility only.799* Use {@link #setModalityType setModalityType()} instead.800* <p>801* Note: changing modality of the visible dialog may have no effect802* until it is hidden and then shown again.803*804* @param modal specifies whether dialog blocks input to other windows805* when shown; calling to {@code setModal(true)} is equivalent to806* {@code setModalityType(Dialog.DEFAULT_MODALITY_TYPE)}, and807* calling to {@code setModal(false)} is equivalent to808* {@code setModalityType(Dialog.ModalityType.MODELESS)}809*810* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE811* @see java.awt.Dialog.ModalityType#MODELESS812* @see java.awt.Dialog#isModal813* @see java.awt.Dialog#getModalityType814* @see java.awt.Dialog#setModalityType815*816* @since 1.1817*/818public void setModal(boolean modal) {819this.modal = modal;820setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);821}822823/**824* Returns the modality type of this dialog.825*826* @return modality type of this dialog827*828* @see java.awt.Dialog#setModalityType829*830* @since 1.6831*/832public ModalityType getModalityType() {833return modalityType;834}835836/**837* Sets the modality type for this dialog. See {@link838* java.awt.Dialog.ModalityType ModalityType} for possible modality types.839* <p>840* If the given modality type is not supported, {@code MODELESS}841* is used. You may want to call {@code getModalityType()} after calling842* this method to ensure that the modality type has been set.843* <p>844* Note: changing modality of the visible dialog may have no effect845* until it is hidden and then shown again.846*847* @param type specifies whether dialog blocks input to other848* windows when shown. {@code null} value and unsupported modality849* types are equivalent to {@code MODELESS}850* @exception SecurityException if the calling thread does not have permission851* to create modal dialogs with the given {@code modalityType}852*853* @see java.awt.Dialog#getModalityType854* @see java.awt.Toolkit#isModalityTypeSupported855*856* @since 1.6857*/858public void setModalityType(ModalityType type) {859if (type == null) {860type = Dialog.ModalityType.MODELESS;861}862if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) {863type = Dialog.ModalityType.MODELESS;864}865if (modalityType == type) {866return;867}868869checkModalityPermission(type);870871modalityType = type;872modal = (modalityType != ModalityType.MODELESS);873}874875/**876* Gets the title of the dialog. The title is displayed in the877* dialog's border.878* @return the title of this dialog window. The title may be879* {@code null}.880* @see java.awt.Dialog#setTitle881*/882public String getTitle() {883return title;884}885886/**887* Sets the title of the Dialog.888* @param title the title displayed in the dialog's border;889* a null value results in an empty title890* @see #getTitle891*/892public void setTitle(String title) {893String oldTitle = this.title;894895synchronized(this) {896this.title = title;897DialogPeer peer = (DialogPeer)this.peer;898if (peer != null) {899peer.setTitle(title);900}901}902firePropertyChange("title", oldTitle, title);903}904905/**906* @return true if we actually showed, false if we just called toFront()907*/908@SuppressWarnings("deprecation")909private boolean conditionalShow(Component toFocus, AtomicLong time) {910boolean retval;911912closeSplashScreen();913914synchronized (getTreeLock()) {915if (peer == null) {916addNotify();917}918validateUnconditionally();919if (visible) {920toFront();921retval = false;922} else {923visible = retval = true;924925// check if this dialog should be modal blocked BEFORE calling peer.show(),926// otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly927// generated for the dialog928if (!isModal()) {929checkShouldBeBlocked(this);930} else {931modalDialogs.add(this);932modalShow();933}934935if (toFocus != null && time != null && isFocusable() &&936isEnabled() && !isModalBlocked()) {937// keep the KeyEvents from being dispatched938// until the focus has been transferred939time.set(Toolkit.getEventQueue().getMostRecentKeyEventTime());940KeyboardFocusManager.getCurrentKeyboardFocusManager().941enqueueKeyEvents(time.get(), toFocus);942}943944// This call is required as the show() method of the Dialog class945// does not invoke the super.show(). So wried... :(946mixOnShowing();947948peer.setVisible(true); // now guaranteed never to block949if (isModalBlocked()) {950modalBlocker.toFront();951}952953setLocationByPlatform(false);954for (int i = 0; i < ownedWindowList.size(); i++) {955Window child = ownedWindowList.elementAt(i).get();956if ((child != null) && child.showWithParent) {957child.show();958child.showWithParent = false;959} // endif960} // endfor961Window.updateChildFocusableWindowState(this);962963createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,964this, parent,965HierarchyEvent.SHOWING_CHANGED,966Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));967if (componentListener != null ||968(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||969Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {970ComponentEvent e =971new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);972Toolkit.getEventQueue().postEvent(e);973}974}975}976977if (retval && (state & OPENED) == 0) {978postWindowEvent(WindowEvent.WINDOW_OPENED);979state |= OPENED;980}981982return retval;983}984985/**986* Shows or hides this {@code Dialog} depending on the value of parameter987* {@code b}.988* @param b if {@code true}, makes the {@code Dialog} visible,989* otherwise hides the {@code Dialog}.990* If the dialog and/or its owner991* are not yet displayable, both are made displayable. The992* dialog will be validated prior to being made visible.993* If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)}994* to return if it is currently blocked.995* <p>996* <b>Notes for modal dialogs</b>.997* <ul>998* <li>{@code setVisible(true)}: If the dialog is not already999* visible, this call will not return until the dialog is1000* hidden by calling {@code setVisible(false)} or1001* {@code dispose}.1002* <li>{@code setVisible(false)}: Hides the dialog and then1003* returns on {@code setVisible(true)} if it is currently blocked.1004* <li>It is OK to call this method from the event dispatching1005* thread because the toolkit ensures that other events are1006* not blocked while this method is blocked.1007* </ul>1008* @see java.awt.Window#setVisible1009* @see java.awt.Window#dispose1010* @see java.awt.Component#isDisplayable1011* @see java.awt.Component#validate1012* @see java.awt.Dialog#isModal1013*/1014public void setVisible(boolean b) {1015super.setVisible(b);1016}10171018/**1019* Makes the {@code Dialog} visible. If the dialog and/or its owner1020* are not yet displayable, both are made displayable. The1021* dialog will be validated prior to being made visible.1022* If the dialog is already visible, this will bring the dialog1023* to the front.1024* <p>1025* If the dialog is modal and is not already visible, this call1026* will not return until the dialog is hidden by calling hide or1027* dispose. It is permissible to show modal dialogs from the event1028* dispatching thread because the toolkit will ensure that another1029* event pump runs while the one which invoked this method is blocked.1030* @see Component#hide1031* @see Component#isDisplayable1032* @see Component#validate1033* @see #isModal1034* @see Window#setVisible(boolean)1035* @deprecated As of JDK version 1.5, replaced by1036* {@link #setVisible(boolean) setVisible(boolean)}.1037*/1038@Deprecated1039public void show() {1040if (!initialized) {1041throw new IllegalStateException("The dialog component " +1042"has not been initialized properly");1043}10441045beforeFirstShow = false;1046if (!isModal()) {1047conditionalShow(null, null);1048} else {1049AppContext showAppContext = AppContext.getAppContext();10501051AtomicLong time = new AtomicLong();1052Component predictedFocusOwner = null;1053try {1054predictedFocusOwner = getMostRecentFocusOwner();1055if (conditionalShow(predictedFocusOwner, time)) {1056modalFilter = ModalEventFilter.createFilterForDialog(this);1057// if this dialog is toolkit-modal, the filter should be added1058// to all EDTs (for all AppContexts)1059if (modalityType == ModalityType.TOOLKIT_MODAL) {1060for (AppContext appContext : AppContext.getAppContexts()) {1061if (appContext == showAppContext) {1062continue;1063}1064EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);1065// it may occur that EDT for appContext hasn't been started yet, so1066// we post an empty invocation event to trigger EDT initialization1067eventQueue.postEvent(new InvocationEvent(this, () -> {}));1068EventDispatchThread edt = eventQueue.getDispatchThread();1069edt.addEventFilter(modalFilter);1070}1071}10721073modalityPushed();1074try {1075@SuppressWarnings("removal")1076final EventQueue eventQueue = AccessController.doPrivileged(1077(PrivilegedAction<EventQueue>) Toolkit.getDefaultToolkit()::getSystemEventQueue);1078secondaryLoop = eventQueue.createSecondaryLoop(() -> true, modalFilter, 0);1079if (!secondaryLoop.enter()) {1080secondaryLoop = null;1081}1082} finally {1083modalityPopped();1084}10851086// if this dialog is toolkit-modal, its filter must be removed1087// from all EDTs (for all AppContexts)1088if (modalityType == ModalityType.TOOLKIT_MODAL) {1089for (AppContext appContext : AppContext.getAppContexts()) {1090if (appContext == showAppContext) {1091continue;1092}1093EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);1094EventDispatchThread edt = eventQueue.getDispatchThread();1095edt.removeEventFilter(modalFilter);1096}1097}1098}1099} finally {1100if (predictedFocusOwner != null) {1101// Restore normal key event dispatching1102KeyboardFocusManager.getCurrentKeyboardFocusManager().1103dequeueKeyEvents(time.get(), predictedFocusOwner);1104}1105}1106}1107}11081109final void modalityPushed() {1110Toolkit tk = Toolkit.getDefaultToolkit();1111if (tk instanceof SunToolkit) {1112SunToolkit stk = (SunToolkit)tk;1113stk.notifyModalityPushed(this);1114}1115}11161117final void modalityPopped() {1118Toolkit tk = Toolkit.getDefaultToolkit();1119if (tk instanceof SunToolkit) {1120SunToolkit stk = (SunToolkit)tk;1121stk.notifyModalityPopped(this);1122}1123}11241125private void hideAndDisposePreHandler() {1126isInHide = true;1127synchronized (getTreeLock()) {1128if (secondaryLoop != null) {1129modalHide();1130// dialog can be shown and then disposed before its1131// modal filter is created1132if (modalFilter != null) {1133modalFilter.disable();1134}1135modalDialogs.remove(this);1136}1137}1138}1139private void hideAndDisposeHandler() {1140if (secondaryLoop != null) {1141secondaryLoop.exit();1142secondaryLoop = null;1143}1144isInHide = false;1145}11461147/**1148* Hides the Dialog and then causes {@code show} to return if it is currently1149* blocked.1150* @see Window#show1151* @see Window#dispose1152* @see Window#setVisible(boolean)1153* @deprecated As of JDK version 1.5, replaced by1154* {@link #setVisible(boolean) setVisible(boolean)}.1155*/1156@Deprecated1157public void hide() {1158hideAndDisposePreHandler();1159super.hide();1160// fix for 5048370: if hide() is called from super.doDispose(), then1161// hideAndDisposeHandler() should not be called here as it will be called1162// at the end of doDispose()1163if (!isInDispose) {1164hideAndDisposeHandler();1165}1166}11671168/**1169* Disposes the Dialog and then causes show() to return if it is currently1170* blocked.1171*/1172void doDispose() {1173// fix for 5048370: set isInDispose flag to true to prevent calling1174// to hideAndDisposeHandler() from hide()1175isInDispose = true;1176super.doDispose();1177hideAndDisposeHandler();1178isInDispose = false;1179}11801181/**1182* {@inheritDoc}1183* <p>1184* If this dialog is modal and blocks some windows, then all of them are1185* also sent to the back to keep them below the blocking dialog.1186*1187* @see java.awt.Window#toBack1188*/1189public void toBack() {1190super.toBack();1191if (visible) {1192synchronized (getTreeLock()) {1193for (Window w : blockedWindows) {1194w.toBack_NoClientCode();1195}1196}1197}1198}11991200/**1201* Indicates whether this dialog is resizable by the user.1202* By default, all dialogs are initially resizable.1203* @return {@code true} if the user can resize the dialog;1204* {@code false} otherwise.1205* @see java.awt.Dialog#setResizable1206*/1207public boolean isResizable() {1208return resizable;1209}12101211/**1212* Sets whether this dialog is resizable by the user.1213* @param resizable {@code true} if the user can1214* resize this dialog; {@code false} otherwise.1215* @see java.awt.Dialog#isResizable1216*/1217public void setResizable(boolean resizable) {1218boolean testvalid = false;12191220synchronized (this) {1221this.resizable = resizable;1222DialogPeer peer = (DialogPeer)this.peer;1223if (peer != null) {1224peer.setResizable(resizable);1225testvalid = true;1226}1227}12281229// On some platforms, changing the resizable state affects1230// the insets of the Dialog. If we could, we'd call invalidate()1231// from the peer, but we need to guarantee that we're not holding1232// the Dialog lock when we call invalidate().1233if (testvalid) {1234invalidateIfValid();1235}1236}123712381239/**1240* Disables or enables decorations for this dialog.1241* <p>1242* This method can only be called while the dialog is not displayable. To1243* make this dialog decorated, it must be opaque and have the default shape,1244* otherwise the {@code IllegalComponentStateException} will be thrown.1245* Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link1246* Window#setBackground} for details1247*1248* @param undecorated {@code true} if no dialog decorations are to be1249* enabled; {@code false} if dialog decorations are to be enabled1250*1251* @throws IllegalComponentStateException if the dialog is displayable1252* @throws IllegalComponentStateException if {@code undecorated} is1253* {@code false}, and this dialog does not have the default shape1254* @throws IllegalComponentStateException if {@code undecorated} is1255* {@code false}, and this dialog opacity is less than {@code 1.0f}1256* @throws IllegalComponentStateException if {@code undecorated} is1257* {@code false}, and the alpha value of this dialog background1258* color is less than {@code 1.0f}1259*1260* @see #isUndecorated1261* @see Component#isDisplayable1262* @see Window#getShape1263* @see Window#getOpacity1264* @see Window#getBackground1265*1266* @since 1.41267*/1268public void setUndecorated(boolean undecorated) {1269/* Make sure we don't run in the middle of peer creation.*/1270synchronized (getTreeLock()) {1271if (isDisplayable()) {1272throw new IllegalComponentStateException("The dialog is displayable.");1273}1274if (!undecorated) {1275if (getOpacity() < 1.0f) {1276throw new IllegalComponentStateException("The dialog is not opaque");1277}1278if (getShape() != null) {1279throw new IllegalComponentStateException("The dialog does not have a default shape");1280}1281Color bg = getBackground();1282if ((bg != null) && (bg.getAlpha() < 255)) {1283throw new IllegalComponentStateException("The dialog background color is not opaque");1284}1285}1286this.undecorated = undecorated;1287}1288}12891290/**1291* Indicates whether this dialog is undecorated.1292* By default, all dialogs are initially decorated.1293* @return {@code true} if dialog is undecorated;1294* {@code false} otherwise.1295* @see java.awt.Dialog#setUndecorated1296* @since 1.41297*/1298public boolean isUndecorated() {1299return undecorated;1300}13011302/**1303* {@inheritDoc}1304*/1305@Override1306public void setOpacity(float opacity) {1307synchronized (getTreeLock()) {1308if ((opacity < 1.0f) && !isUndecorated()) {1309throw new IllegalComponentStateException("The dialog is decorated");1310}1311super.setOpacity(opacity);1312}1313}13141315/**1316* {@inheritDoc}1317*/1318@Override1319public void setShape(Shape shape) {1320synchronized (getTreeLock()) {1321if ((shape != null) && !isUndecorated()) {1322throw new IllegalComponentStateException("The dialog is decorated");1323}1324super.setShape(shape);1325}1326}13271328/**1329* {@inheritDoc}1330*/1331@Override1332public void setBackground(Color bgColor) {1333synchronized (getTreeLock()) {1334if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {1335throw new IllegalComponentStateException("The dialog is decorated");1336}1337super.setBackground(bgColor);1338}1339}13401341/**1342* Returns a string representing the state of this dialog. This1343* method is intended to be used only for debugging purposes, and the1344* content and format of the returned string may vary between1345* implementations. The returned string may be empty but may not be1346* {@code null}.1347*1348* @return the parameter string of this dialog window.1349*/1350protected String paramString() {1351String str = super.paramString() + "," + modalityType;1352if (title != null) {1353str += ",title=" + title;1354}1355return str;1356}13571358/**1359* Initialize JNI field and method IDs1360*/1361private static native void initIDs();13621363/*1364* --- Modality support ---1365*1366*/13671368/*1369* This method is called only for modal dialogs.1370*1371* Goes through the list of all visible top-level windows and1372* divide them into three distinct groups: blockers of this dialog,1373* blocked by this dialog and all others. Then blocks this dialog1374* by first met dialog from the first group (if any) and blocks all1375* the windows from the second group.1376*/1377void modalShow() {1378// find all the dialogs that block this one1379IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>();1380for (Dialog d : modalDialogs) {1381if (d.shouldBlock(this)) {1382Window w = d;1383while ((w != null) && (w != this)) {1384w = w.getOwner_NoClientCode();1385}1386if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {1387blockers.add(d);1388}1389}1390}13911392// add all blockers' blockers to blockers :)1393for (int i = 0; i < blockers.size(); i++) {1394Dialog blocker = blockers.get(i);1395if (blocker.isModalBlocked()) {1396Dialog blockerBlocker = blocker.getModalBlocker();1397if (!blockers.contains(blockerBlocker)) {1398blockers.add(i + 1, blockerBlocker);1399}1400}1401}14021403if (blockers.size() > 0) {1404blockers.get(0).blockWindow(this);1405}14061407// find all windows from blockers' hierarchies1408IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers);1409int k = 0;1410while (k < blockersHierarchies.size()) {1411Window w = blockersHierarchies.get(k);1412Window[] ownedWindows = w.getOwnedWindows_NoClientCode();1413for (Window win : ownedWindows) {1414blockersHierarchies.add(win);1415}1416k++;1417}14181419java.util.List<Window> toBlock = new IdentityLinkedList<Window>();1420// block all windows from scope of blocking except from blockers' hierarchies1421IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows();1422for (Window w : unblockedWindows) {1423if (shouldBlock(w) && !blockersHierarchies.contains(w)) {1424if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {1425Dialog wd = (Dialog)w;1426if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) {1427continue;1428}1429}1430toBlock.add(w);1431}1432}1433blockWindows(toBlock);14341435if (!isModalBlocked()) {1436updateChildrenBlocking();1437}1438}14391440/*1441* This method is called only for modal dialogs.1442*1443* Unblocks all the windows blocked by this modal dialog. After1444* each of them has been unblocked, it is checked to be blocked by1445* any other modal dialogs.1446*/1447void modalHide() {1448// we should unblock all the windows first...1449IdentityArrayList<Window> save = new IdentityArrayList<Window>();1450int blockedWindowsCount = blockedWindows.size();1451for (int i = 0; i < blockedWindowsCount; i++) {1452Window w = blockedWindows.get(0);1453save.add(w);1454unblockWindow(w); // also removes w from blockedWindows1455}1456// ... and only after that check if they should be blocked1457// by another dialogs1458for (int i = 0; i < blockedWindowsCount; i++) {1459Window w = save.get(i);1460if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {1461Dialog d = (Dialog)w;1462d.modalShow();1463} else {1464checkShouldBeBlocked(w);1465}1466}1467}14681469/*1470* Returns whether the given top-level window should be blocked by1471* this dialog. Note, that the given window can be also a modal dialog1472* and it should block this dialog, but this method do not take such1473* situations into consideration (such checks are performed in the1474* modalShow() and modalHide() methods).1475*1476* This method should be called on the getTreeLock() lock.1477*/1478boolean shouldBlock(Window w) {1479if (!isVisible_NoClientCode() ||1480(!w.isVisible_NoClientCode() && !w.isInShow) ||1481isInHide ||1482(w == this) ||1483!isModal_NoClientCode())1484{1485return false;1486}1487if ((w instanceof Dialog) && ((Dialog)w).isInHide) {1488return false;1489}1490// check if w is from children hierarchy1491// fix for 6271546: we should also take into consideration child hierarchies1492// of this dialog's blockers1493Window blockerToCheck = this;1494while (blockerToCheck != null) {1495Component c = w;1496while ((c != null) && (c != blockerToCheck)) {1497c = c.getParent_NoClientCode();1498}1499if (c == blockerToCheck) {1500return false;1501}1502blockerToCheck = blockerToCheck.getModalBlocker();1503}1504switch (modalityType) {1505case MODELESS:1506return false;1507case DOCUMENT_MODAL:1508if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) {1509// application- and toolkit-excluded windows are not blocked by1510// document-modal dialogs from outside their children hierarchy1511Component c = this;1512while ((c != null) && (c != w)) {1513c = c.getParent_NoClientCode();1514}1515return c == w;1516} else {1517return getDocumentRoot() == w.getDocumentRoot();1518}1519case APPLICATION_MODAL:1520return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) &&1521(appContext == w.appContext);1522case TOOLKIT_MODAL:1523return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE);1524}15251526return false;1527}15281529/*1530* Adds the given top-level window to the list of blocked1531* windows for this dialog and marks it as modal blocked.1532* If the window is already blocked by some modal dialog,1533* does nothing.1534*/1535void blockWindow(Window w) {1536if (!w.isModalBlocked()) {1537w.setModalBlocked(this, true, true);1538blockedWindows.add(w);1539}1540}15411542void blockWindows(java.util.List<Window> toBlock) {1543DialogPeer dpeer = (DialogPeer)peer;1544if (dpeer == null) {1545return;1546}1547Iterator<Window> it = toBlock.iterator();1548while (it.hasNext()) {1549Window w = it.next();1550if (!w.isModalBlocked()) {1551w.setModalBlocked(this, true, false);1552} else {1553it.remove();1554}1555}1556dpeer.blockWindows(toBlock);1557blockedWindows.addAll(toBlock);1558}15591560/*1561* Removes the given top-level window from the list of blocked1562* windows for this dialog and marks it as unblocked. If the1563* window is not modal blocked, does nothing.1564*/1565void unblockWindow(Window w) {1566if (w.isModalBlocked() && blockedWindows.contains(w)) {1567blockedWindows.remove(w);1568w.setModalBlocked(this, false, true);1569}1570}15711572/*1573* Checks if any other modal dialog D blocks the given window.1574* If such D exists, mark the window as blocked by D.1575*/1576static void checkShouldBeBlocked(Window w) {1577synchronized (w.getTreeLock()) {1578for (int i = 0; i < modalDialogs.size(); i++) {1579Dialog modalDialog = modalDialogs.get(i);1580if (modalDialog.shouldBlock(w)) {1581modalDialog.blockWindow(w);1582break;1583}1584}1585}1586}15871588private void checkModalityPermission(ModalityType mt) {1589if (mt == ModalityType.TOOLKIT_MODAL) {1590@SuppressWarnings("removal")1591SecurityManager sm = System.getSecurityManager();1592if (sm != null) {1593sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION);1594}1595}1596}15971598/**1599* Reads serializable fields from stream.1600*1601* @param s the {@code ObjectInputStream} to read1602* @throws ClassNotFoundException if the class of a serialized object could1603* not be found1604* @throws IOException if an I/O error occurs1605* @throws HeadlessException if {@code GraphicsEnvironment.isHeadless()}1606* returns {@code true}1607*/1608@Serial1609private void readObject(ObjectInputStream s)1610throws ClassNotFoundException, IOException, HeadlessException1611{1612GraphicsEnvironment.checkHeadless();16131614java.io.ObjectInputStream.GetField fields =1615s.readFields();16161617ModalityType localModalityType = (ModalityType)fields.get("modalityType", null);16181619try {1620checkModalityPermission(localModalityType);1621} catch (@SuppressWarnings("removal") AccessControlException ace) {1622localModalityType = DEFAULT_MODALITY_TYPE;1623}16241625// in 1.5 or earlier modalityType was absent, so use "modal" instead1626if (localModalityType == null) {1627this.modal = fields.get("modal", false);1628setModal(modal);1629} else {1630this.modalityType = localModalityType;1631}16321633this.resizable = fields.get("resizable", true);1634this.undecorated = fields.get("undecorated", false);1635this.title = (String)fields.get("title", "");16361637blockedWindows = new IdentityArrayList<>();16381639SunToolkit.checkAndSetPolicy(this);16401641initialized = true;16421643}16441645/*1646* --- Accessibility Support ---1647*1648*/16491650/**1651* Gets the AccessibleContext associated with this Dialog.1652* For dialogs, the AccessibleContext takes the form of an1653* AccessibleAWTDialog.1654* A new AccessibleAWTDialog instance is created if necessary.1655*1656* @return an AccessibleAWTDialog that serves as the1657* AccessibleContext of this Dialog1658* @since 1.31659*/1660public AccessibleContext getAccessibleContext() {1661if (accessibleContext == null) {1662accessibleContext = new AccessibleAWTDialog();1663}1664return accessibleContext;1665}16661667/**1668* This class implements accessibility support for the1669* {@code Dialog} class. It provides an implementation of the1670* Java Accessibility API appropriate to dialog user-interface elements.1671* @since 1.31672*/1673protected class AccessibleAWTDialog extends AccessibleAWTWindow1674{1675/**1676* Use serialVersionUID from JDK 1.3 for interoperability.1677*/1678@Serial1679private static final long serialVersionUID = 4837230331833941201L;16801681/**1682* Constructs an {@code AccessibleAWTDialog}.1683*/1684protected AccessibleAWTDialog() {}16851686/**1687* Get the role of this object.1688*1689* @return an instance of AccessibleRole describing the role of the1690* object1691* @see AccessibleRole1692*/1693public AccessibleRole getAccessibleRole() {1694return AccessibleRole.DIALOG;1695}16961697/**1698* Get the state of this object.1699*1700* @return an instance of AccessibleStateSet containing the current1701* state set of the object1702* @see AccessibleState1703*/1704public AccessibleStateSet getAccessibleStateSet() {1705AccessibleStateSet states = super.getAccessibleStateSet();1706if (getFocusOwner() != null) {1707states.add(AccessibleState.ACTIVE);1708}1709if (isModal()) {1710states.add(AccessibleState.MODAL);1711}1712if (isResizable()) {1713states.add(AccessibleState.RESIZABLE);1714}1715return states;1716}17171718} // inner class AccessibleAWTDialog1719}172017211722