Package ucar.nc2.ui.geoloc
Class NavigatedPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- ucar.nc2.ui.geoloc.NavigatedPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class NavigatedPanel extends JPanel
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. See NPController class for an example. 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.
- 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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description AbstractAction
setReferenceAction
-
Fields 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 Constructor Description NavigatedPanel()
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActionsToMenu(JMenu menu)
Add all of the toolbar's actions to a menu.void
addCursorMoveEventListener(CursorMoveEventListener l)
Register a CursorMoveEventListener.void
addGeoSelectionListener(GeoSelectionListener l)
Register a PickEventListener.void
addNewMapAreaListener(NewMapAreaListener l)
Register a NewMapAreaListener.void
addNewProjectionListener(NewProjectionListener l)
Register a NewProjectionListener.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
drawG()
Color
getBackgroundColor()
BufferedImage
getBufferedImage()
This is used to do some fancy tricks with double bufferingGraphics2D
getBufferedImageGraphics()
User must get this Graphics2D and draw into it when panel needs redrawingProjectionRect
getGeoSelection()
LatLonRect
getGeoSelectionLL()
ProjectionRect
getMapArea()
Get the current Map AreaLatLonRect
getMapAreaLL()
Get the current Map Area as a lat/lon bounding boxJToolBar
getMoveToolBar()
Navigation
getNavigation()
JToolBar
getNavToolBar()
ProjectionImpl
getProjectionImpl()
Get the current Projection.void
paintComponent(Graphics g)
System-triggered redraw.void
removeCursorMoveEventListener(CursorMoveEventListener l)
Remove a CursorMoveEventListener.void
removeGeoSelectionListener(GeoSelectionListener l)
Remove a PickEventListener.void
removeNewMapAreaListener(NewMapAreaListener l)
Remove a NewMapAreaListener.void
removeNewProjectionListener(NewProjectionListener l)
Remove a NewProjectionListener.void
removePickEventListener(PickEventListener l)
Remove a PickEventListener.void
repaint(long tm, int x, int y, int width, int height)
catch repaints - for debuggingvoid
setChangeable(boolean mode)
sets whether the user can zoom/pan on this NavigatedPanel.void
setEnabledActions(boolean b)
void
setGeoSelection(LatLonRect llbb)
void
setGeoSelection(ProjectionRect bb)
void
setGeoSelectionMode(boolean b)
void
setLatLonCenterMapArea(double lat, double lon)
set the center point of the MapAreavoid
setMapArea(LatLonRect llbb)
Set the Map Area by converting LatLonRect to a ProjectionRect.void
setMapArea(ProjectionRect ma)
Set the Map Area.void
setPositionLabel(JLabel statusLabel)
The status label is where the lat/lon position of the mouse is displayed.void
setProjectionImpl(ProjectionImpl p)
Set the Projection, change the Map Area to the projection's default.void
setWorldCenterX(double wx_center)
kludgy thing to shift LatLon seamboolean
wantRotate(double pwidth, double pheight)
utility routine for printing.-
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, 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, setEnabled, 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, 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, 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 Detail
-
setReferenceAction
public AbstractAction setReferenceAction
-
-
Method Detail
-
getGeoSelectionLL
public LatLonRect getGeoSelectionLL()
-
getGeoSelection
public ProjectionRect getGeoSelection()
-
setGeoSelection
public void setGeoSelection(ProjectionRect bb)
-
setGeoSelection
public void setGeoSelection(LatLonRect llbb)
-
setGeoSelectionMode
public void setGeoSelectionMode(boolean b)
-
addNewMapAreaListener
public void addNewMapAreaListener(NewMapAreaListener l)
Register a NewMapAreaListener.
-
removeNewMapAreaListener
public void removeNewMapAreaListener(NewMapAreaListener l)
Remove a NewMapAreaListener.
-
addNewProjectionListener
public void addNewProjectionListener(NewProjectionListener l)
Register a NewProjectionListener. The only time this is called is when the projection isLatLon, and a zoom or pan crosses the seam.
-
removeNewProjectionListener
public void removeNewProjectionListener(NewProjectionListener l)
Remove a NewProjectionListener.
-
addCursorMoveEventListener
public void addCursorMoveEventListener(CursorMoveEventListener l)
Register a CursorMoveEventListener.
-
removeCursorMoveEventListener
public void removeCursorMoveEventListener(CursorMoveEventListener l)
Remove a CursorMoveEventListener.
-
addPickEventListener
public void addPickEventListener(PickEventListener l)
Register a PickEventListener.
-
removePickEventListener
public void removePickEventListener(PickEventListener l)
Remove a PickEventListener.
-
addGeoSelectionListener
public void addGeoSelectionListener(GeoSelectionListener l)
Register a PickEventListener.
-
removeGeoSelectionListener
public void removeGeoSelectionListener(GeoSelectionListener l)
Remove a PickEventListener.
-
getNavigation
public Navigation getNavigation()
-
getBackgroundColor
public Color getBackgroundColor()
-
setMapArea
public void setMapArea(ProjectionRect ma)
Set the Map Area.
-
setMapArea
public void setMapArea(LatLonRect llbb)
Set the Map Area by converting LatLonRect to a ProjectionRect.
-
getMapArea
public ProjectionRect getMapArea()
Get the current Map Area
-
getMapAreaLL
public LatLonRect getMapAreaLL()
Get the current Map Area as a lat/lon bounding box
-
setWorldCenterX
public void setWorldCenterX(double wx_center)
kludgy thing to shift LatLon seam
-
setLatLonCenterMapArea
public void setLatLonCenterMapArea(double lat, double lon)
set the center point of the MapArea
-
getProjectionImpl
public ProjectionImpl getProjectionImpl()
Get the current Projection.
-
setProjectionImpl
public void setProjectionImpl(ProjectionImpl p)
Set the Projection, change the Map Area to the projection's default.
-
setPositionLabel
public void setPositionLabel(JLabel statusLabel)
The status label is where the lat/lon position of the mouse is displayed. May be null.- Parameters:
statusLabel
- the Jlabel to write into
-
getNavToolBar
public JToolBar getNavToolBar()
- Returns:
- the "Navigate" toolbar
-
getMoveToolBar
public JToolBar getMoveToolBar()
- 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
-
setEnabledActions
public void setEnabledActions(boolean b)
-
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
-
paintComponent
public void paintComponent(Graphics g)
System-triggered redraw.- Overrides:
paintComponent
in classJComponent
-
getBufferedImage
public BufferedImage getBufferedImage()
This is used to do some fancy tricks with double buffering
-
getBufferedImageGraphics
public Graphics2D getBufferedImageGraphics()
User must get this Graphics2D and draw into it when panel needs redrawing
-
wantRotate
public boolean wantRotate(double pwidth, double pheight)
utility routine for printing.- Parameters:
pwidth
- : widtht 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 corner of display areadisplayY
- upper right corner of display areadisplayWidth
- display areadisplayHeight
- display area see Navigation.calcTransform
-
drawG
public void drawG()
-
-