Class 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:
  • Field Details

    • 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 Details

    • NavigatedPanel

      public NavigatedPanel()
      The default constructor.
  • Method Details

    • setEnabled

      public void setEnabled(boolean enabled)
      _more_
      Overrides:
      setEnabled in class JComponent
      Parameters:
      enabled - _more_
    • ProjRectToRectangle2D

      public static Rectangle2D ProjRectToRectangle2D(ucar.unidata.geoloc.ProjectionRect projRect)
      Convert from a ProjectionRect object to a Rectangle2D object
      Parameters:
      projRect - ProjectionRect object
      Returns:
      Rectangle2D
    • ProjPointToPoint2D

      public static Point2D ProjPointToPoint2D(ucar.unidata.geoloc.ProjectionPointImpl ppi)
      Convert from a ProjectionPointImpl object to a Point2D object
      Parameters:
      ppi - ProjectionPointImpl object
      Returns:
      Point2D object
    • 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
    • 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

      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:
    • 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(MouseEvent e)
      Noop
      Specified by:
      mouseExited in interface MouseListener
      Parameters:
      e - The event
    • keyPressed

      public void keyPressed(KeyEvent e)
      Noop
      Specified by:
      keyPressed in interface KeyListener
      Parameters:
      e - The event
    • keyReleased

      public void keyReleased(KeyEvent e)
      Noop
      Specified by:
      keyReleased in interface KeyListener
      Parameters:
      e - The event
    • keyTyped

      public void keyTyped(KeyEvent e)
      Noop
      Specified by:
      keyTyped in interface KeyListener
      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