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