1 /*
   2  * Copyright (c) 1995, 2015, 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.CausedFocusEvent;
  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 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 is scanned for the images of most
 682      * appropriate dimensions from the beginning. If the list contains
 683      * several images of the same size, the first will be used.
 684      * <p>
 685      * Ownerless windows with no icon specified use platform-default icon.
 686      * The icon of an owned window may be inherited from the owner
 687      * unless explicitly overridden.
 688      * Setting the icon to {@code null} or empty list restores
 689      * the default behavior.
 690      * <p>
 691      * Note : Native windowing systems may use different images of differing
 692      * dimensions to represent a window, depending on the context (e.g.
 693      * window decoration, window list, taskbar, etc.). They could also use
 694      * just a single image for all contexts or no image at all.
 695      *
 696      * @param     icons the list of icon images to be displayed.
 697      * @see       #getIconImages()
 698      * @see       #setIconImage(Image)
 699      * @since     1.6
 700      */
 701     public synchronized void setIconImages(java.util.List<? extends Image> icons) {
 702         this.icons = (icons == null) ? new ArrayList<Image>() :
 703             new ArrayList<Image>(icons);
 704         WindowPeer peer = (WindowPeer)this.peer;
 705         if (peer != null) {
 706             peer.updateIconImages();
 707         }
 708         // Always send a property change event
 709         firePropertyChange("iconImage", null, null);
 710     }
 711 
 712     /**
 713      * Sets the image to be displayed as the icon for this window.
 714      * <p>
 715      * This method can be used instead of {@link #setIconImages setIconImages()}
 716      * to specify a single image as a window's icon.
 717      * <p>
 718      * The following statement:
 719      * <pre>
 720      *     setIconImage(image);
 721      * </pre>
 722      * is equivalent to:
 723      * <pre>
 724      *     ArrayList&lt;Image&gt; imageList = new ArrayList&lt;Image&gt;();
 725      *     imageList.add(image);
 726      *     setIconImages(imageList);
 727      * </pre>
 728      * <p>
 729      * Note : Native windowing systems may use different images of differing
 730      * dimensions to represent a window, depending on the context (e.g.
 731      * window decoration, window list, taskbar, etc.). They could also use
 732      * just a single image for all contexts or no image at all.
 733      *
 734      * @param     image the icon image to be displayed.
 735      * @see       #setIconImages
 736      * @see       #getIconImages()
 737      * @since     1.6
 738      */
 739     public void setIconImage(Image image) {
 740         ArrayList<Image> imageList = new ArrayList<Image>();
 741         if (image != null) {
 742             imageList.add(image);
 743         }
 744         setIconImages(imageList);
 745     }
 746 
 747     /**
 748      * Makes this Window displayable by creating the connection to its
 749      * native screen resource.
 750      * This method is called internally by the toolkit and should
 751      * not be called directly by programs.
 752      * @see Component#isDisplayable
 753      * @see Container#removeNotify
 754      * @since 1.0
 755      */
 756     public void addNotify() {
 757         synchronized (getTreeLock()) {
 758             Container parent = this.parent;
 759             if (parent != null && parent.peer == null) {
 760                 parent.addNotify();
 761             }
 762             if (peer == null) {
 763                 peer = getComponentFactory().createWindow(this);
 764             }
 765             synchronized (allWindows) {
 766                 allWindows.add(this);
 767             }
 768             super.addNotify();
 769         }
 770     }
 771 
 772     /**
 773      * {@inheritDoc}
 774      */
 775     public void removeNotify() {
 776         synchronized (getTreeLock()) {
 777             synchronized (allWindows) {
 778                 allWindows.remove(this);
 779             }
 780             super.removeNotify();
 781         }
 782     }
 783 
 784     /**
 785      * Causes this Window to be sized to fit the preferred size
 786      * and layouts of its subcomponents. The resulting width and
 787      * height of the window are automatically enlarged if either
 788      * of dimensions is less than the minimum size as specified
 789      * by the previous call to the {@code setMinimumSize} method.
 790      * <p>
 791      * If the window and/or its owner are not displayable yet,
 792      * both of them are made displayable before calculating
 793      * the preferred size. The Window is validated after its
 794      * size is being calculated.
 795      *
 796      * @see Component#isDisplayable
 797      * @see #setMinimumSize
 798      */
 799     @SuppressWarnings("deprecation")
 800     public void pack() {
 801         Container parent = this.parent;
 802         if (parent != null && parent.peer == null) {
 803             parent.addNotify();
 804         }
 805         if (peer == null) {
 806             addNotify();
 807         }
 808         Dimension newSize = getPreferredSize();
 809         if (peer != null) {
 810             setClientSize(newSize.width, newSize.height);
 811         }
 812 
 813         if(beforeFirstShow) {
 814             isPacked = true;
 815         }
 816 
 817         validateUnconditionally();
 818     }
 819 
 820     /**
 821      * Sets the minimum size of this window to a constant
 822      * value.  Subsequent calls to {@code getMinimumSize}
 823      * will always return this value. If current window's
 824      * size is less than {@code minimumSize} the size of the
 825      * window is automatically enlarged to honor the minimum size.
 826      * <p>
 827      * If the {@code setSize} or {@code setBounds} methods
 828      * are called afterwards with a width or height less than
 829      * that was specified by the {@code setMinimumSize} method
 830      * the window is automatically enlarged to meet
 831      * the {@code minimumSize} value. The {@code minimumSize}
 832      * value also affects the behaviour of the {@code pack} method.
 833      * <p>
 834      * The default behavior is restored by setting the minimum size
 835      * parameter to the {@code null} value.
 836      * <p>
 837      * Resizing operation may be restricted if the user tries
 838      * to resize window below the {@code minimumSize} value.
 839      * This behaviour is platform-dependent.
 840      *
 841      * @param minimumSize the new minimum size of this window
 842      * @see Component#setMinimumSize
 843      * @see #getMinimumSize
 844      * @see #isMinimumSizeSet
 845      * @see #setSize(Dimension)
 846      * @see #pack
 847      * @since 1.6
 848      */
 849     public void setMinimumSize(Dimension minimumSize) {
 850         synchronized (getTreeLock()) {
 851             super.setMinimumSize(minimumSize);
 852             Dimension size = getSize();
 853             if (isMinimumSizeSet()) {
 854                 if (size.width < minimumSize.width || size.height < minimumSize.height) {
 855                     int nw = Math.max(width, minimumSize.width);
 856                     int nh = Math.max(height, minimumSize.height);
 857                     setSize(nw, nh);
 858                 }
 859             }
 860             if (peer != null) {
 861                 ((WindowPeer)peer).updateMinimumSize();
 862             }
 863         }
 864     }
 865 
 866     /**
 867      * {@inheritDoc}
 868      * <p>
 869      * The {@code d.width} and {@code d.height} values
 870      * are automatically enlarged if either is less than
 871      * the minimum size as specified by previous call to
 872      * {@code setMinimumSize}.
 873      * <p>
 874      * The method changes the geometry-related data. Therefore,
 875      * the native windowing system may ignore such requests, or it may modify
 876      * the requested data, so that the {@code Window} object is placed and sized
 877      * in a way that corresponds closely to the desktop settings.
 878      *
 879      * @see #getSize
 880      * @see #setBounds
 881      * @see #setMinimumSize
 882      * @since 1.6
 883      */
 884     public void setSize(Dimension d) {
 885         super.setSize(d);
 886     }
 887 
 888     /**
 889      * {@inheritDoc}
 890      * <p>
 891      * The {@code width} and {@code height} values
 892      * are automatically enlarged if either is less than
 893      * the minimum size as specified by previous call to
 894      * {@code setMinimumSize}.
 895      * <p>
 896      * The method changes the geometry-related data. Therefore,
 897      * the native windowing system may ignore such requests, or it may modify
 898      * the requested data, so that the {@code Window} object is placed and sized
 899      * in a way that corresponds closely to the desktop settings.
 900      *
 901      * @see #getSize
 902      * @see #setBounds
 903      * @see #setMinimumSize
 904      * @since 1.6
 905      */
 906     public void setSize(int width, int height) {
 907         super.setSize(width, height);
 908     }
 909 
 910     /**
 911      * {@inheritDoc}
 912      * <p>
 913      * The method changes the geometry-related data. Therefore,
 914      * the native windowing system may ignore such requests, or it may modify
 915      * the requested data, so that the {@code Window} object is placed and sized
 916      * in a way that corresponds closely to the desktop settings.
 917      */
 918     @Override
 919     public void setLocation(int x, int y) {
 920         super.setLocation(x, y);
 921     }
 922 
 923     /**
 924      * {@inheritDoc}
 925      * <p>
 926      * The method changes the geometry-related data. Therefore,
 927      * the native windowing system may ignore such requests, or it may modify
 928      * the requested data, so that the {@code Window} object is placed and sized
 929      * in a way that corresponds closely to the desktop settings.
 930      */
 931     @Override
 932     public void setLocation(Point p) {
 933         super.setLocation(p);
 934     }
 935 
 936     /**
 937      * @deprecated As of JDK version 1.1,
 938      * replaced by {@code setBounds(int, int, int, int)}.
 939      */
 940     @Deprecated
 941     public void reshape(int x, int y, int width, int height) {
 942         if (isMinimumSizeSet()) {
 943             Dimension minSize = getMinimumSize();
 944             if (width < minSize.width) {
 945                 width = minSize.width;
 946             }
 947             if (height < minSize.height) {
 948                 height = minSize.height;
 949             }
 950         }
 951         super.reshape(x, y, width, height);
 952     }
 953 
 954     void setClientSize(int w, int h) {
 955         synchronized (getTreeLock()) {
 956             setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
 957             setBounds(x, y, w, h);
 958         }
 959     }
 960 
 961     static private final AtomicBoolean
 962         beforeFirstWindowShown = new AtomicBoolean(true);
 963 
 964     final void closeSplashScreen() {
 965         if (isTrayIconWindow) {
 966             return;
 967         }
 968         if (beforeFirstWindowShown.getAndSet(false)) {
 969             // We don't use SplashScreen.getSplashScreen() to avoid instantiating
 970             // the object if it hasn't been requested by user code explicitly
 971             SunToolkit.closeSplashScreen();
 972             SplashScreen.markClosed();
 973         }
 974     }
 975 
 976     /**
 977      * Shows or hides this {@code Window} depending on the value of parameter
 978      * {@code b}.
 979      * <p>
 980      * If the method shows the window then the window is also made
 981      * focused under the following conditions:
 982      * <ul>
 983      * <li> The {@code Window} meets the requirements outlined in the
 984      *      {@link #isFocusableWindow} method.
 985      * <li> The {@code Window}'s {@code autoRequestFocus} property is of the {@code true} value.
 986      * <li> Native windowing system allows the {@code Window} to get focused.
 987      * </ul>
 988      * There is an exception for the second condition (the value of the
 989      * {@code autoRequestFocus} property). The property is not taken into account if the
 990      * window is a modal dialog, which blocks the currently focused window.
 991      * <p>
 992      * Developers must never assume that the window is the focused or active window
 993      * until it receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event.
 994      * @param b  if {@code true}, makes the {@code Window} visible,
 995      * otherwise hides the {@code Window}.
 996      * If the {@code Window} and/or its owner
 997      * are not yet displayable, both are made displayable.  The
 998      * {@code Window} will be validated prior to being made visible.
 999      * If the {@code Window} is already visible, this will bring the
1000      * {@code Window} to the front.<p>
1001      * If {@code false}, hides this {@code Window}, its subcomponents, and all
1002      * of its owned children.
1003      * The {@code Window} and its subcomponents can be made visible again
1004      * with a call to {@code #setVisible(true)}.
1005      * @see java.awt.Component#isDisplayable
1006      * @see java.awt.Component#setVisible
1007      * @see java.awt.Window#toFront
1008      * @see java.awt.Window#dispose
1009      * @see java.awt.Window#setAutoRequestFocus
1010      * @see java.awt.Window#isFocusableWindow
1011      */
1012     public void setVisible(boolean b) {
1013         super.setVisible(b);
1014     }
1015 
1016     /**
1017      * Makes the Window visible. If the Window and/or its owner
1018      * are not yet displayable, both are made displayable.  The
1019      * Window will be validated prior to being made visible.
1020      * If the Window is already visible, this will bring the Window
1021      * to the front.
1022      * @see       Component#isDisplayable
1023      * @see       #toFront
1024      * @deprecated As of JDK version 1.5, replaced by
1025      * {@link #setVisible(boolean)}.
1026      */
1027     @Deprecated
1028     public void show() {
1029         if (peer == null) {
1030             addNotify();
1031         }
1032         validateUnconditionally();
1033 
1034         isInShow = true;
1035         if (visible) {
1036             toFront();
1037         } else {
1038             beforeFirstShow = false;
1039             closeSplashScreen();
1040             Dialog.checkShouldBeBlocked(this);
1041             super.show();
1042             synchronized (getTreeLock()) {
1043                 this.locationByPlatform = false;
1044             }
1045             for (int i = 0; i < ownedWindowList.size(); i++) {
1046                 Window child = ownedWindowList.elementAt(i).get();
1047                 if ((child != null) && child.showWithParent) {
1048                     child.show();
1049                     child.showWithParent = false;
1050                 }       // endif
1051             }   // endfor
1052             if (!isModalBlocked()) {
1053                 updateChildrenBlocking();
1054             } else {
1055                 // fix for 6532736: after this window is shown, its blocker
1056                 // should be raised to front
1057                 modalBlocker.toFront_NoClientCode();
1058             }
1059             if (this instanceof Frame || this instanceof Dialog) {
1060                 updateChildFocusableWindowState(this);
1061             }
1062         }
1063         isInShow = false;
1064 
1065         // If first time shown, generate WindowOpened event
1066         if ((state & OPENED) == 0) {
1067             postWindowEvent(WindowEvent.WINDOW_OPENED);
1068             state |= OPENED;
1069         }
1070     }
1071 
1072     static void updateChildFocusableWindowState(Window w) {
1073         if (w.peer != null && w.isShowing()) {
1074             ((WindowPeer)w.peer).updateFocusableWindowState();
1075         }
1076         for (int i = 0; i < w.ownedWindowList.size(); i++) {
1077             Window child = w.ownedWindowList.elementAt(i).get();
1078             if (child != null) {
1079                 updateChildFocusableWindowState(child);
1080             }
1081         }
1082     }
1083 
1084     synchronized void postWindowEvent(int id) {
1085         if (windowListener != null
1086             || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
1087             ||  Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
1088             WindowEvent e = new WindowEvent(this, id);
1089             Toolkit.getEventQueue().postEvent(e);
1090         }
1091     }
1092 
1093     /**
1094      * Hide this Window, its subcomponents, and all of its owned children.
1095      * The Window and its subcomponents can be made visible again
1096      * with a call to {@code show}.
1097      * @see #show
1098      * @see #dispose
1099      * @deprecated As of JDK version 1.5, replaced by
1100      * {@link #setVisible(boolean)}.
1101      */
1102     @Deprecated
1103     public void hide() {
1104         synchronized(ownedWindowList) {
1105             for (int i = 0; i < ownedWindowList.size(); i++) {
1106                 Window child = ownedWindowList.elementAt(i).get();
1107                 if ((child != null) && child.visible) {
1108                     child.hide();
1109                     child.showWithParent = true;
1110                 }
1111             }
1112         }
1113         if (isModalBlocked()) {
1114             modalBlocker.unblockWindow(this);
1115         }
1116         super.hide();
1117         synchronized (getTreeLock()) {
1118             this.locationByPlatform = false;
1119         }
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} {@code 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.
2163         if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_F1 &&
2164             e.isControlDown() && e.isShiftDown() &&
2165             e.getID() == KeyEvent.KEY_PRESSED) {
2166             list(System.out, 0);
2167         }
2168     }
2169 
2170     void postProcessKeyEvent(KeyEvent e) {
2171         // Do nothing
2172     }
2173 
2174 
2175     /**
2176      * Sets whether this window should always be above other windows.  If
2177      * there are multiple always-on-top windows, their relative order is
2178      * unspecified and platform dependent.
2179      * <p>
2180      * If some other window is already always-on-top then the
2181      * relative order between these windows is unspecified (depends on
2182      * platform).  No window can be brought to be over the always-on-top
2183      * window except maybe another always-on-top window.
2184      * <p>
2185      * All windows owned by an always-on-top window inherit this state and
2186      * automatically become always-on-top.  If a window ceases to be
2187      * always-on-top, the windows that it owns will no longer be
2188      * always-on-top.  When an always-on-top window is sent {@link #toBack
2189      * toBack}, its always-on-top state is set to {@code false}.
2190      *
2191      * <p> When this method is called on a window with a value of
2192      * {@code true}, and the window is visible and the platform
2193      * supports always-on-top for this window, the window is immediately
2194      * brought forward, "sticking" it in the top-most position. If the
2195      * window isn`t currently visible, this method sets the always-on-top
2196      * state to {@code true} but does not bring the window forward.
2197      * When the window is later shown, it will be always-on-top.
2198      *
2199      * <p> When this method is called on a window with a value of
2200      * {@code false} the always-on-top state is set to normal. It may also
2201      * cause an unspecified, platform-dependent change in the z-order of
2202      * top-level windows, but other always-on-top windows will remain in
2203      * top-most position. Calling this method with a value of {@code false}
2204      * on a window that has a normal state has no effect.
2205      *
2206      * <p><b>Note</b>: some platforms might not support always-on-top
2207      * windows.  To detect if always-on-top windows are supported by the
2208      * current platform, use {@link Toolkit#isAlwaysOnTopSupported()} and
2209      * {@link Window#isAlwaysOnTopSupported()}.  If always-on-top mode
2210      * isn't supported for this window or this window's toolkit does not
2211      * support always-on-top windows, calling this method has no effect.
2212      * <p>
2213      * If a SecurityManager is installed, the calling thread must be
2214      * granted the AWTPermission "setWindowAlwaysOnTop" in
2215      * order to set the value of this property. If this
2216      * permission is not granted, this method will throw a
2217      * SecurityException, and the current value of the property will
2218      * be left unchanged.
2219      *
2220      * @param alwaysOnTop true if the window should always be above other
2221      *        windows
2222      * @throws SecurityException if the calling thread does not have
2223      *         permission to set the value of always-on-top property
2224      *
2225      * @see #isAlwaysOnTop
2226      * @see #toFront
2227      * @see #toBack
2228      * @see AWTPermission
2229      * @see #isAlwaysOnTopSupported
2230      * @see #getToolkit
2231      * @see Toolkit#isAlwaysOnTopSupported
2232      * @since 1.5
2233      */
2234     public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
2235         SecurityManager security = System.getSecurityManager();
2236         if (security != null) {
2237             security.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
2238         }
2239 
2240         boolean oldAlwaysOnTop;
2241         synchronized(this) {
2242             oldAlwaysOnTop = this.alwaysOnTop;
2243             this.alwaysOnTop = alwaysOnTop;
2244         }
2245         if (oldAlwaysOnTop != alwaysOnTop ) {
2246             if (isAlwaysOnTopSupported()) {
2247                 WindowPeer peer = (WindowPeer)this.peer;
2248                 synchronized(getTreeLock()) {
2249                     if (peer != null) {
2250                         peer.updateAlwaysOnTopState();
2251                     }
2252                 }
2253             }
2254             firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop);
2255         }
2256         setOwnedWindowsAlwaysOnTop(alwaysOnTop);
2257     }
2258 
2259     @SuppressWarnings({"rawtypes", "unchecked"})
2260     private void setOwnedWindowsAlwaysOnTop(boolean alwaysOnTop) {
2261         WeakReference<Window>[] ownedWindowArray;
2262         synchronized (ownedWindowList) {
2263             ownedWindowArray = new WeakReference[ownedWindowList.size()];
2264             ownedWindowList.copyInto(ownedWindowArray);
2265         }
2266 
2267         for (WeakReference<Window> ref : ownedWindowArray) {
2268             Window window = ref.get();
2269             if (window != null) {
2270                 try {
2271                     window.setAlwaysOnTop(alwaysOnTop);
2272                 } catch (SecurityException ignore) {
2273                 }
2274             }
2275         }
2276     }
2277 
2278     /**
2279      * Returns whether the always-on-top mode is supported for this
2280      * window. Some platforms may not support always-on-top windows, some
2281      * may support only some kinds of top-level windows; for example,
2282      * a platform may not support always-on-top modal dialogs.
2283      *
2284      * @return {@code true}, if the always-on-top mode is supported for
2285      *         this window and this window's toolkit supports always-on-top windows,
2286      *         {@code false} otherwise
2287      *
2288      * @see #setAlwaysOnTop(boolean)
2289      * @see #getToolkit
2290      * @see Toolkit#isAlwaysOnTopSupported
2291      * @since 1.6
2292      */
2293     public boolean isAlwaysOnTopSupported() {
2294         return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
2295     }
2296 
2297 
2298     /**
2299      * Returns whether this window is an always-on-top window.
2300      * @return {@code true}, if the window is in always-on-top state,
2301      *         {@code false} otherwise
2302      * @see #setAlwaysOnTop
2303      * @since 1.5
2304      */
2305     public final boolean isAlwaysOnTop() {
2306         return alwaysOnTop;
2307     }
2308 
2309 
2310     /**
2311      * Returns the child Component of this Window that has focus if this Window
2312      * is focused; returns null otherwise.
2313      *
2314      * @return the child Component with focus, or null if this Window is not
2315      *         focused
2316      * @see #getMostRecentFocusOwner
2317      * @see #isFocused
2318      */
2319     public Component getFocusOwner() {
2320         return (isFocused())
2321             ? KeyboardFocusManager.getCurrentKeyboardFocusManager().
2322                   getFocusOwner()
2323             : null;
2324     }
2325 
2326     /**
2327      * Returns the child Component of this Window that will receive the focus
2328      * when this Window is focused. If this Window is currently focused, this
2329      * method returns the same Component as {@code getFocusOwner()}. If
2330      * this Window is not focused, then the child Component that most recently
2331      * requested focus will be returned. If no child Component has ever
2332      * requested focus, and this is a focusable Window, then this Window's
2333      * initial focusable Component is returned. If no child Component has ever
2334      * requested focus, and this is a non-focusable Window, null is returned.
2335      *
2336      * @return the child Component that will receive focus when this Window is
2337      *         focused
2338      * @see #getFocusOwner
2339      * @see #isFocused
2340      * @see #isFocusableWindow
2341      * @since 1.4
2342      */
2343     public Component getMostRecentFocusOwner() {
2344         if (isFocused()) {
2345             return getFocusOwner();
2346         } else {
2347             Component mostRecent =
2348                 KeyboardFocusManager.getMostRecentFocusOwner(this);
2349             if (mostRecent != null) {
2350                 return mostRecent;
2351             } else {
2352                 return (isFocusableWindow())
2353                     ? getFocusTraversalPolicy().getInitialComponent(this)
2354                     : null;
2355             }
2356         }
2357     }
2358 
2359     /**
2360      * Returns whether this Window is active. Only a Frame or a Dialog may be
2361      * active. The native windowing system may denote the active Window or its
2362      * children with special decorations, such as a highlighted title bar. The
2363      * active Window is always either the focused Window, or the first Frame or
2364      * Dialog that is an owner of the focused Window.
2365      *
2366      * @return whether this is the active Window.
2367      * @see #isFocused
2368      * @since 1.4
2369      */
2370     public boolean isActive() {
2371         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2372                 getActiveWindow() == this);
2373     }
2374 
2375     /**
2376      * Returns whether this Window is focused. If there exists a focus owner,
2377      * the focused Window is the Window that is, or contains, that focus owner.
2378      * If there is no focus owner, then no Window is focused.
2379      * <p>
2380      * If the focused Window is a Frame or a Dialog it is also the active
2381      * Window. Otherwise, the active Window is the first Frame or Dialog that
2382      * is an owner of the focused Window.
2383      *
2384      * @return whether this is the focused Window.
2385      * @see #isActive
2386      * @since 1.4
2387      */
2388     public boolean isFocused() {
2389         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2390                 getGlobalFocusedWindow() == this);
2391     }
2392 
2393     /**
2394      * Gets a focus traversal key for this Window. (See {@code
2395      * setFocusTraversalKeys} for a full description of each key.)
2396      * <p>
2397      * If the traversal key has not been explicitly set for this Window,
2398      * then this Window's parent's traversal key is returned. If the
2399      * traversal key has not been explicitly set for any of this Window's
2400      * ancestors, then the current KeyboardFocusManager's default traversal key
2401      * is returned.
2402      *
2403      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2404      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2405      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2406      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2407      * @return the AWTKeyStroke for the specified key
2408      * @see Container#setFocusTraversalKeys
2409      * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
2410      * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
2411      * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
2412      * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
2413      * @throws IllegalArgumentException if id is not one of
2414      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2415      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2416      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2417      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2418      * @since 1.4
2419      */
2420     @SuppressWarnings("unchecked")
2421     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2422         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
2423             throw new IllegalArgumentException("invalid focus traversal key identifier");
2424         }
2425 
2426         // Okay to return Set directly because it is an unmodifiable view
2427         @SuppressWarnings("rawtypes")
2428         Set keystrokes = (focusTraversalKeys != null)
2429             ? focusTraversalKeys[id]
2430             : null;
2431 
2432         if (keystrokes != null) {
2433             return keystrokes;
2434         } else {
2435             return KeyboardFocusManager.getCurrentKeyboardFocusManager().
2436                 getDefaultFocusTraversalKeys(id);
2437         }
2438     }
2439 
2440     /**
2441      * Does nothing because Windows must always be roots of a focus traversal
2442      * cycle. The passed-in value is ignored.
2443      *
2444      * @param focusCycleRoot this value is ignored
2445      * @see #isFocusCycleRoot
2446      * @see Container#setFocusTraversalPolicy
2447      * @see Container#getFocusTraversalPolicy
2448      * @since 1.4
2449      */
2450     public final void setFocusCycleRoot(boolean focusCycleRoot) {
2451     }
2452 
2453     /**
2454      * Always returns {@code true} because all Windows must be roots of a
2455      * focus traversal cycle.
2456      *
2457      * @return {@code true}
2458      * @see #setFocusCycleRoot
2459      * @see Container#setFocusTraversalPolicy
2460      * @see Container#getFocusTraversalPolicy
2461      * @since 1.4
2462      */
2463     public final boolean isFocusCycleRoot() {
2464         return true;
2465     }
2466 
2467     /**
2468      * Always returns {@code null} because Windows have no ancestors; they
2469      * represent the top of the Component hierarchy.
2470      *
2471      * @return {@code null}
2472      * @see Container#isFocusCycleRoot()
2473      * @since 1.4
2474      */
2475     public final Container getFocusCycleRootAncestor() {
2476         return null;
2477     }
2478 
2479     /**
2480      * Returns whether this Window can become the focused Window, that is,
2481      * whether this Window or any of its subcomponents can become the focus
2482      * owner. For a Frame or Dialog to be focusable, its focusable Window state
2483      * must be set to {@code true}. For a Window which is not a Frame or
2484      * Dialog to be focusable, its focusable Window state must be set to
2485      * {@code true}, its nearest owning Frame or Dialog must be
2486      * showing on the screen, and it must contain at least one Component in
2487      * its focus traversal cycle. If any of these conditions is not met, then
2488      * neither this Window nor any of its subcomponents can become the focus
2489      * owner.
2490      *
2491      * @return {@code true} if this Window can be the focused Window;
2492      *         {@code false} otherwise
2493      * @see #getFocusableWindowState
2494      * @see #setFocusableWindowState
2495      * @see #isShowing
2496      * @see Component#isFocusable
2497      * @since 1.4
2498      */
2499     public final boolean isFocusableWindow() {
2500         // If a Window/Frame/Dialog was made non-focusable, then it is always
2501         // non-focusable.
2502         if (!getFocusableWindowState()) {
2503             return false;
2504         }
2505 
2506         // All other tests apply only to Windows.
2507         if (this instanceof Frame || this instanceof Dialog) {
2508             return true;
2509         }
2510 
2511         // A Window must have at least one Component in its root focus
2512         // traversal cycle to be focusable.
2513         if (getFocusTraversalPolicy().getDefaultComponent(this) == null) {
2514             return false;
2515         }
2516 
2517         // A Window's nearest owning Frame or Dialog must be showing on the
2518         // screen.
2519         for (Window owner = getOwner(); owner != null;
2520              owner = owner.getOwner())
2521         {
2522             if (owner instanceof Frame || owner instanceof Dialog) {
2523                 return owner.isShowing();
2524             }
2525         }
2526 
2527         return false;
2528     }
2529 
2530     /**
2531      * Returns whether this Window can become the focused Window if it meets
2532      * the other requirements outlined in {@code isFocusableWindow}. If
2533      * this method returns {@code false}, then
2534      * {@code isFocusableWindow} will return {@code false} as well.
2535      * If this method returns {@code true}, then
2536      * {@code isFocusableWindow} may return {@code true} or
2537      * {@code false} depending upon the other requirements which must be
2538      * met in order for a Window to be focusable.
2539      * <p>
2540      * By default, all Windows have a focusable Window state of
2541      * {@code true}.
2542      *
2543      * @return whether this Window can be the focused Window
2544      * @see #isFocusableWindow
2545      * @see #setFocusableWindowState
2546      * @see #isShowing
2547      * @see Component#setFocusable
2548      * @since 1.4
2549      */
2550     public boolean getFocusableWindowState() {
2551         return focusableWindowState;
2552     }
2553 
2554     /**
2555      * Sets whether this Window can become the focused Window if it meets
2556      * the other requirements outlined in {@code isFocusableWindow}. If
2557      * this Window's focusable Window state is set to {@code false}, then
2558      * {@code isFocusableWindow} will return {@code false}. If this
2559      * Window's focusable Window state is set to {@code true}, then
2560      * {@code isFocusableWindow} may return {@code true} or
2561      * {@code false} depending upon the other requirements which must be
2562      * met in order for a Window to be focusable.
2563      * <p>
2564      * Setting a Window's focusability state to {@code false} is the
2565      * standard mechanism for an application to identify to the AWT a Window
2566      * which will be used as a floating palette or toolbar, and thus should be
2567      * a non-focusable Window.
2568      *
2569      * Setting the focusability state on a visible {@code Window}
2570      * can have a delayed effect on some platforms — the actual
2571      * change may happen only when the {@code Window} becomes
2572      * hidden and then visible again.  To ensure consistent behavior
2573      * across platforms, set the {@code Window}'s focusable state
2574      * when the {@code Window} is invisible and then show it.
2575      *
2576      * @param focusableWindowState whether this Window can be the focused
2577      *        Window
2578      * @see #isFocusableWindow
2579      * @see #getFocusableWindowState
2580      * @see #isShowing
2581      * @see Component#setFocusable
2582      * @since 1.4
2583      */
2584     public void setFocusableWindowState(boolean focusableWindowState) {
2585         boolean oldFocusableWindowState;
2586         synchronized (this) {
2587             oldFocusableWindowState = this.focusableWindowState;
2588             this.focusableWindowState = focusableWindowState;
2589         }
2590         WindowPeer peer = (WindowPeer)this.peer;
2591         if (peer != null) {
2592             peer.updateFocusableWindowState();
2593         }
2594         firePropertyChange("focusableWindowState", oldFocusableWindowState,
2595                            focusableWindowState);
2596         if (oldFocusableWindowState && !focusableWindowState && isFocused()) {
2597             for (Window owner = getOwner();
2598                  owner != null;
2599                  owner = owner.getOwner())
2600                 {
2601                     Component toFocus =
2602                         KeyboardFocusManager.getMostRecentFocusOwner(owner);
2603                     if (toFocus != null && toFocus.requestFocus(false, CausedFocusEvent.Cause.ACTIVATION)) {
2604                         return;
2605                     }
2606                 }
2607             KeyboardFocusManager.getCurrentKeyboardFocusManager().
2608                 clearGlobalFocusOwnerPriv();
2609         }
2610     }
2611 
2612     /**
2613      * Sets whether this window should receive focus on
2614      * subsequently being shown (with a call to {@link #setVisible setVisible(true)}),
2615      * or being moved to the front (with a call to {@link #toFront}).
2616      * <p>
2617      * Note that {@link #setVisible setVisible(true)} may be called indirectly
2618      * (e.g. when showing an owner of the window makes the window to be shown).
2619      * {@link #toFront} may also be called indirectly (e.g. when
2620      * {@link #setVisible setVisible(true)} is called on already visible window).
2621      * In all such cases this property takes effect as well.
2622      * <p>
2623      * The value of the property is not inherited by owned windows.
2624      *
2625      * @param autoRequestFocus whether this window should be focused on
2626      *        subsequently being shown or being moved to the front
2627      * @see #isAutoRequestFocus
2628      * @see #isFocusableWindow
2629      * @see #setVisible
2630      * @see #toFront
2631      * @since 1.7
2632      */
2633     public void setAutoRequestFocus(boolean autoRequestFocus) {
2634         this.autoRequestFocus = autoRequestFocus;
2635     }
2636 
2637     /**
2638      * Returns whether this window should receive focus on subsequently being shown
2639      * (with a call to {@link #setVisible setVisible(true)}), or being moved to the front
2640      * (with a call to {@link #toFront}).
2641      * <p>
2642      * By default, the window has {@code autoRequestFocus} value of {@code true}.
2643      *
2644      * @return {@code autoRequestFocus} value
2645      * @see #setAutoRequestFocus
2646      * @since 1.7
2647      */
2648     public boolean isAutoRequestFocus() {
2649         return autoRequestFocus;
2650     }
2651 
2652     /**
2653      * Adds a PropertyChangeListener to the listener list. The listener is
2654      * registered for all bound properties of this class, including the
2655      * following:
2656      * <ul>
2657      *    <li>this Window's font ("font")</li>
2658      *    <li>this Window's background color ("background")</li>
2659      *    <li>this Window's foreground color ("foreground")</li>
2660      *    <li>this Window's focusability ("focusable")</li>
2661      *    <li>this Window's focus traversal keys enabled state
2662      *        ("focusTraversalKeysEnabled")</li>
2663      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2664      *        ("forwardFocusTraversalKeys")</li>
2665      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2666      *        ("backwardFocusTraversalKeys")</li>
2667      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2668      *        ("upCycleFocusTraversalKeys")</li>
2669      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2670      *        ("downCycleFocusTraversalKeys")</li>
2671      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2672      *        </li>
2673      *    <li>this Window's focusable Window state ("focusableWindowState")
2674      *        </li>
2675      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2676      * </ul>
2677      * Note that if this Window is inheriting a bound property, then no
2678      * event will be fired in response to a change in the inherited property.
2679      * <p>
2680      * If listener is null, no exception is thrown and no action is performed.
2681      *
2682      * @param    listener  the PropertyChangeListener to be added
2683      *
2684      * @see Component#removePropertyChangeListener
2685      * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
2686      */
2687     public void addPropertyChangeListener(PropertyChangeListener listener) {
2688         super.addPropertyChangeListener(listener);
2689     }
2690 
2691     /**
2692      * Adds a PropertyChangeListener to the listener list for a specific
2693      * property. The specified property may be user-defined, or one of the
2694      * following:
2695      * <ul>
2696      *    <li>this Window's font ("font")</li>
2697      *    <li>this Window's background color ("background")</li>
2698      *    <li>this Window's foreground color ("foreground")</li>
2699      *    <li>this Window's focusability ("focusable")</li>
2700      *    <li>this Window's focus traversal keys enabled state
2701      *        ("focusTraversalKeysEnabled")</li>
2702      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2703      *        ("forwardFocusTraversalKeys")</li>
2704      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2705      *        ("backwardFocusTraversalKeys")</li>
2706      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2707      *        ("upCycleFocusTraversalKeys")</li>
2708      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2709      *        ("downCycleFocusTraversalKeys")</li>
2710      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2711      *        </li>
2712      *    <li>this Window's focusable Window state ("focusableWindowState")
2713      *        </li>
2714      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2715      * </ul>
2716      * Note that if this Window is inheriting a bound property, then no
2717      * event will be fired in response to a change in the inherited property.
2718      * <p>
2719      * If listener is null, no exception is thrown and no action is performed.
2720      *
2721      * @param propertyName one of the property names listed above
2722      * @param listener the PropertyChangeListener to be added
2723      *
2724      * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
2725      * @see Component#removePropertyChangeListener
2726      */
2727     public void addPropertyChangeListener(String propertyName,
2728                                           PropertyChangeListener listener) {
2729         super.addPropertyChangeListener(propertyName, listener);
2730     }
2731 
2732     /**
2733      * Indicates if this container is a validate root.
2734      * <p>
2735      * {@code Window} objects are the validate roots, and, therefore, they
2736      * override this method to return {@code true}.
2737      *
2738      * @return {@code true}
2739      * @since 1.7
2740      * @see java.awt.Container#isValidateRoot
2741      */
2742     @Override
2743     public boolean isValidateRoot() {
2744         return true;
2745     }
2746 
2747     /**
2748      * Dispatches an event to this window or one of its sub components.
2749      * @param e the event
2750      */
2751     void dispatchEventImpl(AWTEvent e) {
2752         if (e.getID() == ComponentEvent.COMPONENT_RESIZED) {
2753             invalidate();
2754             validate();
2755         }
2756         super.dispatchEventImpl(e);
2757     }
2758 
2759     /**
2760      * @deprecated As of JDK version 1.1
2761      * replaced by {@code dispatchEvent(AWTEvent)}.
2762      */
2763     @Deprecated
2764     public boolean postEvent(Event e) {
2765         if (handleEvent(e)) {
2766             e.consume();
2767             return true;
2768         }
2769         return false;
2770     }
2771 
2772     /**
2773      * Checks if this Window is showing on screen.
2774      * @see Component#setVisible
2775     */
2776     public boolean isShowing() {
2777         return visible;
2778     }
2779 
2780     boolean isDisposing() {
2781         return disposing;
2782     }
2783 
2784     /**
2785      * @deprecated As of J2SE 1.4, replaced by
2786      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2787      */
2788     @Deprecated
2789     public void applyResourceBundle(ResourceBundle rb) {
2790         applyComponentOrientation(ComponentOrientation.getOrientation(rb));
2791     }
2792 
2793     /**
2794      * @deprecated As of J2SE 1.4, replaced by
2795      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2796      */
2797     @Deprecated
2798     public void applyResourceBundle(String rbName) {
2799         applyResourceBundle(ResourceBundle.getBundle(rbName));
2800     }
2801 
2802    /*
2803     * Support for tracking all windows owned by this window
2804     */
2805     void addOwnedWindow(WeakReference<Window> weakWindow) {
2806         if (weakWindow != null) {
2807             synchronized(ownedWindowList) {
2808                 // this if statement should really be an assert, but we don't
2809                 // have asserts...
2810                 if (!ownedWindowList.contains(weakWindow)) {
2811                     ownedWindowList.addElement(weakWindow);
2812                 }
2813             }
2814         }
2815     }
2816 
2817     void removeOwnedWindow(WeakReference<Window> weakWindow) {
2818         if (weakWindow != null) {
2819             // synchronized block not required since removeElement is
2820             // already synchronized
2821             ownedWindowList.removeElement(weakWindow);
2822         }
2823     }
2824 
2825     void connectOwnedWindow(Window child) {
2826         child.parent = this;
2827         addOwnedWindow(child.weakThis);
2828         child.disposerRecord.updateOwner();
2829     }
2830 
2831     private void addToWindowList() {
2832         synchronized (Window.class) {
2833             @SuppressWarnings("unchecked")
2834             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
2835             if (windowList == null) {
2836                 windowList = new Vector<WeakReference<Window>>();
2837                 appContext.put(Window.class, windowList);
2838             }
2839             windowList.add(weakThis);
2840         }
2841     }
2842 
2843     private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
2844         synchronized (Window.class) {
2845             @SuppressWarnings("unchecked")
2846             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
2847             if (windowList != null) {
2848                 windowList.remove(weakThis);
2849             }
2850         }
2851     }
2852 
2853     private void removeFromWindowList() {
2854         removeFromWindowList(appContext, weakThis);
2855     }
2856 
2857     /**
2858      * Window type.
2859      *
2860      * Synchronization: ObjectLock
2861      */
2862     private Type type = Type.NORMAL;
2863 
2864     /**
2865      * Sets the type of the window.
2866      *
2867      * This method can only be called while the window is not displayable.
2868      *
2869      * @param  type the window type
2870      * @throws IllegalComponentStateException if the window
2871      *         is displayable.
2872      * @throws IllegalArgumentException if the type is {@code null}
2873      * @see    Component#isDisplayable
2874      * @see    #getType
2875      * @since 1.7
2876      */
2877     public void setType(Type type) {
2878         if (type == null) {
2879             throw new IllegalArgumentException("type should not be null.");
2880         }
2881         synchronized (getTreeLock()) {
2882             if (isDisplayable()) {
2883                 throw new IllegalComponentStateException(
2884                         "The window is displayable.");
2885             }
2886             synchronized (getObjectLock()) {
2887                 this.type = type;
2888             }
2889         }
2890     }
2891 
2892     /**
2893      * Returns the type of the window.
2894      *
2895      * @return the type of the window
2896      * @see   #setType
2897      * @since 1.7
2898      */
2899     public Type getType() {
2900         synchronized (getObjectLock()) {
2901             return type;
2902         }
2903     }
2904 
2905     /**
2906      * The window serialized data version.
2907      *
2908      * @serial
2909      */
2910     private int windowSerializedDataVersion = 2;
2911 
2912     /**
2913      * Writes default serializable fields to stream.  Writes
2914      * a list of serializable {@code WindowListener}s and
2915      * {@code WindowFocusListener}s as optional data.
2916      * Writes a list of child windows as optional data.
2917      * Writes a list of icon images as optional data
2918      *
2919      * @param s the {@code ObjectOutputStream} to write
2920      * @serialData {@code null} terminated sequence of
2921      *    0 or more pairs; the pair consists of a {@code String}
2922      *    and {@code Object}; the {@code String}
2923      *    indicates the type of object and is one of the following:
2924      *    {@code windowListenerK} indicating a
2925      *      {@code WindowListener} object;
2926      *    {@code windowFocusWindowK} indicating a
2927      *      {@code WindowFocusListener} object;
2928      *    {@code ownedWindowK} indicating a child
2929      *      {@code Window} object
2930      *
2931      * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
2932      * @see Component#windowListenerK
2933      * @see Component#windowFocusListenerK
2934      * @see Component#ownedWindowK
2935      * @see #readObject(ObjectInputStream)
2936      */
2937     private void writeObject(ObjectOutputStream s) throws IOException {
2938         synchronized (this) {
2939             // Update old focusMgr fields so that our object stream can be read
2940             // by previous releases
2941             focusMgr = new FocusManager();
2942             focusMgr.focusRoot = this;
2943             focusMgr.focusOwner = getMostRecentFocusOwner();
2944 
2945             s.defaultWriteObject();
2946 
2947             // Clear fields so that we don't keep extra references around
2948             focusMgr = null;
2949 
2950             AWTEventMulticaster.save(s, windowListenerK, windowListener);
2951             AWTEventMulticaster.save(s, windowFocusListenerK, windowFocusListener);
2952             AWTEventMulticaster.save(s, windowStateListenerK, windowStateListener);
2953         }
2954 
2955         s.writeObject(null);
2956 
2957         synchronized (ownedWindowList) {
2958             for (int i = 0; i < ownedWindowList.size(); i++) {
2959                 Window child = ownedWindowList.elementAt(i).get();
2960                 if (child != null) {
2961                     s.writeObject(ownedWindowK);
2962                     s.writeObject(child);
2963                 }
2964             }
2965         }
2966         s.writeObject(null);
2967 
2968         //write icon array
2969         if (icons != null) {
2970             for (Image i : icons) {
2971                 if (i instanceof Serializable) {
2972                     s.writeObject(i);
2973                 }
2974             }
2975         }
2976         s.writeObject(null);
2977     }
2978 
2979     //
2980     // Part of deserialization procedure to be called before
2981     // user's code.
2982     //
2983     private void initDeserializedWindow() {
2984         setWarningString();
2985         inputContextLock = new Object();
2986 
2987         // Deserialized Windows are not yet visible.
2988         visible = false;
2989 
2990         weakThis = new WeakReference<>(this);
2991 
2992         anchor = new Object();
2993         disposerRecord = new WindowDisposerRecord(appContext, this);
2994         sun.java2d.Disposer.addRecord(anchor, disposerRecord);
2995 
2996         addToWindowList();
2997         initGC(null);
2998         ownedWindowList = new Vector<>();
2999     }
3000 
3001     private void deserializeResources(ObjectInputStream s)
3002         throws ClassNotFoundException, IOException, HeadlessException {
3003 
3004             if (windowSerializedDataVersion < 2) {
3005                 // Translate old-style focus tracking to new model. For 1.4 and
3006                 // later releases, we'll rely on the Window's initial focusable
3007                 // Component.
3008                 if (focusMgr != null) {
3009                     if (focusMgr.focusOwner != null) {
3010                         KeyboardFocusManager.
3011                             setMostRecentFocusOwner(this, focusMgr.focusOwner);
3012                     }
3013                 }
3014 
3015                 // This field is non-transient and relies on default serialization.
3016                 // However, the default value is insufficient, so we need to set
3017                 // it explicitly for object data streams prior to 1.4.
3018                 focusableWindowState = true;
3019 
3020 
3021             }
3022 
3023         Object keyOrNull;
3024         while(null != (keyOrNull = s.readObject())) {
3025             String key = ((String)keyOrNull).intern();
3026 
3027             if (windowListenerK == key) {
3028                 addWindowListener((WindowListener)(s.readObject()));
3029             } else if (windowFocusListenerK == key) {
3030                 addWindowFocusListener((WindowFocusListener)(s.readObject()));
3031             } else if (windowStateListenerK == key) {
3032                 addWindowStateListener((WindowStateListener)(s.readObject()));
3033             } else // skip value for unrecognized key
3034                 s.readObject();
3035         }
3036 
3037         try {
3038             while (null != (keyOrNull = s.readObject())) {
3039                 String key = ((String)keyOrNull).intern();
3040 
3041                 if (ownedWindowK == key)
3042                     connectOwnedWindow((Window) s.readObject());
3043 
3044                 else // skip value for unrecognized key
3045                     s.readObject();
3046             }
3047 
3048             //read icons
3049             Object obj = s.readObject(); //Throws OptionalDataException
3050                                          //for pre1.6 objects.
3051             icons = new ArrayList<Image>(); //Frame.readObject() assumes
3052                                             //pre1.6 version if icons is null.
3053             while (obj != null) {
3054                 if (obj instanceof Image) {
3055                     icons.add((Image)obj);
3056                 }
3057                 obj = s.readObject();
3058             }
3059         }
3060         catch (OptionalDataException e) {
3061             // 1.1 serialized form
3062             // ownedWindowList will be updated by Frame.readObject
3063         }
3064 
3065     }
3066 
3067     /**
3068      * Reads the {@code ObjectInputStream} and an optional
3069      * list of listeners to receive various events fired by
3070      * the component; also reads a list of
3071      * (possibly {@code null}) child windows.
3072      * Unrecognized keys or values will be ignored.
3073      *
3074      * @param s the {@code ObjectInputStream} to read
3075      * @exception HeadlessException if
3076      *   {@code GraphicsEnvironment.isHeadless} returns
3077      *   {@code true}
3078      * @see java.awt.GraphicsEnvironment#isHeadless
3079      * @see #writeObject
3080      */
3081     private void readObject(ObjectInputStream s)
3082       throws ClassNotFoundException, IOException, HeadlessException
3083     {
3084          GraphicsEnvironment.checkHeadless();
3085          initDeserializedWindow();
3086          ObjectInputStream.GetField f = s.readFields();
3087 
3088          syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests);
3089          state = f.get("state", 0);
3090          focusableWindowState = f.get("focusableWindowState", true);
3091          windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1);
3092          locationByPlatform = f.get("locationByPlatform", locationByPlatformProp);
3093          // Note: 1.4 (or later) doesn't use focusMgr
3094          focusMgr = (FocusManager)f.get("focusMgr", null);
3095          Dialog.ModalExclusionType et = (Dialog.ModalExclusionType)
3096              f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE);
3097          setModalExclusionType(et); // since 6.0
3098          boolean aot = f.get("alwaysOnTop", false);
3099          if(aot) {
3100              setAlwaysOnTop(aot); // since 1.5; subject to permission check
3101          }
3102          shape = (Shape)f.get("shape", null);
3103          opacity = (Float)f.get("opacity", 1.0f);
3104 
3105          this.securityWarningWidth = 0;
3106          this.securityWarningHeight = 0;
3107          this.securityWarningPointX = 2.0;
3108          this.securityWarningPointY = 0.0;
3109          this.securityWarningAlignmentX = RIGHT_ALIGNMENT;
3110          this.securityWarningAlignmentY = TOP_ALIGNMENT;
3111 
3112          deserializeResources(s);
3113     }
3114 
3115     /*
3116      * --- Accessibility Support ---
3117      *
3118      */
3119 
3120     /**
3121      * Gets the AccessibleContext associated with this Window.
3122      * For windows, the AccessibleContext takes the form of an
3123      * AccessibleAWTWindow.
3124      * A new AccessibleAWTWindow instance is created if necessary.
3125      *
3126      * @return an AccessibleAWTWindow that serves as the
3127      *         AccessibleContext of this Window
3128      * @since 1.3
3129      */
3130     public AccessibleContext getAccessibleContext() {
3131         if (accessibleContext == null) {
3132             accessibleContext = new AccessibleAWTWindow();
3133         }
3134         return accessibleContext;
3135     }
3136 
3137     /**
3138      * This class implements accessibility support for the
3139      * {@code Window} class.  It provides an implementation of the
3140      * Java Accessibility API appropriate to window user-interface elements.
3141      * @since 1.3
3142      */
3143     protected class AccessibleAWTWindow extends AccessibleAWTContainer
3144     {
3145         /*
3146          * JDK 1.3 serialVersionUID
3147          */
3148         private static final long serialVersionUID = 4215068635060671780L;
3149 
3150         /**
3151          * Get the role of this object.
3152          *
3153          * @return an instance of AccessibleRole describing the role of the
3154          * object
3155          * @see javax.accessibility.AccessibleRole
3156          */
3157         public AccessibleRole getAccessibleRole() {
3158             return AccessibleRole.WINDOW;
3159         }
3160 
3161         /**
3162          * Get the state of this object.
3163          *
3164          * @return an instance of AccessibleStateSet containing the current
3165          * state set of the object
3166          * @see javax.accessibility.AccessibleState
3167          */
3168         public AccessibleStateSet getAccessibleStateSet() {
3169             AccessibleStateSet states = super.getAccessibleStateSet();
3170             if (getFocusOwner() != null) {
3171                 states.add(AccessibleState.ACTIVE);
3172             }
3173             return states;
3174         }
3175 
3176     } // inner class AccessibleAWTWindow
3177 
3178     @Override
3179     void setGraphicsConfiguration(GraphicsConfiguration gc) {
3180         if (gc == null) {
3181             gc = GraphicsEnvironment.
3182                     getLocalGraphicsEnvironment().
3183                     getDefaultScreenDevice().
3184                     getDefaultConfiguration();
3185         }
3186         synchronized (getTreeLock()) {
3187             super.setGraphicsConfiguration(gc);
3188             if (log.isLoggable(PlatformLogger.Level.FINER)) {
3189                 log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this);
3190             }
3191         }
3192     }
3193 
3194     /**
3195      * Sets the location of the window relative to the specified
3196      * component according to the following scenarios.
3197      * <p>
3198      * The target screen mentioned below is a screen to which
3199      * the window should be placed after the setLocationRelativeTo
3200      * method is called.
3201      * <ul>
3202      * <li>If the component is {@code null}, or the {@code
3203      * GraphicsConfiguration} associated with this component is
3204      * {@code null}, the window is placed in the center of the
3205      * screen. The center point can be obtained with the {@link
3206      * GraphicsEnvironment#getCenterPoint
3207      * GraphicsEnvironment.getCenterPoint} method.
3208      * <li>If the component is not {@code null}, but it is not
3209      * currently showing, the window is placed in the center of
3210      * the target screen defined by the {@code
3211      * GraphicsConfiguration} associated with this component.
3212      * <li>If the component is not {@code null} and is shown on
3213      * the screen, then the window is located in such a way that
3214      * the center of the window coincides with the center of the
3215      * component.
3216      * </ul>
3217      * <p>
3218      * If the screens configuration does not allow the window to
3219      * be moved from one screen to another, then the window is
3220      * only placed at the location determined according to the
3221      * above conditions and its {@code GraphicsConfiguration} is
3222      * not changed.
3223      * <p>
3224      * <b>Note</b>: If the lower edge of the window is out of the screen,
3225      * then the window is placed to the side of the {@code Component}
3226      * that is closest to the center of the screen. So if the
3227      * component is on the right part of the screen, the window
3228      * is placed to its left, and vice versa.
3229      * <p>
3230      * If after the window location has been calculated, the upper,
3231      * left, or right edge of the window is out of the screen,
3232      * then the window is located in such a way that the upper,
3233      * left, or right edge of the window coincides with the
3234      * corresponding edge of the screen. If both left and right
3235      * edges of the window are out of the screen, the window is
3236      * placed at the left side of the screen. The similar placement
3237      * will occur if both top and bottom edges are out of the screen.
3238      * In that case, the window is placed at the top side of the screen.
3239      * <p>
3240      * The method changes the geometry-related data. Therefore,
3241      * the native windowing system may ignore such requests, or it may modify
3242      * the requested data, so that the {@code Window} object is placed and sized
3243      * in a way that corresponds closely to the desktop settings.
3244      *
3245      * @param c  the component in relation to which the window's location
3246      *           is determined
3247      * @see java.awt.GraphicsEnvironment#getCenterPoint
3248      * @since 1.4
3249      */
3250     public void setLocationRelativeTo(Component c) {
3251         // target location
3252         int dx = 0, dy = 0;
3253         // target GC
3254         GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
3255         Rectangle gcBounds = gc.getBounds();
3256 
3257         Dimension windowSize = getSize();
3258 
3259         // search a top-level of c
3260         Window componentWindow = SunToolkit.getContainingWindow(c);
3261         if ((c == null) || (componentWindow == null)) {
3262             GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
3263             gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
3264             gcBounds = gc.getBounds();
3265             Point centerPoint = ge.getCenterPoint();
3266             dx = centerPoint.x - windowSize.width / 2;
3267             dy = centerPoint.y - windowSize.height / 2;
3268         } else if (!c.isShowing()) {
3269             gc = componentWindow.getGraphicsConfiguration();
3270             gcBounds = gc.getBounds();
3271             dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2;
3272             dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2;
3273         } else {
3274             gc = componentWindow.getGraphicsConfiguration();
3275             gcBounds = gc.getBounds();
3276             Dimension compSize = c.getSize();
3277             Point compLocation = c.getLocationOnScreen();
3278             dx = compLocation.x + ((compSize.width - windowSize.width) / 2);
3279             dy = compLocation.y + ((compSize.height - windowSize.height) / 2);
3280 
3281             // Adjust for bottom edge being offscreen
3282             if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3283                 dy = gcBounds.y + gcBounds.height - windowSize.height;
3284                 if (compLocation.x - gcBounds.x + compSize.width / 2 < gcBounds.width / 2) {
3285                     dx = compLocation.x + compSize.width;
3286                 } else {
3287                     dx = compLocation.x - windowSize.width;
3288                 }
3289             }
3290         }
3291 
3292         // Avoid being placed off the edge of the screen:
3293         // bottom
3294         if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3295             dy = gcBounds.y + gcBounds.height - windowSize.height;
3296         }
3297         // top
3298         if (dy < gcBounds.y) {
3299             dy = gcBounds.y;
3300         }
3301         // right
3302         if (dx + windowSize.width > gcBounds.x + gcBounds.width) {
3303             dx = gcBounds.x + gcBounds.width - windowSize.width;
3304         }
3305         // left
3306         if (dx < gcBounds.x) {
3307             dx = gcBounds.x;
3308         }
3309 
3310         setLocation(dx, dy);
3311     }
3312 
3313     /**
3314      * Overridden from Component.  Top-level Windows should not propagate a
3315      * MouseWheelEvent beyond themselves into their owning Windows.
3316      */
3317     void deliverMouseWheelToAncestor(MouseWheelEvent e) {}
3318 
3319     /**
3320      * Overridden from Component.  Top-level Windows don't dispatch to ancestors
3321      */
3322     boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {return false;}
3323 
3324     /**
3325      * Creates a new strategy for multi-buffering on this component.
3326      * Multi-buffering is useful for rendering performance.  This method
3327      * attempts to create the best strategy available with the number of
3328      * buffers supplied.  It will always create a {@code BufferStrategy}
3329      * with that number of buffers.
3330      * A page-flipping strategy is attempted first, then a blitting strategy
3331      * using accelerated buffers.  Finally, an unaccelerated blitting
3332      * strategy is used.
3333      * <p>
3334      * Each time this method is called,
3335      * the existing buffer strategy for this component is discarded.
3336      * @param numBuffers number of buffers to create
3337      * @exception IllegalArgumentException if numBuffers is less than 1.
3338      * @exception IllegalStateException if the component is not displayable
3339      * @see #isDisplayable
3340      * @see #getBufferStrategy
3341      * @since 1.4
3342      */
3343     public void createBufferStrategy(int numBuffers) {
3344         super.createBufferStrategy(numBuffers);
3345     }
3346 
3347     /**
3348      * Creates a new strategy for multi-buffering on this component with the
3349      * required buffer capabilities.  This is useful, for example, if only
3350      * accelerated memory or page flipping is desired (as specified by the
3351      * buffer capabilities).
3352      * <p>
3353      * Each time this method
3354      * is called, the existing buffer strategy for this component is discarded.
3355      * @param numBuffers number of buffers to create, including the front buffer
3356      * @param caps the required capabilities for creating the buffer strategy;
3357      * cannot be {@code null}
3358      * @exception AWTException if the capabilities supplied could not be
3359      * supported or met; this may happen, for example, if there is not enough
3360      * accelerated memory currently available, or if page flipping is specified
3361      * but not possible.
3362      * @exception IllegalArgumentException if numBuffers is less than 1, or if
3363      * caps is {@code null}
3364      * @see #getBufferStrategy
3365      * @since 1.4
3366      */
3367     public void createBufferStrategy(int numBuffers,
3368         BufferCapabilities caps) throws AWTException {
3369         super.createBufferStrategy(numBuffers, caps);
3370     }
3371 
3372     /**
3373      * Returns the {@code BufferStrategy} used by this component.  This
3374      * method will return null if a {@code BufferStrategy} has not yet
3375      * been created or has been disposed.
3376      *
3377      * @return the buffer strategy used by this component
3378      * @see #createBufferStrategy
3379      * @since 1.4
3380      */
3381     public BufferStrategy getBufferStrategy() {
3382         return super.getBufferStrategy();
3383     }
3384 
3385     Component getTemporaryLostComponent() {
3386         return temporaryLostComponent;
3387     }
3388     Component setTemporaryLostComponent(Component component) {
3389         Component previousComp = temporaryLostComponent;
3390         // Check that "component" is an acceptable focus owner and don't store it otherwise
3391         // - or later we will have problems with opposite while handling  WINDOW_GAINED_FOCUS
3392         if (component == null || component.canBeFocusOwner()) {
3393             temporaryLostComponent = component;
3394         } else {
3395             temporaryLostComponent = null;
3396         }
3397         return previousComp;
3398     }
3399 
3400     /**
3401      * Checks whether this window can contain focus owner.
3402      * Verifies that it is focusable and as container it can container focus owner.
3403      * @since 1.5
3404      */
3405     boolean canContainFocusOwner(Component focusOwnerCandidate) {
3406         return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow();
3407     }
3408 
3409     private boolean locationByPlatform = locationByPlatformProp;
3410 
3411 
3412     /**
3413      * Sets whether this Window should appear at the default location for the
3414      * native windowing system or at the current location (returned by
3415      * {@code getLocation}) the next time the Window is made visible.
3416      * This behavior resembles a native window shown without programmatically
3417      * setting its location.  Most windowing systems cascade windows if their
3418      * locations are not explicitly set. The actual location is determined once the
3419      * window is shown on the screen.
3420      * <p>
3421      * This behavior can also be enabled by setting the System Property
3422      * "java.awt.Window.locationByPlatform" to "true", though calls to this method
3423      * take precedence.
3424      * <p>
3425      * Calls to {@code setVisible}, {@code setLocation} and
3426      * {@code setBounds} after calling {@code setLocationByPlatform} clear
3427      * this property of the Window.
3428      * <p>
3429      * For example, after the following code is executed:
3430      * <pre>
3431      * setLocationByPlatform(true);
3432      * setVisible(true);
3433      * boolean flag = isLocationByPlatform();
3434      * </pre>
3435      * The window will be shown at platform's default location and
3436      * {@code flag} will be {@code false}.
3437      * <p>
3438      * In the following sample:
3439      * <pre>
3440      * setLocationByPlatform(true);
3441      * setLocation(10, 10);
3442      * boolean flag = isLocationByPlatform();
3443      * setVisible(true);
3444      * </pre>
3445      * The window will be shown at (10, 10) and {@code flag} will be
3446      * {@code false}.
3447      *
3448      * @param locationByPlatform {@code true} if this Window should appear
3449      *        at the default location, {@code false} if at the current location
3450      * @throws IllegalComponentStateException if the window
3451      *         is showing on screen and locationByPlatform is {@code true}.
3452      * @see #setLocation
3453      * @see #isShowing
3454      * @see #setVisible
3455      * @see #isLocationByPlatform
3456      * @see java.lang.System#getProperty(String)
3457      * @since 1.5
3458      */
3459     public void setLocationByPlatform(boolean locationByPlatform) {
3460         synchronized (getTreeLock()) {
3461             if (locationByPlatform && isShowing()) {
3462                 throw new IllegalComponentStateException("The window is showing on screen.");
3463             }
3464             this.locationByPlatform = locationByPlatform;
3465         }
3466     }
3467 
3468     /**
3469      * Returns {@code true} if this Window will appear at the default location
3470      * for the native windowing system the next time this Window is made visible.
3471      * This method always returns {@code false} if the Window is showing on the
3472      * screen.
3473      *
3474      * @return whether this Window will appear at the default location
3475      * @see #setLocationByPlatform
3476      * @see #isShowing
3477      * @since 1.5
3478      */
3479     public boolean isLocationByPlatform() {
3480         synchronized (getTreeLock()) {
3481             return locationByPlatform;
3482         }
3483     }
3484 
3485     /**
3486      * {@inheritDoc}
3487      * <p>
3488      * The {@code width} or {@code height} values
3489      * are automatically enlarged if either is less than
3490      * the minimum size as specified by previous call to
3491      * {@code setMinimumSize}.
3492      * <p>
3493      * The method changes the geometry-related data. Therefore,
3494      * the native windowing system may ignore such requests, or it may modify
3495      * the requested data, so that the {@code Window} object is placed and sized
3496      * in a way that corresponds closely to the desktop settings.
3497      *
3498      * @see #getBounds
3499      * @see #setLocation(int, int)
3500      * @see #setLocation(Point)
3501      * @see #setSize(int, int)
3502      * @see #setSize(Dimension)
3503      * @see #setMinimumSize
3504      * @see #setLocationByPlatform
3505      * @see #isLocationByPlatform
3506      * @since 1.6
3507      */
3508     public void setBounds(int x, int y, int width, int height) {
3509         synchronized (getTreeLock()) {
3510             if (getBoundsOp() == ComponentPeer.SET_LOCATION ||
3511                 getBoundsOp() == ComponentPeer.SET_BOUNDS)
3512             {
3513                 locationByPlatform = false;
3514             }
3515             super.setBounds(x, y, width, height);
3516         }
3517     }
3518 
3519     /**
3520      * {@inheritDoc}
3521      * <p>
3522      * The {@code r.width} or {@code r.height} values
3523      * will be automatically enlarged if either is less than
3524      * the minimum size as specified by previous call to
3525      * {@code setMinimumSize}.
3526      * <p>
3527      * The method changes the geometry-related data. Therefore,
3528      * the native windowing system may ignore such requests, or it may modify
3529      * the requested data, so that the {@code Window} object is placed and sized
3530      * in a way that corresponds closely to the desktop settings.
3531      *
3532      * @see #getBounds
3533      * @see #setLocation(int, int)
3534      * @see #setLocation(Point)
3535      * @see #setSize(int, int)
3536      * @see #setSize(Dimension)
3537      * @see #setMinimumSize
3538      * @see #setLocationByPlatform
3539      * @see #isLocationByPlatform
3540      * @since 1.6
3541      */
3542     public void setBounds(Rectangle r) {
3543         setBounds(r.x, r.y, r.width, r.height);
3544     }
3545 
3546     /**
3547      * Determines whether this component will be displayed on the screen.
3548      * @return {@code true} if the component and all of its ancestors
3549      *          until a toplevel window are visible, {@code false} otherwise
3550      */
3551     boolean isRecursivelyVisible() {
3552         // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
3553         // We're overriding isRecursivelyVisible to implement this policy.
3554         return visible;
3555     }
3556 
3557 
3558     // ******************** SHAPES & TRANSPARENCY CODE ********************
3559 
3560     /**
3561      * Returns the opacity of the window.
3562      *
3563      * @return the opacity of the window
3564      *
3565      * @see Window#setOpacity(float)
3566      * @see GraphicsDevice.WindowTranslucency
3567      *
3568      * @since 1.7
3569      */
3570     public float getOpacity() {
3571         synchronized (getTreeLock()) {
3572             return opacity;
3573         }
3574     }
3575 
3576     /**
3577      * Sets the opacity of the window.
3578      * <p>
3579      * The opacity value is in the range [0..1]. Note that setting the opacity
3580      * level of 0 may or may not disable the mouse event handling on this
3581      * window. This is a platform-dependent behavior.
3582      * <p>
3583      * The following conditions must be met in order to set the opacity value
3584      * less than {@code 1.0f}:
3585      * <ul>
3586      * <li>The {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3587      * translucency must be supported by the underlying system
3588      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3589      * and {@link Dialog#setUndecorated})
3590      * <li>The window must not be in full-screen mode (see {@link
3591      * GraphicsDevice#setFullScreenWindow(Window)})
3592      * </ul>
3593      * <p>
3594      * If the requested opacity value is less than {@code 1.0f}, and any of the
3595      * above conditions are not met, the window opacity will not change,
3596      * and the {@code IllegalComponentStateException} will be thrown.
3597      * <p>
3598      * The translucency levels of individual pixels may also be effected by the
3599      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3600      * current shape of this window (see {@link #setShape(Shape)}).
3601      *
3602      * @param opacity the opacity level to set to the window
3603      *
3604      * @throws IllegalArgumentException if the opacity is out of the range
3605      *     [0..1]
3606      * @throws IllegalComponentStateException if the window is decorated and
3607      *     the opacity is less than {@code 1.0f}
3608      * @throws IllegalComponentStateException if the window is in full screen
3609      *     mode, and the opacity is less than {@code 1.0f}
3610      * @throws UnsupportedOperationException if the {@code
3611      *     GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3612      *     translucency is not supported and the opacity is less than
3613      *     {@code 1.0f}
3614      *
3615      * @see Window#getOpacity
3616      * @see Window#setBackground(Color)
3617      * @see Window#setShape(Shape)
3618      * @see Frame#isUndecorated
3619      * @see Dialog#isUndecorated
3620      * @see GraphicsDevice.WindowTranslucency
3621      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3622      *
3623      * @since 1.7
3624      */
3625     @SuppressWarnings("deprecation")
3626     public void setOpacity(float opacity) {
3627         synchronized (getTreeLock()) {
3628             if (opacity < 0.0f || opacity > 1.0f) {
3629                 throw new IllegalArgumentException(
3630                     "The value of opacity should be in the range [0.0f .. 1.0f].");
3631             }
3632             if (opacity < 1.0f) {
3633                 GraphicsConfiguration gc = getGraphicsConfiguration();
3634                 GraphicsDevice gd = gc.getDevice();
3635                 if (gc.getDevice().getFullScreenWindow() == this) {
3636                     throw new IllegalComponentStateException(
3637                         "Setting opacity for full-screen window is not supported.");
3638                 }
3639                 if (!gd.isWindowTranslucencySupported(
3640                     GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3641                 {
3642                     throw new UnsupportedOperationException(
3643                         "TRANSLUCENT translucency is not supported.");
3644                 }
3645             }
3646             this.opacity = opacity;
3647             WindowPeer peer = (WindowPeer) this.peer;
3648             if (peer != null) {
3649                 peer.setOpacity(opacity);
3650             }
3651         }
3652     }
3653 
3654     /**
3655      * Returns the shape of the window.
3656      *
3657      * The value returned by this method may not be the same as
3658      * previously set with {@code setShape(shape)}, but it is guaranteed
3659      * to represent the same shape.
3660      *
3661      * @return the shape of the window or {@code null} if no
3662      *     shape is specified for the window
3663      *
3664      * @see Window#setShape(Shape)
3665      * @see GraphicsDevice.WindowTranslucency
3666      *
3667      * @since 1.7
3668      */
3669     public Shape getShape() {
3670         synchronized (getTreeLock()) {
3671             return shape == null ? null : new Path2D.Float(shape);
3672         }
3673     }
3674 
3675     /**
3676      * Sets the shape of the window.
3677      * <p>
3678      * Setting a shape cuts off some parts of the window. Only the parts that
3679      * belong to the given {@link Shape} remain visible and clickable. If
3680      * the shape argument is {@code null}, this method restores the default
3681      * shape, making the window rectangular on most platforms.
3682      * <p>
3683      * The following conditions must be met to set a non-null shape:
3684      * <ul>
3685      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3686      * PERPIXEL_TRANSPARENT} translucency must be supported by the
3687      * underlying system
3688      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3689      * and {@link Dialog#setUndecorated})
3690      * <li>The window must not be in full-screen mode (see {@link
3691      * GraphicsDevice#setFullScreenWindow(Window)})
3692      * </ul>
3693      * <p>
3694      * If the requested shape is not {@code null}, and any of the above
3695      * conditions are not met, the shape of this window will not change,
3696      * and either the {@code UnsupportedOperationException} or {@code
3697      * IllegalComponentStateException} will be thrown.
3698      * <p>
3699      * The translucency levels of individual pixels may also be effected by the
3700      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3701      * opacity value (see {@link #setOpacity(float)}). See {@link
3702      * GraphicsDevice.WindowTranslucency} for more details.
3703      *
3704      * @param shape the shape to set to the window
3705      *
3706      * @throws IllegalComponentStateException if the shape is not {@code
3707      *     null} and the window is decorated
3708      * @throws IllegalComponentStateException if the shape is not {@code
3709      *     null} and the window is in full-screen mode
3710      * @throws UnsupportedOperationException if the shape is not {@code
3711      *     null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3712      *     PERPIXEL_TRANSPARENT} translucency is not supported
3713      *
3714      * @see Window#getShape()
3715      * @see Window#setBackground(Color)
3716      * @see Window#setOpacity(float)
3717      * @see Frame#isUndecorated
3718      * @see Dialog#isUndecorated
3719      * @see GraphicsDevice.WindowTranslucency
3720      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3721      *
3722      * @since 1.7
3723      */
3724     public void setShape(Shape shape) {
3725         synchronized (getTreeLock()) {
3726             if (shape != null) {
3727                 GraphicsConfiguration gc = getGraphicsConfiguration();
3728                 GraphicsDevice gd = gc.getDevice();
3729                 if (gc.getDevice().getFullScreenWindow() == this) {
3730                     throw new IllegalComponentStateException(
3731                         "Setting shape for full-screen window is not supported.");
3732                 }
3733                 if (!gd.isWindowTranslucencySupported(
3734                         GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3735                 {
3736                     throw new UnsupportedOperationException(
3737                         "PERPIXEL_TRANSPARENT translucency is not supported.");
3738                 }
3739             }
3740             this.shape = (shape == null) ? null : new Path2D.Float(shape);
3741             WindowPeer peer = (WindowPeer) this.peer;
3742             if (peer != null) {
3743                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3744             }
3745         }
3746     }
3747 
3748     /**
3749      * Gets the background color of this window.
3750      * <p>
3751      * Note that the alpha component of the returned color indicates whether
3752      * the window is in the non-opaque (per-pixel translucent) mode.
3753      *
3754      * @return this component's background color
3755      *
3756      * @see Window#setBackground(Color)
3757      * @see Window#isOpaque
3758      * @see GraphicsDevice.WindowTranslucency
3759      */
3760     @Override
3761     public Color getBackground() {
3762         return super.getBackground();
3763     }
3764 
3765     /**
3766      * Sets the background color of this window.
3767      * <p>
3768      * If the windowing system supports the {@link
3769      * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
3770      * translucency, the alpha component of the given background color
3771      * may effect the mode of operation for this window: it indicates whether
3772      * this window must be opaque (alpha equals {@code 1.0f}) or per-pixel translucent
3773      * (alpha is less than {@code 1.0f}). If the given background color is
3774      * {@code null}, the window is considered completely opaque.
3775      * <p>
3776      * All the following conditions must be met to enable the per-pixel
3777      * transparency mode for this window:
3778      * <ul>
3779      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3780      * PERPIXEL_TRANSLUCENT} translucency must be supported by the graphics
3781      * device where this window is located
3782      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3783      * and {@link Dialog#setUndecorated})
3784      * <li>The window must not be in full-screen mode (see {@link
3785      * GraphicsDevice#setFullScreenWindow(Window)})
3786      * </ul>
3787      * <p>
3788      * If the alpha component of the requested background color is less than
3789      * {@code 1.0f}, and any of the above conditions are not met, the background
3790      * color of this window will not change, the alpha component of the given
3791      * background color will not affect the mode of operation for this window,
3792      * and either the {@code UnsupportedOperationException} or {@code
3793      * IllegalComponentStateException} will be thrown.
3794      * <p>
3795      * When the window is per-pixel translucent, the drawing sub-system
3796      * respects the alpha value of each individual pixel. If a pixel gets
3797      * painted with the alpha color component equal to zero, it becomes
3798      * visually transparent. If the alpha of the pixel is equal to 1.0f, the
3799      * pixel is fully opaque. Interim values of the alpha color component make
3800      * the pixel semi-transparent. In this mode, the background of the window
3801      * gets painted with the alpha value of the given background color. If the
3802      * alpha value of the argument of this method is equal to {@code 0}, the
3803      * background is not painted at all.
3804      * <p>
3805      * The actual level of translucency of a given pixel also depends on window
3806      * opacity (see {@link #setOpacity(float)}), as well as the current shape of
3807      * this window (see {@link #setShape(Shape)}).
3808      * <p>
3809      * Note that painting a pixel with the alpha value of {@code 0} may or may
3810      * not disable the mouse event handling on this pixel. This is a
3811      * platform-dependent behavior. To make sure the mouse events do not get
3812      * dispatched to a particular pixel, the pixel must be excluded from the
3813      * shape of the window.
3814      * <p>
3815      * Enabling the per-pixel translucency mode may change the graphics
3816      * configuration of this window due to the native platform requirements.
3817      *
3818      * @param bgColor the color to become this window's background color.
3819      *
3820      * @throws IllegalComponentStateException if the alpha value of the given
3821      *     background color is less than {@code 1.0f} and the window is decorated
3822      * @throws IllegalComponentStateException if the alpha value of the given
3823      *     background color is less than {@code 1.0f} and the window is in
3824      *     full-screen mode
3825      * @throws UnsupportedOperationException if the alpha value of the given
3826      *     background color is less than {@code 1.0f} and {@link
3827      *     GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3828      *     PERPIXEL_TRANSLUCENT} translucency is not supported
3829      *
3830      * @see Window#getBackground
3831      * @see Window#isOpaque
3832      * @see Window#setOpacity(float)
3833      * @see Window#setShape(Shape)
3834      * @see Frame#isUndecorated
3835      * @see Dialog#isUndecorated
3836      * @see GraphicsDevice.WindowTranslucency
3837      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3838      * @see GraphicsConfiguration#isTranslucencyCapable()
3839      */
3840     @Override
3841     public void setBackground(Color bgColor) {
3842         Color oldBg = getBackground();
3843         super.setBackground(bgColor);
3844         if (oldBg != null && oldBg.equals(bgColor)) {
3845             return;
3846         }
3847         int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3848         int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3849         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3850             GraphicsConfiguration gc = getGraphicsConfiguration();
3851             GraphicsDevice gd = gc.getDevice();
3852             if (gc.getDevice().getFullScreenWindow() == this) {
3853                 throw new IllegalComponentStateException(
3854                     "Making full-screen window non opaque is not supported.");
3855             }
3856             if (!gc.isTranslucencyCapable()) {
3857                 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3858                 if (capableGC == null) {
3859                     throw new UnsupportedOperationException(
3860                         "PERPIXEL_TRANSLUCENT translucency is not supported");
3861                 }
3862                 setGraphicsConfiguration(capableGC);
3863             }
3864             setLayersOpaque(this, false);
3865         } else if ((oldAlpha < 255) && (alpha == 255)) {
3866             setLayersOpaque(this, true);
3867         }
3868         WindowPeer peer = (WindowPeer) this.peer;
3869         if (peer != null) {
3870             peer.setOpaque(alpha == 255);
3871         }
3872     }
3873 
3874     /**
3875      * Indicates if the window is currently opaque.
3876      * <p>
3877      * The method returns {@code false} if the background color of the window
3878      * is not {@code null} and the alpha component of the color is less than
3879      * {@code 1.0f}. The method returns {@code true} otherwise.
3880      *
3881      * @return {@code true} if the window is opaque, {@code false} otherwise
3882      *
3883      * @see Window#getBackground
3884      * @see Window#setBackground(Color)
3885      * @since 1.7
3886      */
3887     @Override
3888     public boolean isOpaque() {
3889         Color bg = getBackground();
3890         return bg != null ? bg.getAlpha() == 255 : true;
3891     }
3892 
3893     private void updateWindow() {
3894         synchronized (getTreeLock()) {
3895             WindowPeer peer = (WindowPeer) this.peer;
3896             if (peer != null) {
3897                 peer.updateWindow();
3898             }
3899         }
3900     }
3901 
3902     /**
3903      * {@inheritDoc}
3904      *
3905      * @since 1.7
3906      */
3907     @Override
3908     public void paint(Graphics g) {
3909         if (!isOpaque()) {
3910             Graphics gg = g.create();
3911             try {
3912                 if (gg instanceof Graphics2D) {
3913                     gg.setColor(getBackground());
3914                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
3915                     gg.fillRect(0, 0, getWidth(), getHeight());
3916                 }
3917             } finally {
3918                 gg.dispose();
3919             }
3920         }
3921         super.paint(g);
3922     }
3923 
3924     private static void setLayersOpaque(Component component, boolean isOpaque) {
3925         // Shouldn't use instanceof to avoid loading Swing classes
3926         //    if it's a pure AWT application.
3927         if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
3928             javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
3929             javax.swing.JRootPane root = rpc.getRootPane();
3930             javax.swing.JLayeredPane lp = root.getLayeredPane();
3931             Container c = root.getContentPane();
3932             javax.swing.JComponent content =
3933                 (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
3934             lp.setOpaque(isOpaque);
3935             root.setOpaque(isOpaque);
3936             if (content != null) {
3937                 content.setOpaque(isOpaque);
3938 
3939                 // Iterate down one level to see whether we have a JApplet
3940                 // (which is also a RootPaneContainer) which requires processing
3941                 int numChildren = content.getComponentCount();
3942                 if (numChildren > 0) {
3943                     Component child = content.getComponent(0);
3944                     // It's OK to use instanceof here because we've
3945                     // already loaded the RootPaneContainer class by now
3946                     if (child instanceof javax.swing.RootPaneContainer) {
3947                         setLayersOpaque(child, isOpaque);
3948                     }
3949                 }
3950             }
3951         }
3952     }
3953 
3954 
3955     // ************************** MIXING CODE *******************************
3956 
3957     // A window has an owner, but it does NOT have a container
3958     @Override
3959     final Container getContainer() {
3960         return null;
3961     }
3962 
3963     /**
3964      * Applies the shape to the component
3965      * @param shape Shape to be applied to the component
3966      */
3967     @Override
3968     final void applyCompoundShape(Region shape) {
3969         // The shape calculated by mixing code is not intended to be applied
3970         // to windows or frames
3971     }
3972 
3973     @Override
3974     final void applyCurrentShape() {
3975         // The shape calculated by mixing code is not intended to be applied
3976         // to windows or frames
3977     }
3978 
3979     @Override
3980     final void mixOnReshaping() {
3981         // The shape calculated by mixing code is not intended to be applied
3982         // to windows or frames
3983     }
3984 
3985     @Override
3986     final Point getLocationOnWindow() {
3987         return new Point(0, 0);
3988     }
3989 
3990     // ****************** END OF MIXING CODE ********************************
3991 
3992     /**
3993      * Limit the given double value with the given range.
3994      */
3995     private static double limit(double value, double min, double max) {
3996         value = Math.max(value, min);
3997         value = Math.min(value, max);
3998         return value;
3999     }
4000 
4001     /**
4002      * Calculate the position of the security warning.
4003      *
4004      * This method gets the window location/size as reported by the native
4005      * system since the locally cached values may represent outdated data.
4006      *
4007      * The method is used from the native code, or via AWTAccessor.
4008      *
4009      * NOTE: this method is invoked on the toolkit thread, and therefore is not
4010      * supposed to become public/user-overridable.
4011      */
4012     private Point2D calculateSecurityWarningPosition(double x, double y,
4013             double w, double h)
4014     {
4015         // The position according to the spec of SecurityWarning.setPosition()
4016         double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
4017         double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
4018 
4019         // First, make sure the warning is not too far from the window bounds
4020         wx = Window.limit(wx,
4021                 x - securityWarningWidth - 2,
4022                 x + w + 2);
4023         wy = Window.limit(wy,
4024                 y - securityWarningHeight - 2,
4025                 y + h + 2);
4026 
4027         // Now make sure the warning window is visible on the screen
4028         GraphicsConfiguration graphicsConfig =
4029             getGraphicsConfiguration_NoClientCode();
4030         Rectangle screenBounds = graphicsConfig.getBounds();
4031         Insets screenInsets =
4032             Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
4033 
4034         wx = Window.limit(wx,
4035                 screenBounds.x + screenInsets.left,
4036                 screenBounds.x + screenBounds.width - screenInsets.right
4037                 - securityWarningWidth);
4038         wy = Window.limit(wy,
4039                 screenBounds.y + screenInsets.top,
4040                 screenBounds.y + screenBounds.height - screenInsets.bottom
4041                 - securityWarningHeight);
4042 
4043         return new Point2D.Double(wx, wy);
4044     }
4045 
4046     static {
4047         AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() {
4048             public float getOpacity(Window window) {
4049                 return window.opacity;
4050             }
4051             public void setOpacity(Window window, float opacity) {
4052                 window.setOpacity(opacity);
4053             }
4054             public Shape getShape(Window window) {
4055                 return window.getShape();
4056             }
4057             public void setShape(Window window, Shape shape) {
4058                 window.setShape(shape);
4059             }
4060             public void setOpaque(Window window, boolean opaque) {
4061                 Color bg = window.getBackground();
4062                 if (bg == null) {
4063                     bg = new Color(0, 0, 0, 0);
4064                 }
4065                 window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(),
4066                                                opaque ? 255 : 0));
4067             }
4068             public void updateWindow(Window window) {
4069                 window.updateWindow();
4070             }
4071 
4072             public Dimension getSecurityWarningSize(Window window) {
4073                 return new Dimension(window.securityWarningWidth,
4074                         window.securityWarningHeight);
4075             }
4076 
4077             public void setSecurityWarningSize(Window window, int width, int height)
4078             {
4079                 window.securityWarningWidth = width;
4080                 window.securityWarningHeight = height;
4081             }
4082 
4083             public void setSecurityWarningPosition(Window window,
4084                     Point2D point, float alignmentX, float alignmentY)
4085             {
4086                 window.securityWarningPointX = point.getX();
4087                 window.securityWarningPointY = point.getY();
4088                 window.securityWarningAlignmentX = alignmentX;
4089                 window.securityWarningAlignmentY = alignmentY;
4090 
4091                 synchronized (window.getTreeLock()) {
4092                     WindowPeer peer = (WindowPeer) window.peer;
4093                     if (peer != null) {
4094                         peer.repositionSecurityWarning();
4095                     }
4096                 }
4097             }
4098 
4099             public Point2D calculateSecurityWarningPosition(Window window,
4100                     double x, double y, double w, double h)
4101             {
4102                 return window.calculateSecurityWarningPosition(x, y, w, h);
4103             }
4104 
4105             public void setLWRequestStatus(Window changed, boolean status) {
4106                 changed.syncLWRequests = status;
4107             }
4108 
4109             public boolean isAutoRequestFocus(Window w) {
4110                 return w.autoRequestFocus;
4111             }
4112 
4113             public boolean isTrayIconWindow(Window w) {
4114                 return w.isTrayIconWindow;
4115             }
4116 
4117             public void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
4118                 w.isTrayIconWindow = isTrayIconWindow;
4119             }
4120         }); // WindowAccessor
4121     } // static
4122 
4123     // a window doesn't need to be updated in the Z-order.
4124     @Override
4125     void updateZOrder() {}
4126 
4127 } // class Window
4128 
4129 
4130 /**
4131  * This class is no longer used, but is maintained for Serialization
4132  * backward-compatibility.
4133  */
4134 class FocusManager implements java.io.Serializable {
4135     Container focusRoot;
4136     Component focusOwner;
4137 
4138     /*
4139      * JDK 1.1 serialVersionUID
4140      */
4141     static final long serialVersionUID = 2491878825643557906L;
4142 }