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.DebugSettings;
  56 import sun.awt.SunToolkit;
  57 import sun.awt.util.IdentityArrayList;
  58 import sun.java2d.pipe.Region;
  59 import sun.security.action.GetPropertyAction;
  60 import sun.util.logging.PlatformLogger;
  61 
  62 /**
  63  * A {@code Window} object is a top-level window with no borders and no
  64  * menubar.
  65  * The default layout for a window is {@code BorderLayout}.
  66  * <p>
  67  * A window must have either a frame, dialog, or another window defined as its
  68  * owner when it's constructed.
  69  * <p>
  70  * In a multi-screen environment, you can create a {@code Window}
  71  * on a different screen device by constructing the {@code Window}
  72  * with {@link #Window(Window, GraphicsConfiguration)}.  The
  73  * {@code GraphicsConfiguration} object is one of the
  74  * {@code GraphicsConfiguration} objects of the target screen device.
  75  * <p>
  76  * In a virtual device multi-screen environment in which the desktop
  77  * area could span multiple physical screen devices, the bounds of all
  78  * configurations are relative to the virtual device coordinate system.
  79  * The origin of the virtual-coordinate system is at the upper left-hand
  80  * corner of the primary physical screen.  Depending on the location of
  81  * the primary screen in the virtual device, negative coordinates are
  82  * possible, as shown in the following figure.
  83  * <p>
  84  * <img src="doc-files/MultiScreen.gif"
  85  * alt="Diagram shows virtual device containing 4 physical screens. Primary physical screen shows coords (0,0), other screen shows (-80,-100)."
  86  * style="float:center; margin: 7px 10px;">
  87  * <p>
  88  * In such an environment, when calling {@code setLocation},
  89  * you must pass a virtual coordinate to this method.  Similarly,
  90  * calling {@code getLocationOnScreen} on a {@code Window} returns
  91  * virtual device coordinates.  Call the {@code getBounds} method
  92  * of a {@code GraphicsConfiguration} to find its origin in the virtual
  93  * coordinate system.
  94  * <p>
  95  * The following code sets the location of a {@code Window}
  96  * at (10, 10) relative to the origin of the physical screen
  97  * of the corresponding {@code GraphicsConfiguration}.  If the
  98  * bounds of the {@code GraphicsConfiguration} is not taken
  99  * into account, the {@code Window} location would be set
 100  * at (10, 10) relative to the virtual-coordinate system and would appear
 101  * on the primary physical screen, which might be different from the
 102  * physical screen of the specified {@code GraphicsConfiguration}.
 103  *
 104  * <pre>
 105  *      Window w = new Window(Window owner, GraphicsConfiguration gc);
 106  *      Rectangle bounds = gc.getBounds();
 107  *      w.setLocation(10 + bounds.x, 10 + bounds.y);
 108  * </pre>
 109  *
 110  * <p>
 111  * Note: the location and size of top-level windows (including
 112  * {@code Window}s, {@code Frame}s, and {@code Dialog}s)
 113  * are under the control of the desktop's window management system.
 114  * Calls to {@code setLocation}, {@code setSize}, and
 115  * {@code setBounds} are requests (not directives) which are
 116  * forwarded to the window management system.  Every effort will be
 117  * made to honor such requests.  However, in some cases the window
 118  * management system may ignore such requests, or modify the requested
 119  * geometry in order to place and size the {@code Window} in a way
 120  * that more closely matches the desktop settings.
 121  * <p>
 122  * Due to the asynchronous nature of native event handling, the results
 123  * returned by {@code getBounds}, {@code getLocation},
 124  * {@code getLocationOnScreen}, and {@code getSize} might not
 125  * reflect the actual geometry of the Window on screen until the last
 126  * request has been processed.  During the processing of subsequent
 127  * requests these values might change accordingly while the window
 128  * management system fulfills the requests.
 129  * <p>
 130  * An application may set the size and location of an invisible
 131  * {@code Window} arbitrarily, but the window management system may
 132  * subsequently change its size and/or location when the
 133  * {@code Window} is made visible. One or more {@code ComponentEvent}s
 134  * will be generated to indicate the new geometry.
 135  * <p>
 136  * Windows are capable of generating the following WindowEvents:
 137  * WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus.
 138  *
 139  * @author      Sami Shaio
 140  * @author      Arthur van Hoff
 141  * @see WindowEvent
 142  * @see #addWindowListener
 143  * @see java.awt.BorderLayout
 144  * @since       1.0
 145  */
 146 public class Window extends Container implements Accessible {
 147 
 148     /**
 149      * Enumeration of available <i>window types</i>.
 150      *
 151      * A window type defines the generic visual appearance and behavior of a
 152      * top-level window. For example, the type may affect the kind of
 153      * decorations of a decorated {@code Frame} or {@code Dialog} instance.
 154      * <p>
 155      * Some platforms may not fully support a certain window type. Depending on
 156      * the level of support, some properties of the window type may be
 157      * disobeyed.
 158      *
 159      * @see   #getType
 160      * @see   #setType
 161      * @since 1.7
 162      */
 163     public static enum Type {
 164         /**
 165          * Represents a <i>normal</i> window.
 166          *
 167          * This is the default type for objects of the {@code Window} class or
 168          * its descendants. Use this type for regular top-level windows.
 169          */
 170         NORMAL,
 171 
 172         /**
 173          * Represents a <i>utility</i> window.
 174          *
 175          * A utility window is usually a small window such as a toolbar or a
 176          * palette. The native system may render the window with smaller
 177          * title-bar if the window is either a {@code Frame} or a {@code
 178          * Dialog} object, and if it has its decorations enabled.
 179          */
 180         UTILITY,
 181 
 182         /**
 183          * Represents a <i>popup</i> window.
 184          *
 185          * A popup window is a temporary window such as a drop-down menu or a
 186          * tooltip. On some platforms, windows of that type may be forcibly
 187          * made undecorated even if they are instances of the {@code Frame} or
 188          * {@code Dialog} class, and have decorations enabled.
 189          */
 190         POPUP
 191     }
 192 
 193     /**
 194      * This represents the warning message that is
 195      * to be displayed in a non secure window. ie :
 196      * a window that has a security manager installed that denies
 197      * {@code AWTPermission("showWindowWithoutWarningBanner")}.
 198      * This message can be displayed anywhere in the window.
 199      *
 200      * @serial
 201      * @see #getWarningString
 202      */
 203     String      warningString;
 204 
 205     /**
 206      * {@code icons} is the graphical way we can
 207      * represent the frames and dialogs.
 208      * {@code Window} can't display icon but it's
 209      * being inherited by owned {@code Dialog}s.
 210      *
 211      * @serial
 212      * @see #getIconImages
 213      * @see #setIconImages
 214      */
 215     transient java.util.List<Image> icons;
 216 
 217     /**
 218      * Holds the reference to the component which last had focus in this window
 219      * before it lost focus.
 220      */
 221     private transient Component temporaryLostComponent;
 222 
 223     static boolean systemSyncLWRequests = false;
 224     volatile 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 if debug is enabled.
2163         if (DebugSettings.getInstance().getBoolean("on", false)) {
2164             if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_F1 &&
2165                     e.isControlDown() && e.isShiftDown() &&
2166                     e.getID() == KeyEvent.KEY_PRESSED) {
2167                 list(System.out, 0);
2168             }
2169         }
2170     }
2171 
2172     void postProcessKeyEvent(KeyEvent e) {
2173         // Do nothing
2174     }
2175 
2176 
2177     /**
2178      * Sets whether this window should always be above other windows.  If
2179      * there are multiple always-on-top windows, their relative order is
2180      * unspecified and platform dependent.
2181      * <p>
2182      * If some other window is already always-on-top then the
2183      * relative order between these windows is unspecified (depends on
2184      * platform).  No window can be brought to be over the always-on-top
2185      * window except maybe another always-on-top window.
2186      * <p>
2187      * All windows owned by an always-on-top window inherit this state and
2188      * automatically become always-on-top.  If a window ceases to be
2189      * always-on-top, the windows that it owns will no longer be
2190      * always-on-top.  When an always-on-top window is sent {@link #toBack
2191      * toBack}, its always-on-top state is set to {@code false}.
2192      *
2193      * <p> When this method is called on a window with a value of
2194      * {@code true}, and the window is visible and the platform
2195      * supports always-on-top for this window, the window is immediately
2196      * brought forward, "sticking" it in the top-most position. If the
2197      * window isn`t currently visible, this method sets the always-on-top
2198      * state to {@code true} but does not bring the window forward.
2199      * When the window is later shown, it will be always-on-top.
2200      *
2201      * <p> When this method is called on a window with a value of
2202      * {@code false} the always-on-top state is set to normal. It may also
2203      * cause an unspecified, platform-dependent change in the z-order of
2204      * top-level windows, but other always-on-top windows will remain in
2205      * top-most position. Calling this method with a value of {@code false}
2206      * on a window that has a normal state has no effect.
2207      *
2208      * <p><b>Note</b>: some platforms might not support always-on-top
2209      * windows.  To detect if always-on-top windows are supported by the
2210      * current platform, use {@link Toolkit#isAlwaysOnTopSupported()} and
2211      * {@link Window#isAlwaysOnTopSupported()}.  If always-on-top mode
2212      * isn't supported for this window or this window's toolkit does not
2213      * support always-on-top windows, calling this method has no effect.
2214      * <p>
2215      * If a SecurityManager is installed, the calling thread must be
2216      * granted the AWTPermission "setWindowAlwaysOnTop" in
2217      * order to set the value of this property. If this
2218      * permission is not granted, this method will throw a
2219      * SecurityException, and the current value of the property will
2220      * be left unchanged.
2221      *
2222      * @param alwaysOnTop true if the window should always be above other
2223      *        windows
2224      * @throws SecurityException if the calling thread does not have
2225      *         permission to set the value of always-on-top property
2226      *
2227      * @see #isAlwaysOnTop
2228      * @see #toFront
2229      * @see #toBack
2230      * @see AWTPermission
2231      * @see #isAlwaysOnTopSupported
2232      * @see #getToolkit
2233      * @see Toolkit#isAlwaysOnTopSupported
2234      * @since 1.5
2235      */
2236     public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
2237         SecurityManager security = System.getSecurityManager();
2238         if (security != null) {
2239             security.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
2240         }
2241 
2242         boolean oldAlwaysOnTop;
2243         synchronized(this) {
2244             oldAlwaysOnTop = this.alwaysOnTop;
2245             this.alwaysOnTop = alwaysOnTop;
2246         }
2247         if (oldAlwaysOnTop != alwaysOnTop ) {
2248             if (isAlwaysOnTopSupported()) {
2249                 WindowPeer peer = (WindowPeer)this.peer;
2250                 synchronized(getTreeLock()) {
2251                     if (peer != null) {
2252                         peer.updateAlwaysOnTopState();
2253                     }
2254                 }
2255             }
2256             firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop);
2257         }
2258         setOwnedWindowsAlwaysOnTop(alwaysOnTop);
2259     }
2260 
2261     @SuppressWarnings({"rawtypes", "unchecked"})
2262     private void setOwnedWindowsAlwaysOnTop(boolean alwaysOnTop) {
2263         WeakReference<Window>[] ownedWindowArray;
2264         synchronized (ownedWindowList) {
2265             ownedWindowArray = new WeakReference[ownedWindowList.size()];
2266             ownedWindowList.copyInto(ownedWindowArray);
2267         }
2268 
2269         for (WeakReference<Window> ref : ownedWindowArray) {
2270             Window window = ref.get();
2271             if (window != null) {
2272                 try {
2273                     window.setAlwaysOnTop(alwaysOnTop);
2274                 } catch (SecurityException ignore) {
2275                 }
2276             }
2277         }
2278     }
2279 
2280     /**
2281      * Returns whether the always-on-top mode is supported for this
2282      * window. Some platforms may not support always-on-top windows, some
2283      * may support only some kinds of top-level windows; for example,
2284      * a platform may not support always-on-top modal dialogs.
2285      *
2286      * @return {@code true}, if the always-on-top mode is supported for
2287      *         this window and this window's toolkit supports always-on-top windows,
2288      *         {@code false} otherwise
2289      *
2290      * @see #setAlwaysOnTop(boolean)
2291      * @see #getToolkit
2292      * @see Toolkit#isAlwaysOnTopSupported
2293      * @since 1.6
2294      */
2295     public boolean isAlwaysOnTopSupported() {
2296         return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
2297     }
2298 
2299 
2300     /**
2301      * Returns whether this window is an always-on-top window.
2302      * @return {@code true}, if the window is in always-on-top state,
2303      *         {@code false} otherwise
2304      * @see #setAlwaysOnTop
2305      * @since 1.5
2306      */
2307     public final boolean isAlwaysOnTop() {
2308         return alwaysOnTop;
2309     }
2310 
2311 
2312     /**
2313      * Returns the child Component of this Window that has focus if this Window
2314      * is focused; returns null otherwise.
2315      *
2316      * @return the child Component with focus, or null if this Window is not
2317      *         focused
2318      * @see #getMostRecentFocusOwner
2319      * @see #isFocused
2320      */
2321     public Component getFocusOwner() {
2322         return (isFocused())
2323             ? KeyboardFocusManager.getCurrentKeyboardFocusManager().
2324                   getFocusOwner()
2325             : null;
2326     }
2327 
2328     /**
2329      * Returns the child Component of this Window that will receive the focus
2330      * when this Window is focused. If this Window is currently focused, this
2331      * method returns the same Component as {@code getFocusOwner()}. If
2332      * this Window is not focused, then the child Component that most recently
2333      * requested focus will be returned. If no child Component has ever
2334      * requested focus, and this is a focusable Window, then this Window's
2335      * initial focusable Component is returned. If no child Component has ever
2336      * requested focus, and this is a non-focusable Window, null is returned.
2337      *
2338      * @return the child Component that will receive focus when this Window is
2339      *         focused
2340      * @see #getFocusOwner
2341      * @see #isFocused
2342      * @see #isFocusableWindow
2343      * @since 1.4
2344      */
2345     public Component getMostRecentFocusOwner() {
2346         if (isFocused()) {
2347             return getFocusOwner();
2348         } else {
2349             Component mostRecent =
2350                 KeyboardFocusManager.getMostRecentFocusOwner(this);
2351             if (mostRecent != null) {
2352                 return mostRecent;
2353             } else {
2354                 return (isFocusableWindow())
2355                     ? getFocusTraversalPolicy().getInitialComponent(this)
2356                     : null;
2357             }
2358         }
2359     }
2360 
2361     /**
2362      * Returns whether this Window is active. Only a Frame or a Dialog may be
2363      * active. The native windowing system may denote the active Window or its
2364      * children with special decorations, such as a highlighted title bar. The
2365      * active Window is always either the focused Window, or the first Frame or
2366      * Dialog that is an owner of the focused Window.
2367      *
2368      * @return whether this is the active Window.
2369      * @see #isFocused
2370      * @since 1.4
2371      */
2372     public boolean isActive() {
2373         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2374                 getActiveWindow() == this);
2375     }
2376 
2377     /**
2378      * Returns whether this Window is focused. If there exists a focus owner,
2379      * the focused Window is the Window that is, or contains, that focus owner.
2380      * If there is no focus owner, then no Window is focused.
2381      * <p>
2382      * If the focused Window is a Frame or a Dialog it is also the active
2383      * Window. Otherwise, the active Window is the first Frame or Dialog that
2384      * is an owner of the focused Window.
2385      *
2386      * @return whether this is the focused Window.
2387      * @see #isActive
2388      * @since 1.4
2389      */
2390     public boolean isFocused() {
2391         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2392                 getGlobalFocusedWindow() == this);
2393     }
2394 
2395     /**
2396      * Gets a focus traversal key for this Window. (See {@code
2397      * setFocusTraversalKeys} for a full description of each key.)
2398      * <p>
2399      * If the traversal key has not been explicitly set for this Window,
2400      * then this Window's parent's traversal key is returned. If the
2401      * traversal key has not been explicitly set for any of this Window's
2402      * ancestors, then the current KeyboardFocusManager's default traversal key
2403      * is returned.
2404      *
2405      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2406      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2407      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2408      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2409      * @return the AWTKeyStroke for the specified key
2410      * @see Container#setFocusTraversalKeys
2411      * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
2412      * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
2413      * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
2414      * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
2415      * @throws IllegalArgumentException if id is not one of
2416      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2417      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2418      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2419      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2420      * @since 1.4
2421      */
2422     @SuppressWarnings("unchecked")
2423     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2424         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
2425             throw new IllegalArgumentException("invalid focus traversal key identifier");
2426         }
2427 
2428         // Okay to return Set directly because it is an unmodifiable view
2429         @SuppressWarnings("rawtypes")
2430         Set keystrokes = (focusTraversalKeys != null)
2431             ? focusTraversalKeys[id]
2432             : null;
2433 
2434         if (keystrokes != null) {
2435             return keystrokes;
2436         } else {
2437             return KeyboardFocusManager.getCurrentKeyboardFocusManager().
2438                 getDefaultFocusTraversalKeys(id);
2439         }
2440     }
2441 
2442     /**
2443      * Does nothing because Windows must always be roots of a focus traversal
2444      * cycle. The passed-in value is ignored.
2445      *
2446      * @param focusCycleRoot this value is ignored
2447      * @see #isFocusCycleRoot
2448      * @see Container#setFocusTraversalPolicy
2449      * @see Container#getFocusTraversalPolicy
2450      * @since 1.4
2451      */
2452     public final void setFocusCycleRoot(boolean focusCycleRoot) {
2453     }
2454 
2455     /**
2456      * Always returns {@code true} because all Windows must be roots of a
2457      * focus traversal cycle.
2458      *
2459      * @return {@code true}
2460      * @see #setFocusCycleRoot
2461      * @see Container#setFocusTraversalPolicy
2462      * @see Container#getFocusTraversalPolicy
2463      * @since 1.4
2464      */
2465     public final boolean isFocusCycleRoot() {
2466         return true;
2467     }
2468 
2469     /**
2470      * Always returns {@code null} because Windows have no ancestors; they
2471      * represent the top of the Component hierarchy.
2472      *
2473      * @return {@code null}
2474      * @see Container#isFocusCycleRoot()
2475      * @since 1.4
2476      */
2477     public final Container getFocusCycleRootAncestor() {
2478         return null;
2479     }
2480 
2481     /**
2482      * Returns whether this Window can become the focused Window, that is,
2483      * whether this Window or any of its subcomponents can become the focus
2484      * owner. For a Frame or Dialog to be focusable, its focusable Window state
2485      * must be set to {@code true}. For a Window which is not a Frame or
2486      * Dialog to be focusable, its focusable Window state must be set to
2487      * {@code true}, its nearest owning Frame or Dialog must be
2488      * showing on the screen, and it must contain at least one Component in
2489      * its focus traversal cycle. If any of these conditions is not met, then
2490      * neither this Window nor any of its subcomponents can become the focus
2491      * owner.
2492      *
2493      * @return {@code true} if this Window can be the focused Window;
2494      *         {@code false} otherwise
2495      * @see #getFocusableWindowState
2496      * @see #setFocusableWindowState
2497      * @see #isShowing
2498      * @see Component#isFocusable
2499      * @since 1.4
2500      */
2501     public final boolean isFocusableWindow() {
2502         // If a Window/Frame/Dialog was made non-focusable, then it is always
2503         // non-focusable.
2504         if (!getFocusableWindowState()) {
2505             return false;
2506         }
2507 
2508         // All other tests apply only to Windows.
2509         if (this instanceof Frame || this instanceof Dialog) {
2510             return true;
2511         }
2512 
2513         // A Window must have at least one Component in its root focus
2514         // traversal cycle to be focusable.
2515         if (getFocusTraversalPolicy().getDefaultComponent(this) == null) {
2516             return false;
2517         }
2518 
2519         // A Window's nearest owning Frame or Dialog must be showing on the
2520         // screen.
2521         for (Window owner = getOwner(); owner != null;
2522              owner = owner.getOwner())
2523         {
2524             if (owner instanceof Frame || owner instanceof Dialog) {
2525                 return owner.isShowing();
2526             }
2527         }
2528 
2529         return false;
2530     }
2531 
2532     /**
2533      * Returns whether this Window can become the focused Window if it meets
2534      * the other requirements outlined in {@code isFocusableWindow}. If
2535      * this method returns {@code false}, then
2536      * {@code isFocusableWindow} will return {@code false} as well.
2537      * If this method returns {@code true}, then
2538      * {@code isFocusableWindow} may return {@code true} or
2539      * {@code false} depending upon the other requirements which must be
2540      * met in order for a Window to be focusable.
2541      * <p>
2542      * By default, all Windows have a focusable Window state of
2543      * {@code true}.
2544      *
2545      * @return whether this Window can be the focused Window
2546      * @see #isFocusableWindow
2547      * @see #setFocusableWindowState
2548      * @see #isShowing
2549      * @see Component#setFocusable
2550      * @since 1.4
2551      */
2552     public boolean getFocusableWindowState() {
2553         return focusableWindowState;
2554     }
2555 
2556     /**
2557      * Sets whether this Window can become the focused Window if it meets
2558      * the other requirements outlined in {@code isFocusableWindow}. If
2559      * this Window's focusable Window state is set to {@code false}, then
2560      * {@code isFocusableWindow} will return {@code false}. If this
2561      * Window's focusable Window state is set to {@code true}, then
2562      * {@code isFocusableWindow} may return {@code true} or
2563      * {@code false} depending upon the other requirements which must be
2564      * met in order for a Window to be focusable.
2565      * <p>
2566      * Setting a Window's focusability state to {@code false} is the
2567      * standard mechanism for an application to identify to the AWT a Window
2568      * which will be used as a floating palette or toolbar, and thus should be
2569      * a non-focusable Window.
2570      *
2571      * Setting the focusability state on a visible {@code Window}
2572      * can have a delayed effect on some platforms — the actual
2573      * change may happen only when the {@code Window} becomes
2574      * hidden and then visible again.  To ensure consistent behavior
2575      * across platforms, set the {@code Window}'s focusable state
2576      * when the {@code Window} is invisible and then show it.
2577      *
2578      * @param focusableWindowState whether this Window can be the focused
2579      *        Window
2580      * @see #isFocusableWindow
2581      * @see #getFocusableWindowState
2582      * @see #isShowing
2583      * @see Component#setFocusable
2584      * @since 1.4
2585      */
2586     public void setFocusableWindowState(boolean focusableWindowState) {
2587         boolean oldFocusableWindowState;
2588         synchronized (this) {
2589             oldFocusableWindowState = this.focusableWindowState;
2590             this.focusableWindowState = focusableWindowState;
2591         }
2592         WindowPeer peer = (WindowPeer)this.peer;
2593         if (peer != null) {
2594             peer.updateFocusableWindowState();
2595         }
2596         firePropertyChange("focusableWindowState", oldFocusableWindowState,
2597                            focusableWindowState);
2598         if (oldFocusableWindowState && !focusableWindowState && isFocused()) {
2599             for (Window owner = getOwner();
2600                  owner != null;
2601                  owner = owner.getOwner())
2602                 {
2603                     Component toFocus =
2604                         KeyboardFocusManager.getMostRecentFocusOwner(owner);
2605                     if (toFocus != null && toFocus.requestFocus(false, CausedFocusEvent.Cause.ACTIVATION)) {
2606                         return;
2607                     }
2608                 }
2609             KeyboardFocusManager.getCurrentKeyboardFocusManager().
2610                 clearGlobalFocusOwnerPriv();
2611         }
2612     }
2613 
2614     /**
2615      * Sets whether this window should receive focus on
2616      * subsequently being shown (with a call to {@link #setVisible setVisible(true)}),
2617      * or being moved to the front (with a call to {@link #toFront}).
2618      * <p>
2619      * Note that {@link #setVisible setVisible(true)} may be called indirectly
2620      * (e.g. when showing an owner of the window makes the window to be shown).
2621      * {@link #toFront} may also be called indirectly (e.g. when
2622      * {@link #setVisible setVisible(true)} is called on already visible window).
2623      * In all such cases this property takes effect as well.
2624      * <p>
2625      * The value of the property is not inherited by owned windows.
2626      *
2627      * @param autoRequestFocus whether this window should be focused on
2628      *        subsequently being shown or being moved to the front
2629      * @see #isAutoRequestFocus
2630      * @see #isFocusableWindow
2631      * @see #setVisible
2632      * @see #toFront
2633      * @since 1.7
2634      */
2635     public void setAutoRequestFocus(boolean autoRequestFocus) {
2636         this.autoRequestFocus = autoRequestFocus;
2637     }
2638 
2639     /**
2640      * Returns whether this window should receive focus on subsequently being shown
2641      * (with a call to {@link #setVisible setVisible(true)}), or being moved to the front
2642      * (with a call to {@link #toFront}).
2643      * <p>
2644      * By default, the window has {@code autoRequestFocus} value of {@code true}.
2645      *
2646      * @return {@code autoRequestFocus} value
2647      * @see #setAutoRequestFocus
2648      * @since 1.7
2649      */
2650     public boolean isAutoRequestFocus() {
2651         return autoRequestFocus;
2652     }
2653 
2654     /**
2655      * Adds a PropertyChangeListener to the listener list. The listener is
2656      * registered for all bound properties of this class, including the
2657      * following:
2658      * <ul>
2659      *    <li>this Window's font ("font")</li>
2660      *    <li>this Window's background color ("background")</li>
2661      *    <li>this Window's foreground color ("foreground")</li>
2662      *    <li>this Window's focusability ("focusable")</li>
2663      *    <li>this Window's focus traversal keys enabled state
2664      *        ("focusTraversalKeysEnabled")</li>
2665      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2666      *        ("forwardFocusTraversalKeys")</li>
2667      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2668      *        ("backwardFocusTraversalKeys")</li>
2669      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2670      *        ("upCycleFocusTraversalKeys")</li>
2671      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2672      *        ("downCycleFocusTraversalKeys")</li>
2673      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2674      *        </li>
2675      *    <li>this Window's focusable Window state ("focusableWindowState")
2676      *        </li>
2677      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2678      * </ul>
2679      * Note that if this Window is inheriting a bound property, then no
2680      * event will be fired in response to a change in the inherited property.
2681      * <p>
2682      * If listener is null, no exception is thrown and no action is performed.
2683      *
2684      * @param    listener  the PropertyChangeListener to be added
2685      *
2686      * @see Component#removePropertyChangeListener
2687      * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
2688      */
2689     public void addPropertyChangeListener(PropertyChangeListener listener) {
2690         super.addPropertyChangeListener(listener);
2691     }
2692 
2693     /**
2694      * Adds a PropertyChangeListener to the listener list for a specific
2695      * property. The specified property may be user-defined, or one of the
2696      * following:
2697      * <ul>
2698      *    <li>this Window's font ("font")</li>
2699      *    <li>this Window's background color ("background")</li>
2700      *    <li>this Window's foreground color ("foreground")</li>
2701      *    <li>this Window's focusability ("focusable")</li>
2702      *    <li>this Window's focus traversal keys enabled state
2703      *        ("focusTraversalKeysEnabled")</li>
2704      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2705      *        ("forwardFocusTraversalKeys")</li>
2706      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2707      *        ("backwardFocusTraversalKeys")</li>
2708      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2709      *        ("upCycleFocusTraversalKeys")</li>
2710      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2711      *        ("downCycleFocusTraversalKeys")</li>
2712      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2713      *        </li>
2714      *    <li>this Window's focusable Window state ("focusableWindowState")
2715      *        </li>
2716      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2717      * </ul>
2718      * Note that if this Window is inheriting a bound property, then no
2719      * event will be fired in response to a change in the inherited property.
2720      * <p>
2721      * If listener is null, no exception is thrown and no action is performed.
2722      *
2723      * @param propertyName one of the property names listed above
2724      * @param listener the PropertyChangeListener to be added
2725      *
2726      * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
2727      * @see Component#removePropertyChangeListener
2728      */
2729     public void addPropertyChangeListener(String propertyName,
2730                                           PropertyChangeListener listener) {
2731         super.addPropertyChangeListener(propertyName, listener);
2732     }
2733 
2734     /**
2735      * Indicates if this container is a validate root.
2736      * <p>
2737      * {@code Window} objects are the validate roots, and, therefore, they
2738      * override this method to return {@code true}.
2739      *
2740      * @return {@code true}
2741      * @since 1.7
2742      * @see java.awt.Container#isValidateRoot
2743      */
2744     @Override
2745     public boolean isValidateRoot() {
2746         return true;
2747     }
2748 
2749     /**
2750      * Dispatches an event to this window or one of its sub components.
2751      * @param e the event
2752      */
2753     void dispatchEventImpl(AWTEvent e) {
2754         if (e.getID() == ComponentEvent.COMPONENT_RESIZED) {
2755             invalidate();
2756             validate();
2757         }
2758         super.dispatchEventImpl(e);
2759     }
2760 
2761     /**
2762      * @deprecated As of JDK version 1.1
2763      * replaced by {@code dispatchEvent(AWTEvent)}.
2764      */
2765     @Deprecated
2766     public boolean postEvent(Event e) {
2767         if (handleEvent(e)) {
2768             e.consume();
2769             return true;
2770         }
2771         return false;
2772     }
2773 
2774     /**
2775      * Checks if this Window is showing on screen.
2776      * @see Component#setVisible
2777     */
2778     public boolean isShowing() {
2779         return visible;
2780     }
2781 
2782     boolean isDisposing() {
2783         return disposing;
2784     }
2785 
2786     /**
2787      * @deprecated As of J2SE 1.4, replaced by
2788      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2789      * @param rb the resource bundle
2790      */
2791     @Deprecated
2792     public void applyResourceBundle(ResourceBundle rb) {
2793         applyComponentOrientation(ComponentOrientation.getOrientation(rb));
2794     }
2795 
2796     /**
2797      * @deprecated As of J2SE 1.4, replaced by
2798      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2799      * @param rbName the resource name
2800      */
2801     @Deprecated
2802     public void applyResourceBundle(String rbName) {
2803         applyResourceBundle(ResourceBundle.getBundle(rbName));
2804     }
2805 
2806    /*
2807     * Support for tracking all windows owned by this window
2808     */
2809     void addOwnedWindow(WeakReference<Window> weakWindow) {
2810         if (weakWindow != null) {
2811             synchronized(ownedWindowList) {
2812                 // this if statement should really be an assert, but we don't
2813                 // have asserts...
2814                 if (!ownedWindowList.contains(weakWindow)) {
2815                     ownedWindowList.addElement(weakWindow);
2816                 }
2817             }
2818         }
2819     }
2820 
2821     void removeOwnedWindow(WeakReference<Window> weakWindow) {
2822         if (weakWindow != null) {
2823             // synchronized block not required since removeElement is
2824             // already synchronized
2825             ownedWindowList.removeElement(weakWindow);
2826         }
2827     }
2828 
2829     void connectOwnedWindow(Window child) {
2830         child.parent = this;
2831         addOwnedWindow(child.weakThis);
2832         child.disposerRecord.updateOwner();
2833     }
2834 
2835     private void addToWindowList() {
2836         synchronized (Window.class) {
2837             @SuppressWarnings("unchecked")
2838             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
2839             if (windowList == null) {
2840                 windowList = new Vector<WeakReference<Window>>();
2841                 appContext.put(Window.class, windowList);
2842             }
2843             windowList.add(weakThis);
2844         }
2845     }
2846 
2847     private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
2848         synchronized (Window.class) {
2849             @SuppressWarnings("unchecked")
2850             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
2851             if (windowList != null) {
2852                 windowList.remove(weakThis);
2853             }
2854         }
2855     }
2856 
2857     private void removeFromWindowList() {
2858         removeFromWindowList(appContext, weakThis);
2859     }
2860 
2861     /**
2862      * Window type.
2863      *
2864      * Synchronization: ObjectLock
2865      */
2866     private Type type = Type.NORMAL;
2867 
2868     /**
2869      * Sets the type of the window.
2870      *
2871      * This method can only be called while the window is not displayable.
2872      *
2873      * @param  type the window type
2874      * @throws IllegalComponentStateException if the window
2875      *         is displayable.
2876      * @throws IllegalArgumentException if the type is {@code null}
2877      * @see    Component#isDisplayable
2878      * @see    #getType
2879      * @since 1.7
2880      */
2881     public void setType(Type type) {
2882         if (type == null) {
2883             throw new IllegalArgumentException("type should not be null.");
2884         }
2885         synchronized (getTreeLock()) {
2886             if (isDisplayable()) {
2887                 throw new IllegalComponentStateException(
2888                         "The window is displayable.");
2889             }
2890             synchronized (getObjectLock()) {
2891                 this.type = type;
2892             }
2893         }
2894     }
2895 
2896     /**
2897      * Returns the type of the window.
2898      *
2899      * @return the type of the window
2900      * @see   #setType
2901      * @since 1.7
2902      */
2903     public Type getType() {
2904         synchronized (getObjectLock()) {
2905             return type;
2906         }
2907     }
2908 
2909     /**
2910      * The window serialized data version.
2911      *
2912      * @serial
2913      */
2914     private int windowSerializedDataVersion = 2;
2915 
2916     /**
2917      * Writes default serializable fields to stream.  Writes
2918      * a list of serializable {@code WindowListener}s and
2919      * {@code WindowFocusListener}s as optional data.
2920      * Writes a list of child windows as optional data.
2921      * Writes a list of icon images as optional data
2922      *
2923      * @param s the {@code ObjectOutputStream} to write
2924      * @serialData {@code null} terminated sequence of
2925      *    0 or more pairs; the pair consists of a {@code String}
2926      *    and {@code Object}; the {@code String}
2927      *    indicates the type of object and is one of the following:
2928      *    {@code windowListenerK} indicating a
2929      *      {@code WindowListener} object;
2930      *    {@code windowFocusWindowK} indicating a
2931      *      {@code WindowFocusListener} object;
2932      *    {@code ownedWindowK} indicating a child
2933      *      {@code Window} object
2934      *
2935      * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
2936      * @see Component#windowListenerK
2937      * @see Component#windowFocusListenerK
2938      * @see Component#ownedWindowK
2939      * @see #readObject(ObjectInputStream)
2940      */
2941     private void writeObject(ObjectOutputStream s) throws IOException {
2942         synchronized (this) {
2943             // Update old focusMgr fields so that our object stream can be read
2944             // by previous releases
2945             focusMgr = new FocusManager();
2946             focusMgr.focusRoot = this;
2947             focusMgr.focusOwner = getMostRecentFocusOwner();
2948 
2949             s.defaultWriteObject();
2950 
2951             // Clear fields so that we don't keep extra references around
2952             focusMgr = null;
2953 
2954             AWTEventMulticaster.save(s, windowListenerK, windowListener);
2955             AWTEventMulticaster.save(s, windowFocusListenerK, windowFocusListener);
2956             AWTEventMulticaster.save(s, windowStateListenerK, windowStateListener);
2957         }
2958 
2959         s.writeObject(null);
2960 
2961         synchronized (ownedWindowList) {
2962             for (int i = 0; i < ownedWindowList.size(); i++) {
2963                 Window child = ownedWindowList.elementAt(i).get();
2964                 if (child != null) {
2965                     s.writeObject(ownedWindowK);
2966                     s.writeObject(child);
2967                 }
2968             }
2969         }
2970         s.writeObject(null);
2971 
2972         //write icon array
2973         if (icons != null) {
2974             for (Image i : icons) {
2975                 if (i instanceof Serializable) {
2976                     s.writeObject(i);
2977                 }
2978             }
2979         }
2980         s.writeObject(null);
2981     }
2982 
2983     //
2984     // Part of deserialization procedure to be called before
2985     // user's code.
2986     //
2987     private void initDeserializedWindow() {
2988         setWarningString();
2989         inputContextLock = new Object();
2990 
2991         // Deserialized Windows are not yet visible.
2992         visible = false;
2993 
2994         weakThis = new WeakReference<>(this);
2995 
2996         anchor = new Object();
2997         disposerRecord = new WindowDisposerRecord(appContext, this);
2998         sun.java2d.Disposer.addRecord(anchor, disposerRecord);
2999 
3000         addToWindowList();
3001         initGC(null);
3002         ownedWindowList = new Vector<>();
3003     }
3004 
3005     private void deserializeResources(ObjectInputStream s)
3006         throws ClassNotFoundException, IOException, HeadlessException {
3007 
3008             if (windowSerializedDataVersion < 2) {
3009                 // Translate old-style focus tracking to new model. For 1.4 and
3010                 // later releases, we'll rely on the Window's initial focusable
3011                 // Component.
3012                 if (focusMgr != null) {
3013                     if (focusMgr.focusOwner != null) {
3014                         KeyboardFocusManager.
3015                             setMostRecentFocusOwner(this, focusMgr.focusOwner);
3016                     }
3017                 }
3018 
3019                 // This field is non-transient and relies on default serialization.
3020                 // However, the default value is insufficient, so we need to set
3021                 // it explicitly for object data streams prior to 1.4.
3022                 focusableWindowState = true;
3023 
3024 
3025             }
3026 
3027         Object keyOrNull;
3028         while(null != (keyOrNull = s.readObject())) {
3029             String key = ((String)keyOrNull).intern();
3030 
3031             if (windowListenerK == key) {
3032                 addWindowListener((WindowListener)(s.readObject()));
3033             } else if (windowFocusListenerK == key) {
3034                 addWindowFocusListener((WindowFocusListener)(s.readObject()));
3035             } else if (windowStateListenerK == key) {
3036                 addWindowStateListener((WindowStateListener)(s.readObject()));
3037             } else // skip value for unrecognized key
3038                 s.readObject();
3039         }
3040 
3041         try {
3042             while (null != (keyOrNull = s.readObject())) {
3043                 String key = ((String)keyOrNull).intern();
3044 
3045                 if (ownedWindowK == key)
3046                     connectOwnedWindow((Window) s.readObject());
3047 
3048                 else // skip value for unrecognized key
3049                     s.readObject();
3050             }
3051 
3052             //read icons
3053             Object obj = s.readObject(); //Throws OptionalDataException
3054                                          //for pre1.6 objects.
3055             icons = new ArrayList<Image>(); //Frame.readObject() assumes
3056                                             //pre1.6 version if icons is null.
3057             while (obj != null) {
3058                 if (obj instanceof Image) {
3059                     icons.add((Image)obj);
3060                 }
3061                 obj = s.readObject();
3062             }
3063         }
3064         catch (OptionalDataException e) {
3065             // 1.1 serialized form
3066             // ownedWindowList will be updated by Frame.readObject
3067         }
3068 
3069     }
3070 
3071     /**
3072      * Reads the {@code ObjectInputStream} and an optional
3073      * list of listeners to receive various events fired by
3074      * the component; also reads a list of
3075      * (possibly {@code null}) child windows.
3076      * Unrecognized keys or values will be ignored.
3077      *
3078      * @param s the {@code ObjectInputStream} to read
3079      * @exception HeadlessException if
3080      *   {@code GraphicsEnvironment.isHeadless} returns
3081      *   {@code true}
3082      * @see java.awt.GraphicsEnvironment#isHeadless
3083      * @see #writeObject
3084      */
3085     private void readObject(ObjectInputStream s)
3086       throws ClassNotFoundException, IOException, HeadlessException
3087     {
3088          GraphicsEnvironment.checkHeadless();
3089          initDeserializedWindow();
3090          ObjectInputStream.GetField f = s.readFields();
3091 
3092          syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests);
3093          state = f.get("state", 0);
3094          focusableWindowState = f.get("focusableWindowState", true);
3095          windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1);
3096          locationByPlatform = f.get("locationByPlatform", locationByPlatformProp);
3097          // Note: 1.4 (or later) doesn't use focusMgr
3098          focusMgr = (FocusManager)f.get("focusMgr", null);
3099          Dialog.ModalExclusionType et = (Dialog.ModalExclusionType)
3100              f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE);
3101          setModalExclusionType(et); // since 6.0
3102          boolean aot = f.get("alwaysOnTop", false);
3103          if(aot) {
3104              setAlwaysOnTop(aot); // since 1.5; subject to permission check
3105          }
3106          shape = (Shape)f.get("shape", null);
3107          opacity = (Float)f.get("opacity", 1.0f);
3108 
3109          this.securityWarningWidth = 0;
3110          this.securityWarningHeight = 0;
3111          this.securityWarningPointX = 2.0;
3112          this.securityWarningPointY = 0.0;
3113          this.securityWarningAlignmentX = RIGHT_ALIGNMENT;
3114          this.securityWarningAlignmentY = TOP_ALIGNMENT;
3115 
3116          deserializeResources(s);
3117     }
3118 
3119     /*
3120      * --- Accessibility Support ---
3121      *
3122      */
3123 
3124     /**
3125      * Gets the AccessibleContext associated with this Window.
3126      * For windows, the AccessibleContext takes the form of an
3127      * AccessibleAWTWindow.
3128      * A new AccessibleAWTWindow instance is created if necessary.
3129      *
3130      * @return an AccessibleAWTWindow that serves as the
3131      *         AccessibleContext of this Window
3132      * @since 1.3
3133      */
3134     public AccessibleContext getAccessibleContext() {
3135         if (accessibleContext == null) {
3136             accessibleContext = new AccessibleAWTWindow();
3137         }
3138         return accessibleContext;
3139     }
3140 
3141     /**
3142      * This class implements accessibility support for the
3143      * {@code Window} class.  It provides an implementation of the
3144      * Java Accessibility API appropriate to window user-interface elements.
3145      * @since 1.3
3146      */
3147     protected class AccessibleAWTWindow extends AccessibleAWTContainer
3148     {
3149         /*
3150          * JDK 1.3 serialVersionUID
3151          */
3152         private static final long serialVersionUID = 4215068635060671780L;
3153 
3154         /**
3155          * Get the role of this object.
3156          *
3157          * @return an instance of AccessibleRole describing the role of the
3158          * object
3159          * @see javax.accessibility.AccessibleRole
3160          */
3161         public AccessibleRole getAccessibleRole() {
3162             return AccessibleRole.WINDOW;
3163         }
3164 
3165         /**
3166          * Get the state of this object.
3167          *
3168          * @return an instance of AccessibleStateSet containing the current
3169          * state set of the object
3170          * @see javax.accessibility.AccessibleState
3171          */
3172         public AccessibleStateSet getAccessibleStateSet() {
3173             AccessibleStateSet states = super.getAccessibleStateSet();
3174             if (getFocusOwner() != null) {
3175                 states.add(AccessibleState.ACTIVE);
3176             }
3177             return states;
3178         }
3179 
3180     } // inner class AccessibleAWTWindow
3181 
3182     @Override
3183     void setGraphicsConfiguration(GraphicsConfiguration gc) {
3184         if (gc == null) {
3185             gc = GraphicsEnvironment.
3186                     getLocalGraphicsEnvironment().
3187                     getDefaultScreenDevice().
3188                     getDefaultConfiguration();
3189         }
3190         synchronized (getTreeLock()) {
3191             super.setGraphicsConfiguration(gc);
3192             if (log.isLoggable(PlatformLogger.Level.FINER)) {
3193                 log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this);
3194             }
3195         }
3196     }
3197 
3198     /**
3199      * Sets the location of the window relative to the specified
3200      * component according to the following scenarios.
3201      * <p>
3202      * The target screen mentioned below is a screen to which
3203      * the window should be placed after the setLocationRelativeTo
3204      * method is called.
3205      * <ul>
3206      * <li>If the component is {@code null}, or the {@code
3207      * GraphicsConfiguration} associated with this component is
3208      * {@code null}, the window is placed in the center of the
3209      * screen. The center point can be obtained with the {@link
3210      * GraphicsEnvironment#getCenterPoint
3211      * GraphicsEnvironment.getCenterPoint} method.
3212      * <li>If the component is not {@code null}, but it is not
3213      * currently showing, the window is placed in the center of
3214      * the target screen defined by the {@code
3215      * GraphicsConfiguration} associated with this component.
3216      * <li>If the component is not {@code null} and is shown on
3217      * the screen, then the window is located in such a way that
3218      * the center of the window coincides with the center of the
3219      * component.
3220      * </ul>
3221      * <p>
3222      * If the screens configuration does not allow the window to
3223      * be moved from one screen to another, then the window is
3224      * only placed at the location determined according to the
3225      * above conditions and its {@code GraphicsConfiguration} is
3226      * not changed.
3227      * <p>
3228      * <b>Note</b>: If the lower edge of the window is out of the screen,
3229      * then the window is placed to the side of the {@code Component}
3230      * that is closest to the center of the screen. So if the
3231      * component is on the right part of the screen, the window
3232      * is placed to its left, and vice versa.
3233      * <p>
3234      * If after the window location has been calculated, the upper,
3235      * left, or right edge of the window is out of the screen,
3236      * then the window is located in such a way that the upper,
3237      * left, or right edge of the window coincides with the
3238      * corresponding edge of the screen. If both left and right
3239      * edges of the window are out of the screen, the window is
3240      * placed at the left side of the screen. The similar placement
3241      * will occur if both top and bottom edges are out of the screen.
3242      * In that case, the window is placed at the top side of the screen.
3243      * <p>
3244      * The method changes the geometry-related data. Therefore,
3245      * the native windowing system may ignore such requests, or it may modify
3246      * the requested data, so that the {@code Window} object is placed and sized
3247      * in a way that corresponds closely to the desktop settings.
3248      *
3249      * @param c  the component in relation to which the window's location
3250      *           is determined
3251      * @see java.awt.GraphicsEnvironment#getCenterPoint
3252      * @since 1.4
3253      */
3254     public void setLocationRelativeTo(Component c) {
3255         // target location
3256         int dx = 0, dy = 0;
3257         // target GC
3258         GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
3259         Rectangle gcBounds = gc.getBounds();
3260 
3261         Dimension windowSize = getSize();
3262 
3263         // search a top-level of c
3264         Window componentWindow = SunToolkit.getContainingWindow(c);
3265         if ((c == null) || (componentWindow == null)) {
3266             GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
3267             gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
3268             gcBounds = gc.getBounds();
3269             Point centerPoint = ge.getCenterPoint();
3270             dx = centerPoint.x - windowSize.width / 2;
3271             dy = centerPoint.y - windowSize.height / 2;
3272         } else if (!c.isShowing()) {
3273             gc = componentWindow.getGraphicsConfiguration();
3274             gcBounds = gc.getBounds();
3275             dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2;
3276             dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2;
3277         } else {
3278             gc = componentWindow.getGraphicsConfiguration();
3279             gcBounds = gc.getBounds();
3280             Dimension compSize = c.getSize();
3281             Point compLocation = c.getLocationOnScreen();
3282             dx = compLocation.x + ((compSize.width - windowSize.width) / 2);
3283             dy = compLocation.y + ((compSize.height - windowSize.height) / 2);
3284 
3285             // Adjust for bottom edge being offscreen
3286             if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3287                 dy = gcBounds.y + gcBounds.height - windowSize.height;
3288                 if (compLocation.x - gcBounds.x + compSize.width / 2 < gcBounds.width / 2) {
3289                     dx = compLocation.x + compSize.width;
3290                 } else {
3291                     dx = compLocation.x - windowSize.width;
3292                 }
3293             }
3294         }
3295 
3296         // Avoid being placed off the edge of the screen:
3297         // bottom
3298         if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3299             dy = gcBounds.y + gcBounds.height - windowSize.height;
3300         }
3301         // top
3302         if (dy < gcBounds.y) {
3303             dy = gcBounds.y;
3304         }
3305         // right
3306         if (dx + windowSize.width > gcBounds.x + gcBounds.width) {
3307             dx = gcBounds.x + gcBounds.width - windowSize.width;
3308         }
3309         // left
3310         if (dx < gcBounds.x) {
3311             dx = gcBounds.x;
3312         }
3313 
3314         setLocation(dx, dy);
3315     }
3316 
3317     /**
3318      * Overridden from Component.  Top-level Windows should not propagate a
3319      * MouseWheelEvent beyond themselves into their owning Windows.
3320      */
3321     void deliverMouseWheelToAncestor(MouseWheelEvent e) {}
3322 
3323     /**
3324      * Overridden from Component.  Top-level Windows don't dispatch to ancestors
3325      */
3326     boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {return false;}
3327 
3328     /**
3329      * Creates a new strategy for multi-buffering on this component.
3330      * Multi-buffering is useful for rendering performance.  This method
3331      * attempts to create the best strategy available with the number of
3332      * buffers supplied.  It will always create a {@code BufferStrategy}
3333      * with that number of buffers.
3334      * A page-flipping strategy is attempted first, then a blitting strategy
3335      * using accelerated buffers.  Finally, an unaccelerated blitting
3336      * strategy is used.
3337      * <p>
3338      * Each time this method is called,
3339      * the existing buffer strategy for this component is discarded.
3340      * @param numBuffers number of buffers to create
3341      * @exception IllegalArgumentException if numBuffers is less than 1.
3342      * @exception IllegalStateException if the component is not displayable
3343      * @see #isDisplayable
3344      * @see #getBufferStrategy
3345      * @since 1.4
3346      */
3347     public void createBufferStrategy(int numBuffers) {
3348         super.createBufferStrategy(numBuffers);
3349     }
3350 
3351     /**
3352      * Creates a new strategy for multi-buffering on this component with the
3353      * required buffer capabilities.  This is useful, for example, if only
3354      * accelerated memory or page flipping is desired (as specified by the
3355      * buffer capabilities).
3356      * <p>
3357      * Each time this method
3358      * is called, the existing buffer strategy for this component is discarded.
3359      * @param numBuffers number of buffers to create, including the front buffer
3360      * @param caps the required capabilities for creating the buffer strategy;
3361      * cannot be {@code null}
3362      * @exception AWTException if the capabilities supplied could not be
3363      * supported or met; this may happen, for example, if there is not enough
3364      * accelerated memory currently available, or if page flipping is specified
3365      * but not possible.
3366      * @exception IllegalArgumentException if numBuffers is less than 1, or if
3367      * caps is {@code null}
3368      * @see #getBufferStrategy
3369      * @since 1.4
3370      */
3371     public void createBufferStrategy(int numBuffers,
3372         BufferCapabilities caps) throws AWTException {
3373         super.createBufferStrategy(numBuffers, caps);
3374     }
3375 
3376     /**
3377      * Returns the {@code BufferStrategy} used by this component.  This
3378      * method will return null if a {@code BufferStrategy} has not yet
3379      * been created or has been disposed.
3380      *
3381      * @return the buffer strategy used by this component
3382      * @see #createBufferStrategy
3383      * @since 1.4
3384      */
3385     public BufferStrategy getBufferStrategy() {
3386         return super.getBufferStrategy();
3387     }
3388 
3389     Component getTemporaryLostComponent() {
3390         return temporaryLostComponent;
3391     }
3392     Component setTemporaryLostComponent(Component component) {
3393         Component previousComp = temporaryLostComponent;
3394         // Check that "component" is an acceptable focus owner and don't store it otherwise
3395         // - or later we will have problems with opposite while handling  WINDOW_GAINED_FOCUS
3396         if (component == null || component.canBeFocusOwner()) {
3397             temporaryLostComponent = component;
3398         } else {
3399             temporaryLostComponent = null;
3400         }
3401         return previousComp;
3402     }
3403 
3404     /**
3405      * Checks whether this window can contain focus owner.
3406      * Verifies that it is focusable and as container it can container focus owner.
3407      * @since 1.5
3408      */
3409     boolean canContainFocusOwner(Component focusOwnerCandidate) {
3410         return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow();
3411     }
3412 
3413     private boolean locationByPlatform = locationByPlatformProp;
3414 
3415 
3416     /**
3417      * Sets whether this Window should appear at the default location for the
3418      * native windowing system or at the current location (returned by
3419      * {@code getLocation}) the next time the Window is made visible.
3420      * This behavior resembles a native window shown without programmatically
3421      * setting its location.  Most windowing systems cascade windows if their
3422      * locations are not explicitly set. The actual location is determined once the
3423      * window is shown on the screen.
3424      * <p>
3425      * This behavior can also be enabled by setting the System Property
3426      * "java.awt.Window.locationByPlatform" to "true", though calls to this method
3427      * take precedence.
3428      * <p>
3429      * Calls to {@code setVisible}, {@code setLocation} and
3430      * {@code setBounds} after calling {@code setLocationByPlatform} clear
3431      * this property of the Window.
3432      * <p>
3433      * For example, after the following code is executed:
3434      * <pre>
3435      * setLocationByPlatform(true);
3436      * setVisible(true);
3437      * boolean flag = isLocationByPlatform();
3438      * </pre>
3439      * The window will be shown at platform's default location and
3440      * {@code flag} will be {@code false}.
3441      * <p>
3442      * In the following sample:
3443      * <pre>
3444      * setLocationByPlatform(true);
3445      * setLocation(10, 10);
3446      * boolean flag = isLocationByPlatform();
3447      * setVisible(true);
3448      * </pre>
3449      * The window will be shown at (10, 10) and {@code flag} will be
3450      * {@code false}.
3451      *
3452      * @param locationByPlatform {@code true} if this Window should appear
3453      *        at the default location, {@code false} if at the current location
3454      * @throws IllegalComponentStateException if the window
3455      *         is showing on screen and locationByPlatform is {@code true}.
3456      * @see #setLocation
3457      * @see #isShowing
3458      * @see #setVisible
3459      * @see #isLocationByPlatform
3460      * @see java.lang.System#getProperty(String)
3461      * @since 1.5
3462      */
3463     public void setLocationByPlatform(boolean locationByPlatform) {
3464         synchronized (getTreeLock()) {
3465             if (locationByPlatform && isShowing()) {
3466                 throw new IllegalComponentStateException("The window is showing on screen.");
3467             }
3468             this.locationByPlatform = locationByPlatform;
3469         }
3470     }
3471 
3472     /**
3473      * Returns {@code true} if this Window will appear at the default location
3474      * for the native windowing system the next time this Window is made visible.
3475      * This method always returns {@code false} if the Window is showing on the
3476      * screen.
3477      *
3478      * @return whether this Window will appear at the default location
3479      * @see #setLocationByPlatform
3480      * @see #isShowing
3481      * @since 1.5
3482      */
3483     public boolean isLocationByPlatform() {
3484         synchronized (getTreeLock()) {
3485             return locationByPlatform;
3486         }
3487     }
3488 
3489     /**
3490      * {@inheritDoc}
3491      * <p>
3492      * The {@code width} or {@code height} values
3493      * are automatically enlarged if either is less than
3494      * the minimum size as specified by previous call to
3495      * {@code setMinimumSize}.
3496      * <p>
3497      * The method changes the geometry-related data. Therefore,
3498      * the native windowing system may ignore such requests, or it may modify
3499      * the requested data, so that the {@code Window} object is placed and sized
3500      * in a way that corresponds closely to the desktop settings.
3501      *
3502      * @see #getBounds
3503      * @see #setLocation(int, int)
3504      * @see #setLocation(Point)
3505      * @see #setSize(int, int)
3506      * @see #setSize(Dimension)
3507      * @see #setMinimumSize
3508      * @see #setLocationByPlatform
3509      * @see #isLocationByPlatform
3510      * @since 1.6
3511      */
3512     public void setBounds(int x, int y, int width, int height) {
3513         synchronized (getTreeLock()) {
3514             if (getBoundsOp() == ComponentPeer.SET_LOCATION ||
3515                 getBoundsOp() == ComponentPeer.SET_BOUNDS)
3516             {
3517                 locationByPlatform = false;
3518             }
3519             super.setBounds(x, y, width, height);
3520         }
3521     }
3522 
3523     /**
3524      * {@inheritDoc}
3525      * <p>
3526      * The {@code r.width} or {@code r.height} values
3527      * will be automatically enlarged if either is less than
3528      * the minimum size as specified by previous call to
3529      * {@code setMinimumSize}.
3530      * <p>
3531      * The method changes the geometry-related data. Therefore,
3532      * the native windowing system may ignore such requests, or it may modify
3533      * the requested data, so that the {@code Window} object is placed and sized
3534      * in a way that corresponds closely to the desktop settings.
3535      *
3536      * @see #getBounds
3537      * @see #setLocation(int, int)
3538      * @see #setLocation(Point)
3539      * @see #setSize(int, int)
3540      * @see #setSize(Dimension)
3541      * @see #setMinimumSize
3542      * @see #setLocationByPlatform
3543      * @see #isLocationByPlatform
3544      * @since 1.6
3545      */
3546     public void setBounds(Rectangle r) {
3547         setBounds(r.x, r.y, r.width, r.height);
3548     }
3549 
3550     /**
3551      * Determines whether this component will be displayed on the screen.
3552      * @return {@code true} if the component and all of its ancestors
3553      *          until a toplevel window are visible, {@code false} otherwise
3554      */
3555     boolean isRecursivelyVisible() {
3556         // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
3557         // We're overriding isRecursivelyVisible to implement this policy.
3558         return visible;
3559     }
3560 
3561 
3562     // ******************** SHAPES & TRANSPARENCY CODE ********************
3563 
3564     /**
3565      * Returns the opacity of the window.
3566      *
3567      * @return the opacity of the window
3568      *
3569      * @see Window#setOpacity(float)
3570      * @see GraphicsDevice.WindowTranslucency
3571      *
3572      * @since 1.7
3573      */
3574     public float getOpacity() {
3575         synchronized (getTreeLock()) {
3576             return opacity;
3577         }
3578     }
3579 
3580     /**
3581      * Sets the opacity of the window.
3582      * <p>
3583      * The opacity value is in the range [0..1]. Note that setting the opacity
3584      * level of 0 may or may not disable the mouse event handling on this
3585      * window. This is a platform-dependent behavior.
3586      * <p>
3587      * The following conditions must be met in order to set the opacity value
3588      * less than {@code 1.0f}:
3589      * <ul>
3590      * <li>The {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3591      * translucency must be supported by the underlying system
3592      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3593      * and {@link Dialog#setUndecorated})
3594      * <li>The window must not be in full-screen mode (see {@link
3595      * GraphicsDevice#setFullScreenWindow(Window)})
3596      * </ul>
3597      * <p>
3598      * If the requested opacity value is less than {@code 1.0f}, and any of the
3599      * above conditions are not met, the window opacity will not change,
3600      * and the {@code IllegalComponentStateException} will be thrown.
3601      * <p>
3602      * The translucency levels of individual pixels may also be effected by the
3603      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3604      * current shape of this window (see {@link #setShape(Shape)}).
3605      *
3606      * @param opacity the opacity level to set to the window
3607      *
3608      * @throws IllegalArgumentException if the opacity is out of the range
3609      *     [0..1]
3610      * @throws IllegalComponentStateException if the window is decorated and
3611      *     the opacity is less than {@code 1.0f}
3612      * @throws IllegalComponentStateException if the window is in full screen
3613      *     mode, and the opacity is less than {@code 1.0f}
3614      * @throws UnsupportedOperationException if the {@code
3615      *     GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3616      *     translucency is not supported and the opacity is less than
3617      *     {@code 1.0f}
3618      *
3619      * @see Window#getOpacity
3620      * @see Window#setBackground(Color)
3621      * @see Window#setShape(Shape)
3622      * @see Frame#isUndecorated
3623      * @see Dialog#isUndecorated
3624      * @see GraphicsDevice.WindowTranslucency
3625      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3626      *
3627      * @since 1.7
3628      */
3629     @SuppressWarnings("deprecation")
3630     public void setOpacity(float opacity) {
3631         synchronized (getTreeLock()) {
3632             if (opacity < 0.0f || opacity > 1.0f) {
3633                 throw new IllegalArgumentException(
3634                     "The value of opacity should be in the range [0.0f .. 1.0f].");
3635             }
3636             if (opacity < 1.0f) {
3637                 GraphicsConfiguration gc = getGraphicsConfiguration();
3638                 GraphicsDevice gd = gc.getDevice();
3639                 if (gc.getDevice().getFullScreenWindow() == this) {
3640                     throw new IllegalComponentStateException(
3641                         "Setting opacity for full-screen window is not supported.");
3642                 }
3643                 if (!gd.isWindowTranslucencySupported(
3644                     GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3645                 {
3646                     throw new UnsupportedOperationException(
3647                         "TRANSLUCENT translucency is not supported.");
3648                 }
3649             }
3650             this.opacity = opacity;
3651             WindowPeer peer = (WindowPeer) this.peer;
3652             if (peer != null) {
3653                 peer.setOpacity(opacity);
3654             }
3655         }
3656     }
3657 
3658     /**
3659      * Returns the shape of the window.
3660      *
3661      * The value returned by this method may not be the same as
3662      * previously set with {@code setShape(shape)}, but it is guaranteed
3663      * to represent the same shape.
3664      *
3665      * @return the shape of the window or {@code null} if no
3666      *     shape is specified for the window
3667      *
3668      * @see Window#setShape(Shape)
3669      * @see GraphicsDevice.WindowTranslucency
3670      *
3671      * @since 1.7
3672      */
3673     public Shape getShape() {
3674         synchronized (getTreeLock()) {
3675             return shape == null ? null : new Path2D.Float(shape);
3676         }
3677     }
3678 
3679     /**
3680      * Sets the shape of the window.
3681      * <p>
3682      * Setting a shape cuts off some parts of the window. Only the parts that
3683      * belong to the given {@link Shape} remain visible and clickable. If
3684      * the shape argument is {@code null}, this method restores the default
3685      * shape, making the window rectangular on most platforms.
3686      * <p>
3687      * The following conditions must be met to set a non-null shape:
3688      * <ul>
3689      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3690      * PERPIXEL_TRANSPARENT} translucency must be supported by the
3691      * underlying system
3692      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3693      * and {@link Dialog#setUndecorated})
3694      * <li>The window must not be in full-screen mode (see {@link
3695      * GraphicsDevice#setFullScreenWindow(Window)})
3696      * </ul>
3697      * <p>
3698      * If the requested shape is not {@code null}, and any of the above
3699      * conditions are not met, the shape of this window will not change,
3700      * and either the {@code UnsupportedOperationException} or {@code
3701      * IllegalComponentStateException} will be thrown.
3702      * <p>
3703      * The translucency levels of individual pixels may also be effected by the
3704      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3705      * opacity value (see {@link #setOpacity(float)}). See {@link
3706      * GraphicsDevice.WindowTranslucency} for more details.
3707      *
3708      * @param shape the shape to set to the window
3709      *
3710      * @throws IllegalComponentStateException if the shape is not {@code
3711      *     null} and the window is decorated
3712      * @throws IllegalComponentStateException if the shape is not {@code
3713      *     null} and the window is in full-screen mode
3714      * @throws UnsupportedOperationException if the shape is not {@code
3715      *     null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3716      *     PERPIXEL_TRANSPARENT} translucency is not supported
3717      *
3718      * @see Window#getShape()
3719      * @see Window#setBackground(Color)
3720      * @see Window#setOpacity(float)
3721      * @see Frame#isUndecorated
3722      * @see Dialog#isUndecorated
3723      * @see GraphicsDevice.WindowTranslucency
3724      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3725      *
3726      * @since 1.7
3727      */
3728     public void setShape(Shape shape) {
3729         synchronized (getTreeLock()) {
3730             if (shape != null) {
3731                 GraphicsConfiguration gc = getGraphicsConfiguration();
3732                 GraphicsDevice gd = gc.getDevice();
3733                 if (gc.getDevice().getFullScreenWindow() == this) {
3734                     throw new IllegalComponentStateException(
3735                         "Setting shape for full-screen window is not supported.");
3736                 }
3737                 if (!gd.isWindowTranslucencySupported(
3738                         GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3739                 {
3740                     throw new UnsupportedOperationException(
3741                         "PERPIXEL_TRANSPARENT translucency is not supported.");
3742                 }
3743             }
3744             this.shape = (shape == null) ? null : new Path2D.Float(shape);
3745             WindowPeer peer = (WindowPeer) this.peer;
3746             if (peer != null) {
3747                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3748             }
3749         }
3750     }
3751 
3752     /**
3753      * Gets the background color of this window.
3754      * <p>
3755      * Note that the alpha component of the returned color indicates whether
3756      * the window is in the non-opaque (per-pixel translucent) mode.
3757      *
3758      * @return this component's background color
3759      *
3760      * @see Window#setBackground(Color)
3761      * @see Window#isOpaque
3762      * @see GraphicsDevice.WindowTranslucency
3763      */
3764     @Override
3765     public Color getBackground() {
3766         return super.getBackground();
3767     }
3768 
3769     /**
3770      * Sets the background color of this window.
3771      * <p>
3772      * If the windowing system supports the {@link
3773      * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
3774      * translucency, the alpha component of the given background color
3775      * may effect the mode of operation for this window: it indicates whether
3776      * this window must be opaque (alpha equals {@code 1.0f}) or per-pixel translucent
3777      * (alpha is less than {@code 1.0f}). If the given background color is
3778      * {@code null}, the window is considered completely opaque.
3779      * <p>
3780      * All the following conditions must be met to enable the per-pixel
3781      * transparency mode for this window:
3782      * <ul>
3783      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3784      * PERPIXEL_TRANSLUCENT} translucency must be supported by the graphics
3785      * device where this window is located
3786      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3787      * and {@link Dialog#setUndecorated})
3788      * <li>The window must not be in full-screen mode (see {@link
3789      * GraphicsDevice#setFullScreenWindow(Window)})
3790      * </ul>
3791      * <p>
3792      * If the alpha component of the requested background color is less than
3793      * {@code 1.0f}, and any of the above conditions are not met, the background
3794      * color of this window will not change, the alpha component of the given
3795      * background color will not affect the mode of operation for this window,
3796      * and either the {@code UnsupportedOperationException} or {@code
3797      * IllegalComponentStateException} will be thrown.
3798      * <p>
3799      * When the window is per-pixel translucent, the drawing sub-system
3800      * respects the alpha value of each individual pixel. If a pixel gets
3801      * painted with the alpha color component equal to zero, it becomes
3802      * visually transparent. If the alpha of the pixel is equal to 1.0f, the
3803      * pixel is fully opaque. Interim values of the alpha color component make
3804      * the pixel semi-transparent. In this mode, the background of the window
3805      * gets painted with the alpha value of the given background color. If the
3806      * alpha value of the argument of this method is equal to {@code 0}, the
3807      * background is not painted at all.
3808      * <p>
3809      * The actual level of translucency of a given pixel also depends on window
3810      * opacity (see {@link #setOpacity(float)}), as well as the current shape of
3811      * this window (see {@link #setShape(Shape)}).
3812      * <p>
3813      * Note that painting a pixel with the alpha value of {@code 0} may or may
3814      * not disable the mouse event handling on this pixel. This is a
3815      * platform-dependent behavior. To make sure the mouse events do not get
3816      * dispatched to a particular pixel, the pixel must be excluded from the
3817      * shape of the window.
3818      * <p>
3819      * Enabling the per-pixel translucency mode may change the graphics
3820      * configuration of this window due to the native platform requirements.
3821      *
3822      * @param bgColor the color to become this window's background color.
3823      *
3824      * @throws IllegalComponentStateException if the alpha value of the given
3825      *     background color is less than {@code 1.0f} and the window is decorated
3826      * @throws IllegalComponentStateException if the alpha value of the given
3827      *     background color is less than {@code 1.0f} and the window is in
3828      *     full-screen mode
3829      * @throws UnsupportedOperationException if the alpha value of the given
3830      *     background color is less than {@code 1.0f} and {@link
3831      *     GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3832      *     PERPIXEL_TRANSLUCENT} translucency is not supported
3833      *
3834      * @see Window#getBackground
3835      * @see Window#isOpaque
3836      * @see Window#setOpacity(float)
3837      * @see Window#setShape(Shape)
3838      * @see Frame#isUndecorated
3839      * @see Dialog#isUndecorated
3840      * @see GraphicsDevice.WindowTranslucency
3841      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3842      * @see GraphicsConfiguration#isTranslucencyCapable()
3843      */
3844     @Override
3845     public void setBackground(Color bgColor) {
3846         Color oldBg = getBackground();
3847         super.setBackground(bgColor);
3848         if (oldBg != null && oldBg.equals(bgColor)) {
3849             return;
3850         }
3851         int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3852         int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3853         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3854             GraphicsConfiguration gc = getGraphicsConfiguration();
3855             GraphicsDevice gd = gc.getDevice();
3856             if (gc.getDevice().getFullScreenWindow() == this) {
3857                 throw new IllegalComponentStateException(
3858                     "Making full-screen window non opaque is not supported.");
3859             }
3860             if (!gc.isTranslucencyCapable()) {
3861                 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3862                 if (capableGC == null) {
3863                     throw new UnsupportedOperationException(
3864                         "PERPIXEL_TRANSLUCENT translucency is not supported");
3865                 }
3866                 setGraphicsConfiguration(capableGC);
3867             }
3868             setLayersOpaque(this, false);
3869         } else if ((oldAlpha < 255) && (alpha == 255)) {
3870             setLayersOpaque(this, true);
3871         }
3872         WindowPeer peer = (WindowPeer) this.peer;
3873         if (peer != null) {
3874             peer.setOpaque(alpha == 255);
3875         }
3876     }
3877 
3878     /**
3879      * Indicates if the window is currently opaque.
3880      * <p>
3881      * The method returns {@code false} if the background color of the window
3882      * is not {@code null} and the alpha component of the color is less than
3883      * {@code 1.0f}. The method returns {@code true} otherwise.
3884      *
3885      * @return {@code true} if the window is opaque, {@code false} otherwise
3886      *
3887      * @see Window#getBackground
3888      * @see Window#setBackground(Color)
3889      * @since 1.7
3890      */
3891     @Override
3892     public boolean isOpaque() {
3893         Color bg = getBackground();
3894         return bg != null ? bg.getAlpha() == 255 : true;
3895     }
3896 
3897     private void updateWindow() {
3898         synchronized (getTreeLock()) {
3899             WindowPeer peer = (WindowPeer) this.peer;
3900             if (peer != null) {
3901                 peer.updateWindow();
3902             }
3903         }
3904     }
3905 
3906     /**
3907      * {@inheritDoc}
3908      *
3909      * @since 1.7
3910      */
3911     @Override
3912     public void paint(Graphics g) {
3913         if (!isOpaque()) {
3914             Graphics gg = g.create();
3915             try {
3916                 if (gg instanceof Graphics2D) {
3917                     gg.setColor(getBackground());
3918                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
3919                     gg.fillRect(0, 0, getWidth(), getHeight());
3920                 }
3921             } finally {
3922                 gg.dispose();
3923             }
3924         }
3925         super.paint(g);
3926     }
3927 
3928     private static void setLayersOpaque(Component component, boolean isOpaque) {
3929         // Shouldn't use instanceof to avoid loading Swing classes
3930         //    if it's a pure AWT application.
3931         if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
3932             javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
3933             javax.swing.JRootPane root = rpc.getRootPane();
3934             javax.swing.JLayeredPane lp = root.getLayeredPane();
3935             Container c = root.getContentPane();
3936             javax.swing.JComponent content =
3937                 (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
3938             lp.setOpaque(isOpaque);
3939             root.setOpaque(isOpaque);
3940             if (content != null) {
3941                 content.setOpaque(isOpaque);
3942 
3943                 // Iterate down one level to see whether we have a JApplet
3944                 // (which is also a RootPaneContainer) which requires processing
3945                 int numChildren = content.getComponentCount();
3946                 if (numChildren > 0) {
3947                     Component child = content.getComponent(0);
3948                     // It's OK to use instanceof here because we've
3949                     // already loaded the RootPaneContainer class by now
3950                     if (child instanceof javax.swing.RootPaneContainer) {
3951                         setLayersOpaque(child, isOpaque);
3952                     }
3953                 }
3954             }
3955         }
3956     }
3957 
3958 
3959     // ************************** MIXING CODE *******************************
3960 
3961     // A window has an owner, but it does NOT have a container
3962     @Override
3963     final Container getContainer() {
3964         return null;
3965     }
3966 
3967     /**
3968      * Applies the shape to the component
3969      * @param shape Shape to be applied to the component
3970      */
3971     @Override
3972     final void applyCompoundShape(Region shape) {
3973         // The shape calculated by mixing code is not intended to be applied
3974         // to windows or frames
3975     }
3976 
3977     @Override
3978     final void applyCurrentShape() {
3979         // The shape calculated by mixing code is not intended to be applied
3980         // to windows or frames
3981     }
3982 
3983     @Override
3984     final void mixOnReshaping() {
3985         // The shape calculated by mixing code is not intended to be applied
3986         // to windows or frames
3987     }
3988 
3989     @Override
3990     final Point getLocationOnWindow() {
3991         return new Point(0, 0);
3992     }
3993 
3994     // ****************** END OF MIXING CODE ********************************
3995 
3996     /**
3997      * Limit the given double value with the given range.
3998      */
3999     private static double limit(double value, double min, double max) {
4000         value = Math.max(value, min);
4001         value = Math.min(value, max);
4002         return value;
4003     }
4004 
4005     /**
4006      * Calculate the position of the security warning.
4007      *
4008      * This method gets the window location/size as reported by the native
4009      * system since the locally cached values may represent outdated data.
4010      *
4011      * The method is used from the native code, or via AWTAccessor.
4012      *
4013      * NOTE: this method is invoked on the toolkit thread, and therefore is not
4014      * supposed to become public/user-overridable.
4015      */
4016     private Point2D calculateSecurityWarningPosition(double x, double y,
4017             double w, double h)
4018     {
4019         // The position according to the spec of SecurityWarning.setPosition()
4020         double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
4021         double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
4022 
4023         // First, make sure the warning is not too far from the window bounds
4024         wx = Window.limit(wx,
4025                 x - securityWarningWidth - 2,
4026                 x + w + 2);
4027         wy = Window.limit(wy,
4028                 y - securityWarningHeight - 2,
4029                 y + h + 2);
4030 
4031         // Now make sure the warning window is visible on the screen
4032         GraphicsConfiguration graphicsConfig =
4033             getGraphicsConfiguration_NoClientCode();
4034         Rectangle screenBounds = graphicsConfig.getBounds();
4035         Insets screenInsets =
4036             Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
4037 
4038         wx = Window.limit(wx,
4039                 screenBounds.x + screenInsets.left,
4040                 screenBounds.x + screenBounds.width - screenInsets.right
4041                 - securityWarningWidth);
4042         wy = Window.limit(wy,
4043                 screenBounds.y + screenInsets.top,
4044                 screenBounds.y + screenBounds.height - screenInsets.bottom
4045                 - securityWarningHeight);
4046 
4047         return new Point2D.Double(wx, wy);
4048     }
4049 
4050     static {
4051         AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() {
4052             public float getOpacity(Window window) {
4053                 return window.opacity;
4054             }
4055             public void setOpacity(Window window, float opacity) {
4056                 window.setOpacity(opacity);
4057             }
4058             public Shape getShape(Window window) {
4059                 return window.getShape();
4060             }
4061             public void setShape(Window window, Shape shape) {
4062                 window.setShape(shape);
4063             }
4064             public void setOpaque(Window window, boolean opaque) {
4065                 Color bg = window.getBackground();
4066                 if (bg == null) {
4067                     bg = new Color(0, 0, 0, 0);
4068                 }
4069                 window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(),
4070                                                opaque ? 255 : 0));
4071             }
4072             public void updateWindow(Window window) {
4073                 window.updateWindow();
4074             }
4075 
4076             public Dimension getSecurityWarningSize(Window window) {
4077                 return new Dimension(window.securityWarningWidth,
4078                         window.securityWarningHeight);
4079             }
4080 
4081             public void setSecurityWarningSize(Window window, int width, int height)
4082             {
4083                 window.securityWarningWidth = width;
4084                 window.securityWarningHeight = height;
4085             }
4086 
4087             public void setSecurityWarningPosition(Window window,
4088                     Point2D point, float alignmentX, float alignmentY)
4089             {
4090                 window.securityWarningPointX = point.getX();
4091                 window.securityWarningPointY = point.getY();
4092                 window.securityWarningAlignmentX = alignmentX;
4093                 window.securityWarningAlignmentY = alignmentY;
4094 
4095                 synchronized (window.getTreeLock()) {
4096                     WindowPeer peer = (WindowPeer) window.peer;
4097                     if (peer != null) {
4098                         peer.repositionSecurityWarning();
4099                     }
4100                 }
4101             }
4102 
4103             public Point2D calculateSecurityWarningPosition(Window window,
4104                     double x, double y, double w, double h)
4105             {
4106                 return window.calculateSecurityWarningPosition(x, y, w, h);
4107             }
4108 
4109             public void setLWRequestStatus(Window changed, boolean status) {
4110                 changed.syncLWRequests = status;
4111             }
4112 
4113             public boolean isAutoRequestFocus(Window w) {
4114                 return w.autoRequestFocus;
4115             }
4116 
4117             public boolean isTrayIconWindow(Window w) {
4118                 return w.isTrayIconWindow;
4119             }
4120 
4121             public void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
4122                 w.isTrayIconWindow = isTrayIconWindow;
4123             }
4124         }); // WindowAccessor
4125     } // static
4126 
4127     // a window doesn't need to be updated in the Z-order.
4128     @Override
4129     void updateZOrder() {}
4130 
4131     /**
4132      * Enables the synchronous focus requests on lightweight components in this window
4133      * if {@code true} is specified and the system property
4134      * {@code awt.enableSyncLWFocus} is set. Reverts to the asynchronous focus requests
4135      * if the specified value is {@code false}.
4136      * By default, all windows use asynchronous lightweight focus requests.
4137      *
4138      * The synchronous lightweight focus requests should only enabled
4139      * if this window will never transfer focus to other heavyweight containers.
4140      * In this case the observable focus behavior is the same as with
4141      * asynchronous requests.
4142      *
4143      * If the window does transfer focus to other
4144      * heavyweight containers and the synchronous lightweight focus requests
4145      * are enabled to it then further focus behavior is unspecified.
4146      *
4147      * @param    enable whether to enable the lightweight focus requests
4148      *
4149      * @see java.awt.Component#isLightweight
4150      * @since 1.9
4151      */
4152     public void setSyncLWFocus(boolean enable) {
4153         syncLWRequests = enable && java.security.AccessController.doPrivileged(
4154                 new GetPropertyAction("awt.enableSyncLWFocus")) != null;
4155     }
4156 
4157 } // class Window
4158 
4159 
4160 /**
4161  * This class is no longer used, but is maintained for Serialization
4162  * backward-compatibility.
4163  */
4164 class FocusManager implements java.io.Serializable {
4165     Container focusRoot;
4166     Component focusOwner;
4167 
4168     /*
4169      * JDK 1.1 serialVersionUID
4170      */
4171     static final long serialVersionUID = 2491878825643557906L;
4172 }