ucar.unidata.view.geoloc
Class NavigatedPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by 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:

       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:
Serialized Form

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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  int deltax
          dragging and zooming state
protected  int deltay
          dragging and zooming state
 AbstractAction setReferenceAction
          set reference action
protected  int startX
          dragging and zooming state
protected  int startY
          dragging and zooming state
 
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
NavigatedPanel()
          The default constructor.
 
Method Summary
 void addActionsToMenu(JMenu menu)
          Add all of the toolbar's actions to a menu.
 void addCursorMoveEventListener(CursorMoveEventListener l)
          Register a CursorMoveEventListener.
 void addNewMapAreaListener(NewMapAreaListener l)
          Register a NewMapAreaListener.
 void addPickEventListener(PickEventListener l)
          Register a PickEventListener.
 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).
 void doMoveDown(double factor)
          Translate down
 void doMoveLeft(double factor)
          Translate left
 void doMoveRight(double factor)
          Translate right
 void doMoveUp(double factor)
          Translate up
 void doZoomIn()
          Zoom in
 void doZoomOut()
          Zoom out
 void drawG()
          Draw on the default graphics
 Point2D earthToScreen(ucar.unidata.geoloc.LatLonPoint llp)
          Utility to convert earth coordinates to Java screen coordinates
 ucar.unidata.geoloc.ProjectionRect earthToWorld(ucar.unidata.geoloc.LatLonRect llr)
          Change earth rect to world rect
 Color getBackgroundColor()
          Get the background color of the NavigatedPanel.
 BufferedImage getBufferedImage()
          This is used to do some fancy tricks with double buffering
 Graphics2D getBufferedImageGraphics()
          User must get this Graphics2D and draw into it when panel needs redrawing
 ucar.unidata.geoloc.ProjectionRect getMapArea()
          Get the current Map Area.
 JToolBar getMoveToolBar()
          Get the move toolbar
 Navigation getNavigation()
          Return the Navigation held by this object.
 JToolBar getNavToolBar()
          Get the navigation toolbar for this panel
 ucar.unidata.geoloc.ProjectionImpl getProjectionImpl()
          Get the current Projection.
 ucar.unidata.geoloc.LatLonRect getSelectedEarthRegion()
          Get the SelectedRegion property.
 ucar.unidata.geoloc.ProjectionRect getSelectedRegion()
          Get the SelectedRegion property.
 boolean getSelectRegionMode()
          Get the SelectRegionMode property.
 boolean isFocusTraversable()
          Return whether the focus is traversable
 void keyPressed(KeyEvent e)
          Noop
 void keyReleased(KeyEvent e)
          Noop
 void keyTyped(KeyEvent e)
          Noop
 void mouseClicked(MouseEvent e)
          Handle mouse clicked event
 void mouseDragged(MouseEvent e)
          Handle the mouse dragged event.
 void mouseEntered(MouseEvent e)
          Noop
 void mouseExited(MouseEvent e)
          Noop
 void mouseMoved(MouseEvent e)
          Handle the mouse moved event.
 void mousePressed(MouseEvent e)
          Handle the mouse pressed event
 void mouseReleased(MouseEvent e)
          Handle the mouse released event.
 void paintComponent(Graphics g)
          System-triggered redraw.
 void removeCursorMoveEventListener(CursorMoveEventListener l)
          Remove a CursorMoveEventListener.
 void removeNewMapAreaListener(NewMapAreaListener l)
          Remove a NewMapAreaListener.
 void removePickEventListener(PickEventListener l)
          Remove a PickEventListener.
 void repaint(long tm, int x, int y, int width, int height)
          Catch repaints - for debugging
 void resetZoom()
          Reset the zoom and projection
 ucar.unidata.geoloc.LatLonPoint screenToEarth(Point2D p)
          Utility to convert Java screen coordinates to earth coordinates
protected  void selectedRegionChanged()
          Handle the selected region changed.
 void setChangeable(boolean mode)
          Sets whether the user can zoom/pan on this NavigatedPanel.
 void setEnabled(boolean enabled)
           
 void setMapArea(ucar.unidata.geoloc.ProjectionRect ma)
          Set the Map Area.
 void setPositionLabel(JLabel l)
          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 default
 void 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 seam
 boolean shouldSelectRegion(MouseEvent e)
          Are we in select region mode for the given event
 boolean wantRotate(double pwidth, double pheight)
          utility routine for printing.
 void zoom(double zoomFactor)
          Zoom by the given factor
 
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, 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, 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, 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, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

setReferenceAction

