org.geotools.gui.swing
Class MapPaneImpl

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.geotools.gui.swing.MapPaneImpl
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ComponentListener, java.util.EventListener, java.awt.image.ImageObserver, MapBoundsListener, MapLayerListListener, java.awt.MenuContainer, SelectedToolListener, java.io.Serializable

public class MapPaneImpl
extends javax.swing.JPanel
implements MapBoundsListener, MapLayerListListener, java.awt.event.ComponentListener, SelectedToolListener

This widget is responsible for marshalling the rendering of a map. It processes Listener events and calls the Renderer as required. It maintains the correct aspect ratio by resizing the Context's BoundingBox when this component changes size.

Version:
$Id: MapPaneImpl.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Cameron Shorter
See Also:
Serialized Form
Task:
REVISIT: We need to add a PixcelAspectRatio varible which defaults to 1, ie width/heigh=1. Currently, this is assumed to be 1.

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
protected  java.awt.geom.AffineTransform dotToCoordinateTransform
          A transform from screen coordinates to real world coordinates.
 
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
MapPaneImpl(MapContext context)
          Create a MapPane.
MapPaneImpl(MapContext context, ToolList toolList)
          Create a MapPane.
MapPaneImpl(MapContext context, ToolList toolList, boolean concatTransform)
           
 
Method Summary
 void componentHidden(java.awt.event.ComponentEvent e)
          Invoked when the component has been made invisible.
 void componentMoved(java.awt.event.ComponentEvent e)
          Invoked when the component's position changes.
 void componentResized(java.awt.event.ComponentEvent e)
          Invoked when the component's size changes, change the AreaOfInterest so that the aspect ratio remains the same.
 void componentShown(java.awt.event.ComponentEvent e)
          Invoked when the component has been made visible.
 ToolList getToolList()
          Get the ToolList for this class.
 void layerAdded(MapLayerListEvent event)
          Triggered when a new layer is added to the MapContext
 void layerChanged(MapLayerListEvent event)
          Triggered when something in a layer changed (data, style, title)
 void layerMoved(MapLayerListEvent event)
          Triggered when a group of layers chenges position in the layer list
 void layerRemoved(MapLayerListEvent event)
          Triggered when a layer is removed from the MapContext
 void mapBoundsChanged(MapBoundsEvent event)
          Invoked when the area of interest or the coordinate system changes
 void paintComponent(java.awt.Graphics graphics)
          Loop through all the layers in this mapPane's layerList and render each Layer which is set to Visable.
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 selectedToolChanged(java.util.EventObject event)
          Called when the selectedTool on a MapPane changes.
 void setToolList(ToolList toolList)
          Set the ToolList for this class.
 java.awt.geom.Point2D toScreenPoint(java.awt.geom.Point2D worldPoint)
          Added by Jamison Conley Aug 12, 2004 Takes a point in real world coordinates and returns the same point in screen coordinates.
 java.awt.Shape toScreenShape(java.awt.Shape worldShape)
          Added by Jamison Conley Aug 13, 2004 Takes a point in real world coordinates and returns the same point in screen coordinates.
 java.awt.geom.Point2D toWorldPoint(java.awt.geom.Point2D screenPoint)
          Added by Jamison Conley Aug 12, 2004 Takes a point in screen coordinates and returns the same point in real world coordinates.
 java.awt.Shape toWorldShape(java.awt.Shape screenShape)
          Added by Jamison Conley Aug 13, 2004 Takes a shape in screen coordinates and returns the smape in real world coordinates
 void updateAspectRatio()
           
 void updateTransform()
          Re-evaluate the screen to CoordinateSystem transform, this method should be called whenever the MapPane resizes, boundingBox resizes, or coordinateSystem changes.
 void useMemoryCache(boolean flag)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, 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, addMouseListener, 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
 

Field Detail

dotToCoordinateTransform

protected java.awt.geom.AffineTransform dotToCoordinateTransform
A transform from screen coordinates to real world coordinates.

Constructor Detail

MapPaneImpl

public MapPaneImpl(MapContext context,
                   ToolList toolList)
            throws java.lang.IllegalArgumentException,
                   java.io.IOException
Create a MapPane. A MapPane marshals the drawing of maps.

Parameters:
context - The context where layerList and boundingBox are kept. If context is null, an IllegalArguementException is thrown.
toolList - The list of tools which can be used by this class.
Throws:
java.lang.IllegalArgumentException - when parameters are null.
java.io.IOException

MapPaneImpl

public MapPaneImpl(MapContext context,
                   ToolList toolList,
                   boolean concatTransform)
            throws java.lang.IllegalArgumentException,
                   java.io.IOException

MapPaneImpl

public MapPaneImpl(MapContext context)
            throws java.lang.IllegalArgumentException,
                   java.io.IOException
Create a MapPane. A MapPane marshals the drawing of maps.

