Class WindowGeometry


  • public class WindowGeometry
    extends Object
    This is a helper class for persisting the geometry of a JOSM window to the preference store and for restoring it from the preference store.
    Since:
    12678 (moved from tools package, 2008
    • Constructor Detail

      • WindowGeometry

        public WindowGeometry​(Point topLeft,
                              Dimension extent)
        Creates a window geometry from a position and dimension
        Parameters:
        topLeft - the top left point
        extent - the extent
      • WindowGeometry

        public WindowGeometry​(Rectangle rect)
        Creates a window geometry from a rectangle
        Parameters:
        rect - the position
      • WindowGeometry

        public WindowGeometry​(String preferenceKey,
                              WindowGeometry defaultGeometry)
        Creates a window geometry from the values kept in the preference store under the key preferenceKey. Falls back to the defaultGeometry if something goes wrong.
        Parameters:
        preferenceKey - the preference key
        defaultGeometry - the default geometry
    • Method Detail

      • centerOnScreen

        public static WindowGeometry centerOnScreen​(Dimension extent)
        Replies a window geometry object for a window with a specific size which is centered on screen, where main window is
        Parameters:
        extent - the size
        Returns:
        the geometry object
      • centerOnScreen

        public static WindowGeometry centerOnScreen​(Dimension extent,
                                                    String preferenceKey)
        Replies a window geometry object for a window with a specific size which is centered on screen where the corresponding window is.
        Parameters:
        extent - the size
        preferenceKey - the key to get window size and position from, null value format for whole virtual screen
        Returns:
        the geometry object
      • centerInWindow

        public static WindowGeometry centerInWindow​(Component reference,
                                                    Dimension extent)
        Replies a window geometry object for a window with a specific size which is centered relative to the parent window of a reference component.
        Parameters:
        reference - the reference component.
        extent - the size
        Returns:
        the geometry object
      • fixScreen

        public void fixScreen​(Window window)
        Fixes a window geometry to shift to the correct screen.
        Parameters:
        window - the window
      • mainWindow

        public static WindowGeometry mainWindow​(String preferenceKey,
                                                String arg,
                                                boolean maximize)
        Gets the geometry of the main window
        Parameters:
        preferenceKey - The preference key to use
        arg - The command line geometry arguments
        maximize - If the user requested to maximize the window
        Returns:
        The geometry for the main window
      • remember

        public void remember​(String preferenceKey)
        Remembers a window geometry under a specific preference key
        Parameters:
        preferenceKey - the preference key
      • getTopLeft

        public Point getTopLeft()
        Replies the top left point for the geometry
        Returns:
        the top left point for the geometry
      • getSize

        public Dimension getSize()
        Replies the size specified by the geometry
        Returns:
        the size specified by the geometry
      • getRectangle

        private Rectangle getRectangle()
        Replies the size and position specified by the geometry
        Returns:
        the size and position specified by the geometry
      • applySafe

        public void applySafe​(Window window)
        Applies this geometry to a window. Makes sure that the window is not placed outside of the coordinate range of all available screens.
        Parameters:
        window - the window
      • getVirtualScreenBounds

        public static Rectangle getVirtualScreenBounds()
        Computes the virtual bounds of graphics environment, as an union of all screen bounds.
        Returns:
        The virtual bounds of graphics environment, as an union of all screen bounds.
        Since:
        6522
      • getMaxDimensionOnScreen

        public static Dimension getMaxDimensionOnScreen​(JComponent component)
        Computes the maximum dimension for a component to fit in screen displaying component.
        Parameters:
        component - The component to get current screen info from. Must not be null
        Returns:
        the maximum dimension for a component to fit in current screen
        Throws:
        IllegalArgumentException - if component is null
        Since:
        7463
      • getScreenInfo

        public static Rectangle getScreenInfo​(String preferenceKey)
        Find the size and position of the screen for given coordinates. Use first screen, when no coordinates are stored or null is passed.
        Parameters:
        preferenceKey - the key to get size and position from
        Returns:
        bounds of the screen
      • getScreenInfo

        private static Rectangle getScreenInfo​(Rectangle g)
        Find the size and position of the screen for given coordinates. Use first screen, when no coordinates are stored or null is passed.
        Parameters:
        g - coordinates to check
        Returns:
        bounds of the screen
      • getFullScreenInfo

        public static Rectangle getFullScreenInfo()
        Find the size of the full virtual screen.
        Returns:
        size of the full virtual screen