Class TLcdGXYShapeListPainter

java.lang.Object
com.luciad.view.gxy.ALcdGXYPainter
com.luciad.view.gxy.painter.TLcdGXYShapeListPainter
All Implemented Interfaces:
ILcdCloneable, ILcdDeepCloneable, ILcdPropertyChangeSource, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdGXYPainter, ILcdGXYPainterProvider, ILcdGXYPathPainter, Serializable, Cloneable
Direct Known Subclasses:
TLcdGXYAreaShapeListPainter, TLcdGXYPointShapeListPainter, TLcdGXYPolylineShapeListPainter, TLcdGXYRoutePainter

public class TLcdGXYShapeListPainter extends ALcdGXYPainter implements ILcdGXYPathPainter, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdDeepCloneable
Paints and locates ILcdShapeList objects and enables visual editing of ILcdShapeList objects in an ILcdGXYView.

Painting an ILcdShapeList

Body

This painter provides support for painting an ILcdShapeList object. For each shape of the shape list, a painter is retrieved via the method retrieveShapePainter. The retrieved painter is then used to paint the corresponding ILcdShape object.

In theory, calling this painter recursively would cause problems, since the method setObject(Object) is then called repeatedly inside the recursion, each time overwriting the higher level shape lists. However, this implementation takes care of this case, by storing and restoring the shape lists whenever necessary.

Handles

This painter does not define a handle for ILcdShapeList objects. However, the handles for each individual ILcdShape object are defined by the corresponding painter for that shape.

Snap targets

This painter will process all ILcdShape objects in the ILcdShapeList object and tries to retrieve a snap target for each shape using the corresponding painter. The first snap target that is found, is used as snap target for this TLcdGXYShapeListPainter.

Styling options

The visualization of the ILcdShapeList object is governed by the painter provider set to this painter. The painter provider is responsible for providing a painter to be used for painting each of the individual ILcdShape objects contained in the ILcdShapeList object. Note that this implementation assumes that a painter can be provided for each shape of the shape list.

Locating an ILcdShapeList in a view

Anchor point of an ILcdShapeList

When the ILcdShapeList object only contains one ILcdShape object, the anchor point of that object is used as anchor point for the shape list. If more ILcdShape objects are available, the center point of the bounds, calculated by boundsSFCT, is used.

When is an ILcdShapeList touched

The ILcdShapeList object is touched when one of the ILcdShape objects in the shape list is touched.

Visually editing and creating an ILcdShapeList

Modifying an ILcdShapeList

Depending on the editTouchedOnly property, all shape objects of the shape list need to be edited or only the touched objects. An exception to this is when a handle is edited: this only affects the objects whose handle is touched.
For every shape object that has to be edited, an editor is retrieved via the method retrieveShapeEditor. The retrieved editor is then used to edit the corresponding ILcdShape object.

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

Creating an ILcdShapeList

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

