public class TLcdMapTouchRulerController extends ALcdGXYChainableController implements ILcdAWTEventListener
This ILcdGXYController
serves the purpose of performing
measurements on an ILcdGXYView
. It interacts with a touch device.
A measurement is defined by succeeding touches on the map. The way the measurement is ended depends on the implementation of the used new controller. The measurement is displayed as a polyline having a distance label on every segment and a total distance label. Optionally, the azimuth of every segment can be displayed as well.
All style related settings can be changed using simple set methods. If more advanced customization of the visualization is required, the painters, editors and label painters can be replaced by overriding the factory methods that create them. Formatting of distance and azimuth can be modified by setting a different distance or azimuth format.
Several measure modes are available: geodetic, rhumbline and projection plane. Please refer
to setMeasureMode
for more details.
Events can be received whenever the measurement is changed. This can be used
to display the measurement values in a panel for instance. Please refer to
addMeasurementChangeListener
for more details.
This controller only tries to handle TLcdTouchPoint
s which are not-consumed, and marks the
TLcdTouchPoint
s it uses as consumed, similar to the ALcdGXYTouchChainableController
.
Modifier and Type | Class and Description |
---|---|
static class |
TLcdMapTouchRulerController.MeasureMode |
Modifier and Type | Field and Description |
---|---|
static String |
RULER_MODEL_TYPE_NAME
Returns the type name of the ruler model created by this controller.
|
Constructor and Description |
---|
TLcdMapTouchRulerController(TLcdGXYTouchNewController aNewController,
TLcdGXYTouchSelectEditController aEditController)
Create a new ruler controller.
|
Modifier and Type | Method and Description |
---|---|
void |
addMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
Adds the given
MeasurementChangeListener . |
void |
addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Add the given
PropertyChangeListener . |
protected double |
calculateAzimuth(ILcdPoint aPoint1,
ILcdPoint aPoint2,
ILcdGeoReference aGeoReference,
int aMeasureMode,
ILcdGXYContext aGXYContext)
Calculates the azimuth in degrees between the two given points.
|
protected double |
calculateDistance(ILcdPoint aPoint1,
ILcdPoint aPoint2,
ILcdGeoReference aGeoReference,
int aMeasureMode,
ILcdGXYContext aGXYContext)
Calculates the distance in meters between the two given points.
|
protected ILcdGXYPainter |
createGXYEqualDistanceCurvePainter()
Creates the painter of the equal distance curve for the polylines used to measure the distances.
|
protected ILcdGXYLabelPainter |
createGXYLabelPainter()
Creates the label painter for the distance labels (or maybe angle labels,
etc).
|
protected TLcdGXYLayer |
createGXYLayer()
Create a new layer used for storing the measurements.
|
protected ILcdGXYLayerLabelPainter |
createGXYLayerLabelPainter()
Creates the
ILcdGXYLayerLabelPainter for the ruler controller. |
protected ILcdGXYEditor |
createGXYPolylineEditor()
Creates the editor for the polylines used to measure the distances.
|
protected ILcdGXYPainter |
createGXYPolylinePainter()
Creates the painter for the polylines used to measure the distances.
|
protected void |
firePropertyChange(PropertyChangeEvent aEvent)
Notifies all property change listeners that the value of a property has changed.
|
Format |
getAzimuthFormat()
Returns the format used to format azimuths and display them to the user.
|
Format |
getDistanceFormat()
Returns the distance format used to format distances and display them to the user.
|
ILcdGXYLayer |
getGXYLayer()
Returns the ILcdGXYLayer containing the measurements.
|
Color |
getHaloColor()
Returns the color of the halo to be added around measurement lines.
|
int |
getHaloThickness()
Returns the thickness (in pixels) of the halo to be added around measurement lines.
|
ILcdIcon |
getHotPointIcon()
Returns the hot point icon, it can be
null . |
int |
getLabelAlignment()
Returns the label alignment.
|
Color |
getLabelBackground()
Returns the background color of the labels.
|
Color |
getLabelForeground()
Returns the foreground color of the labels.
|
Color |
getLabelSelectionColor()
Returns the selection color of the labels.
|
int |
getLabelVGap()
Returns the orthogonal distance (in pixels) between the label and the line segment.
|
ILcdLayered |
getLayered()
Returns the layers associated with this controller.
|
ILcdGXYPainterStyle |
getLineStyle()
Returns the style to paint lines.
|
TLcdMapTouchRulerController.MeasureMode |
getMeasureMode()
Returns the current measuring mode.
|
Font |
getSegmentLabelFont()
Returns the font of the segment distance labels (and possibly azimuth, if
isDisplayAzimuth() is true). |
ILcdGXYLayerSubsetList |
getSnappables()
Returns the snappables used by this controller.
|
Font |
getTotalDistanceLabelFont()
Returns the font of the total distance label.
|
void |
handleAWTEvent(AWTEvent aEvent)
This is method is called when the target of the listener has a new AWTEvent available.
|
boolean |
isAddGXYLayerToGXYView()
Checks if the layer containing measurements should be added to the view.
|
boolean |
isAllowMultipleMeasurements()
Checks if multiple measurements are allowed at the same time.
|
boolean |
isDisplayAzimuth()
Returns true if the azimuth is displayed on the map.
|
boolean |
isDrawEqualDistanceCurve()
Returns true if the equal distance curve(s) are drawn, false otherwise.
|
boolean |
isHaloEnabled()
Returns if the halo effect on the measurement lines is enabled.
|
boolean |
isLabelFilled()
Returns true if a filled rectangle should be painted behind the labels.
|
boolean |
isLabelFontBorder()
Returns true if a border is painted around the label text in the background color.
|
boolean |
isLabelFrame()
Returns true if the labels are surrounded by a frame, false otherwise.
|
boolean |
isLabelRotationAllowed()
Returns true if the labels can be rotated along the polyline, false otherwise.
|
boolean |
isPreserveMeasurement()
Returns true if the measurement is preserved when the controller is terminated and
started again.
|
boolean |
isRemoveGXYLayerFromGXYView()
Checks if the layer containing measurements should be removed from the view after terminating
the controller interaction.
|
protected void |
paintImpl(Graphics aGraphics)
The specific implementation of
paint for this controller. |
protected void |
recalculateMeasureMents()
Invalidates the calculations.
|
void |
removeMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
Removes the given
MeasurementChangeListener . |
void |
removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Removes the given
PropertyChangeListener . |
void |
setAddGXYLayerToGXYView(boolean aAddGXYLayerToGXYView)
When set to true, the layer containing measurements is added to the view.
|
void |
setAllowMultipleMeasurements(boolean aAllowMultipleMeasurements)
When set to true, multiple measurements are allowed at the same time.
|
void |
setAzimuthFormat(Format aAzimuthFormat)
Sets the azimuth format to be used to format azimuths and display them to the user.
|
void |
setDisplayAzimuth(boolean aDisplayAzimuth)
Set to true if the azimuth must be displayed as a label on the map.
|
void |
setDistanceFormat(Format aDistanceFormat)
Sets the distance format to use to format distances to be displayed to the user.
|
void |
setDrawEqualDistanceCurve(boolean aDrawEqualDistanceCurve)
Sets if the equal distance curve(s) are drawn or not.
|
void |
setHaloColor(Color aHaloColor)
Sets the color of the halo to be added around measurement lines.
|
void |
setHaloEnabled(boolean aHaloEnabled)
Enables or disables the halo effect on the measurement lines.
|
void |
setHaloThickness(int aHaloThickness)
Sets the thickness (in pixels) of the halo to be added around measurement lines.
|
void |
setHotPointIcon(ILcdIcon aHotPointIcon)
Sets the hot point icon, used to paint the handles on the measurement line.
|
void |
setLabelAlignment(int aLabelAlignment)
Sets the label alignment.
|
void |
setLabelBackground(Color aLabelBackground)
Sets the background color of the labels.
|
void |
setLabelFilled(boolean aLabelFilled)
Sets if a filled rectangle should be painted behind the labels.
|
void |
setLabelFontBorder(boolean aLabelFontBorder)
Sets if the painted text should be bordered with the background color.
|
void |
setLabelForeground(Color aLabelForeground)
Sets the foreground color of the labels.
|
void |
setLabelFrame(boolean aLabelFrame)
Labels can be drawn surrounded by a frame, the frame property determines
whether to frame the labels or not.
|
void |
setLabelRotationAllowed(boolean aLabelRotationAllowed)
Labels can be rotated so that they have the same angle as the polyline.
|
void |
setLabelSelectionColor(Color aLabelSelectionColor)
Sets the selection color of the labels.
|
void |
setLabelVGap(int aVerticalGap)
Sets the orthogonal distance (in pixels) between the label and the line segment.
|
void |
setLineStyle(ILcdGXYPainterStyle aLineStyle)
Sets the style to use to paint lines.
|
void |
setMeasureMode(TLcdMapTouchRulerController.MeasureMode aMeasureMode)
Sets the current measuring mode.
|
void |
setPreserveMeasurement(boolean aPreserveMeasurement)
Set to true to preserve the measurement between succeeding calls to
ALcdGXYChainableController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
and ALcdGXYChainableController.terminateInteraction(com.luciad.view.gxy.ILcdGXYView) . |
void |
setRemoveGXYLayerFromGXYView(boolean aRemoveGXYLayerFromGXYView)
When set to true, the layer containing measurements is removed from the view after terminating
the controller interaction.
|
void |
setSegmentLabelFont(Font aSegmentLabelFont)
Sets the font of the segment distance labels (and possibly azimuth, if
isDisplayAzimuth() is true) to the given font. |
void |
setSnappables(ILcdGXYLayerSubsetList aSnappables)
Sets the new snappables for this controller, default is null.
|
void |
setTotalDistanceLabelFont(Font aTotalDistanceLabelFont)
Sets the font of the total distance label.
|
protected void |
startInteractionImpl(ILcdGXYView aGXYView)
The specific implementation of
startInteraction for this controller. |
protected void |
terminateInteractionImpl(ILcdGXYView aGXYView)
The specific implementation of
terminateInteraction for this controller. |
addStatusListener, appendGXYController, getNextGXYController, paint, removeStatusListener, setNextGXYController, startInteraction, terminateInteraction
asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, isTraceOn, registerInstance, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setCursor, setGXYView, setIcon, setName, setShortDescription, setTraceOn, viewRepaint
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCursor, getIcon, getName, getShortDescription, viewRepaint
public static final String RULER_MODEL_TYPE_NAME
public TLcdMapTouchRulerController(TLcdGXYTouchNewController aNewController, TLcdGXYTouchSelectEditController aEditController)
aNewController
- The controller responsible for the creation of new objectsaEditController
- The controller responsible for editing existing objectspublic void handleAWTEvent(AWTEvent aEvent)
ILcdAWTEventListener
handleAWTEvent
in interface ILcdAWTEventListener
aEvent
- The event to be handled.protected void startInteractionImpl(ILcdGXYView aGXYView)
ALcdGXYChainableController
startInteraction
for this controller.startInteractionImpl
in class ALcdGXYChainableController
aGXYView
- the view to start interaction with.protected void terminateInteractionImpl(ILcdGXYView aGXYView)
ALcdGXYChainableController
terminateInteraction
for this controller.terminateInteractionImpl
in class ALcdGXYChainableController
aGXYView
- the view to terminate interaction with.protected void paintImpl(Graphics aGraphics)
ALcdGXYChainableController
paint
for this controller.paintImpl
in class ALcdGXYChainableController
aGraphics
- the graphics to be used for painting.public ILcdLayered getLayered()
ILcdGXYController
Custom implementations of this method should take care to return the same ILcdLayered
instance every time this method is called to guarantee correct working of the ILcdLayered
interface.
getLayered
in interface ILcdGXYController
public void addMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
MeasurementChangeListener
. This allows to receive updates
whenever the measurement is changed.aListener
- The listener to add.removeMeasurementChangeListener(com.luciad.view.map.TLcdAdvancedMapRulerController.MeasurementChangeListener)
public void removeMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
MeasurementChangeListener
. Does nothing if the
listener was never added or already removed.aListener
- The listener to remove.addMeasurementChangeListener(com.luciad.view.map.TLcdAdvancedMapRulerController.MeasurementChangeListener)
public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
PropertyChangeListener
.aPropertyChangeListener
- The listener to be added.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
PropertyChangeListener
. Does nothing if the
listener was never added (or already removed).aPropertyChangeListener
- The listener to remove.addPropertyChangeListener(java.beans.PropertyChangeListener)
protected void firePropertyChange(PropertyChangeEvent aEvent)
aEvent
- the event describing the property that has changedpublic TLcdMapTouchRulerController.MeasureMode getMeasureMode()
setMeasureMode(com.luciad.view.gxy.controller.touch.TLcdMapTouchRulerController.MeasureMode)
public void setMeasureMode(TLcdMapTouchRulerController.MeasureMode aMeasureMode)
aMeasureMode
- The measuring mode. One of
getMeasureMode()
public ILcdGXYLayerSubsetList getSnappables()
setSnappables(com.luciad.view.gxy.ILcdGXYLayerSubsetList)
public void setSnappables(ILcdGXYLayerSubsetList aSnappables)
aSnappables
- The new list of snappables for this controllergetSnappables()
public Format getAzimuthFormat()
setAzimuthFormat(java.text.Format)
public void setAzimuthFormat(Format aAzimuthFormat)
aAzimuthFormat
- The new azimuth format.getAzimuthFormat()
public boolean isDrawEqualDistanceCurve()
setDrawEqualDistanceCurve(boolean)
public void setDrawEqualDistanceCurve(boolean aDrawEqualDistanceCurve)
aDrawEqualDistanceCurve
- True to draw the curves, false otherwise.public void setLineStyle(ILcdGXYPainterStyle aLineStyle)
aLineStyle
- the new line style to set.getLineStyle()
public ILcdGXYPainterStyle getLineStyle()
setLineStyle(com.luciad.view.gxy.ILcdGXYPainterStyle)
public boolean isDisplayAzimuth()
setDisplayAzimuth(boolean)
public void setDisplayAzimuth(boolean aDisplayAzimuth)
Set to true if the azimuth must be displayed as a label on the map. Default is false.
When set to true
, an arrow is also added to the middle of every line segment.
isDisplayAzimuth()
public void setHaloEnabled(boolean aHaloEnabled)
aHaloEnabled
- true if halos should be added, false otherwiseisHaloEnabled()
public boolean isHaloEnabled()
setHaloEnabled(boolean)
public void setHaloThickness(int aHaloThickness)
aHaloThickness
- the thickness (in pixels) of the halo to be added around measurement lines.getHaloThickness()
public int getHaloThickness()
setHaloThickness(int)
public void setHaloColor(Color aHaloColor)
aHaloColor
- the color of the halo to be added around measurement lines.getHaloColor()
public Color getHaloColor()
setHaloColor(Color)
public boolean isPreserveMeasurement()
setPreserveMeasurement(boolean)
.public void setPreserveMeasurement(boolean aPreserveMeasurement)
ALcdGXYChainableController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
and ALcdGXYChainableController.terminateInteraction(com.luciad.view.gxy.ILcdGXYView)
. If set to false, the previous measurement is removed every
time the controller is started.aPreserveMeasurement
- True to preserve measurements, false otherwise.public ILcdGXYLayer getGXYLayer()
If the preserve measurement is set to false, the contents of the layer are cleared when terminating the interaction with the controller. If it is set ot true, the measurements are kept.
If the allow multiple measurements flag is set ot true, the layer contains at most one measurement. If not, it can contain any number of measurements.
setAllowMultipleMeasurements(boolean)
,
setPreserveMeasurement(boolean)
public void setAllowMultipleMeasurements(boolean aAllowMultipleMeasurements)
Multiple measurements only works when using a TLcdGXYNewController2. If not, creating a new measurement can be interrupted when touching an other measurement.
In order to have control over the removal of measurements, the measurement layer can be used,
getGXYLayer()
can be used.
aAllowMultipleMeasurements
- true to allow multiple measurements at the same time.public boolean isAllowMultipleMeasurements()
setAllowMultipleMeasurements(boolean)
public void setAddGXYLayerToGXYView(boolean aAddGXYLayerToGXYView)
The layer will only display its contents after terminating interaction with the view when the preserve measurements property is enabled, and when the remove measurement layer setting is disabled.
aAddGXYLayerToGXYView
- true if the measurement layer should be added to the view,
and false otherwise.setPreserveMeasurement(boolean)
,
setRemoveGXYLayerFromGXYView(boolean)
public boolean isAddGXYLayerToGXYView()
setAddGXYLayerToGXYView(boolean)
public void setRemoveGXYLayerFromGXYView(boolean aRemoveGXYLayerFromGXYView)
aRemoveGXYLayerFromGXYView
- true if the measurement layer should be removed from the view,
and false otherwise.setAddGXYLayerToGXYView(boolean)
public boolean isRemoveGXYLayerFromGXYView()
(boolean)
public void setLabelAlignment(int aLabelAlignment)
aLabelAlignment
- The alignment of the label. One of
TLcdGXYPolylineLabelPainter.ABOVE
,
TLcdGXYPolylineLabelPainter.CENTER
,
TLcdGXYPolylineLabelPainter.BELOW
getLabelAlignment()
public int getLabelAlignment()
TLcdGXYPolylineLabelPainter.ABOVE
,
TLcdGXYPolylineLabelPainter.CENTER
,
TLcdGXYPolylineLabelPainter.BELOW
.setLabelAlignment(int)
public void setTotalDistanceLabelFont(Font aTotalDistanceLabelFont)
aTotalDistanceLabelFont
- The font.getTotalDistanceLabelFont()
public Font getTotalDistanceLabelFont()
setTotalDistanceLabelFont(java.awt.Font)
public void setSegmentLabelFont(Font aSegmentLabelFont)
isDisplayAzimuth()
is true) to the given font.aSegmentLabelFont
- The new font.getSegmentLabelFont()
public Font getSegmentLabelFont()
isDisplayAzimuth()
is true).setSegmentLabelFont(java.awt.Font)
public boolean isLabelFontBorder()
setLabelFontBorder(boolean)
public void setLabelFontBorder(boolean aLabelFontBorder)
aLabelFontBorder
- True if text should be bordered, false otherwise.isLabelFontBorder()
public void setLabelForeground(Color aLabelForeground)
aLabelForeground
- The foreground color of the labels.getLabelForeground()
public Color getLabelForeground()
setLabelForeground(java.awt.Color)
public void setLabelBackground(Color aLabelBackground)
isLabelFilled()
returns true, or to paint
a border around the text when isLabelFontBorder()
returns true.aLabelBackground
- The background color of the labels.getLabelBackground()
public Color getLabelBackground()
setLabelBackground(java.awt.Color)
public void setLabelSelectionColor(Color aLabelSelectionColor)
aLabelSelectionColor
- The label selection color.getLabelSelectionColor()
public Color getLabelSelectionColor()
setLabelSelectionColor(java.awt.Color)
public void setLabelFrame(boolean aLabelFrame)
aLabelFrame
- True if the labels should be surrounded by a frame,
false otherwise.isLabelFrame()
public boolean isLabelFrame()
setLabelFrame(boolean)
public void setLabelRotationAllowed(boolean aLabelRotationAllowed)
aLabelRotationAllowed
- True if the labels can be rotated, false otherwise.isLabelRotationAllowed()
public boolean isLabelRotationAllowed()
setLabelRotationAllowed(boolean)
public void setLabelFilled(boolean aLabelFilled)
getLabelBackground()
color.aLabelFilled
- True if a filled rectangle is painted behind the
labels, false otherwise.isLabelFilled()
public boolean isLabelFilled()
setLabelFilled(boolean)
public void setLabelVGap(int aVerticalGap)
aVerticalGap
- The orthogonal distance (in pixels) between the label and the line segment.getLabelVGap()
public int getLabelVGap()
setLabelVGap(int)
public Format getDistanceFormat()
setDistanceFormat(java.text.Format)
public void setDistanceFormat(Format aDistanceFormat)
aDistanceFormat
- The new distance formatgetDistanceFormat()
public ILcdIcon getHotPointIcon()
null
.null
.setHotPointIcon(com.luciad.gui.ILcdIcon)
public void setHotPointIcon(ILcdIcon aHotPointIcon)
aHotPointIcon
- The hot point icon, or null
for a default icon.ALcdGXYPen.setHotPointIcon(com.luciad.gui.ILcdIcon)
,
getHotPointIcon()
protected TLcdGXYLayer createGXYLayer()
The default implementation returns a new TLcdGXYLayer.
protected void recalculateMeasureMents()
protected ILcdGXYPainter createGXYPolylinePainter()
ILcd3DEditablePolyline
.
The properties of the returned painter must be synchronized with the
properties of this controller. For example, if the lineStyle of this controller is
changed, the returned painter must respect this change. This can easily
be achieved by adding a property change listener to this controller that
synchronizes the properties of this controller and the painter.
If you override this method, make sure that the painter also implements ILcdGXYEditor,
or override createGXYPolylineEditor()
as well.ILcd3DEditablePolyline
objects.protected ILcdGXYEditor createGXYPolylineEditor()
ILcd3DEditablePolyline
.
The properties of the returned editor must be synchronized with the
properties of this controller. For example, if the lineStyle of this controller is
changed, the returned editor must respect this change. This can easily
be achieved by adding a property change listener to this controller that
synchronizes the properties of this controller and the painter.
The default implementation of this method calls createGXYPolylinePainter()
and casts it to ILcdGXYEditor
.ILcd3DEditablePolyline
objects.protected ILcdGXYPainter createGXYEqualDistanceCurvePainter()
ILcd3DEditablePolyline
, and draw the equal distance
curve when the polyline is modified.
The properties of the returned painter must be synchronized with the
properties of this controller. For example, if the lineStyle of this controller is
changed, the returned painter must respect this change. This can easily
be achieved by adding a property change listener to this controller that
synchronizes the properties of this controller and the painter.ILcd3DEditablePolyline
objects and paints the equal distance curve
when the polyline is modified.protected ILcdGXYLabelPainter createGXYLabelPainter()
ILcdGXYMultiLabelPainter
to put
multiple labels on the one polyline.
This label painter must accept objects of type
ILcd3DEditablePolyline
. This object implements both
ILcdDataObject
and
ILcdFeatured
. The object has the following three properties (features):
Double
Vector
of Double
s) containing
the distance in meters for every segmentILcdGXYLabelPainter
responsible to paint the distance labels etc.protected ILcdGXYLayerLabelPainter createGXYLayerLabelPainter()
ILcdGXYLayerLabelPainter
for the ruler controller. This painter
is used to position the different labels, so it contains the label decluttering logic.ILcdGXYLayerLabelPainter
responsible to position the labels.protected double calculateDistance(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdGeoReference aGeoReference, int aMeasureMode, ILcdGXYContext aGXYContext)
aPoint1
- The first point.aPoint2
- The second point.aGeoReference
- The geo reference of the points.aMeasureMode
- The measure mode: one of GEODETIC,
RHUMBLINE or PROJECTION_PLANEaGXYContext
- The context.Double.NaN == Double.NaN
always returns false
,
one must use Double.isNaN( double )
.protected double calculateAzimuth(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdGeoReference aGeoReference, int aMeasureMode, ILcdGXYContext aGXYContext)
aPoint1
- The first point.aPoint2
- The second point.aGeoReference
- The geo reference of the points.aMeasureMode
- The measure mode: one of GEODETIC,
RHUMBLINE or PROJECTION_PLANEaGXYContext
- The context.Double.NaN == Double.NaN
always returns false
,
one must use Double.isNaN( double )
.