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:
ImageObserver,MenuContainer,PropertyChangeListener,Serializable,EventListener,Helpful,LayerManager.LayerChangeListener,MainLayerManager.ActiveLayerChangeListener,PreferenceChangedListener
public class MapView
extends NavigatableComponent
implements PropertyChangeListener, PreferenceChangedListener, LayerManager.LayerChangeListener, MainLayerManager.ActiveLayerChangeListener
This is a component used in the
MapFrame for browsing the map. It use is to
provide the MapMode's enough capabilities to operate.MapView holds 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..MapView is able to administrate several layers.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classAn invalidation listener that simply calls repaint() for now.static interfaceThis is a listener that gets informed whenever repaint is called for this MapView.private static classA layer painter that issues a warning when being called.Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.NavigatableComponent
NavigatableComponent.ZoomChangeListenerNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MapView.LayerInvalidatedListenerThe listener that listens to invalidations of all layers.private RectangleThe last event performed by mouse.private EastNorthprivate Projectionprivate doubleprivate intprivate final MainLayerManagerA list of all layers currently loaded.private MapMoverprivate final List<? extends JComponent>private BufferedImageprivate BufferedImageprivate Pointprivate Dimensionprivate final AtomicBooleanprivate static final intIcon overhang covered by the pan-strip band in logical pixelsprivate booleanThe play head marker: there is only one of these so it isn't in any specific layerprivate final HashMap<Layer,MapViewPaintable.LayerPainter> This is a map of all Layers that have been added to this view.private final CopyOnWriteArrayList<MapView.RepaintListener>private final DataSelectionListenerprivate final Set<MapViewPaintable>Temporary layers (selection rectangle, etc.) that are never cached and drawn on top of regular layers.private booleanprivate final StrokeFields 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_LOADFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionMapView(MainLayerManager layerManager, ViewportData viewportData) Constructs a newMapView. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled whenever the active or edit layer changed.voidAdds a listener that gets informed whenever repaint() is called for this class.booleanAdds a new temporary layer.voiddestroy()Destroy this map view panel.private voidprivate voiddrawTemporaryLayers(Graphics2D tempG, Bounds box) private voiddrawWorldBorders(Graphics2D tempG) private static BufferedImagegetAcceleratedImage(Component mv, int width, int height) Get a string representation of all layers suitable for thesourcechangeset tag.final MainLayerManagerReturns the layer manager.final MapMoverReturns the internalMapMover.static List<? extends JComponent>getMapNavigationComponents(MapView forMapView) Adds the map navigation components to aGets a list of temporary layers.booleanReplies true if the active data layer (edit layer) is drawable.booleanReplies true if the active data layer is visible.booleanDetermines if a pan is in progress.booleanChecks if virtual nodes should be drawn.voidNotifies this listener that a layer has been added.voidNotifies this listener that the order of layers was changed.voidNotifies this listener that a layer was just removed.voidMoves the layer to the given new position.voidDraw the component.voidpaintLayer(Layer layer, Graphics2D g) Paints the given layer to the graphics object, using the current state of this map view.private voidpaintPanStrip(Graphics2D g, int x, int y, int w, int h, List<Layer> layers, AffineTransform trDef) voidTriggered when a preference entry value changes.booleanSets up the viewport to prepare for drawing the view.voidvoidCall this method to keep map position on screen during next repaintvoidRemoves a registered repaint listener.booleanRemoves 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, zoomToFactorMethods 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, updateUIMethods 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, validateTreeMethods 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 Details
-
layerManager
A list of all layers currently loaded. If we support multiple map views, this list may be different for each of them. -
playHeadMarker
The play head marker: there is only one of these so it isn't in any specific layer -
lastMEvent
The last event performed by mouse. -
temporaryLayers
Temporary layers (selection rectangle, etc.) that are never cached and drawn on top of regular layers. Access must be synchronized. -
nonChangedLayersBuffer
-
offscreenBuffer
-
lastViewID
-
lastPaintedScale
-
lastPaintedCenter
-
lastPaintedProjection
-
lastPaintedLayers
-
panLabelsHidden
-
paintPreferencesChanged
-
lastClipBounds
-
mapMover
-
worldBorderStroke
-
invalidatedListener
The listener that listens to invalidations of all layers. -
registeredLayers
This is a map of all Layers that have been added to this view. -
oldSize
-
oldLoc
-
virtualNodesEnabled
-
PAN_STRIP_MARGIN
Icon overhang covered by the pan-strip band in logical pixels- See Also:
-
repaintSelectionChangedListener
-
repaintListeners
-
-
Constructor Details
-
MapView
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 Details
-
getAcceleratedImage
-
rememberLastPositionOnScreen
Call this method to keep map position on screen during next repaint -
layerAdded
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
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
Replies true if the active data layer is visible.- Returns:
- true if the active data layer is visible, false otherwise
-
layerRemoving
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
Enables or disables drawing of the virtual nodes.- Parameters:
enabled- if virtual nodes are enabled
-
isVirtualNodesEnabled
Checks if virtual nodes should be drawn. Default isfalse- Returns:
- The virtual nodes property.
- See Also:
-
moveLayer
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
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
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:
IllegalArgumentException- If the layer is not part of this map view.- Since:
- 11226
-
isPanning
Determines if a pan is in progress.- Returns:
trueif a pan is in progress- Since:
- 19701
-
paint
Draw the component.- Overrides:
paintin classJComponent
-
drawMapContent
-
paintPanStrip
private void paintPanStrip(Graphics2D g, int x, int y, int w, int h, List<Layer> layers, AffineTransform trDef) -
drawTemporaryLayers
-
drawWorldBorders
-
prepareToDraw
Sets up the viewport to prepare for drawing the view.- Returns:
trueif the view can be drawn,falseotherwise.
-
activeOrEditLayerChanged
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
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
Removes a layer previously added as temporary layer.- Parameters:
mvp- The layer to remove.- Returns:
trueif that layer was removed.
-
getTemporaryLayers
Gets a list of temporary layers.- Returns:
- The layers in the order they are added.
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
preferenceChanged
Description copied from interface:PreferenceChangedListenerTriggered when a preference entry value changes.- Specified by:
preferenceChangedin interfacePreferenceChangedListener- Parameters:
e- the preference change event
-
destroy
Destroy this map view panel. Should be called once when it is not needed any more. -
getLayerInformationForSourceTag
Get a string representation of all layers suitable for thesourcechangeset tag.- Returns:
- A String of sources separated by ';'
-
addRepaintListener
Adds a listener that gets informed whenever repaint() is called for this class.- Parameters:
l- The listener.
-
removeRepaintListener
Removes a registered repaint listener.- Parameters:
l- The listener.
-
repaint
- Overrides:
repaintin classJComponent
-
repaint
-
getLayerManager
Returns the layer manager.- Returns:
- the layer manager
- Since:
- 10282
-
scheduleZoomTo
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
Returns the internalMapMover.- Returns:
- the internal
MapMover - Since:
- 13126