Class SwingUtils


  • public class SwingUtils
    extends java.lang.Object
    A collection of utility functions for Magellan and Swing
    Version:
    1.0, Nov 23, 2010
    Author:
    stm
    • Constructor Summary

      Constructors 
      Constructor Description
      SwingUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Rectangle adjustToScreen​(int x, int y, int width, int height, java.awt.Window window)
      Adjust the given rectangle so that it fits the screen size of window.
      static void center​(java.awt.Component component)
      Centers the given component on the current graphics configuration (i.e. on the current screen).
      static void setBounds​(java.awt.Component component, java.util.Properties settings, java.lang.String rectKey, boolean maximize)
      Sets the component's bounds to the value read from settings by rectKey.
      static void setLocation​(java.awt.Component component, java.util.Properties settings, java.lang.String xKey, java.lang.String yKey)
      Positions the given component either at the position specified by the two property keys, or, if those are not defined, centers it on the current graphics configuration (i.e. on the current screen).
      static void setLocation​(java.awt.Component component, java.util.Properties settings, java.lang.String xKey, java.lang.String yKey, boolean center)
      Positions the given component either at the position specified by the two property keys, or, if those are not defined and center==true, centers it on the current graphics configuration (i.e. on the current screen).
      • Methods inherited from class java.lang.Object

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

      • SwingUtils

        public SwingUtils()
    • Method Detail

      • center

        public static void center​(java.awt.Component component)
        Centers the given component on the current graphics configuration (i.e. on the current screen).
        Parameters:
        component -
        See Also:
        GraphicsConfiguration.getBounds()
      • setLocation

        public static void setLocation​(java.awt.Component component,
                                       java.util.Properties settings,
                                       java.lang.String xKey,
                                       java.lang.String yKey)
        Positions the given component either at the position specified by the two property keys, or, if those are not defined, centers it on the current graphics configuration (i.e. on the current screen). Should the saved location bring the component outside the screen bounds, the position is corrected to at least partly be visible on the screen. This is useful if Magellan is started on different screen resolutions.
        Parameters:
        component - This component's location is changed
        settings - to load the position
        xKey - key for the x value in settings. Should evaluate to an integer.
        yKey - key for the x value in settings. Should evaluate to an integer.
        See Also:
        GraphicsConfiguration.getBounds()
      • setLocation

        public static void setLocation​(java.awt.Component component,
                                       java.util.Properties settings,
                                       java.lang.String xKey,
                                       java.lang.String yKey,
                                       boolean center)
        Positions the given component either at the position specified by the two property keys, or, if those are not defined and center==true, centers it on the current graphics configuration (i.e. on the current screen). Should the saved location bring the component outside the screen bounds, the position is corrected to at least partly be visible on the screen. This is useful if Magellan is started on different screen resolutions.
        Parameters:
        component - This component's location is changed
        settings - to load the position
        xKey - key for the x value in settings. Should evaluate to an integer.
        yKey - key for the x value in settings. Should evaluate to an integer.
        center - If true, the component is centered if the values cannot be read. Otherwise, the location isn't changed.
        See Also:
        GraphicsConfiguration.getBounds()
      • setBounds

        public static void setBounds​(java.awt.Component component,
                                     java.util.Properties settings,
                                     java.lang.String rectKey,
                                     boolean maximize)
        Sets the component's bounds to the value read from settings by rectKey. The settings should contain four keys (rectKey.x, rectKey.y, rectKey.width, rectKey.height) that evaluate to integer. Should the saved location bring the component outside the screen bounds, the position is corrected to at least partly be visible on the screen. This is useful if Magellan is started on different screen resolutions. If the location is not in the settings, the component is maximized on the current device dimensions if maximize==true, then centered.
        Parameters:
        component -
        settings -
        rectKey -
        maximize -
      • adjustToScreen

        public static java.awt.Rectangle adjustToScreen​(int x,
                                                        int y,
                                                        int width,
                                                        int height,
                                                        java.awt.Window window)
        Adjust the given rectangle so that it fits the screen size of window.
        Parameters:
        x - of old rectangle
        y - of old rectangle
        width - of old rectangle
        height - of old rectangle
        window -
        Returns:
        A rectangle that overlaps Window.getToolkit().getScreenSize() by at least a few pixels
        See Also:
        Toolkit.getScreenSize()