Package generic.util
Class WindowUtilities
- java.lang.Object
-
- generic.util.WindowUtilities
-
public class WindowUtilities extends java.lang.Object
A collection of window related utility methods
-
-
Constructor Summary
Constructors Constructor Description WindowUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areModalDialogsVisible()
Returns true if there are one or more modal dialogs displayed in the current JVM.static void
bringModalestDialogToFront(java.awt.Window activeWindow)
Attempts to locate the topmost modal dialog and then bring that dialog to the front of the window hierarchystatic java.awt.Point
centerOnComponent(java.awt.Component parent, java.awt.Component child)
Creates a point that is centered over the givenparent
component, based upon the size of the givenchild
.static java.awt.Point
centerOnScreen(java.awt.Component c, java.awt.Dimension d)
Computes the point such that a rectangle with the given size would be centered on the screen.static java.awt.Point
centerOnScreen(java.awt.Dimension d)
Computes the point such that a rectangle with the given size would be centered on the screen.static void
ensureOnScreen(java.awt.Component c)
Update the component to be within visible bounds of the screenstatic void
ensureOnScreen(java.awt.Component c, java.awt.Rectangle bounds)
Update the bounds to be within visible bounds of the screen.static java.awt.Dialog
findModalestDialog()
static java.util.List<java.awt.Dialog>
getOpenModalDialogsFor(java.awt.Frame parent)
Returns a list of allparent
's descendant modal dialogs.static java.awt.Rectangle
getScreenBounds(java.awt.Component c)
Gets the usable screen bounds for the screen in which the given component is showing.static java.lang.String
getTitle(java.awt.Window w)
Returns the title for the given windowstatic java.awt.Rectangle
getVirtualScreenBounds()
Returns the a rectangle representing the screen bounds for the entire screen space for all screens in use.static java.awt.Shape
getVisibleScreenBounds()
Returns a shape that represents the visible portion of the virtual screen bounds returned fromgetVirtualScreenBounds()
static java.awt.Window
windowForComponent(java.awt.Component c)
Returns the window parent of c.
-
-
-
Method Detail
-
getTitle
public static java.lang.String getTitle(java.awt.Window w)
Returns the title for the given window- Parameters:
w
- the window- Returns:
- the title
-
windowForComponent
public static java.awt.Window windowForComponent(java.awt.Component c)
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
public static java.awt.Rectangle 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
public static java.awt.Shape 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
public static java.awt.Rectangle getScreenBounds(java.awt.Component c)
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
public static java.awt.Point centerOnScreen(java.awt.Dimension d)
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(Component, Dimension)
-
centerOnScreen
public static java.awt.Point centerOnScreen(java.awt.Component c, java.awt.Dimension d)
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:
centerOnScreen(Dimension)
-
centerOnComponent
public static java.awt.Point centerOnComponent(java.awt.Component parent, java.awt.Component child)
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
public static void ensureOnScreen(java.awt.Component c)
Update the component to be within visible bounds of the screenThis 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:
java.lang.IllegalArgumentException
- if the given component is not yet realized (seeComponent.isShowing()
-
ensureOnScreen
public static void ensureOnScreen(java.awt.Component c, java.awt.Rectangle bounds)
Update the bounds to be within 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:
java.lang.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
public static java.awt.Dialog findModalestDialog()
-
getOpenModalDialogsFor
public static java.util.List<java.awt.Dialog> getOpenModalDialogsFor(java.awt.Frame parent)
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
public static void bringModalestDialogToFront(java.awt.Window activeWindow)
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
-
-