Class WindowGeometry


  • public class WindowGeometry
    extends java.lang.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
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  WindowGeometry.WindowGeometryException
      Exception thrown by the WindowGeometry class if something goes wrong
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.awt.Dimension extent
      the size
      static BooleanProperty GUI_GEOMETRY_ENABLED
      Whether storing/restoring of geometries to/from preferences is enabled
      static java.lang.String PREF_KEY_GUI_GEOMETRY
      Preference key for the MainFrame geometry
      private java.awt.Point topLeft
      the top left point
    • Constructor Summary

      Constructors 
      Constructor Description
      WindowGeometry​(java.awt.Point topLeft, java.awt.Dimension extent)
      Creates a window geometry from a position and dimension
      WindowGeometry​(java.awt.Rectangle rect)
      Creates a window geometry from a rectangle
      WindowGeometry​(java.awt.Window window)
      Creates a window geometry from the position and the size of a window.
      WindowGeometry​(java.lang.String preferenceKey)
      Creates a window geometry from the values kept in the preference store under the key preferenceKey
      WindowGeometry​(java.lang.String preferenceKey, WindowGeometry defaultGeometry)
      Creates a window geometry from the values kept in the preference store under the key preferenceKey.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void applySafe​(java.awt.Window window)
      Applies this geometry to a window.
      static WindowGeometry centerInWindow​(java.awt.Component reference, java.awt.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.
      static WindowGeometry centerOnScreen​(java.awt.Dimension extent)
      Replies a window geometry object for a window with a specific size which is centered on screen, where main window is
      static WindowGeometry centerOnScreen​(java.awt.Dimension extent, java.lang.String preferenceKey)
      Replies a window geometry object for a window with a specific size which is centered on screen where the corresponding window is.
      boolean equals​(java.lang.Object obj)  
      void fixScreen​(java.awt.Window window)
      Fixes a window geometry to shift to the correct screen.
      static java.awt.Rectangle getFullScreenInfo()
      Find the size of the full virtual screen.
      static java.awt.Dimension getMaxDimensionOnScreen​(javax.swing.JComponent component)
      Computes the maximum dimension for a component to fit in screen displaying component.
      private java.awt.Rectangle getRectangle()
      Replies the size and position specified by the geometry
      private static java.awt.Rectangle getScreenInfo​(java.awt.Rectangle g)
      Find the size and position of the screen for given coordinates.
      static java.awt.Rectangle getScreenInfo​(java.lang.String preferenceKey)
      Find the size and position of the screen for given coordinates.
      java.awt.Dimension getSize()
      Replies the size specified by the geometry
      java.awt.Point getTopLeft()
      Replies the top left point for the geometry
      static java.awt.Rectangle getVirtualScreenBounds()
      Computes the virtual bounds of graphics environment, as an union of all screen bounds.
      int hashCode()  
      protected void initFromPreferences​(java.lang.String preferenceKey)  
      protected void initFromWindowGeometry​(WindowGeometry other)  
      protected static boolean isBugInMaximumWindowBounds​(java.awt.Rectangle maxbounds)
      Determines if the bug affecting getMaximumWindowBounds() occurred.
      static WindowGeometry mainWindow​(java.lang.String preferenceKey, java.lang.String arg, boolean maximize)
      Gets the geometry of the main window
      protected int parseField​(java.lang.String preferenceKey, java.lang.String preferenceValue, java.lang.String field)  
      void remember​(java.lang.String preferenceKey)
      Remembers a window geometry under a specific preference key
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • WindowGeometry

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

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

        public WindowGeometry​(java.awt.Window window)
        Creates a window geometry from the position and the size of a window.
        Parameters:
        window - the window
        Throws:
        java.awt.IllegalComponentStateException - if the window is not showing on the screen
      • WindowGeometry

        public WindowGeometry​(java.lang.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​(java.awt.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​(java.awt.Dimension extent,
                                                    java.lang.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​(java.awt.Component reference,
                                                    java.awt.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​(java.awt.Window window)
        Fixes a window geometry to shift to the correct screen.
        Parameters:
        window - the window
      • mainWindow

        public static WindowGeometry mainWindow​(java.lang.String preferenceKey,
                                                java.lang.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​(java.lang.String preferenceKey)
        Remembers a window geometry under a specific preference key
        Parameters:
        preferenceKey - the preference key
      • getTopLeft

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

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

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

        public void applySafe​(java.awt.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 java.awt.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 java.awt.Dimension getMaxDimensionOnScreen​(javax.swing.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:
        java.lang.IllegalArgumentException - if component is null
        Since:
        7463
      • getScreenInfo

        public static java.awt.Rectangle getScreenInfo​(java.lang.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 java.awt.Rectangle getScreenInfo​(java.awt.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 java.awt.Rectangle getFullScreenInfo()
        Find the size of the full virtual screen.
        Returns:
        size of the full virtual screen
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object