Class TLcdGXYIconPainter

java.lang.Object
com.luciad.view.gxy.ALcdGXYPainter
com.luciad.view.gxy.painter.TLcdGXYIconPainter
All Implemented Interfaces:
ILcdCloneable, ILcdPropertyChangeSource, ILcdGXYEditor, ILcdGXYEditorProvider, ILcdGXYPainter, ILcdGXYPainterProvider, Serializable, Cloneable
Direct Known Subclasses:
TLcdGXYAISIconProviderPainter, TLcdGXYEditableLabelPainter, TLcdVPFPointPainter

public class TLcdGXYIconPainter extends ALcdGXYPainter implements ILcdGXYPainter, ILcdGXYEditor, ILcdGXYEditorProvider
Paints and locates ILcdShape objects as points and enables visual editing of ILcd2DEditableShape objects as points in an ILcdGXYView.

Painting an ILcdShape

Body

This painter paints ILcdShape objects by painting an ILcdIcon at the location of the shapes focus point. Two icons are used, one to be used as default icon and one to be used when selected. When the object is being edited, the selection icon is used. If the ILcdShape implements ILcdOriented, the top of the icon can be automatically rotated according to the orientation. If an icon implements ILcdAnchoredIcon, the painter maps its anchor point on the object's focus point. If not, the center of the icon is mapped to the object's focus point. In addition, the icon can be automatically scaled.

The painter has the ability to add a halo effect around the painted icons. For a more detailed explanation of halos, please refer to TLcdGXYHaloLabelPainter. The methods that control the appearance of the halos are equivalent to those in TLcdGXYHaloLabelPainter.

It is possible to use an ILcdObjectIconProvider for the default icon and the selection icon with setIconProvider(ILcdObjectIconProvider) and setSelectionIconProvider(ILcdObjectIconProvider). If an icon provider is set, the icon getIcon() is used only as a fallback icon when the icon provider cannot provide an icon for the current object. The method getIcon() always returns the fallback icon, and this is not always the icon that will be painted. For the selection icon, similar functionality and methods are used. The method getIcon(int) returns the icon that will be actually painted for the given rendering mode, so this method may also return the icon given by the icon provider for the current object.

Handles

The icon displayed acts as a handle. Since this is already painted in ILcdGXYPainter.BODY mode, no additional handles are painted.

Snap targets

The focus point of the ILcdShape object can be returned on the condition that it is touched, see isTouched. If the focus point is defined as snap target, it will be highlighted with the snapIcon.

Styling options

The visualization of the ILcdShape object is governed by the icon and selection icon set to this painter.

Locating an ILcdShape in a view

Anchor point of an ILcdShape

The anchor point is located at the focus point of the ILcdShape object.

When is an ILcdShape touched

An ILcdShape object is touched when the mouse position is over the painted icon.

Visually editing and creating an ILcd2DEditableShape

Modifying an ILcd2DEditableShape

This editor will move the ILcd2DEditableShape in both RESHAPED and TRANSLATED mode. The shape is moved to the location of the mouse pointer.

Creating an ILcd2DEditableShape

When initializing an ILcd2DEditableShape object via interaction through the view, the ILcdShape object will be moved when calling edit with START_CREATION mode. The shape is moved to the location of the mouse pointer. In CREATING or END_CREATION mode, the object will not be updated.

Accepted snap targets

All points are accepted as snap target as long as:

  • the point can be transformed to the reference of the ILcdShape object with the model to model transformation,
  • the point is not the focus point of the ILcdShape object set to this painter.

Additional properties

Caching

This painter implementation may cache images of the icons used. Image caching can be turned on/off with the setUseImageCache method.

Halo effect

The painter has the ability to add a halo effect around the painted icons. For a more detailed explanation of halos, please refer to TLcdGXYHaloLabelPainter. The methods that control the appearance of the halos are equivalent to those in TLcdGXYHaloLabelPainter.

