Class ALcd2DEditableLine

All Implemented Interfaces:
ILcdBounded, ILcdPointList, ILcdPolyline, ILcdShape, ILcd2DEditablePointList, ILcd2DEditablePolyline, ILcd2DEditableShape, ILcdCache, ILcdCloneable, Serializable, Cloneable
Direct Known Subclasses:
ALcd3DEditableLine, TLcdLonLatLine, TLcdXYLine

public abstract class ALcd2DEditableLine extends ALcd2DEditableShape implements ILcd2DEditablePolyline, ILcdCache
This abstract class provides a basis for implementing the ILcd2DEditablePolyline interface, where the polyline is a simple line with two vertices.

It implements ILcdCache, thus providing a cache to store expensive calculations, e.g. for painters, to store model-world transformations. The cache is cleared whenever the line is moved or translated.

This class has a focus point cache. For for computing the focus point, implementations may override the method calculateFocusPoint(). The default implementation computes the center of the bounding box. The result of calculateFocusPoint() is only used if the focus point has not been set explicitly using setFocusPoint(ILcdPoint).

This class is thread-safe for concurrent read-only access of its contents. For read-write access, external locking must be used. Such locking is typically done at the model level.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • getPointCount

      public final int getPointCount()
      Description copied from interface: ILcdPointList
      Returns the number of ILcdPoint objects in the list.
      Specified by:
      getPointCount in interface ILcdPointList
      Returns:
      the number of ILcdPoint objects in the list.
    • getPoint

      public final ILcdPoint getPoint(int aIndex)
      Description copied from interface: ILcdPointList
      Returns the ILcdPoint at a given index.
      Specified by:
      getPoint in interface ILcdPointList
      Parameters:
      aIndex - a valid index in the list of ILcdPoint objects.
      Returns:
      the ILcdPoint at the given index.
    • move2DPoint

      public void move2DPoint(int aIndex, double aX, double aY)
      Description copied from interface: ILcd2DEditablePointList
      Moves the specified point of this ILcd2DEditablePointList to the given point in the 2D space. Only the first two dimensions of the ILcdShape are considered. The third dimension is left unchanged.
      Specified by:
      move2DPoint in interface ILcd2DEditablePointList
      Parameters:
      aIndex - a valid index in the list of points.
      aX - the x coordinate of the point.
      aY - the y coordinate of the point.
    • translate2DPoint

      public void translate2DPoint(int aIndex, double aDeltaX, double aDeltaY)
      Description copied from interface: ILcd2DEditablePointList
      Translates the specified point of this ILcd2DEditablePointList from its current position over the given translation vector in the 2D space. Only the first two dimensions of the points are considered. The third dimension is left unchanged.
      Specified by:
      translate2DPoint in interface ILcd2DEditablePointList
      Parameters:
      aDeltaX - the x coordinate of the translation vector.
      aDeltaY - the y coordinate of the translation vector.
    • insert2DPoint

      public void insert2DPoint(int aIndex, double aX, double aY)
      Is not allowed, as a TLcdXYLine always contains two points.
      Specified by:
      insert2DPoint in interface ILcd2DEditablePointList
      Parameters:
      aIndex - a valid new index in the list of points.
      aX - the x coordinate of the new point.
      aY - the y coordinate of the new point.
    • removePointAt

      public void removePointAt(int aIndex)
      Is not allowed, as a TLcdXYLine always contains two points.
      Specified by:
      removePointAt in interface ILcd2DEditablePointList
      Parameters:
      aIndex - a valid index in the list of ILcdPoint objects.
    • invalidateBounds

      protected void invalidateBounds()
    • calculateBounds

      protected abstract void calculateBounds()
      This method should compute the bounds of the polypoint. The resulting ILcd2DEditableBounds should be stored in fBounds.
    • getBounds

      public ILcdBounds getBounds()
      Description copied from interface: ILcdBounded
      Returns the ILcdBounds by which the geometry of this ILcdBounded object is bounded.

      If the geometry does not allow retrieving valid bounds (for example a polyline with 0 points) the return value is unspecified. It is highly recommended to return an undefined bounds. You can create undefined bounds using the default constructors of TLcdLonLatBounds or TLcdXYBounds.

      Specified by:
      getBounds in interface ILcdBounded
      Returns:
      the ILcdBounds by which the geometry of this ILcdBounded object is bounded.
    • calculateFocusPoint

      protected void calculateFocusPoint()
      Computes the focus point as the center of the bounding box. The resulting ILcd2DEditablePoint is stored in fFocusPoint.
    • getFocusPoint

      public ILcdPoint getFocusPoint()
      Description copied from interface: ILcdShape
      Returns the focus point of this ILcdShape.
      Specified by:
      getFocusPoint in interface ILcdShape
      Returns:
      the focus point of this ILcdShape.
    • setFocusPoint

      public void setFocusPoint(ILcd2DEditablePoint aFocusPoint)
    • contains2D

      public boolean contains2D(double aX, double aY)
      Description copied from interface: ILcdShape
      Checks whether this ILcdShape contains the given point in the 2D space. Only the first two dimensions of the ILcdShape are considered.
      Specified by:
      contains2D in interface ILcdShape
      Parameters:
      aX - the x coordinate of the point.
      aY - the y coordinate of the point.
      Returns:
      the boolean result of the containment test.
    • translate2D

      public void translate2D(double aDeltaX, double aDeltaY)
      Description copied from interface: ILcd2DEditableShape
      Translates this ILcd2DEditableShape from its current position over the given translation vector in the 2D space. Only the first two dimensions of the ILcdShape are considered. The third dimension is left unchanged.
      Specified by:
      translate2D in interface ILcd2DEditablePointList
      Specified by:
      translate2D in interface ILcd2DEditableShape
      Parameters:
      aDeltaX - the x coordinate of the translation vector.
      aDeltaY - the y coordinate of the translation vector.
    • move2D

      public void move2D(double aX, double aY)
      Description copied from class: ALcd2DEditableShape
      Translates this shape so that its focus point ends up at the specified position.
      Specified by:
      move2D in interface ILcd2DEditableShape
      Overrides:
      move2D in class ALcd2DEditableShape
      Parameters:
      aX - the x coordinate of the point.
      aY - the y coordinate of the point.
    • insertIntoCache

      public void insertIntoCache(Object aKey, Object aObject)
      Description copied from interface: ILcdCache
      Inserts a cache Object corresponding to the given key Object.
      Specified by:
      insertIntoCache in interface ILcdCache
      Parameters:
      aKey - the key Object that will be used to identify the Object. The key must therefore be a unique identifier, typically the caller itself: insertIntoCache(this, ...).
      aObject - the Object to be cached.
    • getCachedObject

      public Object getCachedObject(Object aKey)
      Description copied from interface: ILcdCache
      Looks up and returns the cached Object corresponding to the given key.
      Specified by:
      getCachedObject in interface ILcdCache
      Parameters:
      aKey - the key Object that was used for storing the cache Object.
      Returns:
      the cached Object, or null if there is no Object corresponding to the given key.
    • removeCachedObject

      public Object removeCachedObject(Object aKey)
      Description copied from interface: ILcdCache
      Looks up and removes the cached Object corresponding to the given key.
      Specified by:
      removeCachedObject in interface ILcdCache
      Parameters:
      aKey - the key Object that was used for storing the cache Object.
      Returns:
      the cached Object, or null if there was no Object corresponding to the given key.
    • clearCache

      public void clearCache()
      Description copied from interface: ILcdCache
      Clears the cache.
      Specified by:
      clearCache in interface ILcdCache
    • clone

      public Object clone()
      Creates and returns a copy of this object.

      The points are copied without being cloned.

      The cache, the bounds and the focus point are not copied or cloned at all, but recalculated when needed.

      Specified by:
      clone in interface ILcdCloneable
      Overrides:
      clone in class ALcdShape
      See Also:
    • equals

      public boolean equals(Object aObject)
      Returns whether the given object has the same class, the same focus point, and the same coordinates.
      Overrides:
      equals in class ALcdShape
    • hashCode

      public int hashCode()
      Description copied from class: ALcdShape
      The hash code of this shape is the hash code of its class, in order to be consistent with the ALcdShape.equals(Object) method. Extensions should refine this implementation, based on their properties.
      Overrides:
      hashCode in class ALcdShape
    • toString

      public String toString()
      Overrides:
      toString in class Object