History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/awt/Window.java (1 of 18352 files). Show all

Unified · Split

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