Package generic.util

Class 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 java.awt.Point adjustBoundsToFitScreen​(java.awt.Rectangle bounds)
      Returns an point which has been adjusted to take into account of the desktop bounds, taskbar and multi-monitor configuration.
      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 hierarchy.
      static java.awt.Point centerOnComponent​(java.awt.Component parent, java.awt.Component child)
      Creates a point that is centered over the given parent component, based upon the size of the given child.
      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 ensureSizeFitsScreen​(java.awt.Dimension size)
      Updates the given dimension as necessary to fit it on the screen.
      static void ensureWindowOnScreen​(java.awt.Window window)
      Makes sure the window is 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 all parent's descendant modal dialogs.
      static java.awt.Rectangle getScreenBounds()
      Returns the a rectangle representing the entire screen bounds.
      static java.lang.String getTitle​(java.awt.Window w)
      Returns the title for the given window
      static java.awt.Window windowForComponent​(java.awt.Component c)
      Returns the window parent of c.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WindowUtilities

        public WindowUtilities()
    • 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
      • getScreenBounds

        public static java.awt.Rectangle getScreenBounds()
        Returns the a rectangle representing the entire screen bounds.
      • 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.
        Parameters:
        d - the size of the rectangle to center.
        Returns:
        the point at which the if the given rectangle were drawn with its upper left corner at that point, it would be centered on the screen.
      • centerOnComponent

        public static java.awt.Point centerOnComponent​(java.awt.Component parent,
                                                       java.awt.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.
      • ensureWindowOnScreen

        public static void ensureWindowOnScreen​(java.awt.Window window)
        Makes sure the window is within visible bounds of the screen.
        Parameters:
        window - the window to move onscreen as necessary.
      • ensureSizeFitsScreen

        public static void ensureSizeFitsScreen​(java.awt.Dimension size)
        Updates the given dimension as necessary to fit it on the screen.
        Parameters:
        size - the size that may get updated
      • adjustBoundsToFitScreen

        public static java.awt.Point adjustBoundsToFitScreen​(java.awt.Rectangle bounds)
        Returns an point which has been adjusted to take into account of the desktop bounds, taskbar and multi-monitor configuration.

        This adjustment may be cancelled by invoking the application with -Djavax.swing.adjustPopupLocationToFit=false

        Parameters:
        bounds - the bounds that must fit onscreen
      • 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 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​(java.awt.Window activeWindow)
        Attempts to locate the topmost modal dialog and then bring that dialog to the front of the window hierarchy.