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