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