Package org.openstreetmap.josm.gui
Class MapView
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- org.openstreetmap.josm.gui.NavigatableComponent
-
- org.openstreetmap.josm.gui.MapView
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.beans.PropertyChangeListener,java.io.Serializable,java.util.EventListener,Helpful,LayerManager.LayerChangeListener,MainLayerManager.ActiveLayerChangeListener,PreferenceChangedListener
public class MapView extends NavigatableComponent implements java.beans.PropertyChangeListener, PreferenceChangedListener, LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener
This is a component used in theMapFramefor browsing the map. It use is to provide the MapMode's enough capabilities to operate.
MapViewholds meta-data about the data set currently displayed, as scale level, center point viewed, what scrolling mode or editing mode is selected or with what projection the map is viewed etc..
MapViewis able to administrate several layers.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classMapView.LayerInvalidatedListenerAn invalidation listener that simply calls repaint() for now.static interfaceMapView.RepaintListenerThis is a listener that gets informed whenever repaint is called for this MapView.private static classMapView.WarningLayerPainterA layer painter that issues a warning when being called.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.NavigatableComponent
NavigatableComponent.ZoomChangeListener
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private MapView.LayerInvalidatedListenerinvalidatedListenerThe listener that listens to invalidations of all layers.private java.awt.RectanglelastClipBoundsjava.awt.event.MouseEventlastMEventThe last event performed by mouse.private intlastViewIDprivate MainLayerManagerlayerManagerA list of all layers currently loaded.private MapMovermapMoverprivate java.util.List<? extends javax.swing.JComponent>mapNavigationComponentsprivate java.util.List<Layer>nonChangedLayersprivate java.awt.image.BufferedImagenonChangedLayersBufferprivate java.awt.image.BufferedImageoffscreenBufferprivate java.awt.PointoldLocprivate java.awt.DimensionoldSizeprivate java.util.concurrent.atomic.AtomicBooleanpaintPreferencesChangedPlayHeadMarkerplayHeadMarkerThe play head marker: there is only one of these so it isn't in any specific layerprivate java.util.HashMap<Layer,MapViewPaintable.LayerPainter>registeredLayersThis is a map of all Layers that have been added to this view.private java.util.concurrent.CopyOnWriteArrayList<MapView.RepaintListener>repaintListenersprivate DataSelectionListenerrepaintSelectionChangedListenerprivate java.util.Set<MapViewPaintable>temporaryLayersTemporary layers (selection rectangle, etc.) that are never cached and drawn on top of regular layers.private booleanvirtualNodesEnabledprivate java.awt.StrokeworldBorderStroke-
Fields inherited from class org.openstreetmap.josm.gui.NavigatableComponent
cursorManager, initialViewport, isSelectablePredicate, PROP_SNAP_DISTANCE, PROP_ZOOM_INTERMEDIATE_STEPS, PROP_ZOOM_RATIO, PROP_ZOOM_SCALE_FOLLOW_NATIVE_RES_AT_LOAD
-
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 MapView(MainLayerManager layerManager, ViewportData viewportData)Constructs a newMapView.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactiveOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)Called whenever the active or edit layer changed.voidaddRepaintListener(MapView.RepaintListener l)Adds a listener that gets informed whenever repaint() is called for this class.booleanaddTemporaryLayer(MapViewPaintable mvp)Adds a new temporary layer.voiddestroy()Destroy this map view panel.private voiddrawMapContent(java.awt.Graphics2D g)private voiddrawTemporaryLayers(java.awt.Graphics2D tempG, Bounds box)private voiddrawWorldBorders(java.awt.Graphics2D tempG)private static java.awt.image.BufferedImagegetAcceleratedImage(java.awt.Component mv, int width, int height)java.lang.StringgetLayerInformationForSourceTag()Get a string representation of all layers suitable for thesourcechangeset tag.MainLayerManagergetLayerManager()Returns the layer manager.MapMovergetMapMover()Returns the internalMapMover.static java.util.List<? extends javax.swing.JComponent>getMapNavigationComponents(MapView forMapView)Adds the map navigation components to ajava.util.List<MapViewPaintable>getTemporaryLayers()Gets a list of temporary layers.booleanisActiveLayerDrawable()Replies true if the active data layer (edit layer) is drawable.booleanisActiveLayerVisible()Replies true if the active data layer is visible.booleanisVirtualNodesEnabled()Checks if virtual nodes should be drawn.voidlayerAdded(LayerManager.LayerAddEvent e)Notifies this listener that a layer has been added.voidlayerOrderChanged(LayerManager.LayerOrderChangeEvent e)Notifies this listener that the order of layers was changed.voidlayerRemoving(LayerManager.LayerRemoveEvent e)Notifies this listener that a layer was just removed.voidmoveLayer(Layer layer, int pos)Moves the layer to the given new position.voidpaint(java.awt.Graphics g)Draw the component.voidpaintLayer(Layer layer, java.awt.Graphics2D g)Paints the given layer to the graphics object, using the current state of this map view.voidpreferenceChanged(PreferenceChangeEvent e)Triggered when a preference entry value changes.booleanprepareToDraw()Sets up the viewport to prepare for drawing the view.voidpropertyChange(java.beans.PropertyChangeEvent evt)voidrememberLastPositionOnScreen()Call this method to keep map position on screen during next repaintvoidremoveRepaintListener(MapView.RepaintListener l)Removes a registered repaint listener.booleanremoveTemporaryLayer(MapViewPaintable mvp)Removes a layer previously added as temporary layer.voidrepaint()voidrepaint(long tm, int x, int y, int width, int height)voidscheduleZoomTo(ViewportData viewportData)Schedule a zoom to the given position on the next redraw.voidsetMapNavigationComponentVisibility(boolean visible)Set the visibility of the navigation componentvoidsetVirtualNodesEnabled(boolean enabled)Enables or disables drawing of the virtual nodes.-
Methods inherited from class org.openstreetmap.josm.gui.NavigatableComponent
addNotify, addPrimitiveHoverListener, addZoomChangeListener, firePrimitiveHovered, fireZoomChanged, fixProjection, getAffineTransform, getAllNearest, getAllNearest, getCenter, getCursorManager, getDist100Pixel, getDist100Pixel, getDist100PixelText, getDistText, getDistText, getEastNorth, getLatLon, getLatLon, getLatLonBounds, getMaxProjectionBounds, getMaxScale, getNativeScaleLayer, getNearestNode, getNearestNode, getNearestNode, getNearestNodeOrWay, getNearestNodes, getNearestNodes, getNearestNodesOrWays, getNearestNodesOrWays, getNearestWay, getNearestWays, getNearestWays, getNearestWaySegment, getNearestWaySegment, getNearestWaySegment, getNearestWaySegments, getNearestWaySegments, getPoint, getPoint, getPoint, getPoint, getPoint2D, getPoint2D, getPoint2D, getPoint2D, getProjection, getProjectionBounds, getProjectionBounds, getRealBounds, getScale, getState, getViewID, hasZoomRedoEntries, hasZoomUndoEntries, helpTopic, isVisibleOnScreen, project, removeNotify, removePrimitiveHoverListener, removeZoomChangeListener, resetCursor, scaleFloor, scaleRound, scaleSnap, scaleZoomIn, scaleZoomManyTimes, scaleZoomOut, setNativeScaleLayer, setNewCursor, setNewCursor, smoothScrollTo, updateLocationState, zoomIn, zoomManyTimes, zoomNext, zoomOut, zoomPrevious, zoomTo, zoomTo, zoomTo, zoomTo, zoomTo, zoomTo, zoomTo, zoomTo, zoomTo, zoomToFactor, zoomToFactor, zoomToFactor
-
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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, 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, 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
-
layerManager
private final MainLayerManager layerManager
A list of all layers currently loaded. If we support multiple map views, this list may be different for each of them.
-
playHeadMarker
public transient PlayHeadMarker playHeadMarker
The play head marker: there is only one of these so it isn't in any specific layer
-
lastMEvent
public java.awt.event.MouseEvent lastMEvent
The last event performed by mouse.
-
temporaryLayers
private final transient java.util.Set<MapViewPaintable> temporaryLayers
Temporary layers (selection rectangle, etc.) that are never cached and drawn on top of regular layers. Access must be synchronized.
-
nonChangedLayersBuffer
private transient java.awt.image.BufferedImage nonChangedLayersBuffer
-
offscreenBuffer
private transient java.awt.image.BufferedImage offscreenBuffer
-
nonChangedLayers
private final transient java.util.List<Layer> nonChangedLayers
-
lastViewID
private int lastViewID
-
paintPreferencesChanged
private final java.util.concurrent.atomic.AtomicBoolean paintPreferencesChanged
-
lastClipBounds
private java.awt.Rectangle lastClipBounds
-
mapNavigationComponents
private final java.util.List<? extends javax.swing.JComponent> mapNavigationComponents
-
worldBorderStroke
private final java.awt.Stroke worldBorderStroke
-
invalidatedListener
private final MapView.LayerInvalidatedListener invalidatedListener
The listener that listens to invalidations of all layers.
-
registeredLayers
private final java.util.HashMap<Layer,MapViewPaintable.LayerPainter> registeredLayers
This is a map of all Layers that have been added to this view.
-
oldSize
private java.awt.Dimension oldSize
-
oldLoc
private java.awt.Point oldLoc
-
virtualNodesEnabled
private boolean virtualNodesEnabled
-
repaintSelectionChangedListener
private final transient DataSelectionListener repaintSelectionChangedListener
-
repaintListeners
private final transient java.util.concurrent.CopyOnWriteArrayList<MapView.RepaintListener> repaintListeners
-
-
Constructor Detail
-
MapView
public MapView(MainLayerManager layerManager, ViewportData viewportData)
Constructs a newMapView.- Parameters:
layerManager- The layers to display.viewportData- the initial viewport of the map. Can be null, then the viewport is derived from the layer data.- Since:
- 11713
-
-
Method Detail
-
getMapNavigationComponents
public static java.util.List<? extends javax.swing.JComponent> getMapNavigationComponents(MapView forMapView)
Adds the map navigation components to a- Parameters:
forMapView- The map view to get the components for.- Returns:
- A list containing the correctly positioned map navigation components.
-
getAcceleratedImage
private static java.awt.image.BufferedImage getAcceleratedImage(java.awt.Component mv, int width, int height)
-
rememberLastPositionOnScreen
public void rememberLastPositionOnScreen()
Call this method to keep map position on screen during next repaint
-
layerAdded
public void layerAdded(LayerManager.LayerAddEvent e)
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that a layer has been added.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerAddedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The new added layer event
-
isActiveLayerDrawable
public boolean isActiveLayerDrawable()
Replies true if the active data layer (edit layer) is drawable.- Returns:
- true if the active data layer (edit layer) is drawable, false otherwise
-
isActiveLayerVisible
public boolean isActiveLayerVisible()
Replies true if the active data layer is visible.- Returns:
- true if the active data layer is visible, false otherwise
-
layerRemoving
public void layerRemoving(LayerManager.LayerRemoveEvent e)
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that a layer was just removed.Listeners are called in the EDT thread after the layer was removed. Use
LayerManager.LayerRemoveEvent.scheduleRemoval(Collection)to remove more layers. You should not do blocking or long-running tasks in this method.- Specified by:
layerRemovingin interfaceLayerManager.LayerChangeListener- Parameters:
e- The layer to be removed (as event)
-
setVirtualNodesEnabled
public void setVirtualNodesEnabled(boolean enabled)
Enables or disables drawing of the virtual nodes.- Parameters:
enabled- if virtual nodes are enabled
-
isVirtualNodesEnabled
public boolean isVirtualNodesEnabled()
Checks if virtual nodes should be drawn. Default isfalse- Returns:
- The virtual nodes property.
- See Also:
Rendering.render(org.openstreetmap.josm.data.osm.OsmData<?, ?, ?, ?>, boolean, org.openstreetmap.josm.data.Bounds)
-
moveLayer
public void moveLayer(Layer layer, int pos)
Moves the layer to the given new position. No event is fired, but repaints according to the new Z-Order of the layers.- Parameters:
layer- The layer to movepos- The new position of the layer
-
layerOrderChanged
public void layerOrderChanged(LayerManager.LayerOrderChangeEvent e)
Description copied from interface:LayerManager.LayerChangeListenerNotifies this listener that the order of layers was changed.Listeners are called in the EDT thread. You should not do blocking or long-running tasks in this method.
- Specified by:
layerOrderChangedin interfaceLayerManager.LayerChangeListener- Parameters:
e- The order change event.
-
paintLayer
public void paintLayer(Layer layer, java.awt.Graphics2D g)
Paints the given layer to the graphics object, using the current state of this map view.- Parameters:
layer- The layer to draw.g- A graphics object. It should have the width and height of this component- Throws:
java.lang.IllegalArgumentException- If the layer is not part of this map view.- Since:
- 11226
-
paint
public void paint(java.awt.Graphics g)
Draw the component.- Overrides:
paintin classjavax.swing.JComponent
-
drawMapContent
private void drawMapContent(java.awt.Graphics2D g)
-
drawTemporaryLayers
private void drawTemporaryLayers(java.awt.Graphics2D tempG, Bounds box)
-
drawWorldBorders
private void drawWorldBorders(java.awt.Graphics2D tempG)
-
prepareToDraw
public boolean prepareToDraw()
Sets up the viewport to prepare for drawing the view.- Returns:
trueif the view can be drawn,falseotherwise.
-
activeOrEditLayerChanged
public void activeOrEditLayerChanged(MainLayerManager.ActiveLayerChangeEvent e)
Description copied from interface:MainLayerManager.ActiveLayerChangeListenerCalled whenever the active or edit layer changed.You can be sure that this layer is still contained in this set.
Listeners are called in the EDT thread and you can manipulate the layer manager in the current thread.
- Specified by:
activeOrEditLayerChangedin interfaceMainLayerManager.ActiveLayerChangeListener- Parameters:
e- The change event.
-
addTemporaryLayer
public boolean addTemporaryLayer(MapViewPaintable mvp)
Adds a new temporary layer.A temporary layer is a layer that is painted above all normal layers. Layers are painted in the order they are added.
- Parameters:
mvp- The layer to paint.- Returns:
trueif the layer was added.
-
removeTemporaryLayer
public boolean removeTemporaryLayer(MapViewPaintable mvp)
Removes a layer previously added as temporary layer.- Parameters:
mvp- The layer to remove.- Returns:
trueif that layer was removed.
-
getTemporaryLayers
public java.util.List<MapViewPaintable> getTemporaryLayers()
Gets a list of temporary layers.- Returns:
- The layers in the order they are added.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
preferenceChanged
public void preferenceChanged(PreferenceChangeEvent e)
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-
destroy
public void destroy()
Destroy this map view panel. Should be called once when it is not needed any more.
-
getLayerInformationForSourceTag
public java.lang.String getLayerInformationForSourceTag()
Get a string representation of all layers suitable for thesourcechangeset tag.- Returns:
- A String of sources separated by ';'
-
addRepaintListener
public void addRepaintListener(MapView.RepaintListener l)
Adds a listener that gets informed whenever repaint() is called for this class.- Parameters:
l- The listener.
-
removeRepaintListener
public void removeRepaintListener(MapView.RepaintListener l)
Removes a registered repaint listener.- Parameters:
l- The listener.
-
repaint
public void repaint(long tm, int x, int y, int width, int height)
- Overrides:
repaintin classjavax.swing.JComponent
-
repaint
public void repaint()
- Overrides:
repaintin classjava.awt.Component
-
getLayerManager
public final MainLayerManager getLayerManager()
Returns the layer manager.- Returns:
- the layer manager
- Since:
- 10282
-
scheduleZoomTo
public void scheduleZoomTo(ViewportData viewportData)
Schedule a zoom to the given position on the next redraw. Temporary, may be removed without warning.- Parameters:
viewportData- the viewport to zoom to- Since:
- 10394
-
getMapMover
public final MapMover getMapMover()
Returns the internalMapMover.- Returns:
- the internal
MapMover - Since:
- 13126
-
setMapNavigationComponentVisibility
public void setMapNavigationComponentVisibility(boolean visible)
Set the visibility of the navigation component- Parameters:
visible-trueto make the navigation component visible- Since:
- 18755
-
-