public AbstractAction setReferenceAction
set reference action


startX

protected int startX
dragging and zooming state


startY

protected int startY
dragging and zooming state


deltax

protected int deltax
dragging and zooming state


deltay

protected int deltay
dragging and zooming state

Constructor Detail

NavigatedPanel

public NavigatedPanel()
The default constructor.

Method Detail

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class JComponent

addCursorMoveEventListener

public void addCursorMoveEventListener(CursorMoveEventListener l)
Register a CursorMoveEventListener.

Parameters:
l - listener to register

removeCursorMoveEventListener

public void removeCursorMoveEventListener(CursorMoveEventListener l)
Remove a CursorMoveEventListener.

Parameters:
l - listener to remove

addPickEventListener

public void addPickEventListener(PickEventListener l)
Register a PickEventListener.

Parameters:
l - listener to register

removePickEventListener

public void removePickEventListener(PickEventListener l)
Remove a PickEventListener.

Parameters:
l - listener to remove

addNewMapAreaListener

public void addNewMapAreaListener(NewMapAreaListener l)
Register a NewMapAreaListener.

Parameters:
l - listener to register

removeNewMapAreaListener

public void removeNewMapAreaListener(NewMapAreaListener l)
Remove a NewMapAreaListener.

Parameters:
l - listener to remove

getBackgroundColor

public Color getBackgroundColor()
Get the background color of the NavigatedPanel.

Returns:
background color

getNavigation

public Navigation getNavigation()
Return the Navigation held by this object.

Returns:
the Navigation

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 class Component
Returns:
true if so

getProjectionImpl

public ucar.unidata.geoloc.ProjectionImpl getProjectionImpl()
Get the current Projection.

Returns:
the current Projection

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

public void setPositionLabel(JLabel l)
The status label is where the lat/lon position of the mouse is displayed. May be null.

Parameters:
l - the Jlabel to write into

getNavToolBar

public JToolBar getNavToolBar()
Get the navigation toolbar for this panel

Returns:
the "Navigate" toolbar

getMoveToolBar

public JToolBar getMoveToolBar()
Get the move toolbar

Returns:
the "Move" toolbar

addActionsToMenu

public void addActionsToMenu(JMenu menu)
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 class JComponent
Parameters:
tm - not used
x - x value of the dirty region
y - y value of the dirty region
width - width of the dirty region
height - height of the dirty region

paintComponent

public void paintComponent(Graphics g)
System-triggered redraw.

Overrides:
paintComponent in class JComponent
Parameters:
g - graphics to paint

getBufferedImage

public BufferedImage getBufferedImage()
This is used to do some fancy tricks with double buffering

Returns:
buffered image

getBufferedImageGraphics

public Graphics2D 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 arbitrary
pheight - 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 area
displayY - upper right Y coord of corner of display area
displayWidth - display area width
displayHeight - display area height
Returns:
transform
See Also:
Navigation.calcTransform(boolean, double, double, double, double)

drawG

public void drawG()
Draw on the default graphics


screenToEarth

public ucar.unidata.geoloc.LatLonPoint screenToEarth(Point2D p)
Utility to convert Java screen coordinates to earth coordinates

Parameters:
p - Screen point
Returns:
Earth point

earthToScreen

public Point2D earthToScreen(ucar.unidata.geoloc.LatLonPoint llp)
Utility to convert earth coordinates to Java screen coordinates

Parameters:
llp - Earth
Returns:
Screen

mouseClicked

public void mouseClicked(MouseEvent e)
Handle mouse clicked event

Specified by:
mouseClicked in interface MouseListener
Parameters:
e - event to handle

shouldSelectRegion

public boolean shouldSelectRegion(MouseEvent e)
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

public void mousePressed(MouseEvent e)
Handle the mouse pressed event

Specified by:
mousePressed in interface MouseListener
Parameters:
e - event to handle

selectedRegionChanged

protected void selectedRegionChanged()
Handle the selected region changed. Subclasses should implement


mouseReleased

public void mouseReleased(MouseEvent e)
Handle the mouse released event.

Specified by:
mouseReleased in interface MouseListener
Parameters:
e - event to handle

mouseDragged

public void mouseDragged(MouseEvent e)
Handle the mouse dragged event.

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
e - event to handle

mouseMoved

public void mouseMoved(MouseEvent e)
Handle the mouse moved event.

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
e - event to handle

mouseEntered

public void mouseEntered(MouseEvent e)
Noop

Specified by:
mouseEntered in interface MouseListener
Parameters:
e - The event

mouseExited

public void mouseExited(