org.geotools.gui.swing
Class MapPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byorg.geotools.gui.swing.ZoomPane
                  extended byorg.geotools.gui.swing.MapPane
All Implemented Interfaces:
DeformableViewer, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
StyledMapPane

public class MapPane
extends ZoomPane

A Swing component for displaying geographic features. Since this class extends ZoomPane, the user can use mouse and keyboard to zoom, translate and rotate around the map (Remind: MapPanel has no scrollbar. To display scrollbars, use ZoomPane.createScrollPane()).

Version:
$Id: MapPane.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.geotools.gui.swing.ZoomPane
DEFAULT_ZOOM, RESET, ROTATE, SCALE_X, SCALE_Y, TRANSLATE_X, TRANSLATE_Y, UNIFORM_SCALE, zoom
 
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
MapPane()
          Construct a default map panel.
MapPane(CoordinateSystem cs)
          Construct a map panel using the specified coordinate system.
 
Method Summary
 java.awt.geom.Rectangle2D getArea()
          Returns a bounding box representative of the geographic area to drawn.
 CoordinateSystem getCoordinateSystem()
          Returns the view coordinate system.
protected  javax.swing.JPopupMenu getDefaultPopupMenu(GeoMouseEvent event)
          Returns a default popup menu for the given mouse event.
protected  java.awt.Dimension getDefaultSize()
          Returns the default size for this component.
protected  javax.swing.JPopupMenu getPopupMenu(java.awt.event.MouseEvent event)
          Returns the popup menu to appears for a given mouse event.
protected  java.awt.geom.Dimension2D getPreferredPixelSize()
          Returns the preferred pixel size in "real world" coordinates.
 Renderer getRenderer()
          Returns the renderer for this map pane.
 java.lang.String getToolTipText(java.awt.event.MouseEvent event)
          Returns the string to be used as the tooltip for a given mouse event.
protected  void paintComponent(java.awt.Graphics2D graphics)
          Paint this MapPane and all visible layers.
protected  void printComponent(java.awt.Graphics2D graphics)
          Print this MapPane and all visible layers.
protected  void processMouseEvent(java.awt.event.MouseEvent event)
          Processes mouse events occurring on this component.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent event)
          Processes mouse motion events occurring on this component.
 void setCoordinateSystem(CoordinateSystem cs)
          Set the view coordinate system.
 void setToolTipText(java.lang.String tooltip)
          Registers the default text to display in a tool tip.
 
Methods inherited from class org.geotools.gui.swing.ZoomPane
addMouseListener, addZoomChangeListener, buildNavigationMenu, correctApparentPixelPosition, createScrollPane, fireZoomChanged, getInsets, getInsets, getMagnifierBorder, getMagnifierGlass, getMagnifierMenu, getMouseSelectionShape, getPreferredArea, getScaleFactor, getVisibleArea, getZoomableBounds, hasPreferredArea, isMagnifierEnabled, isMagnifierVisible, isPaintingWhileAdjusting, mouseSelectionPerformed, paintComponent, paintMagnifier, printComponent, removeZoomChangeListener, repaint, reset, reset, scrollRectToVisible, setMagnifierBorder, setMagnifierEnabled, setMagnifierGlass, setMagnifierVisible, setPaintingWhileAdjusting, setPreferredArea, setResetPolicy, setVisibleArea, tieModels, transform, transformPixels, untieModels, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MapPane

public MapPane()
Construct a default map panel.


MapPane

public MapPane(CoordinateSystem cs)
Construct a map panel using the specified coordinate system.

Parameters:
cs - The rendering coordinate system.
Method Detail

getCoordinateSystem

public CoordinateSystem getCoordinateSystem()
Returns the view coordinate system. This is the "real world" coordinate system used for displaying all features. Note that underlying data doesn't need to be in this coordinate system: transformations will performed on the fly as needed at rendering time.

Returns:
The two dimensional coordinate system used for display. Default to WGS 1984.

setCoordinateSystem

public void setCoordinateSystem(CoordinateSystem cs)
                         throws org.opengis.referencing.operation.TransformException
Set the view coordinate system. This is the "real world" coordinate system to use for displaying all features. Default is WGS 1984. Changing this coordinate system has no effect on any underlying data, since transformation are performed only at rendering time.

Parameters:
cs - The view coordinate system. If this coordinate system has more than 2 dimensions, then only the 2 first will be retained.
Throws:
org.opengis.referencing.operation.TransformException - If cs can't be reduced to a two-dimensional coordinate system., or if data can't be transformed for some other reason.

