com.bbn.openmap.event
Class DistanceMouseMode

java.lang.Object
  extended by com.bbn.openmap.MapHandlerChild
      extended by com.bbn.openmap.OMComponent
          extended by com.bbn.openmap.event.AbstractMouseMode
              extended by com.bbn.openmap.event.CoordMouseMode
                  extended by com.bbn.openmap.event.DistanceMouseMode
All Implemented Interfaces:
MapMouseMode, PaintListener, LightMapHandlerChild, PropertyConsumer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.beans.beancontext.BeanContextChild, java.beans.beancontext.BeanContextMembershipListener, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener

public class DistanceMouseMode
extends CoordMouseMode
implements PaintListener

This mouse mode draws a rubberband line and circle between each mouse click as the mouse is moved and displays the cumulative distance in nautical miles (nm), kilometers (km), statute miles (miles) and the azimuth angle in decimal degrees from north on the status bar. Several distance segments are allowed. To erase (terminate) double click the mouse.

The mode creates lines and circles, and then calls map.repaint(). As a PaintListener to the MapBean, those lines and circles get painted whenever the map is painted.

To use this mouse mode in the OpenMap demo (in setWidgets): create the mouse mode, such as

DistanceMouseMode distMode = new DistanceMouseMode(true, id, DistanceMouseMode.DISTANCE_ALL);

Add the distance mouse mode to the mouse delegator md.addMouseMode(distMode);

This class can easily be extended, for example to create waypoints for objects.

NOTE: If some lines are not properly erased (because the mouse went outside the map for example), just use the redraw from the menu.

You can set the units used for measurements by setting the property:


      prefix.units= &lt name for Length.java (km, miles, meters, nm, all) &gt

 
Note that "all" will display nm, km, and miles.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.bbn.openmap.event.AbstractMouseMode
AbstractMouseMode.MouseWheelTimerListener
 
Field Summary
static java.lang.String AllUnitsPropertyValue
          Special units value for displaying all units ...
 java.text.DecimalFormat df
           
protected  double distance
          Distance of the current segment
protected  boolean drawDistanceObjects
          Flag, true if the mouse has already been pressed
static java.lang.String modeID
          Mouse mode identifier, is "Distance".
protected  DrawingAttributes renderAttributes
          Rendering attributes for lines and circles.
static java.lang.String RepaintToCleanProperty
           
protected  java.awt.geom.Point2D rPoint1
          rPoint1 is the anchor point of a line segment
protected  java.awt.geom.Point2D rPoint2
          rPoint2 is the new (current) point of a line segment
protected  java.util.Vector<java.awt.geom.Point2D> segments
          Vector to store all distance segments, first point and last point pairs
static java.lang.String ShowAngleProperty
           
static java.lang.String ShowCircleProperty
           
protected  double totalDistance
          The cumulative distance from the first mouse click
static java.lang.String UnitProperty
           
 
Fields inherited from class com.bbn.openmap.event.CoordMouseMode
coordFormatter, coordFormatterHandler, CoordFormatterProperty, infoDelegator
 
Fields inherited from class com.bbn.openmap.event.AbstractMouseMode
cursor, CursorIDProperty, guiIcon, iconName, IconProperty, ID, IDProperty, logger, mouseSupport, mouseTimer, mouseWheelListener, MouseWheelListenerProperty, mouseWheelTimerInterval, MouseWheelTimerIntervalProperty, mouseWheelTimerListener, MouseWheelZoomProperty, noMouseWheelListenerTimer, NoMouseWheelListenerTimerProperty, prettyName, PrettyNameProperty, propertyChangeSupport, visible, ZOOM_IN, ZOOM_OUT, zoomWhenMouseWheelUp
 
Fields inherited from class com.bbn.openmap.OMComponent
i18n, propertyPrefix
 
Fields inherited from class com.bbn.openmap.MapHandlerChild
beanContextChildSupport, isolated
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Constructor Summary
DistanceMouseMode()
          Construct a DistanceMouseMode.
DistanceMouseMode(boolean consumeEvents)
          Construct a DistanceMouseMode.
DistanceMouseMode(boolean consumeEvents, InformationDelegator id)
          Construct a DistanceMouseMode.
