Package generic.util

Class WindowUtilities

java.lang.Object
generic.util.WindowUtilities

public class WindowUtilities extends Object
A collection of window related utility methods
  • Constructor Details

    • WindowUtilities

      public WindowUtilities()
  • Method Details

    • getTitle

      public static String getTitle(Window w)
      Returns the title for the given window
      Parameters:
      w - the window
      Returns:
      the title
    • windowForComponent

      public static Window windowForComponent(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 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 Shape getVisibleScreenBounds()
      Returns a shape that represents the visible portion of the virtual screen bounds returned from getVirtualScreenBounds()
      Returns:
      the visible shape of all screen devices
    • getScreenBounds

      public static Rectangle getScreenBounds(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 Point centerOnScreen(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
              GraphicsEnvironment.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

      public static Point centerOnScreen(Component c, 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 screen
      d - the size of the rectangle to center
      Returns:
      the upper-left point of the given centered dimension
      See Also:
    • centerOnComponent

      public static Point centerOnComponent(Component parent, Component child)
      Creates a point that is centered over the given parent component, based upon the size of the given child.
      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 given child.
    • ensureOnScreen

      public static void ensureOnScreen(Component c)
      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 (see Component.isShowing()
    • ensureEntirelyOnScreen

      public static void ensureEntirelyOnScreen(Component c)
      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 (see Component.isShowing()
    • ensureOnScreen

      public static void ensureOnScreen(Component c, Rectangle bounds)
      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 bounds
      bounds - the bounds to adjust
      Throws:
      IllegalArgumentException - if the given component is not yet realized (see Component.isShowing()
    • ensureEntirelyOnScreen

      public static void ensureEntirelyOnScreen(Component c, Rectangle bounds)
      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 bounds
      bounds - the bounds to adjust
      Throws:
      IllegalArgumentException - if the given component is not yet realized (see Component.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 Dialog findModalestDialog()
    • getOpenModalDialogsFor

      public static List<Dialog> getOpenModalDialogsFor(Frame parent)
      Returns a list of all parent'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(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