See Also:
  • Constructor Details

    • TLcdGXYIconPainter

      public TLcdGXYIconPainter()
      Constructs a default TLcdGXYIconPainter and sets the display name to "Point".
    • TLcdGXYIconPainter

      public TLcdGXYIconPainter(String aDisplayName)
      Constructs a default TLcdGXYIconPainter with the given display name.
      Parameters:
      aDisplayName - The display name for this painter, used for textual representation of this painter.
  • Method Details

    • firePropertyChangeEvent

      protected void firePropertyChangeEvent(PropertyChangeEvent aPropertyChangeEvent)
      Fires a PropertyChangeEvent to all PropertyChangeListeners that have been registered to this ILcdGXYPainter.

      This implementation will also clear the image cache when a property change event is fired.

      Overrides:
      firePropertyChangeEvent in class ALcdGXYPainter
      Parameters:
      aPropertyChangeEvent - The PropertyChangeEvent object.
    • 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:
    • setObject

      public void setObject(Object aObject)

      Sets the object to paint and edit. The object should be an instance of or refer to an instance of ILcdShape for painting and ILcd2DEditableShape for editing.

      This painter/editor can be used to paint the object without using the edit functionality. This method shall therefore only check if the object implements ILcdShape and shall throw a ClassCastException if it does not.

      When this painter is used as editor with an object that does not implement the interface ILcd2DEditableShape, the edit method shall throw the necessary exception.

      Specified by:
      setObject in interface ILcdGXYEditor
      Specified by:
      setObject in interface ILcdGXYPainter
      Parameters:
      aObject - The object to paint and edit.
      Throws:
      ClassCastException - when the object does not implement ILcdShape.
      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:
    • setPaintCache

      public void setPaintCache(boolean aPaintCache)
      Turns caching of the object location on or off. Caching greatly reduces the time to paint an object but requires more memory. The location 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:
    • setIcon

      public void setIcon(ILcdIcon aIcon)
      Sets the ILcdIcon used for painting in default mode. For painting, this is a fallback icon, it is only painted if there is no icon provider set or the icon provider can't provide an icon for the current object. When the given icon implements ILcdAnchoredIcon, the painter maps its anchor point on the object's focus point. If not, the center of the icon is mapped to the object's focus point.
      Parameters:
      aIcon - the icon to paint in default mode.
      See Also:
    • getIcon

      public ILcdIcon getIcon()
      Returns the ILcdIcon used for painting in default mode. For painting, this is a fallback icon, it is only painted if there is no icon provider set or the icon provider can't provide an icon for the current object.
      Returns:
      the ILcdIcon used for painting in default mode.
      See Also:
    • setSelectionIcon

      public void setSelectionIcon(ILcdIcon aSelectionIcon)
      Sets the ILcdIcon used for painting in selected mode. For painting, this is a fallback icon, it is only painted if there is no selection icon provider set or the selection icon provider can't provide an icon for the current object. When the given icon implements ILcdAnchoredIcon, the painter maps its anchor point on the object's focus point. If not, the center of the icon is mapped to the object's focus point.
      Parameters:
      aSelectionIcon - the ILcdIcon used for painting in selected mode.
      See Also:
    • getSelectionIcon

      public ILcdIcon getSelectionIcon()
      Returns the ILcdIcon used for painting in selected mode. For painting, this is a fallback icon, it is only painted if there is no selection icon provider set or the selection icon provider can't provide an icon for the current object.
      Returns:
      the ILcdIcon used for painting in selected mode.
      See Also:
    • setSnapIcon

      public void setSnapIcon(ILcdIcon aSnapIcon)
      Sets the icon that marks snap targets of the object currently set to this painter. This icon is painted when the paint method is called with the render mode ILcdGXYPainter.SNAPS. When the given icon implements ILcdAnchoredIcon, the painter maps its anchor point on the object's focus point. If not, the center of the icon is mapped to the object's focus point.
      Parameters:
      aSnapIcon - The icon that should be used to paint snap target points.
      See Also:
    • getSnapIcon

      public ILcdIcon getSnapIcon()
      Returns the icon that is used to paint snap target points of the object set to this painter.
      Returns:
      the icon that is used to paint snap target points of the object set to this painter.
      See Also:
    • setIconProvider

      public void setIconProvider(ILcdObjectIconProvider aIconProvider)

      Sets the ILcdIconProvider used for painting in default mode.

      If an icon provider is set that can provide an icon for the object, it overrides the icon that is set with setIcon(ILcdIcon) for painting.

      Parameters:
      aIconProvider - the icon provider to paint in default mode.
      Since:
      10.0
      See Also:
    • getIconProvider

      public ILcdObjectIconProvider getIconProvider()
      Returns the ILcdIconProvider used for painting in default mode.
      Returns:
      the ILcdIconProvider used for painting in default mode.
      Since:
      10.0
      See Also:
    • setSelectionIconProvider

      public void setSelectionIconProvider(ILcdObjectIconProvider aSelectionIconProvider)
      Sets the ILcdIconProvider used for painting in selected mode.

      If a selection icon provider is set that can provide an icon for the object, it overrides the icon that is set with setSelectionIcon(ILcdIcon) for painting.

      Parameters:
      aSelectionIconProvider - the ILcdIconProvider used for painting in selected mode.
      Since:
      10.0
      See Also:
    • getSelectionIconProvider

      public ILcdObjectIconProvider getSelectionIconProvider()
      Returns the ILcdIconProvider used for painting in selected mode.
      Returns:
      the ILcdIconProvider used for painting in selected mode.
      Since:
      10.0
      See Also:
    • isHaloEnabled

      public boolean isHaloEnabled()
      Returns whether the painter will add a halo effect around the icons.
      Returns:
      whether the painter will add a halo effect around the icons.
      See Also:
    • setHaloEnabled

      public void setHaloEnabled(boolean aHaloEnabled)
      Determines whether the painter will add a halo effect around the icons. By default, this property is set to false.
      Parameters:
      aHaloEnabled - a flag indicating whether to add a halo effect around the icons.
      See Also:
    • getHaloThickness

      public int getHaloThickness()
      Returns the thickness of the halo effect.
      Returns:
      the thickness of the halo effect.
      See Also:
    • setHaloThickness

      public void setHaloThickness(int aHaloThickness)
      Sets the thickness defined in pixels of the halo effect. By default, this property is set to 1.
      Parameters:
      aHaloThickness - the thickness defined in pixels of the halo effect.
      See Also:
    • getHaloColor

      public Color getHaloColor()
      Returns the color of the halo effect.
      Returns:
      the color of the halo effect.
      See Also:
    • setHaloColor

      public void setHaloColor(Color aHaloColor)
      Sets the color of the halo effect. By default, this property is set to Color.white.
      Parameters:
      aHaloColor - the color of the halo effect.
      See Also:
    • setHaloAlgorithm

      public void setHaloAlgorithm(TLcdHaloAlgorithm aHaloAlgorithm)
      Sets the algorithm to be used for rendering halo's. The choice of the halo algorithm may have a major impact on the overall performance of this painter. See TLcdHaloAlgorithm for more information on the available algorithms.
      Parameters:
      aHaloAlgorithm - the algorithm to be used for rendering halo's.
      See Also:
    • getHaloAlgorithm

      public TLcdHaloAlgorithm getHaloAlgorithm()
      Returns the algorithm that is used for rendering halo's.
      Returns:
      the algorithm that is used for rendering halo's.
      See Also:
    • isUseImageCache

      public boolean isUseImageCache()
      Returns true when icon halo image caching is enabled, false otherwise.
      Returns:
      true when icon halo image caching is enabled, false otherwise.
    • setUseImageCache

      public void setUseImageCache(boolean aUseImageCache)
      Enables or disables the caching of icons with halo as images. By default, image caching is turned on. This setting does not have any effect if halo painting is disabled.
      Parameters:
      aUseImageCache - a flag indicating whether image caching should be enabled.
      See Also:
    • clearImageCache

      public void clearImageCache()

      Clears the entire image cache.

      To remove a single item from the cache, use clearImageCache(Object).

      See Also:
    • clearImageCache

      public void clearImageCache(Object aObject)
      Clears the icon image cache for the given object. The next time this object is painted, a new image will be created and cached for it. To remove all cached images at once, use clearImageCache().
      Parameters:
      aObject - the object for which the cache to be cleared.
      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 use the method getIcon(int) with the specified render mode to determine how the object needs to be rendered. In ILcdGXYPainter.RESHAPING and ILcdGXYPainter.TRANSLATING mode, the ILcdShape object is rendered as if the point was moved along the same distance in view coordinates as passed in the context.

      If the halo effect is enabled, a halo effect will be added around the icon. Note that the halo effect will only be added when the rendering mode does not contain the mode SELECTED.

      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.
    • paintSnap

      protected void paintSnap(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
      Called when this painter needs to paint its object in the rendering mode ILcdGXYPainter.SNAPS.
      Parameters:
      aGraphics - The graphics to paint the object on.
      aRenderMode - The mode to render the object in, ILcdGXYPainter.SNAPS included.
      aGXYContext - The context to render the object in.
    • getScale

      public double getScale()
      Returns the current size factor.
      Returns:
      the current size factor
      See Also:
    • setScale

      public void setScale(double aScale)
      Sets the new size factor for the icons. The interpretation of this value depends on the value of getScalingMode().
      Parameters:
      aScale - the new size factor
      See Also:
    • getScalingMode

      public TLcdGXYIconPainter.ScalingMode getScalingMode()
      Returns the current icon scaling mode.
      Returns:
      the current icon scaling mode
      See Also:
    • setScalingMode

      public void setScalingMode(TLcdGXYIconPainter.ScalingMode aScalingMode)
      Sets the icon scaling mode, which determines how the setScale(double) property is interpreted.
      Parameters:
      aScalingMode - the new icon scaling mode
      See Also:
    • isUseOrientation

      public boolean isUseOrientation()
      Returns if the icon will be rotated when the painted object implements ILcdOriented.
      Returns:
      true if the icon is rotated when the painted object implements ILcdOriented, false if the icon is painted without applying rotation.
    • setUseOrientation

      public void setUseOrientation(boolean aUseOrientation)
      Sets whether to paint a rotated icon when the painted object implements ILcdOriented.
      Parameters:
      aUseOrientation - if true, and if the painted object implements ILcdOriented, the icon is rotated so that the top of the original icon follows the orientation with respect to the north
    • getIcon

      protected ILcdIcon getIcon(int aRenderMode)

      Returns the icon that needs to be painted for the specified rendering mode. This implementation will return the selection icon if the rendering mode contains SELECTED. If the mode contains BODY or DEFAULT, the default icon is returned. The method returns null in all other cases.

      The default icon is the icon returned by getIconProvider() if the icon provider is not null and the icon it returns for the current object is not null, otherwise it is the fallback icon, gotten with getIcon()

      The selection icon is the icon returned by getSelectionIconProvider() if the icon provider is not null and the icon it returns for the current object is not null, otherwise it is the fallback selection icon, gotten with getSelectionIcon()

      *

      Parameters:
      aRenderMode - The mode to render the object in.
      Returns:
      the default icon for painting, the selection icon for painting or null.
      See Also:
    • isTouched

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

      Returns whether the mouse position in the given context is touching the painted icon.

      This implementation will use the method getIcon(int) with the specified render mode to determine which icon needs to be 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 the focus point of the ILcdShape object is touched.
      See Also:
    • getCursor

      public Cursor getCursor(Graphics aGraphics, int aRenderMode, ILcdGXYContext aGXYContext)
      Returns a translation Cursor when appropriate, or null otherwise.
      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.
    • 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:
    • supportSnap

      public boolean supportSnap(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Supports snapping when the ILcdShape object set to this painter is visible in the view.

      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 the ILcdShape object is visible in the view, false otherwise.
    • snapTarget

      public Object snapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Returns the focus point of the ILcdShape object if the point is touched. If not, 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 focus point of the ILcdShape object if the point is touched, null otherwise.
      See Also:
    • edit

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

      This implementation edits the ILcdShape object set to the painter. The object needs to implement the interface ILcd2DEditableShape otherwise a ClassCastException will be thrown.

      In ILcdGXYEditor.START_CREATION, ILcdGXYEditor.TRANSLATED and ILcdGXYEditor.RESHAPED render mode, the focus point of the ILcdShape object is moved to the location beneath the mouse pointer.

      If, in all render modes, a snap target is found for the moved point, the snap target location is used for the moved point.

      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.
      Throws:
      ClassCastException - if the painter's object does not implement ILcd2DEditableShape.
      See Also:
    • getCreationClickCount

      public int getCreationClickCount()
      Returns 1 as the number of required user interactions.
      Specified by:
      getCreationClickCount in interface ILcdGXYEditor
      Returns:
      1.
    • setModelModelTransformationClass

      public void setModelModelTransformationClass(Class aModel2ModelTransformationClass)

      Sets the transformation class that should be used when snapping to points that are defined in a different reference than the reference of this painter's object. The transformation will be instantiated and setup to transform points from the model of the snap layer to points in the model which contains the current object of this painter. The default value is the TLcdGeoReference2GeoReference class.

      This property allows the painter to snap to points defined in a different model reference.

      Instances of this specified class should implement ILcdModelModelTransformation, otherwise the snapping functionality to different model references will not work.

      Parameters:
      aModel2ModelTransformationClass - the transformation used as described above.
    • acceptSnapTarget

      public boolean acceptSnapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)

      Determines whether a snap target should be accepted or not. A snap target is accepted if the following conditions are met:

      • The current object is an ILcd2DEditableShape.
      • The snap target is an ILcdPoint whose coordinates are expressed in the same coordinate system as the current objects coordinate system or the model to model transformation can transform the point to a point in the objects coordinate system.
      • The snap object is not the focus point of the current object. If this is wanted, override the function and return true if the snap object is the focus point.
      • The current object is touched. This avoids that when multiple points are edited at once, they all snap to the same point. This would give the impression that the other points disappeared.

      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 the above conditions are met, 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()
      Creates and returns a copy of this object. Deep copies are made of fallback icons (getIcon() and getSelectionIcon()) and the snap icon but shallow copies are made of the icon providers.
      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 instance.
      See Also: