Package org.geotools.swing
Class AbstractMapPane
Object
Component
Container
JComponent
JPanel
AbstractMapPane
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,EventListener,Accessible,MapBoundsListener,MapLayerListListener,MapPane,RenderingExecutorListener
- Direct Known Subclasses:
JLayeredMapPane,JMapPane
public abstract class AbstractMapPane
extends JPanel
implements MapPane, RenderingExecutorListener, MapLayerListListener, MapBoundsListener
Base class for Swing map panes. It extends Swing's
JPanel class and handles window sizing and repainting as
well as redirecting mouse events. It also provides basic implementations of all interface methods. Sub-classes must
implement drawLayers(boolean) and override JComponent.paintComponent(java.awt.Graphics).- Since:
- 8.0
- Author:
- Michael Bedward
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanprotected final AtomicBooleanprotected AtomicBooleanprotected CursorToolstatic final ColorDefault background color (white).static final intDefault delay (500 milliseconds) before the map will be redrawn when resizing the pane or moving the displayed image.protected final MouseDragBoxprotected final Lockprotected ReferencedEnvelopeprotected Future<?>protected final Pointprotected KeyListenerprotected LabelCacheprotected final Set<MapPaneListener>protected MapContentprotected MapMouseEventDispatcherprotected intprotected final ScheduledExecutorServiceprotected final ReadWriteLockprotected ReferencedEnvelopeprotected RenderingExecutorprotected Future<?>Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapPaneListener(MapPaneListener listener) Adds a listener to receiveMapPaneEvents.voidaddMouseListener(MapMouseListener listener) Registers an object that wishes to receiveMapMouseEvents such as a JMapStatusBar.protected voidCalled after the base image has been dragged.protected voiddoSetDisplayArea(Bounds envelope) Helper method for setDisplayArea(org.geotools.api.geometry.Bounds) which is also called by other methods that want to set the display area without provoking repainting of the displayprotected abstract voiddrawLayers(boolean recreate) Draws layers into one or more images which will then be displayed by the map pane.Gets the current cursor tool.Gets the current display area in world coordinates.Gets the current handler for keyboard actions.Gets theMapConentinstance containing the layers being displayed by this map pane.Gets the current mouse event dispatcher which is responsible for converting each input Java AWT mouse event into a MapMouseEvent and forwarding it to each MapMouseListener.longGets the current paint delay interval in milliseconds.Gets the rendering executor, creating a default one if necessary.Gets the screen to world coordinate transform.Gets the world to screen coordinate transform.booleanQuery whether the map pane is currently accepting or ignoring repaint requests from other GUI components and the system.voidlayerAdded(MapLayerListEvent event) Called when a new map layer has been added.voidlayerChanged(MapLayerListEvent event) Called when a map layer has changed, e.g. features added to a displayed feature collectionvoidlayerMoved(MapLayerListEvent event) Triggered when a group of layers chenges position in the layer listvoidlayerPreDispose(MapLayerListEvent event) Triggered when a layer is about to be disposed.voidlayerRemoved(MapLayerListEvent event) Called when a map layer has been removedvoidmapBoundsChanged(MapBoundsEvent event) Called by the map content's viewport when its bounds have changed.voidmoveImage(int dx, int dy) Moves the image(s) displayed by the map pane from the current origin (x,y) (device pixels) to (x+dx, y+dy).protected voidvoidCalled by the executor when rendering has been completed.voidCalled by the executor when rendering failed for some reason.voidCalled by the executor when rendering has started.protected voidprotected voidPublish a MapPaneEvent to registered listenersvoidremoveMapPaneListener(MapPaneListener listener) Removes the specified listener.voidremoveMouseListener(MapMouseListener listener) Removes the specified listener.voidreset()Reset the map area to include the full extent of all layers and redraw the displayvoidsetCursorTool(CursorTool tool) Sets the current cursor tool.voidsetDisplayArea(Bounds envelope) Sets the area to display in world units.protected voidprotected booleanDetermines the full extent of ofvoidsetIgnoreRepaint(boolean ignoreRepaint) Specify whether the map pane should defer its normal repainting behaviour.voidsetKeyHandler(KeyListener controller) Sets a handler for keyboard actions which control the map pane's display.voidsetMapContent(MapContent content) Sets theMapContentinstance containing the layers to display.voidsetMouseEventDispatcher(MapMouseEventDispatcher dispatcher) Replaces the current mouse event dispatcher.voidsetPaintDelay(int delay) Sets the current paint delay interval in milliseconds.voidsetRenderingExecutor(RenderingExecutor executor) Sets the rendering executor.Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods inherited from class JComponent
addAncestorListener, addNotify, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, updateMethods inherited from class 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 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, 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, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
DEFAULT_PAINT_DELAY
public static final int DEFAULT_PAINT_DELAYDefault delay (500 milliseconds) before the map will be redrawn when resizing the pane or moving the displayed image. This avoids flickering and redundant rendering.- See Also:
-
DEFAULT_BACKGROUND_COLOR
Default background color (white). -
paneTaskExecutor
-
resizedFuture
-
paintDelay
protected int paintDelay -
acceptRepaintRequests
-
baseImageMoved
-
imageMovedFuture
-
imageOrigin
-
drawingLock
-
paramsLock
-
listeners
-
dragBox
-
pendingDisplayArea
-
fullExtent
-
mapContent
-
renderingExecutor
-
keyHandler
-
mouseEventDispatcher
-
labelCache
-
clearLabelCache
-
currentCursorTool
-
-
Constructor Details
-
AbstractMapPane
-
-
Method Details
-
drawLayers
protected abstract void drawLayers(boolean recreate) Draws layers into one or more images which will then be displayed by the map pane. -
getRenderingExecutor
Gets the rendering executor, creating a default one if necessary.- Returns:
- the rendering executor
-
getMouseEventDispatcher
Gets the current mouse event dispatcher which is responsible for converting each input Java AWT mouse event into a MapMouseEvent and forwarding it to each MapMouseListener.- Specified by:
getMouseEventDispatcherin interfaceMapPane- Returns:
- the current mouse event dispatcher (may be
null)
-
setMouseEventDispatcher
Replaces the current mouse event dispatcher. All current listeners will be removed. It is the responsibility of the client to add them to the new dispatcher if this is desired.- Specified by:
setMouseEventDispatcherin interfaceMapPane- Parameters:
dispatcher- the new dispatcher (may benull)
-
setRenderingExecutor
Sets the rendering executor. Ifexecutorisnull, the default DefaultRenderingExecutor will be set on the next call to getRenderingExecutor().- Parameters:
executor- the rendering executor
-
getKeyHandler
Gets the current handler for keyboard actions.- Returns:
- current handler (may be
null)
-
setKeyHandler
Sets a handler for keyboard actions which control the map pane's display. The default handler is MapPaneKeyHandler which provides for scrolling and zooming.- Parameters:
controller- the new handler ornullto disable key handling
-
getPaintDelay
public long getPaintDelay()Gets the current paint delay interval in milliseconds. The map pane uses this delay period to avoid flickering and redundant rendering when drag-resizing the pane or panning the map image.- Returns:
- delay in milliseconds
-
setPaintDelay
public void setPaintDelay(int delay) Sets the current paint delay interval in milliseconds. The map pane uses this delay period to avoid flickering and redundant rendering when drag-resizing the pane or panning the map image.- Parameters:
delay- the delay in milliseconds; if<=0 the default delay period will be set
-
setIgnoreRepaint
public void setIgnoreRepaint(boolean ignoreRepaint) Specify whether the map pane should defer its normal repainting behaviour.Typical use:
myMapPane.setRepaint(false); // do various things that would cause time-consuming // re-paints normally myMapPane.setRepaint(true); myMapPane.repaint();- Overrides:
setIgnoreRepaintin classComponent- Parameters:
ignoreRepaint- if false, paint requests will be handled normally; if true, paint requests will be deferred.- See Also:
-
isAcceptingRepaints
public boolean isAcceptingRepaints()Query whether the map pane is currently accepting or ignoring repaint requests from other GUI components and the system.- Returns:
- true if the pane is currently accepting repaint requests; false if it is ignoring them
- See Also:
-
onShownOrResized
protected void onShownOrResized() -
setForNewSize
protected void setForNewSize() -
moveImage
public void moveImage(int dx, int dy) Moves the image(s) displayed by the map pane from the current origin (x,y) (device pixels) to (x+dx, y+dy). If this method is called when the map pane is not visible, or when the pane's visible rectangle is empty, it is ignored. -
onImageMoved
protected void onImageMoved() -
afterImageMoved
protected void afterImageMoved()Called after the base image has been dragged. Sets the new map area and transforms -
getMapContent
Gets theMapConentinstance containing the layers being displayed by this map pane.- Specified by:
getMapContentin interfaceMapPane- Returns:
- the map content
-
setMapContent
Sets theMapContentinstance containing the layers to display.- Specified by:
setMapContentin interfaceMapPane- Parameters:
content- the map content
-
getDisplayArea
Gets the current display area in world coordinates. This is a short-cut formapPane.getMapContent().getViewport().getBounds(). If a MapContent object has not yet been associated with the map pane, an emptyReferencedEnvelopeis returned.- Specified by:
getDisplayAreain interfaceMapPane- Returns:
- the display area in world coordinates
-
setDisplayArea
Sets the area to display in world units.- Specified by:
setDisplayAreain interfaceMapPane- Parameters:
envelope- the new display area
-
doSetDisplayArea
Helper method for setDisplayArea(org.geotools.api.geometry.Bounds) which is also called by other methods that want to set the display area without provoking repainting of the display- Parameters:
envelope- requested display area
-
reset
public void reset()Reset the map area to include the full extent of all layers and redraw the display -
getScreenToWorldTransform
Gets the screen to world coordinate transform. This is a short-cut formapPane.getMapContent().getViewport().getScreenToWorld().- Specified by:
getScreenToWorldTransformin interfaceMapPane- Returns:
- the screen to world coordinate transform
-
getWorldToScreenTransform
Gets the world to screen coordinate transform. This is a short-cut formapPane.getMapContent().getViewport().getWorldToScreen().The returned
AffineTransformcan be used to determine the current drawing scale...double scale = mapPane.getWorldToScreenTransform().getScaleX();- Specified by:
getWorldToScreenTransformin interfaceMapPane- Returns:
- the world to screen coordinate transform
-
addMapPaneListener
Adds a listener to receiveMapPaneEvents.- Specified by:
addMapPaneListenerin interfaceMapPane- Parameters:
listener- the listener to add
-
removeMapPaneListener
Removes the specified listener.- Specified by:
removeMapPaneListenerin interfaceMapPane- Parameters:
listener- the listener to remove
-
addMouseListener
Registers an object that wishes to receiveMapMouseEvents such as a JMapStatusBar.- Specified by:
addMouseListenerin interfaceMapPane- Parameters:
listener- the listener to add- See Also:
-
removeMouseListener
Removes the specified listener.- Specified by:
removeMouseListenerin interfaceMapPane- Parameters:
listener- the listener to remove
-
getCursorTool
Gets the current cursor tool.- Specified by:
getCursorToolin interfaceMapPane- Returns:
- the current cursor tool (may be
null)
-
setCursorTool
Sets the current cursor tool.- Specified by:
setCursorToolin interfaceMapPane- Parameters:
tool- the tool; ornullfor no cursor tool
-
layerAdded
Called when a new map layer has been added. Sets the layer as selected (for queries) and, if the layer table is being used, adds the new layer to the table.- Specified by:
layerAddedin interfaceMapLayerListListener- Parameters:
event- encapsulating the event information
-
layerRemoved
Called when a map layer has been removed- Specified by:
layerRemovedin interfaceMapLayerListListener- Parameters:
event- encapsulating the event information
-
layerChanged
Called when a map layer has changed, e.g. features added to a displayed feature collection- Specified by:
layerChangedin interfaceMapLayerListListener- Parameters:
event- encapsulating the event information
-
layerMoved
Triggered when a group of layers chenges position in the layer list- Specified by:
layerMovedin interfaceMapLayerListListener- Parameters:
event- encapsulating the event information
-
layerPreDispose
Triggered when a layer is about to be disposed.- Specified by:
layerPreDisposein interfaceMapLayerListListener- Parameters:
event- encapsulating the event information
-
mapBoundsChanged
Called by the map content's viewport when its bounds have changed. Used here to watch for a changed CRS, in which case the map is re-displayed at full extent.- Specified by:
mapBoundsChangedin interfaceMapBoundsListener- Parameters:
event- The change event.
-
publishEvent
Publish a MapPaneEvent to registered listeners- Parameters:
ev- the event to publish- See Also:
-
setFullExtent
protected boolean setFullExtent()Determines the full extent of of- Returns:
trueif full extent was set successfully
-
onRenderingStarted
Called by the executor when rendering has started. Publishes a MapPaneEvent of typeMapPaneEvent.Type.RENDERING_STARTEDto listeners.- Specified by:
onRenderingStartedin interfaceRenderingExecutorListener
-
onRenderingCompleted
Called by the executor when rendering has been completed. Publishes a MapPaneEvent of typeMapPaneEvent.Type.RENDERING_STOPPEDto listeners.- Specified by:
onRenderingCompletedin interfaceRenderingExecutorListener
-
onRenderingFailed
Called by the executor when rendering failed for some reason. Publishes a MapPaneEvent of typeMapPaneEvent.Type.RENDERING_STOPPEDto listeners.- Specified by:
onRenderingFailedin interfaceRenderingExecutorListener
-