jdk/src/share/classes/java/awt/Dialog.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7512 1b4801f0c6ff
child 9202 164591974d77
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7512
diff changeset
     2
 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3956
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.DialogPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.concurrent.atomic.AtomicLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.PeerEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.util.IdentityArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.awt.util.IdentityLinkedList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A Dialog is a top-level window with a title and a border
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * that is typically used to take some form of input from the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The size of the dialog includes any area designated for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * border.  The dimensions of the border area can be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * using the <code>getInsets</code> method, however, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * these dimensions are platform-dependent, a valid insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * value cannot be obtained until the dialog is made displayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * by either calling <code>pack</code> or <code>show</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Since the border area is included in the overall size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * dialog, the border effectively obscures a portion of the dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * constraining the area available for rendering and/or displaying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * subcomponents to the rectangle which has an upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * location of <code>(insets.left, insets.top)</code>, and has a size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>width - (insets.left + insets.right)</code> by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>height - (insets.top + insets.bottom)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * The default layout for a dialog is <code>BorderLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * with <code>setUndecorated</code>.  This can only be done while the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * is not {@link Component#isDisplayable() displayable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * A dialog may have another window as its owner when it's constructed.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the owner window of a visible dialog is minimized, the dialog will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * automatically be hidden from the user. When the owner window is subsequently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * restored, the dialog is made visible to the user again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * In a multi-screen environment, you can create a <code>Dialog</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * on a different screen device than its owner.  See {@link java.awt.Frame} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * A dialog can be either modeless (the default) or modal.  A modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * dialog is one which blocks input to some other top-level windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * in the application, except for any windows created with the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * as their owner. See <a href="doc-files/Modality.html">AWT Modality</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * specification for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Dialogs are capable of generating the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>WindowEvents</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <code>WindowOpened</code>, <code>WindowClosing</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <code>WindowClosed</code>, <code>WindowActivated</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <code>WindowLostFocus</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @see WindowEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @see Window#addWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
public class Dialog extends Window {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * A dialog's resizable property. Will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * if the Dialog is to be resizable, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * it will be false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @see #setResizable(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    boolean resizable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * This field indicates whether the dialog is undecorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * This property can only be changed while the dialog is not displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <code>undecorated</code> will be true if the dialog is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * undecorated, otherwise it will be false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @see #setUndecorated(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see #isUndecorated()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @see Component#isDisplayable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    boolean undecorated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Modal dialogs block all input to some top-level windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Whether a particular window is blocked depends on dialog's type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * of modality; this is called the "scope of blocking". The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * <code>ModalityType</code> enum specifies modal types and their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * associated scopes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see Dialog#getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @see Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see Toolkit#isModalityTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public static enum ModalityType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * <code>MODELESS</code> dialog doesn't block any top-level windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        MODELESS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * A <code>DOCUMENT_MODAL</code> dialog blocks input to all top-level windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         * from the same document except those from its own child hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
         * A document is a top-level window without an owner. It may contain child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
         * windows that, together with the top-level window are treated as a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * solid document. Since every top-level window must belong to some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * document, its root can be found as the top-nearest window without an owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        DOCUMENT_MODAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * An <code>APPLICATION_MODAL</code> dialog blocks all top-level windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * from the same Java application except those from its own child hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         * If there are several applets launched in a browser, they can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * treated either as separate applications or a single one. This behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * is implementation-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        APPLICATION_MODAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         * A <code>TOOLKIT_MODAL</code> dialog blocks all top-level windows run
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         * from the same toolkit except those from its own child hierarchy. If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * are several applets launched in a browser, all of them run with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * toolkit; thus, a toolkit-modal dialog displayed by an applet may affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * other applets and all windows of the browser instance which embeds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         * Java runtime environment for this toolkit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         * Special <code>AWTPermission</code> "toolkitModality" must be granted to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         * toolkit-modal dialogs. If a <code>TOOLKIT_MODAL</code> dialog is being created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * and this permission is not granted, a <code>SecurityException</code> will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * thrown, and no dialog will be created. If a modality type is being changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * to <code>TOOLKIT_MODAL</code> and this permission is not granted, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * <code>SecurityException</code> will be thrown, and the modality type will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * be left unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        TOOLKIT_MODAL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Default modality type for modal dialogs. The default modality type is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <code>APPLICATION_MODAL</code>. Calling the oldstyle <code>setModal(true)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * is equal to <code>setModalityType(DEFAULT_MODALITY_TYPE)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public final static ModalityType DEFAULT_MODALITY_TYPE = ModalityType.APPLICATION_MODAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * True if this dialog is modal, false is the dialog is modeless.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * A modal dialog blocks user input to some application top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * windows. This field is kept only for backwards compatibility. Use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * {@link Dialog.ModalityType ModalityType} enum instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @see #isModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @see #setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @see #getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @see #setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @see ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @see #DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    boolean modal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Modality type of this dialog. If the dialog's modality type is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * {@link Dialog.ModalityType#MODELESS ModalityType.MODELESS}, it blocks all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * user input to some application top-level windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @see ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @see #getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    ModalityType modalityType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Any top-level window can be marked not to be blocked by modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * dialogs. This is called "modal exclusion". This enum specifies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * the possible modal exclusion types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see Window#getModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see Window#setModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see Toolkit#isModalExclusionTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static enum ModalExclusionType {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
         * No modal exclusion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        NO_EXCLUDE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         * <code>APPLICATION_EXCLUDE</code> indicates that a top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * won't be blocked by any application-modal dialogs. Also, it isn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         * blocked by document-modal dialogs from outside of its child hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        APPLICATION_EXCLUDE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * <code>TOOLKIT_EXCLUDE</code> indicates that a top-level window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         * won't be blocked by  application-modal or toolkit-modal dialogs. Also,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
         * it isn't blocked by document-modal dialogs from outside of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         * child hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * The "toolkitModality" <code>AWTPermission</code> must be granted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         * for this exclusion. If an exclusion property is being changed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * <code>TOOLKIT_EXCLUDE</code> and this permission is not granted, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * <code>SecurityEcxeption</code> will be thrown, and the exclusion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         * property will be left unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        TOOLKIT_EXCLUDE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /* operations with this list should be synchronized on tree lock*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    transient static IdentityArrayList<Dialog> modalDialogs = new IdentityArrayList<Dialog>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    transient IdentityArrayList<Window> blockedWindows = new IdentityArrayList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Specifies the title of the Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * This field can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @see #getTitle()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #setTitle(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    String title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private transient ModalEventFilter modalFilter;
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
   281
    private transient volatile SecondaryLoop secondaryLoop;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Indicates that this dialog is being hidden. This flag is set to true at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * the beginning of hide() and to false at the end of hide().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @see #hide()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @see #hideAndDisposePreHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @see #hideAndDisposeHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see #shouldBlock()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    transient volatile boolean isInHide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Indicates that this dialog is being disposed. This flag is set to true at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * the beginning of doDispose() and to false at the end of doDispose().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #hide()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see #hideAndDisposePreHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see #hideAndDisposeHandler()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see #doDispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    transient volatile boolean isInDispose = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    private static final String base = "dialog";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private static final long serialVersionUID = 5920926903803293709L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Constructs an initially invisible, modeless <code>Dialog</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * the specified owner <code>Frame</code> and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @param owner the owner of the dialog or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *     this dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     public Dialog(Frame owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         this(owner, "", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Constructs an initially invisible <code>Dialog</code> with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * owner <code>Frame</code> and modality and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param owner the owner of the dialog or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *     this dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param modal specifes whether dialog blocks user input to other top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *     windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *     if <code>true</code>, the modality type property is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *     <code>DEFAULT_MODALITY_TYPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     public Dialog(Frame owner, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         this(owner, "", modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Constructs an initially invisible, modeless <code>Dialog</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * the specified owner <code>Frame</code> and title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @param owner the owner of the dialog or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     *     this dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @exception IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *     <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     public Dialog(Frame owner, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         this(owner, title, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * specified owner <code>Frame</code>, title and modality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @param owner the owner of the dialog or <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *     this dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @param modal specifes whether dialog blocks user input to other top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *     windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *     if <code>true</code>, the modality type property is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *     <code>DEFAULT_MODALITY_TYPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     public Dialog(Frame owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Constructs an initially invisible <code>Dialog</code> with the specified owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <code>Frame</code>, title, modality, and <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @param owner the owner of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *     has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param modal specifes whether dialog blocks user input to other top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *     windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *     if <code>true</code>, the modality type property is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *     <code>DEFAULT_MODALITY_TYPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *     if <code>null</code>, the default system <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *     is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @exception java.lang.IllegalArgumentException if <code>gc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *     is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @see java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     public Dialog(Frame owner, String title, boolean modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                   GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Constructs an initially invisible, modeless <code>Dialog</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * the specified owner <code>Dialog</code> and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param owner the owner of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *     dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *     <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     public Dialog(Dialog owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         this(owner, "", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Constructs an initially invisible, modeless <code>Dialog</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * with the specified owner <code>Dialog</code> and title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @param owner the owner of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *     has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *     <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     public Dialog(Dialog owner, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
         this(owner, title, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * specified owner <code>Dialog</code>, title, and modality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param owner the owner of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *     dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @param title the title of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *     dialog has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * @param modal specifes whether dialog blocks user input to other top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *     windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *     if <code>true</code>, the modality type property is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *     <code>DEFAULT_MODALITY_TYPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @exception IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @see java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     public Dialog(Dialog owner, String title, boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * specified owner <code>Dialog</code>, title, modality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param owner the owner of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *     dialog has no owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @param title the title of the dialog or <code>null</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *     dialog has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @param modal specifes whether dialog blocks user input to other top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     *     windows when shown. If <code>false</code>, the dialog is <code>MODELESS</code>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *     if <code>true</code>, the modality type property is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *     <code>DEFAULT_MODALITY_TYPE</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *     if <code>null</code>, the default system <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *     is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @exception java.lang.IllegalArgumentException if <code>gc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *    is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @see java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     public Dialog(Dialog owner, String title, boolean modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                   GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Constructs an initially invisible, modeless <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * specified owner <code>Window</code> and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @param owner the owner of the dialog. The owner must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *     {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *     of their descendents or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     *     is not an instance of {@link java.awt.Dialog Dialog} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *     java.awt.Frame Frame}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *     <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public Dialog(Window owner) {
7500
dec4b445efc6 6639507: Title of javax.swing.JDialog is null while spec says it's empty
rupashka
parents: 6636
diff changeset
   568
        this(owner, "", ModalityType.MODELESS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Constructs an initially invisible, modeless <code>Dialog</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * the specified owner <code>Window</code> and title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @param owner the owner of the dialog. The owner must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *    {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *    of their descendents or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *    has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     *    is not an instance of {@link java.awt.Dialog Dialog} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *    java.awt.Frame Frame}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public Dialog(Window owner, String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        this(owner, title, ModalityType.MODELESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * specified owner <code>Window</code> and modality and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @param owner the owner of the dialog. The owner must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *    {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *    of their descendents or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param modalityType specifies whether dialog blocks input to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *    windows when shown. <code>null</code> value and unsupported modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *    types are equivalent to <code>MODELESS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *    is not an instance of {@link java.awt.Dialog Dialog} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *    java.awt.Frame Frame}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *    <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *    <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @exception SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *    to create modal dialogs with the given <code>modalityType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see java.awt.Toolkit#isModalityTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public Dialog(Window owner, ModalityType modalityType) {
7500
dec4b445efc6 6639507: Title of javax.swing.JDialog is null while spec says it's empty
rupashka
parents: 6636
diff changeset
   627
        this(owner, "", modalityType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * specified owner <code>Window</code>, title and modality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @param owner the owner of the dialog. The owner must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *     {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *     of their descendents or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @param modalityType specifies whether dialog blocks input to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *    windows when shown. <code>null</code> value and unsupported modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *    types are equivalent to <code>MODELESS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *     is not an instance of {@link java.awt.Dialog Dialog} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *     java.awt.Frame Frame}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *     <code>GraphicsConfiguration</code> is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * @exception SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *     to create modal dialogs with the given <code>modalityType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @see java.awt.Toolkit#isModalityTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public Dialog(Window owner, String title, ModalityType modalityType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        super(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        if ((owner != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            !(owner instanceof Frame) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            !(owner instanceof Dialog))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            throw new IllegalArgumentException("Wrong parent window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        setModalityType(modalityType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        SunToolkit.checkAndSetPolicy(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Constructs an initially invisible <code>Dialog</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * specified owner <code>Window</code>, title, modality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param owner the owner of the dialog. The owner must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *     {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *     of their descendents or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @param title the title of the dialog or <code>null</code> if this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *     has no title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @param modalityType specifies whether dialog blocks input to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *    windows when shown. <code>null</code> value and unsupported modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     *    types are equivalent to <code>MODELESS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @param gc the <code>GraphicsConfiguration</code> of the target screen device;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *     if <code>null</code>, the default system <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *     is assumed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @exception java.lang.IllegalArgumentException if the <code>owner</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *     is not an instance of {@link java.awt.Dialog Dialog} or {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *     java.awt.Frame Frame}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @exception java.lang.IllegalArgumentException if <code>gc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *     is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * @exception SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *     to create modal dialogs with the given <code>modalityType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see java.awt.Dialog.ModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * @see java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @see java.awt.Toolkit#isModalityTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public Dialog(Window owner, String title, ModalityType modalityType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                  GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        super(owner, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        if ((owner != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            !(owner instanceof Frame) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            !(owner instanceof Dialog))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            throw new IllegalArgumentException("wrong owner window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        setModalityType(modalityType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        SunToolkit.checkAndSetPolicy(this, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Construct a name for this component.  Called by getName() when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        synchronized (Dialog.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Makes this Dialog displayable by connecting it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * a native screen resource.  Making a dialog displayable will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * cause any of its children to be made displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (parent != null && parent.getPeer() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                parent.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                peer = getToolkit().createDialog(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * Indicates whether the dialog is modal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * This method is obsolete and is kept for backwards compatiblity only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Use {@link #getModalityType getModalityType()} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @return    <code>true</code> if this dialog window is modal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *            <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @see       java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @see       java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @see       java.awt.Dialog#setModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @see       java.awt.Dialog#getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * @see       java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public boolean isModal() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        return isModal_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    final boolean isModal_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        return modalityType != ModalityType.MODELESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Specifies whether this dialog should be modal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * This method is obsolete and is kept for backwards compatibility only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * Use {@link #setModalityType setModalityType()} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Note: changing modality of the visible dialog may have no effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * until it is hidden and then shown again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @param modal specifies whether dialog blocks input to other windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     *     when shown; calling to <code>setModal(true)</code> is equivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *     <code>setModalityType(Dialog.DEFAULT_MODALITY_TYPE)</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *     calling to <code>setModal(false)</code> is equvivalent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     *     <code>setModalityType(Dialog.ModalityType.MODELESS)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see       java.awt.Dialog#DEFAULT_MODALITY_TYPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @see       java.awt.Dialog.ModalityType#MODELESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see       java.awt.Dialog#isModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @see       java.awt.Dialog#getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see       java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @since     1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public void setModal(boolean modal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        this.modal = modal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * Returns the modality type of this dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @return modality type of this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see java.awt.Dialog#setModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    public ModalityType getModalityType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        return modalityType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Sets the modality type for this dialog. See {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * java.awt.Dialog.ModalityType ModalityType} for possible modality types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * If the given modality type is not supported, <code>MODELESS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * is used. You may want to call <code>getModalityType()</code> after calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * this method to ensure that the modality type has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Note: changing modality of the visible dialog may have no effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * until it is hidden and then shown again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @param type specifies whether dialog blocks input to other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *     windows when shown. <code>null</code> value and unsupported modality
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *     types are equivalent to <code>MODELESS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @exception SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *     to create modal dialogs with the given <code>modalityType</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see       java.awt.Dialog#getModalityType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @see       java.awt.Toolkit#isModalityTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @since     1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    public void setModalityType(ModalityType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            type = Dialog.ModalityType.MODELESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            type = Dialog.ModalityType.MODELESS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        if (modalityType == type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        if (type == ModalityType.TOOLKIT_MODAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            if (sm != null) {
3956
2586d23078e4 6854954: Eliminate static dependency on java.awt.AWTPermission
alanb
parents: 3084
diff changeset
   857
                sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        modalityType = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        modal = (modalityType != ModalityType.MODELESS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * Gets the title of the dialog. The title is displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * dialog's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @return    the title of this dialog window. The title may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     *            <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @see       java.awt.Dialog#setTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public String getTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Sets the title of the Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @param title the title displayed in the dialog's border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * a null value results in an empty title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @see #getTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    public void setTitle(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        String oldTitle = this.title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            DialogPeer peer = (DialogPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                peer.setTitle(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        firePropertyChange("title", oldTitle, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * @return true if we actually showed, false if we just called toFront()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    private boolean conditionalShow(Component toFocus, AtomicLong time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        boolean retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        closeSplashScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                visible = retval = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                // check if this dialog should be modal blocked BEFORE calling peer.show(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                // otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                // generated for the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                if (!isModal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    checkShouldBeBlocked(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    modalDialogs.add(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    modalShow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                if (toFocus != null && time != null && isFocusable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                    isEnabled() && !isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    // keep the KeyEvents from being dispatched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                    // until the focus has been transfered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    time.set(Toolkit.getEventQueue().getMostRecentEventTimeEx());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                        enqueueKeyEvents(time.get(), toFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                // This call is required as the show() method of the Dialog class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                // does not invoke the super.show(). So wried... :(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                mixOnShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
1964
934568dfe859 6749920: Cleanup AWT peer interfaces
rkennke
parents: 1183
diff changeset
   936
                peer.setVisible(true); // now guaranteed never to block
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    modalBlocker.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                setLocationByPlatform(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                for (int i = 0; i < ownedWindowList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    Window child = ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                    if ((child != null) && child.showWithParent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                        child.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                        child.showWithParent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    }       // endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                }   // endfor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                Window.updateChildFocusableWindowState(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                                      this, parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                                      HierarchyEvent.SHOWING_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                                      Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                if (componentListener != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                        (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                        Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                    ComponentEvent e =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                        new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        if (retval && (state & OPENED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            postWindowEvent(WindowEvent.WINDOW_OPENED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            state |= OPENED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * Shows or hides this {@code Dialog} depending on the value of parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * @param b if {@code true}, makes the {@code Dialog} visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * otherwise hides the {@code Dialog}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * If the dialog and/or its owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * are not yet displayable, both are made displayable.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * dialog will be validated prior to being made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * to return if it is currently blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * <b>Notes for modal dialogs</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * <li>{@code setVisible(true)}:  If the dialog is not already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * visible, this call will not return until the dialog is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * hidden by calling {@code setVisible(false)} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * {@code dispose}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * <li>{@code setVisible(false)}:  Hides the dialog and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * returns on {@code setVisible(true)} if it is currently blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * <li>It is OK to call this method from the event dispatching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * thread because the toolkit ensures that other events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * not blocked while this method is blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @see java.awt.Window#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * @see java.awt.Window#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * @see java.awt.Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @see java.awt.Component#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @see java.awt.Dialog#isModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * Makes the {@code Dialog} visible. If the dialog and/or its owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * are not yet displayable, both are made displayable.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * dialog will be validated prior to being made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * If the dialog is already visible, this will bring the dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * If the dialog is modal and is not already visible, this call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * will not return until the dialog is hidden by calling hide or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * dispose. It is permissible to show modal dialogs from the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * dispatching thread because the toolkit will ensure that another
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * event pump runs while the one which invoked this method is blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @see Component#hide
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @see Component#validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @see #isModal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * @see Window#setVisible(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * @deprecated As of JDK version 1.5, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * {@link #setVisible(boolean) setVisible(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        beforeFirstShow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        if (!isModal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            conditionalShow(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        } else {
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1032
            AppContext showAppContext = AppContext.getAppContext();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            AtomicLong time = new AtomicLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            Component predictedFocusOwner = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                predictedFocusOwner = getMostRecentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                if (conditionalShow(predictedFocusOwner, time)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                    modalFilter = ModalEventFilter.createFilterForDialog(this);
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1040
                    Conditional cond = new Conditional() {
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1041
                        @Override
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1042
                        public boolean evaluate() {
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1043
                            return windowClosingException == null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                    // if this dialog is toolkit-modal, the filter should be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    // to all EDTs (for all AppContexts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                        Iterator it = AppContext.getAppContexts().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                            AppContext appContext = (AppContext)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                            if (appContext == showAppContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                            // it may occur that EDT for appContext hasn't been started yet, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                            // we post an empty invocation event to trigger EDT initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                            Runnable createEDT = new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                                public void run() {};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                            eventQueue.postEvent(new InvocationEvent(this, createEDT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                            EventDispatchThread edt = eventQueue.getDispatchThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                            edt.addEventFilter(modalFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                    modalityPushed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                    try {
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1070
                        EventQueue eventQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
6636
a636784de382 6987896: Modal dialogs resumes the calling thread before it's hidden
art
parents: 6484
diff changeset
  1071
                        secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1072
                        if (!secondaryLoop.enter()) {
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1073
                            secondaryLoop = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                    } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                        modalityPopped();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    // if this dialog is toolkit-modal, its filter must be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                    // from all EDTs (for all AppContexts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                    if (modalityType == ModalityType.TOOLKIT_MODAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                        Iterator it = AppContext.getAppContexts().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                            AppContext appContext = (AppContext)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                            if (appContext == showAppContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                            EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                            EventDispatchThread edt = eventQueue.getDispatchThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                            edt.removeEventFilter(modalFilter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                    if (windowClosingException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                        windowClosingException.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                        throw windowClosingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                if (predictedFocusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                    // Restore normal key event dispatching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                    KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                        dequeueKeyEvents(time.get(), predictedFocusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    final void modalityPushed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        if (tk instanceof SunToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            SunToolkit stk = (SunToolkit)tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            stk.notifyModalityPushed(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    final void modalityPopped() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        if (tk instanceof SunToolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            SunToolkit stk = (SunToolkit)tk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            stk.notifyModalityPopped(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    void interruptBlocking() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        if (isModal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        } else if (windowClosingException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            windowClosingException.fillInStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            windowClosingException.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            windowClosingException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    }
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1134
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    private void hideAndDisposePreHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        isInHide = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        synchronized (getTreeLock()) {
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1138
            if (secondaryLoop != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                modalHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                // dialog can be shown and then disposed before its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                // modal filter is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                if (modalFilter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                    modalFilter.disable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                modalDialogs.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    private void hideAndDisposeHandler() {
6484
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1150
        if (secondaryLoop != null) {
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1151
            secondaryLoop.exit();
f5dbd940a640 6949936: Provide API for running nested events loops, similar to what modal dialogs do
art
parents: 5506
diff changeset
  1152
            secondaryLoop = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        isInHide = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * Hides the Dialog and then causes {@code show} to return if it is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * @see Window#show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @see Window#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * @see Window#setVisible(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * @deprecated As of JDK version 1.5, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * {@link #setVisible(boolean) setVisible(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        hideAndDisposePreHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        super.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        // fix for 5048370: if hide() is called from super.doDispose(), then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        // hideAndDisposeHandler() should not be called here as it will be called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        // at the end of doDispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        if (!isInDispose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            hideAndDisposeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * Disposes the Dialog and then causes show() to return if it is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        // fix for 5048370: set isInDispose flag to true to prevent calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // to hideAndDisposeHandler() from hide()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        isInDispose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        super.doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        hideAndDisposeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        isInDispose = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * If this dialog is modal and blocks some windows, then all of them are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * also sent to the back to keep them below the blocking dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @see java.awt.Window#toBack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
    public void toBack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        super.toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                for (Window w : blockedWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                    w.toBack_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * Indicates whether this dialog is resizable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * By default, all dialogs are initially resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @return    <code>true</code> if the user can resize the dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *            <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @see       java.awt.Dialog#setResizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
    public boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        return resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * Sets whether this dialog is resizable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @param     resizable <code>true</code> if the user can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     *                 resize this dialog; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * @see       java.awt.Dialog#isResizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    public void setResizable(boolean resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        boolean testvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            this.resizable = resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            DialogPeer peer = (DialogPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                peer.setResizable(resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                testvalid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        // On some platforms, changing the resizable state affects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        // the insets of the Dialog. If we could, we'd call invalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        // from the peer, but we need to guarantee that we're not holding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        // the Dialog lock when we call invalidate().
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
  1243
        if (testvalid) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
  1244
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * Disables or enables decorations for this dialog.
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1251
     * <p>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1252
     * This method can only be called while the dialog is not displayable. To
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1253
     * make this dialog decorated, it must be opaque and have the default shape,
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1254
     * otherwise the {@code IllegalComponentStateException} will be thrown.
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1255
     * Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1256
     * Window#setBackground} for details
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1257
     *
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1258
     * @param  undecorated {@code true} if no dialog decorations are to be
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1259
     *         enabled; {@code false} if dialog decorations are to be enabled
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1260
     *
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1261
     * @throws IllegalComponentStateException if the dialog is displayable
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1262
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1263
     *      {@code false}, and this dialog does not have the default shape
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1264
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1265
     *      {@code false}, and this dialog opacity is less than {@code 1.0f}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1266
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1267
     *      {@code false}, and the alpha value of this dialog background
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1268
     *      color is less than {@code 1.0f}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1269
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * @see    #isUndecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @see    Component#isDisplayable
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1272
     * @see    Window#getShape
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1273
     * @see    Window#getOpacity
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1274
     * @see    Window#getBackground
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1275
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    public void setUndecorated(boolean undecorated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        /* Make sure we don't run in the middle of peer creation.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            if (isDisplayable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                throw new IllegalComponentStateException("The dialog is displayable.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            }
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1284
            if (!undecorated) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1285
                if (getOpacity() < 1.0f) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1286
                    throw new IllegalComponentStateException("The dialog is not opaque");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1287
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1288
                if (getShape() != null) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1289
                    throw new IllegalComponentStateException("The dialog does not have a default shape");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1290
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1291
                Color bg = getBackground();
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1292
                if ((bg != null) && (bg.getAlpha() < 255)) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1293
                    throw new IllegalComponentStateException("The dialog background color is not opaque");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1294
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1295
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            this.undecorated = undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * Indicates whether this dialog is undecorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * By default, all dialogs are initially decorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * @return    <code>true</code> if dialog is undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     *                        <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @see       java.awt.Dialog#setUndecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    public boolean isUndecorated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        return undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    /**
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1313
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1314
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1315
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1316
    public void setOpacity(float opacity) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1317
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1318
            if ((opacity < 1.0f) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1319
                throw new IllegalComponentStateException("The dialog is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1320
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1321
            super.setOpacity(opacity);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1322
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1323
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1324
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1325
    /**
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1326
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1327
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1328
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1329
    public void setShape(Shape shape) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1330
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1331
            if ((shape != null) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1332
                throw new IllegalComponentStateException("The dialog is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1333
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1334
            super.setShape(shape);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1335
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1336
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1337
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1338
    /**
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1339
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1340
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1341
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1342
    public void setBackground(Color bgColor) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1343
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1344
            if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1345
                throw new IllegalComponentStateException("The dialog is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1346
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1347
            super.setBackground(bgColor);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1348
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1349
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1350
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 6636
diff changeset
  1351
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * Returns a string representing the state of this dialog. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * @return    the parameter string of this dialog window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        String str = super.paramString() + "," + modalityType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            str += ",title=" + title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * --- Modality support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * This method is called only for modal dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * Goes through the list of all visible top-level windows and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * divide them into three distinct groups: blockers of this dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * blocked by this dialog and all others. Then blocks this dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * by first met dialog from the first group (if any) and blocks all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * the windows from the second group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    void modalShow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // find all the dialogs that block this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        IdentityArrayList<Dialog> blockers = new IdentityArrayList<Dialog>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        for (Dialog d : modalDialogs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            if (d.shouldBlock(this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                Window w = d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                while ((w != null) && (w != this)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    w = (Window)(w.getOwner_NoClientCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                if ((w == this) || !shouldBlock(d) || (modalityType.compareTo(d.getModalityType()) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    blockers.add(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        // add all blockers' blockers to blockers :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        for (int i = 0; i < blockers.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            Dialog blocker = blockers.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            if (blocker.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                Dialog blockerBlocker = blocker.getModalBlocker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                if (!blockers.contains(blockerBlocker)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                    blockers.add(i + 1, blockerBlocker);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        if (blockers.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            blockers.get(0).blockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        // find all windows from blockers' hierarchies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
        IdentityArrayList<Window> blockersHierarchies = new IdentityArrayList<Window>(blockers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        int k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        while (k < blockersHierarchies.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
            Window w = blockersHierarchies.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            Window[] ownedWindows = w.getOwnedWindows_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            for (Window win : ownedWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                blockersHierarchies.add(win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            k++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        java.util.List<Window> toBlock = new IdentityLinkedList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        // block all windows from scope of blocking except from blockers' hierarchies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        IdentityArrayList<Window> unblockedWindows = Window.getAllUnblockedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        for (Window w : unblockedWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            if (shouldBlock(w) && !blockersHierarchies.contains(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                    Dialog wd = (Dialog)w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                    if (wd.shouldBlock(this) && (modalDialogs.indexOf(wd) > modalDialogs.indexOf(this))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                toBlock.add(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        blockWindows(toBlock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        if (!isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            updateChildrenBlocking();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * This method is called only for modal dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * Unblocks all the windows blocked by this modal dialog. After
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * each of them has been unblocked, it is checked to be blocked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * any other modal dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    void modalHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        // we should unblock all the windows first...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        IdentityArrayList<Window> save = new IdentityArrayList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        int blockedWindowsCount = blockedWindows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        for (int i = 0; i < blockedWindowsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            Window w = blockedWindows.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            save.add(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            unblockWindow(w); // also removes w from blockedWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        // ... and only after that check if they should be blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        // by another dialogs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        for (int i = 0; i < blockedWindowsCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            Window w = save.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
            if ((w instanceof Dialog) && ((Dialog)w).isModal_NoClientCode()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                Dialog d = (Dialog)w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                d.modalShow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                checkShouldBeBlocked(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * Returns whether the given top-level window should be blocked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * this dialog. Note, that the given window can be also a modal dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * and it should block this dialog, but this method do not take such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     * situations into consideration (such checks are performed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * modalShow() and modalHide() methods).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * This method should be called on the getTreeLock() lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    boolean shouldBlock(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        if (!isVisible_NoClientCode() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            (!w.isVisible_NoClientCode() && !w.isInShow) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            isInHide ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            (w == this) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            !isModal_NoClientCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        if ((w instanceof Dialog) && ((Dialog)w).isInHide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        // check if w is from children hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        // fix for 6271546: we should also take into consideration child hierarchies
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        // of this dialog's blockers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        Window blockerToCheck = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        while (blockerToCheck != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            Component c = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            while ((c != null) && (c != blockerToCheck)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                c = c.getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            if (c == blockerToCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            blockerToCheck = blockerToCheck.getModalBlocker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        switch (modalityType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            case MODELESS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            case DOCUMENT_MODAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                if (w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                    // application- and toolkit-excluded windows are not blocked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                    // document-modal dialogs from outside their children hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                    Component c = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                    while ((c != null) && (c != w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                        c = c.getParent_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                    return c == w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    return getDocumentRoot() == w.getDocumentRoot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
            case APPLICATION_MODAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                return !w.isModalExcluded(ModalExclusionType.APPLICATION_EXCLUDE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                    (appContext == w.appContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            case TOOLKIT_MODAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                return !w.isModalExcluded(ModalExclusionType.TOOLKIT_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * Adds the given top-level window to the list of blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * windows for this dialog and marks it as modal blocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     * If the window is already blocked by some modal dialog,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    void blockWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        if (!w.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            w.setModalBlocked(this, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            blockedWindows.add(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    void blockWindows(java.util.List<Window> toBlock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        DialogPeer dpeer = (DialogPeer)peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        if (dpeer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        Iterator<Window> it = toBlock.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        while (it.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            Window w = it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            if (!w.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                w.setModalBlocked(this, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        dpeer.blockWindows(toBlock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        blockedWindows.addAll(toBlock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * Removes the given top-level window from the list of blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * windows for this dialog and marks it as unblocked. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * window is not modal blocked, does nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
    void unblockWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        if (w.isModalBlocked() && blockedWindows.contains(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            blockedWindows.remove(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            w.setModalBlocked(this, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * Checks if any other modal dialog D blocks the given window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * If such D exists, mark the window as blocked by D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    static void checkShouldBeBlocked(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        synchronized (w.getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            for (int i = 0; i < modalDialogs.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                Dialog modalDialog = modalDialogs.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                if (modalDialog.shouldBlock(w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                    modalDialog.blockWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        // in 1.5 or earlier modalityType was absent, so use "modal" instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        if (modalityType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            setModal(modal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        blockedWindows = new IdentityArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * Gets the AccessibleContext associated with this Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     * For dialogs, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * AccessibleAWTDialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     * A new AccessibleAWTDialog instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * @return an AccessibleAWTDialog that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     *         AccessibleContext of this Dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
            accessibleContext = new AccessibleAWTDialog();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     * <code>Dialog</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
     * Java Accessibility API appropriate to dialog user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    protected class AccessibleAWTDialog extends AccessibleAWTWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        private static final long serialVersionUID = 4837230331833941201L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            return AccessibleRole.DIALOG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
         * Get the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            if (getFocusOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
            if (isModal()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                states.add(AccessibleState.MODAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                states.add(AccessibleState.RESIZABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
    } // inner class AccessibleAWTDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
}