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