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 1.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 platform-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 1.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 adjustDescendantsOnParent(int num) { 1243 // do nothing since parent == owner and we shouldn't 1244 // adjust 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 1.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 1.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 * 1456 * @return the owner of this window 1457 * @since 1.2 1458 */ 1459 public Window getOwner() { 1460 return getOwner_NoClientCode(); 1461 } 1462 final Window getOwner_NoClientCode() { 1463 return (Window)parent; 1464 } 1465 1466 /** 1467 * Return an array containing all the windows this 1468 * window currently owns. 1469 * 1470 * @return the array of all the owned windows 1471 * @since 1.2 1472 */ 1473 public Window[] getOwnedWindows() { 1474 return getOwnedWindows_NoClientCode(); 1475 } 1476 final Window[] getOwnedWindows_NoClientCode() { 1477 Window realCopy[]; 1478 1479 synchronized(ownedWindowList) { 1480 // Recall that ownedWindowList is actually a Vector of 1481 // WeakReferences and calling get() on one of these references 1482 // may return null. Make two arrays-- one the size of the 1483 // Vector (fullCopy with size fullSize), and one the size of 1484 // all non-null get()s (realCopy with size realSize). 1485 int fullSize = ownedWindowList.size(); 1486 int realSize = 0; 1487 Window fullCopy[] = new Window[fullSize]; 1488 1489 for (int i = 0; i < fullSize; i++) { 1490 fullCopy[realSize] = ownedWindowList.elementAt(i).get(); 1491 1492 if (fullCopy[realSize] != null) { 1493 realSize++; 1494 } 1495 } 1496 1497 if (fullSize != realSize) { 1498 realCopy = Arrays.copyOf(fullCopy, realSize); 1499 } else { 1500 realCopy = fullCopy; 1501 } 1502 } 1503 1504 return realCopy; 1505 } 1506 1507 boolean isModalBlocked() { 1508 return modalBlocker != null; 1509 } 1510 1511 void setModalBlocked(Dialog blocker, boolean blocked, boolean peerCall) { 1512 this.modalBlocker = blocked ? blocker : null; 1513 if (peerCall) { 1514 WindowPeer peer = (WindowPeer)this.peer; 1515 if (peer != null) { 1516 peer.setModalBlocked(blocker, blocked); 1517 } 1518 } 1519 } 1520 1521 Dialog getModalBlocker() { 1522 return modalBlocker; 1523 } 1524 1525 /* 1526 * Returns a list of all displayable Windows, i. e. all the 1527 * Windows which peer is not null. 1528 * 1529 * @see #addNotify 1530 * @see #removeNotify 1531 */ 1532 static IdentityArrayList<Window> getAllWindows() { 1533 synchronized (allWindows) { 1534 IdentityArrayList<Window> v = new IdentityArrayList<Window>(); 1535 v.addAll(allWindows); 1536 return v; 1537 } 1538 } 1539 1540 static IdentityArrayList<Window> getAllUnblockedWindows() { 1541 synchronized (allWindows) { 1542 IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>(); 1543 for (int i = 0; i < allWindows.size(); i++) { 1544 Window w = allWindows.get(i); 1545 if (!w.isModalBlocked()) { 1546 unblocked.add(w); 1547 } 1548 } 1549 return unblocked; 1550 } 1551 } 1552 1553 private static Window[] getWindows(AppContext appContext) { 1554 synchronized (Window.class) { 1555 Window realCopy[]; 1556 @SuppressWarnings("unchecked") 1557 Vector<WeakReference<Window>> windowList = 1558 (Vector<WeakReference<Window>>)appContext.get(Window.class); 1559 if (windowList != null) { 1560 int fullSize = windowList.size(); 1561 int realSize = 0; 1562 Window fullCopy[] = new Window[fullSize]; 1563 for (int i = 0; i < fullSize; i++) { 1564 Window w = windowList.get(i).get(); 1565 if (w != null) { 1566 fullCopy[realSize++] = w; 1567 } 1568 } 1569 if (fullSize != realSize) { 1570 realCopy = Arrays.copyOf(fullCopy, realSize); 1571 } else { 1572 realCopy = fullCopy; 1573 } 1574 } else { 1575 realCopy = new Window[0]; 1576 } 1577 return realCopy; 1578 } 1579 } 1580 1581 /** 1582 * Returns an array of all {@code Window}s, both owned and ownerless, 1583 * created by this application. 1584 * If called from an applet, the array includes only the {@code Window}s 1585 * accessible by that applet. 1586 * <p> 1587 * <b>Warning:</b> this method may return system created windows, such 1588 * as a print dialog. Applications should not assume the existence of 1589 * these dialogs, nor should an application assume anything about these 1590 * dialogs such as component positions, {@code LayoutManager}s 1591 * or serialization. 1592 * 1593 * @return the array of all the {@code Window}s created by the application 1594 * @see Frame#getFrames 1595 * @see Window#getOwnerlessWindows 1596 * 1597 * @since 1.6 1598 */ 1599 public static Window[] getWindows() { 1600 return getWindows(AppContext.getAppContext()); 1601 } 1602 1603 /** 1604 * Returns an array of all {@code Window}s created by this application 1605 * that have no owner. They include {@code Frame}s and ownerless 1606 * {@code Dialog}s and {@code Window}s. 1607 * If called from an applet, the array includes only the {@code Window}s 1608 * accessible by that applet. 1609 * <p> 1610 * <b>Warning:</b> this method may return system created windows, such 1611 * as a print dialog. Applications should not assume the existence of 1612 * these dialogs, nor should an application assume anything about these 1613 * dialogs such as component positions, {@code LayoutManager}s 1614 * or serialization. 1615 * 1616 * @return the array of all the ownerless {@code Window}s 1617 * created by this application 1618 * @see Frame#getFrames 1619 * @see Window#getWindows() 1620 * 1621 * @since 1.6 1622 */ 1623 public static Window[] getOwnerlessWindows() { 1624 Window[] allWindows = Window.getWindows(); 1625 1626 int ownerlessCount = 0; 1627 for (Window w : allWindows) { 1628 if (w.getOwner() == null) { 1629 ownerlessCount++; 1630 } 1631 } 1632 1633 Window[] ownerless = new Window[ownerlessCount]; 1634 int c = 0; 1635 for (Window w : allWindows) { 1636 if (w.getOwner() == null) { 1637 ownerless[c++] = w; 1638 } 1639 } 1640 1641 return ownerless; 1642 } 1643 1644 Window getDocumentRoot() { 1645 synchronized (getTreeLock()) { 1646 Window w = this; 1647 while (w.getOwner() != null) { 1648 w = w.getOwner(); 1649 } 1650 return w; 1651 } 1652 } 1653 1654 /** 1655 * Specifies the modal exclusion type for this window. If a window is modal 1656 * excluded, it is not blocked by some modal dialogs. See {@link 1657 * java.awt.Dialog.ModalExclusionType Dialog.ModalExclusionType} for 1658 * possible modal exclusion types. 1659 * <p> 1660 * If the given type is not supported, {@code NO_EXCLUDE} is used. 1661 * <p> 1662 * Note: changing the modal exclusion type for a visible window may have no 1663 * effect until it is hidden and then shown again. 1664 * 1665 * @param exclusionType the modal exclusion type for this window; a {@code null} 1666 * value is equivalent to {@link Dialog.ModalExclusionType#NO_EXCLUDE 1667 * NO_EXCLUDE} 1668 * @throws SecurityException if the calling thread does not have permission 1669 * to set the modal exclusion property to the window with the given 1670 * {@code exclusionType} 1671 * @see java.awt.Dialog.ModalExclusionType 1672 * @see java.awt.Window#getModalExclusionType 1673 * @see java.awt.Toolkit#isModalExclusionTypeSupported 1674 * 1675 * @since 1.6 1676 */ 1677 public void setModalExclusionType(Dialog.ModalExclusionType exclusionType) { 1678 if (exclusionType == null) { 1679 exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; 1680 } 1681 if (!Toolkit.getDefaultToolkit().isModalExclusionTypeSupported(exclusionType)) { 1682 exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; 1683 } 1684 if (modalExclusionType == exclusionType) { 1685 return; 1686 } 1687 if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) { 1688 SecurityManager sm = System.getSecurityManager(); 1689 if (sm != null) { 1690 sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION); 1691 } 1692 } 1693 modalExclusionType = exclusionType; 1694 1695 // if we want on-fly changes, we need to uncomment the lines below 1696 // and override the method in Dialog to use modalShow() instead 1697 // of updateChildrenBlocking() 1698 /* 1699 if (isModalBlocked()) { 1700 modalBlocker.unblockWindow(this); 1701 } 1702 Dialog.checkShouldBeBlocked(this); 1703 updateChildrenBlocking(); 1704 */ 1705 } 1706 1707 /** 1708 * Returns the modal exclusion type of this window. 1709 * 1710 * @return the modal exclusion type of this window 1711 * 1712 * @see java.awt.Dialog.ModalExclusionType 1713 * @see java.awt.Window#setModalExclusionType 1714 * 1715 * @since 1.6 1716 */ 1717 public Dialog.ModalExclusionType getModalExclusionType() { 1718 return modalExclusionType; 1719 } 1720 1721 boolean isModalExcluded(Dialog.ModalExclusionType exclusionType) { 1722 if ((modalExclusionType != null) && 1723 modalExclusionType.compareTo(exclusionType) >= 0) 1724 { 1725 return true; 1726 } 1727 Window owner = getOwner_NoClientCode(); 1728 return (owner != null) && owner.isModalExcluded(exclusionType); 1729 } 1730 1731 void updateChildrenBlocking() { 1732 Vector<Window> childHierarchy = new Vector<Window>(); 1733 Window[] ownedWindows = getOwnedWindows(); 1734 for (int i = 0; i < ownedWindows.length; i++) { 1735 childHierarchy.add(ownedWindows[i]); 1736 } 1737 int k = 0; 1738 while (k < childHierarchy.size()) { 1739 Window w = childHierarchy.get(k); 1740 if (w.isVisible()) { 1741 if (w.isModalBlocked()) { 1742 Dialog blocker = w.getModalBlocker(); 1743 blocker.unblockWindow(w); 1744 } 1745 Dialog.checkShouldBeBlocked(w); 1746 Window[] wOwned = w.getOwnedWindows(); 1747 for (int j = 0; j < wOwned.length; j++) { 1748 childHierarchy.add(wOwned[j]); 1749 } 1750 } 1751 k++; 1752 } 1753 } 1754 1755 /** 1756 * Adds the specified window listener to receive window events from 1757 * this window. 1758 * If l is null, no exception is thrown and no action is performed. 1759 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1760 * >AWT Threading Issues</a> for details on AWT's threading model. 1761 * 1762 * @param l the window listener 1763 * @see #removeWindowListener 1764 * @see #getWindowListeners 1765 */ 1766 public synchronized void addWindowListener(WindowListener l) { 1767 if (l == null) { 1768 return; 1769 } 1770 newEventsOnly = true; 1771 windowListener = AWTEventMulticaster.add(windowListener, l); 1772 } 1773 1774 /** 1775 * Adds the specified window state listener to receive window 1776 * events from this window. If {@code l} is {@code null}, 1777 * no exception is thrown and no action is performed. 1778 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1779 * >AWT Threading Issues</a> for details on AWT's threading model. 1780 * 1781 * @param l the window state listener 1782 * @see #removeWindowStateListener 1783 * @see #getWindowStateListeners 1784 * @since 1.4 1785 */ 1786 public synchronized void addWindowStateListener(WindowStateListener l) { 1787 if (l == null) { 1788 return; 1789 } 1790 windowStateListener = AWTEventMulticaster.add(windowStateListener, l); 1791 newEventsOnly = true; 1792 } 1793 1794 /** 1795 * Adds the specified window focus listener to receive window events 1796 * from this window. 1797 * If l is null, no exception is thrown and no action is performed. 1798 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1799 * >AWT Threading Issues</a> for details on AWT's threading model. 1800 * 1801 * @param l the window focus listener 1802 * @see #removeWindowFocusListener 1803 * @see #getWindowFocusListeners 1804 * @since 1.4 1805 */ 1806 public synchronized void addWindowFocusListener(WindowFocusListener l) { 1807 if (l == null) { 1808 return; 1809 } 1810 windowFocusListener = AWTEventMulticaster.add(windowFocusListener, l); 1811 newEventsOnly = true; 1812 } 1813 1814 /** 1815 * Removes the specified window listener so that it no longer 1816 * receives window events from this window. 1817 * If l is null, no exception is thrown and no action is performed. 1818 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1819 * >AWT Threading Issues</a> for details on AWT's threading model. 1820 * 1821 * @param l the window listener 1822 * @see #addWindowListener 1823 * @see #getWindowListeners 1824 */ 1825 public synchronized void removeWindowListener(WindowListener l) { 1826 if (l == null) { 1827 return; 1828 } 1829 windowListener = AWTEventMulticaster.remove(windowListener, l); 1830 } 1831 1832 /** 1833 * Removes the specified window state listener so that it no 1834 * longer receives window events from this window. If 1835 * {@code l} is {@code null}, no exception is thrown and 1836 * no action is performed. 1837 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1838 * >AWT Threading Issues</a> for details on AWT's threading model. 1839 * 1840 * @param l the window state listener 1841 * @see #addWindowStateListener 1842 * @see #getWindowStateListeners 1843 * @since 1.4 1844 */ 1845 public synchronized void removeWindowStateListener(WindowStateListener l) { 1846 if (l == null) { 1847 return; 1848 } 1849 windowStateListener = AWTEventMulticaster.remove(windowStateListener, l); 1850 } 1851 1852 /** 1853 * Removes the specified window focus listener so that it no longer 1854 * receives window events from this window. 1855 * If l is null, no exception is thrown and no action is performed. 1856 * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" 1857 * >AWT Threading Issues</a> for details on AWT's threading model. 1858 * 1859 * @param l the window focus listener 1860 * @see #addWindowFocusListener 1861 * @see #getWindowFocusListeners 1862 * @since 1.4 1863 */ 1864 public synchronized void removeWindowFocusListener(WindowFocusListener l) { 1865 if (l == null) { 1866 return; 1867 } 1868 windowFocusListener = AWTEventMulticaster.remove(windowFocusListener, l); 1869 } 1870 1871 /** 1872 * Returns an array of all the window listeners 1873 * registered on this window. 1874 * 1875 * @return all of this window's {@code WindowListener}s 1876 * or an empty array if no window 1877 * listeners are currently registered 1878 * 1879 * @see #addWindowListener 1880 * @see #removeWindowListener 1881 * @since 1.4 1882 */ 1883 public synchronized WindowListener[] getWindowListeners() { 1884 return getListeners(WindowListener.class); 1885 } 1886 1887 /** 1888 * Returns an array of all the window focus listeners 1889 * registered on this window. 1890 * 1891 * @return all of this window's {@code WindowFocusListener}s 1892 * or an empty array if no window focus 1893 * listeners are currently registered 1894 * 1895 * @see #addWindowFocusListener 1896 * @see #removeWindowFocusListener 1897 * @since 1.4 1898 */ 1899 public synchronized WindowFocusListener[] getWindowFocusListeners() { 1900 return getListeners(WindowFocusListener.class); 1901 } 1902 1903 /** 1904 * Returns an array of all the window state listeners 1905 * registered on this window. 1906 * 1907 * @return all of this window's {@code WindowStateListener}s 1908 * or an empty array if no window state 1909 * listeners are currently registered 1910 * 1911 * @see #addWindowStateListener 1912 * @see #removeWindowStateListener 1913 * @since 1.4 1914 */ 1915 public synchronized WindowStateListener[] getWindowStateListeners() { 1916 return getListeners(WindowStateListener.class); 1917 } 1918 1919 1920 /** 1921 * Returns an array of all the objects currently registered 1922 * as <code><em>Foo</em>Listener</code>s 1923 * upon this {@code Window}. 1924 * <code><em>Foo</em>Listener</code>s are registered using the 1925 * <code>add<em>Foo</em>Listener</code> method. 1926 * 1927 * <p> 1928 * 1929 * You can specify the {@code listenerType} argument 1930 * with a class literal, such as 1931 * <code><em>Foo</em>Listener.class</code>. 1932 * For example, you can query a 1933 * {@code Window} {@code w} 1934 * for its window listeners with the following code: 1935 * 1936 * <pre>WindowListener[] wls = (WindowListener[])(w.getListeners(WindowListener.class));</pre> 1937 * 1938 * If no such listeners exist, this method returns an empty array. 1939 * 1940 * @param listenerType the type of listeners requested; this parameter 1941 * should specify an interface that descends from 1942 * {@code java.util.EventListener} 1943 * @return an array of all objects registered as 1944 * <code><em>Foo</em>Listener</code>s on this window, 1945 * or an empty array if no such 1946 * listeners have been added 1947 * @exception ClassCastException if {@code listenerType} 1948 * doesn't specify a class or interface that implements 1949 * {@code java.util.EventListener} 1950 * @exception NullPointerException if {@code listenerType} is {@code null} 1951 * 1952 * @see #getWindowListeners 1953 * @since 1.3 1954 */ 1955 public <T extends EventListener> T[] getListeners(Class<T> listenerType) { 1956 EventListener l = null; 1957 if (listenerType == WindowFocusListener.class) { 1958 l = windowFocusListener; 1959 } else if (listenerType == WindowStateListener.class) { 1960 l = windowStateListener; 1961 } else if (listenerType == WindowListener.class) { 1962 l = windowListener; 1963 } else { 1964 return super.getListeners(listenerType); 1965 } 1966 return AWTEventMulticaster.getListeners(l, listenerType); 1967 } 1968 1969 // REMIND: remove when filtering is handled at lower level 1970 boolean eventEnabled(AWTEvent e) { 1971 switch(e.id) { 1972 case WindowEvent.WINDOW_OPENED: 1973 case WindowEvent.WINDOW_CLOSING: 1974 case WindowEvent.WINDOW_CLOSED: 1975 case WindowEvent.WINDOW_ICONIFIED: 1976 case WindowEvent.WINDOW_DEICONIFIED: 1977 case WindowEvent.WINDOW_ACTIVATED: 1978 case WindowEvent.WINDOW_DEACTIVATED: 1979 if ((eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 || 1980 windowListener != null) { 1981 return true; 1982 } 1983 return false; 1984 case WindowEvent.WINDOW_GAINED_FOCUS: 1985 case WindowEvent.WINDOW_LOST_FOCUS: 1986 if ((eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 || 1987 windowFocusListener != null) { 1988 return true; 1989 } 1990 return false; 1991 case WindowEvent.WINDOW_STATE_CHANGED: 1992 if ((eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 || 1993 windowStateListener != null) { 1994 return true; 1995 } 1996 return false; 1997 default: 1998 break; 1999 } 2000 return super.eventEnabled(e); 2001 } 2002 2003 /** 2004 * Processes events on this window. If the event is an 2005 * {@code WindowEvent}, it invokes the 2006 * {@code processWindowEvent} method, else it invokes its 2007 * superclass's {@code processEvent}. 2008 * <p>Note that if the event parameter is {@code null} 2009 * the behavior is unspecified and may result in an 2010 * exception. 2011 * 2012 * @param e the event 2013 */ 2014 protected void processEvent(AWTEvent e) { 2015 if (e instanceof WindowEvent) { 2016 switch (e.getID()) { 2017 case WindowEvent.WINDOW_OPENED: 2018 case WindowEvent.WINDOW_CLOSING: 2019 case WindowEvent.WINDOW_CLOSED: 2020 case WindowEvent.WINDOW_ICONIFIED: 2021 case WindowEvent.WINDOW_DEICONIFIED: 2022 case WindowEvent.WINDOW_ACTIVATED: 2023 case WindowEvent.WINDOW_DEACTIVATED: 2024 processWindowEvent((WindowEvent)e); 2025 break; 2026 case WindowEvent.WINDOW_GAINED_FOCUS: 2027 case WindowEvent.WINDOW_LOST_FOCUS: 2028 processWindowFocusEvent((WindowEvent)e); 2029 break; 2030 case WindowEvent.WINDOW_STATE_CHANGED: 2031 processWindowStateEvent((WindowEvent)e); 2032 break; 2033 } 2034 return; 2035 } 2036 super.processEvent(e); 2037 } 2038 2039 /** 2040 * Processes window events occurring on this window by 2041 * dispatching them to any registered WindowListener objects. 2042 * NOTE: This method will not be called unless window events 2043 * are enabled for this component; this happens when one of the 2044 * following occurs: 2045 * <ul> 2046 * <li>A WindowListener object is registered via 2047 * {@code addWindowListener} 2048 * <li>Window events are enabled via {@code enableEvents} 2049 * </ul> 2050 * <p>Note that if the event parameter is {@code null} 2051 * the behavior is unspecified and may result in an 2052 * exception. 2053 * 2054 * @param e the window event 2055 * @see Component#enableEvents 2056 */ 2057 protected void processWindowEvent(WindowEvent e) { 2058 WindowListener listener = windowListener; 2059 if (listener != null) { 2060 switch(e.getID()) { 2061 case WindowEvent.WINDOW_OPENED: 2062 listener.windowOpened(e); 2063 break; 2064 case WindowEvent.WINDOW_CLOSING: 2065 listener.windowClosing(e); 2066 break; 2067 case WindowEvent.WINDOW_CLOSED: 2068 listener.windowClosed(e); 2069 break; 2070 case WindowEvent.WINDOW_ICONIFIED: 2071 listener.windowIconified(e); 2072 break; 2073 case WindowEvent.WINDOW_DEICONIFIED: 2074 listener.windowDeiconified(e); 2075 break; 2076 case WindowEvent.WINDOW_ACTIVATED: 2077 listener.windowActivated(e); 2078 break; 2079 case WindowEvent.WINDOW_DEACTIVATED: 2080 listener.windowDeactivated(e); 2081 break; 2082 default: 2083 break; 2084 } 2085 } 2086 } 2087 2088 /** 2089 * Processes window focus event occurring on this window by 2090 * dispatching them to any registered WindowFocusListener objects. 2091 * NOTE: this method will not be called unless window focus events 2092 * are enabled for this window. This happens when one of the 2093 * following occurs: 2094 * <ul> 2095 * <li>a WindowFocusListener is registered via 2096 * {@code addWindowFocusListener} 2097 * <li>Window focus events are enabled via {@code enableEvents} 2098 * </ul> 2099 * <p>Note that if the event parameter is {@code null} 2100 * the behavior is unspecified and may result in an 2101 * exception. 2102 * 2103 * @param e the window focus event 2104 * @see Component#enableEvents 2105 * @since 1.4 2106 */ 2107 protected void processWindowFocusEvent(WindowEvent e) { 2108 WindowFocusListener listener = windowFocusListener; 2109 if (listener != null) { 2110 switch (e.getID()) { 2111 case WindowEvent.WINDOW_GAINED_FOCUS: 2112 listener.windowGainedFocus(e); 2113 break; 2114 case WindowEvent.WINDOW_LOST_FOCUS: 2115 listener.windowLostFocus(e); 2116 break; 2117 default: 2118 break; 2119 } 2120 } 2121 } 2122 2123 /** 2124 * Processes window state event occurring on this window by 2125 * dispatching them to any registered {@code WindowStateListener} 2126 * objects. 2127 * NOTE: this method will not be called unless window state events 2128 * are enabled for this window. This happens when one of the 2129 * following occurs: 2130 * <ul> 2131 * <li>a {@code WindowStateListener} is registered via 2132 * {@code addWindowStateListener} 2133 * <li>window state events are enabled via {@code enableEvents} 2134 * </ul> 2135 * <p>Note that if the event parameter is {@code null} 2136 * the behavior is unspecified and may result in an 2137 * exception. 2138 * 2139 * @param e the window state event 2140 * @see java.awt.Component#enableEvents 2141 * @since 1.4 2142 */ 2143 protected void processWindowStateEvent(WindowEvent e) { 2144 WindowStateListener listener = windowStateListener; 2145 if (listener != null) { 2146 switch (e.getID()) { 2147 case WindowEvent.WINDOW_STATE_CHANGED: 2148 listener.windowStateChanged(e); 2149 break; 2150 default: 2151 break; 2152 } 2153 } 2154 } 2155 2156 /** 2157 * Implements a debugging hook -- checks to see if 2158 * the user has typed <i>control-shift-F1</i>. If so, 2159 * the list of child windows is dumped to {@code System.out}. 2160 * @param e the keyboard event 2161 */ 2162 void preProcessKeyEvent(KeyEvent e) { 2163 // Dump the list of child windows to System.out. 2164 if (e.isActionKey() && e.getKeyCode() == KeyEvent.VK_F1 && 2165 e.isControlDown() && e.isShiftDown() && 2166 e.getID() == KeyEvent.KEY_PRESSED) { 2167 list(System.out, 0); 2168 } 2169 } 2170 2171 void postProcessKeyEvent(KeyEvent e) { 2172 // Do nothing 2173 } 2174 2175 2176 /** 2177 * Sets whether this window should always be above other windows. If 2178 * there are multiple always-on-top windows, their relative order is 2179 * unspecified and platform dependent. 2180 * <p> 2181 * If some other window is already always-on-top then the 2182 * relative order between these windows is unspecified (depends on 2183 * platform). No window can be brought to be over the always-on-top 2184 * window except maybe another always-on-top window. 2185 * <p> 2186 * All windows owned by an always-on-top window inherit this state and 2187 * automatically become always-on-top. If a window ceases to be 2188 * always-on-top, the windows that it owns will no longer be 2189 * always-on-top. When an always-on-top window is sent {@link #toBack 2190 * toBack}, its always-on-top state is set to {@code false}. 2191 * 2192 * <p> When this method is called on a window with a value of 2193 * {@code true}, and the window is visible and the platform 2194 * supports always-on-top for this window, the window is immediately 2195 * brought forward, "sticking" it in the top-most position. If the 2196 * window isn`t currently visible, this method sets the always-on-top 2197 * state to {@code true} but does not bring the window forward. 2198 * When the window is later shown, it will be always-on-top. 2199 * 2200 * <p> When this method is called on a window with a value of 2201 * {@code false} the always-on-top state is set to normal. It may also 2202 * cause an unspecified, platform-dependent change in the z-order of 2203 * top-level windows, but other always-on-top windows will remain in 2204 * top-most position. Calling this method with a value of {@code false} 2205 * on a window that has a normal state has no effect. 2206 * 2207 * <p><b>Note</b>: some platforms might not support always-on-top 2208 * windows. To detect if always-on-top windows are supported by the 2209 * current platform, use {@link Toolkit#isAlwaysOnTopSupported()} and 2210 * {@link Window#isAlwaysOnTopSupported()}. If always-on-top mode 2211 * isn't supported for this window or this window's toolkit does not 2212 * support always-on-top windows, calling this method has no effect. 2213 * <p> 2214 * If a SecurityManager is installed, the calling thread must be 2215 * granted the AWTPermission "setWindowAlwaysOnTop" in 2216 * order to set the value of this property. If this 2217 * permission is not granted, this method will throw a 2218 * SecurityException, and the current value of the property will 2219 * be left unchanged. 2220 * 2221 * @param alwaysOnTop true if the window should always be above other 2222 * windows 2223 * @throws SecurityException if the calling thread does not have 2224 * permission to set the value of always-on-top property 2225 * 2226 * @see #isAlwaysOnTop 2227 * @see #toFront 2228 * @see #toBack 2229 * @see AWTPermission 2230 * @see #isAlwaysOnTopSupported 2231 * @see #getToolkit 2232 * @see Toolkit#isAlwaysOnTopSupported 2233 * @since 1.5 2234 */ 2235 public final void setAlwaysOnTop(boolean alwaysOnTop) throws SecurityException { 2236 SecurityManager security = System.getSecurityManager(); 2237 if (security != null) { 2238 security.checkPermission(AWTPermissions.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION); 2239 } 2240 2241 boolean oldAlwaysOnTop; 2242 synchronized(this) { 2243 oldAlwaysOnTop = this.alwaysOnTop; 2244 this.alwaysOnTop = alwaysOnTop; 2245 } 2246 if (oldAlwaysOnTop != alwaysOnTop ) { 2247 if (isAlwaysOnTopSupported()) { 2248 WindowPeer peer = (WindowPeer)this.peer; 2249 synchronized(getTreeLock()) { 2250 if (peer != null) { 2251 peer.updateAlwaysOnTopState(); 2252 } 2253 } 2254 } 2255 firePropertyChange("alwaysOnTop", oldAlwaysOnTop, alwaysOnTop); 2256 } 2257 setOwnedWindowsAlwaysOnTop(alwaysOnTop); 2258 } 2259 2260 @SuppressWarnings({"rawtypes", "unchecked"}) 2261 private void setOwnedWindowsAlwaysOnTop(boolean alwaysOnTop) { 2262 WeakReference<Window>[] ownedWindowArray; 2263 synchronized (ownedWindowList) { 2264 ownedWindowArray = new WeakReference[ownedWindowList.size()]; 2265 ownedWindowList.copyInto(ownedWindowArray); 2266 } 2267 2268 for (WeakReference<Window> ref : ownedWindowArray) { 2269 Window window = ref.get(); 2270 if (window != null) { 2271 try { 2272 window.setAlwaysOnTop(alwaysOnTop); 2273 } catch (SecurityException ignore) { 2274 } 2275 } 2276 } 2277 } 2278 2279 /** 2280 * Returns whether the always-on-top mode is supported for this 2281 * window. Some platforms may not support always-on-top windows, some 2282 * may support only some kinds of top-level windows; for example, 2283 * a platform may not support always-on-top modal dialogs. 2284 * 2285 * @return {@code true}, if the always-on-top mode is supported for 2286 * this window and this window's toolkit supports always-on-top windows, 2287 * {@code false} otherwise 2288 * 2289 * @see #setAlwaysOnTop(boolean) 2290 * @see #getToolkit 2291 * @see Toolkit#isAlwaysOnTopSupported 2292 * @since 1.6 2293 */ 2294 public boolean isAlwaysOnTopSupported() { 2295 return Toolkit.getDefaultToolkit().isAlwaysOnTopSupported(); 2296 } 2297 2298 2299 /** 2300 * Returns whether this window is an always-on-top window. 2301 * @return {@code true}, if the window is in always-on-top state, 2302 * {@code false} otherwise 2303 * @see #setAlwaysOnTop 2304 * @since 1.5 2305 */ 2306 public final boolean isAlwaysOnTop() { 2307 return alwaysOnTop; 2308 } 2309 2310 2311 /** 2312 * Returns the child Component of this Window that has focus if this Window 2313 * is focused; returns null otherwise. 2314 * 2315 * @return the child Component with focus, or null if this Window is not 2316 * focused 2317 * @see #getMostRecentFocusOwner 2318 * @see #isFocused 2319 */ 2320 public Component getFocusOwner() { 2321 return (isFocused()) 2322 ? KeyboardFocusManager.getCurrentKeyboardFocusManager(). 2323 getFocusOwner() 2324 : null; 2325 } 2326 2327 /** 2328 * Returns the child Component of this Window that will receive the focus 2329 * when this Window is focused. If this Window is currently focused, this 2330 * method returns the same Component as {@code getFocusOwner()}. If 2331 * this Window is not focused, then the child Component that most recently 2332 * requested focus will be returned. If no child Component has ever 2333 * requested focus, and this is a focusable Window, then this Window's 2334 * initial focusable Component is returned. If no child Component has ever 2335 * requested focus, and this is a non-focusable Window, null is returned. 2336 * 2337 * @return the child Component that will receive focus when this Window is 2338 * focused 2339 * @see #getFocusOwner 2340 * @see #isFocused 2341 * @see #isFocusableWindow 2342 * @since 1.4 2343 */ 2344 public Component getMostRecentFocusOwner() { 2345 if (isFocused()) { 2346 return getFocusOwner(); 2347 } else { 2348 Component mostRecent = 2349 KeyboardFocusManager.getMostRecentFocusOwner(this); 2350 if (mostRecent != null) { 2351 return mostRecent; 2352 } else { 2353 return (isFocusableWindow()) 2354 ? getFocusTraversalPolicy().getInitialComponent(this) 2355 : null; 2356 } 2357 } 2358 } 2359 2360 /** 2361 * Returns whether this Window is active. Only a Frame or a Dialog may be 2362 * active. The native windowing system may denote the active Window or its 2363 * children with special decorations, such as a highlighted title bar. The 2364 * active Window is always either the focused Window, or the first Frame or 2365 * Dialog that is an owner of the focused Window. 2366 * 2367 * @return whether this is the active Window. 2368 * @see #isFocused 2369 * @since 1.4 2370 */ 2371 public boolean isActive() { 2372 return (KeyboardFocusManager.getCurrentKeyboardFocusManager(). 2373 getActiveWindow() == this); 2374 } 2375 2376 /** 2377 * Returns whether this Window is focused. If there exists a focus owner, 2378 * the focused Window is the Window that is, or contains, that focus owner. 2379 * If there is no focus owner, then no Window is focused. 2380 * <p> 2381 * If the focused Window is a Frame or a Dialog it is also the active 2382 * Window. Otherwise, the active Window is the first Frame or Dialog that 2383 * is an owner of the focused Window. 2384 * 2385 * @return whether this is the focused Window. 2386 * @see #isActive 2387 * @since 1.4 2388 */ 2389 public boolean isFocused() { 2390 return (KeyboardFocusManager.getCurrentKeyboardFocusManager(). 2391 getGlobalFocusedWindow() == this); 2392 } 2393 2394 /** 2395 * Gets a focus traversal key for this Window. (See {@code 2396 * setFocusTraversalKeys} for a full description of each key.) 2397 * <p> 2398 * If the traversal key has not been explicitly set for this Window, 2399 * then this Window's parent's traversal key is returned. If the 2400 * traversal key has not been explicitly set for any of this Window's 2401 * ancestors, then the current KeyboardFocusManager's default traversal key 2402 * is returned. 2403 * 2404 * @param id one of KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 2405 * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 2406 * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or 2407 * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS 2408 * @return the AWTKeyStroke for the specified key 2409 * @see Container#setFocusTraversalKeys 2410 * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS 2411 * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS 2412 * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS 2413 * @see KeyboardFocusManager#DOWN_CYCLE_TRAVERSAL_KEYS 2414 * @throws IllegalArgumentException if id is not one of 2415 * KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, 2416 * KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, 2417 * KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or 2418 * KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS 2419 * @since 1.4 2420 */ 2421 @SuppressWarnings("unchecked") 2422 public Set<AWTKeyStroke> getFocusTraversalKeys(int id) { 2423 if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) { 2424 throw new IllegalArgumentException("invalid focus traversal key identifier"); 2425 } 2426 2427 // Okay to return Set directly because it is an unmodifiable view 2428 @SuppressWarnings("rawtypes") 2429 Set keystrokes = (focusTraversalKeys != null) 2430 ? focusTraversalKeys[id] 2431 : null; 2432 2433 if (keystrokes != null) { 2434 return keystrokes; 2435 } else { 2436 return KeyboardFocusManager.getCurrentKeyboardFocusManager(). 2437 getDefaultFocusTraversalKeys(id); 2438 } 2439 } 2440 2441 /** 2442 * Does nothing because Windows must always be roots of a focus traversal 2443 * cycle. The passed-in value is ignored. 2444 * 2445 * @param focusCycleRoot this value is ignored 2446 * @see #isFocusCycleRoot 2447 * @see Container#setFocusTraversalPolicy 2448 * @see Container#getFocusTraversalPolicy 2449 * @since 1.4 2450 */ 2451 public final void setFocusCycleRoot(boolean focusCycleRoot) { 2452 } 2453 2454 /** 2455 * Always returns {@code true} because all Windows must be roots of a 2456 * focus traversal cycle. 2457 * 2458 * @return {@code true} 2459 * @see #setFocusCycleRoot 2460 * @see Container#setFocusTraversalPolicy 2461 * @see Container#getFocusTraversalPolicy 2462 * @since 1.4 2463 */ 2464 public final boolean isFocusCycleRoot() { 2465 return true; 2466 } 2467 2468 /** 2469 * Always returns {@code null} because Windows have no ancestors; they 2470 * represent the top of the Component hierarchy. 2471 * 2472 * @return {@code null} 2473 * @see Container#isFocusCycleRoot() 2474 * @since 1.4 2475 */ 2476 public final Container getFocusCycleRootAncestor() { 2477 return null; 2478 } 2479 2480 /** 2481 * Returns whether this Window can become the focused Window, that is, 2482 * whether this Window or any of its subcomponents can become the focus 2483 * owner. For a Frame or Dialog to be focusable, its focusable Window state 2484 * must be set to {@code true}. For a Window which is not a Frame or 2485 * Dialog to be focusable, its focusable Window state must be set to 2486 * {@code true}, its nearest owning Frame or Dialog must be 2487 * showing on the screen, and it must contain at least one Component in 2488 * its focus traversal cycle. If any of these conditions is not met, then 2489 * neither this Window nor any of its subcomponents can become the focus 2490 * owner. 2491 * 2492 * @return {@code true} if this Window can be the focused Window; 2493 * {@code false} otherwise 2494 * @see #getFocusableWindowState 2495 * @see #setFocusableWindowState 2496 * @see #isShowing 2497 * @see Component#isFocusable 2498 * @since 1.4 2499 */ 2500 public final boolean isFocusableWindow() { 2501 // If a Window/Frame/Dialog was made non-focusable, then it is always 2502 // non-focusable. 2503 if (!getFocusableWindowState()) { 2504 return false; 2505 } 2506 2507 // All other tests apply only to Windows. 2508 if (this instanceof Frame || this instanceof Dialog) { 2509 return true; 2510 } 2511 2512 // A Window must have at least one Component in its root focus 2513 // traversal cycle to be focusable. 2514 if (getFocusTraversalPolicy().getDefaultComponent(this) == null) { 2515 return false; 2516 } 2517 2518 // A Window's nearest owning Frame or Dialog must be showing on the 2519 // screen. 2520 for (Window owner = getOwner(); owner != null; 2521 owner = owner.getOwner()) 2522 { 2523 if (owner instanceof Frame || owner instanceof Dialog) { 2524 return owner.isShowing(); 2525 } 2526 } 2527 2528 return false; 2529 } 2530 2531 /** 2532 * Returns whether this Window can become the focused Window if it meets 2533 * the other requirements outlined in {@code isFocusableWindow}. If 2534 * this method returns {@code false}, then 2535 * {@code isFocusableWindow} will return {@code false} as well. 2536 * If this method returns {@code true}, then 2537 * {@code isFocusableWindow} may return {@code true} or 2538 * {@code false} depending upon the other requirements which must be 2539 * met in order for a Window to be focusable. 2540 * <p> 2541 * By default, all Windows have a focusable Window state of 2542 * {@code true}. 2543 * 2544 * @return whether this Window can be the focused Window 2545 * @see #isFocusableWindow 2546 * @see #setFocusableWindowState 2547 * @see #isShowing 2548 * @see Component#setFocusable 2549 * @since 1.4 2550 */ 2551 public boolean getFocusableWindowState() { 2552 return focusableWindowState; 2553 } 2554 2555 /** 2556 * Sets whether this Window can become the focused Window if it meets 2557 * the other requirements outlined in {@code isFocusableWindow}. If 2558 * this Window's focusable Window state is set to {@code false}, then 2559 * {@code isFocusableWindow} will return {@code false}. If this 2560 * Window's focusable Window state is set to {@code true}, then 2561 * {@code isFocusableWindow} may return {@code true} or 2562 * {@code false} depending upon the other requirements which must be 2563 * met in order for a Window to be focusable. 2564 * <p> 2565 * Setting a Window's focusability state to {@code false} is the 2566 * standard mechanism for an application to identify to the AWT a Window 2567 * which will be used as a floating palette or toolbar, and thus should be 2568 * a non-focusable Window. 2569 * 2570 * Setting the focusability state on a visible {@code Window} 2571 * can have a delayed effect on some platforms — the actual 2572 * change may happen only when the {@code Window} becomes 2573 * hidden and then visible again. To ensure consistent behavior 2574 * across platforms, set the {@code Window}'s focusable state 2575 * when the {@code Window} is invisible and then show it. 2576 * 2577 * @param focusableWindowState whether this Window can be the focused 2578 * Window 2579 * @see #isFocusableWindow 2580 * @see #getFocusableWindowState 2581 * @see #isShowing 2582 * @see Component#setFocusable 2583 * @since 1.4 2584 */ 2585 public void setFocusableWindowState(boolean focusableWindowState) { 2586 boolean oldFocusableWindowState; 2587 synchronized (this) { 2588 oldFocusableWindowState = this.focusableWindowState; 2589 this.focusableWindowState = focusableWindowState; 2590 } 2591 WindowPeer peer = (WindowPeer)this.peer; 2592 if (peer != null) { 2593 peer.updateFocusableWindowState(); 2594 } 2595 firePropertyChange("focusableWindowState", oldFocusableWindowState, 2596 focusableWindowState); 2597 if (oldFocusableWindowState && !focusableWindowState && isFocused()) { 2598 for (Window owner = getOwner(); 2599 owner != null; 2600 owner = owner.getOwner()) 2601 { 2602 Component toFocus = 2603 KeyboardFocusManager.getMostRecentFocusOwner(owner); 2604 if (toFocus != null && toFocus.requestFocus(false, CausedFocusEvent.Cause.ACTIVATION)) { 2605 return; 2606 } 2607 } 2608 KeyboardFocusManager.getCurrentKeyboardFocusManager(). 2609 clearGlobalFocusOwnerPriv(); 2610 } 2611 } 2612 2613 /** 2614 * Sets whether this window should receive focus on 2615 * subsequently being shown (with a call to {@link #setVisible setVisible(true)}), 2616 * or being moved to the front (with a call to {@link #toFront}). 2617 * <p> 2618 * Note that {@link #setVisible setVisible(true)} may be called indirectly 2619 * (e.g. when showing an owner of the window makes the window to be shown). 2620 * {@link #toFront} may also be called indirectly (e.g. when 2621 * {@link #setVisible setVisible(true)} is called on already visible window). 2622 * In all such cases this property takes effect as well. 2623 * <p> 2624 * The value of the property is not inherited by owned windows. 2625 * 2626 * @param autoRequestFocus whether this window should be focused on 2627 * subsequently being shown or being moved to the front 2628 * @see #isAutoRequestFocus 2629 * @see #isFocusableWindow 2630 * @see #setVisible 2631 * @see #toFront 2632 * @since 1.7 2633 */ 2634 public void setAutoRequestFocus(boolean autoRequestFocus) { 2635 this.autoRequestFocus = autoRequestFocus; 2636 } 2637 2638 /** 2639 * Returns whether this window should receive focus on subsequently being shown 2640 * (with a call to {@link #setVisible setVisible(true)}), or being moved to the front 2641 * (with a call to {@link #toFront}). 2642 * <p> 2643 * By default, the window has {@code autoRequestFocus} value of {@code true}. 2644 * 2645 * @return {@code autoRequestFocus} value 2646 * @see #setAutoRequestFocus 2647 * @since 1.7 2648 */ 2649 public boolean isAutoRequestFocus() { 2650 return autoRequestFocus; 2651 } 2652 2653 /** 2654 * Adds a PropertyChangeListener to the listener list. The listener is 2655 * registered for all bound properties of this class, including the 2656 * following: 2657 * <ul> 2658 * <li>this Window's font ("font")</li> 2659 * <li>this Window's background color ("background")</li> 2660 * <li>this Window's foreground color ("foreground")</li> 2661 * <li>this Window's focusability ("focusable")</li> 2662 * <li>this Window's focus traversal keys enabled state 2663 * ("focusTraversalKeysEnabled")</li> 2664 * <li>this Window's Set of FORWARD_TRAVERSAL_KEYS 2665 * ("forwardFocusTraversalKeys")</li> 2666 * <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS 2667 * ("backwardFocusTraversalKeys")</li> 2668 * <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS 2669 * ("upCycleFocusTraversalKeys")</li> 2670 * <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS 2671 * ("downCycleFocusTraversalKeys")</li> 2672 * <li>this Window's focus traversal policy ("focusTraversalPolicy") 2673 * </li> 2674 * <li>this Window's focusable Window state ("focusableWindowState") 2675 * </li> 2676 * <li>this Window's always-on-top state("alwaysOnTop")</li> 2677 * </ul> 2678 * Note that if this Window is inheriting a bound property, then no 2679 * event will be fired in response to a change in the inherited property. 2680 * <p> 2681 * If listener is null, no exception is thrown and no action is performed. 2682 * 2683 * @param listener the PropertyChangeListener to be added 2684 * 2685 * @see Component#removePropertyChangeListener 2686 * @see #addPropertyChangeListener(java.lang.String,java.beans.PropertyChangeListener) 2687 */ 2688 public void addPropertyChangeListener(PropertyChangeListener listener) { 2689 super.addPropertyChangeListener(listener); 2690 } 2691 2692 /** 2693 * Adds a PropertyChangeListener to the listener list for a specific 2694 * property. The specified property may be user-defined, or one of the 2695 * following: 2696 * <ul> 2697 * <li>this Window's font ("font")</li> 2698 * <li>this Window's background color ("background")</li> 2699 * <li>this Window's foreground color ("foreground")</li> 2700 * <li>this Window's focusability ("focusable")</li> 2701 * <li>this Window's focus traversal keys enabled state 2702 * ("focusTraversalKeysEnabled")</li> 2703 * <li>this Window's Set of FORWARD_TRAVERSAL_KEYS 2704 * ("forwardFocusTraversalKeys")</li> 2705 * <li>this Window's Set of BACKWARD_TRAVERSAL_KEYS 2706 * ("backwardFocusTraversalKeys")</li> 2707 * <li>this Window's Set of UP_CYCLE_TRAVERSAL_KEYS 2708 * ("upCycleFocusTraversalKeys")</li> 2709 * <li>this Window's Set of DOWN_CYCLE_TRAVERSAL_KEYS 2710 * ("downCycleFocusTraversalKeys")</li> 2711 * <li>this Window's focus traversal policy ("focusTraversalPolicy") 2712 * </li> 2713 * <li>this Window's focusable Window state ("focusableWindowState") 2714 * </li> 2715 * <li>this Window's always-on-top state("alwaysOnTop")</li> 2716 * </ul> 2717 * Note that if this Window is inheriting a bound property, then no 2718 * event will be fired in response to a change in the inherited property. 2719 * <p> 2720 * If listener is null, no exception is thrown and no action is performed. 2721 * 2722 * @param propertyName one of the property names listed above 2723 * @param listener the PropertyChangeListener to be added 2724 * 2725 * @see #addPropertyChangeListener(java.beans.PropertyChangeListener) 2726 * @see Component#removePropertyChangeListener 2727 */ 2728 public void addPropertyChangeListener(String propertyName, 2729 PropertyChangeListener listener) { 2730 super.addPropertyChangeListener(propertyName, listener); 2731 } 2732 2733 /** 2734 * Indicates if this container is a validate root. 2735 * <p> 2736 * {@code Window} objects are the validate roots, and, therefore, they 2737 * override this method to return {@code true}. 2738 * 2739 * @return {@code true} 2740 * @since 1.7 2741 * @see java.awt.Container#isValidateRoot 2742 */ 2743 @Override 2744 public boolean isValidateRoot() { 2745 return true; 2746 } 2747 2748 /** 2749 * Dispatches an event to this window or one of its sub components. 2750 * @param e the event 2751 */ 2752 void dispatchEventImpl(AWTEvent e) { 2753 if (e.getID() == ComponentEvent.COMPONENT_RESIZED) { 2754 invalidate(); 2755 validate(); 2756 } 2757 super.dispatchEventImpl(e); 2758 } 2759 2760 /** 2761 * @deprecated As of JDK version 1.1 2762 * replaced by {@code dispatchEvent(AWTEvent)}. 2763 */ 2764 @Deprecated 2765 public boolean postEvent(Event e) { 2766 if (handleEvent(e)) { 2767 e.consume(); 2768 return true; 2769 } 2770 return false; 2771 } 2772 2773 /** 2774 * Checks if this Window is showing on screen. 2775 * @see Component#setVisible 2776 */ 2777 public boolean isShowing() { 2778 return visible; 2779 } 2780 2781 boolean isDisposing() { 2782 return disposing; 2783 } 2784 2785 /** 2786 * @deprecated As of J2SE 1.4, replaced by 2787 * {@link Component#applyComponentOrientation Component.applyComponentOrientation}. 2788 */ 2789 @Deprecated 2790 public void applyResourceBundle(ResourceBundle rb) { 2791 applyComponentOrientation(ComponentOrientation.getOrientation(rb)); 2792 } 2793 2794 /** 2795 * @deprecated As of J2SE 1.4, replaced by 2796 * {@link Component#applyComponentOrientation Component.applyComponentOrientation}. 2797 */ 2798 @Deprecated 2799 public void applyResourceBundle(String rbName) { 2800 applyResourceBundle(ResourceBundle.getBundle(rbName)); 2801 } 2802 2803 /* 2804 * Support for tracking all windows owned by this window 2805 */ 2806 void addOwnedWindow(WeakReference<Window> weakWindow) { 2807 if (weakWindow != null) { 2808 synchronized(ownedWindowList) { 2809 // this if statement should really be an assert, but we don't 2810 // have asserts... 2811 if (!ownedWindowList.contains(weakWindow)) { 2812 ownedWindowList.addElement(weakWindow); 2813 } 2814 } 2815 } 2816 } 2817 2818 void removeOwnedWindow(WeakReference<Window> weakWindow) { 2819 if (weakWindow != null) { 2820 // synchronized block not required since removeElement is 2821 // already synchronized 2822 ownedWindowList.removeElement(weakWindow); 2823 } 2824 } 2825 2826 void connectOwnedWindow(Window child) { 2827 child.parent = this; 2828 addOwnedWindow(child.weakThis); 2829 child.disposerRecord.updateOwner(); 2830 } 2831 2832 private void addToWindowList() { 2833 synchronized (Window.class) { 2834 @SuppressWarnings("unchecked") 2835 Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class); 2836 if (windowList == null) { 2837 windowList = new Vector<WeakReference<Window>>(); 2838 appContext.put(Window.class, windowList); 2839 } 2840 windowList.add(weakThis); 2841 } 2842 } 2843 2844 private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) { 2845 synchronized (Window.class) { 2846 @SuppressWarnings("unchecked") 2847 Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class); 2848 if (windowList != null) { 2849 windowList.remove(weakThis); 2850 } 2851 } 2852 } 2853 2854 private void removeFromWindowList() { 2855 removeFromWindowList(appContext, weakThis); 2856 } 2857 2858 /** 2859 * Window type. 2860 * 2861 * Synchronization: ObjectLock 2862 */ 2863 private Type type = Type.NORMAL; 2864 2865 /** 2866 * Sets the type of the window. 2867 * 2868 * This method can only be called while the window is not displayable. 2869 * 2870 * @param type the window type 2871 * @throws IllegalComponentStateException if the window 2872 * is displayable. 2873 * @throws IllegalArgumentException if the type is {@code null} 2874 * @see Component#isDisplayable 2875 * @see #getType 2876 * @since 1.7 2877 */ 2878 public void setType(Type type) { 2879 if (type == null) { 2880 throw new IllegalArgumentException("type should not be null."); 2881 } 2882 synchronized (getTreeLock()) { 2883 if (isDisplayable()) { 2884 throw new IllegalComponentStateException( 2885 "The window is displayable."); 2886 } 2887 synchronized (getObjectLock()) { 2888 this.type = type; 2889 } 2890 } 2891 } 2892 2893 /** 2894 * Returns the type of the window. 2895 * 2896 * @return the type of the window 2897 * @see #setType 2898 * @since 1.7 2899 */ 2900 public Type getType() { 2901 synchronized (getObjectLock()) { 2902 return type; 2903 } 2904 } 2905 2906 /** 2907 * The window serialized data version. 2908 * 2909 * @serial 2910 */ 2911 private int windowSerializedDataVersion = 2; 2912 2913 /** 2914 * Writes default serializable fields to stream. Writes 2915 * a list of serializable {@code WindowListener}s and 2916 * {@code WindowFocusListener}s as optional data. 2917 * Writes a list of child windows as optional data. 2918 * Writes a list of icon images as optional data 2919 * 2920 * @param s the {@code ObjectOutputStream} to write 2921 * @serialData {@code null} terminated sequence of 2922 * 0 or more pairs; the pair consists of a {@code String} 2923 * and {@code Object}; the {@code String} 2924 * indicates the type of object and is one of the following: 2925 * {@code windowListenerK} indicating a 2926 * {@code WindowListener} object; 2927 * {@code windowFocusWindowK} indicating a 2928 * {@code WindowFocusListener} object; 2929 * {@code ownedWindowK} indicating a child 2930 * {@code Window} object 2931 * 2932 * @see AWTEventMulticaster#save(java.io.ObjectOutputStream, java.lang.String, java.util.EventListener) 2933 * @see Component#windowListenerK 2934 * @see Component#windowFocusListenerK 2935 * @see Component#ownedWindowK 2936 * @see #readObject(ObjectInputStream) 2937 */ 2938 private void writeObject(ObjectOutputStream s) throws IOException { 2939 synchronized (this) { 2940 // Update old focusMgr fields so that our object stream can be read 2941 // by previous releases 2942 focusMgr = new FocusManager(); 2943 focusMgr.focusRoot = this; 2944 focusMgr.focusOwner = getMostRecentFocusOwner(); 2945 2946 s.defaultWriteObject(); 2947 2948 // Clear fields so that we don't keep extra references around 2949 focusMgr = null; 2950 2951 AWTEventMulticaster.save(s, windowListenerK, windowListener); 2952 AWTEventMulticaster.save(s, windowFocusListenerK, windowFocusListener); 2953 AWTEventMulticaster.save(s, windowStateListenerK, windowStateListener); 2954 } 2955 2956 s.writeObject(null); 2957 2958 synchronized (ownedWindowList) { 2959 for (int i = 0; i < ownedWindowList.size(); i++) { 2960 Window child = ownedWindowList.elementAt(i).get(); 2961 if (child != null) { 2962 s.writeObject(ownedWindowK); 2963 s.writeObject(child); 2964 } 2965 } 2966 } 2967 s.writeObject(null); 2968 2969 //write icon array 2970 if (icons != null) { 2971 for (Image i : icons) { 2972 if (i instanceof Serializable) { 2973 s.writeObject(i); 2974 } 2975 } 2976 } 2977 s.writeObject(null); 2978 } 2979 2980 // 2981 // Part of deserialization procedure to be called before 2982 // user's code. 2983 // 2984 private void initDeserializedWindow() { 2985 setWarningString(); 2986 inputContextLock = new Object(); 2987 2988 // Deserialized Windows are not yet visible. 2989 visible = false; 2990 2991 weakThis = new WeakReference<>(this); 2992 2993 anchor = new Object(); 2994 disposerRecord = new WindowDisposerRecord(appContext, this); 2995 sun.java2d.Disposer.addRecord(anchor, disposerRecord); 2996 2997 addToWindowList(); 2998 initGC(null); 2999 ownedWindowList = new Vector<>(); 3000 } 3001 3002 private void deserializeResources(ObjectInputStream s) 3003 throws ClassNotFoundException, IOException, HeadlessException { 3004 3005 if (windowSerializedDataVersion < 2) { 3006 // Translate old-style focus tracking to new model. For 1.4 and 3007 // later releases, we'll rely on the Window's initial focusable 3008 // Component. 3009 if (focusMgr != null) { 3010 if (focusMgr.focusOwner != null) { 3011 KeyboardFocusManager. 3012 setMostRecentFocusOwner(this, focusMgr.focusOwner); 3013 } 3014 } 3015 3016 // This field is non-transient and relies on default serialization. 3017 // However, the default value is insufficient, so we need to set 3018 // it explicitly for object data streams prior to 1.4. 3019 focusableWindowState = true; 3020 3021 3022 } 3023 3024 Object keyOrNull; 3025 while(null != (keyOrNull = s.readObject())) { 3026 String key = ((String)keyOrNull).intern(); 3027 3028 if (windowListenerK == key) { 3029 addWindowListener((WindowListener)(s.readObject())); 3030 } else if (windowFocusListenerK == key) { 3031 addWindowFocusListener((WindowFocusListener)(s.readObject())); 3032 } else if (windowStateListenerK == key) { 3033 addWindowStateListener((WindowStateListener)(s.readObject())); 3034 } else // skip value for unrecognized key 3035 s.readObject(); 3036 } 3037 3038 try { 3039 while (null != (keyOrNull = s.readObject())) { 3040 String key = ((String)keyOrNull).intern(); 3041 3042 if (ownedWindowK == key) 3043 connectOwnedWindow((Window) s.readObject()); 3044 3045 else // skip value for unrecognized key 3046 s.readObject(); 3047 } 3048 3049 //read icons 3050 Object obj = s.readObject(); //Throws OptionalDataException 3051 //for pre1.6 objects. 3052 icons = new ArrayList<Image>(); //Frame.readObject() assumes 3053 //pre1.6 version if icons is null. 3054 while (obj != null) { 3055 if (obj instanceof Image) { 3056 icons.add((Image)obj); 3057 } 3058 obj = s.readObject(); 3059 } 3060 } 3061 catch (OptionalDataException e) { 3062 // 1.1 serialized form 3063 // ownedWindowList will be updated by Frame.readObject 3064 } 3065 3066 } 3067 3068 /** 3069 * Reads the {@code ObjectInputStream} and an optional 3070 * list of listeners to receive various events fired by 3071 * the component; also reads a list of 3072 * (possibly {@code null}) child windows. 3073 * Unrecognized keys or values will be ignored. 3074 * 3075 * @param s the {@code ObjectInputStream} to read 3076 * @exception HeadlessException if 3077 * {@code GraphicsEnvironment.isHeadless} returns 3078 * {@code true} 3079 * @see java.awt.GraphicsEnvironment#isHeadless 3080 * @see #writeObject 3081 */ 3082 private void readObject(ObjectInputStream s) 3083 throws ClassNotFoundException, IOException, HeadlessException 3084 { 3085 GraphicsEnvironment.checkHeadless(); 3086 initDeserializedWindow(); 3087 ObjectInputStream.GetField f = s.readFields(); 3088 3089 syncLWRequests = f.get("syncLWRequests", systemSyncLWRequests); 3090 state = f.get("state", 0); 3091 focusableWindowState = f.get("focusableWindowState", true); 3092 windowSerializedDataVersion = f.get("windowSerializedDataVersion", 1); 3093 locationByPlatform = f.get("locationByPlatform", locationByPlatformProp); 3094 // Note: 1.4 (or later) doesn't use focusMgr 3095 focusMgr = (FocusManager)f.get("focusMgr", null); 3096 Dialog.ModalExclusionType et = (Dialog.ModalExclusionType) 3097 f.get("modalExclusionType", Dialog.ModalExclusionType.NO_EXCLUDE); 3098 setModalExclusionType(et); // since 6.0 3099 boolean aot = f.get("alwaysOnTop", false); 3100 if(aot) { 3101 setAlwaysOnTop(aot); // since 1.5; subject to permission check 3102 } 3103 shape = (Shape)f.get("shape", null); 3104 opacity = (Float)f.get("opacity", 1.0f); 3105 3106 this.securityWarningWidth = 0; 3107 this.securityWarningHeight = 0; 3108 this.securityWarningPointX = 2.0; 3109 this.securityWarningPointY = 0.0; 3110 this.securityWarningAlignmentX = RIGHT_ALIGNMENT; 3111 this.securityWarningAlignmentY = TOP_ALIGNMENT; 3112 3113 deserializeResources(s); 3114 } 3115 3116 /* 3117 * --- Accessibility Support --- 3118 * 3119 */ 3120 3121 /** 3122 * Gets the AccessibleContext associated with this Window. 3123 * For windows, the AccessibleContext takes the form of an 3124 * AccessibleAWTWindow. 3125 * A new AccessibleAWTWindow instance is created if necessary. 3126 * 3127 * @return an AccessibleAWTWindow that serves as the 3128 * AccessibleContext of this Window 3129 * @since 1.3 3130 */ 3131 public AccessibleContext getAccessibleContext() { 3132 if (accessibleContext == null) { 3133 accessibleContext = new AccessibleAWTWindow(); 3134 } 3135 return accessibleContext; 3136 } 3137 3138 /** 3139 * This class implements accessibility support for the 3140 * {@code Window} class. It provides an implementation of the 3141 * Java Accessibility API appropriate to window user-interface elements. 3142 * @since 1.3 3143 */ 3144 protected class AccessibleAWTWindow extends AccessibleAWTContainer 3145 { 3146 /* 3147 * JDK 1.3 serialVersionUID 3148 */ 3149 private static final long serialVersionUID = 4215068635060671780L; 3150 3151 /** 3152 * Get the role of this object. 3153 * 3154 * @return an instance of AccessibleRole describing the role of the 3155 * object 3156 * @see javax.accessibility.AccessibleRole 3157 */ 3158 public AccessibleRole getAccessibleRole() { 3159 return AccessibleRole.WINDOW; 3160 } 3161 3162 /** 3163 * Get the state of this object. 3164 * 3165 * @return an instance of AccessibleStateSet containing the current 3166 * state set of the object 3167 * @see javax.accessibility.AccessibleState 3168 */ 3169 public AccessibleStateSet getAccessibleStateSet() { 3170 AccessibleStateSet states = super.getAccessibleStateSet(); 3171 if (getFocusOwner() != null) { 3172 states.add(AccessibleState.ACTIVE); 3173 } 3174 return states; 3175 } 3176 3177 } // inner class AccessibleAWTWindow 3178 3179 @Override 3180 void setGraphicsConfiguration(GraphicsConfiguration gc) { 3181 if (gc == null) { 3182 gc = GraphicsEnvironment. 3183 getLocalGraphicsEnvironment(). 3184 getDefaultScreenDevice(). 3185 getDefaultConfiguration(); 3186 } 3187 synchronized (getTreeLock()) { 3188 super.setGraphicsConfiguration(gc); 3189 if (log.isLoggable(PlatformLogger.Level.FINER)) { 3190 log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this); 3191 } 3192 } 3193 } 3194 3195 /** 3196 * Sets the location of the window relative to the specified 3197 * component according to the following scenarios. 3198 * <p> 3199 * The target screen mentioned below is a screen to which 3200 * the window should be placed after the setLocationRelativeTo 3201 * method is called. 3202 * <ul> 3203 * <li>If the component is {@code null}, or the {@code 3204 * GraphicsConfiguration} associated with this component is 3205 * {@code null}, the window is placed in the center of the 3206 * screen. The center point can be obtained with the {@link 3207 * GraphicsEnvironment#getCenterPoint 3208 * GraphicsEnvironment.getCenterPoint} method. 3209 * <li>If the component is not {@code null}, but it is not 3210 * currently showing, the window is placed in the center of 3211 * the target screen defined by the {@code 3212 * GraphicsConfiguration} associated with this component. 3213 * <li>If the component is not {@code null} and is shown on 3214 * the screen, then the window is located in such a way that 3215 * the center of the window coincides with the center of the 3216 * component. 3217 * </ul> 3218 * <p> 3219 * If the screens configuration does not allow the window to 3220 * be moved from one screen to another, then the window is 3221 * only placed at the location determined according to the 3222 * above conditions and its {@code GraphicsConfiguration} is 3223 * not changed. 3224 * <p> 3225 * <b>Note</b>: If the lower edge of the window is out of the screen, 3226 * then the window is placed to the side of the {@code Component} 3227 * that is closest to the center of the screen. So if the 3228 * component is on the right part of the screen, the window 3229 * is placed to its left, and vice versa. 3230 * <p> 3231 * If after the window location has been calculated, the upper, 3232 * left, or right edge of the window is out of the screen, 3233 * then the window is located in such a way that the upper, 3234 * left, or right edge of the window coincides with the 3235 * corresponding edge of the screen. If both left and right 3236 * edges of the window are out of the screen, the window is 3237 * placed at the left side of the screen. The similar placement 3238 * will occur if both top and bottom edges are out of the screen. 3239 * In that case, the window is placed at the top side of the screen. 3240 * <p> 3241 * The method changes the geometry-related data. Therefore, 3242 * the native windowing system may ignore such requests, or it may modify 3243 * the requested data, so that the {@code Window} object is placed and sized 3244 * in a way that corresponds closely to the desktop settings. 3245 * 3246 * @param c the component in relation to which the window's location 3247 * is determined 3248 * @see java.awt.GraphicsEnvironment#getCenterPoint 3249 * @since 1.4 3250 */ 3251 public void setLocationRelativeTo(Component c) { 3252 // target location 3253 int dx = 0, dy = 0; 3254 // target GC 3255 GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode(); 3256 Rectangle gcBounds = gc.getBounds(); 3257 3258 Dimension windowSize = getSize(); 3259 3260 // search a top-level of c 3261 Window componentWindow = SunToolkit.getContainingWindow(c); 3262 if ((c == null) || (componentWindow == null)) { 3263 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 3264 gc = ge.getDefaultScreenDevice().getDefaultConfiguration(); 3265 gcBounds = gc.getBounds(); 3266 Point centerPoint = ge.getCenterPoint(); 3267 dx = centerPoint.x - windowSize.width / 2; 3268 dy = centerPoint.y - windowSize.height / 2; 3269 } else if (!c.isShowing()) { 3270 gc = componentWindow.getGraphicsConfiguration(); 3271 gcBounds = gc.getBounds(); 3272 dx = gcBounds.x + (gcBounds.width - windowSize.width) / 2; 3273 dy = gcBounds.y + (gcBounds.height - windowSize.height) / 2; 3274 } else { 3275 gc = componentWindow.getGraphicsConfiguration(); 3276 gcBounds = gc.getBounds(); 3277 Dimension compSize = c.getSize(); 3278 Point compLocation = c.getLocationOnScreen(); 3279 dx = compLocation.x + ((compSize.width - windowSize.width) / 2); 3280 dy = compLocation.y + ((compSize.height - windowSize.height) / 2); 3281 3282 // Adjust for bottom edge being offscreen 3283 if (dy + windowSize.height > gcBounds.y + gcBounds.height) { 3284 dy = gcBounds.y + gcBounds.height - windowSize.height; 3285 if (compLocation.x - gcBounds.x + compSize.width / 2 < gcBounds.width / 2) { 3286 dx = compLocation.x + compSize.width; 3287 } else { 3288 dx = compLocation.x - windowSize.width; 3289 } 3290 } 3291 } 3292 3293 // Avoid being placed off the edge of the screen: 3294 // bottom 3295 if (dy + windowSize.height > gcBounds.y + gcBounds.height) { 3296 dy = gcBounds.y + gcBounds.height - windowSize.height; 3297 } 3298 // top 3299 if (dy < gcBounds.y) { 3300 dy = gcBounds.y; 3301 } 3302 // right 3303 if (dx + windowSize.width > gcBounds.x + gcBounds.width) { 3304 dx = gcBounds.x + gcBounds.width - windowSize.width; 3305 } 3306 // left 3307 if (dx < gcBounds.x) { 3308 dx = gcBounds.x; 3309 } 3310 3311 setLocation(dx, dy); 3312 } 3313 3314 /** 3315 * Overridden from Component. Top-level Windows should not propagate a 3316 * MouseWheelEvent beyond themselves into their owning Windows. 3317 */ 3318 void deliverMouseWheelToAncestor(MouseWheelEvent e) {} 3319 3320 /** 3321 * Overridden from Component. Top-level Windows don't dispatch to ancestors 3322 */ 3323 boolean dispatchMouseWheelToAncestor(MouseWheelEvent e) {return false;} 3324 3325 /** 3326 * Creates a new strategy for multi-buffering on this component. 3327 * Multi-buffering is useful for rendering performance. This method 3328 * attempts to create the best strategy available with the number of 3329 * buffers supplied. It will always create a {@code BufferStrategy} 3330 * with that number of buffers. 3331 * A page-flipping strategy is attempted first, then a blitting strategy 3332 * using accelerated buffers. Finally, an unaccelerated blitting 3333 * strategy is used. 3334 * <p> 3335 * Each time this method is called, 3336 * the existing buffer strategy for this component is discarded. 3337 * @param numBuffers number of buffers to create 3338 * @exception IllegalArgumentException if numBuffers is less than 1. 3339 * @exception IllegalStateException if the component is not displayable 3340 * @see #isDisplayable 3341 * @see #getBufferStrategy 3342 * @since 1.4 3343 */ 3344 public void createBufferStrategy(int numBuffers) { 3345 super.createBufferStrategy(numBuffers); 3346 } 3347 3348 /** 3349 * Creates a new strategy for multi-buffering on this component with the 3350 * required buffer capabilities. This is useful, for example, if only 3351 * accelerated memory or page flipping is desired (as specified by the 3352 * buffer capabilities). 3353 * <p> 3354 * Each time this method 3355 * is called, the existing buffer strategy for this component is discarded. 3356 * @param numBuffers number of buffers to create, including the front buffer 3357 * @param caps the required capabilities for creating the buffer strategy; 3358 * cannot be {@code null} 3359 * @exception AWTException if the capabilities supplied could not be 3360 * supported or met; this may happen, for example, if there is not enough 3361 * accelerated memory currently available, or if page flipping is specified 3362 * but not possible. 3363 * @exception IllegalArgumentException if numBuffers is less than 1, or if 3364 * caps is {@code null} 3365 * @see #getBufferStrategy 3366 * @since 1.4 3367 */ 3368 public void createBufferStrategy(int numBuffers, 3369 BufferCapabilities caps) throws AWTException { 3370 super.createBufferStrategy(numBuffers, caps); 3371 } 3372 3373 /** 3374 * Returns the {@code BufferStrategy} used by this component. This 3375 * method will return null if a {@code BufferStrategy} has not yet 3376 * been created or has been disposed. 3377 * 3378 * @return the buffer strategy used by this component 3379 * @see #createBufferStrategy 3380 * @since 1.4 3381 */ 3382 public BufferStrategy getBufferStrategy() { 3383 return super.getBufferStrategy(); 3384 } 3385 3386 Component getTemporaryLostComponent() { 3387 return temporaryLostComponent; 3388 } 3389 Component setTemporaryLostComponent(Component component) { 3390 Component previousComp = temporaryLostComponent; 3391 // Check that "component" is an acceptable focus owner and don't store it otherwise 3392 // - or later we will have problems with opposite while handling WINDOW_GAINED_FOCUS 3393 if (component == null || component.canBeFocusOwner()) { 3394 temporaryLostComponent = component; 3395 } else { 3396 temporaryLostComponent = null; 3397 } 3398 return previousComp; 3399 } 3400 3401 /** 3402 * Checks whether this window can contain focus owner. 3403 * Verifies that it is focusable and as container it can container focus owner. 3404 * @since 1.5 3405 */ 3406 boolean canContainFocusOwner(Component focusOwnerCandidate) { 3407 return super.canContainFocusOwner(focusOwnerCandidate) && isFocusableWindow(); 3408 } 3409 3410 private boolean locationByPlatform = locationByPlatformProp; 3411 3412 3413 /** 3414 * Sets whether this Window should appear at the default location for the 3415 * native windowing system or at the current location (returned by 3416 * {@code getLocation}) the next time the Window is made visible. 3417 * This behavior resembles a native window shown without programmatically 3418 * setting its location. Most windowing systems cascade windows if their 3419 * locations are not explicitly set. The actual location is determined once the 3420 * window is shown on the screen. 3421 * <p> 3422 * This behavior can also be enabled by setting the System Property 3423 * "java.awt.Window.locationByPlatform" to "true", though calls to this method 3424 * take precedence. 3425 * <p> 3426 * Calls to {@code setVisible}, {@code setLocation} and 3427 * {@code setBounds} after calling {@code setLocationByPlatform} clear 3428 * this property of the Window. 3429 * <p> 3430 * For example, after the following code is executed: 3431 * <pre> 3432 * setLocationByPlatform(true); 3433 * setVisible(true); 3434 * boolean flag = isLocationByPlatform(); 3435 * </pre> 3436 * The window will be shown at platform's default location and 3437 * {@code flag} will be {@code false}. 3438 * <p> 3439 * In the following sample: 3440 * <pre> 3441 * setLocationByPlatform(true); 3442 * setLocation(10, 10); 3443 * boolean flag = isLocationByPlatform(); 3444 * setVisible(true); 3445 * </pre> 3446 * The window will be shown at (10, 10) and {@code flag} will be 3447 * {@code false}. 3448 * 3449 * @param locationByPlatform {@code true} if this Window should appear 3450 * at the default location, {@code false} if at the current location 3451 * @throws IllegalComponentStateException if the window 3452 * is showing on screen and locationByPlatform is {@code true}. 3453 * @see #setLocation 3454 * @see #isShowing 3455 * @see #setVisible 3456 * @see #isLocationByPlatform 3457 * @see java.lang.System#getProperty(String) 3458 * @since 1.5 3459 */ 3460 public void setLocationByPlatform(boolean locationByPlatform) { 3461 synchronized (getTreeLock()) { 3462 if (locationByPlatform && isShowing()) { 3463 throw new IllegalComponentStateException("The window is showing on screen."); 3464 } 3465 this.locationByPlatform = locationByPlatform; 3466 } 3467 } 3468 3469 /** 3470 * Returns {@code true} if this Window will appear at the default location 3471 * for the native windowing system the next time this Window is made visible. 3472 * This method always returns {@code false} if the Window is showing on the 3473 * screen. 3474 * 3475 * @return whether this Window will appear at the default location 3476 * @see #setLocationByPlatform 3477 * @see #isShowing 3478 * @since 1.5 3479 */ 3480 public boolean isLocationByPlatform() { 3481 synchronized (getTreeLock()) { 3482 return locationByPlatform; 3483 } 3484 } 3485 3486 /** 3487 * {@inheritDoc} 3488 * <p> 3489 * The {@code width} or {@code height} values 3490 * are automatically enlarged if either is less than 3491 * the minimum size as specified by previous call to 3492 * {@code setMinimumSize}. 3493 * <p> 3494 * The method changes the geometry-related data. Therefore, 3495 * the native windowing system may ignore such requests, or it may modify 3496 * the requested data, so that the {@code Window} object is placed and sized 3497 * in a way that corresponds closely to the desktop settings. 3498 * 3499 * @see #getBounds 3500 * @see #setLocation(int, int) 3501 * @see #setLocation(Point) 3502 * @see #setSize(int, int) 3503 * @see #setSize(Dimension) 3504 * @see #setMinimumSize 3505 * @see #setLocationByPlatform 3506 * @see #isLocationByPlatform 3507 * @since 1.6 3508 */ 3509 public void setBounds(int x, int y, int width, int height) { 3510 synchronized (getTreeLock()) { 3511 if (getBoundsOp() == ComponentPeer.SET_LOCATION || 3512 getBoundsOp() == ComponentPeer.SET_BOUNDS) 3513 { 3514 locationByPlatform = false; 3515 } 3516 super.setBounds(x, y, width, height); 3517 } 3518 } 3519 3520 /** 3521 * {@inheritDoc} 3522 * <p> 3523 * The {@code r.width} or {@code r.height} values 3524 * will be automatically enlarged if either is less than 3525 * the minimum size as specified by previous call to 3526 * {@code setMinimumSize}. 3527 * <p> 3528 * The method changes the geometry-related data. Therefore, 3529 * the native windowing system may ignore such requests, or it may modify 3530 * the requested data, so that the {@code Window} object is placed and sized 3531 * in a way that corresponds closely to the desktop settings. 3532 * 3533 * @see #getBounds 3534 * @see #setLocation(int, int) 3535 * @see #setLocation(Point) 3536 * @see #setSize(int, int) 3537 * @see #setSize(Dimension) 3538 * @see #setMinimumSize 3539 * @see #setLocationByPlatform 3540 * @see #isLocationByPlatform 3541 * @since 1.6 3542 */ 3543 public void setBounds(Rectangle r) { 3544 setBounds(r.x, r.y, r.width, r.height); 3545 } 3546 3547 /** 3548 * Determines whether this component will be displayed on the screen. 3549 * @return {@code true} if the component and all of its ancestors 3550 * until a toplevel window are visible, {@code false} otherwise 3551 */ 3552 boolean isRecursivelyVisible() { 3553 // 5079694 fix: for a toplevel to be displayed, its parent doesn't have to be visible. 3554 // We're overriding isRecursivelyVisible to implement this policy. 3555 return visible; 3556 } 3557 3558 3559 // ******************** SHAPES & TRANSPARENCY CODE ******************** 3560 3561 /** 3562 * Returns the opacity of the window. 3563 * 3564 * @return the opacity of the window 3565 * 3566 * @see Window#setOpacity(float) 3567 * @see GraphicsDevice.WindowTranslucency 3568 * 3569 * @since 1.7 3570 */ 3571 public float getOpacity() { 3572 synchronized (getTreeLock()) { 3573 return opacity; 3574 } 3575 } 3576 3577 /** 3578 * Sets the opacity of the window. 3579 * <p> 3580 * The opacity value is in the range [0..1]. Note that setting the opacity 3581 * level of 0 may or may not disable the mouse event handling on this 3582 * window. This is a platform-dependent behavior. 3583 * <p> 3584 * The following conditions must be met in order to set the opacity value 3585 * less than {@code 1.0f}: 3586 * <ul> 3587 * <li>The {@link GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT} 3588 * translucency must be supported by the underlying system 3589 * <li>The window must be undecorated (see {@link Frame#setUndecorated} 3590 * and {@link Dialog#setUndecorated}) 3591 * <li>The window must not be in full-screen mode (see {@link 3592 * GraphicsDevice#setFullScreenWindow(Window)}) 3593 * </ul> 3594 * <p> 3595 * If the requested opacity value is less than {@code 1.0f}, and any of the 3596 * above conditions are not met, the window opacity will not change, 3597 * and the {@code IllegalComponentStateException} will be thrown. 3598 * <p> 3599 * The translucency levels of individual pixels may also be effected by the 3600 * alpha component of their color (see {@link Window#setBackground(Color)}) and the 3601 * current shape of this window (see {@link #setShape(Shape)}). 3602 * 3603 * @param opacity the opacity level to set to the window 3604 * 3605 * @throws IllegalArgumentException if the opacity is out of the range 3606 * [0..1] 3607 * @throws IllegalComponentStateException if the window is decorated and 3608 * the opacity is less than {@code 1.0f} 3609 * @throws IllegalComponentStateException if the window is in full screen 3610 * mode, and the opacity is less than {@code 1.0f} 3611 * @throws UnsupportedOperationException if the {@code 3612 * GraphicsDevice.WindowTranslucency#TRANSLUCENT TRANSLUCENT} 3613 * translucency is not supported and the opacity is less than 3614 * {@code 1.0f} 3615 * 3616 * @see Window#getOpacity 3617 * @see Window#setBackground(Color) 3618 * @see Window#setShape(Shape) 3619 * @see Frame#isUndecorated 3620 * @see Dialog#isUndecorated 3621 * @see GraphicsDevice.WindowTranslucency 3622 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency) 3623 * 3624 * @since 1.7 3625 */ 3626 public void setOpacity(float opacity) { 3627 synchronized (getTreeLock()) { 3628 if (opacity < 0.0f || opacity > 1.0f) { 3629 throw new IllegalArgumentException( 3630 "The value of opacity should be in the range [0.0f .. 1.0f]."); 3631 } 3632 if (opacity < 1.0f) { 3633 GraphicsConfiguration gc = getGraphicsConfiguration(); 3634 GraphicsDevice gd = gc.getDevice(); 3635 if (gc.getDevice().getFullScreenWindow() == this) { 3636 throw new IllegalComponentStateException( 3637 "Setting opacity for full-screen window is not supported."); 3638 } 3639 if (!gd.isWindowTranslucencySupported( 3640 GraphicsDevice.WindowTranslucency.TRANSLUCENT)) 3641 { 3642 throw new UnsupportedOperationException( 3643 "TRANSLUCENT translucency is not supported."); 3644 } 3645 } 3646 this.opacity = opacity; 3647 WindowPeer peer = (WindowPeer)getPeer(); 3648 if (peer != null) { 3649 peer.setOpacity(opacity); 3650 } 3651 } 3652 } 3653 3654 /** 3655 * Returns the shape of the window. 3656 * 3657 * The value returned by this method may not be the same as 3658 * previously set with {@code setShape(shape)}, but it is guaranteed 3659 * to represent the same shape. 3660 * 3661 * @return the shape of the window or {@code null} if no 3662 * shape is specified for the window 3663 * 3664 * @see Window#setShape(Shape) 3665 * @see GraphicsDevice.WindowTranslucency 3666 * 3667 * @since 1.7 3668 */ 3669 public Shape getShape() { 3670 synchronized (getTreeLock()) { 3671 return shape == null ? null : new Path2D.Float(shape); 3672 } 3673 } 3674 3675 /** 3676 * Sets the shape of the window. 3677 * <p> 3678 * Setting a shape cuts off some parts of the window. Only the parts that 3679 * belong to the given {@link Shape} remain visible and clickable. If 3680 * the shape argument is {@code null}, this method restores the default 3681 * shape, making the window rectangular on most platforms. 3682 * <p> 3683 * The following conditions must be met to set a non-null shape: 3684 * <ul> 3685 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT 3686 * PERPIXEL_TRANSPARENT} translucency must be supported by the 3687 * underlying system 3688 * <li>The window must be undecorated (see {@link Frame#setUndecorated} 3689 * and {@link Dialog#setUndecorated}) 3690 * <li>The window must not be in full-screen mode (see {@link 3691 * GraphicsDevice#setFullScreenWindow(Window)}) 3692 * </ul> 3693 * <p> 3694 * If the requested shape is not {@code null}, and any of the above 3695 * conditions are not met, the shape of this window will not change, 3696 * and either the {@code UnsupportedOperationException} or {@code 3697 * IllegalComponentStateException} will be thrown. 3698 * <p> 3699 * The translucency levels of individual pixels may also be effected by the 3700 * alpha component of their color (see {@link Window#setBackground(Color)}) and the 3701 * opacity value (see {@link #setOpacity(float)}). See {@link 3702 * GraphicsDevice.WindowTranslucency} for more details. 3703 * 3704 * @param shape the shape to set to the window 3705 * 3706 * @throws IllegalComponentStateException if the shape is not {@code 3707 * null} and the window is decorated 3708 * @throws IllegalComponentStateException if the shape is not {@code 3709 * null} and the window is in full-screen mode 3710 * @throws UnsupportedOperationException if the shape is not {@code 3711 * null} and {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSPARENT 3712 * PERPIXEL_TRANSPARENT} translucency is not supported 3713 * 3714 * @see Window#getShape() 3715 * @see Window#setBackground(Color) 3716 * @see Window#setOpacity(float) 3717 * @see Frame#isUndecorated 3718 * @see Dialog#isUndecorated 3719 * @see GraphicsDevice.WindowTranslucency 3720 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency) 3721 * 3722 * @since 1.7 3723 */ 3724 public void setShape(Shape shape) { 3725 synchronized (getTreeLock()) { 3726 if (shape != null) { 3727 GraphicsConfiguration gc = getGraphicsConfiguration(); 3728 GraphicsDevice gd = gc.getDevice(); 3729 if (gc.getDevice().getFullScreenWindow() == this) { 3730 throw new IllegalComponentStateException( 3731 "Setting shape for full-screen window is not supported."); 3732 } 3733 if (!gd.isWindowTranslucencySupported( 3734 GraphicsDevice.WindowTranslucency.PERPIXEL_TRANSPARENT)) 3735 { 3736 throw new UnsupportedOperationException( 3737 "PERPIXEL_TRANSPARENT translucency is not supported."); 3738 } 3739 } 3740 this.shape = (shape == null) ? null : new Path2D.Float(shape); 3741 WindowPeer peer = (WindowPeer)getPeer(); 3742 if (peer != null) { 3743 peer.applyShape(shape == null ? null : Region.getInstance(shape, null)); 3744 } 3745 } 3746 } 3747 3748 /** 3749 * Gets the background color of this window. 3750 * <p> 3751 * Note that the alpha component of the returned color indicates whether 3752 * the window is in the non-opaque (per-pixel translucent) mode. 3753 * 3754 * @return this component's background color 3755 * 3756 * @see Window#setBackground(Color) 3757 * @see Window#isOpaque 3758 * @see GraphicsDevice.WindowTranslucency 3759 */ 3760 @Override 3761 public Color getBackground() { 3762 return super.getBackground(); 3763 } 3764 3765 /** 3766 * Sets the background color of this window. 3767 * <p> 3768 * If the windowing system supports the {@link 3769 * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT PERPIXEL_TRANSLUCENT} 3770 * translucency, the alpha component of the given background color 3771 * may effect the mode of operation for this window: it indicates whether 3772 * this window must be opaque (alpha equals {@code 1.0f}) or per-pixel translucent 3773 * (alpha is less than {@code 1.0f}). If the given background color is 3774 * {@code null}, the window is considered completely opaque. 3775 * <p> 3776 * All the following conditions must be met to enable the per-pixel 3777 * transparency mode for this window: 3778 * <ul> 3779 * <li>The {@link GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT 3780 * PERPIXEL_TRANSLUCENT} translucency must be supported by the graphics 3781 * device where this window is located 3782 * <li>The window must be undecorated (see {@link Frame#setUndecorated} 3783 * and {@link Dialog#setUndecorated}) 3784 * <li>The window must not be in full-screen mode (see {@link 3785 * GraphicsDevice#setFullScreenWindow(Window)}) 3786 * </ul> 3787 * <p> 3788 * If the alpha component of the requested background color is less than 3789 * {@code 1.0f}, and any of the above conditions are not met, the background 3790 * color of this window will not change, the alpha component of the given 3791 * background color will not affect the mode of operation for this window, 3792 * and either the {@code UnsupportedOperationException} or {@code 3793 * IllegalComponentStateException} will be thrown. 3794 * <p> 3795 * When the window is per-pixel translucent, the drawing sub-system 3796 * respects the alpha value of each individual pixel. If a pixel gets 3797 * painted with the alpha color component equal to zero, it becomes 3798 * visually transparent. If the alpha of the pixel is equal to 1.0f, the 3799 * pixel is fully opaque. Interim values of the alpha color component make 3800 * the pixel semi-transparent. In this mode, the background of the window 3801 * gets painted with the alpha value of the given background color. If the 3802 * alpha value of the argument of this method is equal to {@code 0}, the 3803 * background is not painted at all. 3804 * <p> 3805 * The actual level of translucency of a given pixel also depends on window 3806 * opacity (see {@link #setOpacity(float)}), as well as the current shape of 3807 * this window (see {@link #setShape(Shape)}). 3808 * <p> 3809 * Note that painting a pixel with the alpha value of {@code 0} may or may 3810 * not disable the mouse event handling on this pixel. This is a 3811 * platform-dependent behavior. To make sure the mouse events do not get 3812 * dispatched to a particular pixel, the pixel must be excluded from the 3813 * shape of the window. 3814 * <p> 3815 * Enabling the per-pixel translucency mode may change the graphics 3816 * configuration of this window due to the native platform requirements. 3817 * 3818 * @param bgColor the color to become this window's background color. 3819 * 3820 * @throws IllegalComponentStateException if the alpha value of the given 3821 * background color is less than {@code 1.0f} and the window is decorated 3822 * @throws IllegalComponentStateException if the alpha value of the given 3823 * background color is less than {@code 1.0f} and the window is in 3824 * full-screen mode 3825 * @throws UnsupportedOperationException if the alpha value of the given 3826 * background color is less than {@code 1.0f} and {@link 3827 * GraphicsDevice.WindowTranslucency#PERPIXEL_TRANSLUCENT 3828 * PERPIXEL_TRANSLUCENT} translucency is not supported 3829 * 3830 * @see Window#getBackground 3831 * @see Window#isOpaque 3832 * @see Window#setOpacity(float) 3833 * @see Window#setShape(Shape) 3834 * @see Frame#isUndecorated 3835 * @see Dialog#isUndecorated 3836 * @see GraphicsDevice.WindowTranslucency 3837 * @see GraphicsDevice#isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency) 3838 * @see GraphicsConfiguration#isTranslucencyCapable() 3839 */ 3840 @Override 3841 public void setBackground(Color bgColor) { 3842 Color oldBg = getBackground(); 3843 super.setBackground(bgColor); 3844 if (oldBg != null && oldBg.equals(bgColor)) { 3845 return; 3846 } 3847 int oldAlpha = oldBg != null ? oldBg.getAlpha() : 255; 3848 int alpha = bgColor != null ? bgColor.getAlpha() : 255; 3849 if ((oldAlpha == 255) && (alpha < 255)) { // non-opaque window 3850 GraphicsConfiguration gc = getGraphicsConfiguration(); 3851 GraphicsDevice gd = gc.getDevice(); 3852 if (gc.getDevice().getFullScreenWindow() == this) { 3853 throw new IllegalComponentStateException( 3854 "Making full-screen window non opaque is not supported."); 3855 } 3856 if (!gc.isTranslucencyCapable()) { 3857 GraphicsConfiguration capableGC = gd.getTranslucencyCapableGC(); 3858 if (capableGC == null) { 3859 throw new UnsupportedOperationException( 3860 "PERPIXEL_TRANSLUCENT translucency is not supported"); 3861 } 3862 setGraphicsConfiguration(capableGC); 3863 } 3864 setLayersOpaque(this, false); 3865 } else if ((oldAlpha < 255) && (alpha == 255)) { 3866 setLayersOpaque(this, true); 3867 } 3868 WindowPeer peer = (WindowPeer)getPeer(); 3869 if (peer != null) { 3870 peer.setOpaque(alpha == 255); 3871 } 3872 } 3873 3874 /** 3875 * Indicates if the window is currently opaque. 3876 * <p> 3877 * The method returns {@code false} if the background color of the window 3878 * is not {@code null} and the alpha component of the color is less than 3879 * {@code 1.0f}. The method returns {@code true} otherwise. 3880 * 3881 * @return {@code true} if the window is opaque, {@code false} otherwise 3882 * 3883 * @see Window#getBackground 3884 * @see Window#setBackground(Color) 3885 * @since 1.7 3886 */ 3887 @Override 3888 public boolean isOpaque() { 3889 Color bg = getBackground(); 3890 return bg != null ? bg.getAlpha() == 255 : true; 3891 } 3892 3893 private void updateWindow() { 3894 synchronized (getTreeLock()) { 3895 WindowPeer peer = (WindowPeer)getPeer(); 3896 if (peer != null) { 3897 peer.updateWindow(); 3898 } 3899 } 3900 } 3901 3902 /** 3903 * {@inheritDoc} 3904 * 3905 * @since 1.7 3906 */ 3907 @Override 3908 public void paint(Graphics g) { 3909 if (!isOpaque()) { 3910 Graphics gg = g.create(); 3911 try { 3912 if (gg instanceof Graphics2D) { 3913 gg.setColor(getBackground()); 3914 ((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC)); 3915 gg.fillRect(0, 0, getWidth(), getHeight()); 3916 } 3917 } finally { 3918 gg.dispose(); 3919 } 3920 } 3921 super.paint(g); 3922 } 3923 3924 private static void setLayersOpaque(Component component, boolean isOpaque) { 3925 // Shouldn't use instanceof to avoid loading Swing classes 3926 // if it's a pure AWT application. 3927 if (SunToolkit.isInstanceOf(component, "javax.swing.RootPaneContainer")) { 3928 javax.swing.RootPaneContainer rpc = (javax.swing.RootPaneContainer)component; 3929 javax.swing.JRootPane root = rpc.getRootPane(); 3930 javax.swing.JLayeredPane lp = root.getLayeredPane(); 3931 Container c = root.getContentPane(); 3932 javax.swing.JComponent content = 3933 (c instanceof javax.swing.JComponent) ? (javax.swing.JComponent)c : null; 3934 lp.setOpaque(isOpaque); 3935 root.setOpaque(isOpaque); 3936 if (content != null) { 3937 content.setOpaque(isOpaque); 3938 3939 // Iterate down one level to see whether we have a JApplet 3940 // (which is also a RootPaneContainer) which requires processing 3941 int numChildren = content.getComponentCount(); 3942 if (numChildren > 0) { 3943 Component child = content.getComponent(0); 3944 // It's OK to use instanceof here because we've 3945 // already loaded the RootPaneContainer class by now 3946 if (child instanceof javax.swing.RootPaneContainer) { 3947 setLayersOpaque(child, isOpaque); 3948 } 3949 } 3950 } 3951 } 3952 } 3953 3954 3955 // ************************** MIXING CODE ******************************* 3956 3957 // A window has an owner, but it does NOT have a container 3958 @Override 3959 final Container getContainer() { 3960 return null; 3961 } 3962 3963 /** 3964 * Applies the shape to the component 3965 * @param shape Shape to be applied to the component 3966 */ 3967 @Override 3968 final void applyCompoundShape(Region shape) { 3969 // The shape calculated by mixing code is not intended to be applied 3970 // to windows or frames 3971 } 3972 3973 @Override 3974 final void applyCurrentShape() { 3975 // The shape calculated by mixing code is not intended to be applied 3976 // to windows or frames 3977 } 3978 3979 @Override 3980 final void mixOnReshaping() { 3981 // The shape calculated by mixing code is not intended to be applied 3982 // to windows or frames 3983 } 3984 3985 @Override 3986 final Point getLocationOnWindow() { 3987 return new Point(0, 0); 3988 } 3989 3990 // ****************** END OF MIXING CODE ******************************** 3991 3992 /** 3993 * Limit the given double value with the given range. 3994 */ 3995 private static double limit(double value, double min, double max) { 3996 value = Math.max(value, min); 3997 value = Math.min(value, max); 3998 return value; 3999 } 4000 4001 /** 4002 * Calculate the position of the security warning. 4003 * 4004 * This method gets the window location/size as reported by the native 4005 * system since the locally cached values may represent outdated data. 4006 * 4007 * The method is used from the native code, or via AWTAccessor. 4008 * 4009 * NOTE: this method is invoked on the toolkit thread, and therefore is not 4010 * supposed to become public/user-overridable. 4011 */ 4012 private Point2D calculateSecurityWarningPosition(double x, double y, 4013 double w, double h) 4014 { 4015 // The position according to the spec of SecurityWarning.setPosition() 4016 double wx = x + w * securityWarningAlignmentX + securityWarningPointX; 4017 double wy = y + h * securityWarningAlignmentY + securityWarningPointY; 4018 4019 // First, make sure the warning is not too far from the window bounds 4020 wx = Window.limit(wx, 4021 x - securityWarningWidth - 2, 4022 x + w + 2); 4023 wy = Window.limit(wy, 4024 y - securityWarningHeight - 2, 4025 y + h + 2); 4026 4027 // Now make sure the warning window is visible on the screen 4028 GraphicsConfiguration graphicsConfig = 4029 getGraphicsConfiguration_NoClientCode(); 4030 Rectangle screenBounds = graphicsConfig.getBounds(); 4031 Insets screenInsets = 4032 Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfig); 4033 4034 wx = Window.limit(wx, 4035 screenBounds.x + screenInsets.left, 4036 screenBounds.x + screenBounds.width - screenInsets.right 4037 - securityWarningWidth); 4038 wy = Window.limit(wy, 4039 screenBounds.y + screenInsets.top, 4040 screenBounds.y + screenBounds.height - screenInsets.bottom 4041 - securityWarningHeight); 4042 4043 return new Point2D.Double(wx, wy); 4044 } 4045 4046 static { 4047 AWTAccessor.setWindowAccessor(new AWTAccessor.WindowAccessor() { 4048 public float getOpacity(Window window) { 4049 return window.opacity; 4050 } 4051 public void setOpacity(Window window, float opacity) { 4052 window.setOpacity(opacity); 4053 } 4054 public Shape getShape(Window window) { 4055 return window.getShape(); 4056 } 4057 public void setShape(Window window, Shape shape) { 4058 window.setShape(shape); 4059 } 4060 public void setOpaque(Window window, boolean opaque) { 4061 Color bg = window.getBackground(); 4062 if (bg == null) { 4063 bg = new Color(0, 0, 0, 0); 4064 } 4065 window.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue(), 4066 opaque ? 255 : 0)); 4067 } 4068 public void updateWindow(Window window) { 4069 window.updateWindow(); 4070 } 4071 4072 public Dimension getSecurityWarningSize(Window window) { 4073 return new Dimension(window.securityWarningWidth, 4074 window.securityWarningHeight); 4075 } 4076 4077 public void setSecurityWarningSize(Window window, int width, int height) 4078 { 4079 window.securityWarningWidth = width; 4080 window.securityWarningHeight = height; 4081 } 4082 4083 public void setSecurityWarningPosition(Window window, 4084 Point2D point, float alignmentX, float alignmentY) 4085 { 4086 window.securityWarningPointX = point.getX(); 4087 window.securityWarningPointY = point.getY(); 4088 window.securityWarningAlignmentX = alignmentX; 4089 window.securityWarningAlignmentY = alignmentY; 4090 4091 synchronized (window.getTreeLock()) { 4092 WindowPeer peer = (WindowPeer)window.getPeer(); 4093 if (peer != null) { 4094 peer.repositionSecurityWarning(); 4095 } 4096 } 4097 } 4098 4099 public Point2D calculateSecurityWarningPosition(Window window, 4100 double x, double y, double w, double h) 4101 { 4102 return window.calculateSecurityWarningPosition(x, y, w, h); 4103 } 4104 4105 public void setLWRequestStatus(Window changed, boolean status) { 4106 changed.syncLWRequests = status; 4107 } 4108 4109 public boolean isAutoRequestFocus(Window w) { 4110 return w.autoRequestFocus; 4111 } 4112 4113 public boolean isTrayIconWindow(Window w) { 4114 return w.isTrayIconWindow; 4115 } 4116 4117 public void setTrayIconWindow(Window w, boolean isTrayIconWindow) { 4118 w.isTrayIconWindow = isTrayIconWindow; 4119 } 4120 }); // WindowAccessor 4121 } // static 4122 4123 // a window doesn't need to be updated in the Z-order. 4124 @Override 4125 void updateZOrder() {} 4126 4127 } // class Window 4128 4129 4130 /** 4131 * This class is no longer used, but is maintained for Serialization 4132 * backward-compatibility. 4133 */ 4134 class FocusManager implements java.io.Serializable { 4135 Container focusRoot; 4136 Component focusOwner; 4137 4138 /* 4139 * JDK 1.1 serialVersionUID 4140 */ 4141 static final long serialVersionUID = 2491878825643557906L; 4142 }