Parameters:
context - The context where layerList and boundingBox are kept. If context is null, an IllegalArguementException is thrown.
Throws:
java.lang.IllegalArgumentException - when parameters are null.
java.io.IOException
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics graphics)
Loop through all the layers in this mapPane's layerList and render each Layer which is set to Visable. If the AreaOfInterest is null, then the AreaOfInterest will be set to the AreaOfInterest of the the LayerList. Rendering will not occur now, but will wait until after the AreaOfInterestChangedEvent has been received.

Parameters:
graphics - The graphics object to paint to.
Task:
TODO fill in exception. This should implement logging., REVISIT We should set the AreaOfInterest somewhere other than here., TODO create a layerList.getCoordinateSystem method

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.

Parameters:
event - The click point.

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.

Parameters:
event - The mouse point.

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Invoked when the component has been made invisible.

Specified by:
componentHidden in interface java.awt.event.ComponentListener
Parameters:
e - ComponentEvent.

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Invoked when the component's position changes.

Specified by:
componentMoved in interface java.awt.event.ComponentListener
Parameters:
e - ComponentEvent.

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
Invoked when the component's size changes, change the AreaOfInterest so that the aspect ratio remains the same. One axis will remain the same width/height while the other axis will expand to fit the new aspect ratio.
The method will trigger an AreaOfInterestEvent which in turn will cause a repaint.

Specified by:
componentResized in interface java.awt.event.ComponentListener
Parameters:
e - ComponentEvent.
Throws:
java.lang.reflect.UndeclaredThrowableException - DOCUMENT ME!

updateAspectRatio

public void updateAspectRatio()

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Invoked when the component has been made visible.

Specified by:
componentShown in interface java.awt.event.ComponentListener
Parameters:
e - ComponentEvent.

selectedToolChanged

public void selectedToolChanged(java.util.EventObject event)
Called when the selectedTool on a MapPane changes. Register for mouseEvents on behalf of the tool, and set the Cursor.

Specified by:
selectedToolChanged in interface SelectedToolListener
Parameters:
event - ComponenetEvent.

updateTransform

public void updateTransform()
Re-evaluate the screen to CoordinateSystem transform, this method should be called whenever the MapPane resizes, boundingBox resizes, or coordinateSystem changes.


toWorldPoint

public java.awt.geom.Point2D toWorldPoint(java.awt.geom.Point2D screenPoint)
Added by Jamison Conley Aug 12, 2004 Takes a point in screen coordinates and returns the same point in real world coordinates.

Parameters:
screenPoint - the point in screen coordinates
Returns:
the point in real world coordinates

toScreenPoint

public java.awt.geom.Point2D toScreenPoint(java.awt.geom.Point2D worldPoint)
Added by Jamison Conley Aug 12, 2004 Takes a point in real world coordinates and returns the same point in screen coordinates.

Parameters:
worldPoint - the point in real world coordinates
Returns:
the point in screen coordinates

toWorldShape

public java.awt.Shape toWorldShape(java.awt.Shape screenShape)
Added by Jamison Conley Aug 13, 2004 Takes a shape in screen coordinates and returns the smape in real world coordinates

Parameters:
screenShape - the shape in screen coordinates
Returns:
the shape in real world coordinates

toScreenShape

public java.awt.Shape toScreenShape(java.awt.Shape worldShape)
Added by Jamison Conley Aug 13, 2004 Takes a point in real world coordinates and returns the same point in screen coordinates.

Returns:
the shape in screen coordinates

setToolList

public void setToolList(ToolList toolList)
Set the ToolList for this class.

Parameters:
toolList - The list of tools than can be used by this class.

getToolList

public ToolList getToolList()
Get the ToolList for this class.

Returns:
the toolList for this class.

mapBoundsChanged

public void mapBoundsChanged(MapBoundsEvent event)
Description copied from interface: MapBoundsListener
Invoked when the area of interest or the coordinate system changes

Specified by:
mapBoundsChanged in interface MapBoundsListener
Parameters:
event - The change event.

layerAdded

public void layerAdded(MapLayerListEvent event)
Description copied from interface: MapLayerListListener
Triggered when a new layer is added to the MapContext

Specified by:
layerAdded in interface MapLayerListListener
Parameters:
event - encapsulating the event information

layerRemoved

public void layerRemoved(MapLayerListEvent event)
Description copied from interface: MapLayerListListener
Triggered when a layer is removed from the MapContext

Specified by:
layerRemoved in interface MapLayerListListener
Parameters:
event - encapsulating the event information

layerChanged

public void layerChanged(MapLayerListEvent event)
Description copied from interface: MapLayerListListener
Triggered when something in a layer changed (data, style, title)

Specified by:
layerChanged in interface MapLayerListListener
Parameters:
event - encapsulating the event information

layerMoved

public void layerMoved(MapLayerListEvent event)
Description copied from interface: MapLayerListListener
Triggered when a group of layers chenges position in the layer list

Specified by:
layerMoved in interface MapLayerListListener
Parameters:
event - encapsulating the event information

useMemoryCache

public void useMemoryCache(boolean flag)


Copyright © GeoTools. All Rights Reserved.