Class TLcdGXYHaloLabelPainter
- All Implemented Interfaces:
ILcdGXYLabelPainter,ILcdGXYLabelPainterProvider,ILcdGXYMultiLabelPainter,Serializable,Cloneable
- Direct Known Subclasses:
TLcdGXYHaloLabelPainter2
Wrapping a label painter or label painter provider
This label painter uses the Decorator design pattern to add halo support to any existingILcdGXYLabelPainter or ILcdGXYLabelPainterProvider
implementation.
If the decorated class implements both, a cast to either
ILcdGXYLabelPainter or ILcdGXYLabelPainterProvider is necessary to
select the correct constructor.
When the decorated class is passed as a ILcdGXYLabelPainterProvider, this class
must also be used as a ILcdGXYLabelPainterProvider, which means that
getGXYLabelPainter(Object) must be called before painting any labels.
Delegate requirements
Most of the label painters that ship with LuciadLightspeed (e.g. TLcdGXYStampLabelPainter already provide built-in support for halos. In this case, they will have methods analogous to this class to configure the halo appearance and control the use of image caching. If available, the built-in support should be preferred over the use of TLcdGXYHaloLabelPainter. This implementation can be used with label painters/label painter providers supportingILcdGXYLabelPainter or ILcdGXYMultiLabelPainter.
If your label painter implements ILcdGXYLabelPainter2,
we strongly recommend using TLcdGXYHaloLabelPainter2 instead.
Note that when using this label painter, it is important that the delegate label painter's
ILcdGXYLabelPainter.labelBoundsSFCT method is correctly implemented.
Due to TLcdGXYHaloLabelPainter's use of offscreen images, anything that the delegate label painter
draws outside of the returned label bounds may be clipped away.
Halo settings
The color and thickness of the halo are configurable. Note that there is some overhead associated with drawing the halo. This overhead depends on the label thickness, so small values (1 or 2 pixels) are recommended. To reduce the overhead associated with the halo effect, this painter can perform image caching: the labels and their halos are drawn into an offscreen image and cached, so that subsequent repaints do not require the halo to be recreated. This improves performance considerably, but it is the application's responsibility to ensure the validity of the cache. If an object's label changes over the course of the object's lifetime, the application must call theclearImageCache(Object) method to
remove that object's cached image. Note that changing the halo color or
thickness automatically clears the entire image cache.- Since:
- 7.0.17
- See Also:
-
Field Summary
Fields inherited from interface com.luciad.view.gxy.ILcdGXYLabelPainter
DEFAULT, SELECTED -
Constructor Summary
ConstructorsConstructorDescriptionTLcdGXYHaloLabelPainter(ILcdGXYLabelPainter aLabelPainter) Creates a newTLcdGXYHaloLabelPainterwrapping the given label painter, with default halo parameters (Color = white, thickness = 1).TLcdGXYHaloLabelPainter(ILcdGXYLabelPainterProvider aLabelPainterProvider) Creates a newTLcdGXYHaloLabelPainterProviderwrapping the given label painter provider, with default halo parameters (Color = white, thickness = 1).TLcdGXYHaloLabelPainter(ILcdGXYLabelPainterProvider aLabelPainterProvider, Color aHaloColor, int aHaloThickness) Creates a newTLcdGXYHaloLabelPainterProviderwrapping the given label painter provider, configured with the given halo color and thickness.TLcdGXYHaloLabelPainter(ILcdGXYLabelPainter aLabelPainter, Color aHaloColor, int aHaloThickness) Creates a newTLcdGXYHaloLabelPainterwrapping the given label painter, configured with the given halo color and thickness. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Adds aPropertyChangeListenerto this painter.voidClears the entire label image cache.voidclearImageCache(Object aObject) Clears the label image cache for the given object.clone()RedefinesObject.cloneto make it public.Returns theILcdGXYLabelPainterto which the rendering of the labels is delegated.Returns theILcdGXYLabelPainterProviderto which the rendering of the labels is delegated.getGXYLabelPainter(Object aObject) Always returns this label painter itself.Returns the algorithm that is used for rendering halo's.Returns the current halo color.intReturns the current halo thickness.intgetLabelCount(Graphics aGraphics, ILcdGXYContext aGXYContext) Returns the number of labels for the object set to this label painter.intReturns the index of the label that is currently painted or scheduled to paint.intGets the index of location where to paint the label(s) of the set Object.Gets the Object this ILcdGXYLabelPainter can label.intgetPossibleLocationCount(Graphics aGraphics) Returns the number of possible locations where thisILcdGXYLabelPaintercan paint/draw the labels of the set domainObject.intgetSubLabelCount(int aLabelIndex) Return the number of sublabels in a label.intReturns the index of the sublabel to paint.booleanReturns true if the halo effect is on, false otherwise.booleanReturnstruewhen label image caching is enabled,falseotherwise.doublelabelBoundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) Calculates the bounds of the label that can be painted.voidpaintLabel(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Paints the label of the set Object onaGraphics.voidremovePropertyChangeListener(PropertyChangeListener aPropertyChangeListener) Removes aPropertyChangeListenerfrom this painter.voidsetDelegateLabelPainter(ILcdGXYLabelPainter aDelegateLabelPainter) Sets theILcdGXYLabelPainterto which the rendering of the labels is to be delegated.voidsetDelegateLabelPainterProvider(ILcdGXYLabelPainterProvider aDelegateLabelPainterProvider) Sets theILcdGXYLabelPainterProviderto which the rendering of the labels is to be delegated.voidsetHaloAlgorithm(TLcdHaloAlgorithm aHaloAlgorithm) Sets the algorithm to be used for rendering halo's.voidsetHaloColor(Color aColor) Sets the color of the halo to be added around labels.voidsetHaloEnabled(boolean aHaloEnabled) Switches the halo effect on or off.voidsetHaloThickness(int aThickness) Sets the thickness (in pixels) of the halo to be added around labels.voidsetLabelIndex(int aLabelIndex) Sets the label.voidsetLocationIndex(int aLocationIndex) Sets the index of location where to paint the label(s) of the set Object.voidSets the Object to be labeled by this ILcdGXYLabelPainter.voidsetSubLabelIndex(int aSubLabelIndex) Sets the sublabel index.voidsetUseImageCache(boolean aUseCache) Sets whether or not labels should be cached as images.
-
Constructor Details
-
TLcdGXYHaloLabelPainter
Creates a newTLcdGXYHaloLabelPainterwrapping the given label painter, with default halo parameters (Color = white, thickness = 1). If the delegate painter is anILcdGXYLabelPainter2, useTLcdGXYHaloLabelPainter2instead.- Parameters:
aLabelPainter- theILcdGXYLabelPainterrendering the label.
-
TLcdGXYHaloLabelPainter
public TLcdGXYHaloLabelPainter(ILcdGXYLabelPainter aLabelPainter, Color aHaloColor, int aHaloThickness) Creates a newTLcdGXYHaloLabelPainterwrapping the given label painter, configured with the given halo color and thickness. If the delegate painter is anILcdGXYLabelPainter2, useTLcdGXYHaloLabelPainter2instead.- Parameters:
aLabelPainter- theILcdGXYLabelPainterrendering the label.aHaloColor- the halo coloraHaloThickness- the halo thickness
-
TLcdGXYHaloLabelPainter
Creates a newTLcdGXYHaloLabelPainterProviderwrapping the given label painter provider, with default halo parameters (Color = white, thickness = 1). If the delegate painter provider returns anILcdGXYLabelPainter2label painters, useTLcdGXYHaloLabelPainter2instead.Note that this constructor demands that the provider is used as a
ILcdGXYLabelPainterProvider, which means thatgetGXYLabelPainter(Object)must be called before using it to paint a label.- Parameters:
aLabelPainterProvider- theILcdGXYLabelPainterProviderrendering the label.
-
TLcdGXYHaloLabelPainter
public TLcdGXYHaloLabelPainter(ILcdGXYLabelPainterProvider aLabelPainterProvider, Color aHaloColor, int aHaloThickness) Creates a newTLcdGXYHaloLabelPainterProviderwrapping the given label painter provider, configured with the given halo color and thickness. If the delegate painter provider is anILcdGXYLabelPainterProvider2, useTLcdGXYHaloLabelPainter2instead.Note that this constructor demands that the provider is used as a
ILcdGXYLabelPainterProvider, which means thatgetGXYLabelPainter(Object)must be called before using it to paint a label.- Parameters:
aLabelPainterProvider- theILcdGXYLabelPainterProviderrendering the label.aHaloColor- the halo coloraHaloThickness- the halo thickness
-
-
Method Details
-
isHaloEnabled
public boolean isHaloEnabled()Returns true if the halo effect is on, false otherwise.- Returns:
- true if the halo effect is on, false otherwise
- See Also:
-
setHaloEnabled
public void setHaloEnabled(boolean aHaloEnabled) Switches the halo effect on or off. If halos are not enabled, label painting is delegated directly to the wrapped label painter, without further intervention by this TLcdGXYHaloLabelPainter.- Parameters:
aHaloEnabled- true if halos should be added, false otherwise
-
getHaloThickness
public int getHaloThickness()Returns the current halo thickness.- Returns:
- the current halo thickness
- See Also:
-
setHaloThickness
public void setHaloThickness(int aThickness) Sets the thickness (in pixels) of the halo to be added around labels. A value of 0 (the default) means that the halo effect is disabled. Note that the performance cost of adding a halo is proportional to the halo's thickness. Also note that changing this property invalidates all currently cached label images.- Parameters:
aThickness- the new halo thickness
-
getHaloColor
Returns the current halo color.- Returns:
- the current halo color
- See Also:
-
setHaloColor
Sets the color of the halo to be added around labels. The color should be chosen such that it contrasts with the color of the labels themselves. This will ensure that the label is clearly visible on any background. Note that changing this property invalidates all currently cached label images.- Parameters:
aColor- the new halo color
-
setHaloAlgorithm
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. SeeTLcdHaloAlgorithmfor more information on the available algorithms.- Parameters:
aHaloAlgorithm- the algorithm to be used for rendering halo's.- See Also:
-
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()Returnstruewhen label image caching is enabled,falseotherwise.- Returns:
truewhen label image caching is enabled,falseotherwise
-
setUseImageCache
public void setUseImageCache(boolean aUseCache) Sets whether or not labels should be cached as images. Enabling the cache will improve painting performance significantly, as labels will need to be rendered only once. Two caveats apply, however:- Caching requires more memory (one image for each label).
- A cached image must be removed if its corresponding label changes.
This can happen, for instance, if the label displays a dynamically
changing property of an object. A typical solution is to create an
ILcdModelListenerthat removes an object from the image cache whenever that object changes.
- Parameters:
aUseCache- specifies whether image caching should be enabled- See Also:
-
clearImageCache
public void clearImageCache()Clears the entire label image cache. To remove a single label from the cache, useclearImageCache(Object).- See Also:
-
clearImageCache
Clears the label 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 in one go, useclearImageCache().- Parameters:
aObject- the object for which the cache to be cleared.- See Also:
-
getDelegateLabelPainter
Returns theILcdGXYLabelPainterto which the rendering of the labels is delegated.- Returns:
- the
ILcdGXYLabelPainterto which the rendering of the labels is delegated.
-
setDelegateLabelPainter
Sets theILcdGXYLabelPainterto which the rendering of the labels is to be delegated. If the delegate painter is anILcdGXYLabelPainter2, useTLcdGXYHaloLabelPainter2instead.- Parameters:
aDelegateLabelPainter- theILcdGXYLabelPainterto which the rendering of the labels is delegated.
-
getDelegateLabelPainterProvider
Returns theILcdGXYLabelPainterProviderto which the rendering of the labels is delegated.- Returns:
- the
ILcdGXYLabelPainterProviderto which the rendering of the labels is delegated.
-
setDelegateLabelPainterProvider
public void setDelegateLabelPainterProvider(ILcdGXYLabelPainterProvider aDelegateLabelPainterProvider) Sets theILcdGXYLabelPainterProviderto which the rendering of the labels is to be delegated. If the delegate painter provider returnsILcdGXYLabelPainter2instances, useTLcdGXYHaloLabelPainter2instead.- Parameters:
aDelegateLabelPainterProvider- theILcdGXYLabelPainterProviderto which the rendering of the labels is delegated.
-
addPropertyChangeListener
Adds aPropertyChangeListenerto this painter.- Parameters:
aPropertyChangeListener- the receiver of property change events generated by this object- See Also:
-
removePropertyChangeListener
Removes aPropertyChangeListenerfrom this painter.- Parameters:
aPropertyChangeListener- the listener to be removed- See Also:
-
getGXYLabelPainter
Always returns this label painter itself.- Specified by:
getGXYLabelPainterin interfaceILcdGXYLabelPainterProvider- Parameters:
aObject- the object for which a label painter is requested- Returns:
- this label painter itself
-
setObject
Description copied from interface:ILcdGXYLabelPainterSets the Object to be labeled by this ILcdGXYLabelPainter.- Specified by:
setObjectin interfaceILcdGXYLabelPainter- Parameters:
aObject- The object to be labeled.- See Also:
-
getObject
Description copied from interface:ILcdGXYLabelPainterGets the Object this ILcdGXYLabelPainter can label.- Specified by:
getObjectin interfaceILcdGXYLabelPainter- Returns:
- the Object this ILcdGXYLabelPainter can label.
- See Also:
-
setLocationIndex
public void setLocationIndex(int aLocationIndex) Description copied from interface:ILcdGXYLabelPainterSets the index of location where to paint the label(s) of the set Object.- Specified by:
setLocationIndexin interfaceILcdGXYLabelPainter- Parameters:
aLocationIndex- the index of the location. Must be between 0 and getPossibleLocationCount() - 1.- See Also:
-
getLocationIndex
public int getLocationIndex()Description copied from interface:ILcdGXYLabelPainterGets the index of location where to paint the label(s) of the set Object.- Specified by:
getLocationIndexin interfaceILcdGXYLabelPainter- Returns:
- the index of the position. Must be between 0 and getPossibleLocationCount() - 1.
- See Also:
-
paintLabel
Description copied from interface:ILcdGXYLabelPainterPaints the label of the set Object on
aGraphics.aGXYContextshould contain theILcdGXYViewfor which the label is painted andILcdGXYLayerto which the object belongsThe implementation of this method shall define how to paint the label of the set Object in the given mode, considering
aGXYContextand the possible locationsaLocationIndex(of multiple alternatives).The domain
Objectof the label to be painted and the location index should be set before calling this method using thesetObjectandsetLocationIndexmethods respectively.- Specified by:
paintLabelin interfaceILcdGXYLabelPainter- Parameters:
aGraphics- theGraphicsinstance on which to paint.aMode- a combination of ILcdGXYLabelPainter.DEFAULT and ILcdGXYLabelPainter.SELECTED.aGXYContext- theILcdGXYContextin which the label painting has to be performed.- See Also:
-
getPossibleLocationCount
Description copied from interface:ILcdGXYLabelPainterReturns the number of possible locations where thisILcdGXYLabelPaintercan paint/draw the labels of the set domainObject.The domain
Objectfor which the location count is retrieved should be set before calling this method using theILcdGXYLabelPainter.setObject(java.lang.Object)method.- Specified by:
getPossibleLocationCountin interfaceILcdGXYLabelPainter- Parameters:
aGraphics- the Graphics the label will be painted on.- Returns:
- the number of possible locations where this
ILcdGXYLabelPaintercan paint/draw the labels of the set Object. - See Also:
-
labelBoundsSFCT
public double labelBoundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) throws TLcdNoBoundsException Description copied from interface:ILcdGXYLabelPainterCalculates the bounds of the label that can be painted. The bounds are set as a side effect in
aRectangleSFCT, the orientation ofaRectangleSFCTis returned as an angle.The bounds represent the upper left point of the label, and a width and a height. The rotation value represents the rotation of the label bounds around the upper left point.
The object for which the bounds are retrieved and the location index of the label should be set before calling this method using the
ILcdGXYLabelPainter.setObject(java.lang.Object)andILcdGXYLabelPainter.setLocationIndex(int)methods respectively.- Specified by:
labelBoundsSFCTin interfaceILcdGXYLabelPainter- Parameters:
aGraphics- theaGraphicsto consider.aMode- the representation mode of the label.aGXYContext- theILcdGXYContextthe drawing depends on.aRectangleSFCT- theRectanglecontaining the bounds of the label in view / graphics coordinates as side effect.- Returns:
- the angle orientation of the rectangle around the labels in RADIANs, clockwise, 0 at 3 o'clock.
- Throws:
TLcdNoBoundsException- if the Object doesn't have any valid bounds, e.g. if it is always invisible in the current projection.- See Also:
-
clone
Description copied from interface:ILcdGXYLabelPainterRedefinesObject.cloneto make it public.- Specified by:
clonein interfaceILcdGXYLabelPainter- Specified by:
clonein interfaceILcdGXYLabelPainterProvider- Overrides:
clonein classObject
-
setLabelIndex
public void setLabelIndex(int aLabelIndex) Sets the label. The results of any subsequent method calls to
This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter.ILcdGXYLabelPainter.paintLabel(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)andILcdGXYLabelPainter.labelBoundsSFCT(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext, java.awt.Rectangle)etc. will apply to the label and sublabel indicated by this label index.- Specified by:
setLabelIndexin interfaceILcdGXYMultiLabelPainter- Parameters:
aLabelIndex- The label index. This should be larger than or equal to0and less than the resultILcdGXYMultiLabelPainter.getLabelCount(java.awt.Graphics, com.luciad.view.gxy.ILcdGXYContext).- See Also:
-
getLabelIndex
public int getLabelIndex()Returns the index of the label that is currently painted or scheduled to paint. This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter, else it returns 0;- Specified by:
getLabelIndexin interfaceILcdGXYMultiLabelPainter- Returns:
- the index of the label that is currently painted or scheduled to paint.
- See Also:
-
getLabelCount
Returns the number of labels for the object set to this label painter.
Note: when returning multiple (moveable) labels for the same object, it might be useful to useTLcdGXYEditControllerModel2.EDIT_WHAT_FIRST_TOUCHED_LABELto avoid that a mouse drag moves them all together. This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter, else it returns 1;- Specified by:
getLabelCountin interfaceILcdGXYMultiLabelPainter- Parameters:
aGraphics- The Graphics currently painting onaGXYContext- The ILcdGXYContext currently valid- Returns:
- The number of label for the given object.
-
getSubLabelIndex
public int getSubLabelIndex()Returns the index of the sublabel to paint. This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter, else it returns 0.- Specified by:
getSubLabelIndexin interfaceILcdGXYMultiLabelPainter- Returns:
- the index of the sublabel to paint.
- See Also:
-
setSubLabelIndex
public void setSubLabelIndex(int aSubLabelIndex) Sets the sublabel index. The results of any subsequent method calls toILcdGXYLabelPainter.paintLabel(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)andILcdGXYLabelPainter.labelBoundsSFCT(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext, java.awt.Rectangle)etc. will apply to the label and sublabel indicated by this sublabel index. This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter.- Specified by:
setSubLabelIndexin interfaceILcdGXYMultiLabelPainter- Parameters:
aSubLabelIndex- The sub label index. This should be larger than or equal to0and less than the resultILcdGXYMultiLabelPainter.getSubLabelCount(int).- See Also:
-
getSubLabelCount
public int getSubLabelCount(int aLabelIndex) Return the number of sublabels in a label. The value should be 1 or higher. This implementation calls the delegate label painter if it implements ILcdGXYMultiLabelPainter, else it returns 1.- Specified by:
getSubLabelCountin interfaceILcdGXYMultiLabelPainter- Parameters:
aLabelIndex- the index of the label.- Returns:
- The number of sublabels of the label with the given index.
-