Class TLcdGXYSurfacePainter

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

public class TLcdGXYSurfacePainter extends ALcdGXYAreaPainter implements ILcdGXYPathPainter, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdDeepCloneable
Paints and locates ILcdSurface objects and enables visual editing of ILcdSurface objects in an ILcdGXYView.

Painting an ILcdSurface

Body

This painter provides support for painting an ILcdSurface object. For each ring of the surface, a painter is retrieved using the painter provider set in setRingGXYPainterProvider(com.luciad.view.gxy.ILcdGXYPainterProvider). 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 ring of the surface.

Handles

This painter does not define handles for ILcdSurface objects.

Snap targets

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

Styling options

The visualization of the ILcdRing object is governed by the line style and fill style set to this painter. Depending on the paint mode chosen one or both of these will be taken into account.

Locating an ILcdSurface in a view

Anchor point of an ILcdSurface

The anchor point is defined by the anchor point of the exterior ring.

When is an ILcdSurface touched

The ILcdSurface object is touched when the exterior ring is touched and none of the interior rings is touched.

Visually editing an ILcdSurface

Modifying an ILcdSurface

This implementation translates all objects for ILcdGXYEditor.TRANSLATED. Non-composite curves or rings are expected to implement ILcd2DEditableShape.

Creating an ILcdSurface

This painter supports creating ILcdSurface objects without inner rings. The ring painter provider needs to support creating the exterior ring.

Retrieving 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:
    • INSIDE_SURFACE

      public static final int INSIDE_SURFACE
      Constant value indicating that the anchor point should be chosen somewhere inside the surface.
      See Also:
  • Constructor Details

  • Method Details

    • setMinimumEditDelta

      public void setMinimumEditDelta(int aDelta)
      Sets the minimum pixel distance the input device (a mouse, for example) must move before editing the shape. A larger value ensures that the object easily "snaps" back in place, a small value allows fine editing.
      Parameters:
      aDelta - the minimum pixel distance the input device should move in either the X or Y direction
    • getMinimumEditDelta

      public int getMinimumEditDelta()
      Returns the minimum pixel distance the input device (a mouse, for example) must move before editing the shape. A larger value ensures that the object easily "snaps" back in place, a small value allows fine editing. The default value is 3 pixels.
      Returns:
      the minimum pixel distance the input device should move in either the X or Y direction
    • setRingGXYPainterProvider

      public void setRingGXYPainterProvider(ILcdGXYPainterProvider<ILcdGXYPathPainter> aCurveGXYPainterProvider)
      Sets the painter provider used to provide a painter for the exterior and interior rings.
      Parameters:
      aCurveGXYPainterProvider - the painter provider for the ILcdRing objects defining the surface object.
      See Also:
    • getRingGXYPainterProvider

      public ILcdGXYPainterProvider<ILcdGXYPathPainter> getRingGXYPainterProvider()
      Returns the painter provider used to provide a painter for the exterior and interior rings.
      Returns:
      the painter provider for the ILcdRing objects defining the surface object.
      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 curve.
      See Also:
    • getCurveConnectorProvider

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

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

      public void setAnchorPointLocation(int aAnchorPointLocation)
      Sets the preferred anchor point location.
      Parameters:
      aAnchorPointLocation - one of MIDDLE_OF_BOUNDS, INSIDE_SURFACE.
    • 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:
    • 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 ILcdRing objects defining the surface object and use these to construct a surface.

      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:
    • anchorPointSFCT

      public void anchorPointSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Point aPointSFCT) throws TLcdNoBoundsException
      Description copied from class: ALcdGXYPainter
      Implements ILcdGXYPainter.anchorPointSFCT. aPointSFCT will be set to the center of the bounds calculated by boundsSFCT.
      Specified by:
      anchorPointSFCT in interface ILcdGXYPainter
      Overrides:
      anchorPointSFCT in class ALcdGXYPainter
      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aMode - the mode the object is painted in (see class documentation)
      aGXYContext - the context for which the representation of the object is painted. It contains amongst others the transformations from model to world and world to view.
      aPointSFCT - the point that has to be moved to the location of the anchor point of the representation of the object. This point must not be taken into account when the method has thrown a TLcdNoBoundsException.
      Throws:
      TLcdNoBoundsException - if no anchor point can be determined for the representation of the object. This can be 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 projection as set in the views world reference.
      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.
    • supportSnap

      public boolean supportSnap(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Supports snapping when at least one of the painters of the rings in this surface 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 exterior or interior rings 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 surface rings. 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 surface rings, null otherwise.
      See Also:
    • boundsSFCT

      public void boundsSFCT(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
      Description copied from interface: ILcdGXYPainter
      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 on which the representation of the object is painted
      aRenderMode - the mode the object is represented in (see class documentation). For example, an object may be represented differently in SELECTED mode compared to DEFAULT mode. The returned bounds of the representation must take this different representation into account.
      aGXYContext - the context for which the representation of the object is painted. It contains amongst others the transformations from model to world and world to view.
      aBoundsSFCT - the bounds that must be adapted to encompass the representation of the object in the given mode and context. These bounds must not be taken into account when the method has thrown an exception.
      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:
    • getGXYEditor

      public ILcdGXYEditor getGXYEditor(Object aObject)
      Description copied from interface: ILcdGXYEditorProvider
      Finds an ILcdGXYEditor that can be used to edit the object passed.

      The editor provider is responsible for setting the object to the editor before returning the editor. An implementation should therefore have the following structure:

      
       public ILcdGXYEditor getGXYEditor(Object aObject) {
         ILcdGXYEditor editor = ... // find the editor for the object
         editor.setObject( aObject );
         return editor;
       }
       

      Specified by:
      getGXYEditor in interface ILcdGXYEditorProvider
      Parameters:
      aObject - the object to find an editor for
      Returns:
      an editor that can be used to edit the object.
    • edit

      public boolean edit(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
      This implementation translates all rings for ILcdGXYEditor.TRANSLATED.
      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:
    • getCreationClickCount

      public int getCreationClickCount()
      Returns the number user interactions required to complete the initialization of an object set to this editor. For example, for a circle this can be two: one to determine the center point of the circle and one to determine the radius of the circle. A negative number indicates that there is no upper limit to the number of user interactions. For example, for a polyline this could be -2: it requires a minimum of two clicks to establish a polyline, but there is no upper limit on the number of polyline points.

      This implementation returns 0, since object creation is not supported.

      Specified by:
      getCreationClickCount in interface ILcdGXYEditor
      Returns:
      0
    • acceptSnapTarget

      public boolean acceptSnapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)
      Returns whether the object set to the editor can be edited so that (part of) the object snaps to the object passed as snap target in the context. If the snap target is accepted, a call to the edit method with this context passed should edit the object so that (part of) the object snaps to the object passed as snap target in the context.

      The context contains information on the user interaction at hand: the current location of the user interaction, given by its X and Y coordinates, and the distance in X direction and distance in Y direction over which the user interaction is taking place. For example, getX and getY may contain the current mouse location while getDeltaX and getDeltaY contain the distance over which the mouse has been dragged. The context also contains the candidate snap target and the layer the snap target is contained in.

      This implementation does not support snapping.

      Specified by:
      acceptSnapTarget in interface ILcdGXYEditor
      Parameters:
      aGraphics - the Graphics on which the representation of the object is painted
      aGXYContext - the context containing the information on the user interaction and the snap target.
      Returns:
      false
      See Also:
    • 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:
    • 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:
    • 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