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