Class TLcdMapTouchRulerController

All Implemented Interfaces:
ILcdAWTEventListener, ILcdStatusSource, ILcdGXYChainableController, ILcdGXYController, Serializable

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 TLcdTouchPoints which are not-consumed, and marks the TLcdTouchPoints it uses as consumed, similar to the ALcdGXYTouchChainableController.

Since:
10.0
See Also:
  • Field Details

    • RULER_MODEL_TYPE_NAME

      public static final String RULER_MODEL_TYPE_NAME
      Returns the type name of the ruler model created by this controller.
      Since:
      2018.1
      See Also:
  • Constructor Details

    • TLcdMapTouchRulerController

      public TLcdMapTouchRulerController(TLcdGXYTouchNewController aNewController, TLcdGXYTouchSelectEditController aEditController)
      Create a new ruler controller.
      Parameters:
      aNewController - The controller responsible for the creation of new objects
      aEditController - The controller responsible for editing existing objects
  • Method Details

    • handleAWTEvent

      public void handleAWTEvent(AWTEvent aEvent)
      Description copied from interface: ILcdAWTEventListener
      This is method is called when the target of the listener has a new AWTEvent available.
      Specified by:
      handleAWTEvent in interface ILcdAWTEventListener
      Parameters:
      aEvent - The event to be handled.
    • startInteractionImpl

      protected void startInteractionImpl(ILcdGXYView aGXYView)
      Description copied from class: ALcdGXYChainableController
      The specific implementation of startInteraction for this controller.
      Overrides:
      startInteractionImpl in class ALcdGXYChainableController
      Parameters:
      aGXYView - the view to start interaction with.
    • terminateInteractionImpl

      protected void terminateInteractionImpl(ILcdGXYView aGXYView)
      Description copied from class: ALcdGXYChainableController
      The specific implementation of terminateInteraction for this controller.
      Overrides:
      terminateInteractionImpl in class ALcdGXYChainableController
      Parameters:
      aGXYView - the view to terminate interaction with.
    • paintImpl

      protected void paintImpl(Graphics aGraphics)
      Description copied from class: ALcdGXYChainableController
      The specific implementation of paint for this controller.
      Overrides:
      paintImpl in class ALcdGXYChainableController
      Parameters:
      aGraphics - the graphics to be used for painting.
    • getLayered

      public ILcdLayered getLayered()
      Description copied from interface: ILcdGXYController
      Returns the layers associated with this controller. A view using this controller should visualize the layers of its active controller and take them into account for label placement.

      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.

      Specified by:
      getLayered in interface ILcdGXYController
      Returns:
      an ILcdLayered object with GXY layers, or null if this controller has no layers.
    • addMeasurementChangeListener

      public void addMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
      Adds the given MeasurementChangeListener. This allows to receive updates whenever the measurement is changed.
      Parameters:
      aListener - The listener to add.
      See Also:
    • removeMeasurementChangeListener

      public void removeMeasurementChangeListener(TLcdAdvancedMapRulerController.MeasurementChangeListener aListener)
      Removes the given MeasurementChangeListener. Does nothing if the listener was never added or already removed.
      Parameters:
      aListener - The listener to remove.
      See Also:
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Add the given PropertyChangeListener.
      Parameters:
      aPropertyChangeListener - The listener to be added.
      See Also:
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
      Removes the given PropertyChangeListener. Does nothing if the listener was never added (or already removed).
      Parameters:
      aPropertyChangeListener - The listener to remove.
      See Also:
    • firePropertyChange

      protected void firePropertyChange(PropertyChangeEvent aEvent)
      Notifies all property change listeners that the value of a property has changed. This method should be called from every method that sets a property value in which another class may be interested.
      Parameters:
      aEvent - the event describing the property that has changed
    • getMeasureMode

      public TLcdMapTouchRulerController.MeasureMode getMeasureMode()
      Returns the current measuring mode.
      Returns:
      the current measuring mode.
      See Also:
    • setMeasureMode

      public void setMeasureMode(TLcdMapTouchRulerController.MeasureMode aMeasureMode)
      Sets the current measuring mode.
      Parameters:
      aMeasureMode - The measuring mode. One of
      • TLcdAdvancedMapRulerController.GEODETIC Measures the distance and azimuth between two points using the geodetic mode, on the ILcdEllipsoid of the ILcdXYWorldReference of the ILcdGXYView.

      • TLcdAdvancedMapRulerController.RHUMBLINE Measures the distance and azimuth between two points using the rhumbline mode, on the ILcdEllipsoid of the ILcdXYWorldReference of the ILcdGXYView.

      • TLcdAdvancedMapRulerController.PROJECTION_PLANE

        Measures the distance and angle between two points in the projection plane of the ILcdXYWorldReference of the ILcdGXYView. This means the measurements are only accurate in a small area around the center of the projection.

      See Also:
    • getSnappables

      public ILcdGXYLayerSubsetList getSnappables()
      Returns the snappables used by this controller.
      Returns:
      the snappables used by this controller.
      See Also:
    • setSnappables

      public void setSnappables(ILcdGXYLayerSubsetList aSnappables)
      Sets the new snappables for this controller, default is null. If snappables is set to null, snapping will be disabled.
      Parameters:
      aSnappables - The new list of snappables for this controller
      See Also:
    • getAzimuthFormat

      public Format getAzimuthFormat()
      Returns the format used to format azimuths and display them to the user. The default format shows the angle in degrees, having one fraction digit. It also adds a degree symbol.
      Returns:
      The azimuth format.
      See Also:
    • setAzimuthFormat

      public void setAzimuthFormat(Format aAzimuthFormat)
      Sets the azimuth format to be used to format azimuths and display them to the user.
      Parameters:
      aAzimuthFormat - The new azimuth format.
      See Also:
    • isDrawEqualDistanceCurve

      public boolean isDrawEqualDistanceCurve()
      Returns true if the equal distance curve(s) are drawn, false otherwise.
      Returns:
      true if the equal distance curve(s) are drawn, false otherwise.
      See Also:
    • setDrawEqualDistanceCurve

      public void setDrawEqualDistanceCurve(boolean aDrawEqualDistanceCurve)
      Sets if the equal distance curve(s) are drawn or not. When a measurement is created, a curve showing points at equal distance as the distance between the mouse pointer and the last measurement point can be displayed. This curve is a circle when using the projection plane measuring mode, a geodesic circle when using geodesic measuring mode and a rhumbline circle when using rhumbline measuring mode.
      Parameters:
      aDrawEqualDistanceCurve - True to draw the curves, false otherwise.
    • setLineStyle

      public void setLineStyle(ILcdGXYPainterStyle aLineStyle)
      Sets the style to use to paint lines.
      Parameters:
      aLineStyle - the new line style to set.
      See Also:
    • getLineStyle

      public ILcdGXYPainterStyle getLineStyle()
      Returns the style to paint lines.
      Returns:
      the style to paint lines.
      See Also:
    • isDisplayAzimuth

      public boolean isDisplayAzimuth()
      Returns true if the azimuth is displayed on the map.
      Returns:
      true if the azimuth is displayed on the map.
      See Also:
    • setDisplayAzimuth

      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.

      See Also:
    • setHaloEnabled

      public void setHaloEnabled(boolean aHaloEnabled)
      Enables or disables the halo effect on the measurement lines.
      Parameters:
      aHaloEnabled - true if halos should be added, false otherwise
      See Also:
    • isHaloEnabled

      public boolean isHaloEnabled()
      Returns if the halo effect on the measurement lines is enabled.
      Returns:
      if the halo effect on the measurement lines is enabled.
      See Also:
    • setHaloThickness

      public void setHaloThickness(int aHaloThickness)
      Sets the thickness (in pixels) of the halo to be added around measurement lines.
      Parameters:
      aHaloThickness - the thickness (in pixels) of the halo to be added around measurement lines.
      See Also:
    • getHaloThickness

      public int getHaloThickness()
      Returns the thickness (in pixels) of the halo to be added around measurement lines.
      Returns:
      the thickness (in pixels) of the halo to be added around measurement lines.
      See Also:
    • setHaloColor

      public void setHaloColor(Color aHaloColor)
      Sets the color of the halo to be added around measurement lines.
      Parameters:
      aHaloColor - the color of the halo to be added around measurement lines.
      See Also:
    • getHaloColor

      public Color getHaloColor()
      Returns the color of the halo to be added around measurement lines.
      Returns:
      the color of the halo to be added around measurement lines.
      See Also:
    • isPreserveMeasurement

      public boolean isPreserveMeasurement()
      Returns true if the measurement is preserved when the controller is terminated and started again. See also setPreserveMeasurement(boolean).
      Returns:
      true if the measurement is preserved when the controller is terminated and started again, false otherwise.
    • setPreserveMeasurement

      public 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). If set to false, the previous measurement is removed every time the controller is started.
      Parameters:
      aPreserveMeasurement - True to preserve measurements, false otherwise.
    • getGXYLayer

      public ILcdGXYLayer getGXYLayer()
      Returns the ILcdGXYLayer containing the measurements. Long term references to the returned layer should not be stored, as it may change. The contents of this layer depend on the controller settings.

      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.

      Returns:
      the ILcdGXYLayer containing the measurements.
      See Also:
    • setAllowMultipleMeasurements

      public void setAllowMultipleMeasurements(boolean aAllowMultipleMeasurements)
      When set to true, multiple measurements are allowed at the same time.

      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.

      Parameters:
      aAllowMultipleMeasurements - true to allow multiple measurements at the same time.
    • isAllowMultipleMeasurements

      public boolean isAllowMultipleMeasurements()
      Checks if multiple measurements are allowed at the same time.
      Returns:
      true if multiple measurements are allowed, and false otherwise.
      See Also:
    • setAddGXYLayerToGXYView

      public void setAddGXYLayerToGXYView(boolean aAddGXYLayerToGXYView)
      When set to true, the layer containing measurements is added to the view. This makes it possible to display the measurements, even after terminating the interaction with the controller.

      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.

      Parameters:
      aAddGXYLayerToGXYView - true if the measurement layer should be added to the view, and false otherwise.
      See Also:
    • isAddGXYLayerToGXYView

      public boolean isAddGXYLayerToGXYView()
      Checks if the layer containing measurements should be added to the view.
      Returns:
      true if the layer should be added, and false otherwise.
      See Also:
    • setRemoveGXYLayerFromGXYView

      public void setRemoveGXYLayerFromGXYView(boolean aRemoveGXYLayerFromGXYView)
      When set to true, the layer containing measurements is removed from the view after terminating the controller interaction. This setting only has effect when the layer containing measurements is also added to the view during interaction.
      Parameters:
      aRemoveGXYLayerFromGXYView - true if the measurement layer should be removed from the view, and false otherwise.
      See Also:
    • isRemoveGXYLayerFromGXYView

      public boolean isRemoveGXYLayerFromGXYView()
      Checks if the layer containing measurements should be removed from the view after terminating the controller interaction.
      Returns:
      true if the layer should be removed, and false otherwise.
      See Also:
    • setLabelAlignment

      public void setLabelAlignment(int aLabelAlignment)
      Sets the label alignment.
      Parameters:
      aLabelAlignment - The alignment of the label. One of TLcdGXYPolylineLabelPainter.ABOVE, TLcdGXYPolylineLabelPainter.CENTER, TLcdGXYPolylineLabelPainter.BELOW
      See Also:
    • getLabelAlignment

      public int getLabelAlignment()
      Returns the label alignment.
      Returns:
      The label alignment. One of TLcdGXYPolylineLabelPainter.ABOVE, TLcdGXYPolylineLabelPainter.CENTER, TLcdGXYPolylineLabelPainter.BELOW.
      See Also:
    • setTotalDistanceLabelFont

      public void setTotalDistanceLabelFont(Font aTotalDistanceLabelFont)
      Sets the font of the total distance label.
      Parameters:
      aTotalDistanceLabelFont - The font.
      See Also:
    • getTotalDistanceLabelFont

      public Font getTotalDistanceLabelFont()
      Returns the font of the total distance label.
      Returns:
      the font of the total distance label.
      See Also:
    • setSegmentLabelFont

      public void setSegmentLabelFont(Font aSegmentLabelFont)
      Sets the font of the segment distance labels (and possibly azimuth, if isDisplayAzimuth() is true) to the given font.
      Parameters:
      aSegmentLabelFont - The new font.
      See Also:
    • getSegmentLabelFont

      public Font getSegmentLabelFont()
      Returns the font of the segment distance labels (and possibly azimuth, if isDisplayAzimuth() is true).
      Returns:
      The font of the segment labels.
      See Also:
    • isLabelFontBorder

      public boolean isLabelFontBorder()
      Returns true if a border is painted around the label text in the background color.
      Returns:
      true if a border is painted around the label text.
      See Also:
    • setLabelFontBorder

      public void setLabelFontBorder(boolean aLabelFontBorder)
      Sets if the painted text should be bordered with the background color. This improves readability because the text will be readable on both light and dark background colors.
      Parameters:
      aLabelFontBorder - True if text should be bordered, false otherwise.
      See Also:
    • setLabelForeground

      public void setLabelForeground(Color aLabelForeground)
      Sets the foreground color of the labels.
      Parameters:
      aLabelForeground - The foreground color of the labels.
      See Also:
    • getLabelForeground

      public Color getLabelForeground()
      Returns the foreground color of the labels.
      Returns:
      the foreground color of the labels.
      See Also:
    • setLabelBackground

      public void setLabelBackground(Color aLabelBackground)
      Sets the background color of the labels. This color is used to fill the background of the labels if isLabelFilled() returns true, or to paint a border around the text when isLabelFontBorder() returns true.
      Parameters:
      aLabelBackground - The background color of the labels.
      See Also:
    • getLabelBackground

      public Color getLabelBackground()
      Returns the background color of the labels.
      Returns:
      the background color of the labels.
      See Also:
    • setLabelSelectionColor

      public void setLabelSelectionColor(Color aLabelSelectionColor)
      Sets the selection color of the labels.
      Parameters:
      aLabelSelectionColor - The label selection color.
      See Also:
    • getLabelSelectionColor

      public Color getLabelSelectionColor()
      Returns the selection color of the labels.
      Returns:
      the selection color of the labels.
      See Also:
    • setLabelFrame

      public void setLabelFrame(boolean aLabelFrame)
      Labels can be drawn surrounded by a frame, the frame property determines whether to frame the labels or not.
      Parameters:
      aLabelFrame - True if the labels should be surrounded by a frame, false otherwise.
      See Also:
    • isLabelFrame

      public boolean isLabelFrame()
      Returns true if the labels are surrounded by a frame, false otherwise.
      Returns:
      true if the labels are surrounded by a frame, false otherwise.
      See Also:
    • setLabelRotationAllowed

      public void setLabelRotationAllowed(boolean aLabelRotationAllowed)
      Labels can be rotated so that they have the same angle as the polyline. The rotationAllowed property determines whether it is allowed to rotate labels.
      Parameters:
      aLabelRotationAllowed - True if the labels can be rotated, false otherwise.
      See Also:
    • isLabelRotationAllowed

      public boolean isLabelRotationAllowed()
      Returns true if the labels can be rotated along the polyline, false otherwise.
      Returns:
      true if the labels can be rotated along the polyline, false otherwise.
      See Also:
    • setLabelFilled

      public void setLabelFilled(boolean aLabelFilled)
      Sets if a filled rectangle should be painted behind the labels. The rectangle is filled with the getLabelBackground() color.
      Parameters:
      aLabelFilled - True if a filled rectangle is painted behind the labels, false otherwise.
      See Also:
    • isLabelFilled

      public boolean isLabelFilled()
      Returns true if a filled rectangle should be painted behind the labels.
      Returns:
      true if a filled rectangle should be painted behind the labels.
      See Also:
    • setLabelVGap

      public void setLabelVGap(int aVerticalGap)
      Sets the orthogonal distance (in pixels) between the label and the line segment. This property allows to define a shift on top of the alignment.
      Parameters:
      aVerticalGap - The orthogonal distance (in pixels) between the label and the line segment.
      See Also:
    • getLabelVGap

      public int getLabelVGap()
      Returns the orthogonal distance (in pixels) between the label and the line segment.
      Returns:
      the orthogonal distance (in pixels) between the label and the line segment.
      See Also:
    • getDistanceFormat

      public Format getDistanceFormat()
      Returns the distance format used to format distances and display them to the user. The default format displays the distance as kilometers.
      Returns:
      The distance format.
      See Also:
    • setDistanceFormat

      public void setDistanceFormat(Format aDistanceFormat)
      Sets the distance format to use to format distances to be displayed to the user.
      Parameters:
      aDistanceFormat - The new distance format
      See Also:
    • getHotPointIcon

      public ILcdIcon getHotPointIcon()
      Returns the hot point icon, it can be null.
      Returns:
      the hot point icon, it can be null.
      See Also:
    • setHotPointIcon

      public void setHotPointIcon(ILcdIcon aHotPointIcon)
      Sets the hot point icon, used to paint the handles on the measurement line.
      Parameters:
      aHotPointIcon - The hot point icon, or null for a default icon.
      See Also:
    • createGXYLayer

      protected TLcdGXYLayer createGXYLayer()
      Create a new layer used for storing the measurements.

      The default implementation returns a new TLcdGXYLayer.

      Returns:
      a new layer used for storing the measurements.
    • recalculateMeasureMents

      protected void recalculateMeasureMents()
      Invalidates the calculations. This method should be called when a property is updated which affects the measurement between two points.
    • createGXYPolylinePainter

      protected ILcdGXYPainter createGXYPolylinePainter()
      Creates the painter for the polylines used to measure the distances.

      The painter must accept objects of type 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.

      Returns:
      ILcdGXYPainter that accepts ILcd3DEditablePolyline objects.
    • createGXYPolylineEditor

      protected ILcdGXYEditor createGXYPolylineEditor()
      Creates the editor for the polylines used to measure the distances.

      The editor must accept objects of type 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.

      Returns:
      ILcdGXYEditor that accepts ILcd3DEditablePolyline objects.
    • createGXYEqualDistanceCurvePainter

      protected ILcdGXYPainter createGXYEqualDistanceCurvePainter()
      Creates the painter of the equal distance curve for the polylines used to measure the distances.

      The painter/editor must accepts objects of type 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.

      Returns:
      ILcdGXYPainter that accepts ILcd3DEditablePolyline objects and paints the equal distance curve when the polyline is modified.
    • createGXYLabelPainter

      protected ILcdGXYLabelPainter createGXYLabelPainter()
      Creates the label painter for the distance labels (or maybe angle labels, etc).

      You might want to return a 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):

      • index 0: the total distance of the line as a Double
      • index 1: this property is a list property of type double (the feature value is as such a Vector of Doubles) containing the distance in meters for every segment
      • index 2: this property is also a list property of type double containing the azimuth in degrees of every segment.
      All these values can be null if certain calculations are not available.

      The properties of the returned painter must be synchronized with the properties of this controller. For example, if the distanceFormat of this controller is changed, the returned label 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 label painter.

      Returns:
      The ILcdGXYLabelPainter responsible to paint the distance labels etc.
    • createGXYLayerLabelPainter

      protected ILcdGXYLayerLabelPainter createGXYLayerLabelPainter()
      Creates the ILcdGXYLayerLabelPainter for the ruler controller. This painter is used to position the different labels, so it contains the label decluttering logic.
      Returns:
      The ILcdGXYLayerLabelPainter responsible to position the labels.
    • calculateDistance

      protected double calculateDistance(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdGeoReference aGeoReference, int aMeasureMode, ILcdGXYContext aGXYContext)
      Calculates the distance in meters between the two given points.
      Parameters:
      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_PLANE
      aGXYContext - The context.
      Returns:
      The distance in meters between the two points, or Double.NaN if no distance calculation can be performed. Please note that Double.NaN == Double.NaN always returns false, one must use Double.isNaN( double ).
    • calculateAzimuth

      protected double calculateAzimuth(ILcdPoint aPoint1, ILcdPoint aPoint2, ILcdGeoReference aGeoReference, int aMeasureMode, ILcdGXYContext aGXYContext)
      Calculates the azimuth in degrees between the two given points. 0 degrees is at 12 o clock, positive clock wise.
      Parameters:
      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_PLANE
      aGXYContext - The context.
      Returns:
      The azimuth in degrees between the points, or Double.NaN if no azimuth calculation can be performed. Please note that Double.NaN == Double.NaN always returns false, one must use Double.isNaN( double ).