public abstract class AbstractMapPane extends JPanel implements MapPane, RenderingExecutorListener, MapLayerListListener, MapBoundsListener
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).JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
AbstractMapPane(MapContent content,
RenderingExecutor executor) |
Modifier and Type | Method and Description |
---|---|
void |
addMapPaneListener(MapPaneListener listener)
Adds a listener to receive
MapPaneEvent s. |
void |
addMouseListener(MapMouseListener listener)
Registers an object that wishes to receive
MapMouseEvent s such as a StatusBar. |
protected void |
afterImageMoved()
Called after the base image has been dragged.
|
protected void |
doSetDisplayArea(Envelope envelope)
Helper method for setDisplayArea(org.opengis.geometry.Envelope) which is also called by other methods that
want to set the display area without provoking repainting of the display
|
protected abstract void |
drawLayers(boolean recreate)
Draws layers into one or more images which will then be displayed by the map pane.
|
CursorTool |
getCursorTool()
Gets the current cursor tool.
|
ReferencedEnvelope |
getDisplayArea()
Gets the current display area in world coordinates.
|
KeyListener |
getKeyHandler()
Gets the current handler for keyboard actions.
|
MapContent |
getMapContent()
Gets the
MapConent instance containing the layers being displayed by this map pane. |
MapMouseEventDispatcher |
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.
|
long |
getPaintDelay()
Gets the current paint delay interval in milliseconds.
|
RenderingExecutor |
getRenderingExecutor()
Gets the rendering executor, creating a default one if necessary.
|
AffineTransform |
getScreenToWorldTransform()
Gets the screen to world coordinate transform.
|
AffineTransform |
getWorldToScreenTransform()
Gets the world to screen coordinate transform.
|
boolean |
isAcceptingRepaints()
Query whether the map pane is currently accepting or ignoring repaint requests from other GUI
components and the system.
|
void |
layerAdded(MapLayerListEvent event)
Called when a new map layer has been added.
|
void |
layerChanged(MapLayerListEvent event)
Called when a map layer has changed, e.g. features added to a displayed feature collection
|
void |
layerMoved(MapLayerListEvent event)
Triggered when a group of layers chenges position in the layer list
|
void |
layerPreDispose(MapLayerListEvent event)
Triggered when a layer is about to be disposed.
|
void |
layerRemoved(MapLayerListEvent event)
Called when a map layer has been removed
|
void |
mapBoundsChanged(MapBoundsEvent event)
Called by the map content's viewport when its bounds have changed.
|
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).
|
protected void |
onImageMoved() |
void |
onRenderingCompleted(RenderingExecutorEvent event)
Called by the executor when rendering has been completed.
|
void |
onRenderingFailed(RenderingExecutorEvent ev)
Called by the executor when rendering failed for some reason.
|
void |
onRenderingStarted(RenderingExecutorEvent ev)
Called by the executor when rendering has started.
|
protected void |
onShownOrResized() |
protected void |
publishEvent(MapPaneEvent ev)
Publish a MapPaneEvent to registered listeners
|
void |
removeMapPaneListener(MapPaneListener listener)
Removes the specified listener.
|
void |
removeMouseListener(MapMouseListener listener)
Removes the specified listener.
|
void |
reset()
Reset the map area to include the full extent of all layers and redraw the display
|
void |
setCursorTool(CursorTool tool)
Sets the current cursor tool.
|
void |
setDisplayArea(Envelope envelope)
Sets the area to display in world units.
|
protected void |
setForNewSize() |
protected boolean |
setFullExtent()
Determines the full extent of of
|
void |
setIgnoreRepaint(boolean ignoreRepaint)
Specify whether the map pane should defer its normal repainting behaviour.
|
void |
setKeyHandler(KeyListener controller)
Sets a handler for keyboard actions which control the map pane's display.
|
void |
setMapContent(MapContent content)
Sets the
MapContent instance containing the layers to display. |
void |
setMouseEventDispatcher(MapMouseEventDispatcher dispatcher)
Replaces the current mouse event dispatcher.
|
void |
setPaintDelay(int delay)
Sets the current paint delay interval in milliseconds.
|
void |
setRenderingExecutor(RenderingExecutor executor)
Sets the rendering executor.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, update
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
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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final int DEFAULT_PAINT_DELAY
public static final Color DEFAULT_BACKGROUND_COLOR
protected final ScheduledExecutorService paneTaskExecutor
protected Future<?> resizedFuture
protected int paintDelay
protected final AtomicBoolean acceptRepaintRequests
protected final AtomicBoolean baseImageMoved
protected Future<?> imageMovedFuture
protected final Point imageOrigin
protected final Lock drawingLock
protected final ReadWriteLock paramsLock
protected final Set<MapPaneListener> listeners
protected final MouseDragBox dragBox
protected ReferencedEnvelope pendingDisplayArea
protected ReferencedEnvelope fullExtent
protected MapContent mapContent
protected RenderingExecutor renderingExecutor
protected KeyListener keyHandler
protected MapMouseEventDispatcher mouseEventDispatcher
protected LabelCache labelCache
protected AtomicBoolean clearLabelCache
protected CursorTool currentCursorTool
public AbstractMapPane(MapContent content, RenderingExecutor executor)
protected abstract void drawLayers(boolean recreate)
recreate
- public RenderingExecutor getRenderingExecutor()
public MapMouseEventDispatcher getMouseEventDispatcher()
getMouseEventDispatcher
in interface MapPane
null
)public void setMouseEventDispatcher(MapMouseEventDispatcher dispatcher)
setMouseEventDispatcher
in interface MapPane
dispatcher
- the new dispatcher (may be null
)public void setRenderingExecutor(RenderingExecutor executor)
executor
is null
, the default DefaultRenderingExecutor will be set on the next call to getRenderingExecutor().newExecutor
- the rendering executorpublic KeyListener getKeyHandler()
null
)public void setKeyHandler(KeyListener controller)
controller
- the new handler or null
to disable key handlingpublic long getPaintDelay()
public void setPaintDelay(int delay)
delay
- the delay in milliseconds; if <=
0 the default delay period will be setpublic void setIgnoreRepaint(boolean ignoreRepaint)
Typical use:
myMapPane.setRepaint(false);
// do various things that would cause time-consuming
// re-paints normally
myMapPane.setRepaint(true);
myMapPane.repaint();
setIgnoreRepaint
in class Component
repaint
- if true, paint requests will be handled normally; if false, paint requests
will be deferred.isAcceptingRepaints()
public boolean isAcceptingRepaints()
#setRepaint(boolean)
protected void onShownOrResized()
protected void setForNewSize()
public void moveImage(int dx, int dy)
protected void onImageMoved()
protected void afterImageMoved()
public MapContent getMapContent()
MapConent
instance containing the layers being displayed by this map pane.getMapContent
in interface MapPane
public void setMapContent(MapContent content)
MapContent
instance containing the layers to display.setMapContent
in interface MapPane
content
- the map contentpublic ReferencedEnvelope getDisplayArea()
mapPane.getMapContent().getViewport().getBounds()
. If a MapContent object has not yet been
associated with the map pane, an empty ReferencedEnvelope
is returned.getDisplayArea
in interface MapPane
public void setDisplayArea(Envelope envelope)
setDisplayArea
in interface MapPane
protected void doSetDisplayArea(Envelope envelope)
envelope
- requested display areapublic void reset()
public AffineTransform getScreenToWorldTransform()
mapPane.getMapContent().getViewport().getScreenToWorld()
.getScreenToWorldTransform
in interface MapPane
public AffineTransform getWorldToScreenTransform()
mapPane.getMapContent().getViewport().getWorldToScreen()
.
The returned AffineTransform
can be used to determine the current drawing scale...
double scale = mapPane.getWorldToScreenTransform().getScaleX();
getWorldToScreenTransform
in interface MapPane
public void addMapPaneListener(MapPaneListener listener)
MapPaneEvent
s.addMapPaneListener
in interface MapPane
listener
- the listener to addpublic void removeMapPaneListener(MapPaneListener listener)
removeMapPaneListener
in interface MapPane
listener
- the listener to removepublic void addMouseListener(MapMouseListener listener)
MapMouseEvent
s such as a StatusBar.addMouseListener
in interface MapPane
listener
- the listener to addMapMouseListener
public void removeMouseListener(MapMouseListener listener)
removeMouseListener
in interface MapPane
listener
- the listener to removepublic CursorTool getCursorTool()
getCursorTool
in interface MapPane
null
)public void setCursorTool(CursorTool tool)
setCursorTool
in interface MapPane
tool
- the tool; or null
for no cursor toolpublic void layerAdded(MapLayerListEvent event)
layerAdded
in interface MapLayerListListener
event
- encapsulating the event informationpublic void layerRemoved(MapLayerListEvent event)
layerRemoved
in interface MapLayerListListener
event
- encapsulating the event informationpublic void layerChanged(MapLayerListEvent event)
layerChanged
in interface MapLayerListListener
event
- encapsulating the event informationpublic void layerMoved(MapLayerListEvent event)
layerMoved
in interface MapLayerListListener
event
- encapsulating the event informationpublic void layerPreDispose(MapLayerListEvent event)
layerPreDispose
in interface MapLayerListListener
event
- encapsulating the event informationpublic void mapBoundsChanged(MapBoundsEvent event)
mapBoundsChanged
in interface MapBoundsListener
event
- The change event.protected void publishEvent(MapPaneEvent ev)
ev
- the event to publishMapPaneListener
protected boolean setFullExtent()
true
if full extent was set successfullypublic void onRenderingStarted(RenderingExecutorEvent ev)
MapPaneEvent.Type.RENDERING_STARTED
to listeners.onRenderingStarted
in interface RenderingExecutorListener
public void onRenderingCompleted(RenderingExecutorEvent event)
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.onRenderingCompleted
in interface RenderingExecutorListener
public void onRenderingFailed(RenderingExecutorEvent ev)
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.onRenderingFailed
in interface RenderingExecutorListener
Copyright © 1996–2019 Geotools. All rights reserved.