Class TLspRulerController

java.lang.Object
com.luciad.view.lightspeed.controller.ALspController
com.luciad.view.lightspeed.controller.ruler.TLspRulerController
All Implemented Interfaces:
ILcdUndoableSource, ILcdAWTEventListener, ILspController

public class TLspRulerController extends ALspController implements ILcdUndoableSource

A controller that allows to measure distances on the map.

Ruler controller
Measuring a distance on the map using the ruler controller.

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:

The handleFXEvent(Event aEvent) converts the native JavaFX TouchEvent to a TLcdTouchEvent and passes it to the ALspController.handleAWTEvent(AWTEvent aEvent).

The ruler will automatically snap to nearby features of snappable layers.
Since:
2012.0
  • Constructor Details

    • TLspRulerController

      public TLspRulerController()
      Creates a new ruler controller. Equivalent to new TLspRulerController(false, null).
    • TLspRulerController

      public TLspRulerController(boolean aAddLayerToView)
      Creates a new ruler controller. Based on the passed value, the ruler measurements will be painted in a layer added to the view, or in a layer offered by the 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).
      Parameters:
      aAddLayerToView - true to add layer in view, false otherwise.
    • TLspRulerController

      public TLspRulerController(boolean aAddLayerToView, ALspCreateControllerModel aCreateControllerModel)
      Creates a new ruler controller with the given ALspCreateControllerModel. Use this constructor to:
      • let the ruler controller create custom ALspRulerMeasurement implementations
      • limit the number of points the user can create measurements with
      • be notified when a new measurement is created
      • be notified when measurement creation is canceled
      Parameters:
      aAddLayerToView - 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.
      Since:
      2018.0
  • Method Details

    • paintImpl

      public TLspPaintProgress paintImpl(ILcdGLDrawable aGLDrawable, ILspView aView, TLspPaintPhase aPaintPhase)
      Description copied from class: ALspController
      The specific implementation of paint for this controller.
      Overrides:
      paintImpl in class ALspController
      Parameters:
      aGLDrawable - the drawable that should be painted on
      aView - the view that is painted on
      aPaintPhase - the current paint phase
      Returns:
      whether or not the painting was finished
    • startInteractionImpl

      public void startInteractionImpl(ILspView aView)
      Description copied from class: ALspController
      The specific implementation of startInteraction for this controller.
      Overrides:
      startInteractionImpl in class ALspController
      Parameters:
      aView - the view to start interaction with.
    • terminateInteractionImpl

      public void terminateInteractionImpl(ILspView aView)
      Description copied from class: ALspController
      The specific implementation of terminateInteraction for this controller.
      Overrides:
      terminateInteractionImpl in class ALspController
      Parameters:
      aView - the view to terminate interaction with.
    • handleAWTEventImpl

      public AWTEvent handleAWTEventImpl(AWTEvent aAWTEvent)
      Description copied from class: ALspController
      Called by 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 TLcdTouchEvents). When the controller did not use the given event, it is returned unaltered.
      Specified by:
      handleAWTEventImpl in class ALspController
      Parameters:
      aAWTEvent - the event to be handled.
      Returns:
      null when the input event was consumed, the (possibly modified) input event when it was (partially) consumed.
    • handleFXEvent

      public void handleFXEvent(Event aEvent)
      Description copied from class: ALspController
      Delegates to 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.
      Specified by:
      handleFXEvent in interface ILspController
      Overrides:
      handleFXEvent in class ALspController
      Parameters:
      aEvent - the event to be handled
    • handleFXEventImpl

      public Event handleFXEventImpl(Event aEvent)
      Description copied from class: ALspController
      Called by handleFXEvent. Returns null when the controller consumed the event. When the controller did not use the given event, it is returned unaltered.
      Overrides:
      handleFXEventImpl in class ALspController
      Parameters:
      aEvent - the event to be handled.
      Returns:
      null when the input event was consumed, the (possibly modified) input event when it was (partially) consumed.
    • setStringTranslator

      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.

      Parameters:
      aStringTranslator - The ILcdStringTranslator that should be used. Must not be null.

      The following list of Strings are translated by the given instance:

      • "Clear measurements"
      • "Undo {0}".{0} will be replaced by the display name of the action that is to be undone. E.g. "Undo Clear measurements".
      • "Redo {0}".{0} will be replaced by the display name action that is to be redone. E.g. "Redo Clear measurements"
      • "Edit {0}".{0} will be replaced by the result of calling Object.toString() on the edited object. E.g. "Edit ruler measurement".
      • "Create object"
      • The result of calling Object.toString() on the used ALspMeasurement objects. For the default ALspMeasurement implementation, this is "ruler measurement".
      The 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".
    • getStringTranslator

      public ILcdStringTranslator getStringTranslator()

      Returns the ILcdStringTranslator set on this controller.

      Returns:
      The translator set on this controller. Never null.
    • getCurrentMeasurement

      public ALspRulerMeasurement getCurrentMeasurement()
      Returns the current measurement. This is either the measurement currently under construction or the last created or edited measurement.
      Returns:
      the current measurement.
    • addChangeListener

      public void addChangeListener(ILcdChangeListener aListener)
      Adds a change listener. This listener will be informed when the current measurement is changed.
      Parameters:
      aListener - the listener that should be added.
      See Also:
    • removeChangeListener

      public void removeChangeListener(ILcdChangeListener aListener)
      Removes a change listener if it is present.
      Parameters:
      aListener - the listener that should be removed.
      See Also:
    • isAddLayerToView

      public boolean isAddLayerToView()
      Returns true if a layer containing the measurements is added to the view (and as such visible in the layer tree).
      Returns:
      true if the measurement layer is added to the view, false otherwise.
      See Also:
    • isKeepLayer

      public boolean isKeepLayer()
      Returns true if the layer is kept after the interaction with the ruler controller is terminated. This will only have effect is the layer is added to the view. Otherwise this method will have no effect.
      Returns:
      true if the layer is kept after the interaction with the ruler controller is terminated.
      See Also:
    • setKeepLayer

      public void setKeepLayer(boolean aKeepLayer)
      Set to true if the layer is to be kept after the interaction with the ruler controller is terminated. For this to work, the ruler controller must be configured to add a layer to the view. The default value is false.
      Parameters:
      aKeepLayer - True to keep layer in view, false otherwise.
      See Also:
    • isKeepMeasurements

      public boolean isKeepMeasurements()
      Returns true if measurements are kept after a new measurement is started.
      Returns:
      true if measurements are kept.
      See Also:
    • setKeepMeasurements

      public void setKeepMeasurements(boolean aKeepMeasurements)
      Set to true is measurements should be kept after a new measurement is started. Default is false.
      Parameters:
      aKeepMeasurements - True to keep measurements, false otherwise.
      See Also:
    • getLayered

      public ILcdLayered getLayered()
      Description copied from interface: 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.

      Specified by:
      getLayered in interface ILspController
      Overrides:
      getLayered in class ALspController
      Returns:
      an ILcdLayered object, or null if this controller has no layers.
    • getMeasureMode

      public TLspRulerController.MeasureMode getMeasureMode()
      Returns the current measurement mode. The default mode is MEASURE_GEODETIC.
      Returns:
      the current measurement mode
    • setMeasureMode

      public void setMeasureMode(TLspRulerController.MeasureMode aMeasureMode)
      Sets the measurement mode. The mode must be one of MEASURE_GEODETIC, MEASURE_RHUMB or MEASURE_CARTESIAN.
      Parameters:
      aMeasureMode - the new measurement mode
    • getLineStyler

      public ILspStyler getLineStyler()
      Returns the styler for ruler polylines that are being edited or created.
      Returns:
      the current styler used by the polyline painter.
      See Also:
    • setLineStyler

      public void setLineStyler(ILspStyler aLineStyler)
      Sets the styler for the ruler polylines, for all supported paint states. The objects to provide styles for extend ALspRulerMeasurement and implement ILcdPolyline.
      Parameters:
      aLineStyler - the styler to be used by the polyline painter.
      See Also:
    • setLineStyler

      public void setLineStyler(TLspPaintState aPaintState, ILspStyler aLineStyler)
      Sets the styler for the ruler polylines for the given paint state. The objects to provide styles for extend ALspRulerMeasurement and implement ILcdPolyline.
      Parameters:
      aPaintState - the paintstate to set the styler for.
      aLineStyler - the styler to be used by the polyline painter.
      See Also:
    • isDisplayEqualDistanceCircles

      public boolean isDisplayEqualDistanceCircles()
      Returns true if equal distance circles are displayed for polyline nodes that are moved. Currently this is only relevant for MEASURE_GEODETIC.
      Returns:
      true if equal distance circles are displayed.
    • setDisplayEqualDistanceCircles

      public void setDisplayEqualDistanceCircles(boolean aDisplayEqualDistanceCircles)
      Sets whether or not equal distance circles are displayed for polyline nodes that are moved. Currently this is only relevant for measure modes MEASURE_GEODETIC. When another measure mode is used no circles will be displayed. Default is true.
      Parameters:
      aDisplayEqualDistanceCircles - true if equal distance circles have to be displayed, false otherwise.
    • getCircleStyler

      public ILspCustomizableStyler getCircleStyler()
      Returns the customizable styler currently used to determine the style of equal distance circles.
      Returns:
      the current styler used by the circle painter.
      See Also:
    • setCircleStyler

      public void setCircleStyler(ILspCustomizableStyler aCircleStyler)
      Sets the customizable styler currently used to paint equal distance circles. The customizable styler is in effect treated as a list of styles. All enabled customizable styles that are relevant will be used when styling the circles.
      Parameters:
      aCircleStyler - the styler to be used by the circle painter.
      See Also:
    • getLabelStyler

      public ILspStyler getLabelStyler()
      Returns the styler for distance and azimuth labels of ruler measurements that are being edited or created. This is equivalent to calling getLabelStyler(TLspPaintState.EDITED).
      Returns:
      the current styler used by the label painter.
      See Also:
    • getLabelStyler

      public ILspStyler getLabelStyler(TLspPaintState aPaintState)
      Returns the styler for distance and azimuth labels of ruler measurements for measurements in the given paintstate.
      Parameters:
      aPaintState - the paintstate to get the label styler for.
      Returns:
      the current styler used by the label painter.
      See Also:
    • setLabelStyler

      public void setLabelStyler(ILspStyler aLabelStyler)
      Sets the styler for distance and azimuth labels, for all supported paint states. The objects to provide styles for extend 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.
      Parameters:
      aLabelStyler - the styler to be used by the label painter.
      See Also:
    • setLabelStyler

      public void setLabelStyler(TLspPaintState aState, ILspStyler aLabelStyler)
      Sets the styler for distance and azimuth labels, for the given paint state. The objects to provide styles for extend ALspRulerMeasurement and implement ILcdPolyline. By default a standard TLspRulerLabelStyler is used.
      Parameters:
      aState - the paintstate to get the styler for
      aLabelStyler - the styler to be used by the label painter.
      See Also:
    • setHandleStyler

      public void setHandleStyler(ILspStyler aHandleStyler)
      Sets the styler for editing handles. By default, a standard TLspEditHandleStyler is used.
      Parameters:
      aHandleStyler - The styler to be used for editing handles.
    • getHandleStyler

      public ILspStyler getHandleStyler()
      Returns the styler for editing handles. By default, this is a standard TLspEditHandleStyler.
      Returns:
      The styler for editing handles.
    • setFocusHandleStyler

      public void setFocusHandleStyler(ILspStyler aFocusHandleStyler)
      Sets the styler for focused editing handles. By default, a standard TLspEditHandleStyler with a red icon style for points, is used.
      Parameters:
      aFocusHandleStyler - The styler to be used for focused editing handles.
    • getFocusHandleStyler

      public ILspStyler getFocusHandleStyler()
      Returns the styler for focused editing handles. By default, a standard TLspEditHandleStyler with a red icon style for points, is used.
      Returns:
      The styler for focused editing handles.
    • isDisplayAzimuth

      public boolean isDisplayAzimuth()
      Returns whether or not azimuths are displayed for each segment.
      Returns:
      whether or not azimuths are displayed for each segment.
      See Also:
    • setDisplayAzimuth

      public void setDisplayAzimuth(boolean aDisplayAzimuth)
      Sets whether or not azimuths are displayed for each segment. When set to 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: When these conditions are met, 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
      Parameters:
      aDisplayAzimuth - whether or not azimuths are displayed for each segment
      See Also:
    • addUndoableListener

      public void addUndoableListener(ILcdUndoableListener aUndoableListener)
      Description copied from interface: ILcdUndoableSource
      Adds a listener to this source, so this listener is notified when something undoable has happened.
      Specified by:
      addUndoableListener in interface ILcdUndoableSource
      Parameters:
      aUndoableListener - The listener to be notified when something undoable has happened.
    • removeUndoableListener

      public void removeUndoableListener(ILcdUndoableListener aUndoableListener)
      Description copied from interface: ILcdUndoableSource
      Removes the specified listener so it is no longer notified.
      Specified by:
      removeUndoableListener in interface ILcdUndoableSource
      Parameters:
      aUndoableListener - The listener to remove.
    • calculateAzimuth

      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. The default implementation returns an azimuth depending on the measure mode as follows:
      • 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.
      Parameters:
      aPoint1 - the first point of the segment to calculate the azimuth for
      aPoint2 - the second point of the segment to calculate the azimuth for
      aReference - the reference the points are defined in.
      aMeasureMode - the measure mode to take into account.
      Returns:
      an azimuth for the passed segment, of Double.NaN if no azimuth could be calculated.
    • calculateDistance

      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. The default implementation returns an distance depending on the measure mode as follows:
      • 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.
      Parameters:
      aPoint1 - the first point of the segment to calculate the distance for
      aPoint2 - the second point of the segment to calculate the distance for
      aReference - the reference the points are defined in.
      aMeasureMode - the measure mode to take into account.
      Returns:
      an distance for the passed segment
    • isCreating

      public boolean isCreating()
      Returns whether or not the ruler controller is currently creating or editing.
      Returns:
      true if a ruler polyline is being created, false otherwise.
    • finish

      public void finish()
      Finish the creation of the ruler polyline.
    • cancel

      public void cancel()
      Cancels the creation of the ruler polyline.
    • getCursor

      public Cursor getCursor()
      Description copied from class: ALspController
      Returns the mouse cursor for this controller. The cursor is typically retrieved by the view to configure its host component.
      This method returns the cursor for this controller, not the rest of chain.

      However, the property change listeners of the controller will be informed about cursor changes for the entire controller chain. A cursor property change event's value will be the first non-null cursor along the controller chain.

      For JavaFX, see {#link ALspController.getFXCursor()}.

      Overrides:
      getCursor in class ALspController
      Returns:
      the cursor for this controller, or null if the controller does not have a specific cursor
      See Also: