public class TLcdGXYHaloPainter extends Object implements ILcdGXYPainter, ILcdGXYPainterProvider
ILcdGXYPainter
that adds halo effects when painting objects.
For a more detailed explanation of halos, please refer to TLcdGXYHaloLabelPainter
.
ILcdGXYPainter
or ILcdGXYPainterProvider
implementation. If the decorated class implements both, a cast to either
ILcdGXYPainter
or ILcdGXYPainterProvider
is necessary to
select the correct constructor.
The methods that control the appearance of the halos are equivalent to those in
TLcdGXYHaloPainter
.
register
two
pointlist painters
, each with a different line width.BODY, CREATING, DEFAULT, HANDLES, RESHAPING, SELECTED, SNAPS, TRANSLATING
Constructor and Description |
---|
TLcdGXYHaloPainter(ILcdGXYPainter aPainter)
Creates a new
TLcdGXYHaloPainter wrapping the given painter,
with default halo parameters (Color = white, thickness = 1) |
TLcdGXYHaloPainter(ILcdGXYPainter aPainter,
Color aHaloColor,
int aHaloThickness)
Creates a new
TLcdGXYHaloPainter wrapping the given painter,
configured with the given halo color and thickness. |
TLcdGXYHaloPainter(ILcdGXYPainterProvider aPainterProvider)
Creates a new
TLcdGXYHaloPainter wrapping the given painter provider,
with default halo parameters (Color = white, thickness = 1) |
TLcdGXYHaloPainter(ILcdGXYPainterProvider aPainterProvider,
Color aHaloColor,
int aHaloThickness)
Creates a new
TLcdGXYHaloPainter wrapping the given painter provider,
configured with the given halo color and thickness. |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Registers the given
PropertyChangeListener to be notified when this object's
properties change. |
void |
anchorPointSFCT(Graphics aGraphics,
int aMode,
ILcdGXYContext aGXYContext,
Point aPointSFCT)
Moves the Point passed to the location (in view coordinates, pixels) of the anchor point of the representation of
the object in the given mode taking into account the given context.
|
void |
boundsSFCT(Graphics aGraphics,
int aMode,
ILcdGXYContext aGXYContext,
ILcd2DEditableBounds aBoundsSFCT)
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.
|
void |
clearImageCache()
Clears the entire image cache.
|
void |
clearImageCache(Object aObject)
Clears the image cache for the given object.
|
Object |
clone()
Makes
Object.clone() public. |
Cursor |
getCursor(Graphics aGraphics,
int aMode,
ILcdGXYContext aGXYContext)
Returns a cursor that clarifies the mode and context the painter is operating in.
|
ILcdGXYPainter |
getDelegatePainter()
Returns the
ILcdGXYPainter to which the rendering of the objects is delegated. |
ILcdGXYPainterProvider |
getDelegatePainterProvider()
Returns the
ILcdGXYPainterProvider to which the rendering of the objects is delegated. |
String |
getDisplayName()
Returns a textual representation of this painter.
|
ILcdGXYPainter |
getGXYPainter(Object aObject)
Always returns this painter itself.
|
TLcdHaloAlgorithm |
getHaloAlgorithm()
Returns the algorithm that is used for rendering halo's.
|
Color |
getHaloColor()
Returns the current halo color.
|
int |
getHaloThickness()
Returns the current halo thickness.
|
Object |
getObject()
Returns the Object for which the representation is currently being handled by this painter.
|
boolean |
isHaloEnabled()
Returns true if the halo effect is on, false otherwise.
|
boolean |
isSelectionHaloEnabled()
Returns true if the halo effect is on for selected objects, false otherwise.
|
boolean |
isTouched(Graphics aGraphics,
int aMode,
ILcdGXYContext aGXYContext)
Checks if the representation of the object in the given mode is touched at the location as defined in the
supplied context.
|
boolean |
isUseImageCache()
Returns
true when caching is enabled, false otherwise. |
void |
paint(Graphics aGraphics,
int aMode,
ILcdGXYContext aGXYContext)
Displays the representation of the object in the given mode on the Graphics passed, taking into account the
supplied context.
|
void |
removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
De-registers the given
PropertyChangeListener from receiving property change events
for this object. |
void |
setDelegatePainter(ILcdGXYPainter aDelegatePainter)
Sets the
ILcdGXYPainter to which the rendering of the objects is to be delegated. |
void |
setDelegatePainterProvider(ILcdGXYPainterProvider aDelegatePainterProvider)
Sets the
ILcdGXYPainterProvider to which the rendering of the objects is to be delegated. |
void |
setHaloAlgorithm(TLcdHaloAlgorithm aHaloAlgorithm)
Sets the algorithm to be used for rendering halo's.
|
void |
setHaloColor(Color aColor)
Sets the color of the halo to be added around objects.
|
void |
setHaloEnabled(boolean aHaloEnabled)
Switches the halo effect on or off.
|
void |
setHaloThickness(int aThickness)
Sets the thickness (in pixels) of the halo to be added around objects.
|
void |
setObject(Object aObject)
Sets the Object for which the representation shall be handled by this painter.
|
void |
setSelectionHaloEnabled(boolean aSelectionHaloEnabled)
Switches the halo effect on or off for selected objects.
|
void |
setUseImageCache(boolean aUseCache)
Sets whether to cache the halo renderings as images or not.
|
Object |
snapTarget(Graphics aGraphics,
ILcdGXYContext aGXYContext)
Returns an object that can be used as snapping target when graphically editing an object.
|
boolean |
supportSnap(Graphics aGraphics,
ILcdGXYContext aGXYContext)
Returns whether the painter can provide a snap target based on the representation of the object in the given
context.
|
public TLcdGXYHaloPainter(ILcdGXYPainter aPainter)
TLcdGXYHaloPainter
wrapping the given painter,
with default halo parameters (Color = white, thickness = 1)aPainter
- the ILcdGXYPainter
rendering objects.public TLcdGXYHaloPainter(ILcdGXYPainterProvider aPainterProvider)
TLcdGXYHaloPainter
wrapping the given painter provider,
with default halo parameters (Color = white, thickness = 1)aPainterProvider
- the ILcdGXYPainterProvider
rendering objects.public TLcdGXYHaloPainter(ILcdGXYPainter aPainter, Color aHaloColor, int aHaloThickness)
TLcdGXYHaloPainter
wrapping the given painter,
configured with the given halo color and thickness.aPainter
- the ILcdGXYPainter
rendering objects.aHaloColor
- the halo coloraHaloThickness
- the halo thicknesspublic TLcdGXYHaloPainter(ILcdGXYPainterProvider aPainterProvider, Color aHaloColor, int aHaloThickness)
TLcdGXYHaloPainter
wrapping the given painter provider,
configured with the given halo color and thickness.aPainterProvider
- the ILcdGXYPainterProvider
rendering objects.aHaloColor
- the halo coloraHaloThickness
- the halo thicknesspublic boolean isUseImageCache()
true
when caching is enabled, false
otherwise.true
when caching is enabled, false
otherwise.setUseImageCache(boolean)
public void setUseImageCache(boolean aUseCache)
clearImageCache()
method can be called to clear the image cache if changes
need to be applied.aUseCache
- true if halo renderings should be cachedisUseImageCache()
public void clearImageCache()
clearImageCache(Object)
.
Note: this method only clears the cached images that are stored in the painter itself.
I.e. it doesn't clear the cached images that are stored in the domain objects using
ILcdCache
.
setUseImageCache(boolean)
public void clearImageCache(Object aObject)
clearImageCache()
.
Note : this method only clears the cached image for the given Object
if it is
stored in the painter itself, not when it is stored in the domain objects using
ILcdCache
.
aObject
- the object for which the cache to be cleared.setUseImageCache(boolean)
public boolean isHaloEnabled()
setHaloEnabled(boolean)
public void setHaloEnabled(boolean aHaloEnabled)
aHaloEnabled
- true if halos should be added, false otherwiseisHaloEnabled()
,
setSelectionHaloEnabled(boolean)
public boolean isSelectionHaloEnabled()
setSelectionHaloEnabled(boolean)
,
setSelectionHaloEnabled(boolean)
public void setSelectionHaloEnabled(boolean aSelectionHaloEnabled)
aSelectionHaloEnabled
- true if halos should be added in selection mode, false otherwiseisSelectionHaloEnabled()
,
setHaloEnabled(boolean)
public int getHaloThickness()
setHaloThickness(int)
public void setHaloThickness(int aThickness)
aThickness
- the new halo thicknesssetHaloThickness(int)
public void setHaloAlgorithm(TLcdHaloAlgorithm aHaloAlgorithm)
TLcdHaloAlgorithm
for more information on the available algorithms.aHaloAlgorithm
- the algorithm to be used for rendering halo's.TLcdHaloAlgorithm
,
getHaloAlgorithm()
public TLcdHaloAlgorithm getHaloAlgorithm()
TLcdHaloAlgorithm
,
setHaloAlgorithm(com.luciad.util.TLcdHaloAlgorithm)
public Color getHaloColor()
setHaloColor(java.awt.Color)
public void setHaloColor(Color aColor)
aColor
- the new halo colorTLcdGXYHaloLabelPainter.setHaloColor(java.awt.Color)
public ILcdGXYPainter getDelegatePainter()
ILcdGXYPainter
to which the rendering of the objects is delegated.ILcdGXYPainter
to which the rendering of the objects is delegated.public void setDelegatePainter(ILcdGXYPainter aDelegatePainter)
ILcdGXYPainter
to which the rendering of the objects is to be delegated.
Note that, if a delegate painter provider is set, this property is ignored.aDelegatePainter
- the ILcdGXYPainter
to which the rendering of the objects is delegated.getDelegatePainter()
,
setDelegatePainterProvider(com.luciad.view.gxy.ILcdGXYPainterProvider)
public ILcdGXYPainterProvider getDelegatePainterProvider()
ILcdGXYPainterProvider
to which the rendering of the objects is delegated.ILcdGXYPainterProvider
to which the rendering of the objects is delegated.setDelegatePainterProvider(com.luciad.view.gxy.ILcdGXYPainterProvider)
public void setDelegatePainterProvider(ILcdGXYPainterProvider aDelegatePainterProvider)
ILcdGXYPainterProvider
to which the rendering of the objects is to be delegated.
When calling getGXYPainter(Object)
, the painter to delegate to is automatically retrieved from this
painter provider.aDelegatePainterProvider
- the ILcdGXYPainterProvider
to which the rendering of the objects is delegated.setDelegatePainter(com.luciad.view.gxy.ILcdGXYPainter)
,
getDelegatePainterProvider()
public ILcdGXYPainter getGXYPainter(Object aObject)
getGXYPainter
in interface ILcdGXYPainterProvider
aObject
- the object for which a painter is requestedpublic void paint(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
ILcdGXYPainter
The visual representation of an object depends on the context. Depending on the context (e.g. is the location covered by the view), an object may or may not have a representation. The context contains:
The mode passed in this method indicates what part of the object must be painted, whether it should be painted as selected or not, and whether user interaction (via mouse movements) must be taken into account.
When the mode passed contains either TRANSLATING, RESHAPING or CREATING, this method is also responsible for
interpreting interaction on the representation of an object and modifying the representation of the object
accordingly. The painter is not responsible for modifying the object itself, this is done by
a corresponding ILcdGXYEditor
.
Implementations of ILcdGXYPainter
and ILcdGXYEditor
interfaces must be consistent for
an object: the painter must display the result of the user interaction on the object, while the editor is
responsible for modifying the object as a result of the user interaction.
A good practice to ensure a consistent implementation is to implement both the ILcdGXYPainter
and ILcdGXYEditor
interfaces in a single class.
When the mode passed includes SNAPS, the part of the representation which corresponds to the object returned as
snap target by the method snapTarget
must be painted in order to provide the user with a visual indication of the snap target.
The Graphics passed in this method can be different from the Graphics returned by a view due to techniques such as double buffering (as applied in Swing). Basic drawing operations must always be performed on the Graphics passed as an argument in this method.
paint
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- the mode the object is represented in (see class documentation).aGXYContext
- the ILcdGXYContext
the drawing depends on.public void setObject(Object aObject)
ILcdGXYPainter
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.
setObject
in interface ILcdGXYPainter
aObject
- the object for which the representation shall be handled by this painter.ILcdGXYPainter.getObject()
public Object getObject()
ILcdGXYPainter
getObject
in interface ILcdGXYPainter
ILcdGXYPainter.setObject(Object)
public void boundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, ILcd2DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
ILcdGXYPainter
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.
boundsSFCT
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- 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.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.isTouched
public boolean isTouched(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
ILcdGXYPainter
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:
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.
isTouched
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- the mode the object is represented inaGXYContext
- contains the location of the interaction and the transformations to convert this location into
model coordinatesboundsSFCT
public void anchorPointSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Point aPointSFCT) throws TLcdNoBoundsException
ILcdGXYPainter
The anchor point is an important point of the representation, typically the point which would be used
when the object would be represented as a single point. The anchor point is mostly used to attach extra information
to the representation of an object, for example, using labels. A typical implementation of this method for painters
which can handle ILcdShape
objects is the location of the focus point of the shape.
anchorPointSFCT
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- 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.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.paint
public boolean supportSnap(Graphics aGraphics, ILcdGXYContext aGXYContext)
ILcdGXYPainter
supportSnap
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaGXYContext
- the context in which this object is represented and in which the editing of an object occurs.public Object snapTarget(Graphics aGraphics, ILcdGXYContext aGXYContext)
ILcdGXYPainter
This method must only be called when supportSnap
returns true for the given context.
snapTarget
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaGXYContext
- the context in which this object is represented and in which the editing of an object occurs.supportSnap
public Cursor getCursor(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext)
ILcdGXYPainter
TRANSLATING
, the cursor could be the MOVE cursor.
When no specific cursor is required implementations must return null.getCursor
in interface ILcdGXYPainter
aGraphics
- the Graphics on which the representation of the object is paintedaMode
- the rendering mode to return the cursor for.aGXYContext
- the context in which the rendering occurs.Cursor
to indicate the type of operating
aMode
and aGXYContext
. Returns
null
if no particular Cursor
is required.public String getDisplayName()
ILcdGXYPainter
getDisplayName
in interface ILcdGXYPainter
public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
Registers the given PropertyChangeListener
to be notified when this object's
properties change.
In case you need to register a listener which keeps a reference to an object with a shorter life-time than this change source,
you can use a ALcdWeakPropertyChangeListener
instance as property change listener.
addPropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- The listener to be notifiedALcdWeakPropertyChangeListener
,
ILcdPropertyChangeSource.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILcdPropertyChangeSource
De-registers the given PropertyChangeListener
from receiving property change events
for this object.
If the listener was added more than once, it will be notified one less time after being
removed.
If the listener is null
, or was never added, no exception is thrown and no action is taken.
removePropertyChangeListener
in interface ILcdPropertyChangeSource
aPropertyChangeListener
- the listener that should no longer be notified of changes of
this object's propertiesILcdPropertyChangeSource.addPropertyChangeListener(java.beans.PropertyChangeListener)
public Object clone()
ILcdCloneable
Makes Object.clone()
public.
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 );
}
}
clone
in interface ILcdCloneable
clone
in interface ILcdGXYPainterProvider
clone
in class Object
Object.clone()