DistanceMouseMode(boolean consumeEvents, InformationDelegator id, Length units)
          Construct a DistanceMouseMode.
DistanceMouseMode(boolean consumeEvents, InformationDelegator id, Length units, int lType)
          Construct a DistanceMouseMode.
DistanceMouseMode(java.lang.String name, boolean consumeEvents)
          Construct an DistanceMouseMode.
DistanceMouseMode(java.lang.String name, boolean consumeEvents, InformationDelegator id)
          Construct a DistanceMouseMode.
 
Method Summary
 void cleanUp()
          Reset the segments and distances
protected  java.lang.String createDistanceInformationLine(java.awt.geom.Point2D llp, double distance, double azimuth)
          Create the contents of the information line, based on user inputs.
 double getGreatCircleDist(double phi1, double lambda0, double phi, double lambda, int units)
          Return the distance in the chosen unit between two points (in decimal degrees).
 int getLineType()
          Return the line type either LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT
protected  MapBean getMapBean()
          Return the map bean.
 java.util.Properties getProperties(java.util.Properties getList)
          PropertyConsumer interface method.
 java.util.Properties getPropertyInfo(java.util.Properties list)
          PropertyConsumer interface method.
 boolean getShowAzimuth()
          Whether the display of the azimuth angle on or off.
 boolean getShowCircle()
          Get whether the drawing of the rubberband circle on/off.
 double getSphericalAzimuth(double phi1, double lambda0, double phi, double lambda)
          Return the azimuth angle in decimal degrees from north.
 double getTotalDistance()
           
 Length getUnit()
          Return the unit of distance being displayed: Length.NM, Length.KM or Length.MILE.
 boolean isDisplayCircle()
           
 boolean isShowAngle()
           
 void listenerPaint(java.lang.Object source, java.awt.Graphics g)
          Called by the MapBean when it repaints, to let the MouseMode know when to update itself on the map.
 void mouseClicked(java.awt.event.MouseEvent e)
          Process a mouseClicked event.
 void mouseExited(java.awt.event.MouseEvent e)
          Process a mouseExited event.
 void mouseMoved(java.awt.event.MouseEvent e)
          Get the line and circle ready for the map repaint based on where the mouse is, distance and azimuth angle as the mouse moves.
 void mousePressed(java.awt.event.MouseEvent e)
          Process a mouse pressed event.
 void paintCircle(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2, java.awt.Graphics graphics)
          Draw a rubberband circle between two points
 void paintLine(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2, java.awt.Graphics graphics)
          Draw a rubberband line between two points into the Graphics object.
 void paintRubberband(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2, java.awt.Graphics g)
          Draw a rubberband line and circle between two points
 void setActive(boolean active)
          If the MouseMode has been made inactive, clean out any input that might have been made to the info line.
 void setDisplayCircle(boolean displayCircle)
           
 void setLineType(int lype)
          Set the line type to be drawn see also OMGraphic
protected  void setMapBean(MapBean aMap)
          Set the map bean.
 void setProperties(java.lang.String prefix, java.util.Properties setList)
          PropertyConsumer interface method.
 void setShowAngle(boolean showAngle)
           
 void setTotalDistance(double totalDistance)
           
 void setUnit(Length units)
          Set the unit of distance to be displayed: Length.NM, Length.KM or Length.MILE.
 void showAzimuth(boolean onOff)
          Switch the display of the azimuth angle on or off.
 void showCircle(boolean onOff)
          Set the drawing of the rubberband circle on/off.
 
Methods inherited from class com.bbn.openmap.event.CoordMouseMode
findAndInit, findAndUndo, fireMouseLocation, getCoordFormatter, getCoordFormatterHandler, getInfoDelegator, mouseDragged, propertyChange, setCoordFormatter, setCoordFormatterHandler, setInfoDelegator
 
Methods inherited from class com.bbn.openmap.event.AbstractMouseMode
actAsProxyFor, actAsProxyFor, addMapMouseListener, addPropertyChangeListener, getClassToUseForIconRetrieval, getGUIIcon, getIconName, getID, getModeCursor, getMouseSupport, getMouseWheelTimerInterval, getNoMouseWheelListener, getPrettyName, getProxied, getProxyDistributionMask, isConsumeEvents, isMouseWheelListener, isNoMouseWheelListenerTimer, isProxyFor, isVisible, isZoomWhenMouseWheelUp, mouseEntered, mouseReleased, mouseWheelMoved, releaseProxy, removeAllMapMouseListeners, removeMapMouseListener, removePropertyChangeListener, setConsumeEvents, setGUIIcon, setIconName, setID, setModeCursor, setModeCursor, setMouseSupport, setMouseWheelListener, setMouseWheelTimerInterval, setNoMouseWheelListener, setNoMouseWheelListenerTimer, setPrettyName, setProxyDistributionMask, setVisible, setZoomWhenMouseWheelUp, updateMouseWheelMoved
 
Methods inherited from class com.bbn.openmap.OMComponent
getPropertyPrefix, setProperties, setPropertyPrefix
 
Methods inherited from class com.bbn.openmap.MapHandlerChild
addPropertyChangeListener, addVetoableChangeListener, childrenAdded, childrenRemoved, findAndInit, firePropertyChange, fireVetoableChange, getBeanContext, isIsolated, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext, setIsolated
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modeID

public static final transient java.lang.String modeID
Mouse mode identifier, is "Distance". This is returned on getID()

See Also:
Constant Field Values

UnitProperty

public static final java.lang.String UnitProperty
See Also:
Constant Field Values

ShowCircleProperty

public static final java.lang.String ShowCircleProperty
See Also:
Constant Field Values

ShowAngleProperty

public static final java.lang.String ShowAngleProperty
See Also:
Constant Field Values

RepaintToCleanProperty

public static final java.lang.String RepaintToCleanProperty
See Also:
Constant Field Values

df

public transient java.text.DecimalFormat df

AllUnitsPropertyValue

public static final java.lang.String AllUnitsPropertyValue
Special units value for displaying all units ... use only in properties file

See Also:
Constant Field Values

rPoint1

protected java.awt.geom.Point2D rPoint1
rPoint1 is the anchor point of a line segment


rPoint2

protected java.awt.geom.Point2D rPoint2
rPoint2 is the new (current) point of a line segment


drawDistanceObjects

protected boolean drawDistanceObjects
Flag, true if the mouse has already been pressed


segments

protected java.util.Vector<java.awt.geom.Point2D> segments
Vector to store all distance segments, first point and last point pairs


distance

protected double distance
Distance of the current segment


totalDistance

protected double totalDistance
The cumulative distance from the first mouse click


renderAttributes

protected DrawingAttributes renderAttributes
Rendering attributes for lines and circles.

Constructor Detail

DistanceMouseMode

public DistanceMouseMode()
Construct a DistanceMouseMode. Default constructor. Sets the ID to the modeID, and the consume mode to true. You need to setInfoDelegator, setUnit and setLineType if you use this constructor.


DistanceMouseMode

public DistanceMouseMode(boolean consumeEvents)
Construct a DistanceMouseMode. Lets you set the consume mode. If the events are consumed, then a MouseEvent is sent only to the first MapMouseListener that successfully processes the event. If they are not consumed, then all of the listeners get a chance to act on the event. You need to setInfoDelegator, setUnit and setLineType if you use this constructor.

Parameters:
consumeEvents - the mode setting.

DistanceMouseMode

public DistanceMouseMode(java.lang.String name,
                         boolean consumeEvents)
Construct an DistanceMouseMode. For convenience for derived classes.

Parameters:
name - the ID of the mode.
consumeEvents - if true, events are propagated to the first MapMouseListener that successfully processes the event, if false, events are propagated to all MapMouseListeners. You need to setInfoDelegator, setUnit and setLineType if you use this constructor.

DistanceMouseMode

public DistanceMouseMode(boolean consumeEvents,
                         InformationDelegator id,
                         Length units)
Construct a DistanceMouseMode. Lets you set the consume mode. If the events are consumed, then a MouseEvent is sent only to the first MapMouseListener that successfully processes the event. If they are not consumed, then all of the listeners get a chance to act on the event. You need to the setLineType if you use this constructor.

