|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.geotools.swing.JMapPane
public class JMapPane
A map display pane that works with a GTRenderer and MapContext to display features. It supports the use of tool classes to implement, for example, mouse-controlled zooming and panning.
Rendering is performed on a background thread and is managed by the RenderingExecutor class.
Adapted from original code by Ian Turton.
JMapFrame
,
MapPaneListener
,
CursorTool
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
javax.swing.JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
static int |
DEFAULT_RESIZING_PAINT_DELAY
Default delay (milliseconds) before the map will be redrawn when resizing the pane. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
JMapPane()
Constructor - creates an instance of JMapPane with no map context or renderer initially |
|
JMapPane(GTRenderer renderer,
MapContext context)
Constructor - creates an instance of JMapPane with the given renderer and map context. |
Method Summary | |
---|---|
void |
addMapPaneListener(MapPaneListener listener)
Register an object that wishes to receive MapPaneEvent s |
void |
addMouseListener(MapMouseListener listener)
Register an object that wishes to receive MapMouseEvent s
such as a StatusBar |
protected void |
afterImageMove(ReferencedEnvelope env,
java.awt.Rectangle paintArea)
Called after the base image has been dragged. |
java.awt.image.RenderedImage |
getBaseImage()
Retrieve the map pane's current base image. |
ReferencedEnvelope |
getDisplayArea()
Return a (copy of) the currently displayed map area. |
MapContext |
getMapContext()
Get the map context associated with this map pane |
GTRenderer |
getRenderer()
Get the renderer being used by this map pane |
int |
getResizeDelay()
Get the length of the delay period between the pane being resized and the next repaint. |
java.awt.geom.AffineTransform |
getScreenToWorldTransform()
Get a (copy of) the screen to world coordinate transform being used by this map pane. |
java.awt.geom.AffineTransform |
getWorldToScreenTransform()
Get a (copy of) the world to screen coordinate transform being used by this map pane. |
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. |
void |
layerMoved(MapLayerListEvent event)
Called when the bounds of a map layer have changed |
void |
layerRemoved(MapLayerListEvent event)
Called when a map layer has been removed |
void |
mapBoundsChanged(MapBoundsEvent event)
Called by the map context when its bounds have changed. |
void |
moveImage(int dx,
int dy)
Move the image currently displayed by the map pane from its current origin (x,y) to (x+dx, y+dy). |
void |
onRenderingCancelled()
Called by the JMapPane.RenderingTask when rendering was cancelled. |
void |
onRenderingCompleted()
Called by the JMapPane.RenderingTask when rendering has been completed Publishes a MapPaneEvent of type MapPaneEvent.Type.RENDERING_STOPPED to listeners. |
void |
onRenderingFailed()
Called by the JMapPane.RenderingTask when rendering failed. |
void |
onRenderingRejected()
Called when a rendering request has been rejected. |
protected void |
paintComponent(java.awt.Graphics g)
Called by the system to draw the layers currently visible layers. |
void |
removeMouseListener(MapMouseListener listener)
Unregister the MapMouseListener object. |
void |
reset()
Reset the map area to include the full extent of all layers and redraw the display |
void |
setCursorTool(CursorTool tool)
Set the current cursor tool |
void |
setDisplayArea(org.opengis.geometry.Envelope envelope)
Sets the area to display by calling the MapContext.setAreaOfInterest(com.vividsolutions.jts.geom.Envelope) method of this pane's map context. |
void |
setMapContext(MapContext context)
Set the map context for this map pane to display |
void |
setMapLayerTable(MapLayerTable layerTable)
Register a MapLayerTable object to be receive layer change events from this map pane and to control layer ordering, visibility and selection. |
void |
setRenderer(GTRenderer renderer)
Set the renderer for this map pane. |
void |
setRepaint(boolean repaint)
Specify whether the map pane should defer its normal repainting behaviour. |
void |
setResizeDelay(int delay)
Set the length of the delay period between the pane being resized and the next repaint. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class javax.swing.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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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 |
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, 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, hide, 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, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_RESIZING_PAINT_DELAY
Constructor Detail |
---|
public JMapPane()
public JMapPane(GTRenderer renderer, MapContext context)
renderer
- a renderer objectcontext
- an instance of MapContextMethod Detail |
---|
public void setCursorTool(CursorTool tool)
tool
- the tool to set; null means no active cursor toolpublic void addMouseListener(MapMouseListener listener)
MapMouseEvent
s
such as a StatusBar
listener
- an object that implements MapMouseListener
java.lang.IllegalArgumentException
- if listener is nullMapMouseListener
public void removeMouseListener(MapMouseListener listener)
MapMouseListener
object.
listener
- the listener to remove
java.lang.IllegalArgumentException
- if listener is nullpublic void addMapPaneListener(MapPaneListener listener)
MapPaneEvent
s
listener
- an object that implements MapPaneListener
MapPaneListener
public void setMapLayerTable(MapLayerTable layerTable)
layerTable
- an instance of MapLayerTable
java.lang.IllegalArgumentException
- if layerTable is nullpublic GTRenderer getRenderer()
public void setRenderer(GTRenderer renderer)
renderer
- the renderer to usepublic MapContext getMapContext()
public void setMapContext(MapContext context)
context
- the map contextpublic ReferencedEnvelope getDisplayArea()
Note, this will not always be the same as the envelope returned by
MapContext.getAreaOfInterest()
. For example, when the
map is displayed at the full extent of all layers
MapContext.getAreaOfInterest()
will return the union of the
layer bounds while this method will return an evnelope that can
included extra space beyond the bounds of the layers.
ReferencedEnvelope
public void setDisplayArea(org.opengis.geometry.Envelope envelope)
The map area that ends up being displayed will often be larger than the requested display area. For instance, if the square area is requested, but the map pane's screen area is a rectangle with width greater than height, then the displayed area will be centred on the requested square but include additional area on each side.
You can pass any GeoAPI Envelope implementation to this method such as ReferenedEnvelope or Envelope2D.
Note: This method does not check that the requested area overlaps the bounds of the current map layers.
envelope
- the bounds of the map to display
java.lang.IllegalStateException
- if a map context is not setpublic void reset()
public void setRepaint(boolean repaint)
Typical use:
myMapPane.setRepaint(false);
// do various things that would cause time-consuming
// re-paints normally
myMapPane.setRepaint(true);
myMapPane.repaint();
repaint
- if true, paint requests will be handled normally;
if false, paint requests will be deferred.isAcceptingRepaints()
public boolean isAcceptingRepaints()
setRepaint(boolean)
public java.awt.image.RenderedImage getBaseImage()
The map pane caches the most recent rendering of map layers as an image to avoid time-consuming rendering requests whenever possible. The base image will be re-drawn whenever there is a change to map layer data, style or visibility; and it will be replaced by a new image when the pane is resized.
This method returns a live reference to the current base image. Use with caution.
public int getResizeDelay()
The map pane imposes a delay between resize events and repainting to avoid flickering of the display during drag-resizing.
public void setResizeDelay(int delay)
The map pane imposes a delay between resize events and repainting to avoid flickering of the display during drag-resizing.
delay
- the delay in milliseconds; if <
0 the default delay
period will be setpublic java.awt.geom.AffineTransform getScreenToWorldTransform()
public java.awt.geom.AffineTransform getWorldToScreenTransform()
double scale = mapPane.getWorldToScreenTransform().getScaleX();
public void moveImage(int dx, int dy)
PanTool
.
dx
- the x offset in pixelsdy
- the y offset in pixels.protected void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public void onRenderingCompleted()
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.
MapPaneListener.onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
public void onRenderingCancelled()
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.
MapPaneListener.onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
public void onRenderingFailed()
MapPaneEvent.Type.RENDERING_STOPPED
to listeners.
MapPaneListener.onRenderingStopped(org.geotools.swing.event.MapPaneEvent)
public void onRenderingRejected()
protected void afterImageMove(ReferencedEnvelope env, java.awt.Rectangle paintArea)
env
- the display area (world coordinates) prior to the image being movedpaintArea
- the current drawing area (screen units)public 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 mapBoundsChanged(MapBoundsEvent event)
mapBoundsChanged
in interface MapBoundsListener
event
- The change event.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |