Package ucar.unidata.view.geoloc
Class NavigatedPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ucar.unidata.view.geoloc.NavigatedPanel
- All Implemented Interfaces:
KeyListener
,MouseListener
,MouseMotionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
public class NavigatedPanel
extends JPanel
implements MouseListener, MouseMotionListener, KeyListener
Implements a "navigated" JPanel within which a user can zoom and pan.
The mapping of the screen area to world coordinates is called "navigation", and
it's NavigatedPanel's job to keep track of the navigation as the user zooms and pans.
It throws NewMapAreaEvent to indicate that the user has changed the Map area,
and the display needs to be redrawn. It throws PickEvents when the user double clicks
on the panel.
NavigatedPanel has a standard JToolbar that can be displayed. It also implements a "reference" point and fast updating of the status of the mouse position relative to the reference point.
A user typically adds a NavigatedPanel and its toolbar to its frame/applet, and registers itself for NewMapAreaEvent's. When an event occurs, the user obtains a Graphics2D (through the getBufferedImageGraphics() method) to draw into. The AffineTransform of the Graphics2D has been set correctly to map projection coords to screen coords, based on the current zoomed and panned Map area. The renderer can use the AffineTransform if needed, but more typically just works in projection coordinates. The renderer can also get a clipping rectangle by calling g.getClip() and casting the Shape to a Rectangle2D, eg:
NavigatedPanel has a standard JToolbar that can be displayed. It also implements a "reference" point and fast updating of the status of the mouse position relative to the reference point.
A user typically adds a NavigatedPanel and its toolbar to its frame/applet, and registers itself for NewMapAreaEvent's. When an event occurs, the user obtains a Graphics2D (through the getBufferedImageGraphics() method) to draw into. The AffineTransform of the Graphics2D has been set correctly to map projection coords to screen coords, based on the current zoomed and panned Map area. The renderer can use the AffineTransform if needed, but more typically just works in projection coordinates. The renderer can also get a clipping rectangle by calling g.getClip() and casting the Shape to a Rectangle2D, eg:
Rectangle2D clipRect = (Rectangle2D) g.getClip();Our "world coordinates" are the same as java2D's "user coordinates". In general, the world coordinate plane is a projective geometry surface, typically in units of "km on the projection surface". The transformation from lat/lon to the projection plane is handled by a ProjectionImpl object. If a user selects a different projection, NavigatedPanel.setProjection() should be called. The default projection is "Cylindrical Equidistant" or "LatLon" which simply maps lat/lon degrees linearly to screen coordinates. A peculiarity of this projection is that the "seam" of the cylinder shifts as the user pans around. Currently our implementation sends a NewMapAreaEvent whenever this happens.
- Version:
- $Id: NavigatedPanel.java,v 1.60 2007/07/25 21:56:52 jeffmc Exp $
- Author:
- John Caron
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
dragging and zooming stateprotected int
dragging and zooming stateset reference actionprotected int
dragging and zooming stateprotected int
dragging and zooming stateFields inherited from class javax.swing.JComponent
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
accessibleContext, 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
addActionsToMenu
(JMenu menu) Add all of the toolbar's actions to a menu.void
Register a CursorMoveEventListener.void
Register a NewMapAreaListener.void
Register a PickEventListener.calcTransform
(boolean rotate, double displayX, double displayY, double displayWidth, double displayHeight) This calculates the Affine Transform that maps the current map area (in Projection Coordinates) to a display area (in arbitrary units).void
doMoveDown
(double factor) Translate downvoid
doMoveLeft
(double factor) Translate leftvoid
doMoveRight
(double factor) Translate rightvoid
doMoveUp
(double factor) Translate upvoid
doZoomIn()
Zoom invoid
Zoom outvoid
drawG()
Draw on the default graphicsearthToScreen
(ucar.unidata.geoloc.LatLonPoint llp) Utility to convert earth coordinates to Java screen coordinatesucar.unidata.geoloc.ProjectionRect
earthToWorld
(ucar.unidata.geoloc.LatLonRect llr) Change earth rect to world rectvoid
flipLon()
flip the latlon map between 0 360 and +-180Get the background color of the NavigatedPanel.This is used to do some fancy tricks with double bufferingUser must get this Graphics2D and draw into it when panel needs redrawingucar.unidata.geoloc.ProjectionRect
Get the current Map Area.Get the move toolbarReturn the Navigation held by this object.Get the navigation toolbar for this panelucar.unidata.geoloc.ProjectionImpl
Get the current Projection.ucar.unidata.geoloc.LatLonRect
Get the SelectedRegion property.ucar.unidata.geoloc.ProjectionRect
Get the SelectedRegion property.boolean
Get the SelectRegionMode property.boolean
Return whether the focus is traversablevoid
Noopvoid
Noopvoid
Noopvoid
Handle mouse clicked eventvoid
Handle the mouse dragged event.void
Noopvoid
Noopvoid
Handle the mouse moved event.void
Handle the mouse pressed eventvoid
Handle the mouse released event.ucar.unidata.geoloc.ProjectionRect
normalizeRectangle
(ucar.unidata.geoloc.ProjectionRect bb) If the projection is a LatLonProjection then this routine normalizes the rectangle to be between -180/180void
System-triggered redraw.static Point2D
ProjPointToPoint2D
(ucar.unidata.geoloc.ProjectionPointImpl ppi) Convert from a ProjectionPointImpl object to a Point2D objectstatic Rectangle2D
ProjRectToRectangle2D
(ucar.unidata.geoloc.ProjectionRect projRect) Convert from a ProjectionRect object to a Rectangle2D objectvoid
Remove a CursorMoveEventListener.void
Remove a NewMapAreaListener.void
Remove a PickEventListener.void
repaint
(long tm, int x, int y, int width, int height) Catch repaints - for debuggingvoid
Reset the zoom and projectionucar.unidata.geoloc.LatLonPoint
Utility to convert Java screen coordinates to earth coordinatesprotected void
Handle the selected region changed.void
setChangeable
(boolean mode) Sets whether the user can zoom/pan on this NavigatedPanel.void
setEnabled
(boolean enabled) _more_void
setMapArea
(ucar.unidata.geoloc.ProjectionRect ma) Set the Map Area.void
The status label is where the lat/lon position of the mouse is displayed.void
setProjectionImpl
(ucar.unidata.geoloc.ProjectionImpl p) Set the Projection, change the Map Area to the projection's defaultvoid
setSelectedRegion
(ucar.unidata.geoloc.LatLonRect llr) Set the SelectedRegion property.void
setSelectedRegion
(ucar.unidata.geoloc.ProjectionRect value) Set the SelectedRegion property.void
setSelectedRegionBounds
(ucar.unidata.geoloc.ProjectionRect bounds) Define a bounding rectangle, in world coordinates, that the selection region is limited to.void
setSelectRegionMode
(boolean value) Set the SelectRegionMode property.void
setWorldCenterX
(double wx_center) kludgy thing to shift LatLon seamboolean
Are we in select region mode for the given eventboolean
wantRotate
(double pwidth, double pheight) utility routine for printing.void
zoom
(double zoomFactor) Zoom by the given factorMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
setReferenceAction
set reference action -
startX
protected int startXdragging and zooming state -
startY
protected int startYdragging and zooming state -
deltax
protected int deltaxdragging and zooming state -
deltay
protected int deltaydragging and zooming state
-
-
Constructor Details
-
NavigatedPanel
public NavigatedPanel()The default constructor.
-
-
Method Details
-
setEnabled
public void setEnabled(boolean enabled) _more_- Overrides:
setEnabled
in classJComponent
- Parameters:
enabled
- _more_
-
ProjRectToRectangle2D
Convert from a ProjectionRect object to a Rectangle2D object- Parameters:
projRect
- ProjectionRect object- Returns:
- Rectangle2D
-
ProjPointToPoint2D
Convert from a ProjectionPointImpl object to a Point2D object- Parameters:
ppi
- ProjectionPointImpl object- Returns:
- Point2D object
-
addCursorMoveEventListener
Register a CursorMoveEventListener.- Parameters:
l
- listener to register
-
removeCursorMoveEventListener
Remove a CursorMoveEventListener.- Parameters:
l
- listener to remove
-
addPickEventListener
Register a PickEventListener.- Parameters:
l
- listener to register
-
removePickEventListener
Remove a PickEventListener.- Parameters:
l
- listener to remove
-
addNewMapAreaListener
Register a NewMapAreaListener.- Parameters:
l
- listener to register
-
removeNewMapAreaListener
Remove a NewMapAreaListener.- Parameters:
l
- listener to remove
-
getBackgroundColor
Get the background color of the NavigatedPanel.- Returns:
- background color
-
getMapArea
public ucar.unidata.geoloc.ProjectionRect getMapArea()Get the current Map Area.- Returns:
- the current Map Area
-
setMapArea
public void setMapArea(ucar.unidata.geoloc.ProjectionRect ma) Set the Map Area.- Parameters:
ma
- the MapArea
-
setWorldCenterX
public void setWorldCenterX(double wx_center) kludgy thing to shift LatLon seam- Parameters:
wx_center
- world center point
-
isFocusTraversable
public boolean isFocusTraversable()Return whether the focus is traversable- Overrides:
isFocusTraversable
in classComponent
- Returns:
- true if so
-
getProjectionImpl
public ucar.unidata.geoloc.ProjectionImpl getProjectionImpl()Get the current Projection.- Returns:
- the current Projection
-
normalizeRectangle
public ucar.unidata.geoloc.ProjectionRect normalizeRectangle(ucar.unidata.geoloc.ProjectionRect bb) If the projection is a LatLonProjection then this routine normalizes the rectangle to be between -180/180- Parameters:
bb
- Incoming rectangle- Returns:
- The input bb if not in LatLon, else the bb normalized
-
setProjectionImpl
public void setProjectionImpl(ucar.unidata.geoloc.ProjectionImpl p) Set the Projection, change the Map Area to the projection's default- Parameters:
p
- the Projection
-
setPositionLabel
The status label is where the lat/lon position of the mouse is displayed. May be null.- Parameters:
l
- the Jlabel to write into
-
getMoveToolBar
Get the move toolbar- Returns:
- the "Move" toolbar
-
addActionsToMenu
Add all of the toolbar's actions to a menu.- Parameters:
menu
- the menu to add the actions to
-
setChangeable
public void setChangeable(boolean mode) Sets whether the user can zoom/pan on this NavigatedPanel. Default = true.- Parameters:
mode
- set to false if user can't zoom/pan
-
repaint
public void repaint(long tm, int x, int y, int width, int height) Catch repaints - for debugging- Overrides:
repaint
in classJComponent
- Parameters:
tm
- not usedx
- x value of the dirty regiony
- y value of the dirty regionwidth
- width of the dirty regionheight
- height of the dirty region
-
paintComponent
System-triggered redraw.- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- graphics to paint
-
getBufferedImage
This is used to do some fancy tricks with double buffering- Returns:
- buffered image
-
getBufferedImageGraphics
User must get this Graphics2D and draw into it when panel needs redrawing- Returns:
- get the graphics for the buffered image
-
wantRotate
public boolean wantRotate(double pwidth, double pheight) utility routine for printing.- Parameters:
pwidth
- width of the page, units are arbitrarypheight
- height of the page, units are arbitrary- Returns:
- true if we want to rotate the page
-
calcTransform
public AffineTransform calcTransform(boolean rotate, double displayX, double displayY, double displayWidth, double displayHeight) This calculates the Affine Transform that maps the current map area (in Projection Coordinates) to a display area (in arbitrary units).- Parameters:
rotate
- should the page be rotated?displayX
- upper right X coord of corner of display areadisplayY
- upper right Y coord of corner of display areadisplayWidth
- display area widthdisplayHeight
- display area height- Returns:
- transform
- See Also:
-
drawG
public void drawG()Draw on the default graphics -
screenToEarth
Utility to convert Java screen coordinates to earth coordinates- Parameters:
p
- Screen point- Returns:
- Earth point
-
earthToScreen
Utility to convert earth coordinates to Java screen coordinates- Parameters:
llp
- Earth- Returns:
- Screen
-
mouseClicked
Handle mouse clicked event- Specified by:
mouseClicked
in interfaceMouseListener
- Parameters:
e
- event to handle
-
shouldSelectRegion
Are we in select region mode for the given event- Parameters:
e
- event- Returns:
- should be selecting
-
earthToWorld
public ucar.unidata.geoloc.ProjectionRect earthToWorld(ucar.unidata.geoloc.LatLonRect llr) Change earth rect to world rect- Parameters:
llr
- earth- Returns:
- world rect
-
mousePressed
Handle the mouse pressed event- Specified by:
mousePressed
in interfaceMouseListener
- Parameters:
e
- event to handle
-
selectedRegionChanged
protected void selectedRegionChanged()Handle the selected region changed. Subclasses should implement -
mouseReleased
Handle the mouse released event.- Specified by:
mouseReleased
in interfaceMouseListener
- Parameters:
e
- event to handle
-
mouseDragged
Handle the mouse dragged event.- Specified by:
mouseDragged
in interfaceMouseMotionListener
- Parameters:
e
- event to handle
-
mouseMoved
Handle the mouse moved event.- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Parameters:
e
- event to handle
-
mouseEntered
Noop- Specified by:
mouseEntered
in interfaceMouseListener
- Parameters:
e
- The event
-
mouseExited
Noop- Specified by:
mouseExited
in interfaceMouseListener
- Parameters:
e
- The event
-
keyPressed
Noop- Specified by:
keyPressed
in interfaceKeyListener
- Parameters:
e
- The event
-
keyReleased
Noop- Specified by:
keyReleased
in interfaceKeyListener
- Parameters:
e
- The event
-
keyTyped
Noop- Specified by:
keyTyped
in interfaceKeyListener
- Parameters:
e
- The event
-
doZoomIn
public void doZoomIn()Zoom in -
doZoomOut
public void doZoomOut()Zoom out -
zoom
public void zoom(double zoomFactor) Zoom by the given factor- Parameters:
zoomFactor
- zoom factor
-
doMoveUp
public void doMoveUp(double factor) Translate up- Parameters:
factor
- by
-
doMoveDown
public void doMoveDown(double factor) Translate down- Parameters:
factor
- by
-
doMoveRight
public void doMoveRight(double factor) Translate right- Parameters:
factor
- by
-
doMoveLeft
public void doMoveLeft(double factor) Translate left- Parameters:
factor
- by
-
resetZoom
public void resetZoom()Reset the zoom and projection -
flipLon
public void flipLon()flip the latlon map between 0 360 and +-180 -
setSelectRegionMode
public void setSelectRegionMode(boolean value) Set the SelectRegionMode property.- Parameters:
value
- The new value for SelectRegionMode
-
setSelectedRegionBounds
public void setSelectedRegionBounds(ucar.unidata.geoloc.ProjectionRect bounds) Define a bounding rectangle, in world coordinates, that the selection region is limited to.- Parameters:
bounds
- The bounds
-
getSelectRegionMode
public boolean getSelectRegionMode()Get the SelectRegionMode property.- Returns:
- The SelectRegionMode
-
setSelectedRegion
public void setSelectedRegion(ucar.unidata.geoloc.ProjectionRect value) Set the SelectedRegion property.- Parameters:
value
- The new value for SelectedRegion
-
setSelectedRegion
public void setSelectedRegion(ucar.unidata.geoloc.LatLonRect llr) Set the SelectedRegion property.- Parameters:
llr
- The new region
-
getSelectedRegion
public ucar.unidata.geoloc.ProjectionRect getSelectedRegion()Get the SelectedRegion property.- Returns:
- The SelectedRegion
-
getSelectedEarthRegion
public ucar.unidata.geoloc.LatLonRect getSelectedEarthRegion()Get the SelectedRegion property.- Returns:
- The SelectedRegion
-