Parameters:
consumeEvents - the mode setting.
id - the calling object's info delegator.
units - the unit of distance that will be displayed, such as Length.NM, Length.KM or Length.MILE. If null, display all of them.

DistanceMouseMode

public DistanceMouseMode(boolean consumeEvents,
                         InformationDelegator id,
                         Length units,
                         int lType)
Construct a DistanceMouseMode. Lets you set the consume mode. If the events are consumed, then a MouseEvent is sent only to the first MapMouseListener that successfully processes the event. If they are not consumed, then all of the listeners get a chance to act on the event. You need to the setLineType if you use this constructor.

Parameters:
consumeEvents - the mode setting.
id - the calling object's info delegator.
units - the unit of distance that will be displayed, such as Length.NM, Length.KM or Length.MILE. If null, display all of them.
lType - the line type that will be displayed such as LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT

DistanceMouseMode

public DistanceMouseMode(boolean consumeEvents,
                         InformationDelegator id)
Construct a DistanceMouseMode. Lets you set the consume mode. If the events are consumed, then a MouseEvent is sent only to the first MapMouseListener that successfully processes the event. If they are not consumed, then all of the listeners get a chance to act on the event.

Parameters:
consumeEvents - the mode setting.
id - the calling object's info delegator.

DistanceMouseMode

public DistanceMouseMode(java.lang.String name,
                         boolean consumeEvents,
                         InformationDelegator id)
Construct a DistanceMouseMode. For convenience for derived classes. Lets you set the consume mode. If the events are consumed, then a MouseEvent is sent only to the first MapMouseListener that successfully processes the event. If they are not consumed, then all of the listeners get a chance to act on the event.

Parameters:
name - the ID of the mode.
consumeEvents - the mode setting.
id - the calling object's info delegator.
Method Detail

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Process a mouseClicked event. Erase all drawn lines and circles upon a double mouse click

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Overrides:
mouseClicked in class AbstractMouseMode
Parameters:
e - mouse event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Process a mouse pressed event. Add the mouse location to the segment vector. Calculate the cumulative total distance.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class AbstractMouseMode
Parameters:
e - mouse event.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Get the line and circle ready for the map repaint based on where the mouse is, distance and azimuth angle as the mouse moves. Display distance and azimuth angle in on the infoDelegator.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class CoordMouseMode
Parameters:
e - mouse event.

createDistanceInformationLine

protected java.lang.String createDistanceInformationLine(java.awt.geom.Point2D llp,
                                                         double distance,
                                                         double azimuth)
Create the contents of the information line, based on user inputs.

Parameters:
llp - current lat/lon of the mouse
distance - current distance in radians
azimuth - direction of last line
Returns:
String to put in information line.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Process a mouseExited event. If a line is being drawn (and mouse go off the map), it will be erased. The anchor point rPoint1 is kept in case the mouse comes back on the screen. Then, a new line will be drawn with the original mouse press position.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class AbstractMouseMode
Parameters:
e - mouse event.

setActive

public void setActive(boolean active)
Description copied from class: CoordMouseMode
If the MouseMode has been made inactive, clean out any input that might have been made to the info line.

Specified by:
setActive in interface MapMouseMode
Overrides:
setActive in class CoordMouseMode
Parameters:
active - true if the mode has been made active, false if it has been made inactive.

listenerPaint

public void listenerPaint(java.lang.Object source,
                          java.awt.Graphics g)
Called by the MapBean when it repaints, to let the MouseMode know when to update itself on the map. PaintListener interface.

Specified by:
listenerPaint in interface PaintListener
Overrides:
listenerPaint in class AbstractMouseMode
Parameters:
source - the source object, may be null, you need to check.
g - the graphics to paint into.

paintLine

public void paintLine(java.awt.geom.Point2D pt1,
                      java.awt.geom.Point2D pt2,
                      java.awt.Graphics graphics)
Draw a rubberband line between two points into the Graphics object.

Parameters:
pt1 - the anchor point.
pt2 - the current (mouse) position.
graphics - a java.awt.Graphics object to render into.

paintCircle

public void paintCircle(java.awt.geom.Point2D pt1,
                        java.awt.geom.Point2D pt2,
                        java.awt.Graphics graphics)
