Package generic.util
Class WindowUtilities
java.lang.Object
generic.util.WindowUtilities
A collection of window related utility methods
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Returns true if there are one or more modal dialogs displayed in the current JVM.static void
bringModalestDialogToFront
(Window activeWindow) Attempts to locate the topmost modal dialog and then bring that dialog to the front of the window hierarchystatic Point
centerOnComponent
(Component parent, Component child) Creates a point that is centered over the givenparent
component, based upon the size of the givenchild
.static Point
centerOnScreen
(Component c, Dimension d) Computes the point such that a rectangle with the given size would be centered on the screen.static Point
Computes the point such that a rectangle with the given size would be centered on the screen.static void
Update the component to be within visible bounds of the screen.static void
ensureEntirelyOnScreen
(Component c, Rectangle bounds) Update the bounds to be within contained within the visible bounds of the screen.static void
Update the component to intersect the visible bounds of the screen.static void
ensureOnScreen
(Component c, Rectangle bounds) Update the bounds to intersect visible bounds of the screen.static Dialog
getOpenModalDialogsFor
(Frame parent) Returns a list of allparent
's descendant modal dialogs.static Rectangle
Gets the usable screen bounds for the screen in which the given component is showing.static String
Returns the title for the given windowstatic Rectangle
Returns the a rectangle representing the screen bounds for the entire screen space for all screens in use.static Shape
Returns a shape that represents the visible portion of the virtual screen bounds returned fromgetVirtualScreenBounds()
static Window
Returns the window parent of c.
-
Constructor Details
-
WindowUtilities
public WindowUtilities()
-
-
Method Details
-
getTitle
Returns the title for the given window- Parameters:
w
- the window- Returns:
- the title
-
windowForComponent
Returns the window parent of c. If c is a window, then c is returned.Warning: this differs from
SwingUtilities.windowForComponent(Component)
in that the latter method will not return the given component if it is a window.- Parameters:
c
- the component- Returns:
- the window
-
getVirtualScreenBounds
Returns the a rectangle representing the screen bounds for the entire screen space for all screens in use. The result will include virtual space that may not be rendered on any physical hardware. Said differently, the rectangle returned from this method will contain all visible display coordinates, as well as potentially coordinates that are virtual and not displayed on any physical screen. The OS's window manager is responsible for controlling how the virtual space is created.- Returns:
- the virtual screen bounds
-
getVisibleScreenBounds
Returns a shape that represents the visible portion of the virtual screen bounds returned fromgetVirtualScreenBounds()
- Returns:
- the visible shape of all screen devices
-
getScreenBounds
Gets the usable screen bounds for the screen in which the given component is showing. Returns null if the given component is not showing. Usable bounds are the screen bounds after subtracting insets (for things like menu bars and task bars).- Parameters:
c
- the component- Returns:
- the screen bounds; null if the component is not showing
-
centerOnScreen
Computes the point such that a rectangle with the given size would be centered on the screen. The chosen screen in this case is the screen defined byGraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
If the given size is too big to fit on the screen in either dimension, then it will be placed at the 0 position for that dimension.
- Parameters:
d
- the size of the rectangle to center- Returns:
- the upper-left point of the given centered dimension
- See Also:
-
centerOnScreen
Computes the point such that a rectangle with the given size would be centered on the screen. The chosen screen in this case is the screen defined by using the given component. If the given size is too big to fit on the screen in either dimension, then it will be placed at the 0 position for that dimension.- Parameters:
c
- the component that should be used to find the current screend
- the size of the rectangle to center- Returns:
- the upper-left point of the given centered dimension
- See Also:
-
centerOnComponent
Creates a point that is centered over the givenparent
component, based upon the size of the givenchild
.- Parameters:
parent
- The component over which to center the child.child
- The component which will be centered over the parent- Returns:
- a point that is centered over the given
parent
component, based upon the size of the givenchild
.
-
ensureOnScreen
Update the component to intersect the visible bounds of the screen.This method differs from
ensureOnScreen(Component, Rectangle)
in that the other method does not adjust the component's bounds like this method does.- Parameters:
c
- the component to move on screen as necessary- Throws:
IllegalArgumentException
- if the given component is not yet realized (seeComponent.isShowing()
-
ensureEntirelyOnScreen
Update the component to be within visible bounds of the screen.This method differs from
ensureEntirelyOnScreen(Component, Rectangle)
in that the other method does not adjust the component's bounds like this method does.- Parameters:
c
- the component to move on screen as necessary- Throws:
IllegalArgumentException
- if the given component is not yet realized (seeComponent.isShowing()
-
ensureOnScreen
Update the bounds to intersect visible bounds of the screen. The given component is used to determine which screen to use for updating the bounds.Note: the given component's bounds will not be adjusted by this method
- Parameters:
c
- the on screen component, used to determine which screen to check against the given boundsbounds
- the bounds to adjust- Throws:
IllegalArgumentException
- if the given component is not yet realized (seeComponent.isShowing()
-
ensureEntirelyOnScreen
Update the bounds to be within contained within the visible bounds of the screen. The given component is used to determine which screen to use for updating the bounds.Note: the given comonent's bounds will not be adjusted by this method
- Parameters:
c
- the on screen component, used to determine which screen to check against the given boundsbounds
- the bounds to adjust- Throws:
IllegalArgumentException
- if the given component is not yet realized (seeComponent.isShowing()
-
areModalDialogsVisible
public static boolean areModalDialogsVisible()Returns true if there are one or more modal dialogs displayed in the current JVM.- Returns:
- true if there are one or more modal dialogs displayed in the current JVM.
-
findModalestDialog
-
getOpenModalDialogsFor
Returns a list of allparent
's descendant modal dialogs.- Parameters:
parent
- the parent for which to find modal dialogs- Returns:
- a list of all
parent
's descendant modal dialogs.
-
bringModalestDialogToFront
Attempts to locate the topmost modal dialog and then bring that dialog to the front of the window hierarchy- Parameters:
activeWindow
- the system's active window
-