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