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      * @see #show
1079      * @see #dispose
1080      * @deprecated As of JDK version 1.5, replaced by
1081      * {@link #setVisible(boolean)}.
1082      */
1083     @Deprecated
1084     public void hide() {
1085         synchronized(ownedWindowList) {
1086             for (int i = 0; i < ownedWindowList.size(); i++) {
1087                 Window child = ownedWindowList.elementAt(i).get();
1088                 if ((child != null) && child.visible) {
1089                     child.hide();
1090                     child.showWithParent = true;
1091                 }
1092             }
1093         }
1094         if (isModalBlocked()) {
1095             modalBlocker.unblockWindow(this);
1096         }
1097         super.hide();
1098     }
1099 
1100     final void clearMostRecentFocusOwnerOnHide() {
1101         /* do nothing */
1102     }
1103 
1104     /**
1105      * Releases all of the native screen resources used by this
1106      * {@code Window}, its subcomponents, and all of its owned
1107      * children. That is, the resources for these {@code Component}s
1108      * will be destroyed, any memory they consume will be returned to the
1109      * OS, and they will be marked as undisplayable.
1110      * <p>
1111      * The {@code Window} and its subcomponents can be made displayable
1112      * again by rebuilding the native resources with a subsequent call to
1113      * {@code pack} or {@code show}. The states of the recreated
1114      * {@code Window} and its subcomponents will be identical to the
1115      * states of these objects at the point where the {@code Window}
1116      * was disposed (not accounting for additional modifications between
1117      * those actions).
1118      * <p>
1119      * <b>Note</b>: When the last displayable window
1120      * within the Java virtual machine (VM) is disposed of, the VM may
1121      * terminate.  See <a href="doc-files/AWTThreadIssues.html#Autoshutdown">
1122      * AWT Threading Issues</a> for more information.
1123      * @see Component#isDisplayable
1124      * @see #pack
1125      * @see #show
1126      */
1127     public void dispose() {
1128         doDispose();
1129     }
1130 
1131     /*
1132      * Fix for 4872170.
1133      * If dispose() is called on parent then its children have to be disposed as well
1134      * as reported in javadoc. So we need to implement this functionality even if a
1135      * child overrides dispose() in a wrong way without calling super.dispose().
1136      */
1137     void disposeImpl() {
1138         dispose();
1139         if (getPeer() != null) {
1140             doDispose();
1141         }
1142     }
1143 
1144     void doDispose() {
1145     class DisposeAction implements Runnable {
1146         public void run() {
1147             disposing = true;
1148             try {
1149                 // Check if this window is the fullscreen window for the
1150                 // device. Exit the fullscreen mode prior to disposing
1151                 // of the window if that's the case.
1152                 GraphicsDevice gd = getGraphicsConfiguration().getDevice();
1153                 if (gd.getFullScreenWindow() == Window.this) {
1154                     gd.setFullScreenWindow(null);
1155                 }
1156 
1157                 Object[] ownedWindowArray;
1158                 synchronized(ownedWindowList) {
1159                     ownedWindowArray = new Object[ownedWindowList.size()];
1160                     ownedWindowList.copyInto(ownedWindowArray);
1161                 }
1162                 for (int i = 0; i < ownedWindowArray.length; i++) {
1163                     Window child = (Window) (((WeakReference)
1164                                    (ownedWindowArray[i])).get());
1165                     if (child != null) {
1166                         child.disposeImpl();
1167                     }
1168                 }
1169                 hide();
1170                 beforeFirstShow = true;
1171                 removeNotify();
1172                 synchronized (inputContextLock) {
1173                     if (inputContext != null) {
1174                         inputContext.dispose();
1175                         inputContext = null;
1176                     }
1177                 }
1178                 clearCurrentFocusCycleRootOnHide();
1179             } finally {
1180                 disposing = false;
1181             }
1182         }
1183     }
1184         boolean fireWindowClosedEvent = isDisplayable();
1185         DisposeAction action = new DisposeAction();
1186         if (EventQueue.isDispatchThread()) {
1187             action.run();
1188         }
1189         else {
1190             try {
1191                 EventQueue.invokeAndWait(this, action);
1192             }
1193             catch (InterruptedException e) {
1194                 System.err.println("Disposal was interrupted:");
1195                 e.printStackTrace();
1196             }
1197             catch (InvocationTargetException e) {
1198                 System.err.println("Exception during disposal:");
1199                 e.printStackTrace();
1200             }
1201         }
1202         // Execute outside the Runnable because postWindowEvent is
1203         // synchronized on (this). We don't need to synchronize the call
1204         // on the EventQueue anyways.
1205         if (fireWindowClosedEvent) {
1206             postWindowEvent(WindowEvent.WINDOW_CLOSED);
1207         }
1208     }
1209 
1210     /*
1211      * Should only be called while holding the tree lock.
1212      * It's overridden here because parent == owner in Window,
1213      * and we shouldn't adjust counter on owner
1214      */
1215     void adjustListeningChildrenOnParent(long mask, int num) {
1216     }
1217 
1218     // Should only be called while holding tree lock
1219     void adjustDecendantsOnParent(int num) {
1220         // do nothing since parent == owner and we shouldn't
1221         // ajust counter on owner
1222     }
1223 
1224     /**
1225      * If this Window is visible, brings this Window to the front and may make
1226      * it the focused Window.
1227      * <p>
1228      * Places this Window at the top of the stacking order and shows it in
1229      * front of any other Windows in this VM. No action will take place if this
1230      * Window is not visible. Some platforms do not allow Windows which own
1231      * other Windows to appear on top of those owned Windows. Some platforms
1232      * may not permit this VM to place its Windows above windows of native
1233      * applications, or Windows of other VMs. This permission may depend on
1234      * whether a Window in this VM is already focused. Every attempt will be
1235      * made to move this Window as high as possible in the stacking order;
1236      * however, developers should not assume that this method will move this
1237      * Window above all other windows in every situation.
1238      * <p>
1239      * Developers must never assume that this Window is the focused or active
1240      * Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED
1241      * event. On platforms where the top-most window is the focused window, this
1242      * method will <b>probably</b> focus this Window (if it is not already focused)
1243      * under the following conditions:
1244      * <ul>
1245      * <li> The window meets the requirements outlined in the
1246      *      {@link #isFocusableWindow} method.
1247      * <li> The window's property {@code autoRequestFocus} is of the
1248      *      {@code true} value.
1249      * <li> Native windowing system allows the window to get focused.
1250      * </ul>
1251      * On platforms where the stacking order does not typically affect the focused
1252      * window, this method will <b>probably</b> leave the focused and active
1253      * Windows unchanged.
1254      * <p>
1255      * If this method causes this Window to be focused, and this Window is a
1256      * Frame or a Dialog, it will also become activated. If this Window is
1257      * focused, but it is not a Frame or a Dialog, then the first Frame or
1258      * Dialog that is an owner of this Window will be activated.
1259      * <p>
1260      * If this window is blocked by modal dialog, then the blocking dialog
1261      * is brought to the front and remains above the blocked window.
1262      *
1263      * @see       #toBack
1264      * @see       #setAutoRequestFocus
1265      * @see       #isFocusableWindow
1266      */
1267     public void toFront() {
1268         toFront_NoClientCode();
1269     }
1270 
1271     // This functionality is implemented in a final package-private method
1272     // to insure that it cannot be overridden by client subclasses.
1273     final void toFront_NoClientCode() {
1274         if (visible) {
1275             WindowPeer peer = (WindowPeer)this.peer;
1276             if (peer != null) {
1277                 peer.toFront();
1278             }
1279             if (isModalBlocked()) {
1280                 modalBlocker.toFront_NoClientCode();
1281             }
1282         }
1283     }
1284 
1285     /**
1286      * If this Window is visible, sends this Window to the back and may cause
1287      * it to lose focus or activation if it is the focused or active Window.
1288      * <p>
1289      * Places this Window at the bottom of the stacking order and shows it
1290      * behind any other Windows in this VM. No action will take place is this
1291      * Window is not visible. Some platforms do not allow Windows which are
1292      * owned by other Windows to appear below their owners. Every attempt will
1293      * be made to move this Window as low as possible in the stacking order;
1294      * however, developers should not assume that this method will move this
1295      * Window below all other windows in every situation.
1296      * <p>
1297      * Because of variations in native windowing systems, no guarantees about
1298      * changes to the focused and active Windows can be made. Developers must
1299      * never assume that this Window is no longer the focused or active Window
1300      * until this Window receives a WINDOW_LOST_FOCUS or WINDOW_DEACTIVATED
1301      * event. On platforms where the top-most window is the focused window,
1302      * this method will <b>probably</b> cause this Window to lose focus. In
1303      * that case, the next highest, focusable Window in this VM will receive
1304      * focus. On platforms where the stacking order does not typically affect
1305      * the focused window, this method will <b>probably</b> leave the focused
1306      * and active Windows unchanged.
1307      *
1308      * @see       #toFront
1309      */
1310     public void toBack() {
1311         toBack_NoClientCode();
1312     }
1313 
1314     // This functionality is implemented in a final package-private method
1315     // to insure that it cannot be overridden by client subclasses.
1316     final void toBack_NoClientCode() {
1317         if(isAlwaysOnTop()) {
1318             try {
1319                 setAlwaysOnTop(false);
1320             }catch(SecurityException e) {
1321             }
1322         }
1323         if (visible) {
1324             WindowPeer peer = (WindowPeer)this.peer;
1325             if (peer != null) {
1326                 peer.toBack();
1327             }
1328         }
1329     }
1330 
1331     /**
1332      * Returns the toolkit of this frame.
1333      * @return    the toolkit of this window.
1334      * @see       Toolkit
1335      * @see       Toolkit#getDefaultToolkit
1336      * @see       Component#getToolkit
1337      */
1338     public Toolkit getToolkit() {
1339         return Toolkit.getDefaultToolkit();
1340     }
1341 
1342     /**
1343      * Gets the warning string that is displayed with this window.
1344      * If this window is insecure, the warning string is displayed
1345      * somewhere in the visible area of the window. A window is
1346      * insecure if there is a security manager and the security
1347      * manager denies
1348      * {@code AWTPermission("showWindowWithoutWarningBanner")}.
1349      * <p>
1350      * If the window is secure, then {@code getWarningString}
1351      * returns {@code null}. If the window is insecure, this
1352      * method checks for the system property
1353      * {@code awt.appletWarning}
1354      * and returns the string value of that property.
1355      * @return    the warning string for this window.
1356      */
1357     public final String getWarningString() {
1358         return warningString;
1359     }
1360 
1361     private void setWarningString() {
1362         warningString = null;
1363         SecurityManager sm = System.getSecurityManager();
1364         if (sm != null) {
1365             try {
1366                 sm.checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION);
1367             } catch (SecurityException se) {
1368                 // make sure the privileged action is only
1369                 // for getting the property! We don't want the
1370                 // above checkPermission call to always succeed!
1371                 warningString = AccessController.doPrivileged(
1372                       new GetPropertyAction("awt.appletWarning",
1373                                             "Java Applet Window"));
1374             }
1375         }
1376     }
1377 
1378     /**
1379      * Gets the {@code Locale} object that is associated
1380      * with this window, if the locale has been set.
1381      * If no locale has been set, then the default locale
1382      * is returned.
1383      * @return    the locale that is set for this window.
1384      * @see       java.util.Locale
1385      * @since     JDK1.1
1386      */
1387     public Locale getLocale() {
1388       if (this.locale == null) {
1389         return Locale.getDefault();
1390       }
1391       return this.locale;
1392     }
1393 
1394     /**
1395      * Gets the input context for this window. A window always has an input context,
1396      * which is shared by subcomponents unless they create and set their own.
1397      * @see Component#getInputContext
1398      * @since 1.2
1399      */
1400     public InputContext getInputContext() {
1401         synchronized (inputContextLock) {
1402             if (inputContext == null) {
1403                 inputContext = InputContext.getInstance();
1404             }
1405         }
1406         return inputContext;
1407     }
1408 
1409     /**
1410      * Set the cursor image to a specified cursor.
1411      * <p>
1412      * The method may have no visual effect if the Java platform
1413      * implementation and/or the native system do not support
1414      * changing the mouse cursor shape.
1415      * @param     cursor One of the constants defined
1416      *            by the {@code Cursor} class. If this parameter is null
1417      *            then the cursor for this window will be set to the type
1418      *            Cursor.DEFAULT_CURSOR.
1419      * @see       Component#getCursor
1420      * @see       Cursor
1421      * @since     JDK1.1
1422      */
1423     public void setCursor(Cursor cursor) {
1424         if (cursor == null) {
1425             cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
1426         }
1427         super.setCursor(cursor);
1428     }
1429 
1430     /**
1431      * Returns the owner of this window.
1432      * @since 1.2
1433      */
1434     public Window getOwner() {
1435         return getOwner_NoClientCode();
1436     }
1437     final Window getOwner_NoClientCode() {
1438         return (Window)parent;
1439     }
1440 
1441     /**
1442      * Return an array containing all the windows this
1443      * window currently owns.
1444      * @since 1.2
1445      */
1446     public Window[] getOwnedWindows() {
1447         return getOwnedWindows_NoClientCode();
1448     }
1449     final Window[] getOwnedWindows_NoClientCode() {
1450         Window realCopy[];
1451 
1452         synchronized(ownedWindowList) {
1453             // Recall that ownedWindowList is actually a Vector of
1454             // WeakReferences and calling get() on one of these references
1455             // may return null. Make two arrays-- one the size of the
1456             // Vector (fullCopy with size fullSize), and one the size of
1457             // all non-null get()s (realCopy with size realSize).
1458             int fullSize = ownedWindowList.size();
1459             int realSize = 0;
1460             Window fullCopy[] = new Window[fullSize];
1461 
1462             for (int i = 0; i < fullSize; i++) {
1463                 fullCopy[realSize] = ownedWindowList.elementAt(i).get();
1464 
1465                 if (fullCopy[realSize] != null) {
1466                     realSize++;
1467                 }
1468             }
1469 
1470             if (fullSize != realSize) {
1471                 realCopy = Arrays.copyOf(fullCopy, realSize);
1472             } else {
1473                 realCopy = fullCopy;
1474             }
1475         }
1476 
1477         return realCopy;
1478     }
1479 
1480     boolean isModalBlocked() {
1481         return modalBlocker != null;
1482     }
1483 
1484     void setModalBlocked(Dialog blocker, boolean blocked, boolean peerCall) {
1485         this.modalBlocker = blocked ? blocker : null;
1486         if (peerCall) {
1487             WindowPeer peer = (WindowPeer)this.peer;
1488             if (peer != null) {
1489                 peer.setModalBlocked(blocker, blocked);
1490             }
1491         }
1492     }
1493 
1494     Dialog getModalBlocker() {
1495         return modalBlocker;
1496     }
1497 
1498     /*
1499      * Returns a list of all displayable Windows, i. e. all the
1500      * Windows which peer is not null.
1501      *
1502      * @see #addNotify
1503      * @see #removeNotify
1504      */
1505     static IdentityArrayList<Window> getAllWindows() {
1506         synchronized (allWindows) {
1507             IdentityArrayList<Window> v = new IdentityArrayList<Window>();
1508             v.addAll(allWindows);
1509             return v;
1510         }
1511     }
1512 
1513     static IdentityArrayList<Window> getAllUnblockedWindows() {
1514         synchronized (allWindows) {
1515             IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>();
1516             for (int i = 0; i < allWindows.size(); i++) {
1517                 Window w = allWindows.get(i);
1518                 if (!w.isModalBlocked()) {
1519                     unblocked.add(w);
1520                 }
1521             }
1522             return unblocked;
1523         }
1524     }
1525 
1526     private static Window[] getWindows(AppContext appContext) {
1527         synchronized (Window.class) {
1528             Window realCopy[];
1529             @SuppressWarnings("unchecked")
1530             Vector<WeakReference<Window>> windowList =
1531                 (Vector<WeakReference<Window>>)appContext.get(Window.class);
1532             if (windowList != null) {
1533                 int fullSize = windowList.size();
1534                 int realSize = 0;
1535                 Window fullCopy[] = new Window[fullSize];
1536                 for (int i = 0; i < fullSize; i++) {
1537                     Window w = windowList.get(i).get();
1538                     if (w != null) {
1539                         fullCopy[realSize++] = w;
1540                     }
1541                 }
1542                 if (fullSize != realSize) {
1543                     realCopy = Arrays.copyOf(fullCopy, realSize);
1544                 } else {
1545                     realCopy = fullCopy;
1546                 }
1547             } else {
1548                 realCopy = new Window[0];
1549             }
1550             return realCopy;
1551         }
1552     }
1553 
1554     /**
1555      * Returns an array of all {@code Window}s, both owned and ownerless,
1556      * created by this application.
1557      * If called from an applet, the array includes only the {@code Window}s
1558      * accessible by that applet.
1559      * <p>
1560      * <b>Warning:</b> this method may return system created windows, such
1561      * as a print dialog. Applications should not assume the existence of
1562      * these dialogs, nor should an application assume anything about these
1563      * dialogs such as component positions, {@code LayoutManager}s
1564      * or serialization.
1565      *
1566      * @see Frame#getFrames
1567      * @see Window#getOwnerlessWindows
1568      *
1569      * @since 1.6
1570      */
1571     public static Window[] getWindows() {
1572         return getWindows(AppContext.getAppContext());
1573     }
1574 
1575     /**
1576      * Returns an array of all {@code Window}s created by this application
1577      * that have no owner. They include {@code Frame}s and ownerless
1578      * {@code Dialog}s and {@code Window}s.
1579      * If called from an applet, the array includes only the {@code Window}s
1580      * accessible by that applet.
1581      * <p>
1582      * <b>Warning:</b> this method may return system created windows, such
1583      * as a print dialog. Applications should not assume the existence of
1584      * these dialogs, nor should an application assume anything about these
1585      * dialogs such as component positions, {@code LayoutManager}s
1586      * or serialization.
1587      *
1588      * @see Frame#getFrames
1589      * @see Window#getWindows()
1590      *
1591      * @since 1.6
1592      */
1593     public static Window[] getOwnerlessWindows() {
1594         Window[] allWindows = Window.getWindows();
1595 
1596         int ownerlessCount = 0;
1597         for (Window w : allWindows) {
1598             if (w.getOwner() == null) {
1599                 ownerlessCount++;
1600             }
1601         }
1602 
1603         Window[] ownerless = new Window[ownerlessCount];
1604         int c = 0;
1605         for (Window w : allWindows) {
1606             if (w.getOwner() == null) {
1607                 ownerless[c++] = w;
1608             }
1609         }
1610 
1611         return ownerless;
1612     }
1613 
1614     Window getDocumentRoot() {
1615         synchronized (getTreeLock()) {
1616             Window w = this;
1617             while (w.getOwner() != null) {
1618                 w = w.getOwner();
1619             }
1620             return w;
1621         }
1622     }
1623 
1624     /**
1625      * Specifies the modal exclusion type for this window. If a window is modal
1626      * excluded, it is not blocked by some modal dialogs. See {@link
1627      * java.awt.Dialog.ModalExclusionType Dialog.ModalExclusionType} for
1628      * possible modal exclusion types.
1629      * <p>
1630      * If the given type is not supported, {@code NO_EXCLUDE} is used.
1631      * <p>
1632      * Note: changing the modal exclusion type for a visible window may have no
1633      * effect until it is hidden and then shown again.
1634      *
1635      * @param exclusionType the modal exclusion type for this window; a {@code null}
1636      *     value is equivivalent to {@link Dialog.ModalExclusionType#NO_EXCLUDE
1637      *     NO_EXCLUDE}
1638      * @throws SecurityException if the calling thread does not have permission
1639      *     to set the modal exclusion property to the window with the given
1640      *     {@code exclusionType}
1641      * @see java.awt.Dialog.ModalExclusionType
1642      * @see java.awt.Window#getModalExclusionType
1643      * @see java.awt.Toolkit#isModalExclusionTypeSupported
1644      *
1645      * @since 1.6
1646      */
1647     public void setModalExclusionType(Dialog.ModalExclusionType exclusionType) {
1648         if (exclusionType == null) {
1649             exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
1650         }
1651         if (!Toolkit.getDefaultToolkit().isModalExclusionTypeSupported(exclusionType)) {
1652             exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
1653         }
1654         if (modalExclusionType == exclusionType) {
1655             return;
1656         }
1657         if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
1658             SecurityManager sm = System.getSecurityManager();
1659             if (sm != null) {
1660                 sm.checkPermission(SecurityConstants.AWT.TOOLKIT_MODALITY_PERMISSION);
1661             }
1662         }
1663         modalExclusionType = exclusionType;
1664 
1665         // if we want on-fly changes, we need to uncomment the lines below
1666         //   and override the method in Dialog to use modalShow() instead
1667         //   of updateChildrenBlocking()
1668  /*
1669         if (isModalBlocked()) {
1670             modalBlocker.unblockWindow(this);
1671         }
1672         Dialog.checkShouldBeBlocked(this);
1673         updateChildrenBlocking();
1674  */
1675     }
1676 
1677     /**
1678      * Returns the modal exclusion type of this window.
1679      *
1680      * @return the modal exclusion type of this window
1681      *
1682      * @see java.awt.Dialog.ModalExclusionType
1683      * @see java.awt.Window#setModalExclusionType
1684      *
1685      * @since 1.6
1686      */
1687     public Dialog.ModalExclusionType getModalExclusionType() {
1688         return modalExclusionType;
1689     }
1690 
1691     boolean isModalExcluded(Dialog.ModalExclusionType exclusionType) {
1692         if ((modalExclusionType != null) &&
1693             modalExclusionType.compareTo(exclusionType) >= 0)
1694         {
1695             return true;
1696         }
1697         Window owner = getOwner_NoClientCode();
1698         return (owner != null) && owner.isModalExcluded(exclusionType);
1699     }
1700 
1701     void updateChildrenBlocking() {
1702         Vector<Window> childHierarchy = new Vector<Window>();
1703         Window[] ownedWindows = getOwnedWindows();
1704         for (int i = 0; i < ownedWindows.length; i++) {
1705             childHierarchy.add(ownedWindows[i]);
1706         }
1707         int k = 0;
1708         while (k < childHierarchy.size()) {
1709             Window w = childHierarchy.get(k);
1710             if (w.isVisible()) {
1711                 if (w.isModalBlocked()) {
1712                     Dialog blocker = w.getModalBlocker();
1713                     blocker.unblockWindow(w);
1714                 }
1715                 Dialog.checkShouldBeBlocked(w);
1716                 Window[] wOwned = w.getOwnedWindows();
1717                 for (int j = 0; j < wOwned.length; j++) {
1718                     childHierarchy.add(wOwned[j]);
1719                 }
1720             }
1721             k++;
1722         }
1723     }
1724 
1725     /**
1726      * Adds the specified window listener to receive window events from
1727      * this window.
1728      * If l is null, no exception is thrown and no action is performed.
1729      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1730      * >AWT Threading Issues</a> for details on AWT's threading model.
1731      *
1732      * @param   l the window listener
1733      * @see #removeWindowListener
1734      * @see #getWindowListeners
1735      */
1736     public synchronized void addWindowListener(WindowListener l) {
1737         if (l == null) {
1738             return;
1739         }
1740         newEventsOnly = true;
1741         windowListener = AWTEventMulticaster.add(windowListener, l);
1742     }
1743 
1744     /**
1745      * Adds the specified window state listener to receive window
1746      * events from this window.  If {@code l} is {@code null},
1747      * no exception is thrown and no action is performed.
1748      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1749      * >AWT Threading Issues</a> for details on AWT's threading model.
1750      *
1751      * @param   l the window state listener
1752      * @see #removeWindowStateListener
1753      * @see #getWindowStateListeners
1754      * @since 1.4
1755      */
1756     public synchronized void addWindowStateListener(WindowStateListener l) {
1757         if (l == null) {
1758             return;
1759         }
1760         windowStateListener = AWTEventMulticaster.add(windowStateListener, l);
1761         newEventsOnly = true;
1762     }
1763 
1764     /**
1765      * Adds the specified window focus listener to receive window events
1766      * from this window.
1767      * If l is null, no exception is thrown and no action is performed.
1768      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1769      * >AWT Threading Issues</a> for details on AWT's threading model.
1770      *
1771      * @param   l the window focus listener
1772      * @see #removeWindowFocusListener
1773      * @see #getWindowFocusListeners
1774      * @since 1.4
1775      */
1776     public synchronized void addWindowFocusListener(WindowFocusListener l) {
1777         if (l == null) {
1778             return;
1779         }
1780         windowFocusListener = AWTEventMulticaster.add(windowFocusListener, l);
1781         newEventsOnly = true;
1782     }
1783 
1784     /**
1785      * Removes the specified window listener so that it no longer
1786      * receives window events from this window.
1787      * If l is null, no exception is thrown and no action is performed.
1788      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1789      * >AWT Threading Issues</a> for details on AWT's threading model.
1790      *
1791      * @param   l the window listener
1792      * @see #addWindowListener
1793      * @see #getWindowListeners
1794      */
1795     public synchronized void removeWindowListener(WindowListener l) {
1796         if (l == null) {
1797             return;
1798         }
1799         windowListener = AWTEventMulticaster.remove(windowListener, l);
1800     }
1801 
1802     /**
1803      * Removes the specified window state listener so that it no
1804      * longer receives window events from this window.  If
1805      * {@code l} is {@code null}, no exception is thrown and
1806      * no action is performed.
1807      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1808      * >AWT Threading Issues</a> for details on AWT's threading model.
1809      *
1810      * @param   l the window state listener
1811      * @see #addWindowStateListener
1812      * @see #getWindowStateListeners
1813      * @since 1.4
1814      */
1815     public synchronized void removeWindowStateListener(WindowStateListener l) {
1816         if (l == null) {
1817             return;
1818         }
1819         windowStateListener = AWTEventMulticaster.remove(windowStateListener, l);
1820     }
1821 
1822     /**
1823      * Removes the specified window focus listener so that it no longer
1824      * receives window events from this window.
1825      * If l is null, no exception is thrown and no action is performed.
1826      * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads"
1827      * >AWT Threading Issues</a> for details on AWT's threading model.
1828      *
1829      * @param   l the window focus listener
1830      * @see #addWindowFocusListener
1831      * @see #getWindowFocusListeners
1832      * @since 1.4
1833      */
1834     public synchronized void removeWindowFocusListener(WindowFocusListener l) {
1835         if (l == null) {
1836             return;
1837         }
1838         windowFocusListener = AWTEventMulticaster.remove(windowFocusListener, l);
1839     }
1840 
1841     /**
1842      * Returns an array of all the window listeners
1843      * registered on this window.
1844      *
1845      * @return all of this window's {@code WindowListener}s
1846      *         or an empty array if no window
1847      *         listeners are currently registered
1848      *
1849      * @see #addWindowListener
1850      * @see #removeWindowListener
1851      * @since 1.4
1852      */
1853     public synchronized WindowListener[] getWindowListeners() {
1854         return getListeners(WindowListener.class);
1855     }
1856 
1857     /**
1858      * Returns an array of all the window focus listeners
1859      * registered on this window.
1860      *
1861      * @return all of this window's {@code WindowFocusListener}s
1862      *         or an empty array if no window focus
1863      *         listeners are currently registered
1864      *
1865      * @see #addWindowFocusListener
1866      * @see #removeWindowFocusListener
1867      * @since 1.4
1868      */
1869     public synchronized WindowFocusListener[] getWindowFocusListeners() {
1870         return getListeners(WindowFocusListener.class);
1871     }
1872 
1873     /**
1874      * Returns an array of all the window state listeners
1875      * registered on this window.
1876      *
1877      * @return all of this window's {@code WindowStateListener}s
1878      *         or an empty array if no window state
1879      *         listeners are currently registered
1880      *
1881      * @see #addWindowStateListener
1882      * @see #removeWindowStateListener
1883      * @since 1.4
1884      */
1885     public synchronized WindowStateListener[] getWindowStateListeners() {
1886         return getListeners(WindowStateListener.class);
1887     }
1888 
1889 
1890     /**
1891      * Returns an array of all the objects currently registered
1892      * as <code><em>Foo</em>Listener</code>s
1893      * upon this {@code Window}.
1894      * <code><em>Foo</em>Listener</code>s are registered using the
1895      * <code>add<em>Foo</em>Listener</code> method.
1896      *
1897      * <p>
1898      *
1899      * You can specify the {@code listenerType} argument
1900      * with a class literal, such as
1901      * <code><em>Foo</em>Listener.class</code>.
1902      * For example, you can query a
1903      * {@code Window} {@code w}
1904      * for its window listeners with the following code:
1905      *
1906      * <pre>WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));</pre>
1907      *
1908      * If no such listeners exist, this method returns an empty array.
1909      *
1910      * @param listenerType the type of listeners requested; this parameter
1911      *          should specify an interface that descends from
1912      *          {@code java.util.EventListener}
1913      * @return an array of all objects registered as
1914      *          <code><em>Foo</em>Listener</code>s on this window,
1915      *          or an empty array if no such
1916      *          listeners have been added
1917      * @exception ClassCastException if {@code listenerType}
1918      *          doesn't specify a class or interface that implements
1919      *          {@code java.util.EventListener}
1920      * @exception NullPointerException if {@code listenerType} is {@code null}
1921      *
1922      * @see #getWindowListeners
1923      * @since 1.3
1924      */
1925     public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
1926         EventListener l = null;
1927         if (listenerType == WindowFocusListener.class) {
1928             l = windowFocusListener;
1929         } else if (listenerType == WindowStateListener.class) {
1930             l = windowStateListener;
1931         } else if (listenerType == WindowListener.class) {
1932             l = windowListener;
1933         } else {
1934             return super.getListeners(listenerType);
1935         }
1936         return AWTEventMulticaster.getListeners(l, listenerType);
1937     }
1938 
1939     // REMIND: remove when filtering is handled at lower level
1940     boolean eventEnabled(AWTEvent e) {
1941         switch(e.id) {
1942           case WindowEvent.WINDOW_OPENED:
1943           case WindowEvent.WINDOW_CLOSING:
1944           case WindowEvent.WINDOW_CLOSED:
1945           case WindowEvent.WINDOW_ICONIFIED:
1946           case WindowEvent.WINDOW_DEICONIFIED:
1947           case WindowEvent.WINDOW_ACTIVATED:
1948           case WindowEvent.WINDOW_DEACTIVATED:
1949             if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 ||
1950                 windowListener != null) {
1951                 return true;
1952             }
1953             return false;
1954           case WindowEvent.WINDOW_GAINED_FOCUS:
1955           case WindowEvent.WINDOW_LOST_FOCUS:
1956             if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 ||
1957                 windowFocusListener != null) {
1958                 return true;
1959             }
1960             return false;
1961           case WindowEvent.WINDOW_STATE_CHANGED:
1962             if ((eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 ||
1963                 windowStateListener != null) {
1964                 return true;
1965             }
1966             return false;
1967           default:
1968             break;
1969         }
1970         return super.eventEnabled(e);
1971     }
1972 
1973     /**
1974      * Processes events on this window. If the event is an
1975      * {@code WindowEvent}, it invokes the
1976      * {@code processWindowEvent} method, else it invokes its
1977      * superclass's {@code processEvent}.
1978      * <p>Note that if the event parameter is {@code null}
1979      * the behavior is unspecified and may result in an
1980      * exception.
1981      *
1982      * @param e the event
1983      */
1984     protected void processEvent(AWTEvent e) {
1985         if (e instanceof WindowEvent) {
1986             switch (e.getID()) {
1987                 case WindowEvent.WINDOW_OPENED:
1988                 case WindowEvent.WINDOW_CLOSING:
1989                 case WindowEvent.WINDOW_CLOSED:
1990                 case WindowEvent.WINDOW_ICONIFIED:
1991                 case WindowEvent.WINDOW_DEICONIFIED:
1992                 case WindowEvent.WINDOW_ACTIVATED:
1993                 case WindowEvent.WINDOW_DEACTIVATED:
1994                     processWindowEvent((WindowEvent)e);
1995                     break;
1996                 case WindowEvent.WINDOW_GAINED_FOCUS:
1997                 case WindowEvent.WINDOW_LOST_FOCUS:
1998                     processWindowFocusEvent((WindowEvent)e);
1999                     break;
2000                 case WindowEvent.WINDOW_STATE_CHANGED:
2001                     processWindowStateEvent((WindowEvent)e);
2002                     break;
2003             }
2004             return;
2005         }
2006         super.processEvent(e);
2007     }
2008 
2009     /**
2010      * Processes window events occurring on this window by
2011      * dispatching them to any registered WindowListener objects.
2012      * NOTE: This method will not be called unless window events
2013      * are enabled for this component; this happens when one of the
2014      * following occurs:
2015      * <ul>
2016      * <li>A WindowListener object is registered via
2017      *     {@code addWindowListener}
2018      * <li>Window events are enabled via {@code enableEvents}
2019      * </ul>
2020      * <p>Note that if the event parameter is {@code null}
2021      * the behavior is unspecified and may result in an
2022      * exception.
2023      *
2024      * @param e the window event
2025      * @see Component#enableEvents
2026      */
2027     protected void processWindowEvent(WindowEvent e) {
2028         WindowListener listener = windowListener;
2029         if (listener != null) {
2030             switch(e.getID()) {
2031                 case WindowEvent.WINDOW_OPENED:
2032                     listener.windowOpened(e);
2033                     break;
2034                 case WindowEvent.WINDOW_CLOSING:
2035                     listener.windowClosing(e);
2036                     break;
2037                 case WindowEvent.WINDOW_CLOSED:
2038                     listener.windowClosed(e);
2039                     break;
2040                 case WindowEvent.WINDOW_ICONIFIED:
2041                     listener.windowIconified(e);
2042                     break;
2043                 case WindowEvent.WINDOW_DEICONIFIED:
2044                     listener.windowDeiconified(e);
2045                     break;
2046                 case WindowEvent.WINDOW_ACTIVATED:
2047                     listener.windowActivated(e);
2048                     break;
2049                 case WindowEvent.WINDOW_DEACTIVATED:
2050                     listener.windowDeactivated(e);
2051                     break;
2052                 default:
2053                     break;
2054             }
2055         }
2056     }
2057 
2058     /**
2059      * Processes window focus event occuring on this window by
2060      * dispatching them to any registered WindowFocusListener objects.
2061      * NOTE: this method will not be called unless window focus events
2062      * are enabled for this window. This happens when one of the
2063      * following occurs:
2064      * <ul>
2065      * <li>a WindowFocusListener is registered via
2066      *     {@code addWindowFocusListener}
2067      * <li>Window focus events are enabled via {@code enableEvents}
2068      * </ul>
2069      * <p>Note that if the event parameter is {@code null}
2070      * the behavior is unspecified and may result in an
2071      * exception.
2072      *
2073      * @param e the window focus event
2074      * @see Component#enableEvents
2075      * @since 1.4
2076      */
2077     protected void processWindowFocusEvent(WindowEvent e) {
2078         WindowFocusListener listener = windowFocusListener;
2079         if (listener != null) {
2080             switch (e.getID()) {
2081                 case WindowEvent.WINDOW_GAINED_FOCUS:
2082                     listener.windowGainedFocus(e);
2083                     break;
2084                 case WindowEvent.WINDOW_LOST_FOCUS:
2085                     listener.windowLostFocus(e);
2086                     break;
2087                 default:
2088                     break;
2089             }
2090         }
2091     }
2092 
2093     /**
2094      * Processes window state event occuring on this window by
2095      * dispatching them to any registered {@code WindowStateListener}
2096      * objects.
2097      * NOTE: this method will not be called unless window state events
2098      * are enabled for this window.  This happens when one of the
2099      * following occurs:
2100      * <ul>
2101      * <li>a {@code WindowStateListener} is registered via
2102      *    {@code addWindowStateListener}
2103      * <li>window state events are enabled via {@code enableEvents}
2104      * </ul>
2105      * <p>Note that if the event parameter is {@code null}
2106      * the behavior is unspecified and may result in an
2107      * exception.
2108      *
2109      * @param e the window state event
2110      * @see java.awt.Component#enableEvents
2111      * @since 1.4
2112      */
2113     protected void processWindowStateEvent(WindowEvent e) {
2114         WindowStateListener listener = windowStateListener;
2115         if (listener != null) {
2116             switch (e.getID()) {
2117                 case WindowEvent.WINDOW_STATE_CHANGED:
2118                     listener.windowStateChanged(e);
2119                     break;
2120                 default:
2121                     break;
2122             }
2123         }
2124     }
2125 
2126     /**
2127      * Implements a debugging hook -- checks to see if
2128      * the user has typed <i>control-shift-F1</i>.  If so,
2129      * the list of child windows is dumped to {@code System.out}.
2130      * @param e  the keyboard event
2131      */
2132     void preProcessKeyEvent(KeyEvent e) {
2133         // Dump the list of child windows to System.out.
2134         if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_F1 &&
2135             e.isControlDown() && e.isShiftDown() &&
2136             e.getID() == KeyEvent.KEY_PRESSED) {
2137             list(System.out, 0);
2138         }
2139     }
2140 
2141     void postProcessKeyEvent(KeyEvent e) {
2142         // Do nothing
2143     }
2144 
2145 
2146     /**
2147      * Sets whether this window should always be above other windows.  If
2148      * there are multiple always-on-top windows, their relative order is
2149      * unspecified and platform dependent.
2150      * <p>
2151      * If some other window is already always-on-top then the
2152      * relative order between these windows is unspecified (depends on
2153      * platform).  No window can be brought to be over the always-on-top
2154      * window except maybe another always-on-top window.
2155      * <p>
2156      * All windows owned by an always-on-top window inherit this state and
2157      * automatically become always-on-top.  If a window ceases to be
2158      * always-on-top, the windows that it owns will no longer be
2159      * always-on-top.  When an always-on-top window is sent {@link #toBack
2160      * toBack}, its always-on-top state is set to {@code false}.
2161      *
2162      * <p> When this method is called on a window with a value of
2163      * {@code true}, and the window is visible and the platform
2164      * supports always-on-top for this window, the window is immediately
2165      * brought forward, "sticking" it in the top-most position. If the
2166      * window isn`t currently visible, this method sets the always-on-top
2167      * state to {@code true} but does not bring the window forward.
2168      * When the window is later shown, it will be always-on-top.
2169      *
2170      * <p> When this method is called on a window with a value of
2171      * {@code false} the always-on-top state is set to normal. The
2172      * window remains in the top-most position but it`s z-order can be
2173      * changed as for any other window.  Calling this method with a value
2174      * of {@code false} on a window that has a normal state has no
2175      * effect.  Setting the always-on-top state to false has no effect on
2176      * the relative z-order of the windows if there are no other
2177      * always-on-top windows.
2178      *
2179      * <p><b>Note</b>: some platforms might not support always-on-top
2180      * windows.  To detect if always-on-top windows are supported by the
2181      * current platform, use {@link Toolkit#isAlwaysOnTopSupported()} and
2182      * {@link Window#isAlwaysOnTopSupported()}.  If always-on-top mode
2183      * isn't supported by the toolkit or for this window, calling this
2184      * method has no effect.
2185      * <p>
2186      * If a SecurityManager is installed, the calling thread must be
2187      * granted the AWTPermission "setWindowAlwaysOnTop" in
2188      * order to set the value of this property. If this
2189      * permission is not granted, this method will throw a
2190      * SecurityException, and the current value of the property will
2191      * be left unchanged.
2192      *
2193      * @param alwaysOnTop true if the window should always be above other
2194      *        windows
2195      * @throws SecurityException if the calling thread does not have
2196      *         permission to set the value of always-on-top property
2197      * @see #isAlwaysOnTop
2198      * @see #toFront
2199      * @see #toBack
2200      * @see AWTPermission
2201      * @see #isAlwaysOnTopSupported
2202      * @see Toolkit#isAlwaysOnTopSupported
2203      * @since 1.5
2204      */
2205     public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException {
2206         SecurityManager security = System.getSecurityManager();
2207         if (security != null) {
2208             security.checkPermission(SecurityConstants.AWT.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
2209         }
2210 
2211         boolean oldAlwaysOnTop;
2212         synchronized(this) {
2213             oldAlwaysOnTop = this.alwaysOnTop;
2214             this.alwaysOnTop = alwaysOnTop;
2215         }
2216         if (oldAlwaysOnTop != alwaysOnTop ) {
2217             if (isAlwaysOnTopSupported()) {
2218                 WindowPeer peer = (WindowPeer)this.peer;
2219                 synchronized(getTreeLock()) {
2220                     if (peer != null) {
2221                         peer.updateAlwaysOnTopState();
2222                     }
2223                 }
2224             }
2225             firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop);
2226         }
2227     }
2228 
2229     /**
2230      * Returns whether the always-on-top mode is supported for this
2231      * window. Some platforms may not support always-on-top windows, some
2232      * may support only some kinds of top-level windows; for example,
2233      * a platform may not support always-on-top modal dialogs.
2234      * @return {@code true}, if the always-on-top mode is
2235      *         supported by the toolkit and for this window,
2236      *         {@code false}, if always-on-top mode is not supported
2237      *         for this window or toolkit doesn't support always-on-top windows.
2238      * @see #setAlwaysOnTop(boolean)
2239      * @see Toolkit#isAlwaysOnTopSupported
2240      * @since 1.6
2241      */
2242     public boolean isAlwaysOnTopSupported() {
2243         return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported();
2244     }
2245 
2246 
2247     /**
2248      * Returns whether this window is an always-on-top window.
2249      * @return {@code true}, if the window is in always-on-top state,
2250      *         {@code false} otherwise
2251      * @see #setAlwaysOnTop
2252      * @since 1.5
2253      */
2254     public final boolean isAlwaysOnTop() {
2255         return alwaysOnTop;
2256     }
2257 
2258 
2259     /**
2260      * Returns the child Component of this Window that has focus if this Window
2261      * is focused; returns null otherwise.
2262      *
2263      * @return the child Component with focus, or null if this Window is not
2264      *         focused
2265      * @see #getMostRecentFocusOwner
2266      * @see #isFocused
2267      */
2268     public Component getFocusOwner() {
2269         return (isFocused())
2270             ? KeyboardFocusManager.getCurrentKeyboardFocusManager().
2271                   getFocusOwner()
2272             : null;
2273     }
2274 
2275     /**
2276      * Returns the child Component of this Window that will receive the focus
2277      * when this Window is focused. If this Window is currently focused, this
2278      * method returns the same Component as {@code getFocusOwner()}. If
2279      * this Window is not focused, then the child Component that most recently
2280      * requested focus will be returned. If no child Component has ever
2281      * requested focus, and this is a focusable Window, then this Window's
2282      * initial focusable Component is returned. If no child Component has ever
2283      * requested focus, and this is a non-focusable Window, null is returned.
2284      *
2285      * @return the child Component that will receive focus when this Window is
2286      *         focused
2287      * @see #getFocusOwner
2288      * @see #isFocused
2289      * @see #isFocusableWindow
2290      * @since 1.4
2291      */
2292     public Component getMostRecentFocusOwner() {
2293         if (isFocused()) {
2294             return getFocusOwner();
2295         } else {
2296             Component mostRecent =
2297                 KeyboardFocusManager.getMostRecentFocusOwner(this);
2298             if (mostRecent != null) {
2299                 return mostRecent;
2300             } else {
2301                 return (isFocusableWindow())
2302                     ? getFocusTraversalPolicy().getInitialComponent(this)
2303                     : null;
2304             }
2305         }
2306     }
2307 
2308     /**
2309      * Returns whether this Window is active. Only a Frame or a Dialog may be
2310      * active. The native windowing system may denote the active Window or its
2311      * children with special decorations, such as a highlighted title bar. The
2312      * active Window is always either the focused Window, or the first Frame or
2313      * Dialog that is an owner of the focused Window.
2314      *
2315      * @return whether this is the active Window.
2316      * @see #isFocused
2317      * @since 1.4
2318      */
2319     public boolean isActive() {
2320         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2321                 getActiveWindow() == this);
2322     }
2323 
2324     /**
2325      * Returns whether this Window is focused. If there exists a focus owner,
2326      * the focused Window is the Window that is, or contains, that focus owner.
2327      * If there is no focus owner, then no Window is focused.
2328      * <p>
2329      * If the focused Window is a Frame or a Dialog it is also the active
2330      * Window. Otherwise, the active Window is the first Frame or Dialog that
2331      * is an owner of the focused Window.
2332      *
2333      * @return whether this is the focused Window.
2334      * @see #isActive
2335      * @since 1.4
2336      */
2337     public boolean isFocused() {
2338         return (KeyboardFocusManager.getCurrentKeyboardFocusManager().
2339                 getGlobalFocusedWindow() == this);
2340     }
2341 
2342     /**
2343      * Gets a focus traversal key for this Window. (See {@code
2344      * setFocusTraversalKeys} for a full description of each key.)
2345      * <p>
2346      * If the traversal key has not been explicitly set for this Window,
2347      * then this Window's parent's traversal key is returned. If the
2348      * traversal key has not been explicitly set for any of this Window's
2349      * ancestors, then the current KeyboardFocusManager's default traversal key
2350      * is returned.
2351      *
2352      * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2353      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2354      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2355      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2356      * @return the AWTKeyStroke for the specified key
2357      * @see Container#setFocusTraversalKeys
2358      * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
2359      * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
2360      * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
2361      * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS
2362      * @throws IllegalArgumentException if id is not one of
2363      *         KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
2364      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
2365      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
2366      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
2367      * @since 1.4
2368      */
2369     @SuppressWarnings("unchecked")
2370     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
2371         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
2372             throw new IllegalArgumentException("invalid focus traversal key identifier");
2373         }
2374 
2375         // Okay to return Set directly because it is an unmodifiable view
2376         @SuppressWarnings("rawtypes")
2377         Set keystrokes = (focusTraversalKeys != null)
2378             ? focusTraversalKeys[id]
2379             : null;
2380 
2381         if (keystrokes != null) {
2382             return keystrokes;
2383         } else {
2384             return KeyboardFocusManager.getCurrentKeyboardFocusManager().
2385                 getDefaultFocusTraversalKeys(id);
2386         }
2387     }
2388 
2389     /**
2390      * Does nothing because Windows must always be roots of a focus traversal
2391      * cycle. The passed-in value is ignored.
2392      *
2393      * @param focusCycleRoot this value is ignored
2394      * @see #isFocusCycleRoot
2395      * @see Container#setFocusTraversalPolicy
2396      * @see Container#getFocusTraversalPolicy
2397      * @since 1.4
2398      */
2399     public final void setFocusCycleRoot(boolean focusCycleRoot) {
2400     }
2401 
2402     /**
2403      * Always returns {@code true} because all Windows must be roots of a
2404      * focus traversal cycle.
2405      *
2406      * @return {@code true}
2407      * @see #setFocusCycleRoot
2408      * @see Container#setFocusTraversalPolicy
2409      * @see Container#getFocusTraversalPolicy
2410      * @since 1.4
2411      */
2412     public final boolean isFocusCycleRoot() {
2413         return true;
2414     }
2415 
2416     /**
2417      * Always returns {@code null} because Windows have no ancestors; they
2418      * represent the top of the Component hierarchy.
2419      *
2420      * @return {@code null}
2421      * @see Container#isFocusCycleRoot()
2422      * @since 1.4
2423      */
2424     public final Container getFocusCycleRootAncestor() {
2425         return null;
2426     }
2427 
2428     /**
2429      * Returns whether this Window can become the focused Window, that is,
2430      * whether this Window or any of its subcomponents can become the focus
2431      * owner. For a Frame or Dialog to be focusable, its focusable Window state
2432      * must be set to {@code true}. For a Window which is not a Frame or
2433      * Dialog to be focusable, its focusable Window state must be set to
2434      * {@code true}, its nearest owning Frame or Dialog must be
2435      * showing on the screen, and it must contain at least one Component in
2436      * its focus traversal cycle. If any of these conditions is not met, then
2437      * neither this Window nor any of its subcomponents can become the focus
2438      * owner.
2439      *
2440      * @return {@code true} if this Window can be the focused Window;
2441      *         {@code false} otherwise
2442      * @see #getFocusableWindowState
2443      * @see #setFocusableWindowState
2444      * @see #isShowing
2445      * @see Component#isFocusable
2446      * @since 1.4
2447      */
2448     public final boolean isFocusableWindow() {
2449         // If a Window/Frame/Dialog was made non-focusable, then it is always
2450         // non-focusable.
2451         if (!getFocusableWindowState()) {
2452             return false;
2453         }
2454 
2455         // All other tests apply only to Windows.
2456         if (this instanceof Frame || this instanceof Dialog) {
2457             return true;
2458         }
2459 
2460         // A Window must have at least one Component in its root focus
2461         // traversal cycle to be focusable.
2462         if (getFocusTraversalPolicy().getDefaultComponent(this) == null) {
2463             return false;
2464         }
2465 
2466         // A Window's nearest owning Frame or Dialog must be showing on the
2467         // screen.
2468         for (Window owner = getOwner(); owner != null;
2469              owner = owner.getOwner())
2470         {
2471             if (owner instanceof Frame || owner instanceof Dialog) {
2472                 return owner.isShowing();
2473             }
2474         }
2475 
2476         return false;
2477     }
2478 
2479     /**
2480      * Returns whether this Window can become the focused Window if it meets
2481      * the other requirements outlined in {@code isFocusableWindow}. If
2482      * this method returns {@code false}, then
2483      * {@code isFocusableWindow} will return {@code false} as well.
2484      * If this method returns {@code true}, then
2485      * {@code isFocusableWindow} may return {@code true} or
2486      * {@code false} depending upon the other requirements which must be
2487      * met in order for a Window to be focusable.
2488      * <p>
2489      * By default, all Windows have a focusable Window state of
2490      * {@code true}.
2491      *
2492      * @return whether this Window can be the focused Window
2493      * @see #isFocusableWindow
2494      * @see #setFocusableWindowState
2495      * @see #isShowing
2496      * @see Component#setFocusable
2497      * @since 1.4
2498      */
2499     public boolean getFocusableWindowState() {
2500         return focusableWindowState;
2501     }
2502 
2503     /**
2504      * Sets whether this Window can become the focused Window if it meets
2505      * the other requirements outlined in {@code isFocusableWindow}. If
2506      * this Window's focusable Window state is set to {@code false}, then
2507      * {@code isFocusableWindow} will return {@code false}. If this
2508      * Window's focusable Window state is set to {@code true}, then
2509      * {@code isFocusableWindow} may return {@code true} or
2510      * {@code false} depending upon the other requirements which must be
2511      * met in order for a Window to be focusable.
2512      * <p>
2513      * Setting a Window's focusability state to {@code false} is the
2514      * standard mechanism for an application to identify to the AWT a Window
2515      * which will be used as a floating palette or toolbar, and thus should be
2516      * a non-focusable Window.
2517      *
2518      * Setting the focusability state on a visible {@code Window}
2519      * can have a delayed effect on some platforms &#151; the actual
2520      * change may happen only when the {@code Window} becomes
2521      * hidden and then visible again.  To ensure consistent behavior
2522      * across platforms, set the {@code Window}'s focusable state
2523      * when the {@code Window} is invisible and then show it.
2524      *
2525      * @param focusableWindowState whether this Window can be the focused
2526      *        Window
2527      * @see #isFocusableWindow
2528      * @see #getFocusableWindowState
2529      * @see #isShowing
2530      * @see Component#setFocusable
2531      * @since 1.4
2532      */
2533     public void setFocusableWindowState(boolean focusableWindowState) {
2534         boolean oldFocusableWindowState;
2535         synchronized (this) {
2536             oldFocusableWindowState = this.focusableWindowState;
2537             this.focusableWindowState = focusableWindowState;
2538         }
2539         WindowPeer peer = (WindowPeer)this.peer;
2540         if (peer != null) {
2541             peer.updateFocusableWindowState();
2542         }
2543         firePropertyChange("focusableWindowState", oldFocusableWindowState,
2544                            focusableWindowState);
2545         if (oldFocusableWindowState && !focusableWindowState && isFocused()) {
2546             for (Window owner = getOwner();
2547                  owner != null;
2548                  owner = owner.getOwner())
2549                 {
2550                     Component toFocus =
2551                         KeyboardFocusManager.getMostRecentFocusOwner(owner);
2552                     if (toFocus != null && toFocus.requestFocus(false, CausedFocusEvent.Cause.ACTIVATION)) {
2553                         return;
2554                     }
2555                 }
2556             KeyboardFocusManager.getCurrentKeyboardFocusManager().
2557                 clearGlobalFocusOwnerPriv();
2558         }
2559     }
2560 
2561     /**
2562      * Sets whether this window should receive focus on
2563      * subsequently being shown (with a call to {@link #setVisible setVisible(true)}),
2564      * or being moved to the front (with a call to {@link #toFront}).
2565      * <p>
2566      * Note that {@link #setVisible setVisible(true)} may be called indirectly
2567      * (e.g. when showing an owner of the window makes the window to be shown).
2568      * {@link #toFront} may also be called indirectly (e.g. when
2569      * {@link #setVisible setVisible(true)} is called on already visible window).
2570      * In all such cases this property takes effect as well.
2571      * <p>
2572      * The value of the property is not inherited by owned windows.
2573      *
2574      * @param autoRequestFocus whether this window should be focused on
2575      *        subsequently being shown or being moved to the front
2576      * @see #isAutoRequestFocus
2577      * @see #isFocusableWindow
2578      * @see #setVisible
2579      * @see #toFront
2580      * @since 1.7
2581      */
2582     public void setAutoRequestFocus(boolean autoRequestFocus) {
2583         this.autoRequestFocus = autoRequestFocus;
2584     }
2585 
2586     /**
2587      * Returns whether this window should receive focus on subsequently being shown
2588      * (with a call to {@link #setVisible setVisible(true)}), or being moved to the front
2589      * (with a call to {@link #toFront}).
2590      * <p>
2591      * By default, the window has {@code autoRequestFocus} value of {@code true}.
2592      *
2593      * @return {@code autoRequestFocus} value
2594      * @see #setAutoRequestFocus
2595      * @since 1.7
2596      */
2597     public boolean isAutoRequestFocus() {
2598         return autoRequestFocus;
2599     }
2600 
2601     /**
2602      * Adds a PropertyChangeListener to the listener list. The listener is
2603      * registered for all bound properties of this class, including the
2604      * following:
2605      * <ul>
2606      *    <li>this Window's font ("font")</li>
2607      *    <li>this Window's background color ("background")</li>
2608      *    <li>this Window's foreground color ("foreground")</li>
2609      *    <li>this Window's focusability ("focusable")</li>
2610      *    <li>this Window's focus traversal keys enabled state
2611      *        ("focusTraversalKeysEnabled")</li>
2612      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2613      *        ("forwardFocusTraversalKeys")</li>
2614      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2615      *        ("backwardFocusTraversalKeys")</li>
2616      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2617      *        ("upCycleFocusTraversalKeys")</li>
2618      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2619      *        ("downCycleFocusTraversalKeys")</li>
2620      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2621      *        </li>
2622      *    <li>this Window's focusable Window state ("focusableWindowState")
2623      *        </li>
2624      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2625      * </ul>
2626      * Note that if this Window is inheriting a bound property, then no
2627      * event will be fired in response to a change in the inherited property.
2628      * <p>
2629      * If listener is null, no exception is thrown and no action is performed.
2630      *
2631      * @param    listener  the PropertyChangeListener to be added
2632      *
2633      * @see Component#removePropertyChangeListener
2634      * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener)
2635      */
2636     public void addPropertyChangeListener(PropertyChangeListener listener) {
2637         super.addPropertyChangeListener(listener);
2638     }
2639 
2640     /**
2641      * Adds a PropertyChangeListener to the listener list for a specific
2642      * property. The specified property may be user-defined, or one of the
2643      * following:
2644      * <ul>
2645      *    <li>this Window's font ("font")</li>
2646      *    <li>this Window's background color ("background")</li>
2647      *    <li>this Window's foreground color ("foreground")</li>
2648      *    <li>this Window's focusability ("focusable")</li>
2649      *    <li>this Window's focus traversal keys enabled state
2650      *        ("focusTraversalKeysEnabled")</li>
2651      *    <li>this Window's Set of FORWARD_TRAVERSAL_KEYS
2652      *        ("forwardFocusTraversalKeys")</li>
2653      *    <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS
2654      *        ("backwardFocusTraversalKeys")</li>
2655      *    <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS
2656      *        ("upCycleFocusTraversalKeys")</li>
2657      *    <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS
2658      *        ("downCycleFocusTraversalKeys")</li>
2659      *    <li>this Window's focus traversal policy ("focusTraversalPolicy")
2660      *        </li>
2661      *    <li>this Window's focusable Window state ("focusableWindowState")
2662      *        </li>
2663      *    <li>this Window's always-on-top state("alwaysOnTop")</li>
2664      * </ul>
2665      * Note that if this Window is inheriting a bound property, then no
2666      * event will be fired in response to a change in the inherited property.
2667      * <p>
2668      * If listener is null, no exception is thrown and no action is performed.
2669      *
2670      * @param propertyName one of the property names listed above
2671      * @param listener the PropertyChangeListener to be added
2672      *
2673      * @see #addPropertyChangeListener(java.beans.PropertyChangeListener)
2674      * @see Component#removePropertyChangeListener
2675      */
2676     public void addPropertyChangeListener(String propertyName,
2677                                           PropertyChangeListener listener) {
2678         super.addPropertyChangeListener(propertyName, listener);
2679     }
2680 
2681     /**
2682      * Indicates if this container is a validate root.
2683      * <p>
2684      * {@code Window} objects are the validate roots, and, therefore, they
2685      * override this method to return {@code true}.
2686      *
2687      * @return {@code true}
2688      * @since 1.7
2689      * @see java.awt.Container#isValidateRoot
2690      */
2691     @Override
2692     public boolean isValidateRoot() {
2693         return true;
2694     }
2695 
2696     /**
2697      * Dispatches an event to this window or one of its sub components.
2698      * @param e the event
2699      */
2700     void dispatchEventImpl(AWTEvent e) {
2701         if (e.getID() == ComponentEvent.COMPONENT_RESIZED) {
2702             invalidate();
2703             validate();
2704         }
2705         super.dispatchEventImpl(e);
2706     }
2707 
2708     /**
2709      * @deprecated As of JDK version 1.1
2710      * replaced by {@code dispatchEvent(AWTEvent)}.
2711      */
2712     @Deprecated
2713     public boolean postEvent(Event e) {
2714         if (handleEvent(e)) {
2715             e.consume();
2716             return true;
2717         }
2718         return false;
2719     }
2720 
2721     /**
2722      * Checks if this Window is showing on screen.
2723      * @see Component#setVisible
2724     */
2725     public boolean isShowing() {
2726         return visible;
2727     }
2728 
2729     boolean isDisposing() {
2730         return disposing;
2731     }
2732 
2733     /**
2734      * @deprecated As of J2SE 1.4, replaced by
2735      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2736      */
2737     @Deprecated
2738     public void applyResourceBundle(ResourceBundle rb) {
2739         applyComponentOrientation(ComponentOrientation.getOrientation(rb));
2740     }
2741 
2742     /**
2743      * @deprecated As of J2SE 1.4, replaced by
2744      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
2745      */
2746     @Deprecated
2747     public void applyResourceBundle(String rbName) {
2748         applyResourceBundle(ResourceBundle.getBundle(rbName));
2749     }
2750 
2751    /*
2752     * Support for tracking all windows owned by this window
2753     */
2754     void addOwnedWindow(WeakReference<Window> weakWindow) {
2755         if (weakWindow != null) {
2756             synchronized(ownedWindowList) {
2757                 // this if statement should really be an assert, but we don't
2758                 // have asserts...
2759                 if (!ownedWindowList.contains(weakWindow)) {
2760                     ownedWindowList.addElement(weakWindow);
2761                 }
2762             }
2763         }
2764     }
2765 
2766     void removeOwnedWindow(WeakReference<Window> weakWindow) {
2767         if (weakWindow != null) {
2768             // synchronized block not required since removeElement is
2769             // already synchronized
2770             ownedWindowList.removeElement(weakWindow);
2771         }
2772     }
2773 
2774     void connectOwnedWindow(Window child) {
2775         child.parent = this;
2776         addOwnedWindow(child.weakThis);
2777     }
2778 
2779     private void addToWindowList() {
2780         synchronized (Window.class) {
2781             @SuppressWarnings("unchecked")
2782             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
2783             if (windowList == null) {
2784                 windowList = new Vector<WeakReference<Window>>();
2785                 appContext.put(Window.class, windowList);
2786             }
2787             windowList.add(weakThis);
2788         }
2789     }
2790 
2791     private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
2792         synchronized (Window.class) {
2793             @SuppressWarnings("unchecked")
2794             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
2795             if (windowList != null) {
2796                 windowList.remove(weakThis);
2797             }
2798         }
2799     }
2800 
2801     private void removeFromWindowList() {
2802         removeFromWindowList(appContext, weakThis);
2803     }
2804 
2805     /**
2806      * Window type.
2807      *
2808      * Synchronization: ObjectLock
2809      */
2810     private Type type = Type.NORMAL;
2811 
2812     /**
2813      * Sets the type of the window.
2814      *
2815      * This method can only be called while the window is not displayable.
2816      *
2817      * @throws IllegalComponentStateException if the window
2818      *         is displayable.
2819      * @throws IllegalArgumentException if the type is {@code null}
2820      * @see    Component#isDisplayable
2821      * @see    #getType
2822      * @since 1.7
2823      */
2824     public void setType(Type type) {
2825         if (type == null) {
2826             throw new IllegalArgumentException("type should not be null.");
2827         }
2828         synchronized (getTreeLock()) {
2829             if (isDisplayable()) {
2830                 throw new IllegalComponentStateException(
2831                         "The window is displayable.");
2832             }
2833             synchronized (getObjectLock()) {
2834                 this.type = type;
2835             }
2836         }
2837     }
2838 
2839     /**
2840      * Returns the type of the window.
2841      *
2842      * @see   #setType
2843      * @since 1.7
2844      */
2845     public Type getType() {
2846         synchronized (getObjectLock()) {
2847             return type;
2848         }
2849     }
2850 
2851     /**
2852      * The window serialized data version.
2853      *
2854      * @serial
2855      */
2856     private int windowSerializedDataVersion = 2;
2857 
2858     /**
2859      * Writes default serializable fields to stream.  Writes
2860      * a list of serializable {@code WindowListener}s and
2861      * {@code WindowFocusListener}s as optional data.
2862      * Writes a list of child windows as optional data.
2863      * Writes a list of icon images as optional data
2864      *
2865      * @param s the {@code ObjectOutputStream} to write
2866      * @serialData {@code null} terminated sequence of
2867      *    0 or more pairs; the pair consists of a {@code String}
2868      *    and {@code Object}; the {@code String}
2869      *    indicates the type of object and is one of the following:
2870      *    {@code windowListenerK} indicating a
2871      *      {@code WindowListener} object;
2872      *    {@code windowFocusWindowK} indicating a
2873      *      {@code WindowFocusListener} object;
2874      *    {@code ownedWindowK} indicating a child
2875      *      {@code Window} object
2876      *
2877      * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener)
2878      * @see Component#windowListenerK
2879      * @see Component#windowFocusListenerK
2880      * @see Component#ownedWindowK
2881      * @see #readObject(ObjectInputStream)
2882      */
2883     private void writeObject(ObjectOutputStream s) throws IOException {
2884         synchronized (this) {
2885             // Update old focusMgr fields so that our object stream can be read
2886             // by previous releases
2887             focusMgr = new FocusManager();
2888             focusMgr.focusRoot = this;
2889             focusMgr.focusOwner = getMostRecentFocusOwner();
2890 
2891             s.defaultWriteObject();
2892 
2893             // Clear fields so that we don't keep extra references around
2894             focusMgr = null;
2895 
2896             AWTEventMulticaster.save(s, windowListenerK, windowListener);
2897             AWTEventMulticaster.save(s, windowFocusListenerK, windowFocusListener);
2898             AWTEventMulticaster.save(s, windowStateListenerK, windowStateListener);
2899         }
2900 
2901         s.writeObject(null);
2902 
2903         synchronized (ownedWindowList) {
2904             for (int i = 0; i < ownedWindowList.size(); i++) {
2905                 Window child = ownedWindowList.elementAt(i).get();
2906                 if (child != null) {
2907                     s.writeObject(ownedWindowK);
2908                     s.writeObject(child);
2909                 }
2910             }
2911         }
2912         s.writeObject(null);
2913 
2914         //write icon array
2915         if (icons != null) {
2916             for (Image i : icons) {
2917                 if (i instanceof Serializable) {
2918                     s.writeObject(i);
2919                 }
2920             }
2921         }
2922         s.writeObject(null);
2923     }
2924 
2925     //
2926     // Part of deserialization procedure to be called before
2927     // user's code.
2928     //
2929     private void initDeserializedWindow() {
2930         setWarningString();
2931         inputContextLock = new Object();
2932 
2933         // Deserialized Windows are not yet visible.
2934         visible = false;
2935 
2936         weakThis = new WeakReference<>(this);
2937 
2938         anchor = new Object();
2939         sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this));
2940 
2941         addToWindowList();
2942         initGC(null);
2943     }
2944 
2945     private void deserializeResources(ObjectInputStream s)
2946         throws ClassNotFoundException, IOException, HeadlessException {
2947             ownedWindowList = new Vector<>();
2948 
2949             if (windowSerializedDataVersion < 2) {
2950                 // Translate old-style focus tracking to new model. For 1.4 and
2951                 // later releases, we'll rely on the Window's initial focusable
2952                 // Component.
2953                 if (focusMgr != null) {
2954                     if (focusMgr.focusOwner != null) {
2955                         KeyboardFocusManager.
2956                             setMostRecentFocusOwner(this, focusMgr.focusOwner);
2957                     }
2958                 }
2959 
2960                 // This field is non-transient and relies on default serialization.
2961                 // However, the default value is insufficient, so we need to set
2962                 // it explicitly for object data streams prior to 1.4.
2963                 focusableWindowState = true;
2964 
2965 
2966             }
2967 
2968         Object keyOrNull;
2969         while(null != (keyOrNull = s.readObject())) {
2970             String key = ((String)keyOrNull).intern();
2971 
2972             if (windowListenerK == key) {
2973                 addWindowListener((WindowListener)(s.readObject()));
2974             } else if (windowFocusListenerK == key) {
2975                 addWindowFocusListener((WindowFocusListener)(s.readObject()));
2976             } else if (windowStateListenerK == key) {
2977                 addWindowStateListener((WindowStateListener)(s.readObject()));
2978             } else // skip value for unrecognized key
2979                 s.readObject();
2980         }
2981 
2982         try {
2983             while (null != (keyOrNull = s.readObject())) {
2984                 String key = ((String)keyOrNull).intern();
2985 
2986                 if (ownedWindowK == key)
2987                     connectOwnedWindow((Window) s.readObject());
2988 
2989                 else // skip value for unrecognized key
2990                     s.readObject();
2991             }
2992 
2993             //read icons
2994             Object obj = s.readObject(); //Throws OptionalDataException
2995                                          //for pre1.6 objects.
2996             icons = new ArrayList<Image>(); //Frame.readObject() assumes
2997                                             //pre1.6 version if icons is null.
2998             while (obj != null) {
2999                 if (obj instanceof Image) {
3000                     icons.add((Image)obj);
3001                 }
3002                 obj = s.readObject();
3003             }
3004         }
3005         catch (OptionalDataException e) {
3006             // 1.1 serialized form
3007             // ownedWindowList will be updated by Frame.readObject
3008         }
3009 
3010     }
3011 
3012     /**
3013      * Reads the {@code ObjectInputStream} and an optional
3014      * list of listeners to receive various events fired by
3015      * the component; also reads a list of
3016      * (possibly {@code null}) child windows.
3017      * Unrecognized keys or values will be ignored.
3018      *
3019      * @param s the {@code ObjectInputStream} to read
3020      * @exception HeadlessException if
3021      *   {@code GraphicsEnvironment.isHeadless} returns
3022      *   {@code true}
3023      * @see java.awt.GraphicsEnvironment#isHeadless
3024      * @see #writeObject
3025      */
3026     private void readObject(ObjectInputStream s)
3027       throws ClassNotFoundException, IOException, HeadlessException
3028     {
3029          GraphicsEnvironment.checkHeadless();
3030          initDeserializedWindow();
3031          ObjectInputStream.GetField f = s.readFields();
3032 
3033          syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests);
3034          state = f.get("state", 0);
3035          focusableWindowState = f.get("focusableWindowState", true);
3036          windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1);
3037          locationByPlatform = f.get("locationByPlatform", locationByPlatformProp);
3038          // Note: 1.4 (or later) doesn't use focusMgr
3039          focusMgr = (FocusManager)f.get("focusMgr", null);
3040          Dialog.ModalExclusionType et = (Dialog.ModalExclusionType)
3041              f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE);
3042          setModalExclusionType(et); // since 6.0
3043          boolean aot = f.get("alwaysOnTop", false);
3044          if(aot) {
3045              setAlwaysOnTop(aot); // since 1.5; subject to permission check
3046          }
3047          shape = (Shape)f.get("shape", null);
3048          opacity = (Float)f.get("opacity", 1.0f);
3049 
3050          this.securityWarningWidth = 0;
3051          this.securityWarningHeight = 0;
3052          this.securityWarningPointX = 2.0;
3053          this.securityWarningPointY = 0.0;
3054          this.securityWarningAlignmentX = RIGHT_ALIGNMENT;
3055          this.securityWarningAlignmentY = TOP_ALIGNMENT;
3056 
3057          deserializeResources(s);
3058     }
3059 
3060     /*
3061      * --- Accessibility Support ---
3062      *
3063      */
3064 
3065     /**
3066      * Gets the AccessibleContext associated with this Window.
3067      * For windows, the AccessibleContext takes the form of an
3068      * AccessibleAWTWindow.
3069      * A new AccessibleAWTWindow instance is created if necessary.
3070      *
3071      * @return an AccessibleAWTWindow that serves as the
3072      *         AccessibleContext of this Window
3073      * @since 1.3
3074      */
3075     public AccessibleContext getAccessibleContext() {
3076         if (accessibleContext == null) {
3077             accessibleContext = new AccessibleAWTWindow();
3078         }
3079         return accessibleContext;
3080     }
3081 
3082     /**
3083      * This class implements accessibility support for the
3084      * {@code Window} class.  It provides an implementation of the
3085      * Java Accessibility API appropriate to window user-interface elements.
3086      * @since 1.3
3087      */
3088     protected class AccessibleAWTWindow extends AccessibleAWTContainer
3089     {
3090         /*
3091          * JDK 1.3 serialVersionUID
3092          */
3093         private static final long serialVersionUID = 4215068635060671780L;
3094 
3095         /**
3096          * Get the role of this object.
3097          *
3098          * @return an instance of AccessibleRole describing the role of the
3099          * object
3100          * @see javax.accessibility.AccessibleRole
3101          */
3102         public AccessibleRole getAccessibleRole() {
3103             return AccessibleRole.WINDOW;
3104         }
3105 
3106         /**
3107          * Get the state of this object.
3108          *
3109          * @return an instance of AccessibleStateSet containing the current
3110          * state set of the object
3111          * @see javax.accessibility.AccessibleState
3112          */
3113         public AccessibleStateSet getAccessibleStateSet() {
3114             AccessibleStateSet states = super.getAccessibleStateSet();
3115             if (getFocusOwner() != null) {
3116                 states.add(AccessibleState.ACTIVE);
3117             }
3118             return states;
3119         }
3120 
3121     } // inner class AccessibleAWTWindow
3122 
3123     @Override
3124     void setGraphicsConfiguration(GraphicsConfiguration gc) {
3125         if (gc == null) {
3126             gc = GraphicsEnvironment.
3127                     getLocalGraphicsEnvironment().
3128                     getDefaultScreenDevice().
3129                     getDefaultConfiguration();
3130         }
3131         synchronized (getTreeLock()) {
3132             super.setGraphicsConfiguration(gc);
3133             if (log.isLoggable(PlatformLogger.Level.FINER)) {
3134                 log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this);
3135             }
3136         }
3137     }
3138 
3139     /**
3140      * Sets the location of the window relative to the specified
3141      * component according to the following scenarios.
3142      * <p>
3143      * The target screen mentioned below is a screen to which
3144      * the window should be placed after the setLocationRelativeTo
3145      * method is called.
3146      * <ul>
3147      * <li>If the component is {@code null}, or the {@code
3148      * GraphicsConfiguration} associated with this component is
3149      * {@code null}, the window is placed in the center of the
3150      * screen. The center point can be obtained with the {@link
3151      * GraphicsEnvironment#getCenterPoint
3152      * GraphicsEnvironment.getCenterPoint} method.
3153      * <li>If the component is not {@code null}, but it is not
3154      * currently showing, the window is placed in the center of
3155      * the target screen defined by the {@code
3156      * GraphicsConfiguration} associated with this component.
3157      * <li>If the component is not {@code null} and is shown on
3158      * the screen, then the window is located in such a way that
3159      * the center of the window coincides with the center of the
3160      * component.
3161      * </ul>
3162      * <p>
3163      * If the screens configuration does not allow the window to
3164      * be moved from one screen to another, then the window is
3165      * only placed at the location determined according to the
3166      * above conditions and its {@code GraphicsConfiguration} is
3167      * not changed.
3168      * <p>
3169      * <b>Note</b>: If the lower edge of the window is out of the screen,
3170      * then the window is placed to the side of the {@code Component}
3171      * that is closest to the center of the screen. So if the
3172      * component is on the right part of the screen, the window
3173      * is placed to its left, and vice versa.
3174      * <p>
3175      * If after the window location has been calculated, the upper,
3176      * left, or right edge of the window is out of the screen,
3177      * then the window is located in such a way that the upper,
3178      * left, or right edge of the window coincides with the
3179      * corresponding edge of the screen. If both left and right
3180      * edges of the window are out of the screen, the window is
3181      * placed at the left side of the screen. The similar placement
3182      * will occur if both top and bottom edges are out of the screen.
3183      * In that case, the window is placed at the top side of the screen.
3184      * <p>
3185      * The method changes the geometry-related data. Therefore,
3186      * the native windowing system may ignore such requests, or it may modify
3187      * the requested data, so that the {@code Window} object is placed and sized
3188      * in a way that corresponds closely to the desktop settings.
3189      *
3190      * @param c  the component in relation to which the window's location
3191      *           is determined
3192      * @see java.awt.GraphicsEnvironment#getCenterPoint
3193      * @since 1.4
3194      */
3195     public void setLocationRelativeTo(Component c) {
3196         // target location
3197         int dx = 0, dy = 0;
3198         // target GC
3199         GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode();
3200         Rectangle gcBounds = gc.getBounds();
3201 
3202         Dimension windowSize = getSize();
3203 
3204         // search a top-level of c
3205         Window componentWindow = SunToolkit.getContainingWindow(c);
3206         if ((c == null) || (componentWindow == null)) {
3207             GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
3208             gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
3209             gcBounds = gc.getBounds();
3210             Point centerPoint = ge.getCenterPoint();
3211             dx = centerPoint.x - windowSize.width / 2;
3212             dy = centerPoint.y - windowSize.height / 2;
3213         } else if (!c.isShowing()) {
3214             gc = componentWindow.getGraphicsConfiguration();
3215             gcBounds = gc.getBounds();
3216             dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2;
3217             dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2;
3218         } else {
3219             gc = componentWindow.getGraphicsConfiguration();
3220             gcBounds = gc.getBounds();
3221             Dimension compSize = c.getSize();
3222             Point compLocation = c.getLocationOnScreen();
3223             dx = compLocation.x + ((compSize.width - windowSize.width) / 2);
3224             dy = compLocation.y + ((compSize.height - windowSize.height) / 2);
3225 
3226             // Adjust for bottom edge being offscreen
3227             if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3228                 dy = gcBounds.y + gcBounds.height - windowSize.height;
3229                 if (compLocation.x - gcBounds.x + compSize.width / 2 < gcBounds.width / 2) {
3230                     dx = compLocation.x + compSize.width;
3231                 } else {
3232                     dx = compLocation.x - windowSize.width;
3233                 }
3234             }
3235         }
3236 
3237         // Avoid being placed off the edge of the screen:
3238         // bottom
3239         if (dy + windowSize.height > gcBounds.y + gcBounds.height) {
3240             dy = gcBounds.y + gcBounds.height - windowSize.height;
3241         }
3242         // top
3243         if (dy < gcBounds.y) {
3244             dy = gcBounds.y;
3245         }
3246         // right
3247         if (dx + windowSize.width > gcBounds.x + gcBounds.width) {
3248             dx = gcBounds.x + gcBounds.width - windowSize.width;
3249         }
3250         // left
3251         if (dx < gcBounds.x) {
3252             dx = gcBounds.x;
3253         }
3254 
3255         setLocation(dx, dy);
3256     }
3257 
3258     /**
3259      * Overridden from Component.  Top-level Windows should not propagate a
3260      * MouseWheelEvent beyond themselves into their owning Windows.
3261      */
3262     void deliverMouseWheelToAncestor(MouseWheelEvent e) {}
3263 
3264     /**
3265      * Overridden from Component.  Top-level Windows don't dispatch to ancestors
3266      */
3267     boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {return false;}
3268 
3269     /**
3270      * Creates a new strategy for multi-buffering on this component.
3271      * Multi-buffering is useful for rendering performance.  This method
3272      * attempts to create the best strategy available with the number of
3273      * buffers supplied.  It will always create a {@code BufferStrategy}
3274      * with that number of buffers.
3275      * A page-flipping strategy is attempted first, then a blitting strategy
3276      * using accelerated buffers.  Finally, an unaccelerated blitting
3277      * strategy is used.
3278      * <p>
3279      * Each time this method is called,
3280      * the existing buffer strategy for this component is discarded.
3281      * @param numBuffers number of buffers to create
3282      * @exception IllegalArgumentException if numBuffers is less than 1.
3283      * @exception IllegalStateException if the component is not displayable
3284      * @see #isDisplayable
3285      * @see #getBufferStrategy
3286      * @since 1.4
3287      */
3288     public void createBufferStrategy(int numBuffers) {
3289         super.createBufferStrategy(numBuffers);
3290     }
3291 
3292     /**
3293      * Creates a new strategy for multi-buffering on this component with the
3294      * required buffer capabilities.  This is useful, for example, if only
3295      * accelerated memory or page flipping is desired (as specified by the
3296      * buffer capabilities).
3297      * <p>
3298      * Each time this method
3299      * is called, the existing buffer strategy for this component is discarded.
3300      * @param numBuffers number of buffers to create, including the front buffer
3301      * @param caps the required capabilities for creating the buffer strategy;
3302      * cannot be {@code null}
3303      * @exception AWTException if the capabilities supplied could not be
3304      * supported or met; this may happen, for example, if there is not enough
3305      * accelerated memory currently available, or if page flipping is specified
3306      * but not possible.
3307      * @exception IllegalArgumentException if numBuffers is less than 1, or if
3308      * caps is {@code null}
3309      * @see #getBufferStrategy
3310      * @since 1.4
3311      */
3312     public void createBufferStrategy(int numBuffers,
3313         BufferCapabilities caps) throws AWTException {
3314         super.createBufferStrategy(numBuffers, caps);
3315     }
3316 
3317     /**
3318      * Returns the {@code BufferStrategy} used by this component.  This
3319      * method will return null if a {@code BufferStrategy} has not yet
3320      * been created or has been disposed.
3321      *
3322      * @return the buffer strategy used by this component
3323      * @see #createBufferStrategy
3324      * @since 1.4
3325      */
3326     public BufferStrategy getBufferStrategy() {
3327         return super.getBufferStrategy();
3328     }
3329 
3330     Component getTemporaryLostComponent() {
3331         return temporaryLostComponent;
3332     }
3333     Component setTemporaryLostComponent(Component component) {
3334         Component previousComp = temporaryLostComponent;
3335         // Check that "component" is an acceptable focus owner and don't store it otherwise
3336         // - or later we will have problems with opposite while handling  WINDOW_GAINED_FOCUS
3337         if (component == null || component.canBeFocusOwner()) {
3338             temporaryLostComponent = component;
3339         } else {
3340             temporaryLostComponent = null;
3341         }
3342         return previousComp;
3343     }
3344 
3345     /**
3346      * Checks whether this window can contain focus owner.
3347      * Verifies that it is focusable and as container it can container focus owner.
3348      * @since 1.5
3349      */
3350     boolean canContainFocusOwner(Component focusOwnerCandidate) {
3351         return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow();
3352     }
3353 
3354     private boolean locationByPlatform = locationByPlatformProp;
3355 
3356 
3357     /**
3358      * Sets whether this Window should appear at the default location for the
3359      * native windowing system or at the current location (returned by
3360      * {@code getLocation}) the next time the Window is made visible.
3361      * This behavior resembles a native window shown without programmatically
3362      * setting its location.  Most windowing systems cascade windows if their
3363      * locations are not explicitly set. The actual location is determined once the
3364      * window is shown on the screen.
3365      * <p>
3366      * This behavior can also be enabled by setting the System Property
3367      * "java.awt.Window.locationByPlatform" to "true", though calls to this method
3368      * take precedence.
3369      * <p>
3370      * Calls to {@code setVisible}, {@code setLocation} and
3371      * {@code setBounds} after calling {@code setLocationByPlatform} clear
3372      * this property of the Window.
3373      * <p>
3374      * For example, after the following code is executed:
3375      * <pre>
3376      * setLocationByPlatform(true);
3377      * setVisible(true);
3378      * boolean flag = isLocationByPlatform();
3379      * </pre>
3380      * The window will be shown at platform's default location and
3381      * {@code flag} will be {@code false}.
3382      * <p>
3383      * In the following sample:
3384      * <pre>
3385      * setLocationByPlatform(true);
3386      * setLocation(10, 10);
3387      * boolean flag = isLocationByPlatform();
3388      * setVisible(true);
3389      * </pre>
3390      * The window will be shown at (10, 10) and {@code flag} will be
3391      * {@code false}.
3392      *
3393      * @param locationByPlatform {@code true} if this Window should appear
3394      *        at the default location, {@code false} if at the current location
3395      * @throws IllegalComponentStateException if the window
3396      *         is showing on screen and locationByPlatform is {@code true}.
3397      * @see #setLocation
3398      * @see #isShowing
3399      * @see #setVisible
3400      * @see #isLocationByPlatform
3401      * @see java.lang.System#getProperty(String)
3402      * @since 1.5
3403      */
3404     public void setLocationByPlatform(boolean locationByPlatform) {
3405         synchronized (getTreeLock()) {
3406             if (locationByPlatform && isShowing()) {
3407                 throw new IllegalComponentStateException("The window is showing on screen.");
3408             }
3409             this.locationByPlatform = locationByPlatform;
3410         }
3411     }
3412 
3413     /**
3414      * Returns {@code true} if this Window will appear at the default location
3415      * for the native windowing system the next time this Window is made visible.
3416      * This method always returns {@code false} if the Window is showing on the
3417      * screen.
3418      *
3419      * @return whether this Window will appear at the default location
3420      * @see #setLocationByPlatform
3421      * @see #isShowing
3422      * @since 1.5
3423      */
3424     public boolean isLocationByPlatform() {
3425         synchronized (getTreeLock()) {
3426             return locationByPlatform;
3427         }
3428     }
3429 
3430     /**
3431      * {@inheritDoc}
3432      * <p>
3433      * The {@code width} or {@code height} values
3434      * are automatically enlarged if either is less than
3435      * the minimum size as specified by previous call to
3436      * {@code setMinimumSize}.
3437      * <p>
3438      * The method changes the geometry-related data. Therefore,
3439      * the native windowing system may ignore such requests, or it may modify
3440      * the requested data, so that the {@code Window} object is placed and sized
3441      * in a way that corresponds closely to the desktop settings.
3442      *
3443      * @see #getBounds
3444      * @see #setLocation(int, int)
3445      * @see #setLocation(Point)
3446      * @see #setSize(int, int)
3447      * @see #setSize(Dimension)
3448      * @see #setMinimumSize
3449      * @see #setLocationByPlatform
3450      * @see #isLocationByPlatform
3451      * @since 1.6
3452      */
3453     public void setBounds(int x, int y, int width, int height) {
3454         synchronized (getTreeLock()) {
3455             if (getBoundsOp() == ComponentPeer.SET_LOCATION ||
3456                 getBoundsOp() == ComponentPeer.SET_BOUNDS)
3457             {
3458                 locationByPlatform = false;
3459             }
3460             super.setBounds(x, y, width, height);
3461         }
3462     }
3463 
3464     /**
3465      * {@inheritDoc}
3466      * <p>
3467      * The {@code r.width} or {@code r.height} values
3468      * will be automatically enlarged if either is less than
3469      * the minimum size as specified by previous call to
3470      * {@code setMinimumSize}.
3471      * <p>
3472      * The method changes the geometry-related data. Therefore,
3473      * the native windowing system may ignore such requests, or it may modify
3474      * the requested data, so that the {@code Window} object is placed and sized
3475      * in a way that corresponds closely to the desktop settings.
3476      *
3477      * @see #getBounds
3478      * @see #setLocation(int, int)
3479      * @see #setLocation(Point)
3480      * @see #setSize(int, int)
3481      * @see #setSize(Dimension)
3482      * @see #setMinimumSize
3483      * @see #setLocationByPlatform
3484      * @see #isLocationByPlatform
3485      * @since 1.6
3486      */
3487     public void setBounds(Rectangle r) {
3488         setBounds(r.x, r.y, r.width, r.height);
3489     }
3490 
3491     /**
3492      * Determines whether this component will be displayed on the screen.
3493      * @return {@code true} if the component and all of its ancestors
3494      *          until a toplevel window are visible, {@code false} otherwise
3495      */
3496     boolean isRecursivelyVisible() {
3497         // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible.
3498         // We're overriding isRecursivelyVisible to implement this policy.
3499         return visible;
3500     }
3501 
3502 
3503     // ******************** SHAPES & TRANSPARENCY CODE ********************
3504 
3505     /**
3506      * Returns the opacity of the window.
3507      *
3508      * @return the opacity of the window
3509      *
3510      * @see Window#setOpacity(float)
3511      * @see GraphicsDevice.WindowTranslucency
3512      *
3513      * @since 1.7
3514      */
3515     public float getOpacity() {
3516         synchronized (getTreeLock()) {
3517             return opacity;
3518         }
3519     }
3520 
3521     /**
3522      * Sets the opacity of the window.
3523      * <p>
3524      * The opacity value is in the range [0..1]. Note that setting the opacity
3525      * level of 0 may or may not disable the mouse event handling on this
3526      * window. This is a platform-dependent behavior.
3527      * <p>
3528      * The following conditions must be met in order to set the opacity value
3529      * less than {@code 1.0f}:
3530      * <ul>
3531      * <li>The {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3532      * translucency must be supported by the underlying system
3533      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3534      * and {@link Dialog#setUndecorated})
3535      * <li>The window must not be in full-screen mode (see {@link
3536      * GraphicsDevice#setFullScreenWindow(Window)})
3537      * </ul>
3538      * <p>
3539      * If the requested opacity value is less than {@code 1.0f}, and any of the
3540      * above conditions are not met, the window opacity will not change,
3541      * and the {@code IllegalComponentStateException} will be thrown.
3542      * <p>
3543      * The translucency levels of individual pixels may also be effected by the
3544      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3545      * current shape of this window (see {@link #setShape(Shape)}).
3546      *
3547      * @param opacity the opacity level to set to the window
3548      *
3549      * @throws IllegalArgumentException if the opacity is out of the range
3550      *     [0..1]
3551      * @throws IllegalComponentStateException if the window is decorated and
3552      *     the opacity is less than {@code 1.0f}
3553      * @throws IllegalComponentStateException if the window is in full screen
3554      *     mode, and the opacity is less than {@code 1.0f}
3555      * @throws UnsupportedOperationException if the {@code
3556      *     GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT}
3557      *     translucency is not supported and the opacity is less than
3558      *     {@code 1.0f}
3559      *
3560      * @see Window#getOpacity
3561      * @see Window#setBackground(Color)
3562      * @see Window#setShape(Shape)
3563      * @see Frame#isUndecorated
3564      * @see Dialog#isUndecorated
3565      * @see GraphicsDevice.WindowTranslucency
3566      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3567      *
3568      * @since 1.7
3569      */
3570     public void setOpacity(float opacity) {
3571         synchronized (getTreeLock()) {
3572             if (opacity < 0.0f || opacity > 1.0f) {
3573                 throw new IllegalArgumentException(
3574                     "The value of opacity should be in the range [0.0f .. 1.0f].");
3575             }
3576             if (opacity < 1.0f) {
3577                 GraphicsConfiguration gc = getGraphicsConfiguration();
3578                 GraphicsDevice gd = gc.getDevice();
3579                 if (gc.getDevice().getFullScreenWindow() == this) {
3580                     throw new IllegalComponentStateException(
3581                         "Setting opacity for full-screen window is not supported.");
3582                 }
3583                 if (!gd.isWindowTranslucencySupported(
3584                     GraphicsDevice.WindowTranslucency.TRANSLUCENT))
3585                 {
3586                     throw new UnsupportedOperationException(
3587                         "TRANSLUCENT translucency is not supported.");
3588                 }
3589             }
3590             this.opacity = opacity;
3591             WindowPeer peer = (WindowPeer)getPeer();
3592             if (peer != null) {
3593                 peer.setOpacity(opacity);
3594             }
3595         }
3596     }
3597 
3598     /**
3599      * Returns the shape of the window.
3600      *
3601      * The value returned by this method may not be the same as
3602      * previously set with {@code setShape(shape)}, but it is guaranteed
3603      * to represent the same shape.
3604      *
3605      * @return the shape of the window or {@code null} if no
3606      *     shape is specified for the window
3607      *
3608      * @see Window#setShape(Shape)
3609      * @see GraphicsDevice.WindowTranslucency
3610      *
3611      * @since 1.7
3612      */
3613     public Shape getShape() {
3614         synchronized (getTreeLock()) {
3615             return shape == null ? null : new Path2D.Float(shape);
3616         }
3617     }
3618 
3619     /**
3620      * Sets the shape of the window.
3621      * <p>
3622      * Setting a shape cuts off some parts of the window. Only the parts that
3623      * belong to the given {@link Shape} remain visible and clickable. If
3624      * the shape argument is {@code null}, this method restores the default
3625      * shape, making the window rectangular on most platforms.
3626      * <p>
3627      * The following conditions must be met to set a non-null shape:
3628      * <ul>
3629      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3630      * PERPIXEL_TRANSPARENT} translucency must be supported by the
3631      * underlying system
3632      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3633      * and {@link Dialog#setUndecorated})
3634      * <li>The window must not be in full-screen mode (see {@link
3635      * GraphicsDevice#setFullScreenWindow(Window)})
3636      * </ul>
3637      * <p>
3638      * If the requested shape is not {@code null}, and any of the above
3639      * conditions are not met, the shape of this window will not change,
3640      * and either the {@code UnsupportedOperationException} or {@code
3641      * IllegalComponentStateException} will be thrown.
3642      * <p>
3643      * The tranlucency levels of individual pixels may also be effected by the
3644      * alpha component of their color (see {@link Window#setBackground(Color)}) and the
3645      * opacity value (see {@link #setOpacity(float)}). See {@link
3646      * GraphicsDevice.WindowTranslucency} for more details.
3647      *
3648      * @param shape the shape to set to the window
3649      *
3650      * @throws IllegalComponentStateException if the shape is not {@code
3651      *     null} and the window is decorated
3652      * @throws IllegalComponentStateException if the shape is not {@code
3653      *     null} and the window is in full-screen mode
3654      * @throws UnsupportedOperationException if the shape is not {@code
3655      *     null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT
3656      *     PERPIXEL_TRANSPARENT} translucency is not supported
3657      *
3658      * @see Window#getShape()
3659      * @see Window#setBackground(Color)
3660      * @see Window#setOpacity(float)
3661      * @see Frame#isUndecorated
3662      * @see Dialog#isUndecorated
3663      * @see GraphicsDevice.WindowTranslucency
3664      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3665      *
3666      * @since 1.7
3667      */
3668     public void setShape(Shape shape) {
3669         synchronized (getTreeLock()) {
3670             if (shape != null) {
3671                 GraphicsConfiguration gc = getGraphicsConfiguration();
3672                 GraphicsDevice gd = gc.getDevice();
3673                 if (gc.getDevice().getFullScreenWindow() == this) {
3674                     throw new IllegalComponentStateException(
3675                         "Setting shape for full-screen window is not supported.");
3676                 }
3677                 if (!gd.isWindowTranslucencySupported(
3678                         GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT))
3679                 {
3680                     throw new UnsupportedOperationException(
3681                         "PERPIXEL_TRANSPARENT translucency is not supported.");
3682                 }
3683             }
3684             this.shape = (shape == null) ? null : new Path2D.Float(shape);
3685             WindowPeer peer = (WindowPeer)getPeer();
3686             if (peer != null) {
3687                 peer.applyShape(shape == null ? null : Region.getInstance(shape, null));
3688             }
3689         }
3690     }
3691 
3692     /**
3693      * Gets the background color of this window.
3694      * <p>
3695      * Note that the alpha component of the returned color indicates whether
3696      * the window is in the non-opaque (per-pixel translucent) mode.
3697      *
3698      * @return this component's background color
3699      *
3700      * @see Window#setBackground(Color)
3701      * @see Window#isOpaque
3702      * @see GraphicsDevice.WindowTranslucency
3703      */
3704     @Override
3705     public Color getBackground() {
3706         return super.getBackground();
3707     }
3708 
3709     /**
3710      * Sets the background color of this window.
3711      * <p>
3712      * If the windowing system supports the {@link
3713      * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT}
3714      * tranclucency, the alpha component of the given background color
3715      * may effect the mode of operation for this window: it indicates whether
3716      * this window must be opaque (alpha equals {@code 1.0f}) or per-pixel translucent
3717      * (alpha is less than {@code 1.0f}). If the given background color is
3718      * {@code null}, the window is considered completely opaque.
3719      * <p>
3720      * All the following conditions must be met to enable the per-pixel
3721      * transparency mode for this window:
3722      * <ul>
3723      * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3724      * PERPIXEL_TRANSLUCENT} translucency must be supported by the graphics
3725      * device where this window is located
3726      * <li>The window must be undecorated (see {@link Frame#setUndecorated}
3727      * and {@link Dialog#setUndecorated})
3728      * <li>The window must not be in full-screen mode (see {@link
3729      * GraphicsDevice#setFullScreenWindow(Window)})
3730      * </ul>
3731      * <p>
3732      * If the alpha component of the requested background color is less than
3733      * {@code 1.0f}, and any of the above conditions are not met, the background
3734      * color of this window will not change, the alpha component of the given
3735      * background color will not affect the mode of operation for this window,
3736      * and either the {@code UnsupportedOperationException} or {@code
3737      * IllegalComponentStateException} will be thrown.
3738      * <p>
3739      * When the window is per-pixel translucent, the drawing sub-system
3740      * respects the alpha value of each individual pixel. If a pixel gets
3741      * painted with the alpha color component equal to zero, it becomes
3742      * visually transparent. If the alpha of the pixel is equal to 1.0f, the
3743      * pixel is fully opaque. Interim values of the alpha color component make
3744      * the pixel semi-transparent. In this mode, the background of the window
3745      * gets painted with the alpha value of the given background color. If the
3746      * alpha value of the argument of this method is equal to {@code 0}, the
3747      * background is not painted at all.
3748      * <p>
3749      * The actual level of translucency of a given pixel also depends on window
3750      * opacity (see {@link #setOpacity(float)}), as well as the current shape of
3751      * this window (see {@link #setShape(Shape)}).
3752      * <p>
3753      * Note that painting a pixel with the alpha value of {@code 0} may or may
3754      * not disable the mouse event handling on this pixel. This is a
3755      * platform-dependent behavior. To make sure the mouse events do not get
3756      * dispatched to a particular pixel, the pixel must be excluded from the
3757      * shape of the window.
3758      * <p>
3759      * Enabling the per-pixel translucency mode may change the graphics
3760      * configuration of this window due to the native platform requirements.
3761      *
3762      * @param bgColor the color to become this window's background color.
3763      *
3764      * @throws IllegalComponentStateException if the alpha value of the given
3765      *     background color is less than {@code 1.0f} and the window is decorated
3766      * @throws IllegalComponentStateException if the alpha value of the given
3767      *     background color is less than {@code 1.0f} and the window is in
3768      *     full-screen mode
3769      * @throws UnsupportedOperationException if the alpha value of the given
3770      *     background color is less than {@code 1.0f} and {@link
3771      *     GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT
3772      *     PERPIXEL_TRANSLUCENT} translucency is not supported
3773      *
3774      * @see Window#getBackground
3775      * @see Window#isOpaque
3776      * @see Window#setOpacity(float)
3777      * @see Window#setShape(Shape)
3778      * @see Frame#isUndecorated
3779      * @see Dialog#isUndecorated
3780      * @see GraphicsDevice.WindowTranslucency
3781      * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency)
3782      * @see GraphicsConfiguration#isTranslucencyCapable()
3783      */
3784     @Override
3785     public void setBackground(Color bgColor) {
3786         Color oldBg = getBackground();
3787         super.setBackground(bgColor);
3788         if (oldBg != null && oldBg.equals(bgColor)) {
3789             return;
3790         }
3791         int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255;
3792         int alpha = bgColor != null ? bgColor.getAlpha() : 255;
3793         if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window
3794             GraphicsConfiguration gc = getGraphicsConfiguration();
3795             GraphicsDevice gd = gc.getDevice();
3796             if (gc.getDevice().getFullScreenWindow() == this) {
3797                 throw new IllegalComponentStateException(
3798                     "Making full-screen window non opaque is not supported.");
3799             }
3800             if (!gc.isTranslucencyCapable()) {
3801                 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC();
3802                 if (capableGC == null) {
3803                     throw new UnsupportedOperationException(
3804                         "PERPIXEL_TRANSLUCENT translucency is not supported");
3805                 }
3806                 setGraphicsConfiguration(capableGC);
3807             }
3808             setLayersOpaque(this, false);
3809         } else if ((oldAlpha < 255) && (alpha == 255)) {
3810             setLayersOpaque(this, true);
3811         }
3812         WindowPeer peer = (WindowPeer)getPeer();
3813         if (peer != null) {
3814             peer.setOpaque(alpha == 255);
3815         }
3816     }
3817 
3818     /**
3819      * Indicates if the window is currently opaque.
3820      * <p>
3821      * The method returns {@code false} if the background color of the window
3822      * is not {@code null} and the alpha component of the color is less than
3823      * {@code 1.0f}. The method returns {@code true} otherwise.
3824      *
3825      * @return {@code true} if the window is opaque, {@code false} otherwise
3826      *
3827      * @see Window#getBackground
3828      * @see Window#setBackground(Color)
3829      * @since 1.7
3830      */
3831     @Override
3832     public boolean isOpaque() {
3833         Color bg = getBackground();
3834         return bg != null ? bg.getAlpha() == 255 : true;
3835     }
3836 
3837     private void updateWindow() {
3838         synchronized (getTreeLock()) {
3839             WindowPeer peer = (WindowPeer)getPeer();
3840             if (peer != null) {
3841                 peer.updateWindow();
3842             }
3843         }
3844     }
3845 
3846     /**
3847      * {@inheritDoc}
3848      *
3849      * @since 1.7
3850      */
3851     @Override
3852     public void paint(Graphics g) {
3853         if (!isOpaque()) {
3854             Graphics gg = g.create();
3855             try {
3856                 if (gg instanceof Graphics2D) {
3857                     gg.setColor(getBackground());
3858                     ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
3859                     gg.fillRect(0, 0, getWidth(), getHeight());
3860                 }
3861             } finally {
3862                 gg.dispose();
3863             }
3864         }
3865         super.paint(g);
3866     }
3867 
3868     private static void setLayersOpaque(Component component, boolean isOpaque) {
3869         // Shouldn't use instanceof to avoid loading Swing classes
3870         //    if it's a pure AWT application.
3871         if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) {
3872             javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component;
3873             javax.swing.JRootPane root = rpc.getRootPane();
3874             javax.swing.JLayeredPane lp = root.getLayeredPane();
3875             Container c = root.getContentPane();
3876             javax.swing.JComponent content =
3877                 (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null;
3878             lp.setOpaque(isOpaque);
3879             root.setOpaque(isOpaque);
3880             if (content != null) {
3881                 content.setOpaque(isOpaque);
3882 
3883                 // Iterate down one level to see whether we have a JApplet
3884                 // (which is also a RootPaneContainer) which requires processing
3885                 int numChildren = content.getComponentCount();
3886                 if (numChildren > 0) {
3887                     Component child = content.getComponent(0);
3888                     // It's OK to use instanceof here because we've
3889                     // already loaded the RootPaneContainer class by now
3890                     if (child instanceof javax.swing.RootPaneContainer) {
3891                         setLayersOpaque(child, isOpaque);
3892                     }
3893                 }
3894             }
3895         }
3896     }
3897 
3898 
3899     // ************************** MIXING CODE *******************************
3900 
3901     // A window has an owner, but it does NOT have a container
3902     @Override
3903     final Container getContainer() {
3904         return null;
3905     }
3906 
3907     /**
3908      * Applies the shape to the component
3909      * @param shape Shape to be applied to the component
3910      */
3911     @Override
3912     final void applyCompoundShape(Region shape) {
3913         // The shape calculated by mixing code is not intended to be applied
3914         // to windows or frames
3915     }
3916 
3917     @Override
3918     final void applyCurrentShape() {
3919         // The shape calculated by mixing code is not intended to be applied
3920         // to windows or frames
3921     }
3922 
3923     @Override
3924     final void mixOnReshaping() {
3925         // The shape calculated by mixing code is not intended to be applied
3926         // to windows or frames
3927     }
3928 
3929     @Override
3930     final Point getLocationOnWindow() {
3931         return new Point(0, 0);
3932     }
3933 
3934     // ****************** END OF MIXING CODE ********************************
3935 
3936     /**
3937      * Limit the given double value with the given range.
3938      */
3939     private static double limit(double value, double min, double max) {
3940         value = Math.max(value, min);
3941         value = Math.min(value, max);
3942         return value;
3943     }
3944 
3945     /**
3946      * Calculate the position of the security warning.
3947      *
3948      * This method gets the window location/size as reported by the native
3949      * system since the locally cached values may represent outdated data.
3950      *
3951      * The method is used from the native code, or via AWTAccessor.
3952      *
3953      * NOTE: this method is invoked on the toolkit thread, and therefore is not
3954      * supposed to become public/user-overridable.
3955      */
3956     private Point2D calculateSecurityWarningPosition(double x, double y,
3957             double w, double h)
3958     {
3959         // The position according to the spec of SecurityWarning.setPosition()
3960         double wx = x + w * securityWarningAlignmentX + securityWarningPointX;
3961         double wy = y + h * securityWarningAlignmentY + securityWarningPointY;
3962 
3963         // First, make sure the warning is not too far from the window bounds
3964         wx = Window.limit(wx,
3965                 x - securityWarningWidth - 2,
3966                 x + w + 2);
3967         wy = Window.limit(wy,
3968                 y - securityWarningHeight - 2,
3969                 y + h + 2);
3970 
3971         // Now make sure the warning window is visible on the screen
3972         GraphicsConfiguration graphicsConfig =
3973             getGraphicsConfiguration_NoClientCode();
3974         Rectangle screenBounds = graphicsConfig.getBounds();
3975         Insets screenInsets =
3976             Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig);
3977 
3978         wx = Window.limit(wx,
3979                 screenBounds.x + screenInsets.left,
3980                 screenBounds.x + screenBounds.width - screenInsets.right
3981                 - securityWarningWidth);
3982         wy = Window.limit(wy,
3983                 screenBounds.y + screenInsets.top,
3984                 screenBounds.y + screenBounds.height - screenInsets.bottom
3985                 - securityWarningHeight);
3986 
3987         return new Point2D.Double(wx, wy);
3988     }
3989 
3990     static {
3991         AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() {
3992             public float getOpacity(Window window) {
3993                 return window.opacity;
3994             }
3995             public void setOpacity(Window window, float opacity) {
3996                 window.setOpacity(opacity);
3997             }
3998             public Shape getShape(Window window) {
3999                 return window.getShape();
4000             }
4001             public void setShape(Window window, Shape shape) {
4002                 window.setShape(shape);
4003             }
4004             public void setOpaque(Window window, boolean opaque) {
4005                 Color bg = window.getBackground();
4006                 if (bg == null) {
4007                     bg = new Color(0, 0, 0, 0);
4008                 }
4009                 window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(),
4010                                                opaque ? 255 : 0));
4011             }
4012             public void updateWindow(Window window) {
4013                 window.updateWindow();
4014             }
4015 
4016             public Dimension getSecurityWarningSize(Window window) {
4017                 return new Dimension(window.securityWarningWidth,
4018                         window.securityWarningHeight);
4019             }
4020 
4021             public void setSecurityWarningSize(Window window, int width, int height)
4022             {
4023                 window.securityWarningWidth = width;
4024                 window.securityWarningHeight = height;
4025             }
4026 
4027             public void setSecurityWarningPosition(Window window,
4028                     Point2D point, float alignmentX, float alignmentY)
4029             {
4030                 window.securityWarningPointX = point.getX();
4031                 window.securityWarningPointY = point.getY();
4032                 window.securityWarningAlignmentX = alignmentX;
4033                 window.securityWarningAlignmentY = alignmentY;
4034 
4035                 synchronized (window.getTreeLock()) {
4036                     WindowPeer peer = (WindowPeer)window.getPeer();
4037                     if (peer != null) {
4038                         peer.repositionSecurityWarning();
4039                     }
4040                 }
4041             }
4042 
4043             public Point2D calculateSecurityWarningPosition(Window window,
4044                     double x, double y, double w, double h)
4045             {
4046                 return window.calculateSecurityWarningPosition(x, y, w, h);
4047             }
4048 
4049             public void setLWRequestStatus(Window changed, boolean status) {
4050                 changed.syncLWRequests = status;
4051             }
4052 
4053             public boolean isAutoRequestFocus(Window w) {
4054                 return w.autoRequestFocus;
4055             }
4056 
4057             public boolean isTrayIconWindow(Window w) {
4058                 return w.isTrayIconWindow;
4059             }
4060 
4061             public void setTrayIconWindow(Window w, boolean isTrayIconWindow) {
4062                 w.isTrayIconWindow = isTrayIconWindow;
4063             }
4064         }); // WindowAccessor
4065     } // static
4066 
4067     // a window doesn't need to be updated in the Z-order.
4068     @Override
4069     void updateZOrder() {}
4070 
4071 } // class Window
4072 
4073 
4074 /**
4075  * This class is no longer used, but is maintained for Serialization
4076  * backward-compatibility.
4077  */
4078 class FocusManager implements java.io.Serializable {
4079     Container focusRoot;
4080     Component focusOwner;
4081 
4082     /*
4083      * JDK 1.1 serialVersionUID
4084      */
4085     static final long serialVersionUID = 2491878825643557906L;
4086 }