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