src/java.desktop/share/classes/java/awt/Window.java
author darcy
Tue, 24 Sep 2019 18:25:54 -0700
changeset 58309 c6f8b2c3dc66
parent 52248 2e330da7cbf4
child 58329 483f14c3e0a2
permissions -rw-r--r--
8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51929
0e514f1549b4 8210692: The "com.sun.awt.SecurityWarning" class can be dropped
serb
parents: 47510
diff changeset
     2
 * Copyright (c) 1995, 2018, 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: 4371
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: 4371
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: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    25
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    28
import java.awt.event.ComponentEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    29
import java.awt.event.FocusEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    30
import java.awt.event.KeyEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    31
import java.awt.event.MouseWheelEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    32
import java.awt.event.WindowEvent;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    33
import java.awt.event.WindowFocusListener;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    34
import java.awt.event.WindowListener;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    35
import java.awt.event.WindowStateListener;
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
    36
import java.awt.geom.Path2D;
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
    37
import java.awt.geom.Point2D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.im.InputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.BufferStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.peer.WindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.io.OptionalDataException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.EventListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.util.concurrent.atomic.AtomicBoolean;
47510
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    59
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    60
import javax.accessibility.Accessible;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    61
import javax.accessibility.AccessibleContext;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    62
import javax.accessibility.AccessibleRole;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    63
import javax.accessibility.AccessibleState;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    64
import javax.accessibility.AccessibleStateSet;
6442b5049af7 8186617: The "com.sun.awt.AWTUtilities" class can be dropped in favour of public API
serb
parents: 47216
diff changeset
    65
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
    66
import sun.awt.AWTAccessor;
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21957
diff changeset
    67
import sun.awt.AWTPermissions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import sun.awt.AppContext;
32294
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
    69
