net.agmodel.panel
Class MapPanel
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--javax.swing.JPanel
|
+--net.agmodel.panel.MapPanel
- All Implemented Interfaces:
- Accessible, DataSourceListener, EventListener, GeographicalAreaListener, ImageObserver, MapDisplayListener, MenuContainer, MouseListener, MouseMotionListener, RequestBeanListener, Serializable
- Direct Known Subclasses:
- ChizuPanel, DEMPanel, MapBlast
- public abstract class MapPanel
- extends JPanel
- implements MouseListener, MouseMotionListener, GeographicalAreaListener, DataSourceListener, MapDisplayListener, RequestBeanListener
MapPanel is an abstract class handling the display of spatially distributed information, like maps, or digital elevation models.
How MapPanel handles latitude and longitude.
When asked to display a target Geographical Box, MapPanel must handle the fact that the shape (aspect ratio) of the target region and panel may differ. MapPanels approach to handling this is to maintain the aspect ratio of the display (so the scale of the display vertically and horizontally is the same) and to display the entire target Region without clipping it. This means that it must usually display a larger region in one dimension than has been requested.
MapPanel does the following:
1. Determines the centre of the box (lat and long). This point remains in the centre of the display.
2. Calculates the relationship between distance and longitude at the center of the display.
3. Calculates the latitude range of the box and distance from north to south bound (say 1000km). (The relationship between latitude and distances is constant, unlike the relationship between longitude and distance).
4. Uses the number of vertical display pixels, and an assumption about the size of each pixel to calculate the vertical display distance (say 15cm).
5. Calculates the vertical scale needed to fit the north and south bounds to the upper and lower display bounds. (as a ratio of north/south world distance to vertical screen distance).
6. Calculates the horizontal scale needed to fit the west and east bounds to the left and right display bounds.
7. Determines the display scale as the larger of the two scales and flags whether the display is "targetRegionWide"
8. If targetRegionWide then
Calculates the latitudes corresponding to the top and bottom of the display.
Retrieves a map from calculatedNorth,actualWest to calculatedSouth, actualEast
Draws horizontal lines on the map showing the target north and south bounds
else
Calculates either the longitudes corresponding to the left and right edge of the display
Retrieves a map from actualNorth,calculatedWest to actualSouth, calculatedEast
Draws vertical dashed lines on the map showing the target west and east bounds.
Copyright: Copyright (c) 2002
Company:
- See Also:
- Serialized Form
| Fields inherited from class java.awt.Container |
|
|
Method Summary |
void |
addIndeterminateListener(IndeterminateListener x)
|
void |
addMapDisplayListener(MapDisplayListener x)
|
protected void |
calculateDisplayRegion()
|
protected void |
centredMessage(Graphics g,
String message)
|
protected void |
createOffScreenImage(Rectangle bounds)
|
void |
drawBox(int x,
int y)
|
protected void |
fireIndeterminateEvent(IndeterminateEvent evt)
Notifies listeners that a task of unknown duration has started
and enables or disables the button as appropriate |
protected void |
fireMapDisplayEvent(MapDisplayEvent evt)
|
static double |
fitScale(GeographicalBox targetRegion,
Rectangle screen)
Determines a scale large enough to ensure that the entire target region will be displayed in the screen rectangle |
protected abstract Color |
getBoxColor()
|
protected Location2D |
getLocation(int x,
int y)
|
protected Graphics2D |
getOffScreenGraphics()
|
protected BufferedImage |
getOffScreenImage()
|
static double |
getRequiredHorizontalScale(GeographicalBox targetRegion,
Rectangle screen)
|
static double |
getRequiredVerticalScale(GeographicalBox targetRegion,
Rectangle screen)
|
GeographicalBox |
getTargetRegion()
|
protected boolean |
isGettingImage()
|
void |
jumpToBox()
|
void |
jumpToLatLong()
|
void |
map(Location2D location,
Point p)
|
protected void |
maybeFireMapDisplayEvent()
|
void |
mouseClicked(MouseEvent e)
|
void |
mouseDragged(MouseEvent e)
|
void |
mouseEntered(MouseEvent e)
|
void |
mouseExited(MouseEvent e)
|
void |
mouseMoved(MouseEvent e)
|
void |
mousePressed(MouseEvent e)
|
void |
mouseReleased(MouseEvent e)
|
void |
newDataSource(DataSourceEvent evt)
|
void |
newGeographicalArea(GeographicalAreaEvent evt)
|
void |
newMapDisplay(MapDisplayEvent evt)
|
void |
paintComponent(Graphics g)
|
void |
panEast()
|
void |
panNorth()
|
void |
panSouth()
|
void |
panWest()
|
protected void |
popupMenu(JComponent comp,
int x,
int y)
|
void |
removeIndeterminateListener(IndeterminateListener x)
|
void |
removeMapDisplayListener(MapDisplayListener x)
|
void |
requestSent(EventObject evt)
|
protected void |
scale(double north,
double west,
double south,
double east)
Moves the target region. |
protected void |
setGettingImage(boolean isGetting)
|
void |
setTargetRegion(GeographicalBox box)
|
void |
zoomIn()
|
void |
zoomOut()
|
| Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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 |
ub
protected static final ResourceBundle ub
parent
protected ImageObserver parent
scale
protected double scale
anchor
protected Point anchor
prevBox
protected Rectangle prevBox
currentBox
protected Rectangle currentBox
gettingImage
protected transient boolean gettingImage
MapPanel
public MapPanel(ImageObserver parent)
paintComponent
public void paintComponent(Graphics g)
- Overrides:
paintComponent in class JComponent
getRequiredHorizontalScale
public static double getRequiredHorizontalScale(GeographicalBox targetRegion,
Rectangle screen)
getRequiredVerticalScale
public static double getRequiredVerticalScale(GeographicalBox targetRegion,
Rectangle screen)
fitScale
public static double fitScale(GeographicalBox targetRegion,
Rectangle screen)
- Determines a scale large enough to ensure that the entire target region will be displayed in the screen rectangle
- Parameters:
targetRegion - the geographical area of interestscreen - the area of pixels to be filled on the screen
- Returns:
- the larger of the required horizontal and required vertical scales
calculateDisplayRegion
protected void calculateDisplayRegion()
getBoxColor
protected abstract Color getBoxColor()
getOffScreenImage
protected BufferedImage getOffScreenImage()
getOffScreenGraphics
protected Graphics2D getOffScreenGraphics()
createOffScreenImage
protected void createOffScreenImage(Rectangle bounds)
requestSent
public void requestSent(EventObject evt)
- Specified by:
requestSent in interface RequestBeanListener
centredMessage
protected void centredMessage(Graphics g,
String message)
setTargetRegion
public void setTargetRegion(GeographicalBox box)
getLocation
protected Location2D getLocation(int x,
int y)
map
public void map(Location2D location,
Point p)
drawBox
public void drawBox(int x,
int y)
mousePressed
public void mousePressed(MouseEvent e)
- Specified by:
mousePressed in interface MouseListener
mouseReleased
public void mouseReleased(MouseEvent e)
- Specified by:
mouseReleased in interface MouseListener
mouseDragged
public void mouseDragged(MouseEvent e)
- Specified by:
mouseDragged in interface MouseMotionListener
mouseClicked
public void mouseClicked(MouseEvent e)
- Specified by:
mouseClicked in interface MouseListener
mouseEntered
public void mouseEntered(MouseEvent e)
- Specified by:
mouseEntered in interface MouseListener
mouseExited
public void mouseExited(MouseEvent e)
- Specified by:
mouseExited in interface MouseListener
mouseMoved
public void mouseMoved(MouseEvent e)
- Specified by:
mouseMoved in interface MouseMotionListener
popupMenu
protected void popupMenu(JComponent comp,
int x,
int y)
zoomIn
public void zoomIn()
zoomOut
public void zoomOut()
panNorth
public void panNorth()
panSouth
public void panSouth()
panEast
public void panEast()
panWest
public void panWest()
jumpToLatLong
public void jumpToLatLong()
jumpToBox
public void jumpToBox()
scale
protected void scale(double north,
double west,
double south,
double east)
- Moves the target region. Parameters are multiples of the corresponding range to add to north, south latitudes and east and west longitudes respectively.
- Parameters:
north - eg -1/2 means reduce northmost latitude by half of target rangewest - south - eg +1/4 means add quarter of target range to southmost latitudeeast - eg -1 means subtract the current longitude range from the east bound.
setGettingImage
protected void setGettingImage(boolean isGetting)
isGettingImage
protected boolean isGettingImage()
getTargetRegion
public GeographicalBox getTargetRegion()
maybeFireMapDisplayEvent
protected void maybeFireMapDisplayEvent()
fireMapDisplayEvent
protected void fireMapDisplayEvent(MapDisplayEvent evt)
addMapDisplayListener
public void addMapDisplayListener(MapDisplayListener x)
removeMapDisplayListener
public void removeMapDisplayListener(MapDisplayListener x)
fireIndeterminateEvent
protected void fireIndeterminateEvent(IndeterminateEvent evt)
- Notifies listeners that a task of unknown duration has started
and enables or disables the button as appropriate
addIndeterminateListener
public void addIndeterminateListener(IndeterminateListener x)
removeIndeterminateListener
public void removeIndeterminateListener(IndeterminateListener x)
newGeographicalArea
public void newGeographicalArea(GeographicalAreaEvent evt)
- Specified by:
newGeographicalArea in interface GeographicalAreaListener
newDataSource
public void newDataSource(DataSourceEvent evt)
newMapDisplay
public void newMapDisplay(MapDisplayEvent evt)
- Specified by:
newMapDisplay in interface MapDisplayListener