public class TLspRulerController extends ALspController implements ILcdUndoableSource
A controller that allows to measure distances on the map.
The measurement information is displayed on a label with the polyline as illustrated in the figure above.
The polylines can be edited after creation.
As such, TLspRulerController
is very similar to the TLspCreateController
and TLspEditController
.
The created polylines are instances of ALspRulerMeasurement
.
The ruler measurement class exposes the distances (in meters) and azimuths (in degrees) calculated by the ruler controller.
You can access the last measurement in the controller itself.
You can also register a change listener to be notified when the current polyline changes.
It is possible to customize various aspects of this controller:
setLineStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
.setCircleStyler(com.luciad.view.lightspeed.style.styler.ILspCustomizableStyler)
and setDisplayEqualDistanceCircles(boolean)
.setLabelStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
, passing a
TLspRulerLabelStyler
.setHandleStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
and setFocusHandleStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
setMeasureMode(com.luciad.view.lightspeed.controller.ruler.TLspRulerController.MeasureMode)
setKeepLayer(boolean)
and
setKeepMeasurements(boolean)
.calculateAzimuth(com.luciad.shape.ILcdPoint, com.luciad.shape.ILcdPoint, com.luciad.model.ILcdModelReference, com.luciad.view.lightspeed.controller.ruler.TLspRulerController.MeasureMode)
or calculateDistance(com.luciad.shape.ILcdPoint, com.luciad.shape.ILcdPoint, com.luciad.model.ILcdModelReference, com.luciad.view.lightspeed.controller.ruler.TLspRulerController.MeasureMode)
methods.The handleFXEvent(Event aEvent) converts the native JavaFX TouchEvent
to a TLcdTouchEvent
and passes it to the ALspController.handleAWTEvent(AWTEvent aEvent).
snappable layers
.Modifier and Type | Class and Description |
---|---|
static class |
TLspRulerController.MeasureMode
Enumeration that describes how the distances and azimuths are calculated.
|
Constructor and Description |
---|
TLspRulerController()
Creates a new ruler controller.
|
TLspRulerController(boolean aAddLayerToView)
Creates a new ruler controller.
|
TLspRulerController(boolean aAddLayerToView,
ALspCreateControllerModel aCreateControllerModel)
Creates a new ruler controller with the given
ALspCreateControllerModel . |
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(ILcdChangeListener aListener)
Adds a change listener.
|
void |
addUndoableListener(ILcdUndoableListener aUndoableListener)
Adds a listener to this source, so this listener is notified when something undoable has
happened.
|
protected double |
calculateAzimuth(ILcdPoint aPoint1,
ILcdPoint aPoint2,
ILcdModelReference aReference,
TLspRulerController.MeasureMode aMeasureMode)
This method is called to calculate the azimuth for a segment of a ruler
measurement.
|
protected double |
calculateDistance(ILcdPoint aPoint1,
ILcdPoint aPoint2,
ILcdModelReference aReference,
TLspRulerController.MeasureMode aMeasureMode)
This method is called to calculate the distance of a segment of a ruler
measurement.
|
void |
cancel()
Cancels the creation of the ruler polyline.
|
void |
finish()
Finish the creation of the ruler polyline.
|
ILspCustomizableStyler |
getCircleStyler()
Returns the customizable styler currently used to determine the style of equal distance circles.
|
ALspRulerMeasurement |
getCurrentMeasurement()
Returns the current measurement.
|
Cursor |
getCursor()
Returns the mouse cursor for this controller.
|
ILspStyler |
getFocusHandleStyler()
Returns the styler for focused editing handles.
|
ILspStyler |
getHandleStyler()
Returns the styler for editing handles.
|
ILspStyler |
getLabelStyler()
Returns the styler for distance and azimuth labels of ruler measurements that are being
edited or created.
|
ILspStyler |
getLabelStyler(TLspPaintState aPaintState)
Returns the styler for distance and azimuth labels of ruler measurements for measurements in the given paintstate.
|
ILcdLayered |
getLayered()
Returns an
ILcdLayered for this controller. |
ILspStyler |
getLineStyler()
Returns the styler for ruler polylines that are being edited or created.
|
TLspRulerController.MeasureMode |
getMeasureMode()
Returns the current measurement mode.
|
ILcdStringTranslator |
getStringTranslator()
Returns the
ILcdStringTranslator set on this controller. |
AWTEvent |
handleAWTEventImpl(AWTEvent aAWTEvent)
Called by
handleAWTEvent . |
void |
handleFXEvent(javafx.event.Event aEvent)
Delegates to
handleFXEventImpl . |
javafx.event.Event |
handleFXEventImpl(javafx.event.Event aEvent)
Called by
handleFXEvent . |
boolean |
isAddLayerToView()
Returns true if a layer containing the measurements is added to the view (and as such visible in
the layer tree).
|
boolean |
isCreating()
Returns whether or not the ruler controller is currently creating or editing.
|
boolean |
isDisplayAzimuth()
Returns whether or not azimuths are displayed for each segment.
|
boolean |
isDisplayEqualDistanceCircles()
Returns true if equal distance circles are displayed for polyline nodes that are moved.
|
boolean |
isKeepLayer()
Returns true if the layer is kept after the interaction with the ruler controller is terminated.
|
boolean |
isKeepMeasurements()
Returns true if measurements are kept after a new measurement is started.
|
TLspPaintProgress |
paintImpl(ILcdGLDrawable aGLDrawable,
ILspView aView,
TLspPaintPhase aPaintPhase)
The specific implementation of
paint for this controller. |
void |
removeChangeListener(ILcdChangeListener aListener)
Removes a change listener if it is present.
|
void |
removeUndoableListener(ILcdUndoableListener aUndoableListener)
Removes the specified listener so it is no longer notified.
|
void |
setCircleStyler(ILspCustomizableStyler aCircleStyler)
Sets the customizable styler currently used to paint equal distance circles.
|
void |
setDisplayAzimuth(boolean aDisplayAzimuth)
Sets whether or not azimuths are displayed for each segment.
|
void |
setDisplayEqualDistanceCircles(boolean aDisplayEqualDistanceCircles)
Sets whether or not equal distance circles are displayed for polyline nodes that are moved.
|
void |
setFocusHandleStyler(ILspStyler aFocusHandleStyler)
Sets the styler for focused editing handles.
|
void |
setHandleStyler(ILspStyler aHandleStyler)
Sets the styler for editing handles.
|
void |
setKeepLayer(boolean aKeepLayer)
Set to true if the layer is to be kept after the interaction with the ruler controller is terminated.
|
void |
setKeepMeasurements(boolean aKeepMeasurements)
Set to true is measurements should be kept after a new measurement is started.
|
void |
setLabelStyler(ILspStyler aLabelStyler)
Sets the styler for distance and azimuth labels, for all supported paint states.
|
void |
setLabelStyler(TLspPaintState aState,
ILspStyler aLabelStyler)
Sets the styler for distance and azimuth labels, for the given paint state.
|
void |
setLineStyler(ILspStyler aLineStyler)
Sets the styler for the ruler polylines, for all supported paint states.
|
void |
setLineStyler(TLspPaintState aPaintState,
ILspStyler aLineStyler)
Sets the styler for the ruler polylines for the given paint state.
|
void |
setMeasureMode(TLspRulerController.MeasureMode aMeasureMode)
Sets the measurement mode.
|
void |
setStringTranslator(ILcdStringTranslator aStringTranslator)
Sets the
ILcdStringTranslator that this controller should use to
translate the Strings that will be visible in the user interface. |
void |
startInteractionImpl(ILspView aView)
The specific implementation of
startInteraction for this controller. |
void |
terminateInteractionImpl(ILspView aView)
The specific implementation of
terminateInteraction for this controller. |
addPropertyChangeListener, addStatusListener, appendController, firePropertyChange, fireStatusEvent, getAWTFilter, getFXCursor, getFXFilter, getIcon, getName, getNextController, getShortDescription, getView, handleAWTEvent, paint, registerViewPropertyNameForReset, removePropertyChangeListener, removeStatusListener, setAWTFilter, setCursor, setFXCursor, setFXFilter, setIcon, setName, setShortDescription, startInteraction, terminateInteraction
public TLspRulerController()
new TLspRulerController(false, null)
.public TLspRulerController(boolean aAddLayerToView)
layered
of this
controller. If the layer is added to the view, it is possible to keep it, even if the interaction
with this controller is terminated.
Equivalent to new TLspRulerController(aAddLayerToView, null)
.aAddLayerToView
- true to add layer in view, false otherwise.public TLspRulerController(boolean aAddLayerToView, ALspCreateControllerModel aCreateControllerModel)
ALspCreateControllerModel
.
Use this constructor to:
ALspRulerMeasurement
implementationsaAddLayerToView
- true to add layer in view, false otherwise. See TLspRulerController(boolean)
for more information.aCreateControllerModel
- The ruler controller uses this to create new measurements.
When null, the ruler controller will use a default ALspCreateControllerModel
implementation.
Note that its getLayer
implementation must return null
.
If null
is returned from its create
,
then a default measurement will be created.public TLspPaintProgress paintImpl(ILcdGLDrawable aGLDrawable, ILspView aView, TLspPaintPhase aPaintPhase)
ALspController
paint
for this controller.paintImpl
in class ALspController
aGLDrawable
- the drawable that should be painted onaView
- the view that is painted onaPaintPhase
- the current paint phasepublic void startInteractionImpl(ILspView aView)
ALspController
startInteraction
for this controller.startInteractionImpl
in class ALspController
aView
- the view to start interaction with.public void terminateInteractionImpl(ILspView aView)
ALspController
terminateInteraction
for this controller.terminateInteractionImpl
in class ALspController
aView
- the view to terminate interaction with.public AWTEvent handleAWTEventImpl(AWTEvent aAWTEvent)
ALspController
handleAWTEvent
.
Returns null
when the controller consumed the event or a partially consumed event
when the controller partially consumed the event (which could happen with
TLcdTouchEvent
s). When the controller did not use the given event, it is returned
unaltered.handleAWTEventImpl
in class ALspController
aAWTEvent
- the event to be handled.null
when the input event was consumed, the (possibly modified) input
event when it was (partially) consumed.public void handleFXEvent(javafx.event.Event aEvent)
ALspController
handleFXEventImpl
.
If that method does not return null
, the result is passed on to the next controller in the chain (if one exists).
If the controller has a filter that does not accept the event, the event is not delegated
and is immediately passed on to the next controller.handleFXEvent
in interface ILspController
handleFXEvent
in class ALspController
aEvent
- the event to be handledpublic javafx.event.Event handleFXEventImpl(javafx.event.Event aEvent)
ALspController
handleFXEvent
.
Returns null
when the controller consumed the event. When the controller did not use the
given event, it is returned unaltered.handleFXEventImpl
in class ALspController
aEvent
- the event to be handled.null
when the input event was consumed, the (possibly modified) input
event when it was (partially) consumed.public void setStringTranslator(ILcdStringTranslator aStringTranslator)
Sets the ILcdStringTranslator
that this controller should use to
translate the Strings
that will be visible in the user interface.
This method should be called before this controller is used. Any Strings
already
created by this controller will not be translated with the specified translator. The
ILcdStringTranslator
does not translate the controller's name and description.
aStringTranslator
- The ILcdStringTranslator
that should be used. Must not be
null
.
The following list of Strings
are translated by the given instance:
{0}
will be replaced by the display name of the action that is to be undone. E.g. "Undo Clear measurements".{0}
will be replaced by the display name action that is to be redone. E.g. "Redo Clear measurements"{0}
will be replaced by the result of calling Object.toString()
on the edited object. E.g. "Edit ruler measurement".Object.toString()
on the used ALspMeasurement
objects.
For the default ALspMeasurement
implementation, this is "ruler measurement".ILcdStringTranslator
needs to be able to translate what is passed in {0}
, but not the
entire formatted String
. For example, for "Undo {0}" it needs to be able to translate "Undo {0}" itself
and "Clear measurements", but not "Undo Clear measurements".public ILcdStringTranslator getStringTranslator()
Returns the ILcdStringTranslator
set on this controller.
null
.public ALspRulerMeasurement getCurrentMeasurement()
public void addChangeListener(ILcdChangeListener aListener)
aListener
- the listener that should be added.getCurrentMeasurement()
public void removeChangeListener(ILcdChangeListener aListener)
aListener
- the listener that should be removed.addChangeListener(com.luciad.util.ILcdChangeListener)
public boolean isAddLayerToView()
TLspRulerController(boolean)
public boolean isKeepLayer()
added
to the view. Otherwise
this method will have no effect.setKeepLayer(boolean)
,
isAddLayerToView()
public void setKeepLayer(boolean aKeepLayer)
add a layer to the view
.
The default value is false
.aKeepLayer
- True to keep layer in view, false otherwise.isKeepLayer()
,
isAddLayerToView()
public boolean isKeepMeasurements()
setKeepMeasurements(boolean)
public void setKeepMeasurements(boolean aKeepMeasurements)
aKeepMeasurements
- True to keep measurements, false otherwise.isKeepMeasurements()
public ILcdLayered getLayered()
ILspController
Returns an ILcdLayered
for this controller. 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.
The returned layered object should contain layers that are relevant to this controller. Any view using this controller should take into account the layers of its active controller.
Note that the ILcdLayered is only allowed to contain ILspLayer
instances.
getLayered
in interface ILspController
getLayered
in class ALspController
public TLspRulerController.MeasureMode getMeasureMode()
MEASURE_GEODETIC
.public void setMeasureMode(TLspRulerController.MeasureMode aMeasureMode)
MEASURE_GEODETIC
,
MEASURE_RHUMB
or
MEASURE_CARTESIAN
.aMeasureMode
- the new measurement modepublic ILspStyler getLineStyler()
setLineStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
public void setLineStyler(ILspStyler aLineStyler)
ALspRulerMeasurement
and implement
ILcdPolyline
.aLineStyler
- the styler to be used by the polyline painter.getLineStyler()
public void setLineStyler(TLspPaintState aPaintState, ILspStyler aLineStyler)
ALspRulerMeasurement
and implement
ILcdPolyline
.aPaintState
- the paintstate to set the styler for.aLineStyler
- the styler to be used by the polyline painter.getLineStyler()
public boolean isDisplayEqualDistanceCircles()
MEASURE_GEODETIC
.public void setDisplayEqualDistanceCircles(boolean aDisplayEqualDistanceCircles)
MEASURE_GEODETIC
.
When another measure mode is used no circles will be displayed.
Default is true.aDisplayEqualDistanceCircles
- true if equal distance circles have to be displayed, false otherwise.public ILspCustomizableStyler getCircleStyler()
setCircleStyler(com.luciad.view.lightspeed.style.styler.ILspCustomizableStyler)
,
isDisplayEqualDistanceCircles()
public void setCircleStyler(ILspCustomizableStyler aCircleStyler)
aCircleStyler
- the styler to be used by the circle painter.getCircleStyler()
,
setDisplayEqualDistanceCircles(boolean)
public ILspStyler getLabelStyler()
getLabelStyler(TLspPaintState.EDITED)
.setLabelStyler(com.luciad.view.lightspeed.style.styler.ILspStyler)
public ILspStyler getLabelStyler(TLspPaintState aPaintState)
aPaintState
- the paintstate to get the label styler for.setLabelStyler(com.luciad.view.lightspeed.layer.TLspPaintState, com.luciad.view.lightspeed.style.styler.ILspStyler)
public void setLabelStyler(ILspStyler aLabelStyler)
ALspRulerMeasurement
and implement
ILcdPolyline
.
By default a standard TLspRulerLabelStyler
is used.
The styler will be used to paint measurements in the REGULAR, EDITED and SELECTED paintstates.aLabelStyler
- the styler to be used by the label painter.getLabelStyler()
public void setLabelStyler(TLspPaintState aState, ILspStyler aLabelStyler)
ALspRulerMeasurement
and implement
ILcdPolyline
.
By default a standard TLspRulerLabelStyler
is used.aState
- the paintstate to get the styler foraLabelStyler
- the styler to be used by the label painter.getLabelStyler()
public void setHandleStyler(ILspStyler aHandleStyler)
TLspEditHandleStyler
is used.aHandleStyler
- The styler to be used for editing handles.public ILspStyler getHandleStyler()
TLspEditHandleStyler
.public void setFocusHandleStyler(ILspStyler aFocusHandleStyler)
TLspEditHandleStyler
with a red icon style for points, is used.aFocusHandleStyler
- The styler to be used for focused editing handles.public ILspStyler getFocusHandleStyler()
TLspEditHandleStyler
with a red icon style for points, is used.public boolean isDisplayAzimuth()
setDisplayAzimuth(boolean)
public void setDisplayAzimuth(boolean aDisplayAzimuth)
true
, an azimuth label
is shown for every segment. Note that this method is a convenience method; it works when the ruler
label styler is not customized. More specifically, it works under the following conditions:
TLspRulerSegmentLabelContentStyle
.TLspRulerSegmentLabelContentStyle.Builder#displayAzimuth
is used to create a new
TLspRulerSegmentLabelContentStyle
that is capable of returning the current azimuth value.
On top of that, calling this method also adds an arrow to the middle of every line segment. Note that this is a
convenience method as well. It works by default, or when the used line styler
ALspStyleCollector#geometry
.TLspLineStyle
objects.aDisplayAzimuth
- whether or not azimuths are displayed for each segmentisDisplayAzimuth()
public void addUndoableListener(ILcdUndoableListener aUndoableListener)
ILcdUndoableSource
addUndoableListener
in interface ILcdUndoableSource
aUndoableListener
- The listener to be notified when something undoable has happened.public void removeUndoableListener(ILcdUndoableListener aUndoableListener)
ILcdUndoableSource
removeUndoableListener
in interface ILcdUndoableSource
aUndoableListener
- The listener to remove.protected double calculateAzimuth(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdModelReference aReference, TLspRulerController.MeasureMode aMeasureMode)
MEASURE_GEODETIC
: the two dimensional forward azimuth
between the two points, according to the ellipsoid the model reference is
based on (see
ILcdEllipsoid.forwardAzimuth2D
).MEASURE_RHUMB
: the two dimensional rhumbline azimuth
between the two points, according to the ellipsoid the model reference is
based on (see
ILcdEllipsoid.rhumblineAzimuth2D
).MEASURE_CARTESIAN
: Double.NaN
, there is no
reliable way to calculate an azimuth for a line in world space.aPoint1
- the first point of the segment to calculate the azimuth foraPoint2
- the second point of the segment to calculate the azimuth foraReference
- the reference the points are defined in.aMeasureMode
- the measure mode to take into account.Double.NaN
if no
azimuth could be calculated.protected double calculateDistance(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdModelReference aReference, TLspRulerController.MeasureMode aMeasureMode)
MEASURE_GEODETIC
: the geodetic distance between the two
points, according to the ellipsoid the model reference is based on (see
ILcdEllipsoid.geodesicDistance
).MEASURE_RHUMB
: the rhumbline distance between the two
points, according to the ellipsoid the model reference is based on (see
ILcdEllipsoid.rhumblineDistance
).MEASURE_CARTESIAN
: the cartesian distance between the two
points (see
TLcdCartesian.distance3D
), taking into account the unit of measure of the
model reference (in this case the world reference of the view) if
available.aPoint1
- the first point of the segment to calculate the distance foraPoint2
- the second point of the segment to calculate the distance foraReference
- the reference the points are defined in.aMeasureMode
- the measure mode to take into account.public boolean isCreating()
public void finish()
public void cancel()
public Cursor getCursor()
ALspController
ALspController.getFXCursor()
}.getCursor
in class ALspController
ALspController.setCursor(java.awt.Cursor)