/* * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * A {@code Window} object is a top-level window with no borders and no * menubar. * The default layout for a window is {@code BorderLayout}. * <p> * A window must have either a frame, dialog, or another window defined as its * owner when it's constructed. * <p> * In a multi-screen environment, you can create a {@code Window} * on a different screen device by constructing the {@code Window} * with {@link #Window(Window, GraphicsConfiguration)}. The * {@code GraphicsConfiguration} object is one of the * {@code GraphicsConfiguration} objects of the target screen device. * <p> * In a virtual device multi-screen environment in which the desktop * area could span multiple physical screen devices, the bounds of all * configurations are relative to the virtual device coordinate system. * The origin of the virtual-coordinate system is at the upper left-hand * corner of the primary physical screen. Depending on the location of * the primary screen in the virtual device, negative coordinates are * possible, as shown in the following figure. * <p> * <img src="doc-files/MultiScreen.gif" * alt="Diagram shows virtual device containing 4 physical screens. Primary * physical screen shows coords (0,0), other screen shows (-80,-100)." * style="margin: 7px 10px;"> * <p> * In such an environment, when calling {@code setLocation}, * you must pass a virtual coordinate to this method. Similarly, * calling {@code getLocationOnScreen} on a {@code Window} returns * virtual device coordinates. Call the {@code getBounds} method * of a {@code GraphicsConfiguration} to find its origin in the virtual * coordinate system. * <p> * The following code sets the location of a {@code Window} * at (10, 10) relative to the origin of the physical screen * of the corresponding {@code GraphicsConfiguration}. If the * bounds of the {@code GraphicsConfiguration} is not taken * into account, the {@code Window} location would be set * at (10, 10) relative to the virtual-coordinate system and would appear * on the primary physical screen, which might be different from the * physical screen of the specified {@code GraphicsConfiguration}. * * <pre> * Window w = new Window(Window owner, GraphicsConfiguration gc); * Rectangle bounds = gc.getBounds(); * w.setLocation(10 + bounds.x, 10 + bounds.y); * </pre> * * <p> * Note: the location and size of top-level windows (including * {@code Window}s, {@code Frame}s, and {@code Dialog}s) * are under the control of the desktop's window management system. * Calls to {@code setLocation}, {@code setSize}, and * {@code setBounds} are requests (not directives) which are * forwarded to the window management system. Every effort will be * made to honor such requests. However, in some cases the window * management system may ignore such requests, or modify the requested * geometry in order to place and size the {@code Window} in a way * that more closely matches the desktop settings. * <p> * Visual effects such as halos, shadows, motion effects and animations may be * applied to the window by the desktop window management system. These are * outside the knowledge and control of the AWT and so for the purposes of this * specification are not considered part of the top-level window. * <p> * Due to the asynchronous nature of native event handling, the results * returned by {@code getBounds}, {@code getLocation}, * {@code getLocationOnScreen}, and {@code getSize} might not * reflect the actual geometry of the Window on screen until the last * request has been processed. During the processing of subsequent * requests these values might change accordingly while the window * management system fulfills the requests. * <p> * An application may set the size and location of an invisible * {@code Window} arbitrarily, but the window management system may * subsequently change its size and/or location when the * {@code Window} is made visible. One or more {@code ComponentEvent}s * will be generated to indicate the new geometry. * <p> * Windows are capable of generating the following WindowEvents: * WindowOpened, WindowClosed, WindowGainedFocus, WindowLostFocus. * * @author Sami Shaio * @author Arthur van Hoff * @see WindowEvent * @see #addWindowListener * @see java.awt.BorderLayout * @since 1.0
*/ publicclass Window extends Container implements Accessible {
/** * Enumeration of available <i>window types</i>. * * A window type defines the generic visual appearance and behavior of a * top-level window. For example, the type may affect the kind of * decorations of a decorated {@code Frame} or {@code Dialog} instance. * <p> * Some platforms may not fully support a certain window type. Depending on * the level of support, some properties of the window type may be * disobeyed. * * @see #getType * @see #setType * @since 1.7
*/ publicstaticenum Type { /** * Represents a <i>normal</i> window. * * This is the default type for objects of the {@code Window} class or * its descendants. Use this type for regular top-level windows.
*/
NORMAL,
/** * Represents a <i>utility</i> window. * * A utility window is usually a small window such as a toolbar or a * palette. The native system may render the window with smaller * title-bar if the window is either a {@code Frame} or a {@code * Dialog} object, and if it has its decorations enabled.
*/
UTILITY,
/** * Represents a <i>popup</i> window. * * A popup window is a temporary window such as a drop-down menu or a * tooltip. On some platforms, windows of that type may be forcibly * made undecorated even if they are instances of the {@code Frame} or * {@code Dialog} class, and have decorations enabled.
*/
POPUP
}
/** * This represents the warning message that is * to be displayed in a non secure window. ie : * a window that has a security manager installed that denies * {@code AWTPermission("showWindowWithoutWarningBanner")}. * This message can be displayed anywhere in the window. * * @serial * @see #getWarningString
*/
String warningString;
/** * {@code icons} is the graphical way we can * represent the frames and dialogs. * {@code Window} can't display icon but it's * being inherited by owned {@code Dialog}s. * * @serial * @see #getIconImages * @see #setIconImages
*/ transient java.util.List<Image> icons;
/** * Holds the reference to the component which last had focus in this window * before it lost focus.
*/ privatetransient Component temporaryLostComponent;
staticboolean systemSyncLWRequests = false;
/** * Focus transfers should be synchronous for lightweight component requests.
*/ boolean syncLWRequests = false; transientboolean beforeFirstShow = true; privatetransientboolean disposing = false; transient WindowDisposerRecord disposerRecord = null;
staticfinalint OPENED = 0x01;
/** * An Integer value representing the Window State. * * @serial * @since 1.2 * @see #show
*/ int state;
/** * A boolean value representing Window always-on-top state * @since 1.5 * @serial * @see #setAlwaysOnTop * @see #isAlwaysOnTop
*/ privateboolean alwaysOnTop;
/** * Contains all the windows that have a peer object associated, * i. e. between addNotify() and removeNotify() calls. The list * of all Window instances can be obtained from AppContext object. * * @since 1.6
*/ privatestaticfinal IdentityArrayList<Window> allWindows = new IdentityArrayList<Window>();
/** * A vector containing all the windows this * window currently owns. * @since 1.2 * @see #getOwnedWindows
*/ transient Vector<WeakReference<Window>> ownedWindowList = new Vector<WeakReference<Window>>();
/* * We insert a weak reference into the Vector of all Windows in AppContext * instead of 'this' so that garbage collection can still take place * correctly.
*/ privatetransient WeakReference<Window> weakThis;
transientboolean showWithParent;
/** * Contains the modal dialog that blocks this window, or null * if the window is unblocked. * * @since 1.6
*/ transient Dialog modalBlocker;
/** * Indicates whether this Window can become the focused Window. * * @serial * @see #getFocusableWindowState * @see #setFocusableWindowState * @since 1.4
*/ privateboolean focusableWindowState = true;
/** * Indicates whether this window should receive focus on * subsequently being shown (with a call to {@code setVisible(true)}), or * being moved to the front (with a call to {@code toFront()}). * * @serial * @see #setAutoRequestFocus * @see #isAutoRequestFocus * @since 1.7
*/ privatevolatileboolean autoRequestFocus = true;
/* * Indicates that this window is being shown. This flag is set to true at * the beginning of show() and to false at the end of show(). * * @see #show() * @see Dialog#shouldBlock
*/ transientboolean isInShow = false;
/** * The opacity level of the window * * @serial * @see #setOpacity(float) * @see #getOpacity() * @since 1.7
*/ privatevolatilefloat opacity = 1.0f;
/** * The shape assigned to this window. This field is set to {@code null} if * no shape is set (rectangular window). * * @serial * @see #getShape() * @see #setShape(Shape) * @since 1.7
*/
@SuppressWarnings("serial") // Not statically typed as Serializable private Shape shape = null;
privatestaticfinal String base = "win"; privatestaticint nameCounter = 0;
/** * Use serialVersionUID from JDK 1.1 for interoperability.
*/
@Serial privatestaticfinallong serialVersionUID = 4497834738069338734L;
/** * These fields are initialized in the native peer code * or via AWTAccessor's WindowAccessor.
*/ privatetransientvolatileint securityWarningWidth; privatetransientvolatileint securityWarningHeight;
static { /* ensure that the necessary native libraries are loaded */
Toolkit.loadLibraries(); if (!GraphicsEnvironment.isHeadless()) {
initIDs();
}
@SuppressWarnings("removal")
String s = java.security.AccessController.doPrivileged( new GetPropertyAction("java.awt.syncLWRequests"));
systemSyncLWRequests = "true".equals(s);
@SuppressWarnings("removal")
String s2 = java.security.AccessController.doPrivileged( new GetPropertyAction("java.awt.Window.locationByPlatform"));
locationByPlatformProp = "true".equals(s2);
}
/** * Initialize JNI field and method IDs for fields that may be accessed from C.
*/ privatestaticnativevoid initIDs();
/** * Constructs a new, initially invisible window in default size with the * specified {@code GraphicsConfiguration}. * <p> * If there is a security manager, then it is invoked to check * {@code AWTPermission("showWindowWithoutWarningBanner")} * to determine whether or not the window must be displayed with * a warning banner. * * @param gc the {@code GraphicsConfiguration} of the target screen * device. If {@code gc} is {@code null}, the system default * {@code GraphicsConfiguration} is assumed * @throws IllegalArgumentException if {@code gc} * is not from a screen device * @throws HeadlessException when * {@code GraphicsEnvironment.isHeadless()} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless
*/
Window(GraphicsConfiguration gc) {
init(gc);
}
transient Object anchor = new Object(); staticclass WindowDisposerRecord implements sun.java2d.DisposerRecord {
WeakReference<Window> owner; final WeakReference<Window> weakThis; final WeakReference<AppContext> context;
if (gc.getDevice().getType() !=
GraphicsDevice.TYPE_RASTER_SCREEN) { thrownew IllegalArgumentException("not a screen device");
}
setLayout(new BorderLayout());
/* offset the initial location with the original of the screen */ /* and any insets */
Rectangle screenBounds = gc.getBounds();
Insets screenInsets = getToolkit().getScreenInsets(gc); int x = getX() + screenBounds.x + screenInsets.left; int y = getY() + screenBounds.y + screenInsets.top; if (x != this.x || y != this.y) {
setLocation(x, y); /* reset after setLocation */
setLocationByPlatform(locationByPlatformProp);
}
modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
disposerRecord = new WindowDisposerRecord(appContext, this);
sun.java2d.Disposer.addRecord(anchor, disposerRecord);
SunToolkit.checkAndSetPolicy(this);
}
/** * Constructs a new, initially invisible window in the default size. * <p> * If there is a security manager set, it is invoked to check * {@code AWTPermission("showWindowWithoutWarningBanner")}. * If that check fails with a {@code SecurityException} then a warning * banner is created. * * @throws HeadlessException when * {@code GraphicsEnvironment.isHeadless()} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless
*/
Window() throws HeadlessException {
GraphicsEnvironment.checkHeadless();
init((GraphicsConfiguration)null);
}
/** * Constructs a new, initially invisible window with the specified * {@code Frame} as its owner. The window will not be focusable * unless its owner is showing on the screen. * <p> * If there is a security manager set, it is invoked to check * {@code AWTPermission("showWindowWithoutWarningBanner")}. * If that check fails with a {@code SecurityException} then a warning * banner is created. * * @param owner the {@code Frame} to act as owner or {@code null} * if this window has no owner * @throws IllegalArgumentException if the {@code owner}'s * {@code GraphicsConfiguration} is not from a screen device * @throws HeadlessException when * {@code GraphicsEnvironment.isHeadless} returns {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless * @see #isShowing
*/ public Window(Frame owner) { this(owner == null ? (GraphicsConfiguration)null :
owner.getGraphicsConfiguration());
ownedInit(owner);
}
/** * Constructs a new, initially invisible window with the specified * {@code Window} as its owner. This window will not be focusable * unless its nearest owning {@code Frame} or {@code Dialog} * is showing on the screen. * <p> * If there is a security manager set, it is invoked to check * {@code AWTPermission("showWindowWithoutWarningBanner")}. * If that check fails with a {@code SecurityException} then a * warning banner is created. * * @param owner the {@code Window} to act as owner or * {@code null} if this window has no owner * @throws IllegalArgumentException if the {@code owner}'s * {@code GraphicsConfiguration} is not from a screen device * @throws HeadlessException when * {@code GraphicsEnvironment.isHeadless()} returns * {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless * @see #isShowing * * @since 1.2
*/ public Window(Window owner) { this(owner == null ? (GraphicsConfiguration)null :
owner.getGraphicsConfiguration());
ownedInit(owner);
}
/** * Constructs a new, initially invisible window with the specified owner * {@code Window} and a {@code GraphicsConfiguration} * of a screen device. The Window will not be focusable unless * its nearest owning {@code Frame} or {@code Dialog} * is showing on the screen. * <p> * If there is a security manager set, it is invoked to check * {@code AWTPermission("showWindowWithoutWarningBanner")}. If that * check fails with a {@code SecurityException} then a warning banner * is created. * * @param owner the window to act as owner or {@code null} * if this window has no owner * @param gc the {@code GraphicsConfiguration} of the target * screen device; if {@code gc} is {@code null}, * the system default {@code GraphicsConfiguration} is assumed * @throws IllegalArgumentException if {@code gc} * is not from a screen device * @throws HeadlessException when * {@code GraphicsEnvironment.isHeadless()} returns * {@code true} * * @see java.awt.GraphicsEnvironment#isHeadless * @see GraphicsConfiguration#getBounds * @see #isShowing * @since 1.3
*/ public Window(Window owner, GraphicsConfiguration gc) { this(gc);
ownedInit(owner);
}
// WindowDisposerRecord requires a proper value of parent field.
disposerRecord.updateOwner();
}
/** * Construct a name for this component. Called by getName() when the * name is null.
*/
String constructComponentName() { synchronized (Window.class) { return base + nameCounter++;
}
}
/** * Returns the sequence of images to be displayed as the icon for this window. * <p> * This method returns a copy of the internally stored list, so all operations * on the returned object will not affect the window's behavior. * * @return the copy of icon images' list for this window, or * empty list if this window doesn't have icon images. * @see #setIconImages * @see #setIconImage(Image) * @since 1.6
*/ public java.util.List<Image> getIconImages() {
java.util.List<Image> icons = this.icons; if (icons == null || icons.size() == 0) { returnnew ArrayList<Image>();
} returnnew ArrayList<Image>(icons);
}
/** * Sets the sequence of images to be displayed as the icon * for this window. Subsequent calls to {@code getIconImages} will * always return a copy of the {@code icons} list. * <p> * Depending on the platform capabilities one or several images * of different dimensions will be used as the window's icon. * <p> * The {@code icons} list can contain {@code MultiResolutionImage} images also. * Suitable image depending on screen resolution is extracted from * base {@code MultiResolutionImage} image and added to the icons list * while base resolution image is removed from list. * The {@code icons} list is scanned for the images of most * appropriate dimensions from the beginning. If the list contains * several images of the same size, the first will be used. * <p> * Ownerless windows with no icon specified use platform-default icon. * The icon of an owned window may be inherited from the owner * unless explicitly overridden. * Setting the icon to {@code null} or empty list restores * the default behavior. * <p> * Note : Native windowing systems may use different images of differing * dimensions to represent a window, depending on the context (e.g. * window decoration, window list, taskbar, etc.). They could also use * just a single image for all contexts or no image at all. * * @param icons the list of icon images to be displayed. * @see #getIconImages() * @see #setIconImage(Image) * @since 1.6
*/ publicsynchronizedvoid setIconImages(java.util.List<? extends Image> icons) { this.icons = (icons == null) ? new ArrayList<Image>() : new ArrayList<Image>(icons);
WindowPeer peer = (WindowPeer)this.peer; if (peer != null) {
peer.updateIconImages();
} // Always send a property change event
firePropertyChange("iconImage", null, null);
}
/** * Sets the image to be displayed as the icon for this window. * <p> * This method can be used instead of {@link #setIconImages setIconImages()} * to specify a single image as a window's icon. * <p> * The following statement: * <pre> * setIconImage(image); * </pre> * is equivalent to: * <pre> * ArrayList<Image> imageList = new ArrayList<Image>(); * imageList.add(image); * setIconImages(imageList); * </pre> * <p> * Note : Native windowing systems may use different images of differing * dimensions to represent a window, depending on the context (e.g. * window decoration, window list, taskbar, etc.). They could also use * just a single image for all contexts or no image at all. * * @param image the icon image to be displayed. * @see #setIconImages * @see #getIconImages() * @since 1.6
*/ publicvoid setIconImage(Image image) {
ArrayList<Image> imageList = new ArrayList<Image>(); if (image != null) {
imageList.add(image);
}
setIconImages(imageList);
}
/** * Makes this Window displayable by creating the connection to its * native screen resource. * This method is called internally by the toolkit and should * not be called directly by programs. * @see Component#isDisplayable * @see Container#removeNotify * @since 1.0
*/ publicvoid addNotify() { synchronized (getTreeLock()) {
Container parent = this.parent; if (parent != null && parent.peer == null) {
parent.addNotify();
} if (peer == null) {
peer = getComponentFactory().createWindow(this);
} synchronized (allWindows) {
allWindows.add(this);
} super.addNotify();
}
}
/** * Causes this Window to be sized to fit the preferred size * and layouts of its subcomponents. The resulting width and * height of the window are automatically enlarged if either * of dimensions is less than the minimum size as specified * by the previous call to the {@code setMinimumSize} method. * <p> * If the window and/or its owner are not displayable yet, * both of them are made displayable before calculating * the preferred size. The Window is validated after its * size is being calculated. * * @see Component#isDisplayable * @see #setMinimumSize
*/
@SuppressWarnings("deprecation") publicvoid pack() {
Container parent = this.parent; if (parent != null && parent.peer == null) {
parent.addNotify();
} if (peer == null) {
addNotify();
}
Dimension newSize = getPreferredSize(); if (peer != null) {
setClientSize(newSize.width, newSize.height);
}
if(beforeFirstShow) {
isPacked = true;
}
validateUnconditionally();
}
/** * Sets the minimum size of this window to a constant * value. Subsequent calls to {@code getMinimumSize} * will always return this value. If current window's * size is less than {@code minimumSize} the size of the * window is automatically enlarged to honor the minimum size. * <p> * If the {@code setSize} or {@code setBounds} methods * are called afterwards with a width or height less than * that was specified by the {@code setMinimumSize} method * the window is automatically enlarged to meet * the {@code minimumSize} value. The {@code minimumSize} * value also affects the behaviour of the {@code pack} method. * <p> * The default behavior is restored by setting the minimum size * parameter to the {@code null} value. * <p> * Resizing operation may be restricted if the user tries * to resize window below the {@code minimumSize} value. * This behaviour is platform-dependent. * * @param minimumSize the new minimum size of this window * @see Component#setMinimumSize * @see #getMinimumSize * @see #isMinimumSizeSet * @see #setSize(Dimension) * @see #pack * @since 1.6
*/ publicvoid setMinimumSize(Dimension minimumSize) { synchronized (getTreeLock()) { super.setMinimumSize(minimumSize);
Dimension size = getSize(); if (isMinimumSizeSet()) { if (size.width < minimumSize.width || size.height < minimumSize.height) { int nw = Math.max(width, minimumSize.width); int nh = Math.max(height, minimumSize.height);
setSize(nw, nh);
}
} if (peer != null) {
((WindowPeer)peer).updateMinimumSize();
}
}
}
/** * {@inheritDoc} * <p> * The {@code d.width} and {@code d.height} values * are automatically enlarged if either is less than * the minimum size as specified by previous call to * {@code setMinimumSize}. * <p> * The method changes the geometry-related data. Therefore, * the native windowing system may ignore such requests, or it may modify * the requested data, so that the {@code Window} object is placed and sized * in a way that corresponds closely to the desktop settings. * * @see #getSize * @see #setBounds * @see #setMinimumSize * @since 1.6
*/ publicvoid setSize(Dimension d) { super.setSize(d);
}
/** * {@inheritDoc} * <p> * The {@code width} and {@code height} values * are automatically enlarged if either is less than * the minimum size as specified by previous call to * {@code setMinimumSize}. * <p> * The method changes the geometry-related data. Therefore, * the native windowing system may ignore such requests, or it may modify * the requested data, so that the {@code Window} object is placed and sized * in a way that corresponds closely to the desktop settings. * * @see #getSize * @see #setBounds * @see #setMinimumSize * @since 1.6
*/ publicvoid setSize(int width, int height) { super.setSize(width, height);
}
/** * {@inheritDoc} * <p> * The method changes the geometry-related data. Therefore, * the native windowing system may ignore such requests, or it may modify * the requested data, so that the {@code Window} object is placed and sized * in a way that corresponds closely to the desktop settings.
*/
@Override publicvoid setLocation(int x, int y) { super.setLocation(x, y);
}
/** * {@inheritDoc} * <p> * The method changes the geometry-related data. Therefore, * the native windowing system may ignore such requests, or it may modify * the requested data, so that the {@code Window} object is placed and sized * in a way that corresponds closely to the desktop settings.
*/
@Override publicvoid setLocation(Point p) { super.setLocation(p);
}
/** * @deprecated As of JDK version 1.1, * replaced by {@code setBounds(int, int, int, int)}.
*/
@Deprecated publicvoid reshape(int x, int y, int width, int height) { if (isMinimumSizeSet()) {
Dimension minSize = getMinimumSize(); if (width < minSize.width) {
width = minSize.width;
} if (height < minSize.height) {
height = minSize.height;
}
} super.reshape(x, y, width, height);
}
void setClientSize(int w, int h) { synchronized (getTreeLock()) {
setBoundsOp(ComponentPeer.SET_CLIENT_SIZE);
setBounds(x, y, w, h);
}
}
privatestaticfinal AtomicBoolean
beforeFirstWindowShown = new AtomicBoolean(true);
finalvoid closeSplashScreen() { if (isTrayIconWindow) { return;
} if (beforeFirstWindowShown.getAndSet(false)) { // We don't use SplashScreen.getSplashScreen() to avoid instantiating // the object if it hasn't been requested by user code explicitly
SunToolkit.closeSplashScreen();
SplashScreen.markClosed();
}
}
/** * Shows or hides this {@code Window} depending on the value of parameter * {@code b}. * <p> * If the method shows the window then the window is also made * focused under the following conditions: * <ul> * <li> The {@code Window} meets the requirements outlined in the * {@link #isFocusableWindow} method. * <li> The {@code Window}'s {@code autoRequestFocus} property is of the {@code true} value. * <li> Native windowing system allows the {@code Window} to get focused. * </ul> * There is an exception for the second condition (the value of the * {@code autoRequestFocus} property). The property is not taken into account if the * window is a modal dialog, which blocks the currently focused window. * <p> * Developers must never assume that the window is the focused or active window * until it receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED event. * @param b if {@code true}, makes the {@code Window} visible, * otherwise hides the {@code Window}. * If the {@code Window} and/or its owner * are not yet displayable, both are made displayable. The * {@code Window} will be validated prior to being made visible. * If the {@code Window} is already visible, this will bring the * {@code Window} to the front.<p> * If {@code false}, hides this {@code Window}, its subcomponents, and all * of its owned children. * The {@code Window} and its subcomponents can be made visible again * with a call to {@code #setVisible(true)}. * @see java.awt.Component#isDisplayable * @see java.awt.Component#setVisible * @see java.awt.Window#toFront * @see java.awt.Window#dispose * @see java.awt.Window#setAutoRequestFocus * @see java.awt.Window#isFocusableWindow
*/ publicvoid setVisible(boolean b) { super.setVisible(b);
}
/** * Makes the Window visible. If the Window and/or its owner * are not yet displayable, both are made displayable. The * Window will be validated prior to being made visible. * If the Window is already visible, this will bring the Window * to the front. * @see Component#isDisplayable * @see #toFront * @deprecated As of JDK version 1.5, replaced by * {@link #setVisible(boolean)}.
*/
@Deprecated publicvoid show() { if (peer == null) {
addNotify();
}
validateUnconditionally();
isInShow = true; if (visible) {
toFront();
} else {
beforeFirstShow = false;
closeSplashScreen();
Dialog.checkShouldBeBlocked(this); super.show();
locationByPlatform = false; for (int i = 0; i < ownedWindowList.size(); i++) {
Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.showWithParent) {
child.show();
child.showWithParent = false;
} // endif
} // endfor if (!isModalBlocked()) {
updateChildrenBlocking();
} else { // fix for 6532736: after this window is shown, its blocker // should be raised to front
modalBlocker.toFront_NoClientCode();
} if (thisinstanceof Frame || thisinstanceof Dialog) {
updateChildFocusableWindowState(this);
}
}
isInShow = false;
// If first time shown, generate WindowOpened event if ((state & OPENED) == 0) {
postWindowEvent(WindowEvent.WINDOW_OPENED);
state |= OPENED;
}
}
staticvoid updateChildFocusableWindowState(Window w) { if (w.peer != null && w.isShowing()) {
((WindowPeer)w.peer).updateFocusableWindowState();
} for (int i = 0; i < w.ownedWindowList.size(); i++) {
Window child = w.ownedWindowList.elementAt(i).get(); if (child != null) {
updateChildFocusableWindowState(child);
}
}
}
synchronizedvoid postWindowEvent(int id) { if (windowListener != null
|| (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0
|| Toolkit.enabledOnToolkit(AWTEvent.WINDOW_EVENT_MASK)) {
WindowEvent e = new WindowEvent(this, id);
Toolkit.getEventQueue().postEvent(e);
}
}
/** * Hide this Window, its subcomponents, and all of its owned children. * The Window and its subcomponents can be made visible again * with a call to {@code show}. * @see #show * @see #dispose * @deprecated As of JDK version 1.5, replaced by * {@link #setVisible(boolean)}.
*/
@Deprecated publicvoid hide() { synchronized(ownedWindowList) { for (int i = 0; i < ownedWindowList.size(); i++) {
Window child = ownedWindowList.elementAt(i).get(); if ((child != null) && child.visible) {
child.hide();
child.showWithParent = true;
}
}
} if (isModalBlocked()) {
modalBlocker.unblockWindow(this);
} super.hide();
locationByPlatform = false;
}
finalvoid clearMostRecentFocusOwnerOnHide() { /* do nothing */
}
/** * Releases all of the native screen resources used by this * {@code Window}, its subcomponents, and all of its owned * children. That is, the resources for these {@code Component}s * will be destroyed, any memory they consume will be returned to the * OS, and they will be marked as undisplayable. * <p> * The {@code Window} and its subcomponents can be made displayable * again by rebuilding the native resources with a subsequent call to * {@code pack} or {@code show}. The states of the recreated * {@code Window} and its subcomponents will be identical to the * states of these objects at the point where the {@code Window} * was disposed (not accounting for additional modifications between * those actions). * <p> * <b>Note</b>: When the last displayable window * within the Java virtual machine (VM) is disposed of, the VM may * terminate. See <a href="doc-files/AWTThreadIssues.html#Autoshutdown"> * AWT Threading Issues</a> for more information. * @see Component#isDisplayable * @see #pack * @see #show
*/ publicvoid dispose() {
doDispose();
}
/* * Fix for 4872170. * If dispose() is called on parent then its children have to be disposed as well * as reported in javadoc. So we need to implement this functionality even if a * child overrides dispose() in a wrong way without calling super.dispose().
*/ void disposeImpl() {
dispose(); if (peer != null) {
doDispose();
}
}
void doDispose() { class DisposeAction implements Runnable { publicvoid run() {
disposing = true; try { // Check if this window is the fullscreen window for the // device. Exit the fullscreen mode prior to disposing // of the window if that's the case.
GraphicsDevice gd = getGraphicsConfiguration().getDevice(); if (gd.getFullScreenWindow() == Window.this) {
gd.setFullScreenWindow(null);
}
Object[] ownedWindowArray; synchronized(ownedWindowList) {
ownedWindowArray = new Object[ownedWindowList.size()];
ownedWindowList.copyInto(ownedWindowArray);
} for (int i = 0; i < ownedWindowArray.length; i++) {
Window child = (Window) (((WeakReference)
(ownedWindowArray[i])).get()); if (child != null) {
child.disposeImpl();
}
}
hide();
beforeFirstShow = true;
removeNotify(); synchronized (inputContextLock) { if (inputContext != null) {
inputContext.dispose();
inputContext = null;
}
}
clearCurrentFocusCycleRootOnHide();
} finally {
disposing = false;
}
}
} boolean fireWindowClosedEvent = isDisplayable();
DisposeAction action = new DisposeAction(); if (EventQueue.isDispatchThread()) {
action.run();
} else { try {
EventQueue.invokeAndWait(this, action);
} catch (InterruptedException e) {
System.err.println("Disposal was interrupted:");
e.printStackTrace();
} catch (InvocationTargetException e) {
System.err.println("Exception during disposal:");
e.printStackTrace();
}
} // Execute outside the Runnable because postWindowEvent is // synchronized on (this). We don't need to synchronize the call // on the EventQueue anyways. if (fireWindowClosedEvent) {
postWindowEvent(WindowEvent.WINDOW_CLOSED);
}
}
/* * Should only be called while holding the tree lock. * It's overridden here because parent == owner in Window, * and we shouldn't adjust counter on owner
*/ void adjustListeningChildrenOnParent(long mask, int num) {
}
// Should only be called while holding tree lock void adjustDescendantsOnParent(int num) { // do nothing since parent == owner and we shouldn't // adjust counter on owner
}
/** * If this Window is visible, brings this Window to the front and may make * it the focused Window. * <p> * Places this Window at the top of the stacking order and shows it in * front of any other Windows in this VM. No action will take place if this * Window is not visible. Some platforms do not allow Windows which own * other Windows to appear on top of those owned Windows. Some platforms * may not permit this VM to place its Windows above windows of native * applications, or Windows of other VMs. This permission may depend on * whether a Window in this VM is already focused. Every attempt will be * made to move this Window as high as possible in the stacking order; * however, developers should not assume that this method will move this * Window above all other windows in every situation. * <p> * Developers must never assume that this Window is the focused or active * Window until this Window receives a WINDOW_GAINED_FOCUS or WINDOW_ACTIVATED * event. On platforms where the top-most window is the focused window, this * method will <b>probably</b> focus this Window (if it is not already focused) * under the following conditions: * <ul> * <li> The window meets the requirements outlined in the * {@link #isFocusableWindow} method. * <li> The window's property {@code autoRequestFocus} is of the * {@code true} value. * <li> Native windowing system allows the window to get focused. * </ul> * On platforms where the stacking order does not typically affect the focused * window, this method will <b>probably</b> leave the focused and active * Windows unchanged. * <p> * If this method causes this Window to be focused, and this Window is a * Frame or a Dialog, it will also become activated. If this Window is * focused, but it is not a Frame or a Dialog, then the first Frame or * Dialog that is an owner of this Window will be activated. * <p> * If this window is blocked by modal dialog, then the blocking dialog * is brought to the front and remains above the blocked window. * * @see #toBack * @see #setAutoRequestFocus * @see #isFocusableWindow
*/ publicvoid toFront() {
toFront_NoClientCode();
}
// This functionality is implemented in a final package-private method // to insure that it cannot be overridden by client subclasses. finalvoid toFront_NoClientCode() { if (visible) {
WindowPeer peer = (WindowPeer)this.peer; if (peer != null) {
peer.toFront();
} if (isModalBlocked()) {
modalBlocker.toFront_NoClientCode();
}
}
}
/** * If this Window is visible, sends this Window to the back and may cause * it to lose focus or activation if it is the focused or active Window. * <p> * Places this Window at the bottom of the stacking order and shows it * behind any other Windows in this VM. No action will take place is this * Window is not visible. Some platforms do not allow Windows which are * owned by other Windows to appear below their owners. Every attempt will * be made to move this Window as low as possible in the stacking order; * however, developers should not assume that this method will move this * Window below all other windows in every situation. * <p> * Because of variations in native windowing systems, no guarantees about * changes to the focused and active Windows can be made. Developers must * never assume that this Window is no longer the focused or active Window * until this Window receives a WINDOW_LOST_FOCUS or WINDOW_DEACTIVATED * event. On platforms where the top-most window is the focused window, * this method will <b>probably</b> cause this Window to lose focus. In * that case, the next highest, focusable Window in this VM will receive * focus. On platforms where the stacking order does not typically affect * the focused window, this method will <b>probably</b> leave the focused * and active Windows unchanged. * * @see #toFront
*/ publicvoid toBack() {
toBack_NoClientCode();
}
// This functionality is implemented in a final package-private method // to insure that it cannot be overridden by client subclasses. finalvoid toBack_NoClientCode() { if(isAlwaysOnTop()) { try {
setAlwaysOnTop(false);
}catch(SecurityException e) {
}
} if (visible) {
WindowPeer peer = (WindowPeer)this.peer; if (peer != null) {
peer.toBack();
}
}
}
/** * Returns the toolkit of this frame. * @return the toolkit of this window. * @see Toolkit * @see Toolkit#getDefaultToolkit * @see Component#getToolkit
*/ public Toolkit getToolkit() { return Toolkit.getDefaultToolkit();
}
/** * Gets the warning string that is displayed with this window. * If this window is insecure, the warning string is displayed * somewhere in the visible area of the window. A window is * insecure if there is a security manager and the security * manager denies * {@code AWTPermission("showWindowWithoutWarningBanner")}. * <p> * If the window is secure, then {@code getWarningString} * returns {@code null}. If the window is insecure, this * method checks for the system property * {@code awt.appletWarning} * and returns the string value of that property. * @return the warning string for this window.
*/ publicfinal String getWarningString() { return warningString;
}
@SuppressWarnings("removal") privatevoid setWarningString() {
warningString = null;
SecurityManager sm = System.getSecurityManager(); if (sm != null) { try {
sm.checkPermission(AWTPermissions.TOPLEVEL_WINDOW_PERMISSION);
} catch (SecurityException se) { // make sure the privileged action is only // for getting the property! We don't want the // above checkPermission call to always succeed!
warningString = AccessController.doPrivileged( new GetPropertyAction("awt.appletWarning", "Java Applet Window"));
}
}
}
/** * Gets the {@code Locale} object that is associated * with this window, if the locale has been set. * If no locale has been set, then the default locale * is returned. * @return the locale that is set for this window. * @see java.util.Locale * @since 1.1
*/ public Locale getLocale() { if (this.locale == null) { return Locale.getDefault();
} returnthis.locale;
}
/** * Gets the input context for this window. A window always has an input context, * which is shared by subcomponents unless they create and set their own. * @see Component#getInputContext * @since 1.2
*/ public InputContext getInputContext() { synchronized (inputContextLock) { if (inputContext == null) {
inputContext = InputContext.getInstance();
}
} return inputContext;
}
/** * Set the cursor image to a specified cursor. * <p> * The method may have no visual effect if the Java platform * implementation and/or the native system do not support * changing the mouse cursor shape. * @param cursor One of the constants defined * by the {@code Cursor} class. If this parameter is null * then the cursor for this window will be set to the type * Cursor.DEFAULT_CURSOR. * @see Component#getCursor * @see Cursor * @since 1.1
*/ publicvoid setCursor(Cursor cursor) { if (cursor == null) {
cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
} super.setCursor(cursor);
}
/** * Returns the owner of this window. * * @return the owner of this window * @since 1.2
*/ public Window getOwner() { return getOwner_NoClientCode();
} final Window getOwner_NoClientCode() { return (Window)parent;
}
/** * Return an array containing all the windows this * window currently owns. * * @return the array of all the owned windows * @since 1.2
*/ public Window[] getOwnedWindows() { return getOwnedWindows_NoClientCode();
} final Window[] getOwnedWindows_NoClientCode() {
Window[] realCopy;
synchronized(ownedWindowList) { // Recall that ownedWindowList is actually a Vector of // WeakReferences and calling get() on one of these references // may return null. Make two arrays-- one the size of the // Vector (fullCopy with size fullSize), and one the size of // all non-null get()s (realCopy with size realSize). int fullSize = ownedWindowList.size(); int realSize = 0;
Window[] fullCopy = new Window[fullSize];
for (int i = 0; i < fullSize; i++) {
fullCopy[realSize] = ownedWindowList.elementAt(i).get();
/* * Returns a list of all displayable Windows, i. e. all the * Windows which peer is not null. * * @see #addNotify * @see #removeNotify
*/ static IdentityArrayList<Window> getAllWindows() { synchronized (allWindows) {
IdentityArrayList<Window> v = new IdentityArrayList<Window>();
v.addAll(allWindows); return v;
}
}
static IdentityArrayList<Window> getAllUnblockedWindows() { synchronized (allWindows) {
IdentityArrayList<Window> unblocked = new IdentityArrayList<Window>(); for (int i = 0; i < allWindows.size(); i++) {
Window w = allWindows.get(i); if (!w.isModalBlocked()) {
unblocked.add(w);
}
} return unblocked;
}
}
privatestatic Window[] getWindows(AppContext appContext) { synchronized (Window.class) {
Window[] realCopy;
@SuppressWarnings("unchecked")
Vector<WeakReference<Window>> windowList =
(Vector<WeakReference<Window>>)appContext.get(Window.class); if (windowList != null) { int fullSize = windowList.size(); int realSize = 0;
Window[] fullCopy = new Window[fullSize]; for (int i = 0; i < fullSize; i++) {
Window w = windowList.get(i).get(); if (w != null) {
fullCopy[realSize++] = w;
}
} if (fullSize != realSize) {
realCopy = Arrays.copyOf(fullCopy, realSize);
} else {
realCopy = fullCopy;
}
} else {
realCopy = new Window[0];
} return realCopy;
}
}
/** * Returns an array of all {@code Window}s, both owned and ownerless, * created by this application. * If called from an applet, the array includes only the {@code Window}s * accessible by that applet. * <p> * <b>Warning:</b> this method may return system created windows, such * as a print dialog. Applications should not assume the existence of * these dialogs, nor should an application assume anything about these * dialogs such as component positions, {@code LayoutManager}s * or serialization. * * @return the array of all the {@code Window}s created by the application * @see Frame#getFrames * @see Window#getOwnerlessWindows * * @since 1.6
*/ publicstatic Window[] getWindows() { return getWindows(AppContext.getAppContext());
}
/** * Returns an array of all {@code Window}s created by this application * that have no owner. They include {@code Frame}s and ownerless * {@code Dialog}s and {@code Window}s. * If called from an applet, the array includes only the {@code Window}s * accessible by that applet. * <p> * <b>Warning:</b> this method may return system created windows, such * as a print dialog. Applications should not assume the existence of * these dialogs, nor should an application assume anything about these * dialogs such as component positions, {@code LayoutManager}s * or serialization. * * @return the array of all the ownerless {@code Window}s * created by this application * @see Frame#getFrames * @see Window#getWindows() * * @since 1.6
*/ publicstatic Window[] getOwnerlessWindows() {
Window[] allWindows = Window.getWindows();
int ownerlessCount = 0; for (Window w : allWindows) { if (w.getOwner() == null) {
ownerlessCount++;
}
}
Window[] ownerless = new Window[ownerlessCount]; int c = 0; for (Window w : allWindows) { if (w.getOwner() == null) {
ownerless[c++] = w;
}
}
return ownerless;
}
Window getDocumentRoot() { synchronized (getTreeLock()) {
Window w = this; while (w.getOwner() != null) {
w = w.getOwner();
} return w;
}
}
/** * Specifies the modal exclusion type for this window. If a window is modal * excluded, it is not blocked by some modal dialogs. See {@link * java.awt.Dialog.ModalExclusionType Dialog.ModalExclusionType} for * possible modal exclusion types. * <p> * If the given type is not supported, {@code NO_EXCLUDE} is used. * <p> * Note: changing the modal exclusion type for a visible window may have no * effect until it is hidden and then shown again. * * @param exclusionType the modal exclusion type for this window; a {@code null} * value is equivalent to {@link Dialog.ModalExclusionType#NO_EXCLUDE * NO_EXCLUDE} * @throws SecurityException if the calling thread does not have permission * to set the modal exclusion property to the window with the given * {@code exclusionType} * @see java.awt.Dialog.ModalExclusionType * @see java.awt.Window#getModalExclusionType * @see java.awt.Toolkit#isModalExclusionTypeSupported * * @since 1.6
*/ publicvoid setModalExclusionType(Dialog.ModalExclusionType exclusionType) { if (exclusionType == null) {
exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
} if (!Toolkit.getDefaultToolkit().isModalExclusionTypeSupported(exclusionType)) {
exclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
} if (modalExclusionType == exclusionType) { return;
} if (exclusionType == Dialog.ModalExclusionType.TOOLKIT_EXCLUDE) {
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager(); if (sm != null) {
sm.checkPermission(AWTPermissions.TOOLKIT_MODALITY_PERMISSION);
}
}
modalExclusionType = exclusionType;
// if we want on-fly changes, we need to uncomment the lines below // and override the method in Dialog to use modalShow() instead // of updateChildrenBlocking() /* if (isModalBlocked()) { modalBlocker.unblockWindow(this); } Dialog.checkShouldBeBlocked(this); updateChildrenBlocking();
*/
}
/** * Returns the modal exclusion type of this window. * * @return the modal exclusion type of this window * * @see java.awt.Dialog.ModalExclusionType * @see java.awt.Window#setModalExclusionType * * @since 1.6
*/ public Dialog.ModalExclusionType getModalExclusionType() { return modalExclusionType;
}
void updateChildrenBlocking() {
ArrayList<Window> childHierarchy = new ArrayList<>();
Window[] ownedWindows = getOwnedWindows(); for (int i = 0; i < ownedWindows.length; i++) {
childHierarchy.add(ownedWindows[i]);
} int k = 0; while (k < childHierarchy.size()) {
Window w = childHierarchy.get(k); if (w.isVisible()) { if (w.isModalBlocked()) {
Dialog blocker = w.getModalBlocker();
blocker.unblockWindow(w);
}
Dialog.checkShouldBeBlocked(w);
Window[] wOwned = w.getOwnedWindows(); for (int j = 0; j < wOwned.length; j++) {
childHierarchy.add(wOwned[j]);
}
}
k++;
}
}
/** * Adds the specified window listener to receive window events from * this window. * If l is null, no exception is thrown and no action is performed. * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" * >AWT Threading Issues</a> for details on AWT's threading model. * * @param l the window listener * @see #removeWindowListener * @see #getWindowListeners
*/ publicsynchronizedvoid addWindowListener(WindowListener l) { if (l == null) { return;
}
newEventsOnly = true;
windowListener = AWTEventMulticaster.add(windowListener, l);
}
/** * Adds the specified window state listener to receive window * events from this window. If {@code l} is {@code null}, * no exception is thrown and no action is performed. * <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" * >AWT Threading Issues</a> for details on AWT's threading model. * * @param l the window state listener * @see #removeWindowStateListener * @see #getWindowStateListeners * @since 1.4
*/ publicsynchronizedvoid addWindowStateListener(WindowStateListener l) { if (l == null) { return;
}
windowStateListener = AWTEventMulticaster.add(windowStateListener, l);
newEventsOnly = true;
}
/**
--> --------------------
--> maximum size reached
--> --------------------
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.