org.openstreetmap.josm.tools
Class WindowGeometry

java.lang.Object
  extended by org.openstreetmap.josm.tools.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.


Nested Class Summary
static class WindowGeometry.WindowGeometryException
          Exception thrown by the WindowGeometry class if something goes wrong
 
Field Summary
private  java.awt.Dimension extent
          the size
private  java.awt.Point topLeft
          the top left point
 
Constructor Summary
WindowGeometry(java.awt.Point topLeft, java.awt.Dimension extent)
           
WindowGeometry(java.awt.Rectangle rect)
           
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.
WindowGeometry(java.awt.Window window)
          Creates a window geometry from the position and the size of a window.
 
Method Summary
 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.
static java.awt.Rectangle getFullScreenInfo()
          Find the size of the full virtual screen.
private  java.awt.Rectangle getRectangle()
           
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 spezified by the geometry
 java.awt.Point getTopLeft()
          Replies the top left point for the geometry
protected  void initFromPreferences(java.lang.String preferenceKey)
           
protected  void initFromWindowGeometry(WindowGeometry other)
           
static WindowGeometry mainWindow(java.lang.String preferenceKey, java.lang.String arg, boolean maximize)
           
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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

topLeft

private java.awt.Point topLeft
the top left point


extent

private java.awt.Dimension extent
the size

Constructor Detail

WindowGeometry

public WindowGeometry(java.awt.Point topLeft,
                      java.awt.Dimension extent)
Parameters:
topLeft - the top left point
extent - the extent

WindowGeometry

public WindowGeometry(java.awt.Rectangle rect)
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

WindowGeometry

public WindowGeometry(java.lang.String preferenceKey)
               throws WindowGeometry.WindowGeometryException
Creates a window geometry from the values kept in the preference store under the key preferenceKey

Parameters:
preferenceKey - the preference key
Throws:
WindowGeometry.WindowGeometryException - thrown if no such key exist or if the preference value has an illegal format

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

parseField

protected int parseField(java.lang.String preferenceKey,
                         java.lang.String preferenceValue,
                         java.lang.String field)
                  throws WindowGeometry.WindowGeometryException
Throws:
WindowGeometry.WindowGeometryException

initFromPreferences

protected void initFromPreferences(java.lang.String preferenceKey)
                            throws WindowGeometry.WindowGeometryException
Throws:
WindowGeometry.WindowGeometryException

initFromWindowGeometry

protected void initFromWindowGeometry(WindowGeometry other)

mainWindow

public static WindowGeometry mainWindow(java.lang.String preferenceKey,
                                        java.lang.String arg,
                                        boolean maximize)

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 spezified by the geometry

Returns:
the size spezified by the geometry

getRectangle

private java.awt.Rectangle getRectangle()

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

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

getFullScreenInfo

public static java.awt.Rectangle getFullScreenInfo()
Find the size of the full virtual screen.


toString

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


JOSM