Class TLcdGXYCompositeRingPainter

All Implemented Interfaces:
ILcdCloneable, ILcdDeepCloneable, ILcdPropertyChangeSource, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdGXYPainter, ILcdGXYPainterProvider, ILcdGXYPathPainter, Serializable, Cloneable

public class TLcdGXYCompositeRingPainter extends ALcdGXYAreaPainter implements ILcdGXYPathPainter, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdDeepCloneable
Paints and locates composite ring objects, i.e. objects that are of type ILcdCompositeCurve and ILcdRing, and enables visual editing of editable composite ring objects, i.e. objects that are of type ILcdEditableCompositeCurve and ILcdRing, in an ILcdGXYView.

Painting a composite ring

Body

This painter provides support for painting a composite ring object. For each curve of the composite ring, a painter is retrieved via the set painter provider.. The retrieved painter is then used to paint the corresponding ILcdCurve object. Note that this implementation assumes that a painter can be provided for each curve of the composite ring. Also, the painter must implement ILcdGXYPathPainter.

Handles

This painter does not define a handle for composite ring objects. However, the handles for each individual ILcdCurve object are defined by the corresponding painter for that curve.

Snap targets

This painter will process all ILcdCurve objects in the composite ring object and tries to retrieve a snap target for each curve using the corresponding painter. The first snap target that is found, is used as snap target for this TLcdGXYCompositeRingPainter.

Styling options

The visualization of the composite ring object is governed by the line style, fill style, and painter provider set to this painter. The painter provider is responsible for providing a painter to be used for painting each of the individual ILcdCurve objects contained in the composite ring object.

Locating a composite ring in a view

Anchor point of a composite ring

When the composite ring object only contains one ILcdCurve object, the anchor point of that object is used as anchor point for the composite ring. If more ILcdCurve objects are available, the center point of the bounds, calculated by boundsSFCT, is used.

When is a composite ring touched

The composite ring object is touched when one of the ILcdCurve objects in the composite ring is touched.

Visually editing and creating a composite ring

Modifying a composite ring

This implementation translates either the touched handle or the entire composite curve for ILcdGXYEditor.TRANSLATED, and translates the touched sub curve if the user drags with ILcdGXYEditor.RESHAPED. Note that this behavior relies on the sub curve painter's isTouched method to distinguish between touching the curve body and the handles. Other edit operations are passed onto the first touched sub curve that is successfully edited. For every shape that has to be edited, an editor is retrieved via the set editor provider. The retrieved editor is then used to edit the corresponding ILcdCurve object.

Similarly to the painter provider, the editor provider is responsible for providing an editor to be used for editing the individual ILcdCurve objects contained in the composite ring object. Note that this implementation assumes that an editor can be provided for each shape of the composite ring.

Creating a composite ring

When initializing an composite ring object via interaction through the view, only the last curve object is edited. The number of user interactions required to complete the initialization is defined by the editor corresponding to the last ILcdCurve object.

Accepted snap targets

This painter accepts a snap target if at least one of the curve editors returned by the curve editor provider accepts the snap target.

