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