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