Class NavigatableComponent
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- org.openstreetmap.josm.gui.NavigatableComponent
-
- All Implemented Interfaces:
java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,Helpful
- Direct Known Subclasses:
MapView
public class NavigatableComponent extends javax.swing.JComponent implements Helpful
A component that can be navigated by aMapMover
. Used as map view and for the zoomer in the download dialog.- Since:
- 41
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
NavigatableComponent.PrimitiveHoverMouseListener
Listener for mouse movement events.private class
NavigatableComponent.SmoothScrollThread
Thread class for smooth scrolling.static interface
NavigatableComponent.ZoomChangeListener
Interface to notify listeners of the change of the zoom area.private static class
NavigatableComponent.ZoomData
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private static double
ALIGNMENT_EPSILON
private java.awt.event.ComponentAdapter
componentListenerNavigatableComponent
protected CursorManager
cursorManager
private java.awt.event.HierarchyListener
hierarchyListenerNavigatableComponent
protected ViewportData
initialViewport
java.util.function.Predicate<OsmPrimitive>
isSelectablePredicate
To determine if a primitive is currently selectable.private NativeScaleLayer
nativeScaleLayer
The layer which scale is set to.private IPrimitive
previousHoveredPrimitive
private java.util.concurrent.CopyOnWriteArrayList<PrimitiveHoverListener>
primitiveHoverListeners
private NavigatableComponent.PrimitiveHoverMouseListener
primitiveHoverMouseListenerHelper
private ProjectionChangeListener
projectionChangeListener
Main uses weak link to store this, so we need to keep a reference.static IntegerProperty
PROP_SNAP_DISTANCE
Snap distancestatic BooleanProperty
PROP_ZOOM_INTERMEDIATE_STEPS
Divide intervals between native resolution levels to smaller steps if they are much larger than zoom ratiostatic DoubleProperty
PROP_ZOOM_RATIO
Zoom steps to get double scalestatic BooleanProperty
PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD
scale follows native resolution of layer status when layer is createdprivate MapViewState
state
The current state (scale, center, ...) of this map view.private static java.util.concurrent.CopyOnWriteArrayList<NavigatableComponent.ZoomChangeListener>
zoomChangeListeners
the zoom listenersprivate java.util.Stack<NavigatableComponent.ZoomData>
zoomRedoBuffer
private long
zoomTimestamp
private java.util.Stack<NavigatableComponent.ZoomData>
zoomUndoBuffer
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description NavigatableComponent()
Constructs a newNavigatableComponent
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNotify()
void
addPrimitiveHoverListener(PrimitiveHoverListener listener)
Adds a primitive hover listenerprivate void
addPrimitiveHoverMouseListeners()
static void
addZoomChangeListener(NavigatableComponent.ZoomChangeListener listener)
Adds a zoom change listenerprotected void
firePrimitiveHovered(PrimitiveHoverListener.PrimitiveHoverEvent e)
Send aPrimitiveHoverListener.PrimitiveHoverEvent
to registeredPrimitiveHoverListener
sprotected static void
fireZoomChanged()
void
fixProjection()
Changes the projection settings used for this map view.java.awt.geom.AffineTransform
getAffineTransform()
Creates an affine transform that is used to convert the east/north coordinates to view coordinates.java.util.List<OsmPrimitive>
getAllNearest(java.awt.Point p, java.util.Collection<OsmPrimitive> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.util.List<OsmPrimitive>
getAllNearest(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.private BBox
getBBox(java.awt.Point p, int snapDistance)
EastNorth
getCenter()
Returns the current center of the viewport.CursorManager
getCursorManager()
Gets the cursor manager that is used for this NavigatableComponent.double
getDist100Pixel()
Get the distance in meter that correspond to 100 px on screen.double
getDist100Pixel(boolean alwaysPositive)
Get the distance in meter that correspond to 100 px on screen.java.lang.String
getDist100PixelText()
Returns the text describing the distance in meter that correspond to 100 px on screen.static java.lang.String
getDistText(double dist)
Returns the text describing the given distance in the current system of measurement.static java.lang.String
getDistText(double dist, java.text.NumberFormat format, double threshold)
Returns the text describing the given distance in the current system of measurement.EastNorth
getEastNorth(int x, int y)
Returns geographic coordinates from a specific pixel coordination on the screen.LatLon
getLatLon(double x, double y)
Returns unprojected geographic coordinates for a specific pixel position on the screen.LatLon
getLatLon(int x, int y)
Returns unprojected geographic coordinates for a specific pixel position on the screen.Bounds
getLatLonBounds(java.awt.Rectangle r)
Returns minimum bounds that will cover a given rectangle.ProjectionBounds
getMaxProjectionBounds()
double
getMaxScale()
Get a max scale for projection that describes world in 1/512 of the projection unitNativeScaleLayer
getNativeScaleLayer()
Replies the layer which scale is set to.Node
getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
Convenience method togetNearestNode(Point, Predicate, boolean)
.Node
getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.Node
getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected, java.util.Collection<OsmPrimitive> preferredRefs)
The *result* depends on the current map selection state IF use_selected is trueOsmPrimitive
getNearestNodeOrWay(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.java.util.List<Node>
getNearestNodes(java.awt.Point p, java.util.Collection<Node> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.util.List<Node>
getNearestNodes(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.private java.util.Map<java.lang.Double,java.util.List<Node>>
getNearestNodesImpl(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.util.List<OsmPrimitive>
getNearestNodesOrWays(java.awt.Point p, java.util.Collection<OsmPrimitive> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.util.List<OsmPrimitive>
getNearestNodesOrWays(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.Way
getNearestWay(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* depends on the current map selection state.java.util.List<Way>
getNearestWays(java.awt.Point p, java.util.Collection<Way> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.util.List<Way>
getNearestWays(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.WaySegment
getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
Convenience method togetNearestWaySegment(Point, Predicate, boolean)
.WaySegment
getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.WaySegment
getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected, java.util.Collection<OsmPrimitive> preferredRefs)
The *result* depends on the current map selection state IF use_selected is true.java.util.List<WaySegment>
getNearestWaySegments(java.awt.Point p, java.util.Collection<WaySegment> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The result *order* depends on the current map selection state.java.util.List<WaySegment>
getNearestWaySegments(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The result *order* depends on the current map selection state.private java.util.Map<java.lang.Double,java.util.List<WaySegment>>
getNearestWaySegmentsImpl(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*.java.awt.Point
getPoint(EastNorth p)
looses precision, may overflow (depends on p and current scale)java.awt.Point
getPoint(ILatLon latlon)
looses precision, may overflow (depends on p and current scale)java.awt.Point
getPoint(LatLon latlon)
looses precision, may overflow (depends on p and current scale)java.awt.Point
getPoint(Node n)
looses precision, may overflow (depends on p and current scale)java.awt.geom.Point2D
getPoint2D(EastNorth p)
Return the point on the screen where this Coordinate would be.java.awt.geom.Point2D
getPoint2D(ILatLon latlon)
Return the point on the screen where this Coordinate would be.java.awt.geom.Point2D
getPoint2D(LatLon latlon)
Return the point on the screen where this Coordinate would be.java.awt.geom.Point2D
getPoint2D(Node n)
Return the point on the screen where this Node would be.Projection
getProjection()
Returns the projection to be used in calculating stuff.ProjectionBounds
getProjectionBounds()
Determines the projection bounds of view area.ProjectionBounds
getProjectionBounds(java.awt.Rectangle r)
Determines the projection bounds of given rectangle.Bounds
getRealBounds()
double
getScale()
Returns the current scale.MapViewState
getState()
Gets the current view state.int
getViewID()
Return an ID which is unique as long as viewport dimensions are the sameboolean
hasZoomRedoEntries()
Determines if zoom history contains "redo" entries.boolean
hasZoomUndoEntries()
Determines if zoom history contains "undo" entries.java.lang.String
helpTopic()
Returns the help topic on JOSM wiki for this feature.private boolean
isPrecedenceNode(Node osm, java.awt.Point p, boolean useSelected)
This is used as a helper routine togetNearestNodeOrWay(Point, Predicate, boolean)
It decides, whether to yield the node to be tested or look for further (way) candidates.protected boolean
isVisibleOnScreen()
static java.awt.geom.Point2D
project(double r, java.awt.geom.Point2D a, java.awt.geom.Point2D b)
if r = 0 returns a, if r=1 returns b, if r = 0.5 returns center between a and b, etc.private void
pushZoomUndo(EastNorth center, double scale)
void
removeNotify()
void
removePrimitiveHoverListener(PrimitiveHoverListener listener)
Removes a primitive hover listenerprivate void
removePrimitiveHoverMouseListeners()
static void
removeZoomChangeListener(NavigatableComponent.ZoomChangeListener listener)
Removes a zoom change listenervoid
resetCursor(java.lang.Object reference)
Remove the new cursor and reset to previousdouble
scaleFloor(double scale)
Get a scale snapped to native resolutions.double
scaleRound(double scale)
Get a scale snapped to native resolutions, use round method.double
scaleSnap(double scale, boolean floor)
Get a scale snapped to native resolutions.double
scaleZoomIn()
Get a new scale that is zoomed in from previous scale and snapped to selected native scale layer.double
scaleZoomManyTimes(int times)
Get a new scale that is zoomed in/out a number of times from previous scale and snapped to selected native scale layer.double
scaleZoomOut()
Get a new scale that is zoomed out from previous scale and snapped to selected native scale layer.void
setNativeScaleLayer(NativeScaleLayer nativeScaleLayer)
Choose a layer that scale will be snap to its native scales.void
setNewCursor(int cursor, java.lang.Object reference)
Set new cursor.void
setNewCursor(java.awt.Cursor cursor, java.lang.Object reference)
Set new cursor.void
smoothScrollTo(EastNorth newCenter)
Create a thread that moves the viewport to the given center in an animated fashion.private void
updateHoveredPrimitive(IPrimitive hovered, java.awt.event.MouseEvent e)
protected void
updateLocationState()
void
zoomIn()
Zoom in current view.void
zoomManyTimes(double x, double y, int times)
void
zoomNext()
Zoom to next location.private void
zoomNoUndoTo(EastNorth newCenter, double newScale, boolean initial)
Zoom to the given coordinate without adding to the zoom undo buffer.void
zoomOut()
Zoom out current view.void
zoomPrevious()
Zoom to previous location.void
zoomTo(Bounds box)
Zoom to given bounds.void
zoomTo(EastNorth newCenter)
Zoom to given east/north.void
zoomTo(EastNorth newCenter, double newScale)
Zoom to the given coordinate and scale.void
zoomTo(EastNorth center, double scale, boolean initial)
Zoom to the given coordinate and scale.void
zoomTo(ILatLon newCenter)
Zoom to given lat/lon.void
zoomTo(LatLon newCenter)
Zoom to given lat/lon.void
zoomTo(BoundingXYVisitor v)
Set the new dimension to the view.void
zoomTo(ProjectionBounds box)
Zoom to given projection bounds.void
zoomTo(ViewportData viewport)
Zoom to given viewport data.void
zoomToFactor(double factor)
void
zoomToFactor(double x, double y, double factor)
void
zoomToFactor(EastNorth newCenter, double factor)
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
ALIGNMENT_EPSILON
private static final double ALIGNMENT_EPSILON
- See Also:
- Constant Field Values
-
isSelectablePredicate
public transient java.util.function.Predicate<OsmPrimitive> isSelectablePredicate
To determine if a primitive is currently selectable.
-
PROP_SNAP_DISTANCE
public static final IntegerProperty PROP_SNAP_DISTANCE
Snap distance
-
PROP_ZOOM_RATIO
public static final DoubleProperty PROP_ZOOM_RATIO
Zoom steps to get double scale
-
PROP_ZOOM_INTERMEDIATE_STEPS
public static final BooleanProperty PROP_ZOOM_INTERMEDIATE_STEPS
Divide intervals between native resolution levels to smaller steps if they are much larger than zoom ratio
-
PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD
public static final BooleanProperty PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD
scale follows native resolution of layer status when layer is created
-
nativeScaleLayer
private transient NativeScaleLayer nativeScaleLayer
The layer which scale is set to.
-
zoomChangeListeners
private static final java.util.concurrent.CopyOnWriteArrayList<NavigatableComponent.ZoomChangeListener> zoomChangeListeners
the zoom listeners
-
primitiveHoverListeners
private final java.util.concurrent.CopyOnWriteArrayList<PrimitiveHoverListener> primitiveHoverListeners
-
previousHoveredPrimitive
private IPrimitive previousHoveredPrimitive
-
primitiveHoverMouseListenerHelper
private final NavigatableComponent.PrimitiveHoverMouseListener primitiveHoverMouseListenerHelper
-
hierarchyListenerNavigatableComponent
private final transient java.awt.event.HierarchyListener hierarchyListenerNavigatableComponent
-
componentListenerNavigatableComponent
private final transient java.awt.event.ComponentAdapter componentListenerNavigatableComponent
-
initialViewport
protected transient ViewportData initialViewport
-
cursorManager
protected final transient CursorManager cursorManager
-
state
private transient MapViewState state
The current state (scale, center, ...) of this map view.
-
projectionChangeListener
private final ProjectionChangeListener projectionChangeListener
Main uses weak link to store this, so we need to keep a reference.
-
zoomUndoBuffer
private final transient java.util.Stack<NavigatableComponent.ZoomData> zoomUndoBuffer
-
zoomRedoBuffer
private final transient java.util.Stack<NavigatableComponent.ZoomData> zoomRedoBuffer
-
zoomTimestamp
private long zoomTimestamp
-
-
Constructor Detail
-
NavigatableComponent
public NavigatableComponent()
Constructs a newNavigatableComponent
.
-
-
Method Detail
-
removeZoomChangeListener
public static void removeZoomChangeListener(NavigatableComponent.ZoomChangeListener listener)
Removes a zoom change listener- Parameters:
listener
- the listener. Ignored if null or already absent
-
addZoomChangeListener
public static void addZoomChangeListener(NavigatableComponent.ZoomChangeListener listener)
Adds a zoom change listener- Parameters:
listener
- the listener. Ignored if null or already registered.
-
fireZoomChanged
protected static void fireZoomChanged()
-
removePrimitiveHoverListener
public void removePrimitiveHoverListener(PrimitiveHoverListener listener)
Removes a primitive hover listener- Parameters:
listener
- the listener. Ignored if null or already absent.- Since:
- 18574
-
addPrimitiveHoverListener
public void addPrimitiveHoverListener(PrimitiveHoverListener listener)
Adds a primitive hover listener- Parameters:
listener
- the listener. Ignored if null or already registered.- Since:
- 18574
-
firePrimitiveHovered
protected void firePrimitiveHovered(PrimitiveHoverListener.PrimitiveHoverEvent e)
Send aPrimitiveHoverListener.PrimitiveHoverEvent
to registeredPrimitiveHoverListener
s- Parameters:
e
- primitive hover event information- Since:
- 18574
-
updateHoveredPrimitive
private void updateHoveredPrimitive(IPrimitive hovered, java.awt.event.MouseEvent e)
-
addNotify
public void addNotify()
- Overrides:
addNotify
in classjavax.swing.JComponent
-
removeNotify
public void removeNotify()
- Overrides:
removeNotify
in classjavax.swing.JComponent
-
addPrimitiveHoverMouseListeners
private void addPrimitiveHoverMouseListeners()
-
removePrimitiveHoverMouseListeners
private void removePrimitiveHoverMouseListeners()
-
setNativeScaleLayer
public void setNativeScaleLayer(NativeScaleLayer nativeScaleLayer)
Choose a layer that scale will be snap to its native scales.- Parameters:
nativeScaleLayer
- layer to which scale will be snapped
-
getNativeScaleLayer
public NativeScaleLayer getNativeScaleLayer()
Replies the layer which scale is set to.- Returns:
- the current scale layer (may be
null
)
-
scaleZoomIn
public double scaleZoomIn()
Get a new scale that is zoomed in from previous scale and snapped to selected native scale layer.- Returns:
- new scale
-
scaleZoomOut
public double scaleZoomOut()
Get a new scale that is zoomed out from previous scale and snapped to selected native scale layer.- Returns:
- new scale
-
scaleZoomManyTimes
public double scaleZoomManyTimes(int times)
Get a new scale that is zoomed in/out a number of times from previous scale and snapped to selected native scale layer.- Parameters:
times
- count of zoom operations, negative means zoom in- Returns:
- new scale
-
scaleRound
public double scaleRound(double scale)
Get a scale snapped to native resolutions, use round method. It gives nearest step from scale list. Use round method.- Parameters:
scale
- to snap- Returns:
- snapped scale
-
scaleFloor
public double scaleFloor(double scale)
Get a scale snapped to native resolutions. It gives nearest lower step from scale list, usable to fit objects.- Parameters:
scale
- to snap- Returns:
- snapped scale
-
scaleSnap
public double scaleSnap(double scale, boolean floor)
Get a scale snapped to native resolutions. It gives nearest lower step from scale list, usable to fit objects.- Parameters:
scale
- to snapfloor
- use floor instead of round, set true when fitting view to objects- Returns:
- new scale
-
zoomIn
public void zoomIn()
Zoom in current view. Use configured zoom step and scaling settings.
-
zoomOut
public void zoomOut()
Zoom out current view. Use configured zoom step and scaling settings.
-
updateLocationState
protected void updateLocationState()
-
isVisibleOnScreen
protected boolean isVisibleOnScreen()
-
fixProjection
public void fixProjection()
Changes the projection settings used for this map view.Made public temporarily, will be made private later.
-
getState
public MapViewState getState()
Gets the current view state. This includes the scale, the current view area and the position.- Returns:
- The current state.
-
getDistText
public static java.lang.String getDistText(double dist)
Returns the text describing the given distance in the current system of measurement.- Parameters:
dist
- The distance in metres.- Returns:
- the text describing the given distance in the current system of measurement.
- Since:
- 3406
-
getDistText
public static java.lang.String getDistText(double dist, java.text.NumberFormat format, double threshold)
Returns the text describing the given distance in the current system of measurement.- Parameters:
dist
- The distance in metresformat
- ANumberFormat
to format the area valuethreshold
- Values lower than thisthreshold
are displayed as"< [threshold]"
- Returns:
- the text describing the given distance in the current system of measurement.
- Since:
- 7135
-
getDist100PixelText
public java.lang.String getDist100PixelText()
Returns the text describing the distance in meter that correspond to 100 px on screen.- Returns:
- the text describing the distance in meter that correspond to 100 px on screen
-
getDist100Pixel
public double getDist100Pixel()
Get the distance in meter that correspond to 100 px on screen.- Returns:
- the distance in meter that correspond to 100 px on screen
-
getDist100Pixel
public double getDist100Pixel(boolean alwaysPositive)
Get the distance in meter that correspond to 100 px on screen.- Parameters:
alwaysPositive
- if true, makes sure the return value is always > 0. (Two points 100 px apart can appear to be identical if the user has zoomed out a lot and the projection code does something funny.)- Returns:
- the distance in meter that correspond to 100 px on screen
-
getCenter
public EastNorth getCenter()
Returns the current center of the viewport.(Use
zoomTo(EastNorth)
to the change the center.)- Returns:
- the current center of the viewport
-
getScale
public double getScale()
Returns the current scale.In east/north units per pixel.
- Returns:
- the current scale
-
getEastNorth
public EastNorth getEastNorth(int x, int y)
Returns geographic coordinates from a specific pixel coordination on the screen.- Parameters:
x
- X-Pixelposition to get coordinate fromy
- Y-Pixelposition to get coordinate from- Returns:
- Geographic coordinates from a specific pixel coordination on the screen.
-
getProjectionBounds
public ProjectionBounds getProjectionBounds()
Determines the projection bounds of view area.- Returns:
- the projection bounds of view area
-
getMaxProjectionBounds
public ProjectionBounds getMaxProjectionBounds()
-
getRealBounds
public Bounds getRealBounds()
-
getLatLon
public LatLon getLatLon(int x, int y)
Returns unprojected geographic coordinates for a specific pixel position on the screen.- Parameters:
x
- X-Pixelposition to get coordinate fromy
- Y-Pixelposition to get coordinate from- Returns:
- Geographic unprojected coordinates from a specific pixel position on the screen.
-
getLatLon
public LatLon getLatLon(double x, double y)
Returns unprojected geographic coordinates for a specific pixel position on the screen.- Parameters:
x
- X-Pixelposition to get coordinate fromy
- Y-Pixelposition to get coordinate from- Returns:
- Geographic unprojected coordinates from a specific pixel position on the screen.
-
getProjectionBounds
public ProjectionBounds getProjectionBounds(java.awt.Rectangle r)
Determines the projection bounds of given rectangle.- Parameters:
r
- rectangle- Returns:
- the projection bounds of
r
-
getLatLonBounds
public Bounds getLatLonBounds(java.awt.Rectangle r)
Returns minimum bounds that will cover a given rectangle.- Parameters:
r
- rectangle- Returns:
- Minimum bounds that will cover rectangle
-
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.
-
getPoint2D
public java.awt.geom.Point2D getPoint2D(EastNorth p)
Return the point on the screen where this Coordinate would be.- Parameters:
p
- The point, where this geopoint would be drawn.- Returns:
- The point on screen where "point" would be drawn, relative to the own top/left.
-
getPoint2D
public java.awt.geom.Point2D getPoint2D(ILatLon latlon)
Return the point on the screen where this Coordinate would be.Alternative:
getState()
, thenMapViewState.getPointFor(ILatLon)
- Parameters:
latlon
- The point, where this geopoint would be drawn.- Returns:
- The point on screen where "point" would be drawn, relative to the own top/left.
-
getPoint2D
public java.awt.geom.Point2D getPoint2D(LatLon latlon)
Return the point on the screen where this Coordinate would be.Alternative:
getState()
, thenMapViewState.getPointFor(ILatLon)
- Parameters:
latlon
- The point, where this geopoint would be drawn.- Returns:
- The point on screen where "point" would be drawn, relative to the own top/left.
-
getPoint2D
public java.awt.geom.Point2D getPoint2D(Node n)
Return the point on the screen where this Node would be.Alternative:
getState()
, thenMapViewState.getPointFor(ILatLon)
- Parameters:
n
- The node, where this geopoint would be drawn.- Returns:
- The point on screen where "node" would be drawn, relative to the own top/left.
-
getPoint
public java.awt.Point getPoint(EastNorth p)
looses precision, may overflow (depends on p and current scale)- Parameters:
p
- east/north- Returns:
- point
- See Also:
getPoint2D(EastNorth)
-
getPoint
public java.awt.Point getPoint(ILatLon latlon)
looses precision, may overflow (depends on p and current scale)- Parameters:
latlon
- lat/lon- Returns:
- point
- Since:
- 12725
- See Also:
getPoint2D(LatLon)
-
getPoint
public java.awt.Point getPoint(LatLon latlon)
looses precision, may overflow (depends on p and current scale)- Parameters:
latlon
- lat/lon- Returns:
- point
- See Also:
getPoint2D(LatLon)
-
getPoint
public java.awt.Point getPoint(Node n)
looses precision, may overflow (depends on p and current scale)- Parameters:
n
- node- Returns:
- point
- See Also:
getPoint2D(Node)
-
zoomTo
public void zoomTo(EastNorth newCenter, double newScale)
Zoom to the given coordinate and scale.- Parameters:
newCenter
- The center x-value (easting) to zoom to.newScale
- The scale to use.
-
zoomTo
public void zoomTo(EastNorth center, double scale, boolean initial)
Zoom to the given coordinate and scale.- Parameters:
center
- The center x-value (easting) to zoom to.scale
- The scale to use.initial
- true if this call initializes the viewport.
-
zoomNoUndoTo
private void zoomNoUndoTo(EastNorth newCenter, double newScale, boolean initial)
Zoom to the given coordinate without adding to the zoom undo buffer.- Parameters:
newCenter
- The center x-value (easting) to zoom to.newScale
- The scale to use.initial
- true if this call initializes the viewport.
-
zoomTo
public void zoomTo(EastNorth newCenter)
Zoom to given east/north.- Parameters:
newCenter
- new center coordinates
-
zoomTo
public void zoomTo(ILatLon newCenter)
Zoom to given lat/lon.- Parameters:
newCenter
- new center coordinates- Since:
- 12725
-
zoomTo
public void zoomTo(LatLon newCenter)
Zoom to given lat/lon.- Parameters:
newCenter
- new center coordinates
-
smoothScrollTo
public void smoothScrollTo(EastNorth newCenter)
Create a thread that moves the viewport to the given center in an animated fashion.- Parameters:
newCenter
- new east/north center
-
zoomManyTimes
public void zoomManyTimes(double x, double y, int times)
-
zoomToFactor
public void zoomToFactor(double x, double y, double factor)
-
zoomToFactor
public void zoomToFactor(EastNorth newCenter, double factor)
-
zoomToFactor
public void zoomToFactor(double factor)
-
zoomTo
public void zoomTo(ProjectionBounds box)
Zoom to given projection bounds.- Parameters:
box
- new projection bounds
-
zoomTo
public void zoomTo(ViewportData viewport)
Zoom to given viewport data.- Parameters:
viewport
- new viewport data
-
zoomTo
public void zoomTo(BoundingXYVisitor v)
Set the new dimension to the view.- Parameters:
v
- box to zoom to
-
pushZoomUndo
private void pushZoomUndo(EastNorth center, double scale)
-
zoomPrevious
public void zoomPrevious()
Zoom to previous location.
-
zoomNext
public void zoomNext()
Zoom to next location.
-
hasZoomUndoEntries
public boolean hasZoomUndoEntries()
Determines if zoom history contains "undo" entries.- Returns:
true
if zoom history contains "undo" entries
-
hasZoomRedoEntries
public boolean hasZoomRedoEntries()
Determines if zoom history contains "redo" entries.- Returns:
true
if zoom history contains "redo" entries
-
getNearestNodesImpl
private java.util.Map<java.lang.Double,java.util.List<Node>> getNearestNodesImpl(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- pointpredicate
- predicate to match- Returns:
- a sorted map with the keys representing the distance of their associated nodes to point p.
-
getNearestNodes
public final java.util.List<Node> getNearestNodes(java.awt.Point p, java.util.Collection<Node> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- the point for which to search the nearest segment.ignore
- a collection of nodes which are not to be returned.predicate
- the returned objects have to fulfill certain properties.- Returns:
- All nodes nearest to point p that are in a belt from dist(nearest) to dist(nearest)+4px around p and that are not in ignore.
-
getNearestNodes
public final java.util.List<Node> getNearestNodes(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- the point for which to search the nearest segment.predicate
- the returned objects have to fulfill certain properties.- Returns:
- All nodes nearest to point p that are in a belt from dist(nearest) to dist(nearest)+4px around p.
- See Also:
getNearestNodes(Point, Collection, Predicate)
-
getNearestNode
public final Node getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.If more than one node within node.snap-distance pixels is found, the nearest node selected is returned IF use_selected is true.
Else the nearest new/id=0 node within about the same distance as the true nearest node is returned.
If no such node is found either, the true nearest node to p is returned.
Finally, if a node is not found at all,
null
is returned.- Parameters:
p
- the screen pointpredicate
- this parameter imposes a condition on the returned object, e.g. give the nearest node that is tagged.useSelected
- make search depend on selection- Returns:
- A node within snap-distance to point p, that is chosen by the algorithm described.
-
getNearestNode
public final Node getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected, java.util.Collection<OsmPrimitive> preferredRefs)
The *result* depends on the current map selection state IF use_selected is trueIf more than one node within node.snap-distance pixels is found, the nearest node selected is returned IF use_selected is true.
If there are no selected nodes near that point, the node that is related to some of the preferredRefs
Else the nearest new/id=0 node within about the same distance as the true nearest node is returned.
If no such node is found either, the true nearest node to p is returned.
Finally, if a node is not found at all,
null
is returned.- Parameters:
p
- the screen pointpredicate
- this parameter imposes a condition on the returned object, e.g. give the nearest node that is tagged.useSelected
- make search depend on selectionpreferredRefs
- primitives, whose nodes we prefer- Returns:
- A node within snap-distance to point p, that is chosen by the algorithm described.
- Since:
- 6065
-
getNearestNode
public final Node getNearestNode(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
Convenience method togetNearestNode(Point, Predicate, boolean)
.- Parameters:
p
- the screen pointpredicate
- this parameter imposes a condition on the returned object, e.g. give the nearest node that is tagged.- Returns:
- The nearest node to point p.
-
getNearestWaySegmentsImpl
private java.util.Map<java.lang.Double,java.util.List<WaySegment>> getNearestWaySegmentsImpl(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- the screen pointpredicate
- this parameter imposes a condition on the returned object, e.g. give the nearest node that is tagged.- Returns:
- a sorted map with the keys representing the perpendicular distance of their associated way segments to point p.
-
getNearestWaySegments
public final java.util.List<WaySegment> getNearestWaySegments(java.awt.Point p, java.util.Collection<WaySegment> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The result *order* depends on the current map selection state. Segments within 10px of p are searched and sorted by their distance top
, then, within groups of equally distant segments, prefer those that are selected.- Parameters:
p
- the point for which to search the nearest segments.ignore
- a collection of segments which are not to be returned.predicate
- the returned objects have to fulfill certain properties.- Returns:
- all segments within 10px of p that are not in ignore, sorted by their perpendicular distance.
-
getNearestWaySegments
public final java.util.List<WaySegment> getNearestWaySegments(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The result *order* depends on the current map selection state.- Parameters:
p
- the point for which to search the nearest segments.predicate
- the returned objects have to fulfill certain properties.- Returns:
- all segments within 10px of p, sorted by their perpendicular distance.
- See Also:
getNearestWaySegments(Point, Collection, Predicate)
-
getNearestWaySegment
public final WaySegment getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.- Parameters:
p
- the point for which to search the nearest segment.predicate
- the returned object has to fulfill certain properties.useSelected
- whether selected way segments should be preferred.- Returns:
- The nearest way segment to point p, and, depending on use_selected, prefers a selected way segment, if found.
- See Also:
getNearestWaySegments(Point, Collection, Predicate)
-
getNearestWaySegment
public final WaySegment getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected, java.util.Collection<OsmPrimitive> preferredRefs)
The *result* depends on the current map selection state IF use_selected is true.- Parameters:
p
- the point for which to search the nearest segment.predicate
- the returned object has to fulfill certain properties.useSelected
- whether selected way segments should be preferred.preferredRefs
- - prefer segments related to these primitives, may be null- Returns:
- The nearest way segment to point p, and, depending on use_selected, prefers a selected way segment, if found. Also prefers segments of ways that are related to one of preferredRefs primitives
- Since:
- 6065
- See Also:
getNearestWaySegments(Point, Collection, Predicate)
-
getNearestWaySegment
public final WaySegment getNearestWaySegment(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
Convenience method togetNearestWaySegment(Point, Predicate, boolean)
.- Parameters:
p
- the point for which to search the nearest segment.predicate
- the returned object has to fulfill certain properties.- Returns:
- The nearest way segment to point p.
-
getNearestWays
public final java.util.List<Way> getNearestWays(java.awt.Point p, java.util.Collection<Way> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the perpendicular distance to point p.- Parameters:
p
- the point for which to search the nearest ways.ignore
- a collection of ways which are not to be returned.predicate
- the returned object has to fulfill certain properties.- Returns:
- all nearest ways to the screen point given that are not in ignore.
- See Also:
getNearestWaySegments(Point, Collection, Predicate)
-
getNearestWays
public final java.util.List<Way> getNearestWays(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the perpendicular distance to point p.- Parameters:
p
- the point for which to search the nearest ways.predicate
- the returned object has to fulfill certain properties.- Returns:
- all nearest ways to the screen point given.
- See Also:
getNearestWays(Point, Collection, Predicate)
-
getNearestWay
public final Way getNearestWay(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* depends on the current map selection state.- Parameters:
p
- the point for which to search the nearest segment.predicate
- the returned object has to fulfill certain properties.- Returns:
- The nearest way to point p, prefer a selected way if there are multiple nearest.
- See Also:
getNearestWaySegment(Point, Predicate)
-
getNearestNodesOrWays
public final java.util.List<OsmPrimitive> getNearestNodesOrWays(java.awt.Point p, java.util.Collection<OsmPrimitive> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.First, nodes will be searched. If there are nodes within BBox found, return a collection of those nodes only.
If no nodes are found, search for nearest ways. If there are ways within BBox found, return a collection of those ways only.
If nothing is found, return an empty collection.
- Parameters:
p
- The point on screen.ignore
- a collection of ways which are not to be returned.predicate
- the returned object has to fulfill certain properties.- Returns:
- Primitives nearest to the given screen point that are not in ignore.
- See Also:
getNearestNodes(Point, Collection, Predicate)
,getNearestWays(Point, Collection, Predicate)
-
getNearestNodesOrWays
public final java.util.List<OsmPrimitive> getNearestNodesOrWays(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- The point on screen.predicate
- the returned object has to fulfill certain properties.- Returns:
- Primitives nearest to the given screen point.
- See Also:
getNearestNodesOrWays(Point, Collection, Predicate)
-
isPrecedenceNode
private boolean isPrecedenceNode(Node osm, java.awt.Point p, boolean useSelected)
This is used as a helper routine togetNearestNodeOrWay(Point, Predicate, boolean)
It decides, whether to yield the node to be tested or look for further (way) candidates.- Parameters:
osm
- node to checkp
- point clickeduseSelected
- whether to prefer selected nodes- Returns:
- true, if the node fulfills the properties of the function body
-
getNearestNodeOrWay
public final OsmPrimitive getNearestNodeOrWay(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate, boolean useSelected)
The *result* depends on the current map selection state IF use_selected is true.IF use_selected is true, use
getNearestNode(Point, Predicate)
to find the nearest, selected node. If not found, trygetNearestWaySegment(Point, Predicate)
to find the nearest selected way.IF use_selected is false, or if no selected primitive was found, do the following.
If the nearest node found is within 4px of p, simply take it. Else, find the nearest way segment. Then, if p is closer to its middle than to the node, take the way segment, else take the node.
Finally, if no nearest primitive is found at all, return
null
.- Parameters:
p
- The point on screen.predicate
- the returned object has to fulfill certain properties.useSelected
- whether to prefer primitives that are currently selected or referred by selected primitives- Returns:
- A primitive within snap-distance to point p, that is chosen by the algorithm described.
- See Also:
getNearestNode(Point, Predicate)
,getNearestWay(Point, Predicate)
-
project
public static java.awt.geom.Point2D project(double r, java.awt.geom.Point2D a, java.awt.geom.Point2D b)
if r = 0 returns a, if r=1 returns b, if r = 0.5 returns center between a and b, etc.- Parameters:
r
- scale valuea
- root of vectorb
- vector- Returns:
- new point at a + r*(ab)
-
getAllNearest
public final java.util.List<OsmPrimitive> getAllNearest(java.awt.Point p, java.util.Collection<OsmPrimitive> ignore, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- The point on screen.ignore
- a collection of ways which are not to be returned.predicate
- the returned object has to fulfill certain properties.- Returns:
- a list of all objects that are nearest to point p and not in ignore or an empty list if nothing was found.
-
getAllNearest
public final java.util.List<OsmPrimitive> getAllNearest(java.awt.Point p, java.util.function.Predicate<OsmPrimitive> predicate)
The *result* does not depend on the current map selection state, neither does the result *order*. It solely depends on the distance to point p.- Parameters:
p
- The point on screen.predicate
- the returned object has to fulfill certain properties.- Returns:
- a list of all objects that are nearest to point p or an empty list if nothing was found.
- See Also:
getAllNearest(Point, Collection, Predicate)
-
getProjection
public Projection getProjection()
Returns the projection to be used in calculating stuff.- Returns:
- The projection to be used in calculating stuff.
-
helpTopic
public java.lang.String helpTopic()
Description copied from interface:Helpful
Returns the help topic on JOSM wiki for this feature.
-
getViewID
public int getViewID()
Return an ID which is unique as long as viewport dimensions are the same- Returns:
- A unique ID, as long as viewport dimensions are the same
-
setNewCursor
public void setNewCursor(java.awt.Cursor cursor, java.lang.Object reference)
Set new cursor.- Parameters:
cursor
- The new cursor to use.reference
- A reference object that can be passed to the next set/reset calls to identify the caller.
-
setNewCursor
public void setNewCursor(int cursor, java.lang.Object reference)
Set new cursor.- Parameters:
cursor
- the type of predefined cursorreference
- A reference object that can be passed to the next set/reset calls to identify the caller.
-
resetCursor
public void resetCursor(java.lang.Object reference)
Remove the new cursor and reset to previous- Parameters:
reference
- Cursor reference
-
getCursorManager
public CursorManager getCursorManager()
Gets the cursor manager that is used for this NavigatableComponent.- Returns:
- The cursor manager.
-
getMaxScale
public double getMaxScale()
Get a max scale for projection that describes world in 1/512 of the projection unit- Returns:
- max scale
-
-