|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ucar.unidata.view.geoloc.NavigatedPanel
public class NavigatedPanel
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.
| 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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public AbstractAction setReferenceAction
protected int startX
protected int startY
protected int deltax
protected int deltay
| Constructor Detail |
|---|
public NavigatedPanel()
| Method Detail |
|---|
public void setEnabled(boolean enabled)
setEnabled in class JComponentpublic void addCursorMoveEventListener(CursorMoveEventListener l)
l - listener to registerpublic void removeCursorMoveEventListener(CursorMoveEventListener l)
l - listener to removepublic void addPickEventListener(PickEventListener l)
l - listener to registerpublic void removePickEventListener(PickEventListener l)
l - listener to removepublic void addNewMapAreaListener(NewMapAreaListener l)
l - listener to registerpublic void removeNewMapAreaListener(NewMapAreaListener l)
l - listener to removepublic Color getBackgroundColor()
public Navigation getNavigation()
public ucar.unidata.geoloc.ProjectionRect getMapArea()
public void setMapArea(ucar.unidata.geoloc.ProjectionRect ma)
ma - the MapAreapublic void setWorldCenterX(double wx_center)
wx_center - world center pointpublic boolean isFocusTraversable()
isFocusTraversable in class Componentpublic ucar.unidata.geoloc.ProjectionImpl getProjectionImpl()
public void setProjectionImpl(ucar.unidata.geoloc.ProjectionImpl p)
p - the Projectionpublic void setPositionLabel(JLabel l)
l - the Jlabel to write intopublic JToolBar getNavToolBar()
public JToolBar getMoveToolBar()
public void addActionsToMenu(JMenu menu)
menu - the menu to add the actions topublic void setChangeable(boolean mode)
mode - set to false if user can't zoom/pan
public void repaint(long tm,
int x,
int y,
int width,
int height)
repaint in class JComponenttm - not usedx - x value of the dirty regiony - y value of the dirty regionwidth - width of the dirty regionheight - height of the dirty regionpublic void paintComponent(Graphics g)
paintComponent in class JComponentg - graphics to paintpublic BufferedImage getBufferedImage()
public Graphics2D getBufferedImageGraphics()
public boolean wantRotate(double pwidth,
double pheight)
pwidth - width of the page, units are arbitrarypheight - height of the page, units are arbitrary
public AffineTransform calcTransform(boolean rotate,
double displayX,
double displayY,
double displayWidth,
double displayHeight)
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
Navigation.calcTransform(boolean, double, double, double, double)public void drawG()
public ucar.unidata.geoloc.LatLonPoint screenToEarth(Point2D p)
p - Screen point
public Point2D earthToScreen(ucar.unidata.geoloc.LatLonPoint llp)
llp - Earth
public void mouseClicked(MouseEvent e)
mouseClicked in interface MouseListenere - event to handlepublic boolean shouldSelectRegion(MouseEvent e)
e - event
public ucar.unidata.geoloc.ProjectionRect earthToWorld(ucar.unidata.geoloc.LatLonRect llr)
llr - earth
public void mousePressed(MouseEvent e)
mousePressed in interface MouseListenere - event to handleprotected void selectedRegionChanged()
public void mouseReleased(MouseEvent e)
mouseReleased in interface MouseListenere - event to handlepublic void mouseDragged(MouseEvent e)
mouseDragged in interface MouseMotionListenere - event to handlepublic void mouseMoved(MouseEvent e)
mouseMoved in interface MouseMotionListenere - event to handlepublic void mouseEntered(MouseEvent e)
mouseEntered in interface MouseListenere - The eventpublic void mouseExited(