Package org.openstreetmap.josm.gui.util
Class WindowGeometry
- java.lang.Object
-
- org.openstreetmap.josm.gui.util.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 sizestatic BooleanProperty
GUI_GEOMETRY_ENABLED
Whether storing/restoring of geometries to/from preferences is enabledstatic java.lang.String
PREF_KEY_GUI_GEOMETRY
Preference key for theMainFrame
geometryprivate 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 dimensionWindowGeometry(java.awt.Rectangle rect)
Creates a window geometry from a rectangleWindowGeometry(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 keypreferenceKey
WindowGeometry(java.lang.String preferenceKey, WindowGeometry defaultGeometry)
Creates a window geometry from the values kept in the preference store under the keypreferenceKey
.
-
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 isstatic 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 displayingcomponent
.private java.awt.Rectangle
getRectangle()
Replies the size and position specified by the geometryprivate 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 geometryjava.awt.Point
getTopLeft()
Replies the top left point for the geometrystatic 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 windowprotected 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 keyjava.lang.String
toString()
-
-
-
Field Detail
-
PREF_KEY_GUI_GEOMETRY
public static final java.lang.String PREF_KEY_GUI_GEOMETRY
Preference key for theMainFrame
geometry- See Also:
- Constant Field Values
-
GUI_GEOMETRY_ENABLED
public static final BooleanProperty GUI_GEOMETRY_ENABLED
Whether storing/restoring of geometries to/from preferences is enabled
-
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)
Creates a window geometry from a position and dimension- Parameters:
topLeft
- the top left pointextent
- 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) throws WindowGeometry.WindowGeometryException
Creates a window geometry from the values kept in the preference store under the keypreferenceKey
- Parameters:
preferenceKey
- the preference key- Throws:
WindowGeometry.WindowGeometryException
- 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 keypreferenceKey
. Falls back to thedefaultGeometry
if something goes wrong.- Parameters:
preferenceKey
- the preference keydefaultGeometry
- 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 sizepreferenceKey
- 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
-
parseField
protected int parseField(java.lang.String preferenceKey, java.lang.String preferenceValue, java.lang.String field) throws WindowGeometry.WindowGeometryException
-
initFromPreferences
protected final void initFromPreferences(java.lang.String preferenceKey) throws WindowGeometry.WindowGeometryException
-
initFromWindowGeometry
protected final void initFromWindowGeometry(WindowGeometry other)
-
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 usearg
- The command line geometry argumentsmaximize
- 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
-
isBugInMaximumWindowBounds
protected static boolean isBugInMaximumWindowBounds(java.awt.Rectangle maxbounds)
Determines if the bug affecting getMaximumWindowBounds() occurred.- Parameters:
maxbounds
- result of getMaximumWindowBounds()- Returns:
true
if the bug happened,false otherwise
- See Also:
- JOSM-9699, Ubuntu-1171563, IcedTea-1669, JDK-8034224
-
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 displayingcomponent
.- Parameters:
component
- The component to get current screen info from. Must not benull
- Returns:
- the maximum dimension for a component to fit in current screen
- Throws:
java.lang.IllegalArgumentException
- ifcomponent
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-