Accepted snap targets

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

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 shape list. If this point cannot be retrieved, the middle of the bounds are returned.
      See Also:
    • ONE_SHAPE_ANCHOR_POINT

      public static final int ONE_SHAPE_ANCHOR_POINT
      Constant value indicating that the anchor point should be chosen as the anchor point of the only shape in the shape list. If the shape list contains more than one shape, or if the only shape cannot provide an anchor point, the middle of the bounds are returned.
      See Also:
    • FIRST_POSSIBLE_SHAPE_ANCHOR_POINT

      public static final int FIRST_POSSIBLE_SHAPE_ANCHOR_POINT
      Constant value indicating that the anchor point should be the anchor point of the first possible shape in the shape list. If the first shape can't provide an anchor point, the second shape is used, and so on... If no shape in the shape list can provide an anchor point, the middle of the bounds are used.
      See Also:
    • fShapeGXYPainterProvider

      protected ILcdGXYPainterProvider fShapeGXYPainterProvider
      The painter provider to retrieve painters for the objects inside the ILcdShapeList object.
    • fShapeGXYEditorProvider

      protected ILcdGXYEditorProvider fShapeGXYEditorProvider
      The editor provider to retrieve editors for the objects inside the ILcdShapeList object.
  • Constructor Details

  • Method Details

    • setShapeGXYPainterProvider

      public void setShapeGXYPainterProvider(ILcdGXYPainterProvider aShapeGXYPainterProvider)
      Sets the painter provider used to provide a painter for each shape inside the shape list.
      Parameters:
      aShapeGXYPainterProvider - the painter provider for the ILcdShape objects inside the ILcdShapeList object.
      See Also:
    • getShapeGXYPainterProvider

      public ILcdGXYPainterProvider getShapeGXYPainterProvider()
      Returns the painter provider used to provide a painter for each shape inside the shape list.
      Returns:
      the painter provider used to provide a painter for each shape inside the shape list.
      See Also:
    • retrieveShapePainter

      protected ILcdGXYPainter retrieveShapePainter(ILcdShapeList aShapeList, int aShapeIndex)
      Returns the painter for the shape at the given index in the ILcdShapeList object.
      Parameters:
      aShapeList - The shape list containing the shape.
      aShapeIndex - The index of the shape within the shape list.
      Returns:
      the painter for the shape at the given index in the ILcdShapeList object.
    • setObject

      public void setObject(Object aObject)

      Sets the object to paint and edit. The object should be an instance of ILcdShapeList for painting and editing. When the object does not implement the ILcdShapeList interface, an IllegalArgumentException will be thrown.

      Specified by:
      setObject in interface ILcdGXYEditor
      Specified by:
      setObject in interface ILcdGXYPainter
      Parameters:
      aObject - The object to paint and edit.
      Throws:
      IllegalArgumentException - when the object does not implement ILcdShapeList.
      See Also:
    • getObject

      public final Object getObject()
      Returns the object that can currently be painted or edited by this painter/editor.
      Specified by:
      getObject in interface ILcdGXYEditor
      Specified by:
      getObject in interface ILcdGXYPainter
      Returns:
      the object that can currently be painted or edited by this painter/editor.
      See Also:
    • setEditTouchedOnly

      public final void setEditTouchedOnly(boolean aEditTouchedOnly)
      Determines whether only the touched ILcdShape objects in the ILcdShapeList object are edited or whether all shape objects should be edited. By default, this property is set to false.
      Parameters:
      aEditTouchedOnly - a flag indicating whether only the touched shapes are edited or all shapes.
      See Also:
    • isEditTouchedOnly

      public final boolean isEditTouchedOnly()
      Returns whether only the touched shape objects should be edited or all of them.
      Returns:
      whether only the touched shape objects should be edited or all of them.
      See Also:
    • getAnchorPointLocation

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

      public void setAnchorPointLocation(int aAnchorPointLocation)
      Sets the preferred anchor point location.
      Parameters:
      aAnchorPointLocation - one of MIDDLE_OF_BOUNDS, ONE_SHAPE_ANCHOR_POINT, FOCUS_POINT, FIRST_POSSIBLE_SHAPE_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 ILcdShape objects inside the ILcdShapeList object using the retrieveShapePainter method 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 aRenderMode, ILcdGXYContext aGXYContext)
      Returns whether one of the ILcdShape objects inside the ILcdShapeList object is touched.
      Specified by:
      isTouched in interface ILcdGXYPainter
      Parameters:
      aGraphics - The graphics to paint the object on.
      aRenderMode - The mode to render the object in.
      aGXYContext - The context in which the object is rendered.
      Returns:
      whether one of the ILcdShape objects inside the ILcdShapeList object is touched.
      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 ILcdShapeList object. See getAnchorPointLocation() on how the anchor point is calculated.

      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 ILcdShapeList 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 ILcdShapeList 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 ILcdShapeList 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 ILcdShapeList 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 ILcdShapeList 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:
    • 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.
    • setShapeGXYEditorProvider

      public void setShapeGXYEditorProvider(ILcdGXYEditorProvider aShapeGXYEditorProvider)
      Sets the editor provider used to provide an editor for each shape inside the shape list.
      Parameters:
      aShapeGXYEditorProvider - the editor provider for the ILcdShape objects inside the ILcdShapeList object.
      See Also:
    • getShapeGXYEditorProvider

      public ILcdGXYEditorProvider getShapeGXYEditorProvider()
      Returns the editor provider used to provide an editor for each shape inside the shape list.
      Returns:
      the editor provider used to provide an editor for each shape inside the shape list.
      See Also:
    • retrieveShapeEditor

      protected ILcdGXYEditor retrieveShapeEditor(ILcdShapeList aShapeList, int aShapeIndex)
      Returns the editor for the shape at the given index in the ILcdShapeList object.
      Parameters:
      aShapeList - The shape list containing the shape.
      aShapeIndex - The index of the shape within the shape list.
      Returns:
      the editor for the shape at the given index in the ILcdShapeList object.
    • edit

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

      This implementation edits, depending on the editTouchedOnly property, all ILcdShape objects of the ILcdShapeList object are edited or only the touched object. An exception to this is when a handle is edited: this only affects the objects whose handle is touched.
      For each shape object that has to be edited, an editor is retrieved via the method retrieveShapeEditor. The retrieved editor is then used to edit the corresponding ILcdShape object.

      In the creation render modes, only the last ILcdShape 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:
    • editShape

      protected boolean editShape(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext, ILcdGXYEditor aGXYEditor, ILcdShapeList aShapeList, int aIndex)
      Edits the shape at the specified index in aShapeList. This method is called by the edit method.
      Parameters:
      aGraphics - the graphics on which to edit.
      aRenderMode - the rendering mode.
      aGXYContext - the GXY context.
      aGXYEditor - the shape's editor
      aShapeList - the shape list to be edited.
      aIndex - the index of the shape to be edited.
      Returns:
      true if the shape has been edited, false otherwise.
    • getCreationClickCount

      public int getCreationClickCount()
      Returns the number of user interactions required to complete the initialization of the ILcdShapeList object set to this editor. This method will return the number of user interactions required by the editor corresponding to the last ILcdShape object.
      Specified by:
      getCreationClickCount in interface ILcdGXYEditor
      Returns:
      the number of user interactions required by the editor corresponding to the last ILcdShape 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 shape editors returned by the shape 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 shape editors returned by the shape editor provider accepts the snap target, false otherwise.
      See Also:
    • 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.
    • 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 ALcdGXYPainter
      Returns:
      a clone of this painter provider.
      See Also:
    • appendAWTPath

      public boolean appendAWTPath(ILcdGXYContext aGXYContext, int aRenderMode, ILcdAWTPath aAWTPathSFCT)
      Appends a discretized representation in view coordinates to the given path. This implementation returns true if at least one shape in the current shape list could be appended 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)
      Appends a discretized representation in world coordinates to the given path. This implementation returns true if at least one shape in the current shape list could be appended 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