import sun.awt.DebugSettings;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import sun.awt.util.IdentityArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import sun.security.action.GetPropertyAction;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3711
diff changeset
    74
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    77
 * A {@code Window} object is a top-level window with no borders and no
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * menubar.
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    79
 * The default layout for a window is {@code BorderLayout}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * A window must have either a frame, dialog, or another window defined as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * owner when it's constructed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    84
 * In a multi-screen environment, you can create a {@code Window}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    85
 * on a different screen device by constructing the {@code Window}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * with {@link #Window(Window, GraphicsConfiguration)}.  The
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    87
 * {@code GraphicsConfiguration} object is one of the
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
    88
 * {@code GraphicsConfiguration} objects of the target screen device.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * In a virtual device multi-screen environment in which the desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * area could span multiple physical screen devices, the bounds of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * configurations are relative to the virtual device coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * The origin of the virtual-coordinate system is at the upper left-hand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * corner of the primary physical screen.  Depending on the location of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * the primary screen in the virtual device, negative coordinates are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * possible, as shown in the following figure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <img src="doc-files/MultiScreen.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * alt="Diagram shows virtual device containing 4 physical screens. Primary physical screen shows coords (0,0), other screen shows (-80,-100)."
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20450
diff changeset
   100
 * style="float:center; margin: 7px 10px;">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   102
 * In such an environment, when calling {@code setLocation},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * you must pass a virtual coordinate to this method.  Similarly,
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   104
 * calling {@code getLocationOnScreen} on a {@code Window} returns
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   105
 * virtual device coordinates.  Call the {@code getBounds} method
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   106
 * of a {@code GraphicsConfiguration} to find its origin in the virtual
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   109
 * The following code sets the location of a {@code Window}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * at (10, 10) relative to the origin of the physical screen
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   111
 * of the corresponding {@code GraphicsConfiguration}.  If the
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   112
 * bounds of the {@code GraphicsConfiguration} is not taken
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   113
 * into account, the {@code Window} location would be set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * at (10, 10) relative to the virtual-coordinate system and would appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * on the primary physical screen, which might be different from the
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   116
 * physical screen of the specified {@code GraphicsConfiguration}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *      Window w = new Window(Window owner, GraphicsConfiguration gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *      Rectangle bounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *      w.setLocation(10 + bounds.x, 10 + bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * Note: the location and size of top-level windows (including
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   126
 * {@code Window}s, {@code Frame}s, and {@code Dialog}s)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * are under the control of the desktop's window management system.
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   128
 * Calls to {@code setLocation}, {@code setSize}, and
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   129
 * {@code setBounds} are requests (not directives) which are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * forwarded to the window management system.  Every effort will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * made to honor such requests.  However, in some cases the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * management system may ignore such requests, or modify the requested
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   133
 * geometry in order to place and size the {@code Window} in a way
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * that more closely matches the desktop settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * Due to the asynchronous nature of native event handling, the results
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   137
 * returned by {@code getBounds}, {@code getLocation},
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   138
 * {@code getLocationOnScreen}, and {@code getSize} might not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * reflect the actual geometry of the Window on screen until the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * request has been processed.  During the processing of subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * requests these values might change accordingly while the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * management system fulfills the requests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * An application may set the size and location of an invisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * {@code Window} arbitrarily, but the window management system may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * subsequently change its size and/or location when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * {@code Window} is made visible. One or more {@code ComponentEvent}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * will be generated to indicate the new geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * Windows are capable of generating the following WindowEvents:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * @see WindowEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * @see #addWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * @see java.awt.BorderLayout
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   158
 * @since       1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
public class Window extends Container implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   163
     * Enumeration of available <i>window types</i>.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   164
     *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   165
     * A window type defines the generic visual appearance and behavior of a
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   166
     * top-level window. For example, the type may affect the kind of
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   167
     * decorations of a decorated {@code Frame} or {@code Dialog} instance.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   168
     * <p>
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   169
     * Some platforms may not fully support a certain window type. Depending on
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   170
     * the level of support, some properties of the window type may be
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   171
     * disobeyed.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   172
     *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   173
     * @see   #getType
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   174
     * @see   #setType
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   175
     * @since 1.7
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   176
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   177
    public static enum Type {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   178
        /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   179
         * Represents a <i>normal</i> window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   180
         *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   181
         * This is the default type for objects of the {@code Window} class or
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   182
         * its descendants. Use this type for regular top-level windows.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   183
         */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   184
        NORMAL,
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   185
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   186
        /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   187
         * Represents a <i>utility</i> window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   188
         *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   189
         * A utility window is usually a small window such as a toolbar or a
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   190
         * palette. The native system may render the window with smaller
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   191
         * title-bar if the window is either a {@code Frame} or a {@code
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   192
         * Dialog} object, and if it has its decorations enabled.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   193
         */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   194
        UTILITY,
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   195
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   196
        /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   197
         * Represents a <i>popup</i> window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   198
         *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   199
         * A popup window is a temporary window such as a drop-down menu or a
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   200
         * tooltip. On some platforms, windows of that type may be forcibly
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   201
         * made undecorated even if they are instances of the {@code Frame} or
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   202
         * {@code Dialog} class, and have decorations enabled.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   203
         */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   204
        POPUP
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   205
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   206
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
   207
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * This represents the warning message that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * to be displayed in a non secure window. ie :
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   210
     * a window that has a security manager installed that denies
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   211
     * {@code AWTPermission("showWindowWithoutWarningBanner")}.
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   212
     * This message can be displayed anywhere in the window.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see #getWarningString
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    String      warningString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * {@code icons} is the graphical way we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * represent the frames and dialogs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * {@code Window} can't display icon but it's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * being inherited by owned {@code Dialog}s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see #getIconImages
21957
97758de70fbd 8028019: AWT Doclint warning/error cleanup
rriggs
parents: 21281
diff changeset
   227
     * @see #setIconImages
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    transient java.util.List<Image> icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Holds the reference to the component which last had focus in this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * before it lost focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private transient Component temporaryLostComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    static boolean systemSyncLWRequests = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    boolean     syncLWRequests = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    transient boolean beforeFirstShow = true;
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
   240
    private transient boolean disposing = false;
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   241
    transient WindowDisposerRecord disposerRecord = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    static final int OPENED = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * An Integer value representing the Window State.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see #show
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    int state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * A boolean value representing Window always-on-top state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see #setAlwaysOnTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @see #isAlwaysOnTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    private boolean alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Contains all the windows that have a peer object associated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * i. e. between addNotify() and removeNotify() calls. The list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * of all Window instances can be obtained from AppContext object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private static final IdentityArrayList<Window> allWindows = new IdentityArrayList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * A vector containing all the windows this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * window currently owns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #getOwnedWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    transient Vector<WeakReference<Window>> ownedWindowList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                            new Vector<WeakReference<Window>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * We insert a weak reference into the Vector of all Windows in AppContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * instead of 'this' so that garbage collection can still take place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    private transient WeakReference<Window> weakThis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    transient boolean showWithParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Contains the modal dialog that blocks this window, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * if the window is unblocked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    transient Dialog modalBlocker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @see java.awt.Dialog.ModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see #getModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @see #setModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    Dialog.ModalExclusionType modalExclusionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    transient WindowListener windowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    transient WindowStateListener windowStateListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    transient WindowFocusListener windowFocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    transient InputContext inputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private transient Object inputContextLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Unused. Maintained for serialization backward-compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    private FocusManager focusMgr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * Indicates whether this Window can become the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see #getFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see #setFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    private boolean focusableWindowState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Indicates whether this window should receive focus on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * subsequently being shown (with a call to {@code setVisible(true)}), or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * being moved to the front (with a call to {@code toFront()}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see #setAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @see #isAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    private volatile boolean autoRequestFocus = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * Indicates that this window is being shown. This flag is set to true at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * the beginning of show() and to false at the end of show().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @see #show()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see Dialog#shouldBlock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    transient boolean isInShow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   355
    /**
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   356
     * The opacity level of the window
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   357
     *
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
   358
     * @serial
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   359
     * @see #setOpacity(float)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   360
     * @see #getOpacity()
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   361
     * @since 1.7
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   362
     */
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
   363
    private volatile float opacity = 1.0f;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   364
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   365
    /**
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
   366
     * The shape assigned to this window. This field is set to {@code null} if
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   367
     * no shape is set (rectangular window).
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   368
     *
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
   369
     * @serial
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   370
     * @see #getShape()
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   371
     * @see #setShape(Shape)
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   372
     * @since 1.7
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   373
     */
58309
c6f8b2c3dc66 8231334: Suppress warnings on non-serializable instance fields in client libs serializable classes
darcy
parents: 52248
diff changeset
   374
    @SuppressWarnings("serial") // Not statically typed as Serializable
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   375
    private Shape shape = null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
   376
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private static final String base = "win";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private static final long serialVersionUID = 4497834738069338734L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 3711
diff changeset
   385
    private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Window");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    private static final boolean locationByPlatformProp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    transient boolean isTrayIconWindow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   391
    /**
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   392
     * These fields are initialized in the native peer code
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   393
     * or via AWTAccessor's WindowAccessor.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   394
     */
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   395
    private transient volatile int securityWarningWidth = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   396
    private transient volatile int securityWarningHeight = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
   397
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
11813
643f5bef6ab4 7144475: fix some warnings in java.awt, javax.print.attribute.standard, and sun.beans.infos
chegar
parents: 9210
diff changeset
   405
        String s = java.security.AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            new GetPropertyAction("java.awt.syncLWRequests"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        systemSyncLWRequests = (s != null && s.equals("true"));
11813
643f5bef6ab4 7144475: fix some warnings in java.awt, javax.print.attribute.standard, and sun.beans.infos
chegar
parents: 9210
diff changeset
   408
        s = java.security.AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            new GetPropertyAction("java.awt.Window.locationByPlatform"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        locationByPlatformProp = (s != null && s.equals("true"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Constructs a new, initially invisible window in default size with the
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   421
     * specified {@code GraphicsConfiguration}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * <p>
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   423
     * If there is a security manager, then it is invoked to check
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   424
     * {@code AWTPermission("showWindowWithoutWarningBanner")}
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   425
     * to determine whether or not the window must be displayed with
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   426
     * a warning banner.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   428
     * @param gc the {@code GraphicsConfiguration} of the target screen
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   429
     *     device. If {@code gc} is {@code null}, the system default
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   430
     *     {@code GraphicsConfiguration} is assumed
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   431
     * @exception IllegalArgumentException if {@code gc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *    is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @exception HeadlessException when
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   434
     *     {@code GraphicsEnvironment.isHeadless()} returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    Window(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        init(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    transient Object anchor = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   444
        WeakReference<Window> owner;
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
   445
        final WeakReference<Window> weakThis;
106
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   446
        final WeakReference<AppContext> context;
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   447
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        WindowDisposerRecord(AppContext context, Window victim) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            weakThis = victim.weakThis;
106
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   450
            this.context = new WeakReference<AppContext>(context);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   452
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   453
        public void updateOwner() {
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   454
            Window victim = weakThis.get();
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   455
            owner = (victim == null)
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   456
                    ? null
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   457
                    : new WeakReference<Window>(victim.getOwner());
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   458
        }
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   459
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        public void dispose() {
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   461
            if (owner != null) {
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   462
                Window parent = owner.get();
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   463
                if (parent != null) {
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   464
                    parent.removeOwnedWindow(weakThis);
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   465
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
106
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   467
            AppContext ac = context.get();
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   468
            if (null != ac) {
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   469
                Window.removeFromWindowList(ac, weakThis);
e8dca729bb5b 6616095: AWT's WindowDisposerRecord keeps AppContext alive too long
son
parents: 2
diff changeset
   470
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   474
    private GraphicsConfiguration initGC(GraphicsConfiguration gc) {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   475
        GraphicsEnvironment.checkHeadless();
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   476
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   477
        if (gc == null) {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   478
            gc = GraphicsEnvironment.getLocalGraphicsEnvironment().
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   479
                getDefaultScreenDevice().getDefaultConfiguration();
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   480
        }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   481
        setGraphicsConfiguration(gc);
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   482
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   483
        return gc;
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   484
    }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   485
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    private void init(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        syncLWRequests = systemSyncLWRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        weakThis = new WeakReference<Window>(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        addToWindowList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        setWarningString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        this.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        this.visible = false;
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   497
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   498
        gc = initGC(gc);
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   499
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   500
        if (gc.getDevice().getType() !=
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            GraphicsDevice.TYPE_RASTER_SCREEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            throw new IllegalArgumentException("not a screen device");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        setLayout(new BorderLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        /* offset the initial location with the original of the screen */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        /* and any insets                                              */
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   508
        Rectangle screenBounds = gc.getBounds();
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
   509
        Insets screenInsets = getToolkit().getScreenInsets(gc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        int x = getX() + screenBounds.x + screenInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        int y = getY() + screenBounds.y + screenInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (x != this.x || y != this.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            setLocation(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            /* reset after setLocation */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            setLocationByPlatform(locationByPlatformProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   519
        disposerRecord = new WindowDisposerRecord(appContext, this);
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   520
        sun.java2d.Disposer.addRecord(anchor, disposerRecord);
8136
d81295a8ece1 6741526: KeyboardFocusManager.setDefaultFocusTraversalPolicy(FocusTraversalPolicy) affects created components
dav
parents: 7668
diff changeset
   521
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 12651
diff changeset
   522
        SunToolkit.checkAndSetPolicy(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Constructs a new, initially invisible window in the default size.
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   527
     * <p>
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   528
     * If there is a security manager set, it is invoked to check
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   529
     * {@code AWTPermission("showWindowWithoutWarningBanner")}.
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   530
     * If that check fails with a {@code SecurityException} then a warning
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   531
     * banner is created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @exception HeadlessException when
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   534
     *     {@code GraphicsEnvironment.isHeadless()} returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    Window() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        init((GraphicsConfiguration)null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Constructs a new, initially invisible window with the specified
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   545
     * {@code Frame} as its owner. The window will not be focusable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * unless its owner is showing on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <p>
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   548
     * If there is a security manager set, it is invoked to check
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   549
     * {@code AWTPermission("showWindowWithoutWarningBanner")}.
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   550
     * If that check fails with a {@code SecurityException} then a warning
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   551
     * banner is created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   553
     * @param owner the {@code Frame} to act as owner or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *    if this window has no owner
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   555
     * @exception IllegalArgumentException if the {@code owner}'s
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   556
     *    {@code GraphicsConfiguration} is not from a screen device
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * @exception HeadlessException when
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   558
     *    {@code GraphicsEnvironment.isHeadless} returns {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    public Window(Frame owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        this(owner == null ? (GraphicsConfiguration)null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            owner.getGraphicsConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        ownedInit(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Constructs a new, initially invisible window with the specified
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   571
     * {@code Window} as its owner. This window will not be focusable
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   572
     * unless its nearest owning {@code Frame} or {@code Dialog}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * is showing on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <p>
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   575
     * If there is a security manager set, it is invoked to check
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   576
     * {@code AWTPermission("showWindowWithoutWarningBanner")}.
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   577
     * If that check fails with a {@code SecurityException} then a
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   578
     * warning banner is created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   580
     * @param owner the {@code Window} to act as owner or
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   581
     *     {@code null} if this window has no owner
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   582
     * @exception IllegalArgumentException if the {@code owner}'s
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   583
     *     {@code GraphicsConfiguration} is not from a screen device
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @exception HeadlessException when
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   585
     *     {@code GraphicsEnvironment.isHeadless()} returns
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   586
     *     {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @see       java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @since     1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public Window(Window owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        this(owner == null ? (GraphicsConfiguration)null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            owner.getGraphicsConfiguration());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        ownedInit(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * Constructs a new, initially invisible window with the specified owner
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   601
     * {@code Window} and a {@code GraphicsConfiguration}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * of a screen device. The Window will not be focusable unless
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   603
     * its nearest owning {@code Frame} or {@code Dialog}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * is showing on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <p>
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   606
     * If there is a security manager set, it is invoked to check
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   607
     * {@code AWTPermission("showWindowWithoutWarningBanner")}. If that
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   608
     * check fails with a {@code SecurityException} then a warning banner
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
   609
     * is created.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   611
     * @param owner the window to act as owner or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *     if this window has no owner
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   613
     * @param gc the {@code GraphicsConfiguration} of the target
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   614
     *     screen device; if {@code gc} is {@code null},
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   615
     *     the system default {@code GraphicsConfiguration} is assumed
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   616
     * @exception IllegalArgumentException if {@code gc}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *     is not from a screen device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @exception HeadlessException when
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   619
     *     {@code GraphicsEnvironment.isHeadless()} returns
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   620
     *     {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @see       java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @see       GraphicsConfiguration#getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * @see       #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @since     1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public Window(Window owner, GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        this(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        ownedInit(owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    private void ownedInit(Window owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        this.parent = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (owner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            owner.addOwnedWindow(weakThis);
20467
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   636
            if (owner.isAlwaysOnTop()) {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   637
                try {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   638
                    setAlwaysOnTop(true);
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   639
                } catch (SecurityException ignore) {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   640
                }
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
   641
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
1972
8aeb4ecbfa44 6758673: WeakReference leak in Window.ownedWindowList
art
parents: 1171
diff changeset
   643
8aeb4ecbfa44 6758673: WeakReference leak in Window.ownedWindowList
art
parents: 1171
diff changeset
   644
        // WindowDisposerRecord requires a proper value of parent field.
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
   645
        disposerRecord.updateOwner();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Construct a name for this component.  Called by getName() when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        synchronized (Window.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Returns the sequence of images to be displayed as the icon for this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * This method returns a copy of the internally stored list, so all operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * on the returned object will not affect the window's behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @return    the copy of icon images' list for this window, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *            empty list if this window doesn't have icon images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @see       #setIconImages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @see       #setIconImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @since     1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public java.util.List<Image> getIconImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        java.util.List<Image> icons = this.icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (icons == null || icons.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            return new ArrayList<Image>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        return new ArrayList<Image>(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Sets the sequence of images to be displayed as the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * for this window. Subsequent calls to {@code getIconImages} will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * always return a copy of the {@code icons} list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * Depending on the platform capabilities one or several images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * of different dimensions will be used as the window's icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * <p>
41395
2a6f7eb1dc23 8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents: 37694
diff changeset
   686
     * The {@code icons} list can contain {@code MultiResolutionImage} images also.
2a6f7eb1dc23 8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents: 37694
diff changeset
   687
     * Suitable image depending on screen resolution is extracted from
2a6f7eb1dc23 8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents: 37694
diff changeset
   688
     * base {@code MultiResolutionImage} image and added to the icons list
2a6f7eb1dc23 8149371: multi-res. image: -Dsun.java2d.uiScale does not work for Window icons (some ambiguity for Window.setIconImages()?)
rchamyal
parents: 37694
diff changeset
   689
     * while base resolution image is removed from list.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * The {@code icons} list is scanned for the images of most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * appropriate dimensions from the beginning. If the list contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * several images of the same size, the first will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <p>
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
   694
     * Ownerless windows with no icon specified use platform-default icon.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * The icon of an owned window may be inherited from the owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * unless explicitly overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * Setting the icon to {@code null} or empty list restores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * the default behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * Note : Native windowing systems may use different images of differing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * dimensions to represent a window, depending on the context (e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * window decoration, window list, taskbar, etc.). They could also use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * just a single image for all contexts or no image at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param     icons the list of icon images to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see       #getIconImages()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @see       #setIconImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @since     1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public synchronized void setIconImages(java.util.List<? extends Image> icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        this.icons = (icons == null) ? new ArrayList<Image>() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            new ArrayList<Image>(icons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            peer.updateIconImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        // Always send a property change event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        firePropertyChange("iconImage", null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * Sets the image to be displayed as the icon for this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * This method can be used instead of {@link #setIconImages setIconImages()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * to specify a single image as a window's icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * The following statement:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *     setIconImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * is equivalent to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *     ArrayList&lt;Image&gt; imageList = new ArrayList&lt;Image&gt;();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *     imageList.add(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *     setIconImages(imageList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Note : Native windowing systems may use different images of differing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * dimensions to represent a window, depending on the context (e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * window decoration, window list, taskbar, etc.). They could also use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * just a single image for all contexts or no image at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * @param     image the icon image to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @see       #setIconImages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @see       #getIconImages()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @since     1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public void setIconImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        ArrayList<Image> imageList = new ArrayList<Image>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            imageList.add(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        setIconImages(imageList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Makes this Window displayable by creating the connection to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * native screen resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * @see Container#removeNotify
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
   763
     * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            Container parent = this.parent;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   768
            if (parent != null && parent.peer == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                parent.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            if (peer == null) {
30471
c1568a2416a8 8074757: Remove java.awt.Toolkit methods which return peer types
serb
parents: 30469
diff changeset
   772
                peer = getComponentFactory().createWindow(this);
2455
e2d60882b891 6769607: PIT : Modal frame hangs for a while for few seconds in 6u12 b01 pit build
dcherepanov
parents: 2451
diff changeset
   773
            }
e2d60882b891 6769607: PIT : Modal frame hangs for a while for few seconds in 6u12 b01 pit build
dcherepanov
parents: 2451
diff changeset
   774
            synchronized (allWindows) {
e2d60882b891 6769607: PIT : Modal frame hangs for a while for few seconds in 6u12 b01 pit build
dcherepanov
parents: 2451
diff changeset
   775
                allWindows.add(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        }
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
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            synchronized (allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                allWindows.remove(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * Causes this Window to be sized to fit the preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * and layouts of its subcomponents. The resulting width and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * height of the window are automatically enlarged if either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * of dimensions is less than the minimum size as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * by the previous call to the {@code setMinimumSize} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * If the window and/or its owner are not displayable yet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * both of them are made displayable before calculating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * the preferred size. The Window is validated after its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * size is being calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 27766
diff changeset
   808
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    public void pack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        Container parent = this.parent;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
   811
        if (parent != null && parent.peer == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            parent.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        Dimension newSize = getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            setClientSize(newSize.width, newSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        if(beforeFirstShow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            isPacked = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
   826
        validateUnconditionally();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Sets the minimum size of this window to a constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * value.  Subsequent calls to {@code getMinimumSize}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * will always return this value. If current window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * size is less than {@code minimumSize} the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * window is automatically enlarged to honor the minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * If the {@code setSize} or {@code setBounds} methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * are called afterwards with a width or height less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * that was specified by the {@code setMinimumSize} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * the window is automatically enlarged to meet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * the {@code minimumSize} value. The {@code minimumSize}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * value also affects the behaviour of the {@code pack} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * The default behavior is restored by setting the minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * parameter to the {@code null} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Resizing operation may be restricted if the user tries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * to resize window below the {@code minimumSize} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * This behaviour is platform-dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @param minimumSize the new minimum size of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @see Component#setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @see #getMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * @see #isMinimumSizeSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @see #setSize(Dimension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @see #pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public void setMinimumSize(Dimension minimumSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            super.setMinimumSize(minimumSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            Dimension size = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                if (size.width < minimumSize.width || size.height < minimumSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                    int nw = Math.max(width, minimumSize.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    int nh = Math.max(height, minimumSize.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                    setSize(nw, nh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                ((WindowPeer)peer).updateMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
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
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * The {@code d.width} and {@code d.height} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * are automatically enlarged if either is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * the minimum size as specified by previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * {@code setMinimumSize}.
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   882
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   883
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   884
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   885
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   886
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @see #setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    public void setSize(Dimension d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        super.setSize(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * The {@code width} and {@code height} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * are automatically enlarged if either is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * the minimum size as specified by previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * {@code setMinimumSize}.
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   904
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   905
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   906
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   907
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   908
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @see #getSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @see #setBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    public void setSize(int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        super.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   920
     * {@inheritDoc}
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   921
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   922
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   923
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   924
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   925
     * in a way that corresponds closely to the desktop settings.
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   926
     */
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   927
    @Override
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   928
    public void setLocation(int x, int y) {
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   929
        super.setLocation(x, y);
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   930
    }
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   931
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   932
    /**
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   933
     * {@inheritDoc}
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   934
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   935
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   936
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   937
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   938
     * in a way that corresponds closely to the desktop settings.
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   939
     */
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   940
    @Override
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   941
    public void setLocation(Point p) {
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   942
        super.setLocation(p);
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   943
    }
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   944
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
   945
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @deprecated As of JDK version 1.1,
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
   947
     * replaced by {@code setBounds(int, int, int, int)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    public void reshape(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if (isMinimumSizeSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            Dimension minSize = getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            if (width < minSize.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                width = minSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            if (height < minSize.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                height = minSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        super.reshape(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    void setClientSize(int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            setBounds(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 32294
diff changeset
   970
    private static final AtomicBoolean
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        beforeFirstWindowShown = new AtomicBoolean(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
127
dca034368b70 6304277: PIT: Adding a TrayIcon closes a SplashScreen on Solaris but not on Win32
anthony
parents: 106
diff changeset
   973
    final void closeSplashScreen() {
dca034368b70 6304277: PIT: Adding a TrayIcon closes a SplashScreen on Solaris but not on Win32
anthony
parents: 106
diff changeset
   974
        if (isTrayIconWindow) {
dca034368b70 6304277: PIT: Adding a TrayIcon closes a SplashScreen on Solaris but not on Win32
anthony
parents: 106
diff changeset
   975
            return;
dca034368b70 6304277: PIT: Adding a TrayIcon closes a SplashScreen on Solaris but not on Win32
anthony
parents: 106
diff changeset
   976
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (beforeFirstWindowShown.getAndSet(false)) {
6823
cff6c85026c4 6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents: 5506
diff changeset
   978
            // We don't use SplashScreen.getSplashScreen() to avoid instantiating
cff6c85026c4 6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents: 5506
diff changeset
   979
            // the object if it hasn't been requested by user code explicitly
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            SunToolkit.closeSplashScreen();
6823
cff6c85026c4 6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents: 5506
diff changeset
   981
            SplashScreen.markClosed();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * Shows or hides this {@code Window} depending on the value of parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * If the method shows the window then the window is also made
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * focused under the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * <li> The {@code Window} meets the requirements outlined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     *      {@link #isFocusableWindow} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * <li> The {@code Window}'s {@code autoRequestFocus} property is of the {@code true} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * <li> Native windowing system allows the {@code Window} to get focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * There is an exception for the second condition (the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * {@code autoRequestFocus} property). The property is not taken into account if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * window is a modal dialog, which blocks the currently focused window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * Developers must never assume that the window is the focused or active window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * until it receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @param b  if {@code true}, makes the {@code Window} visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * otherwise hides the {@code Window}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * If the {@code Window} and/or its owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * are not yet displayable, both are made displayable.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * {@code Window} will be validated prior to being made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * If the {@code Window} is already visible, this will bring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * {@code Window} to the front.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * If {@code false}, hides this {@code Window}, its subcomponents, and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * of its owned children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * The {@code Window} and its subcomponents can be made visible again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * with a call to {@code #setVisible(true)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @see java.awt.Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * @see java.awt.Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * @see java.awt.Window#toFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * @see java.awt.Window#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @see java.awt.Window#setAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @see java.awt.Window#isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Makes the Window visible. If the Window and/or its owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * are not yet displayable, both are made displayable.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * Window will be validated prior to being made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * If the Window is already visible, this will bring the Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * to the front.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @see       Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @see       #toFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * @deprecated As of JDK version 1.5, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * {@link #setVisible(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    public void show() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  1041
        validateUnconditionally();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        isInShow = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            beforeFirstShow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            closeSplashScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            Dialog.checkShouldBeBlocked(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            super.show();
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
  1051
            locationByPlatform = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            for (int i = 0; i < ownedWindowList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                Window child = ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                if ((child != null) && child.showWithParent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                    child.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    child.showWithParent = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                }       // endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            }   // endfor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            if (!isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                updateChildrenBlocking();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                // fix for 6532736: after this window is shown, its blocker
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                // should be raised to front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                modalBlocker.toFront_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            if (this instanceof Frame || this instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                updateChildFocusableWindowState(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        isInShow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        // If first time shown, generate WindowOpened event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        if ((state & OPENED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            postWindowEvent(WindowEvent.WINDOW_OPENED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            state |= OPENED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    static void updateChildFocusableWindowState(Window w) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  1080
        if (w.peer != null && w.isShowing()) {
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  1081
            ((WindowPeer)w.peer).updateFocusableWindowState();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        for (int i = 0; i < w.ownedWindowList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            Window child = w.ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            if (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                updateChildFocusableWindowState(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    synchronized void postWindowEvent(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        if (windowListener != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            WindowEvent e = new WindowEvent(this, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            Toolkit.getEventQueue().postEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * Hide this Window, its subcomponents, and all of its owned children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * The Window and its subcomponents can be made visible again
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * with a call to {@code show}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @see #show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @see #dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @deprecated As of JDK version 1.5, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * {@link #setVisible(boolean)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    public void hide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        synchronized(ownedWindowList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            for (int i = 0; i < ownedWindowList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                Window child = ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                if ((child != null) && child.visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    child.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    child.showWithParent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            modalBlocker.unblockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        super.hide();
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
  1124
        locationByPlatform = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    final void clearMostRecentFocusOwnerOnHide() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Releases all of the native screen resources used by this
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1133
     * {@code Window}, its subcomponents, and all of its owned
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1134
     * children. That is, the resources for these {@code Component}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * will be destroyed, any memory they consume will be returned to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * OS, and they will be marked as undisplayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1138
     * The {@code Window} and its subcomponents can be made displayable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * again by rebuilding the native resources with a subsequent call to
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1140
     * {@code pack} or {@code show}. The states of the recreated
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1141
     * {@code Window} and its subcomponents will be identical to the
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1142
     * states of these objects at the point where the {@code Window}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * was disposed (not accounting for additional modifications between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * those actions).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * <b>Note</b>: When the last displayable window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * within the Java virtual machine (VM) is disposed of, the VM may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * terminate.  See <a href="doc-files/AWTThreadIssues.html#Autoshutdown">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * AWT Threading Issues</a> for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @see #pack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @see #show
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * Fix for 4872170.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * If dispose() is called on parent then its children have to be disposed as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * as reported in javadoc. So we need to implement this functionality even if a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * child overrides dispose() in a wrong way without calling super.dispose().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        dispose();
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  1166
        if (peer != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            doDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
    void doDispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
    class DisposeAction implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        public void run() {
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1174
            disposing = true;
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1175
            try {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1176
                // Check if this window is the fullscreen window for the
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1177
                // device. Exit the fullscreen mode prior to disposing
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1178
                // of the window if that's the case.
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1179
                GraphicsDevice gd = getGraphicsConfiguration().getDevice();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1180
                if (gd.getFullScreenWindow() == Window.this) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1181
                    gd.setFullScreenWindow(null);
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1182
                }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1183
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1184
                Object[] ownedWindowArray;
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1185
                synchronized(ownedWindowList) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1186
                    ownedWindowArray = new Object[ownedWindowList.size()];
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1187
                    ownedWindowList.copyInto(ownedWindowArray);
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1188
                }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1189
                for (int i = 0; i < ownedWindowArray.length; i++) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1190
                    Window child = (Window) (((WeakReference)
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1191
                                   (ownedWindowArray[i])).get());
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1192
                    if (child != null) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1193
                        child.disposeImpl();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1194
                    }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1195
                }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1196
                hide();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1197
                beforeFirstShow = true;
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1198
                removeNotify();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1199
                synchronized (inputContextLock) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1200
                    if (inputContext != null) {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1201
                        inputContext.dispose();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1202
                        inputContext = null;
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1203
                    }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1204
                }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1205
                clearCurrentFocusCycleRootOnHide();
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1206
            } finally {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  1207
                disposing = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    }
17901
88326b660820 8015500: Prevent sending multiple WINDOW_CLOSED events for already disposed windows
anthony
parents: 17150
diff changeset
  1211
        boolean fireWindowClosedEvent = isDisplayable();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        DisposeAction action = new DisposeAction();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if (EventQueue.isDispatchThread()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            action.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            try {
16092
129d7d8a7399 7192977: Issue in toolkit thread
bagiras
parents: 12661
diff changeset
  1218
                EventQueue.invokeAndWait(this, action);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                System.err.println("Disposal was interrupted:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                System.err.println("Exception during disposal:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        // Execute outside the Runnable because postWindowEvent is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        // synchronized on (this). We don't need to synchronize the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        // on the EventQueue anyways.
17901
88326b660820 8015500: Prevent sending multiple WINDOW_CLOSED events for already disposed windows
anthony
parents: 17150
diff changeset
  1232
        if (fireWindowClosedEvent) {
88326b660820 8015500: Prevent sending multiple WINDOW_CLOSED events for already disposed windows
anthony
parents: 17150
diff changeset
  1233
            postWindowEvent(WindowEvent.WINDOW_CLOSED);
88326b660820 8015500: Prevent sending multiple WINDOW_CLOSED events for already disposed windows
anthony
parents: 17150
diff changeset
  1234
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Should only be called while holding the tree lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * It's overridden here because parent == owner in Window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * and we shouldn't adjust counter on owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    void adjustListeningChildrenOnParent(long mask, int num) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    // Should only be called while holding tree lock
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  1246
    void adjustDescendantsOnParent(int num) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        // do nothing since parent == owner and we shouldn't
26749
b6598aa90114 8055326: Fix typos in client-related packages
serb
parents: 25859
diff changeset
  1248
        // adjust counter on owner
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * If this Window is visible, brings this Window to the front and may make
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * it the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * Places this Window at the top of the stacking order and shows it in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * front of any other Windows in this VM. No action will take place if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * Window is not visible. Some platforms do not allow Windows which own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * other Windows to appear on top of those owned Windows. Some platforms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * may not permit this VM to place its Windows above windows of native
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * applications, or Windows of other VMs. This permission may depend on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * whether a Window in this VM is already focused. Every attempt will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * made to move this Window as high as possible in the stacking order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * however, developers should not assume that this method will move this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * Window above all other windows in every situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * Developers must never assume that this Window is the focused or active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * event. On platforms where the top-most window is the focused window, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * method will <b>probably</b> focus this Window (if it is not already focused)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * under the following conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * <li> The window meets the requirements outlined in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     *      {@link #isFocusableWindow} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * <li> The window's property {@code autoRequestFocus} is of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     *      {@code true} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * <li> Native windowing system allows the window to get focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * On platforms where the stacking order does not typically affect the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * window, this method will <b>probably</b> leave the focused and active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * Windows unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * If this method causes this Window to be focused, and this Window is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * Frame or a Dialog, it will also become activated. If this Window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * focused, but it is not a Frame or a Dialog, then the first Frame or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * Dialog that is an owner of this Window will be activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * If this window is blocked by modal dialog, then the blocking dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * is brought to the front and remains above the blocked window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * @see       #toBack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * @see       #setAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * @see       #isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    public void toFront() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        toFront_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    // This functionality is implemented in a final package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    // to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    final void toFront_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                peer.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                modalBlocker.toFront_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * If this Window is visible, sends this Window to the back and may cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * it to lose focus or activation if it is the focused or active Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * Places this Window at the bottom of the stacking order and shows it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * behind any other Windows in this VM. No action will take place is this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * Window is not visible. Some platforms do not allow Windows which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * owned by other Windows to appear below their owners. Every attempt will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * be made to move this Window as low as possible in the stacking order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * however, developers should not assume that this method will move this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * Window below all other windows in every situation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * Because of variations in native windowing systems, no guarantees about
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * changes to the focused and active Windows can be made. Developers must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * never assume that this Window is no longer the focused or active Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * until this Window receives a WINDOW_LOST_FOCUS or WINDOW_DEACTIVATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * event. On platforms where the top-most window is the focused window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * this method will <b>probably</b> cause this Window to lose focus. In
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * that case, the next highest, focusable Window in this VM will receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * focus. On platforms where the stacking order does not typically affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * the focused window, this method will <b>probably</b> leave the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * and active Windows unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * @see       #toFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
    public void toBack() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        toBack_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
    // This functionality is implemented in a final package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    // to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
    final void toBack_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        if(isAlwaysOnTop()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                setAlwaysOnTop(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            }catch(SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                peer.toBack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * Returns the toolkit of this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * @return    the toolkit of this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @see       Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * @see       Toolkit#getDefaultToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * @see       Component#getToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    public Toolkit getToolkit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        return Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     * Gets the warning string that is displayed with this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * If this window is insecure, the warning string is displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * somewhere in the visible area of the window. A window is
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1373
     * insecure if there is a security manager and the security
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1374
     * manager denies
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1375
     * {@code AWTPermission("showWindowWithoutWarningBanner")}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1377
     * If the window is secure, then {@code getWarningString}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1378
     * returns {@code null}. If the window is insecure, this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * method checks for the system property
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1380
     * {@code awt.appletWarning}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     * and returns the string value of that property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * @return    the warning string for this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    public final String getWarningString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        return warningString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
    private void setWarningString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        warningString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        if (sm != null) {
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1392
            try {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21957
diff changeset
  1393
                sm.checkPermission(AWTPermissions.TOPLEVEL_WINDOW_PERMISSION);
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1394
            } catch (SecurityException se) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                // make sure the privileged action is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                // for getting the property! We don't want the
19807
9f7860fad128 8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents: 19361
diff changeset
  1397
                // above checkPermission call to always succeed!
11813
643f5bef6ab4 7144475: fix some warnings in java.awt, javax.print.attribute.standard, and sun.beans.infos
chegar
parents: 9210
diff changeset
  1398
                warningString = AccessController.doPrivileged(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                      new GetPropertyAction("awt.appletWarning",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                                            "Java Applet Window"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1406
     * Gets the {@code Locale} object that is associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * with this window, if the locale has been set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * If no locale has been set, then the default locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @return    the locale that is set for this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @see       java.util.Locale
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
  1412
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
      if (this.locale == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        return Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
      return this.locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * Gets the input context for this window. A window always has an input context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * which is shared by subcomponents unless they create and set their own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     * @see Component#getInputContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    public InputContext getInputContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        synchronized (inputContextLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            if (inputContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                inputContext = InputContext.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        return inputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * Set the cursor image to a specified cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * The method may have no visual effect if the Java platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * implementation and/or the native system do not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * changing the mouse cursor shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * @param     cursor One of the constants defined
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1443
     *            by the {@code Cursor} class. If this parameter is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     *            then the cursor for this window will be set to the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     *            Cursor.DEFAULT_CURSOR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * @see       Component#getCursor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * @see       Cursor
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23717
diff changeset
  1448
     * @since     1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
    public void setCursor(Cursor cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        if (cursor == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        super.setCursor(cursor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     * Returns the owner of this window.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1459
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1460
     * @return the owner of this window
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
    public Window getOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        return getOwner_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    final Window getOwner_NoClientCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        return (Window)parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * Return an array containing all the windows this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * window currently owns.
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1473
     *
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1474
     * @return the array of all the owned windows
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    public Window[] getOwnedWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        return getOwnedWindows_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    final Window[] getOwnedWindows_NoClientCode() {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 51929
diff changeset
  1481
        Window[] realCopy;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
        synchronized(ownedWindowList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            // Recall that ownedWindowList is actually a Vector of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            // WeakReferences and calling get() on one of these references
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            // may return null. Make two arrays-- one the size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            // Vector (fullCopy with size fullSize), and one the size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            // all non-null get()s (realCopy with size realSize).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            int fullSize = ownedWindowList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            int realSize = 0;
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 51929
diff changeset
  1491
            Window[] fullCopy = new Window[fullSize];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            for (int i = 0; i < fullSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                fullCopy[realSize] = ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                if (fullCopy[realSize] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                    realSize++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            if (fullSize != realSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                realCopy = Arrays.copyOf(fullCopy, realSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                realCopy = fullCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        return realCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    boolean isModalBlocked() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        return modalBlocker != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    void setModalBlocked(Dialog blocker, boolean blocked, boolean peerCall) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        this.modalBlocker = blocked ? blocker : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        if (peerCall) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                peer.setModalBlocked(blocker, blocked);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    Dialog getModalBlocker() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        return modalBlocker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
     * Returns a list of all displayable Windows, i. e. all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * Windows which peer is not null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
    static IdentityArrayList<Window> getAllWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        synchronized (allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            IdentityArrayList<Window> v = new IdentityArrayList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            v.addAll(allWindows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
            return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    static IdentityArrayList<Window> getAllUnblockedWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        synchronized (allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
            for (int i = 0; i < allWindows.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                Window w = allWindows.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                if (!w.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                    unblocked.add(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
            return unblocked;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
    private static Window[] getWindows(AppContext appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        synchronized (Window.class) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 51929
diff changeset
  1559
            Window[] realCopy;
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  1560
            @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            Vector<WeakReference<Window>> windowList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                (Vector<WeakReference<Window>>)appContext.get(Window.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            if (windowList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                int fullSize = windowList.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                int realSize = 0;
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 51929
diff changeset
  1566
                Window[] fullCopy = new Window[fullSize];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                for (int i = 0; i < fullSize; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    Window w = windowList.get(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    if (w != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                        fullCopy[realSize++] = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                if (fullSize != realSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                    realCopy = Arrays.copyOf(fullCopy, realSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    realCopy = fullCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                realCopy = new Window[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            return realCopy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * Returns an array of all {@code Window}s, both owned and ownerless,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * created by this application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * If called from an applet, the array includes only the {@code Window}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * accessible by that applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * <b>Warning:</b> this method may return system created windows, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     * as a print dialog. Applications should not assume the existence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * these dialogs, nor should an application assume anything about these
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1594
     * dialogs such as component positions, {@code LayoutManager}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     * or serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1597
     * @return the array of all the {@code Window}s created by the application
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * @see Frame#getFrames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * @see Window#getOwnerlessWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
    public static Window[] getWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        return getWindows(AppContext.getAppContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * Returns an array of all {@code Window}s created by this application
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * that have no owner. They include {@code Frame}s and ownerless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     * {@code Dialog}s and {@code Window}s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * If called from an applet, the array includes only the {@code Window}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * accessible by that applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * <b>Warning:</b> this method may return system created windows, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * as a print dialog. Applications should not assume the existence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * these dialogs, nor should an application assume anything about these
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1617
     * dialogs such as component positions, {@code LayoutManager}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * or serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1620
     * @return the array of all the ownerless {@code Window}s
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  1621
     *         created by this application
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
     * @see Frame#getFrames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
     * @see Window#getWindows()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    public static Window[] getOwnerlessWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        Window[] allWindows = Window.getWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
        int ownerlessCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
        for (Window w : allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            if (w.getOwner() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                ownerlessCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        Window[] ownerless = new Window[ownerlessCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        int c = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        for (Window w : allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            if (w.getOwner() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                ownerless[c++] = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        return ownerless;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
    Window getDocumentRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            Window w = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            while (w.getOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                w = w.getOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            return w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
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
     * Specifies the modal exclusion type for this window. If a window is modal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * excluded, it is not blocked by some modal dialogs. See {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     * java.awt.Dialog.ModalExclusionType Dialog.ModalExclusionType} for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
     * possible modal exclusion types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
     * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1664
     * If the given type is not supported, {@code NO_EXCLUDE} is used.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
     * Note: changing the modal exclusion type for a visible window may have no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
     * effect until it is hidden and then shown again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1669
     * @param exclusionType the modal exclusion type for this window; a {@code null}
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21262
diff changeset
  1670
     *     value is equivalent to {@link Dialog.ModalExclusionType#NO_EXCLUDE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     *     NO_EXCLUDE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * @throws SecurityException if the calling thread does not have permission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     *     to set the modal exclusion property to the window with the given
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1674
     *     {@code exclusionType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
     * @see java.awt.Dialog.ModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
     * @see java.awt.Window#getModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
     * @see java.awt.Toolkit#isModalExclusionTypeSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
    public void setModalExclusionType(Dialog.ModalExclusionType exclusionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        if (exclusionType == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        if (!Toolkit.getDefaultToolkit().isModalExclusionTypeSupported(exclusionType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        if (modalExclusionType == exclusionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            if (sm != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21957
diff changeset
  1694
                sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        modalExclusionType = exclusionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        // if we want on-fly changes, we need to uncomment the lines below
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
        //   and override the method in Dialog to use modalShow() instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        //   of updateChildrenBlocking()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
 /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        if (isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
            modalBlocker.unblockWindow(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        Dialog.checkShouldBeBlocked(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        updateChildrenBlocking();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * Returns the modal exclusion type of this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * @return the modal exclusion type of this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * @see java.awt.Dialog.ModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * @see java.awt.Window#setModalExclusionType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    public Dialog.ModalExclusionType getModalExclusionType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
        return modalExclusionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    boolean isModalExcluded(Dialog.ModalExclusionType exclusionType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
        if ((modalExclusionType != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
            modalExclusionType.compareTo(exclusionType) >= 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        Window owner = getOwner_NoClientCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        return (owner != null) && owner.isModalExcluded(exclusionType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    void updateChildrenBlocking() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        Vector<Window> childHierarchy = new Vector<Window>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        Window[] ownedWindows = getOwnedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        for (int i = 0; i < ownedWindows.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            childHierarchy.add(ownedWindows[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        int k = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        while (k < childHierarchy.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            Window w = childHierarchy.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
            if (w.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                if (w.isModalBlocked()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                    Dialog blocker = w.getModalBlocker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                    blocker.unblockWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                Dialog.checkShouldBeBlocked(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                Window[] wOwned = w.getOwnedWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                for (int j = 0; j < wOwned.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    childHierarchy.add(wOwned[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            k++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * Adds the specified window listener to receive window events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * @param   l the window listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @see #removeWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * @see #getWindowListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
    public synchronized void addWindowListener(WindowListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        windowListener = AWTEventMulticaster.add(windowListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * Adds the specified window state listener to receive window
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1780
     * events from this window.  If {@code l} is {@code null},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * @param   l the window state listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * @see #removeWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * @see #getWindowStateListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
    public synchronized void addWindowStateListener(WindowStateListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
        windowStateListener = AWTEventMulticaster.add(windowStateListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * Adds the specified window focus listener to receive window events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * from this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * @param   l the window focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * @see #removeWindowFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * @see #getWindowFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
    public synchronized void addWindowFocusListener(WindowFocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        windowFocusListener = AWTEventMulticaster.add(windowFocusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        newEventsOnly = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * Removes the specified window listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * receives window events from this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * @param   l the window listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * @see #addWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * @see #getWindowListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
    public synchronized void removeWindowListener(WindowListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        windowListener = AWTEventMulticaster.remove(windowListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * Removes the specified window state listener so that it no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * longer receives window events from this window.  If
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1839
     * {@code l} is {@code null}, no exception is thrown and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * @param   l the window state listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * @see #addWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * @see #getWindowStateListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
    public synchronized void removeWindowStateListener(WindowStateListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        windowStateListener = AWTEventMulticaster.remove(windowStateListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * Removes the specified window focus listener so that it no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * receives window events from this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * If l is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * >AWT Threading Issues</a> for details on AWT's threading model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * @param   l the window focus listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * @see #addWindowFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @see #getWindowFocusListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
    public synchronized void removeWindowFocusListener(WindowFocusListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        if (l == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        windowFocusListener = AWTEventMulticaster.remove(windowFocusListener, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     * Returns an array of all the window listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     * registered on this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1879
     * @return all of this window's {@code WindowListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     *         or an empty array if no window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     * @see #addWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     * @see #removeWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    public synchronized WindowListener[] getWindowListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  1888
        return getListeners(WindowListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     * Returns an array of all the window focus listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
     * registered on this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1895
     * @return all of this window's {@code WindowFocusListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     *         or an empty array if no window focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * @see #addWindowFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * @see #removeWindowFocusListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
    public synchronized WindowFocusListener[] getWindowFocusListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  1904
        return getListeners(WindowFocusListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * Returns an array of all the window state listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     * registered on this window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1911
     * @return all of this window's {@code WindowStateListener}s
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     *         or an empty array if no window state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * @see #addWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * @see #removeWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    public synchronized WindowStateListener[] getWindowStateListeners() {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  1920
        return getListeners(WindowStateListener.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * Returns an array of all the objects currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * as <code><em>Foo</em>Listener</code>s
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1927
     * upon this {@code Window}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * <code><em>Foo</em>Listener</code>s are registered using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * <code>add<em>Foo</em>Listener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1933
     * You can specify the {@code listenerType} argument
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * with a class literal, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     * <code><em>Foo</em>Listener.class</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * For example, you can query a
35667
ed476aba94de 8138838: docs cleanup for java.desktop
avstepan
parents: 33510
diff changeset
  1937
     * {@code Window w}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * for its window listeners with the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * <pre>WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     * If no such listeners exist, this method returns an empty array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     * @param listenerType the type of listeners requested; this parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     *          should specify an interface that descends from
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1946
     *          {@code java.util.EventListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * @return an array of all objects registered as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     *          <code><em>Foo</em>Listener</code>s on this window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     *          or an empty array if no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     *          listeners have been added
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1951
     * @exception ClassCastException if {@code listenerType}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
     *          doesn't specify a class or interface that implements
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  1953
     *          {@code java.util.EventListener}
7154
4e8371f358ac 6877895: Some AWT's methods should specify throwing NPE for null arg value
dcherepanov
parents: 6823
diff changeset
  1954
     * @exception NullPointerException if {@code listenerType} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * @see #getWindowListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
    public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        EventListener l = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
        if (listenerType == WindowFocusListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            l = windowFocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        } else if (listenerType == WindowStateListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            l = windowStateListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        } else if (listenerType == WindowListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            l = windowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
            return super.getListeners(listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        return AWTEventMulticaster.getListeners(l, listenerType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
    // REMIND: remove when filtering is handled at lower level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
    boolean eventEnabled(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        switch(e.id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
          case WindowEvent.WINDOW_OPENED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
          case WindowEvent.WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
          case WindowEvent.WINDOW_CLOSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
          case WindowEvent.WINDOW_ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
          case WindowEvent.WINDOW_DEICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
          case WindowEvent.WINDOW_ACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
          case WindowEvent.WINDOW_DEACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                windowListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
          case WindowEvent.WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
          case WindowEvent.WINDOW_LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                windowFocusListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
          case WindowEvent.WINDOW_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            if ((eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                windowStateListener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        return super.eventEnabled(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * Processes events on this window. If the event is an
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2009
     * {@code WindowEvent}, it invokes the
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2010
     * {@code processWindowEvent} method, else it invokes its
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2011
     * superclass's {@code processEvent}.
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2012
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    protected void processEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        if (e instanceof WindowEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                case WindowEvent.WINDOW_OPENED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                case WindowEvent.WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                case WindowEvent.WINDOW_CLOSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                case WindowEvent.WINDOW_ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                case WindowEvent.WINDOW_DEICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                case WindowEvent.WINDOW_ACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                case WindowEvent.WINDOW_DEACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                    processWindowEvent((WindowEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                case WindowEvent.WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                case WindowEvent.WINDOW_LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                    processWindowFocusEvent((WindowEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
                case WindowEvent.WINDOW_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
                    processWindowStateEvent((WindowEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
        super.processEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * Processes window events occurring on this window by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * dispatching them to any registered WindowListener objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * NOTE: This method will not be called unless window events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * are enabled for this component; this happens when one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * <li>A WindowListener object is registered via
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2051
     *     {@code addWindowListener}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2052
     * <li>Window events are enabled via {@code enableEvents}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * </ul>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2054
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * @param e the window event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * @see Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
    protected void processWindowEvent(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
        WindowListener listener = windowListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
            switch(e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                case WindowEvent.WINDOW_OPENED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                    listener.windowOpened(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                case WindowEvent.WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                    listener.windowClosing(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                case WindowEvent.WINDOW_CLOSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                    listener.windowClosed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
                case WindowEvent.WINDOW_ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
                    listener.windowIconified(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                case WindowEvent.WINDOW_DEICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                    listener.windowDeiconified(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                case WindowEvent.WINDOW_ACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                    listener.windowActivated(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                case WindowEvent.WINDOW_DEACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                    listener.windowDeactivated(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21262
diff changeset
  2093
     * Processes window focus event occurring on this window by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * dispatching them to any registered WindowFocusListener objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * NOTE: this method will not be called unless window focus events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * are enabled for this window. This happens when one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     * <li>a WindowFocusListener is registered via
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2100
     *     {@code addWindowFocusListener}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2101
     * <li>Window focus events are enabled via {@code enableEvents}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     * </ul>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2103
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * @param e the window focus event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * @see Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
    protected void processWindowFocusEvent(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
        WindowFocusListener listener = windowFocusListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
                case WindowEvent.WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
                    listener.windowGainedFocus(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                case WindowEvent.WINDOW_LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                    listener.windowLostFocus(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21262
diff changeset
  2128
     * Processes window state event occurring on this window by
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2129
     * dispatching them to any registered {@code WindowStateListener}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * NOTE: this method will not be called unless window state events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * are enabled for this window.  This happens when one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * following occurs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * <ul>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2135
     * <li>a {@code WindowStateListener} is registered via
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2136
     *    {@code addWindowStateListener}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2137
     * <li>window state events are enabled via {@code enableEvents}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     * </ul>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2139
     * <p>Note that if the event parameter is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * the behavior is unspecified and may result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     * @param e the window state event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * @see java.awt.Component#enableEvents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    protected void processWindowStateEvent(WindowEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
        WindowStateListener listener = windowStateListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        if (listener != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
            switch (e.getID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                case WindowEvent.WINDOW_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                    listener.windowStateChanged(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
     * Implements a debugging hook -- checks to see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
     * the user has typed <i>control-shift-F1</i>.  If so,
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2163
     * the list of child windows is dumped to {@code System.out}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * @param e  the keyboard event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
    void preProcessKeyEvent(KeyEvent e) {
32294
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2167
        // Dump the list of child windows to System.out if debug is enabled.
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2168
        if (DebugSettings.getInstance().getBoolean("on", false)) {
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2169
            if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_F1 &&
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2170
                    e.isControlDown() && e.isShiftDown() &&
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2171
                    e.getID() == KeyEvent.KEY_PRESSED) {
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2172
                list(System.out, 0);
58789f875b54 4379403: Need to disable the "magic AWT dump key" (CTRL+SHIFT+F1)
serb
parents: 30471
diff changeset
  2173
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
    void postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        // Do nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     * Sets whether this window should always be above other windows.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
     * there are multiple always-on-top windows, their relative order is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
     * unspecified and platform dependent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * If some other window is already always-on-top then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * relative order between these windows is unspecified (depends on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * platform).  No window can be brought to be over the always-on-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * window except maybe another always-on-top window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * All windows owned by an always-on-top window inherit this state and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * automatically become always-on-top.  If a window ceases to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * always-on-top, the windows that it owns will no longer be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * always-on-top.  When an always-on-top window is sent {@link #toBack
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2196
     * toBack}, its always-on-top state is set to {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * <p> When this method is called on a window with a value of
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2199
     * {@code true}, and the window is visible and the platform
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * supports always-on-top for this window, the window is immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * brought forward, "sticking" it in the top-most position. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * window isn`t currently visible, this method sets the always-on-top
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2203
     * state to {@code true} but does not bring the window forward.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * When the window is later shown, it will be always-on-top.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * <p> When this method is called on a window with a value of
21262
88e6e648168e 8025225: Window.setAlwaysOnTop documentation should be updated
serb
parents: 20467
diff changeset
  2207
     * {@code false} the always-on-top state is set to normal. It may also
88e6e648168e 8025225: Window.setAlwaysOnTop documentation should be updated
serb
parents: 20467
diff changeset
  2208
     * cause an unspecified, platform-dependent change in the z-order of
88e6e648168e 8025225: Window.setAlwaysOnTop documentation should be updated
serb
parents: 20467
diff changeset
  2209
     * top-level windows, but other always-on-top windows will remain in
88e6e648168e 8025225: Window.setAlwaysOnTop documentation should be updated
serb
parents: 20467
diff changeset
  2210
     * top-most position. Calling this method with a value of {@code false}
88e6e648168e 8025225: Window.setAlwaysOnTop documentation should be updated
serb
parents: 20467
diff changeset
  2211
     * on a window that has a normal state has no effect.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * <p><b>Note</b>: some platforms might not support always-on-top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * windows.  To detect if always-on-top windows are supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * current platform, use {@link Toolkit#isAlwaysOnTopSupported()} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * {@link Window#isAlwaysOnTopSupported()}.  If always-on-top mode
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2217
     * isn't supported for this window or this window's toolkit does not
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2218
     * support always-on-top windows, calling this method has no effect.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * If a SecurityManager is installed, the calling thread must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * granted the AWTPermission "setWindowAlwaysOnTop" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * order to set the value of this property. If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * permission is not granted, this method will throw a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     * SecurityException, and the current value of the property will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
     * be left unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * @param alwaysOnTop true if the window should always be above other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     *        windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * @throws SecurityException if the calling thread does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     *         permission to set the value of always-on-top property
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2231
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
     * @see #isAlwaysOnTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
     * @see #toFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
     * @see #toBack
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
     * @see AWTPermission
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
     * @see #isAlwaysOnTopSupported
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2237
     * @see #getToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
     * @see Toolkit#isAlwaysOnTopSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        if (security != null) {
22060
cd4f9d7dbeda 8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents: 21957
diff changeset
  2244
            security.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        boolean oldAlwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            oldAlwaysOnTop = this.alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            this.alwaysOnTop = alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
        if (oldAlwaysOnTop != alwaysOnTop ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
            if (isAlwaysOnTopSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
                synchronized(getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
                    if (peer != null) {
16892
24a521782b42 8006790: Improve checking for windows
malenkov
parents: 16100
diff changeset
  2257
                        peer.updateAlwaysOnTopState();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
            firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
        }
27766
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2263
        setOwnedWindowsAlwaysOnTop(alwaysOnTop);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2264
    }
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2265
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2266
    @SuppressWarnings({"rawtypes", "unchecked"})
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2267
    private void setOwnedWindowsAlwaysOnTop(boolean alwaysOnTop) {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2268
        WeakReference<Window>[] ownedWindowArray;
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2269
        synchronized (ownedWindowList) {
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2270
            ownedWindowArray = new WeakReference[ownedWindowList.size()];
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2271
            ownedWindowList.copyInto(ownedWindowArray);
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2272
        }
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2273
e3dd9610de38 8064468: ownedWindowList access requires synchronization in Window.setAlwaysOnTop() method
alexsch
parents: 26749
diff changeset
  2274
        for (WeakReference<Window> ref : ownedWindowArray) {
20467
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2275
            Window window = ref.get();
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2276
            if (window != null) {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2277
                try {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2278
                    window.setAlwaysOnTop(alwaysOnTop);
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2279
                } catch (SecurityException ignore) {
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2280
                }
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2281
            }
c516e99769d7 7081594: Windows owned by an always-on-top window DO NOT automatically become always-on-top
alexsch
parents: 20465
diff changeset
  2282
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * Returns whether the always-on-top mode is supported for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * window. Some platforms may not support always-on-top windows, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * may support only some kinds of top-level windows; for example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * a platform may not support always-on-top modal dialogs.
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2290
     *
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2291
     * @return {@code true}, if the always-on-top mode is supported for
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2292
     *         this window and this window's toolkit supports always-on-top windows,
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2293
     *         {@code false} otherwise
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2294
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
     * @see #setAlwaysOnTop(boolean)
20465
b08b3909ee92 7081584: Specification for Window.isAlwaysOnTopSupported needs to be clarified
malenkov
parents: 20454
diff changeset
  2296
     * @see #getToolkit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
     * @see Toolkit#isAlwaysOnTopSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
    public boolean isAlwaysOnTopSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * Returns whether this window is an always-on-top window.
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2307
     * @return {@code true}, if the window is in always-on-top state,
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2308
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     * @see #setAlwaysOnTop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    public final boolean isAlwaysOnTop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        return alwaysOnTop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * Returns the child Component of this Window that has focus if this Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * is focused; returns null otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * @return the child Component with focus, or null if this Window is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     *         focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * @see #getMostRecentFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * @see #isFocused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
    public Component getFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
        return (isFocused())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            ? KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                  getFocusOwner()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
     * Returns the child Component of this Window that will receive the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * when this Window is focused. If this Window is currently focused, this
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2336
     * method returns the same Component as {@code getFocusOwner()}. If
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * this Window is not focused, then the child Component that most recently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * requested focus will be returned. If no child Component has ever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * requested focus, and this is a focusable Window, then this Window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     * initial focusable Component is returned. If no child Component has ever
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * requested focus, and this is a non-focusable Window, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * @return the child Component that will receive focus when this Window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     *         focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * @see #getFocusOwner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     * @see #isFocused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
     * @see #isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    public Component getMostRecentFocusOwner() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        if (isFocused()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            return getFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
            Component mostRecent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                KeyboardFocusManager.getMostRecentFocusOwner(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            if (mostRecent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                return mostRecent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
                return (isFocusableWindow())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
                    ? getFocusTraversalPolicy().getInitialComponent(this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                    : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     * Returns whether this Window is active. Only a Frame or a Dialog may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     * active. The native windowing system may denote the active Window or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     * children with special decorations, such as a highlighted title bar. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
     * active Window is always either the focused Window, or the first Frame or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
     * Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
     * @return whether this is the active Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
     * @see #isFocused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
    public boolean isActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
        return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                getActiveWindow() == this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * Returns whether this Window is focused. If there exists a focus owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     * the focused Window is the Window that is, or contains, that focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
     * If there is no focus owner, then no Window is focused.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
     * If the focused Window is a Frame or a Dialog it is also the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
     * Window. Otherwise, the active Window is the first Frame or Dialog that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
     * is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
     * @return whether this is the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
     * @see #isActive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
    public boolean isFocused() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
                getGlobalFocusedWindow() == this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2401
     * Gets a focus traversal key for this Window. (See {@code
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2402
     * setFocusTraversalKeys} for a full description of each key.)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * If the traversal key has not been explicitly set for this Window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * then this Window's parent's traversal key is returned. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * traversal key has not been explicitly set for any of this Window's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     * ancestors, then the current KeyboardFocusManager's default traversal key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
     * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
     *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
     * @return the AWTKeyStroke for the specified key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
     * @see Container#setFocusTraversalKeys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
     * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
     * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
     * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * @throws IllegalArgumentException if id is not one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
     *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
     *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
     *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     */
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2427
    @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
        if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
            throw new IllegalArgumentException("invalid focus traversal key identifier");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        // Okay to return Set directly because it is an unmodifiable view
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2434
        @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        Set keystrokes = (focusTraversalKeys != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            ? focusTraversalKeys[id]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
        if (keystrokes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
            return keystrokes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
            return KeyboardFocusManager.getCurrentKeyboardFocusManager().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                getDefaultFocusTraversalKeys(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     * Does nothing because Windows must always be roots of a focus traversal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     * cycle. The passed-in value is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
     * @param focusCycleRoot this value is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
     * @see #isFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
     * @see Container#setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
     * @see Container#getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
    public final void setFocusCycleRoot(boolean focusCycleRoot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2461
     * Always returns {@code true} because all Windows must be roots of a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
     * focus traversal cycle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2464
     * @return {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
     * @see #setFocusCycleRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
     * @see Container#setFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
     * @see Container#getFocusTraversalPolicy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    public final boolean isFocusCycleRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2475
     * Always returns {@code null} because Windows have no ancestors; they
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
     * represent the top of the Component hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2478
     * @return {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
     * @see Container#isFocusCycleRoot()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    public final Container getFocusCycleRootAncestor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * Returns whether this Window can become the focused Window, that is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * whether this Window or any of its subcomponents can become the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * owner. For a Frame or Dialog to be focusable, its focusable Window state
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2490
     * must be set to {@code true}. For a Window which is not a Frame or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * Dialog to be focusable, its focusable Window state must be set to
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2492
     * {@code true}, its nearest owning Frame or Dialog must be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * showing on the screen, and it must contain at least one Component in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * its focus traversal cycle. If any of these conditions is not met, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     * neither this Window nor any of its subcomponents can become the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2498
     * @return {@code true} if this Window can be the focused Window;
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2499
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
     * @see #getFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
     * @see #setFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * @see Component#isFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
    public final boolean isFocusableWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
        // If a Window/Frame/Dialog was made non-focusable, then it is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        // non-focusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        if (!getFocusableWindowState()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        // All other tests apply only to Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        if (this instanceof Frame || this instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        // A Window must have at least one Component in its root focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        // traversal cycle to be focusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
        if (getFocusTraversalPolicy().getDefaultComponent(this) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
        // A Window's nearest owning Frame or Dialog must be showing on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        // screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
        for (Window owner = getOwner(); owner != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
             owner = owner.getOwner())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
            if (owner instanceof Frame || owner instanceof Dialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                return owner.isShowing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
     * Returns whether this Window can become the focused Window if it meets
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2539
     * the other requirements outlined in {@code isFocusableWindow}. If
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2540
     * this method returns {@code false}, then
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2541
     * {@code isFocusableWindow} will return {@code false} as well.
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2542
     * If this method returns {@code true}, then
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2543
     * {@code isFocusableWindow} may return {@code true} or
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2544
     * {@code false} depending upon the other requirements which must be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
     * met in order for a Window to be focusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * By default, all Windows have a focusable Window state of
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2548
     * {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
     * @return whether this Window can be the focused Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
     * @see #isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
     * @see #setFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
     * @see Component#setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
    public boolean getFocusableWindowState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
        return focusableWindowState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * Sets whether this Window can become the focused Window if it meets
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2563
     * the other requirements outlined in {@code isFocusableWindow}. If
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2564
     * this Window's focusable Window state is set to {@code false}, then
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2565
     * {@code isFocusableWindow} will return {@code false}. If this
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2566
     * Window's focusable Window state is set to {@code true}, then
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2567
     * {@code isFocusableWindow} may return {@code true} or
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2568
     * {@code false} depending upon the other requirements which must be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * met in order for a Window to be focusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2571
     * Setting a Window's focusability state to {@code false} is the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * standard mechanism for an application to identify to the AWT a Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * which will be used as a floating palette or toolbar, and thus should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * a non-focusable Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2576
     * Setting the focusability state on a visible {@code Window}
23717
6457189cd574 8039259: Tidy warnings cleanup for java.awt
yan
parents: 22060
diff changeset
  2577
     * can have a delayed effect on some platforms &#8212; the actual
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2578
     * change may happen only when the {@code Window} becomes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     * hidden and then visible again.  To ensure consistent behavior
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2580
     * across platforms, set the {@code Window}'s focusable state
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2581
     * when the {@code Window} is invisible and then show it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * @param focusableWindowState whether this Window can be the focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     *        Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     * @see #isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * @see #getFocusableWindowState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
     * @see Component#setFocusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
    public void setFocusableWindowState(boolean focusableWindowState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
        boolean oldFocusableWindowState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            oldFocusableWindowState = this.focusableWindowState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            this.focusableWindowState = focusableWindowState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
        WindowPeer peer = (WindowPeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            peer.updateFocusableWindowState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
        firePropertyChange("focusableWindowState", oldFocusableWindowState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
                           focusableWindowState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
        if (oldFocusableWindowState && !focusableWindowState && isFocused()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
            for (Window owner = getOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
                 owner != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
                 owner = owner.getOwner())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
                    Component toFocus =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
                        KeyboardFocusManager.getMostRecentFocusOwner(owner);
37694
c064aefc5a2f 8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents: 36511
diff changeset
  2610
                    if (toFocus != null && toFocus.requestFocus(false, FocusEvent.Cause.ACTIVATION)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
            KeyboardFocusManager.getCurrentKeyboardFocusManager().
12651
8c69dd24bf07 7110683: Issues with some KeyboardFocusManager method
ant
parents: 11982
diff changeset
  2615
                clearGlobalFocusOwnerPriv();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
     * Sets whether this window should receive focus on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
     * subsequently being shown (with a call to {@link #setVisible setVisible(true)}),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * or being moved to the front (with a call to {@link #toFront}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     * Note that {@link #setVisible setVisible(true)} may be called indirectly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
     * (e.g. when showing an owner of the window makes the window to be shown).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
     * {@link #toFront} may also be called indirectly (e.g. when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
     * {@link #setVisible setVisible(true)} is called on already visible window).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
     * In all such cases this property takes effect as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
     * The value of the property is not inherited by owned windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
     * @param autoRequestFocus whether this window should be focused on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
     *        subsequently being shown or being moved to the front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
     * @see #isAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
     * @see #isFocusableWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
     * @see #toFront
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    public void setAutoRequestFocus(boolean autoRequestFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
        this.autoRequestFocus = autoRequestFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * Returns whether this window should receive focus on subsequently being shown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * (with a call to {@link #setVisible setVisible(true)}), or being moved to the front
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * (with a call to {@link #toFront}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * By default, the window has {@code autoRequestFocus} value of {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
     * @return {@code autoRequestFocus} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     * @see #setAutoRequestFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    public boolean isAutoRequestFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
        return autoRequestFocus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
     * registered for all bound properties of this class, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
     *    <li>this Window's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
     *    <li>this Window's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
     *    <li>this Window's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
     *    <li>this Window's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
     *    <li>this Window's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
     *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
     *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
     *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
     *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
     *        ("downCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
     *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
     *    <li>this Window's focusable Window state ("focusableWindowState")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
     *    <li>this Window's always-on-top state("alwaysOnTop")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
     * Note that if this Window is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
     * @param    listener  the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
     * @see Component#removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
     * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
        super.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
     * Adds a PropertyChangeListener to the listener list for a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
     * property. The specified property may be user-defined, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
     * following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
     *    <li>this Window's font ("font")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
     *    <li>this Window's background color ("background")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
     *    <li>this Window's foreground color ("foreground")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
     *    <li>this Window's focusability ("focusable")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
     *    <li>this Window's focus traversal keys enabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
     *        ("focusTraversalKeysEnabled")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
     *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
     *        ("forwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
     *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
     *        ("backwardFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
     *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
     *        ("upCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
     *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
     *        ("downCycleFocusTraversalKeys")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
     *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
     *    <li>this Window's focusable Window state ("focusableWindowState")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
     *        </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
     *    <li>this Window's always-on-top state("alwaysOnTop")</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
     * Note that if this Window is inheriting a bound property, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
     * event will be fired in response to a change in the inherited property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
     * @param propertyName one of the property names listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
     * @param listener the PropertyChangeListener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
     * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
     * @see Component#removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
    public void addPropertyChangeListener(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                                          PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
        super.addPropertyChangeListener(propertyName, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
    /**
4261
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2740
     * Indicates if this container is a validate root.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2741
     * <p>
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2742
     * {@code Window} objects are the validate roots, and, therefore, they
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2743
     * override this method to return {@code true}.
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2744
     *
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2745
     * @return {@code true}
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2746
     * @since 1.7
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2747
     * @see java.awt.Container#isValidateRoot
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2748
     */
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2749
    @Override
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2750
    public boolean isValidateRoot() {
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2751
        return true;
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2752
    }
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2753
126dc6fe0d7b 6852592: invalidate() must be smarter
anthony
parents: 3965
diff changeset
  2754
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
     * Dispatches an event to this window or one of its sub components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     * @param e the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
    void dispatchEventImpl(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
        if (e.getID() == ComponentEvent.COMPONENT_RESIZED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
            validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
        super.dispatchEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     * @deprecated As of JDK version 1.1
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2768
     * replaced by {@code dispatchEvent(AWTEvent)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
    public boolean postEvent(Event e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
        if (handleEvent(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
     * Checks if this Window is showing on screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
     * @see Component#setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    public boolean isShowing() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
11982
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  2787
    boolean isDisposing() {
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  2788
        return disposing;
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  2789
    }
9e19ca1ff707 7145980: Dispose method of window.java takes long
bagiras
parents: 11813
diff changeset
  2790
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     * @deprecated As of J2SE 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
     * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
29886
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28231
diff changeset
  2794
     * @param rb the resource bundle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
    public void applyResourceBundle(ResourceBundle rb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        applyComponentOrientation(ComponentOrientation.getOrientation(rb));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
     * @deprecated As of J2SE 1.4, replaced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
     * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
29886
545c0c3809b8 8075081: Fix missing doclint warnings in java.awt
darcy
parents: 28231
diff changeset
  2804
     * @param rbName the resource name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
    public void applyResourceBundle(String rbName) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2808
        // Use the unnamed module from the TCCL or system class loader.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2809
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2810
        if (cl == null) {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2811
            cl = ClassLoader.getSystemClassLoader();
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2812
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 35667
diff changeset
  2813
        applyResourceBundle(ResourceBundle.getBundle(rbName, cl.getUnnamedModule()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
    * Support for tracking all windows owned by this window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
    */
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2819
    void addOwnedWindow(WeakReference<Window> weakWindow) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        if (weakWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            synchronized(ownedWindowList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                // this if statement should really be an assert, but we don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                // have asserts...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
                if (!ownedWindowList.contains(weakWindow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                    ownedWindowList.addElement(weakWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2831
    void removeOwnedWindow(WeakReference<Window> weakWindow) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
        if (weakWindow != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
            // synchronized block not required since removeElement is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
            // already synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
            ownedWindowList.removeElement(weakWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    void connectOwnedWindow(Window child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
        child.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
        addOwnedWindow(child.weakThis);
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
  2842
        child.disposerRecord.updateOwner();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
    private void addToWindowList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
        synchronized (Window.class) {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2847
            @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
            Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
            if (windowList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                windowList = new Vector<WeakReference<Window>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                appContext.put(Window.class, windowList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
            windowList.add(weakThis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2857
    private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
        synchronized (Window.class) {
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  2859
            @SuppressWarnings("unchecked")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
            Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
            if (windowList != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                windowList.remove(weakThis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
    private void removeFromWindowList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
        removeFromWindowList(appContext, weakThis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
    /**
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2872
     * Window type.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2873
     *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2874
     * Synchronization: ObjectLock
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2875
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2876
    private Type type = Type.NORMAL;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2877
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2878
    /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2879
     * Sets the type of the window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2880
     *
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2881
     * This method can only be called while the window is not displayable.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2882
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  2883
     * @param  type the window type
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2884
     * @throws IllegalComponentStateException if the window
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2885
     *         is displayable.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2886
     * @throws IllegalArgumentException if the type is {@code null}
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2887
     * @see    Component#isDisplayable
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2888
     * @see    #getType
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2889
     * @since 1.7
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2890
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2891
    public void setType(Type type) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2892
        if (type == null) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2893
            throw new IllegalArgumentException("type should not be null.");
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2894
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2895
        synchronized (getTreeLock()) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2896
            if (isDisplayable()) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2897
                throw new IllegalComponentStateException(
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2898
                        "The window is displayable.");
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2899
            }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2900
            synchronized (getObjectLock()) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2901
                this.type = type;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2902
            }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2903
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2904
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2905
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2906
    /**
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2907
     * Returns the type of the window.
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2908
     *
25162
c388078278d4 8043967: Fix doclint warnings for java.awt
yan
parents: 24865
diff changeset
  2909
     * @return the type of the window
4366
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2910
     * @see   #setType
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2911
     * @since 1.7
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2912
     */
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2913
    public Type getType() {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2914
        synchronized (getObjectLock()) {
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2915
            return type;
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2916
        }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2917
    }
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2918
4446f3b8a9b4 6402325: Swing toolbars vs native toolbars on Windows
anthony
parents: 4261
diff changeset
  2919
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
     * The window serialized data version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
    private int windowSerializedDataVersion = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * Writes default serializable fields to stream.  Writes
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2928
     * a list of serializable {@code WindowListener}s and
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2929
     * {@code WindowFocusListener}s as optional data.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * Writes a list of child windows as optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * Writes a list of icon images as optional data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2933
     * @param s the {@code ObjectOutputStream} to write
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2934
     * @serialData {@code null} terminated sequence of
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2935
     *    0 or more pairs; the pair consists of a {@code String}
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2936
     *    and {@code Object}; the {@code String}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     *    indicates the type of object and is one of the following:
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2938
     *    {@code windowListenerK} indicating a
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2939
     *      {@code WindowListener} object;
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2940
     *    {@code windowFocusWindowK} indicating a
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2941
     *      {@code WindowFocusListener} object;
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2942
     *    {@code ownedWindowK} indicating a child
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  2943
     *      {@code Window} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * @see Component#windowListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * @see Component#windowFocusListenerK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     * @see Component#ownedWindowK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
            // Update old focusMgr fields so that our object stream can be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
            // by previous releases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            focusMgr = new FocusManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            focusMgr.focusRoot = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
            focusMgr.focusOwner = getMostRecentFocusOwner();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
            // Clear fields so that we don't keep extra references around
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            focusMgr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
            AWTEventMulticaster.save(s, windowListenerK, windowListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            AWTEventMulticaster.save(s, windowFocusListenerK, windowFocusListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
            AWTEventMulticaster.save(s, windowStateListenerK, windowStateListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
        synchronized (ownedWindowList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
            for (int i = 0; i < ownedWindowList.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
                Window child = ownedWindowList.elementAt(i).get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
                if (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
                    s.writeObject(ownedWindowK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                    s.writeObject(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
        //write icon array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
        if (icons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            for (Image i : icons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                if (i instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                    s.writeObject(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
    // Part of deserialization procedure to be called before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
    // user's code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
    private void initDeserializedWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
        setWarningString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
        inputContextLock = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        // Deserialized Windows are not yet visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
        visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
15318
607db339afcc 8005492: Reduce number of warnings in sun/awt/* classes
mcherkas
parents: 12661
diff changeset
  3004
        weakThis = new WeakReference<>(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
        anchor = new Object();
20450
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
  3007
        disposerRecord = new WindowDisposerRecord(appContext, this);
008da09ac2b2 8013563: Memory leak in JFrame on Linux
serb
parents: 20172
diff changeset
  3008
        sun.java2d.Disposer.addRecord(anchor, disposerRecord);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
        addToWindowList();
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3011
        initGC(null);
21281
061c0ee6607c 8027152: Regression: test closed/java/awt/Serialize/NullSerializationTest/NullSerializationTest.html fails since JDK 8 b112
pchelko
parents: 21278
diff changeset
  3012
        ownedWindowList = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
    private void deserializeResources(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
        throws ClassNotFoundException, IOException, HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
            if (windowSerializedDataVersion < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
                // Translate old-style focus tracking to new model. For 1.4 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
                // later releases, we'll rely on the Window's initial focusable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
                // Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
                if (focusMgr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
                    if (focusMgr.focusOwner != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                        KeyboardFocusManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                            setMostRecentFocusOwner(this, focusMgr.focusOwner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
                // This field is non-transient and relies on default serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
                // However, the default value is insufficient, so we need to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
                // it explicitly for object data streams prior to 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
                focusableWindowState = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
        Object keyOrNull;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        while(null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
            String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
            if (windowListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
                addWindowListener((WindowListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
            } else if (windowFocusListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
                addWindowFocusListener((WindowFocusListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
            } else if (windowStateListenerK == key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
                addWindowStateListener((WindowStateListener)(s.readObject()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
            } else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
                s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
            while (null != (keyOrNull = s.readObject())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
                String key = ((String)keyOrNull).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
                if (ownedWindowK == key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
                    connectOwnedWindow((Window) s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
                else // skip value for unrecognized key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
                    s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
            //read icons
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
            Object obj = s.readObject(); //Throws OptionalDataException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
                                         //for pre1.6 objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
            icons = new ArrayList<Image>(); //Frame.readObject() assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
                                            //pre1.6 version if icons is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
            while (obj != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
                if (obj instanceof Image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
                    icons.add((Image)obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
                obj = s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
        catch (OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
            // 1.1 serialized form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
            // ownedWindowList will be updated by Frame.readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3082
     * Reads the {@code ObjectInputStream} and an optional
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
     * list of listeners to receive various events fired by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
     * the component; also reads a list of
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3085
     * (possibly {@code null}) child windows.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3088
     * @param s the {@code ObjectInputStream} to read
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
     * @exception HeadlessException if
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3090
     *   {@code GraphicsEnvironment.isHeadless} returns
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3091
     *   {@code true}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
     * @see java.awt.GraphicsEnvironment#isHeadless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
     * @see #writeObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
         GraphicsEnvironment.checkHeadless();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
         initDeserializedWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
         ObjectInputStream.GetField f = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
         syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
         state = f.get("state", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
         focusableWindowState = f.get("focusableWindowState", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
         windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
         locationByPlatform = f.get("locationByPlatform", locationByPlatformProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
         // Note: 1.4 (or later) doesn't use focusMgr
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
         focusMgr = (FocusManager)f.get("focusMgr", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
         Dialog.ModalExclusionType et = (Dialog.ModalExclusionType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
             f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
         setModalExclusionType(et); // since 6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
         boolean aot = f.get("alwaysOnTop", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
         if(aot) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
             setAlwaysOnTop(aot); // since 1.5; subject to permission check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
         }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3116
         shape = (Shape)f.get("shape", null);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3117
         opacity = (Float)f.get("opacity", 1.0f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  3119
         this.securityWarningWidth = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  3120
         this.securityWarningHeight = 0;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  3121
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
         deserializeResources(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
     * Gets the AccessibleContext associated with this Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
     * For windows, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
     * AccessibleAWTWindow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
     * A new AccessibleAWTWindow instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
     * @return an AccessibleAWTWindow that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
     *         AccessibleContext of this Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
            accessibleContext = new AccessibleAWTWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
     * This class implements accessibility support for the
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3149
     * {@code Window} class.  It provides an implementation of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
     * Java Accessibility API appropriate to window user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
    protected class AccessibleAWTWindow extends AccessibleAWTContainer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
        private static final long serialVersionUID = 4215068635060671780L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
         * @see javax.accessibility.AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
            return AccessibleRole.WINDOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
         * Get the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
         * @see javax.accessibility.AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
            if (getFocusOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
                states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
    } // inner class AccessibleAWTWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3188
    @Override
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3189
    void setGraphicsConfiguration(GraphicsConfiguration gc) {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3190
        if (gc == null) {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3191
            gc = GraphicsEnvironment.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
                    getLocalGraphicsEnvironment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
                    getDefaultScreenDevice().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
                    getDefaultConfiguration();
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3195
        }
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3196
        synchronized (getTreeLock()) {
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3197
            super.setGraphicsConfiguration(gc);
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 17901
diff changeset
  3198
            if (log.isLoggable(PlatformLogger.Level.FINER)) {
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3199
                log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
     * Sets the location of the window relative to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
     * component according to the following scenarios.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
     * The target screen mentioned below is a screen to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
     * the window should be placed after the setLocationRelativeTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
     * method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
     * <li>If the component is {@code null}, or the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
     * GraphicsConfiguration} associated with this component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
     * {@code null}, the window is placed in the center of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
     * screen. The center point can be obtained with the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
     * GraphicsEnvironment#getCenterPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
     * GraphicsEnvironment.getCenterPoint} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
     * <li>If the component is not {@code null}, but it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
     * currently showing, the window is placed in the center of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
     * the target screen defined by the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
     * GraphicsConfiguration} associated with this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
     * <li>If the component is not {@code null} and is shown on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
     * the screen, then the window is located in such a way that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
     * the center of the window coincides with the center of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
     * component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
     * If the screens configuration does not allow the window to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
     * be moved from one screen to another, then the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
     * only placed at the location determined according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
     * above conditions and its {@code GraphicsConfiguration} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
     * not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
     * <b>Note</b>: If the lower edge of the window is out of the screen,
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3235
     * then the window is placed to the side of the {@code Component}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
     * that is closest to the center of the screen. So if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
     * component is on the right part of the screen, the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
     * is placed to its left, and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
     * If after the window location has been calculated, the upper,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
     * left, or right edge of the window is out of the screen,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
     * then the window is located in such a way that the upper,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
     * left, or right edge of the window coincides with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
     * corresponding edge of the screen. If both left and right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
     * edges of the window are out of the screen, the window is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
     * placed at the left side of the screen. The similar placement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
     * will occur if both top and bottom edges are out of the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
     * In that case, the window is placed at the top side of the screen.
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3249
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3250
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3251
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3252
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3253
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
     * @param c  the component in relation to which the window's location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
     *           is determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
     * @see java.awt.GraphicsEnvironment#getCenterPoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
    public void setLocationRelativeTo(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
        // target location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
        int dx = 0, dy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        // target GC
2459
08f3416ff334 6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents: 2455
diff changeset
  3264
        GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
        Rectangle gcBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
        Dimension windowSize = getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
        // search a top-level of c
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3270
        Window componentWindow = SunToolkit.getContainingWindow(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
        if ((c == null) || (componentWindow == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
            GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
            gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
            gcBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
            Point centerPoint = ge.getCenterPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
            dx = centerPoint.x - windowSize.width / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            dy = centerPoint.y - windowSize.height / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
        } else if (!c.isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
            gc = componentWindow.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
            gcBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
            dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
            dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
            gc = componentWindow.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
            gcBounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
            Dimension compSize = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
            Point compLocation = c.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
            dx = compLocation.x + ((compSize.width - windowSize.width) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
            dy = compLocation.y + ((compSize.height - windowSize.height) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            // Adjust for bottom edge being offscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
            if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
                dy = gcBounds.y + gcBounds.height - windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
                if (compLocation.x - gcBounds.x + compSize.width / 2 < gcBounds.width / 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
                    dx = compLocation.x + compSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
                    dx = compLocation.x - windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
        // Avoid being placed off the edge of the screen:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
        if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
            dy = gcBounds.y + gcBounds.height - windowSize.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
        // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
        if (dy < gcBounds.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
            dy = gcBounds.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
        if (dx + windowSize.width > gcBounds.x + gcBounds.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
            dx = gcBounds.x + gcBounds.width - windowSize.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
        // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
        if (dx < gcBounds.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
            dx = gcBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        setLocation(dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
     * Overridden from Component.  Top-level Windows should not propagate a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
     * MouseWheelEvent beyond themselves into their owning Windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
    void deliverMouseWheelToAncestor(MouseWheelEvent e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
     * Overridden from Component.  Top-level Windows don't dispatch to ancestors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
    boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {return false;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
     * Creates a new strategy for multi-buffering on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
     * Multi-buffering is useful for rendering performance.  This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
     * attempts to create the best strategy available with the number of
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3338
     * buffers supplied.  It will always create a {@code BufferStrategy}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * with that number of buffers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     * A page-flipping strategy is attempted first, then a blitting strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
     * using accelerated buffers.  Finally, an unaccelerated blitting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
     * strategy is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
     * Each time this method is called,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
     * the existing buffer strategy for this component is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
     * @param numBuffers number of buffers to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
     * @exception IllegalArgumentException if numBuffers is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
     * @exception IllegalStateException if the component is not displayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
     * @see #isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     * @see #getBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
    public void createBufferStrategy(int numBuffers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
        super.createBufferStrategy(numBuffers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
     * Creates a new strategy for multi-buffering on this component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
     * required buffer capabilities.  This is useful, for example, if only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
     * accelerated memory or page flipping is desired (as specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
     * buffer capabilities).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
     * Each time this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
     * is called, the existing buffer strategy for this component is discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
     * @param numBuffers number of buffers to create, including the front buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
     * @param caps the required capabilities for creating the buffer strategy;
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3367
     * cannot be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
     * @exception AWTException if the capabilities supplied could not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
     * supported or met; this may happen, for example, if there is not enough
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
     * accelerated memory currently available, or if page flipping is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
     * but not possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
     * @exception IllegalArgumentException if numBuffers is less than 1, or if
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3373
     * caps is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
     * @see #getBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
    public void createBufferStrategy(int numBuffers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
        BufferCapabilities caps) throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
        super.createBufferStrategy(numBuffers, caps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3383
     * Returns the {@code BufferStrategy} used by this component.  This
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3384
     * method will return null if a {@code BufferStrategy} has not yet
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
     * been created or has been disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
     * @return the buffer strategy used by this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
     * @see #createBufferStrategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
    public BufferStrategy getBufferStrategy() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
        return super.getBufferStrategy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
    Component getTemporaryLostComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
        return temporaryLostComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
    Component setTemporaryLostComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
        Component previousComp = temporaryLostComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
        // Check that "component" is an acceptable focus owner and don't store it otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
        // - or later we will have problems with opposite while handling  WINDOW_GAINED_FOCUS
1171
a2782dd9f312 4685768: A11y issue - Focus set to disabled component, can't Tab/Shift-Tab
ant
parents: 127
diff changeset
  3402
        if (component == null || component.canBeFocusOwner()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
            temporaryLostComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            temporaryLostComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
        return previousComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
     * Checks whether this window can contain focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
     * Verifies that it is focusable and as container it can container focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
    boolean canContainFocusOwner(Component focusOwnerCandidate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
  3419
    private volatile boolean locationByPlatform = locationByPlatformProp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * Sets whether this Window should appear at the default location for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * native windowing system or at the current location (returned by
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3425
     * {@code getLocation}) the next time the Window is made visible.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     * This behavior resembles a native window shown without programmatically
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * setting its location.  Most windowing systems cascade windows if their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * locations are not explicitly set. The actual location is determined once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * window is shown on the screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * This behavior can also be enabled by setting the System Property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     * "java.awt.Window.locationByPlatform" to "true", though calls to this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * take precedence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * <p>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3435
     * Calls to {@code setVisible}, {@code setLocation} and
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3436
     * {@code setBounds} after calling {@code setLocationByPlatform} clear
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     * this property of the Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
     * For example, after the following code is executed:
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  3440
     * <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
     * setLocationByPlatform(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
     * setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
     * boolean flag = isLocationByPlatform();
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  3444
     * </pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
     * The window will be shown at platform's default location and
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3446
     * {@code flag} will be {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
     * In the following sample:
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  3449
     * <pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
     * setLocationByPlatform(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3451
     * setLocation(10, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3452
     * boolean flag = isLocationByPlatform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3453
     * setVisible(true);
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  3454
     * </pre>
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3455
     * The window will be shown at (10, 10) and {@code flag} will be
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3456
     * {@code false}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3457
     *
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3458
     * @param locationByPlatform {@code true} if this Window should appear
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3459
     *        at the default location, {@code false} if at the current location
20172
f48935a247ec 8025218: [javadoc] some errors in java/awt classes
yan
parents: 19807
diff changeset
  3460
     * @throws IllegalComponentStateException if the window
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3461
     *         is showing on screen and locationByPlatform is {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3462
     * @see #setLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
     * @see #setVisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
     * @see #isLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
     * @see java.lang.System#getProperty(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3467
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
    public void setLocationByPlatform(boolean locationByPlatform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
            if (locationByPlatform && isShowing()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                throw new IllegalComponentStateException("The window is showing on screen.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            this.locationByPlatform = locationByPlatform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
    /**
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3479
     * Returns {@code true} if this Window will appear at the default location
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
     * for the native windowing system the next time this Window is made visible.
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3481
     * This method always returns {@code false} if the Window is showing on the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
     * screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
     * @return whether this Window will appear at the default location
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
     * @see #setLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
     * @see #isShowing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
    public boolean isLocationByPlatform() {
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
  3490
        return locationByPlatform;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
     * The {@code width} or {@code height} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
     * are automatically enlarged if either is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
     * the minimum size as specified by previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
     * {@code setMinimumSize}.
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3500
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3501
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3502
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3503
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3504
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
     * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
     * @see #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
     * @see #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
     * @see #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
     * @see #setSize(Dimension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
     * @see #setLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
     * @see #isLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
    public void setBounds(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            if (getBoundsOp() == ComponentPeer.SET_LOCATION ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                getBoundsOp() == ComponentPeer.SET_BOUNDS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
                locationByPlatform = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
            super.setBounds(x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
     * The {@code r.width} or {@code r.height} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
     * will be automatically enlarged if either is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
     * the minimum size as specified by previous call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
     * {@code setMinimumSize}.
9200
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3534
     * <p>
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3535
     * The method changes the geometry-related data. Therefore,
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3536
     * the native windowing system may ignore such requests, or it may modify
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3537
     * the requested data, so that the {@code Window} object is placed and sized
d3e9a8fecd4f 7016889: GraphicsDevice.setFullScreenWindow() spec for simulated full-screen mode is not always correct
dcherepanov
parents: 8136
diff changeset
  3538
     * in a way that corresponds closely to the desktop settings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
     * @see #getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
     * @see #setLocation(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
     * @see #setLocation(Point)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * @see #setSize(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * @see #setSize(Dimension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * @see #setMinimumSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     * @see #setLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     * @see #isLocationByPlatform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
    public void setBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
        setBounds(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
     * Determines whether this component will be displayed on the screen.
19361
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3556
     * @return {@code true} if the component and all of its ancestors
424d84a2276f 7027045: (doc) java/awt/Window.java has several typos in javadoc
serb
parents: 18178
diff changeset
  3557
     *          until a toplevel window are visible, {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
    boolean isRecursivelyVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
        // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
        // We're overriding isRecursivelyVisible to implement this policy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
        return visible;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3566
    // ******************** SHAPES & TRANSPARENCY CODE ********************
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3567
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3568
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3569
     * Returns the opacity of the window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3570
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3571
     * @return the opacity of the window
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3572
     *
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3573
     * @see Window#setOpacity(float)
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3574
     * @see GraphicsDevice.WindowTranslucency
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3575
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3576
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3577
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3578
    public float getOpacity() {
33510
1895624f2983 8138764: In some cases the usage of TreeLock can be replaced by other synchronization
serb
parents: 32865
diff changeset
  3579
        return opacity;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3580
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3581
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3582
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3583
     * Sets the opacity of the window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3584
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3585
     * The opacity value is in the range [0..1]. Note that setting the opacity
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3586
     * level of 0 may or may not disable the mouse event handling on this
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3587
     * window. This is a platform-dependent behavior.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3588
     * <p>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3589
     * The following conditions must be met in order to set the opacity value
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3590
     * less than {@code 1.0f}:
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3591
     * <ul>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3592
     * <li>The {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3593
     * translucency must be supported by the underlying system
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3594
     * <li>The window must be undecorated (see {@link Frame#setUndecorated}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3595
     * and {@link Dialog#setUndecorated})
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3596
     * <li>The window must not be in full-screen mode (see {@link
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3597
     * GraphicsDevice#setFullScreenWindow(Window)})
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3598
     * </ul>
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3599
     * <p>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3600
     * If the requested opacity value is less than {@code 1.0f}, and any of the
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3601
     * above conditions are not met, the window opacity will not change,
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3602
     * and the {@code IllegalComponentStateException} will be thrown.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3603
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3604
     * The translucency levels of individual pixels may also be effected by the
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3605
     * alpha component of their color (see {@link Window#setBackground(Color)}) and the
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3606
     * current shape of this window (see {@link #setShape(Shape)}).
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3607
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3608
     * @param opacity the opacity level to set to the window
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3609
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3610
     * @throws IllegalArgumentException if the opacity is out of the range
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3611
     *     [0..1]
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3612
     * @throws IllegalComponentStateException if the window is decorated and
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3613
     *     the opacity is less than {@code 1.0f}
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3614
     * @throws IllegalComponentStateException if the window is in full screen
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3615
     *     mode, and the opacity is less than {@code 1.0f}
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3616
     * @throws UnsupportedOperationException if the {@code
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3617
     *     GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3618
     *     translucency is not supported and the opacity is less than
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3619
     *     {@code 1.0f}
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3620
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3621
     * @see Window#getOpacity
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3622
     * @see Window#setBackground(Color)
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3623
     * @see Window#setShape(Shape)
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3624
     * @see Frame#isUndecorated
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3625
     * @see Dialog#isUndecorated
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3626
     * @see GraphicsDevice.WindowTranslucency
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3627
     * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3628
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3629
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3630
     */
28231
b608ffcaed74 8066621: Suppress deprecation warnings in java.desktop module
darcy
parents: 27766
diff changeset
  3631
    @SuppressWarnings("deprecation")
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3632
    public void setOpacity(float opacity) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3633
        synchronized (getTreeLock()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3634
            if (opacity < 0.0f || opacity > 1.0f) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3635
                throw new IllegalArgumentException(
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3636
                    "The value of opacity should be in the range [0.0f .. 1.0f].");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3637
            }
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3638
            if (opacity < 1.0f) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3639
                GraphicsConfiguration gc = getGraphicsConfiguration();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3640
                GraphicsDevice gd = gc.getDevice();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3641
                if (gc.getDevice().getFullScreenWindow() == this) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3642
                    throw new IllegalComponentStateException(
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3643
                        "Setting opacity for full-screen window is not supported.");
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3644
                }
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3645
                if (!gd.isWindowTranslucencySupported(
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3646
                    GraphicsDevice.WindowTranslucency.TRANSLUCENT))
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3647
                {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3648
                    throw new UnsupportedOperationException(
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3649
                        "TRANSLUCENT translucency is not supported.");
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3650
                }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3651
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3652
            this.opacity = opacity;
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  3653
            WindowPeer peer = (WindowPeer) this.peer;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3654
            if (peer != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3655
                peer.setOpacity(opacity);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3656
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3657
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3658
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3659
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3660
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3661
     * Returns the shape of the window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3662
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3663
     * The value returned by this method may not be the same as
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3664
     * previously set with {@code setShape(shape)}, but it is guaranteed
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3665
     * to represent the same shape.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3666
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3667
     * @return the shape of the window or {@code null} if no
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3668
     *     shape is specified for the window
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3669
     *
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3670
     * @see Window#setShape(Shape)
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3671
     * @see GraphicsDevice.WindowTranslucency
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3672
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3673
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3674
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3675
    public Shape getShape() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3676
        synchronized (getTreeLock()) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3677
            return shape == null ? null : new Path2D.Float(shape);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3678
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3679
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3680
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3681
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3682
     * Sets the shape of the window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3683
     * <p>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3684
     * Setting a shape cuts off some parts of the window. Only the parts that
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3685
     * belong to the given {@link Shape} remain visible and clickable. If
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3686
     * the shape argument is {@code null}, this method restores the default
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3687
     * shape, making the window rectangular on most platforms.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3688
     * <p>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3689
     * The following conditions must be met to set a non-null shape:
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3690
     * <ul>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3691
     * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3692
     * PERPIXEL_TRANSPARENT} translucency must be supported by the
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3693
     * underlying system
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3694
     * <li>The window must be undecorated (see {@link Frame#setUndecorated}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3695
     * and {@link Dialog#setUndecorated})
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3696
     * <li>The window must not be in full-screen mode (see {@link
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3697
     * GraphicsDevice#setFullScreenWindow(Window)})
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3698
     * </ul>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3699
     * <p>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3700
     * If the requested shape is not {@code null}, and any of the above
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3701
     * conditions are not met, the shape of this window will not change,
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3702
     * and either the {@code UnsupportedOperationException} or {@code
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3703
     * IllegalComponentStateException} will be thrown.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3704
     * <p>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21262
diff changeset
  3705
     * The translucency levels of individual pixels may also be effected by the
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3706
     * alpha component of their color (see {@link Window#setBackground(Color)}) and the
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3707
     * opacity value (see {@link #setOpacity(float)}). See {@link
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3708
     * GraphicsDevice.WindowTranslucency} for more details.
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3709
     *
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3710
     * @param shape the shape to set to the window
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3711
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3712
     * @throws IllegalComponentStateException if the shape is not {@code
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3713
     *     null} and the window is decorated
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3714
     * @throws IllegalComponentStateException if the shape is not {@code
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3715
     *     null} and the window is in full-screen mode
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3716
     * @throws UnsupportedOperationException if the shape is not {@code
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3717
     *     null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3718
     *     PERPIXEL_TRANSPARENT} translucency is not supported
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3719
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3720
     * @see Window#getShape()
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3721
     * @see Window#setBackground(Color)
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3722
     * @see Window#setOpacity(float)
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3723
     * @see Frame#isUndecorated
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3724
     * @see Dialog#isUndecorated
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3725
     * @see GraphicsDevice.WindowTranslucency
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3726
     * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3727
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3728
     * @since 1.7
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3729
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3730
    public void setShape(Shape shape) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3731
        synchronized (getTreeLock()) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3732
            if (shape != null) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3733
                GraphicsConfiguration gc = getGraphicsConfiguration();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3734
                GraphicsDevice gd = gc.getDevice();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3735
                if (gc.getDevice().getFullScreenWindow() == this) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3736
                    throw new IllegalComponentStateException(
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3737
                        "Setting shape for full-screen window is not supported.");
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3738
                }
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3739
                if (!gd.isWindowTranslucencySupported(
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3740
                        GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3741
                {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3742
                    throw new UnsupportedOperationException(
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3743
                        "PERPIXEL_TRANSPARENT translucency is not supported.");
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3744
                }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3745
            }
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3746
            this.shape = (shape == null) ? null : new Path2D.Float(shape);
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  3747
            WindowPeer peer = (WindowPeer) this.peer;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3748
            if (peer != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3749
                peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3750
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3751
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3752
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3753
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3754
    /**
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3755
     * Gets the background color of this window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3756
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3757
     * Note that the alpha component of the returned color indicates whether
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3758
     * the window is in the non-opaque (per-pixel translucent) mode.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3759
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3760
     * @return this component's background color
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3761
     *
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3762
     * @see Window#setBackground(Color)
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3763
     * @see Window#isOpaque
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3764
     * @see GraphicsDevice.WindowTranslucency
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3765
     */
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3766
    @Override
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3767
    public Color getBackground() {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3768
        return super.getBackground();
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3769
    }
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3770
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3771
    /**
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3772
     * Sets the background color of this window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3773
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3774
     * If the windowing system supports the {@link
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3775
     * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21262
diff changeset
  3776
     * translucency, the alpha component of the given background color
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3777
     * may effect the mode of operation for this window: it indicates whether
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3778
     * this window must be opaque (alpha equals {@code 1.0f}) or per-pixel translucent
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3779
     * (alpha is less than {@code 1.0f}). If the given background color is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3780
     * {@code null}, the window is considered completely opaque.
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3781
     * <p>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3782
     * All the following conditions must be met to enable the per-pixel
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3783
     * transparency mode for this window:
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3784
     * <ul>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3785
     * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3786
     * PERPIXEL_TRANSLUCENT} translucency must be supported by the graphics
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3787
     * device where this window is located
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3788
     * <li>The window must be undecorated (see {@link Frame#setUndecorated}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3789
     * and {@link Dialog#setUndecorated})
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3790
     * <li>The window must not be in full-screen mode (see {@link
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3791
     * GraphicsDevice#setFullScreenWindow(Window)})
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3792
     * </ul>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3793
     * <p>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3794
     * If the alpha component of the requested background color is less than
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3795
     * {@code 1.0f}, and any of the above conditions are not met, the background
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3796
     * color of this window will not change, the alpha component of the given
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3797
     * background color will not affect the mode of operation for this window,
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3798
     * and either the {@code UnsupportedOperationException} or {@code
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3799
     * IllegalComponentStateException} will be thrown.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3800
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3801
     * When the window is per-pixel translucent, the drawing sub-system
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3802
     * respects the alpha value of each individual pixel. If a pixel gets
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3803
     * painted with the alpha color component equal to zero, it becomes
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3804
     * visually transparent. If the alpha of the pixel is equal to 1.0f, the
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3805
     * pixel is fully opaque. Interim values of the alpha color component make
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3806
     * the pixel semi-transparent. In this mode, the background of the window
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3807
     * gets painted with the alpha value of the given background color. If the
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3808
     * alpha value of the argument of this method is equal to {@code 0}, the
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3809
     * background is not painted at all.
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3810
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3811
     * The actual level of translucency of a given pixel also depends on window
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3812
     * opacity (see {@link #setOpacity(float)}), as well as the current shape of
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3813
     * this window (see {@link #setShape(Shape)}).
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3814
     * <p>
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3815
     * Note that painting a pixel with the alpha value of {@code 0} may or may
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3816
     * not disable the mouse event handling on this pixel. This is a
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3817
     * platform-dependent behavior. To make sure the mouse events do not get
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3818
     * dispatched to a particular pixel, the pixel must be excluded from the
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3819
     * shape of the window.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3820
     * <p>
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3821
     * Enabling the per-pixel translucency mode may change the graphics
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3822
     * configuration of this window due to the native platform requirements.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3823
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3824
     * @param bgColor the color to become this window's background color.
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3825
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3826
     * @throws IllegalComponentStateException if the alpha value of the given
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3827
     *     background color is less than {@code 1.0f} and the window is decorated
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3828
     * @throws IllegalComponentStateException if the alpha value of the given
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3829
     *     background color is less than {@code 1.0f} and the window is in
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3830
     *     full-screen mode
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3831
     * @throws UnsupportedOperationException if the alpha value of the given
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3832
     *     background color is less than {@code 1.0f} and {@link
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3833
     *     GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3834
     *     PERPIXEL_TRANSLUCENT} translucency is not supported
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3835
     *
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3836
     * @see Window#getBackground
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3837
     * @see Window#isOpaque
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3838
     * @see Window#setOpacity(float)
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3839
     * @see Window#setShape(Shape)
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3840
     * @see Frame#isUndecorated
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3841
     * @see Dialog#isUndecorated
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3842
     * @see GraphicsDevice.WindowTranslucency
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3843
     * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3844
     * @see GraphicsConfiguration#isTranslucencyCapable()
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3845
     */
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3846
    @Override
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3847
    public void setBackground(Color bgColor) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3848
        Color oldBg = getBackground();
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3849
        super.setBackground(bgColor);
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3850
        if (oldBg != null && oldBg.equals(bgColor)) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3851
            return;
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3852
        }
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3853
        int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3231
10acb97474ff 6853916: java.awt.Window.setBackground(null) throws NullPointerException
anthony
parents: 3084
diff changeset
  3854
        int alpha = bgColor != null ? bgColor.getAlpha() : 255;
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3855
        if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3856
            GraphicsConfiguration gc = getGraphicsConfiguration();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3857
            GraphicsDevice gd = gc.getDevice();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3858
            if (gc.getDevice().getFullScreenWindow() == this) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3859
                throw new IllegalComponentStateException(
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3860
                    "Making full-screen window non opaque is not supported.");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3861
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3862
            if (!gc.isTranslucencyCapable()) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3863
                GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3864
                if (capableGC == null) {
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3865
                    throw new UnsupportedOperationException(
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3866
                        "PERPIXEL_TRANSLUCENT translucency is not supported");
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3867
                }
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3868
                setGraphicsConfiguration(capableGC);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3869
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3870
            setLayersOpaque(this, false);
2648
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3871
        } else if ((oldAlpha < 255) && (alpha == 255)) {
aa45a227fce3 6802853: API: shaped & translucent windows
anthony
parents: 2647
diff changeset
  3872
            setLayersOpaque(this, true);
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3873
        }
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  3874
        WindowPeer peer = (WindowPeer) this.peer;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3875
        if (peer != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3876
            peer.setOpaque(alpha == 255);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3877
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3878
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3879
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3880
    /**
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3881
     * Indicates if the window is currently opaque.
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3882
     * <p>
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3883
     * The method returns {@code false} if the background color of the window
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3884
     * is not {@code null} and the alpha component of the color is less than
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 7154
diff changeset
  3885
     * {@code 1.0f}. The method returns {@code true} otherwise.
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3886
     *
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3887
     * @return {@code true} if the window is opaque, {@code false} otherwise
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3888
     *
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3889
     * @see Window#getBackground
3711
675253c23780 6877122: Many javadoc warnings from java.awt.Window, other awt classes
darcy
parents: 3476
diff changeset
  3890
     * @see Window#setBackground(Color)
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3891
     * @since 1.7
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3892
     */
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3893
    @Override
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3894
    public boolean isOpaque() {
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3895
        Color bg = getBackground();
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3896
        return bg != null ? bg.getAlpha() == 255 : true;
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3897
    }
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3898
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3899
    private void updateWindow() {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3900
        synchronized (getTreeLock()) {
30469
bac0a7ff7e1e 8074028: Remove API references to java.awt.peer
serb
parents: 29886
diff changeset
  3901
            WindowPeer peer = (WindowPeer) this.peer;
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3902
            if (peer != null) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3903
                peer.updateWindow();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3904
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3905
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3906
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3907
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3908
    /**
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3909
     * {@inheritDoc}
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3910
     *
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3911
     * @since 1.7
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3912
     */
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3913
    @Override
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3914
    public void paint(Graphics g) {
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3915
        if (!isOpaque()) {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3916
            Graphics gg = g.create();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3917
            try {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3918
                if (gg instanceof Graphics2D) {
3237
7c6c2d9361d9 6837446: Introduce Window.isOpaque() method
anthony
parents: 3231
diff changeset
  3919
                    gg.setColor(getBackground());
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3920
                    ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3921
                    gg.fillRect(0, 0, getWidth(), getHeight());
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3922
                }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3923
            } finally {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3924
                gg.dispose();
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3925
            }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3926
        }
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3927
        super.paint(g);
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  3928
    }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3929
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3930
    private static void setLayersOpaque(Component component, boolean isOpaque) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3931
        // Shouldn't use instanceof to avoid loading Swing classes
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3932
        //    if it's a pure AWT application.
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2808
diff changeset
  3933
        if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3934
            javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3935
            javax.swing.JRootPane root = rpc.getRootPane();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3936
            javax.swing.JLayeredPane lp = root.getLayeredPane();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3937
            Container c = root.getContentPane();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3938
            javax.swing.JComponent content =
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3939
                (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3940
            lp.setOpaque(isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3941
            root.setOpaque(isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3942
            if (content != null) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3943
                content.setOpaque(isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3944
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3945
                // Iterate down one level to see whether we have a JApplet
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3946
                // (which is also a RootPaneContainer) which requires processing
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3947
                int numChildren = content.getComponentCount();
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3948
                if (numChildren > 0) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3949
                    Component child = content.getComponent(0);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3950
                    // It's OK to use instanceof here because we've
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3951
                    // already loaded the RootPaneContainer class by now
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3952
                    if (child instanceof javax.swing.RootPaneContainer) {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3953
                        setLayersOpaque(child, isOpaque);
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3954
                    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3955
                }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3956
            }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3957
        }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3958
    }
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3959
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  3960
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3961
    // ************************** MIXING CODE *******************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3962
17150
a842e8c6660a 7166296: closed/java/awt/Frame/DisabledParentOfToplevel/DisabledParentOfToplevel.html failed since 1.8.0b36
serb
parents: 16892
diff changeset
  3963
    // A window has an owner, but it does NOT have a container
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3964
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3965
    final Container getContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3966
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3970
     * Applies the shape to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3971
     * @param shape Shape to be applied to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3972
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3973
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3974
    final void applyCompoundShape(Region shape) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3975
        // The shape calculated by mixing code is not intended to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3976
        // to windows or frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3977
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3979
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3980
    final void applyCurrentShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3981
        // The shape calculated by mixing code is not intended to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3982
        // to windows or frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3983
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3985
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3986
    final void mixOnReshaping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3987
        // The shape calculated by mixing code is not intended to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3988
        // to windows or frames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3990
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3991
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3992
    final Point getLocationOnWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3993
        return new Point(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3995
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3996
    // ****************** END OF MIXING CODE ********************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3997
3444
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  3998
    /**
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  3999
     * Limit the given double value with the given range.
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4000
     */
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4001
    private static double limit(double value, double min, double max) {
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4002
        value = Math.max(value, min);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4003
        value = Math.min(value, max);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4004
        return value;
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4005
    }
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4006
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4007
    /**
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4008
     * Calculate the position of the security warning.
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4009
     *
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4010
     * This method gets the window location/size as reported by the native
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4011
     * system since the locally cached values may represent outdated data.
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4012
     *
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4013
     * The method is used from the native code, or via AWTAccessor.
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4014
     *
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4015
     * NOTE: this method is invoked on the toolkit thread, and therefore is not
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4016
     * supposed to become public/user-overridable.
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4017
     */
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4018
    private Point2D calculateSecurityWarningPosition(double x, double y,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4019
            double w, double h)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4020
    {
51929
0e514f1549b4 8210692: The "com.sun.awt.SecurityWarning" class can be dropped
serb
parents: 47510
diff changeset
  4021
         // The desired location for the security warning
0e514f1549b4 8210692: The "com.sun.awt.SecurityWarning" class can be dropped
serb
parents: 47510
diff changeset
  4022
        double wx = x + w * RIGHT_ALIGNMENT + 2.0;
0e514f1549b4 8210692: The "com.sun.awt.SecurityWarning" class can be dropped
serb
parents: 47510
diff changeset
  4023
        double wy = y + h * TOP_ALIGNMENT + 0.0;
3444
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4024
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4025
        // First, make sure the warning is not too far from the window bounds
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4026
        wx = Window.limit(wx,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4027
                x - securityWarningWidth - 2,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4028
                x + w + 2);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4029
        wy = Window.limit(wy,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4030
                y - securityWarningHeight - 2,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4031
                y + h + 2);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4032
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4033
        // Now make sure the warning window is visible on the screen
3446
4a07252d2e92 6736293: OpenType checks can be bypassed through finalizer resurrection
emcmanus
parents: 3444
diff changeset
  4034
        GraphicsConfiguration graphicsConfig =
4a07252d2e92 6736293: OpenType checks can be bypassed through finalizer resurrection
emcmanus
parents: 3444
diff changeset
  4035
            getGraphicsConfiguration_NoClientCode();
3444
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4036
        Rectangle screenBounds = graphicsConfig.getBounds();
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4037
        Insets screenInsets =
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4038
            Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4039
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4040
        wx = Window.limit(wx,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4041
                screenBounds.x + screenInsets.left,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4042
                screenBounds.x + screenBounds.width - screenInsets.right
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4043
                - securityWarningWidth);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4044
        wy = Window.limit(wy,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4045
                screenBounds.y + screenInsets.top,
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4046
                screenBounds.y + screenBounds.height - screenInsets.bottom
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4047
                - securityWarningHeight);
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4048
18840bd1c784 6818787: It is possible to reposition the security icon too far from the border of the window on X11
anthony
parents: 2472
diff changeset
  4049
        return new Point2D.Double(wx, wy);
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4050
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4051
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4052
    static {
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4053
        AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() {
2808
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  4054
            public void updateWindow(Window window) {
a139a919f645 6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents: 2648
diff changeset
  4055
                window.updateWindow();
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4056
            }
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4057
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4058
            public void setSecurityWarningSize(Window window, int width, int height)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4059
            {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4060
                window.securityWarningWidth = width;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4061
                window.securityWarningHeight = height;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4062
            }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4063
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4064
            public Point2D calculateSecurityWarningPosition(Window window,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4065
                    double x, double y, double w, double h)
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4066
            {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4067
                return window.calculateSecurityWarningPosition(x, y, w, h);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents: 2459
diff changeset
  4068
            }
3084
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2808
diff changeset
  4069
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2808
diff changeset
  4070
            public void setLWRequestStatus(Window changed, boolean status) {
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2808
diff changeset
  4071
                changed.syncLWRequests = status;
67ca55732362 6824169: Need to remove some AWT class dependencies
dcherepanov
parents: 2808
diff changeset
  4072
            }
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4073
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4074
            public boolean isAutoRequestFocus(Window w) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4075
                return w.autoRequestFocus;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4076
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4077
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4078
            public boolean isTrayIconWindow(Window w) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4079
                return w.isTrayIconWindow;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4080
            }
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4081
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4082
            public void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4083
                w.isTrayIconWindow = isTrayIconWindow;
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 4366
diff changeset
  4084
            }
42731
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 41395
diff changeset
  4085
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 41395
diff changeset
  4086
            public Window[] getOwnedWindows(Window w) {
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 41395
diff changeset
  4087
                return w.getOwnedWindows_NoClientCode();
631236c16dff 8169589: [macosx] Activating a JDialog puts to back another dialog
dmarkov
parents: 41395
diff changeset
  4088
            }
2451
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4089
        }); // WindowAccessor
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4090
    } // static
597df8e1d786 6633275: Need to support shaped/translucent windows
art
parents: 1972
diff changeset
  4091
2647
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  4092
    // a window doesn't need to be updated in the Z-order.
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  4093
    @Override
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  4094
    void updateZOrder() {}
ea80a312972e 6825362: Avoid calling peer.setZOrder on Window instances
dcherepanov
parents: 2472
diff changeset
  4095
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4096
} // class Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4099
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4100
 * This class is no longer used, but is maintained for Serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4101
 * backward-compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4102
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4103
class FocusManager implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4104
    Container focusRoot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4105
    Component focusOwner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4107
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4108
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4110
    static final long serialVersionUID = 2491878825643557906L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  4111
}