Package org.openstreetmap.josm.gui
Class MapViewState
- java.lang.Object
-
- org.openstreetmap.josm.gui.MapViewState
-
- All Implemented Interfaces:
java.io.Serializable
public final class MapViewState extends java.lang.Object implements java.io.Serializable
This class represents a state of theMapView.- Since:
- 10343
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMapViewState.MapViewEastNorthPointclassMapViewState.MapViewPointA class representing a point in the map view.classMapViewState.MapViewRectangleA rectangle on the MapView.private classMapViewState.MapViewViewPoint
-
Field Summary
Fields Modifier and Type Field Description private static intCLIP_BOUNDSAdditional pixels outside the view for where to start clipping.static intOUTSIDE_BOTTOMA flag indicating that the point is outside to the bottom of the map view.static intOUTSIDE_LEFTA flag indicating that the point is outside to the left of the map view.static intOUTSIDE_RIGHTA flag indicating that the point is outside to the right of the map view.static intOUTSIDE_TOPA flag indicating that the point is outside to the top of the map view.private Projectingprojectingprivate doublescaleprivate static longserialVersionUIDprivate EastNorthtopLeftTop leftEastNorthcoordinate of the view.private java.awt.PointtopLeftInWindowprivate java.awt.PointtopLeftOnScreenprivate intviewHeightprivate intviewWidth
-
Constructor Summary
Constructors Modifier Constructor Description privateMapViewState(double scale, MapViewState mvs)privateMapViewState(javax.swing.JComponent position, MapViewState mvs)privateMapViewState(EastNorth topLeft, MapViewState mvs)privateMapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft)privateMapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft, java.awt.Point topLeftInWindow, java.awt.Point topLeftOnScreen)Create a newMapViewStateprivateMapViewState(Projecting projecting, MapViewState mvs)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static EastNorthcalculateDefaultCenter()static MapViewStatecreateDefaultState(int width, int height)Create the defaultMapViewStateobject for the given map view.booleanequalsInWindow(MapViewState other)Check if this MapViewState equals another one, disregarding the position of the JOSM window on screen.(package private) static java.awt.PointfindTopLeftInWindow(javax.swing.JComponent position)This is visible for JMockit.(package private) static java.awt.PointfindTopLeftOnScreen(javax.swing.JComponent position)This is visible for JMockit.java.awt.geom.AffineTransformgetAffineTransform()Creates an affine transform that is used to convert the east/north coordinates to view coordinates.java.awt.geom.AreagetArea(Bounds bounds)Returns the area for the given bounds.MapViewState.MapViewPointgetCenter()Gets the center of the view.MapViewState.MapViewPointgetForView(double x, double y)Gets the MapViewPoint representation for a position in view coordinates.MapViewState.MapViewPointgetPointFor(EastNorth eastNorth)Gets theMapViewState.MapViewPointfor the givenEastNorthcoordinate.MapViewState.MapViewPointgetPointFor(ILatLon latlon)Gets theMapViewState.MapViewPointfor the givenLatLoncoordinate.MapViewState.MapViewPointgetPointFor(LatLon latlon)Gets theMapViewState.MapViewPointfor the givenLatLoncoordinate.MapViewState.MapViewPointgetPointFor(Node node)Gets theMapViewState.MapViewPointfor the given node.ProjectinggetProjecting()Gets the current projecting instance that is used to convert between east/north and lat/lon space.ProjectiongetProjection()Gets the current projection used for the MapView.doublegetScale()The scale in east/north units per pixel.MapViewState.MapViewRectanglegetViewArea()Gets a rectangle representing the whole view area.MapViewState.MapViewRectanglegetViewArea(java.awt.geom.Rectangle2D rectangle)Gets a rectangle of the view as map view area.MapViewState.MapViewRectanglegetViewClipRectangle()Gets a rectangle that is several pixel bigger than the view.doublegetViewHeight()Gets the height of the view on the Screen;doublegetViewWidth()Gets the width of the view on the Screen;MapViewStatemovedTo(MapViewState.MapViewPoint mapViewPoint, EastNorth newEastNorthThere)Creates a new state that is moved to an east/north coordinate.java.lang.StringtoString()MapViewStateusingCenter(EastNorth newCenter)Creates a new state that is the same as the current state except for that it is using a new center.MapViewStateusingLocation(javax.swing.JComponent position)Creates a new state that is the same as the current state except for that it is using the location of the given component.MapViewStateusingProjection(Projection projection)Creates a state that uses the projection.MapViewStateusingScale(double newScale)Creates a new state that is the same as the current state except for that it is using a new scale.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
OUTSIDE_TOP
public static final int OUTSIDE_TOP
A flag indicating that the point is outside to the top of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_BOTTOM
public static final int OUTSIDE_BOTTOM
A flag indicating that the point is outside to the bottom of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_LEFT
public static final int OUTSIDE_LEFT
A flag indicating that the point is outside to the left of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
OUTSIDE_RIGHT
public static final int OUTSIDE_RIGHT
A flag indicating that the point is outside to the right of the map view.- Since:
- 10827
- See Also:
- Constant Field Values
-
CLIP_BOUNDS
private static final int CLIP_BOUNDS
Additional pixels outside the view for where to start clipping.- See Also:
- Constant Field Values
-
projecting
private final transient Projecting projecting
-
viewWidth
private final int viewWidth
-
viewHeight
private final int viewHeight
-
scale
private final double scale
-
topLeftOnScreen
private final java.awt.Point topLeftOnScreen
-
topLeftInWindow
private final java.awt.Point topLeftInWindow
-
-
Constructor Detail
-
MapViewState
private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft, java.awt.Point topLeftInWindow, java.awt.Point topLeftOnScreen)
Create a newMapViewState- Parameters:
projection- The projection to use.viewWidth- The view widthviewHeight- The view heightscale- The scale to usetopLeft- The top left corner in east/north space.topLeftInWindow- The top left point in windowtopLeftOnScreen- The top left point on screen
-
MapViewState
private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft)
-
MapViewState
private MapViewState(EastNorth topLeft, MapViewState mvs)
-
MapViewState
private MapViewState(double scale, MapViewState mvs)
-
MapViewState
private MapViewState(javax.swing.JComponent position, MapViewState mvs)
-
MapViewState
private MapViewState(Projecting projecting, MapViewState mvs)
-
-
Method Detail
-
findTopLeftInWindow
static java.awt.Point findTopLeftInWindow(javax.swing.JComponent position)
This is visible for JMockit.- Parameters:
position- The component to get the top left position of its window- Returns:
- the top left point in window
-
findTopLeftOnScreen
static java.awt.Point findTopLeftOnScreen(javax.swing.JComponent position)
This is visible for JMockit.- Parameters:
position- The component to get the top left position of its screen- Returns:
- the top left point on screen
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getScale
public double getScale()
The scale in east/north units per pixel.- Returns:
- The scale.
-
getForView
public MapViewState.MapViewPoint getForView(double x, double y)
Gets the MapViewPoint representation for a position in view coordinates.- Parameters:
x- The x coordinate inside the view.y- The y coordinate inside the view.- Returns:
- The MapViewPoint.
-
getPointFor
public MapViewState.MapViewPoint getPointFor(EastNorth eastNorth)
Gets theMapViewState.MapViewPointfor the givenEastNorthcoordinate.- Parameters:
eastNorth- the position.- Returns:
- The point for that position.
-
getPointFor
public MapViewState.MapViewPoint getPointFor(LatLon latlon)
Gets theMapViewState.MapViewPointfor the givenLatLoncoordinate.This method exists to not break binary compatibility with old plugins
- Parameters:
latlon- the position- Returns:
- The point for that position.
- Since:
- 10651
-
getPointFor
public MapViewState.MapViewPoint getPointFor(ILatLon latlon)
Gets theMapViewState.MapViewPointfor the givenLatLoncoordinate.- Parameters:
latlon- the position- Returns:
- The point for that position.
- Since:
- 12161
-
getPointFor
public MapViewState.MapViewPoint getPointFor(Node node)
Gets theMapViewState.MapViewPointfor the given node. This is faster thangetPointFor(LatLon)because it uses the node east/north cache.- Parameters:
node- The node- Returns:
- The position of that node.
- Since:
- 10827
-
getViewArea
public MapViewState.MapViewRectangle getViewArea()
Gets a rectangle representing the whole view area.- Returns:
- The rectangle.
-
getViewArea
public MapViewState.MapViewRectangle getViewArea(java.awt.geom.Rectangle2D rectangle)
Gets a rectangle of the view as map view area.- Parameters:
rectangle- The rectangle to get.- Returns:
- The view area.
- Since:
- 10827
-
getCenter
public MapViewState.MapViewPoint getCenter()
Gets the center of the view.- Returns:
- The center position.
-
getViewWidth
public double getViewWidth()
Gets the width of the view on the Screen;- Returns:
- The width of the view component in screen pixel.
-
getViewHeight
public double getViewHeight()
Gets the height of the view on the Screen;- Returns:
- The height of the view component in screen pixel.
-
getProjection
public Projection getProjection()
Gets the current projection used for the MapView.- Returns:
- The projection.
- See Also:
getProjecting()
-
getProjecting
public Projecting getProjecting()
Gets the current projecting instance that is used to convert between east/north and lat/lon space.- Returns:
- The projection.
- Since:
- 12161
-
getAffineTransform
public java.awt.geom.AffineTransform getAffineTransform()
Creates an affine transform that is used to convert the east/north coordinates to view coordinates.- Returns:
- The affine transform. It should not be changed.
- Since:
- 10375
-
getViewClipRectangle
public MapViewState.MapViewRectangle getViewClipRectangle()
Gets a rectangle that is several pixel bigger than the view. It is used to define the view clipping.- Returns:
- The rectangle.
-
getArea
public java.awt.geom.Area getArea(Bounds bounds)
Returns the area for the given bounds.- Parameters:
bounds- bounds- Returns:
- the area for the given bounds
-
usingCenter
public MapViewState usingCenter(EastNorth newCenter)
Creates a new state that is the same as the current state except for that it is using a new center.- Parameters:
newCenter- The new center coordinate.- Returns:
- The new state.
- Since:
- 10375
-
movedTo
public MapViewState movedTo(MapViewState.MapViewPoint mapViewPoint, EastNorth newEastNorthThere)
Creates a new state that is moved to an east/north coordinate.- Parameters:
mapViewPoint- The reference point.newEastNorthThere- The east/north coordinate that should be there.- Returns:
- The new state.
- Since:
- 10375
-
usingScale
public MapViewState usingScale(double newScale)
Creates a new state that is the same as the current state except for that it is using a new scale.- Parameters:
newScale- The new scale to use.- Returns:
- The new state.
- Since:
- 10375
-
usingLocation
public MapViewState usingLocation(javax.swing.JComponent position)
Creates a new state that is the same as the current state except for that it is using the location of the given component.The view is moved so that the center is the same as the old center.
- Parameters:
position- The new location to use.- Returns:
- The new state.
- Since:
- 10375
-
usingProjection
public MapViewState usingProjection(Projection projection)
Creates a state that uses the projection.- Parameters:
projection- The projection to use.- Returns:
- The new state.
- Since:
- 10486
-
createDefaultState
public static MapViewState createDefaultState(int width, int height)
Create the defaultMapViewStateobject for the given map view. The screen position won't be set so that this method can be used before the view was added to the hierarchy.- Parameters:
width- The view widthheight- The view height- Returns:
- The state
- Since:
- 10375
-
calculateDefaultCenter
private static EastNorth calculateDefaultCenter()
-
equalsInWindow
public boolean equalsInWindow(MapViewState other)
Check if this MapViewState equals another one, disregarding the position of the JOSM window on screen.- Parameters:
other- the other MapViewState- Returns:
- true if the other MapViewState has the same size, scale, position and projection, false otherwise
-
-