Draw a rubberband circle between two points

Parameters:
pt1 - the anchor point.
pt2 - the current (mouse) position.
graphics - a java.awt.Graphics object to render into.

paintRubberband

public void paintRubberband(java.awt.geom.Point2D pt1,
                            java.awt.geom.Point2D pt2,
                            java.awt.Graphics g)
Draw a rubberband line and circle between two points

Parameters:
pt1 - the anchor point.
pt2 - the current (mouse) position.
g - a java.awt.Graphics object to render into.

cleanUp

public void cleanUp()
Reset the segments and distances


getGreatCircleDist

public double getGreatCircleDist(double phi1,
                                 double lambda0,
                                 double phi,
                                 double lambda,
                                 int units)
Return the distance in the chosen unit between two points (in decimal degrees). Based on spherical arc distance between two points. See class GreatCircle.java

Parameters:
phi1 - latitude in decimal degrees of start point
lambda0 - longitude in decimal degrees of start point
phi - latitude in decimal degrees of end point
lambda - longitude in decimal degrees of end point
units - the unit of distance, DISTANCE_NM, DISTANCE_KM, DISTANCE_MILE or all 3 types DISTANCE_ALL
Returns:
double distance in chosen unit

getSphericalAzimuth

public double getSphericalAzimuth(double phi1,
                                  double lambda0,
                                  double phi,
                                  double lambda)
Return the azimuth angle in decimal degrees from north. Based on spherical_azimuth. See class GreatCircle.java

Parameters:
phi1 - latitude in decimal degrees of start point
lambda0 - longitude in decimal degrees of start point
phi - latitude in decimal degrees of end point
lambda - longitude in decimal degrees of end point
Returns:
float azimuth angle in degrees

setMapBean

protected void setMapBean(MapBean aMap)
Set the map bean.

Parameters:
aMap - a map bean

getMapBean

protected MapBean getMapBean()
Return the map bean.


setUnit

public void setUnit(Length units)
Set the unit of distance to be displayed: Length.NM, Length.KM or Length.MILE. If null, displays all of them.


getUnit

public Length getUnit()
Return the unit of distance being displayed: Length.NM, Length.KM or Length.MILE. If null, displays all of them.


showAzimuth

public void showAzimuth(boolean onOff)
Switch the display of the azimuth angle on or off.

Parameters:
onOff - true to display the azimuth angle, false to turn off

getShowAzimuth

public boolean getShowAzimuth()
Whether the display of the azimuth angle on or off.


setLineType

public void setLineType(int lype)
Set the line type to be drawn see also OMGraphic

Parameters:
lype - either LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT

getLineType

public int getLineType()
Return the line type either LINETYPE_GREATCIRCLE, LINETYPE_RHUMB, LINETYPE_STRAIGHT


showCircle

public void showCircle(boolean onOff)
Set the drawing of the rubberband circle on/off.

Parameters:
onOff - true or false

getShowCircle

public boolean getShowCircle()
Get whether the drawing of the rubberband circle on/off.


isDisplayCircle

public boolean isDisplayCircle()

setDisplayCircle

public void setDisplayCircle(boolean displayCircle)

isShowAngle

public boolean isShowAngle()

setShowAngle

public void setShowAngle(boolean showAngle)

getTotalDistance

public double getTotalDistance()

setTotalDistance

public void setTotalDistance(double totalDistance)

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties setList)
PropertyConsumer interface method.

Specified by:
setProperties in interface PropertyConsumer
Overrides:
setProperties in class CoordMouseMode
Parameters:
prefix - the token to prefix the property names
setList - the Properties object

getProperties

public java.util.Properties getProperties(java.util.Properties getList)
PropertyConsumer interface method.

Specified by:
getProperties in interface PropertyConsumer
Overrides:
getProperties in class CoordMouseMode
Parameters:
getList - a Properties object to load the PropertyConsumer properties into. If props equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

getPropertyInfo

public java.util.Properties getPropertyInfo(java.util.Properties list)
PropertyConsumer interface method.

Specified by:
getPropertyInfo in interface PropertyConsumer
Overrides:
getPropertyInfo in class CoordMouseMode
Parameters:
list - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details