getArea

public java.awt.geom.Rectangle2D getArea()
Returns a bounding box representative of the geographic area to drawn. The default implementation computes the area from all layers currently registered in the renderer.

Specified by:
getArea in class ZoomPane
Returns:
The enclosing area to be drawn with the default zoom, or null if this area can't be computed.
See Also:
ZoomPane.setPreferredArea(java.awt.geom.Rectangle2D), Renderer.getPreferredArea()

getPreferredPixelSize

protected java.awt.geom.Dimension2D getPreferredPixelSize()
Returns the preferred pixel size in "real world" coordinates. When user ask for a "close zoom", ZoomPane will adjusts the map scale in such a way that structures of preferredPixelSize will appears as one pixel on the screen device.

Overrides:
getPreferredPixelSize in class ZoomPane
See Also:
Renderer.getPreferredPixelSize()

getDefaultSize

protected java.awt.Dimension getDefaultSize()
Returns the default size for this component. This is the size returned by JComponent.getPreferredSize() if no preferred size has been explicitly set.

Overrides:
getDefaultSize in class ZoomPane
Returns:
The default size for this component.

getRenderer

public Renderer getRenderer()
Returns the renderer for this map pane.

See Also:
Renderer.addLayer(org.geotools.renderer.j2d.RenderedLayer), Renderer.removeLayer(org.geotools.renderer.j2d.RenderedLayer), Renderer.removeAllLayers(), Renderer.getLayers(), Renderer.getLayerCount()

paintComponent

protected void paintComponent(java.awt.Graphics2D graphics)
Paint this MapPane and all visible layers.

Specified by:
paintComponent in class ZoomPane
Parameters:
graphics - The graphics context.

printComponent

protected void printComponent(java.awt.Graphics2D graphics)
Print this MapPane and all visible layers.

Overrides:
printComponent in class ZoomPane
Parameters:
graphics - The graphics context.

setToolTipText

public void setToolTipText(java.lang.String tooltip)
Registers the default text to display in a tool tip. The text displays when the cursor lingers over the component and no layer has proposed a tool tip (i.e. Renderer.getToolTipText(org.geotools.renderer.j2d.GeoMouseEvent) returned null for all registered layers).

Parameters:
tooltip - The default tooltip, or null if none.

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Returns the string to be used as the tooltip for a given mouse event. The default implementation delegates to Renderer.getToolTipText(org.geotools.renderer.j2d.GeoMouseEvent).

Parameters:
event - The mouse event.
Returns:
The tool tip text, or null if there is no tool tip for this location.
See Also:
setToolTipText(java.lang.String), Renderer.getToolTipText(org.geotools.renderer.j2d.GeoMouseEvent)

getPopupMenu

protected javax.swing.JPopupMenu getPopupMenu(java.awt.event.MouseEvent event)
Returns the popup menu to appears for a given mouse event. This method invokes ContextualMenuTool#getPopupMenu in decreasing z-order until one is found to returns a non-null menu. If no layer has a popup menu for this event, then this method returns getDefaultPopupMenu(org.geotools.renderer.j2d.GeoMouseEvent).

Overrides:
getPopupMenu in class ZoomPane
Parameters:
event - The mouse event.
Returns:
The popup menu for this event, or null if there is none.
See Also:
getDefaultPopupMenu(org.geotools.renderer.j2d.GeoMouseEvent)

getDefaultPopupMenu

protected javax.swing.JPopupMenu getDefaultPopupMenu(GeoMouseEvent event)
Returns a default popup menu for the given mouse event. This method is invoked when no layers proposed a popup menu for this event. The default implementation returns a menu with navigation options.

See Also:
getPopupMenu(java.awt.event.MouseEvent), ZoomPane.getPopupMenu(java.awt.event.MouseEvent)

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent event)
Processes mouse events occurring on this component. This method overrides the default AWT's implementation in order to wrap the MouseEvent into a GeoMouseEvent. Then, the default AWT's implementation is invoked in order to pass this event to any registered MouseListener objects.


processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent event)
Processes mouse motion events occurring on this component. This method overrides the default AWT's implementation in order to wrap the MouseEvent into a GeoMouseEvent. Then, the default AWT's implementation is invoked in order to pass this event to any registered MouseMotionListener objects.



Copyright © GeoTools. All Rights Reserved.