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