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