Since:
9.0
See Also:
  • Field Details

    • MIDDLE_OF_BOUNDS

      public static final int MIDDLE_OF_BOUNDS
      Constant value indicating that the anchor point should be chosen in the middle of the bounds, calculated by boundsSFCT.
      See Also:
    • FOCUS_POINT

      public static final int FOCUS_POINT
      Constant value indicating that the anchor point should be chosen as the focus point of the composite ring. This focus point is first retrieved in model coordinates, and then transformed to view coordinates. If this point cannot be retrieved, the MIDDLE_OF_BOUNDS method is used.
      See Also:
    • ONE_RING_ANCHOR_POINT

      public static final int ONE_RING_ANCHOR_POINT
      Constant value indicating that the anchor point should be chosen as the anchor point of the only ring in the composite ring. If more than one ring exists in the composite ring, the MIDDLE_OF_BOUNDS method is used.
      See Also:
    • FIRST_POSSIBLE_RING_ANCHOR_POINT

      public static final int FIRST_POSSIBLE_RING_ANCHOR_POINT
      Constant value indicating that the anchor point should be chosen at the anchor point of the first possible ring. If this point is invalid, then the second ring is used, and so on... If no valid anchor point can be found, the MIDDLE_OF_BOUNDS method is used.
      See Also:
  • Constructor Details

  • Method Details

    • getAnchorPointLocation

      public int getAnchorPointLocation()
      Returns the location of the anchor point (by default: ONE_RING_ANCHOR_POINT).
      Returns:
      one of MIDDLE_OF_BOUNDS, FOCUS_POINT, ONE_RING_ANCHOR_POINT, FIRST_POSSIBLE_RING_ANCHOR_POINT.
    • setAnchorPointLocation

      public void setAnchorPointLocation(int aAnchorPointLocation)
      Sets the preferred anchor point location.
      Parameters:
      aAnchorPointLocation - one of MIDDLE_OF_BOUNDS, FOCUS_POINT, ONE_RING_ANCHOR_POINT, FIRST_POSSIBLE_RING_ANCHOR_POINT.
    • paint

      public void paint(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
      Displays the representation of the object in the given mode on the Graphics passed, taking into account the context passed.

      This implementation will retrieve a painter for all ILcdCurve objects inside the composite ring object using the set painter provider and will use that painter to paint the corresponding shape.

      Specified by:
      paint in interface ILcdGXYPainter
      Parameters:
      aGraphics - The graphics to paint the object on.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context to render the object in.
    • isTouched

      public boolean isTouched(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
      Description copied from interface: ILcdGXYPainter
      Checks if the representation of the object in the given mode is touched at the location as defined in the supplied context.

      The location that must be taken into account to check whether the representation is touched can be retrieved from the context passed with the methods ILcdGXYContext.getX() and ILcdGXYContext.getY(). If the check is part of an ongoing operation of user interaction, for example, when the mouse is being dragged, the location of the start of the operation can also be taken into account using the methods ILcdGXYContext.getDeltaX() and ILcdGXYContext.getDeltaY(). The context contains the transformations required to convert this location into the equivalent location in model space. Implementations of this interface usually follow either of the following patterns:

      • transform the location of the interaction back to model space and compare the coordinates with the object in model space.
      • transform the location to world space and compare with a world representation of the object. This forces the painter into caching a world representation of the object. Caching a view representation of an object is not very practical as it would have to change whenever the view's scale changes or when it is panned. A world representation of an object only changes when the view's XYWorldReference changes, which happens less frequently.

      As the mode influences the way an object is represented, it must also be taken into account when checking whether that representation is being touched. When the mode contains CREATING, RESHAPING or TRANSLATING which indicate that the object must be represented in a state for an ongoing operation, the location of the start of the operation may be taken into account as mentioned above. The painting result can take into account multiple locations, to respond to, for example, multi-touch input. When the mode contains SELECTED, the painter should also check if the non-selected representation is touched, since these are always painted on top of each other.

      The boundsSFCT is often used to speed up the performance of this method as a location outside these bounds can never touch the representation of the object.

      Note that this method does not give an indication of what part of the object is touched. It is up to the painter implementations to provide methods to make this distinction. The method does also not indicate what sensitivity must be applied when checking if an object is touched. It is up to the implementation to decide what should be the maximum distance between the location given in the context and the closest relevant point or area of the representation of the object.

      Specified by:
      isTouched in interface ILcdGXYPainter
      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aMode - the mode the object is represented in
      aGXYContext - contains the location of the interaction and the transformations to convert this location into model coordinates
      Returns:
      true if the representation of the object in the given mode is touched by the location as defined in the context passed, false otherwise
      See Also:
    • getCursor

      public Cursor getCursor(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
      Returns a Cursor that clarifies the render mode and context this painter is operating in. When no specific Cursor is required, null is returned.
      Specified by:
      getCursor in interface ILcdGXYPainter
      Overrides:
      getCursor in class ALcdGXYPainter
      Parameters:
      aGraphics - The graphics on which the object is painted.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context in which the object is rendered.
      Returns:
      a cursor to indicate the type of operating mode and context. Returns null if no particular cursor is required.
    • getGXYEditor

      public ILcdGXYEditor getGXYEditor(Object aObject)
      Returns this instance as editor for editing the specified Object. If this Object is not the same as the Object set to this painter, the setObject(Object) method is called to update the object set to the painter.
      Specified by:
      getGXYEditor in interface ILcdGXYEditorProvider
      Parameters:
      aObject - the object to be edited.
      Returns:
      this instance as editor for editing the specified Object.
    • setObject

      public void setObject(Object aObject)
      Description copied from interface: ILcdGXYPainter
      Sets the Object for which the representation shall be handled by this painter.

      Setting the object on the painter may have an effect on the internal state of the painter, for example, the color to use.

      When the object is set to a painter, the context parameter in subsequent calls to methods in this class must contain a layer that contains this object and for which the painter for this object is this painter.

      Specified by:
      setObject in interface ILcdGXYEditor
      Specified by:
      setObject in interface ILcdGXYPainter
      Parameters:
      aObject - the object for which the representation shall be handled by this painter.
      See Also:
    • getObject

      public Object getObject()
      Description copied from interface: ILcdGXYPainter
      Returns the Object for which the representation is currently being handled by this painter.
      Specified by:
      getObject in interface ILcdGXYEditor
      Specified by:
      getObject in interface ILcdGXYPainter
      Returns:
      the Object for which the representation is currently being handled by this painter.
      See Also:
    • setCurveGXYPainterProvider

      public void setCurveGXYPainterProvider(ILcdGXYPainterProvider<ILcdGXYPathPainter> aCurveGXYPainterProvider)
      Sets the painter provider used to provide a painter for each shape inside the composite ring.
      Parameters:
      aCurveGXYPainterProvider - the painter provider for the ILcdCurve objects inside the composite ring object.
      See Also:
    • getCurveGXYPainterProvider

      public ILcdGXYPainterProvider<ILcdGXYPathPainter> getCurveGXYPainterProvider()
      Returns the painter provider used to provide a painter for each shape inside the composite ring.
      Returns:
      the painter provider used to provide a painter for each shape inside the composite ring.
      See Also:
    • setCurveGXYEditorProvider

      public void setCurveGXYEditorProvider(ILcdGXYEditorProvider aCurveGXYEditorProvider)
      Sets the editor provider used to provide an editor for each shape inside the composite ring.
      Parameters:
      aCurveGXYEditorProvider - the editor provider for the ILcdCurve objects inside the composite ring object.
      See Also:
    • getCurveGXYEditorProvider

      public ILcdGXYEditorProvider getCurveGXYEditorProvider()
      Returns the editor provider used to provide an editor for each shape inside the composite ring.
      Returns:
      the editor provider used to provide an editor for each shape inside the composite ring.
      See Also:
    • setCurveConnectorProvider

      public void setCurveConnectorProvider(ILcdCurveConnectorProvider aCurveConnectorProvider)
      Sets a connector provider to ensure connectivity during editing operations.
      Parameters:
      aCurveConnectorProvider - a connector provider that returns a connector for the curve types encountered in every composite ring.
      See Also:
    • getCurveConnectorProvider

      public ILcdCurveConnectorProvider getCurveConnectorProvider()
      Returns the curve provider used to provider a curve connector for each shape inside the composite ring.
      Returns:
      the curve provider used to provider a curve connector for each shape inside the composite ring.
      See Also:
    • setPaintCache

      public void setPaintCache(boolean aPaintCache)
      Turns caching of the representation of the object on or off. Caching greatly reduces the time to paint an object but requires more memory. The representation of an object can only be cached for objects which implement ILcdCache. By default, caching is turned on.
      Parameters:
      aPaintCache - A flag indicating whether to use caching when painting an object.
      See Also:
    • getPaintCache

      public boolean getPaintCache()
      Returns whether caching is used when painting this painter's object.
      Returns:
      true if caching is used to paint this painter's object, false otherwise.
      See Also:
    • edit

      public boolean edit(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)

      This implementation translates either the touched handle or the entire composite curve for ILcdGXYEditor.TRANSLATED, and translates the touched sub curve if the user drags with ILcdGXYEditor.RESHAPED. Note that this behavior relies on the sub curve painter's isTouched method to distinguish between touching the curve body and the handles. Other edit operations are passed onto the first touched sub curve that is successfully edited. For every shape that has to be edited, an editor is retrieved via the set editor provider. The retrieved editor is then used to edit the corresponding ILcdCurve object.

      In the creation render modes, only the last ILcdCurve object is edited.

      Specified by:
      edit in interface ILcdGXYEditor
      Parameters:
      aGraphics - The graphics to edit the object on.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context to render the object in.
      Returns:
      true if the object has changed when this method returns, false otherwise.
      See Also:
    • anchorPointSFCT

      public void anchorPointSFCT(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext, Point aPointSFCT) throws TLcdNoBoundsException

      Moves the specified aPointSFCT to the anchor point of the ILcdRing object. If the ring only contains one object, the anchor point of that object is used. When more shapes are available in the composite ring, the center point of the bounds, calculated by boundsSFCT, is used

      Specified by:
      anchorPointSFCT in interface ILcdGXYPainter
      Overrides:
      anchorPointSFCT in class ALcdGXYPainter
      Parameters:
      aGraphics - The graphics to paint the object on.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context to render the object in.
      aPointSFCT - The point that needs to be updated.
      Throws:
      TLcdNoBoundsException - if the composite ring object doesn't have a valid anchor point, e.g. if it is always invisible in the current projection.
      See Also:
    • supportSnap

      public boolean supportSnap(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Supports snapping when at least one of the painters of the shapes inside the composite ring object supports snapping.

      Specified by:
      supportSnap in interface ILcdGXYPainter
      Overrides:
      supportSnap in class ALcdGXYPainter
      Parameters:
      aGraphics - the graphics on which is worked.
      aGXYContext - the context of the snapping.
      Returns:
      true if one of the painters for the shapes inside the composite ring object supports snapping, false otherwise.
    • snapTarget

      public Object snapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Returns the first snap target that was found by the painters of the shapes inside the composite ring object. If no point was touched, null will be returned.

      Specified by:
      snapTarget in interface ILcdGXYPainter
      Overrides:
      snapTarget in class ALcdGXYPainter
      Parameters:
      aGraphics - the graphics on which is worked.
      aGXYContext - the context of the snapping.
      Returns:
      the first snap target that was found by the painters of the shapes inside the composite ring object, null otherwise.
      See Also:
    • boundsSFCT

      public void boundsSFCT(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
      Sets the supplied bounds (in view coordinates, pixels) so that it encompasses the representation of the object in the given mode taking into account the given context.

      If this method returns without exception the bounds argument must encompass the representation of the object. A point outside the bounds will not be contained within the painted object.

      The bounds returned in this method can be seen as the equivalent in the view space of the bounds in the model space for ILcdBounded objects.

      Specified by:
      boundsSFCT in interface ILcdGXYPainter
      Parameters:
      aGraphics - The graphics to paint the object on.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context to render the object in.
      aBoundsSFCT - The bounds to update.
      Throws:
      TLcdNoBoundsException - if no bounds can be determined for the representation of the object. This can happen when the object does not have a representation in the given context, for example when it is located in a part of the world which is not visible in the current view.
      See Also:
    • getCreationClickCount

      public int getCreationClickCount()
      Returns the number of user interactions required to complete the initialization of the ILcdRing object set to this editor. This method will return the number of user interactions required by the editor corresponding to the last ILcdCurve object.
      Specified by:
      getCreationClickCount in interface ILcdGXYEditor
      Returns:
      the number of user interactions required by the editor corresponding to the last ILcdCurve object.
    • acceptSnapTarget

      public boolean acceptSnapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Determines whether a snap target should be accepted or not. A snap target is accepted if at least one of the curve editors returned by the curve editor provider accepts the snap target.

      Specified by:
      acceptSnapTarget in interface ILcdGXYEditor
      Parameters:
      aGraphics - the graphics on which the snap target should be checked.
      aGXYContext - the context in which the snap target should be checked.
      Returns:
      true if at least one of the curve editors returned by the curve editor provider accepts the snap target, false otherwise.
      See Also:
    • appendAWTPath

      public boolean appendAWTPath(ILcdGXYContext aGXYContext, int aRenderMode, ILcdAWTPath aAWTPathSFCT)
      Description copied from interface: ILcdGXYPathPainter
      Appends a discretized representation in view coordinates to the given path.
      Specified by:
      appendAWTPath in interface ILcdGXYPathPainter
      Parameters:
      aGXYContext - the graphics context
      aRenderMode - the rendering mode
      aAWTPathSFCT - the path to append to
      Returns:
      true if a discretization of the shape could be successfully appended to the path
    • appendGeneralPath

      public boolean appendGeneralPath(ILcdGXYContext aGXYContext, int aRenderMode, ILcdGeneralPath aGeneralPathSFCT)
      Description copied from interface: ILcdGXYPathPainter
      Appends a discretized representation in world coordinates to the given path.
      Specified by:
      appendGeneralPath in interface ILcdGXYPathPainter
      Parameters:
      aGXYContext - the graphics context
      aRenderMode - the rendering mode
      aGeneralPathSFCT - the path to append to
      Returns:
      true if a discretization of the shape could be successfully appended to the path
    • clone

      public Object clone(Map aObjectDictionary)
      Description copied from interface: ILcdDeepCloneable
      Returns a deep clone of this Object.

      An object dictionary is used to keep track of all objects of the original Object graph, for which a clone has already been created. The dictionary should be a java.util.Map, using reference-equality instead of object-equality when comparing keys (such as the java.util.IdentityHashMap). It contains as keys the objects in the original object graph that have already been cloned, and as values their corresponding clone.

      The Object returned by this method should fulfill the following conditions, as specified in the general Object.clone() contract:

      • this.clone(aObjectDictionary) != this
      • this.clone(aObjectDictionary).getClass() == this.getClass()
      • this.clone(aObjectDictionary).equals(this)

      In addition, the following conditions should also hold:

      • If a clone of this Object already exists in the object dictionary before this clone method is called, this method shall return that clone:
        aObjectDictionary.get(this) == null || aObjectDictionary.get(this) == this.clone(aObjectDictionary)
      • The object dictionary shall contain the resulting clone, after this clone method has completed:
        this.clone(aObjectDictionary) == aObjectDictionary.get(this)
      Specified by:
      clone in interface ILcdDeepCloneable
      Parameters:
      aObjectDictionary - the Object dictionary that keeps track of the objects for which a clone has already been made, and their corresponding clone Object.
      Returns:
      a deep clone of this Object that fulfills the conditions described above.
    • clone

      public Object clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from java.lang.Object, it can be implemented like this:
      
       public Object clone() {
         try {
           return super.clone();
         } catch ( CloneNotSupportedException e ) {
           // Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
           throw new RuntimeException( e );
         }
       }
       
      Specified by:
      clone in interface ILcdCloneable
      Specified by:
      clone in interface ILcdGXYEditorProvider
      Specified by:
      clone in interface ILcdGXYPainterProvider
      Overrides:
      clone in class ALcdGXYAreaPainter
      Returns:
      a clone of this painter provider.
      See Also: