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