Class MapPanel
- All Implemented Interfaces:
LayerListListener
,ActionListener
,MouseListener
,MouseMotionListener
,WindowListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
LayerList
object that contains information about the layers that
should be drawn in the component.
This component maintains the extent and scale of the data to be
drawn, and handles mouse motion for zooming and panning. The
MapPanel
is a 'viewer' in the MVC model, and an
associated LayerList
is the Model. Some other object
(such as a MapViewer
) would be the controller.
The LayerList
does most of the heavy work involved
in rendering by maintaining a backing store,
coordinating state, etc.
When drawing is performed is is done in the LayerList
by a background thread (this allows the GUI to remain responsive).
The MapPanel
will refresh itself on 1000 msec
intervals based on a Timer
. The Timer
invokes a method to determine if a refresh is appropriate, and
conserves resources if there is nothing to redraw.
When screen damage must be repaired it is done so from a backing store.
This component is simple and unornamented. Most applications will
embed the MapPanel
within a MapViewer
,
which provides the ornamentation that you would expect from a map
viewer (toolbar, scale box, eastings and northings, legend).
This Object accept drop actions, and will open files or run scripts accordingly.
This component is based on Swing and must follow the Swing threading rules.
- See Also:
LayerList
,MapViewer
, Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
static int
static int
static int
static int
static int
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Handle events from the timer or scale changes.void
Add files to the MapPanel.Get a previously defined action.Get the ButtonGroup that is used for pointer modes such as zoomInMode, zoomOutMode, panMode etc., in case you need to add other actions to this buttongroup.Get an Extent2D object that represents the current extent of the view in geographic coordinates.Return the reference to the LayerList used in this panel to interested parties.double
getScale()
Compute the mapscale that is being used on the page (screen).Get the AffineTransform that represents the mapping of geographic coordinates into page (screen) coordinates.void
layerAdded(int index)
Receive notification that a layer was added.void
layersChanged(int index)
Receive notification that some layers have changed.loadToolBar(JToolBar toolbar)
This routine will populate a toolbar with commonly used toolsstatic JButton
makeButton(Action a)
Make a JButton from an Action, setting the command and insets to conform to the Patchworks look and feel.void
Update the map, so long as the mouse is not involved in a drag operation.void
void
Catch mouse dragged events.void
void
void
mouseMoved(MouseEvent e)
Track the X,Y location of the mousevoid
Arm the system for a mouse drag operation.void
Clean up after drag mode has ended.void
paintComponent(Graphics gc)
Custom component painting routine This still needs to be fixed to not draw on bordersPop a map extent off of the history stackvoid
print(Graphics2D g, Dimension d, double printScale, int dpi, LayerPrintCallback callback)
Print the map to a graphics context.void
pushHistory(Extent2D e)
Push a map extent on to the history stackvoid
reset()
Set the extent back to the maximum.void
This method initializes a set of Action objects that describe functions that can be performed by this MapPanel.void
setAdjust(boolean scaleChanged)
Request that the drawing methods prepare to repaint the screen as soon as possible.void
setBounds(int x, int y, int width, int height)
Change the bounds of the componentvoid
setEastingLabel(JLabel label)
Define a status label for the map eastings under the cursorvoid
setMaxExtent(Extent2D extent)
Set the default maximum extent of the imagevoid
setMouseMode(int mode)
Set the mouse motion mode to PAN, ZOOMIN, ZOOMOUT or SELECTvoid
setMouseMode(ClickHandler clickHandler)
Set the mouse motion mode to a ClickHandlervoid
setMouseMode(LinetoHandler linetoHandler)
Set the mouse motion mode to a LineHandlervoid
setMouseMode(RecordHandler recordHandler)
Set the mouse motion mode to a ClickHandlervoid
setNorthingLabel(JLabel label)
Define a status label for the map northings under the cursorvoid
setScale(double value)
Set the mapscale to be used on the page (screen).void
setScaleField(WholeNumberField field)
void
translate(double x, double y)
Translate the extent by a specified x and y distance.void
void
void
void
void
void
void
void
zoom(double factor)
Zoom by an arbitrary factor.void
zoomAt(double x, double y, double factor)
Zoom to a new center location.void
zoomIn()
Zoom in by a default 50%void
zoomOut()
Zoom out by a default 100%void
zoomOutRelative(double xmin, double ymin, double xmax, double ymax)
Zoom out by a relative amount.void
zoomTo(double xmin, double ymin, double xmax, double ymax)
Zoom to a new extent.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
ZOOMIN
public static final int ZOOMIN- See Also:
- Constant Field Values
-
ZOOMOUT
public static final int ZOOMOUT- See Also:
- Constant Field Values
-
PAN
public static final int PAN- See Also:
- Constant Field Values
-
SELECT
public static final int SELECT- See Also:
- Constant Field Values
-
IDENTIFY
public static final int IDENTIFY- See Also:
- Constant Field Values
-
REFRESH_INTERVAL
public static int REFRESH_INTERVAL
-
-
Constructor Details
-
MapPanel
MapPanel constructor.- Parameters:
layers
- A LayerList object that contains the layer model.
-
MapPanel
public MapPanel()No-args constructor only for use by the Serialization routines.
-
-
Method Details
-
getLayerList
Return the reference to the LayerList used in this panel to interested parties. -
layersChanged
public void layersChanged(int index)Receive notification that some layers have changed. The mapextents and limits will have to be recalculated.- Specified by:
layersChanged
in interfaceLayerListListener
-
layerAdded
public void layerAdded(int index)Receive notification that a layer was added. If this is the initial layer then change the extent to match this new layer.- Specified by:
layerAdded
in interfaceLayerListListener
-
setEastingLabel
Define a status label for the map eastings under the cursor -
setNorthingLabel
Define a status label for the map northings under the cursor -
setScaleField
-
getTransform
Get the AffineTransform that represents the mapping of geographic coordinates into page (screen) coordinates.- Specified by:
getTransform
in interfaceLayerListListener
-
getExtent2D
Get an Extent2D object that represents the current extent of the view in geographic coordinates.- Specified by:
getExtent2D
in interfaceLayerListListener
-
setBounds
public void setBounds(int x, int y, int width, int height)Change the bounds of the component -
windowClosing
- Specified by:
windowClosing
in interfaceWindowListener
-
windowOpened
- Specified by:
windowOpened
in interfaceWindowListener
-
windowClosed
- Specified by:
windowClosed
in interfaceWindowListener
-
windowIconified
- Specified by:
windowIconified
in interfaceWindowListener
-
windowDeiconified
- Specified by:
windowDeiconified
in interfaceWindowListener
-
windowActivated
- Specified by:
windowActivated
in interfaceWindowListener
-
windowDeactivated
- Specified by:
windowDeactivated
in interfaceWindowListener
-
setMouseMode
public void setMouseMode(int mode)Set the mouse motion mode to PAN, ZOOMIN, ZOOMOUT or SELECT -
setMouseMode
Set the mouse motion mode to a ClickHandler -
setMouseMode
Set the mouse motion mode to a ClickHandler -
setMouseMode
Set the mouse motion mode to a LineHandler -
getScale
public double getScale()Compute the mapscale that is being used on the page (screen).- Specified by:
getScale
in interfaceLayerListListener
-
setScale
public void setScale(double value)Set the mapscale to be used on the page (screen). -
setMaxExtent
Set the default maximum extent of the image- Specified by:
setMaxExtent
in interfaceLayerListListener
-
pushHistory
Push a map extent on to the history stack -
popHistory
Pop a map extent off of the history stack -
zoom
public void zoom(double factor)Zoom by an arbitrary factor.- Parameters:
factor
- Factors less than 1 zoom in, greater than one zoom out.
-
zoomIn
public void zoomIn()Zoom in by a default 50% -
zoomOut
public void zoomOut()Zoom out by a default 100% -
zoomTo
public void zoomTo(double xmin, double ymin, double xmax, double ymax)Zoom to a new extent. -
zoomAt
public void zoomAt(double x, double y, double factor)Zoom to a new center location. -
zoomOutRelative
public void zoomOutRelative(double xmin, double ymin, double xmax, double ymax)Zoom out by a relative amount. The new extent will be centered on the midpoint of the box. The zoom out factor will be the ratio of the current extent to the box. -
translate
public void translate(double x, double y)Translate the extent by a specified x and y distance. -
reset
public void reset()Set the extent back to the maximum.- Specified by:
reset
in interfaceLayerListListener
-
setAdjust
public void setAdjust(boolean scaleChanged)Request that the drawing methods prepare to repaint the screen as soon as possible. Actual redrawing will not occur until the repaint timer fires the next time.- Parameters:
scaleChanged
- Indicate if the scale has changed as a result of this request, in order to pass notification up to any other LayerList listeners (for example, the legend).
-
paintComponent
Custom component painting routine This still needs to be fixed to not draw on borders -
print
public void print(Graphics2D g, Dimension d, double printScale, int dpi, LayerPrintCallback callback)Print the map to a graphics context. This will require user code to set up the print job and get the map context. Probably not usable in user scripts. -
actionPerformed
Handle events from the timer or scale changes. Repaint the map if an update has occured.- Specified by:
actionPerformed
in interfaceActionListener
-
maybeUpdate
public void maybeUpdate()Update the map, so long as the mouse is not involved in a drag operation.- Specified by:
maybeUpdate
in interfaceLayerListListener
-
mouseEntered
- Specified by:
mouseEntered
in interfaceMouseListener
-
mouseExited
- Specified by:
mouseExited
in interfaceMouseListener
-
mouseClicked
- Specified by:
mouseClicked
in interfaceMouseListener
-
mousePressed
Arm the system for a mouse drag operation.- Specified by:
mousePressed
in interfaceMouseListener
-
mouseReleased
Clean up after drag mode has ended.- Specified by:
mouseReleased
in interfaceMouseListener
-
mouseMoved
Track the X,Y location of the mouse- Specified by:
mouseMoved
in interfaceMouseMotionListener
-
mouseDragged
Catch mouse dragged events. These occur when the mouse is moved while the button is pressed.- Specified by:
mouseDragged
in interfaceMouseMotionListener
-
setActions
public void setActions()This method initializes a set of Action objects that describe functions that can be performed by this MapPanel. -
getAction
Get a previously defined action. This useful for building user interfaces. -
makeButton
Make a JButton from an Action, setting the command and insets to conform to the Patchworks look and feel. -
getButtonGroup
Get the ButtonGroup that is used for pointer modes such as zoomInMode, zoomOutMode, panMode etc., in case you need to add other actions to this buttongroup. -
loadToolBar
This routine will populate a toolbar with commonly used tools -
addFiles
Add files to the MapPanel. This is primarily used by the drag-and-drop mechanism, but can also be called from user scripts.
-