Class NavigatableComponent

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
org.openstreetmap.josm.gui.NavigatableComponent
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Helpful
Direct Known Subclasses:
MapView

public class NavigatableComponent extends JComponent implements Helpful
A component that can be navigated by a MapMover. Used as map view and for the zoomer in the download dialog.
Since:
41
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • removeZoomChangeListener

      Removes a zoom change listener
      Parameters:
      listener - the listener. Ignored if null or already absent
    • addZoomChangeListener

      Adds a zoom change listener
      Parameters:
      listener - the listener. Ignored if null or already registered.
    • fireZoomChanged

      protected static void fireZoomChanged()
    • removePrimitiveHoverListener

      Removes a primitive hover listener
      Parameters:
      listener - the listener. Ignored if null or already absent.
      Since:
      18574
    • addPrimitiveHoverListener

      Adds a primitive hover listener
      Parameters:
      listener - the listener. Ignored if null or already registered.
      Since:
      18574
    • firePrimitiveHovered

      Parameters:
      e - primitive hover event information
      Since:
      18574
    • updateHoveredPrimitive

      private void updateHoveredPrimitive(IPrimitive hovered, MouseEvent e)
    • addNotify

      public void addNotify()
      Overrides:
      addNotify in class JComponent
    • removeNotify

      public void removeNotify()
      Overrides:
      removeNotify in class JComponent
    • addPrimitiveHoverMouseListeners

    • 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

      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 snap
      floor - 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

      Gets the current view state. This includes the scale, the current view area and the position.
      Returns:
      The current state.
    • getDistText

      public static 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 String getDistText(double dist, NumberFormat format, double threshold)
      Returns the text describing the given distance in the current system of measurement.
      Parameters:
      dist - The distance in metres
      format - A NumberFormat to format the area value
      threshold - Values lower than this threshold are displayed as "< [threshold]"
      Returns:
      the text describing the given distance in the current system of measurement.
      Since:
      7135
    • 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 from
      y - Y-Pixelposition to get coordinate from
      Returns:
      Geographic coordinates from a specific pixel coordination on the screen.
    • getProjectionBounds

      Determines the projection bounds of view area.
      Returns:
      the projection bounds of view area
    • getMaxProjectionBounds

    • 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 from
      y - 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 from
      y - Y-Pixelposition to get coordinate from
      Returns:
      Geographic unprojected coordinates from a specific pixel position on the screen.
    • getProjectionBounds

      Determines the projection bounds of given rectangle.
      Parameters:
      r - rectangle
      Returns:
      the projection bounds of r
    • getLatLonBounds

      Returns minimum bounds that will cover a given rectangle.
      Parameters:
      r - rectangle
      Returns:
      Minimum bounds that will cover rectangle
    • getAffineTransform

      Creates an affine transform that is used to convert the east/north coordinates to view coordinates.
      Returns:
      The affine transform.
    • getPoint2D

      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 Point2D getPoint2D(ILatLon latlon)
      Return the point on the screen where this Coordinate would be.

      Alternative: getState(), then MapViewState.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 Point2D getPoint2D(LatLon latlon)
      Return the point on the screen where this Coordinate would be.

      Alternative: getState(), then MapViewState.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 Point2D getPoint2D(Node n)
      Return the point on the screen where this Node would be.

      Alternative: getState(), then MapViewState.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 Point getPoint(EastNorth p)
      looses precision, may overflow (depends on p and current scale)
      Parameters:
      p - east/north
      Returns:
      point
      See Also:
    • getPoint

      public Point getPoint(ILatLon latlon)
      looses precision, may overflow (depends on p and current scale)
      Parameters:
      latlon - lat/lon
      Returns:
      point
      Since:
      12725
      See Also:
    • getPoint

      public Point getPoint(LatLon latlon)
      looses precision, may overflow (depends on p and current scale)
      Parameters:
      latlon - lat/lon
      Returns:
      point
      See Also:
    • getPoint

      public Point getPoint(Node n)
      looses precision, may overflow (depends on p and current scale)
      Parameters:
      n - node
      Returns:
      point
      See Also:
    • 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(Bounds box)
      Zoom to given bounds.
      Parameters:
      box - new 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
    • getBBox

      private BBox getBBox(Point p, int snapDistance)
    • getNearestNodesImpl

      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 - point
      predicate - predicate to match
      Returns:
      a sorted map with the keys representing the distance of their associated nodes to point p.
    • getNearestNodes

      public final List<Node> getNearestNodes(Point p, Collection<Node> ignore, 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 List<Node> getNearestNodes(Point p, 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:
    • getNearestNode

      public final Node getNearestNode(Point p, 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 point
      predicate - 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(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected, Collection<OsmPrimitive> preferredRefs)
      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.

      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 point
      predicate - this parameter imposes a condition on the returned object, e.g. give the nearest node that is tagged.
      useSelected - make search depend on selection
      preferredRefs - 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(Point p, Predicate<OsmPrimitive> predicate)
      Parameters:
      p - the screen point
      predicate - 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

      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 point
      predicate - 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

      The result *order* depends on the current map selection state. Segments within 10px of p are searched and sorted by their distance to p, 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

      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:
    • getNearestWaySegment

      public final WaySegment getNearestWaySegment(Point p, 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:
    • getNearestWaySegment

      public final WaySegment getNearestWaySegment(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected, 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:
    • getNearestWaySegment

      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 List<Way> getNearestWays(Point p, Collection<Way> ignore, 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:
    • getNearestWays

      public final List<Way> getNearestWays(Point p, 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:
    • getNearestWay

      public final Way getNearestWay(Point p, 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:
    • getNearestNodesOrWays

      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:
    • getNearestNodesOrWays

      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:
    • isPrecedenceNode

      private boolean isPrecedenceNode(Node osm, Point p, boolean useSelected)
      This is used as a helper routine to getNearestNodeOrWay(Point, Predicate, boolean) It decides, whether to yield the node to be tested or look for further (way) candidates.
      Parameters:
      osm - node to check
      p - point clicked
      useSelected - whether to prefer selected nodes
      Returns:
      true, if the node fulfills the properties of the function body
    • getNearestNodeOrWay

      public final OsmPrimitive getNearestNodeOrWay(Point p, 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, try getNearestWaySegment(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:
    • project

      public static Point2D project(double r, Point2D a, 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 value
      a - root of vector
      b - vector
      Returns:
      new point at a + r*(ab)
    • getAllNearest

      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 List<OsmPrimitive> getAllNearest(Point p, 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:
    • getProjection

      Returns the projection to be used in calculating stuff.
      Returns:
      The projection to be used in calculating stuff.
    • helpTopic

      public String helpTopic()
      Description copied from interface: Helpful
      Returns the help topic on JOSM wiki for this feature.
      Specified by:
      helpTopic in 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(Cursor cursor, 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, Object reference)
      Set new cursor.
      Parameters:
      cursor - the type of predefined cursor
      reference - A reference object that can be passed to the next set/reset calls to identify the caller.
    • resetCursor

      public void resetCursor(Object reference)
      Remove the new cursor and reset to previous
      Parameters:
      reference - Cursor reference
    • 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