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