public class TLspLabelPainter extends Object implements ILspLabelPainter, ILspEditableStyledPainter, ILspPathLocationLabelPainter, ILspStampLocationLabelPainter
A label painter that draws a screen-aligned images for domain objects. These can be either images/icons or text.
To customize the look and content of your labels, add an ILspStyler
to this painter.
If you need control over other labeling aspects such as positioning or priorities, use an ALspLabelStyler
.
The content of the labels can be determined by using the proper styles. Either use:
When painting content using a TLspTextStyle
, the layout of the text is as demonstrated in the following image:
Optionally, you can also set:
toString()
). See
for example TLspDataObjectLabelTextProviderStyle.TLspLabelBoxStyle
instances for the same label.
See the TLspLabelBoxStyle
class doc for more information.It is possible to paint labels with or without an overlay
option. Overlay determines if depth checking is used during painting. true
means that
(conceptually) the label is painted at depth 0 (and is always painted in front of the terrain
and other objects). false
means that it can be obscured by the terrain or other
objects. This setting doesn't influence which labels are painted and which ones are not.
Performance considerations:
ILspPaintGroupsChangeListener.Callback
Constructor and Description |
---|
TLspLabelPainter()
Creates a new label painter.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Adds a
PropertyChangeListener
to the list of listeners that must be notified when
any of the properties of this ILspPainter changes. |
void |
commitChanges(Object aEventId)
Called when the changes for a specified event should be committed.
|
Object |
getAnchorObject(TLspLabelID aLabel,
TLspPaintState aPaintState,
TLspContext aContext)
Returns the anchor object of the given label.
|
long |
getDefaultOpacityFadeDuration()
Returns the duration of label fade in/out animations.
|
Iterable<TLspLabelID> |
getLabelIDs(Object aObject,
TLspPaintRepresentationState aPaintRepresentationState,
TLspContext aContext)
Enumerates all the desired labels associated with a domain object.
|
TLspOpenGLProfile |
getRequiredOpenGLProfile()
Returns the minimum required OpenGL profile that a view must support in
order to be compatible with this painter.
|
ILspStyler |
getStyler(TLspPaintState aPaintState)
Returns the styler used by this painter for the given
PaintState . |
boolean |
isHorizonFading()
Returns if horizon fading is enabled.
|
boolean |
isOverlayLabels()
Indicates whether overlaying labels is enabled.
|
boolean |
isUseTerrainForCulling()
Returns if culling based on the terrain is enabled in 3D
|
void |
labelAnchorPointOffsetSFCT(TLspLabelID aLabel,
Dimension2D aDimension,
TLspPaintState aPaintState,
TLspContext aContext,
ILcd2DEditablePoint aOffsetSFCT)
Returns the anchor point offset.
|
void |
labelAnchorPointSFCT(TLspLabelID aLabel,
ALspLabelLocation aLabelLocation,
ALspLabelLocations aLabelLocations,
TLspPaintState aPaintState,
TLspContext aContext,
ILcd3DEditablePoint aAnchorPointSFCT)
Retrieves the anchor point of the given label.
|
double |
labelBoundsSFCT(TLspLabelID aLabel,
ALspLabelLocation aLabelLocation,
ALspLabelLocations aLocations,
TLspPaintState aPaintState,
TLspContext aContext,
ILcd3DEditableBounds aBoundsSFCT)
Calculates the bounds of the given label for the given label location.
|
void |
labelDimensionSFCT(TLspLabelID aLabelID,
TLspPaintState aPaintState,
TLspContext aContext,
Dimension2D aDimensionSFCT)
Returns the dimension of the given label.
|
TLspPaintProgress |
paintObjects(ILcdGLDrawable aGLDrawable,
List<TLspPaintGroup> aPaintGroups,
TLspPaintPass aPass,
TLspContext aContext)
Paints the specified groups of objects into a view.
|
void |
prepareChanges(List<TLspPaintGroupsChangedEvent> aEvents,
Object aEventId,
ILspPaintGroupsChangeListener.Callback aCallback)
Called when the paint groups will change.
|
<T> boolean |
query(List<TLspPaintGroup> aPaintGroups,
ALspPaintQuery<T> aQuery,
TLspPaintRepresentationState aPaintRepresentationState,
TLspContext aContext)
Retrieves a set of domain objects and data based on the parameters given by the query.
|
void |
registerLayer(ILspInteractivePaintableLayer aLayer,
TLspPaintRepresentation aPaintRepresentation)
Registers a layer with this painter.
|
void |
removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
Removes a
PropertyChangeListener from the list of listeners. |
void |
setDefaultOpacityFadeDuration(long aDefaultOpacityFadeDuration)
Sets the default duration of label fade in/out animations.
|
void |
setHorizonFading(boolean aDistanceBasedFading)
Sets if horizon fading is enabled.
|
void |
setOverlayLabels(boolean aOverlayLabels)
Enables overlaying labels above transparent objects.
|
void |
setStyler(TLspPaintState aPaintState,
ILspStyler aStyler)
Sets the styler used by this object for the given
PaintState . |
void |
setUseTerrainForCulling(boolean aUseTerrainForCulling)
Sets if culling based on the terrain is enabled in 3D.
|
void |
unregisterLayer(ILspInteractivePaintableLayer aLayer,
TLspPaintRepresentation aPaintRepresentation)
Unregisters a layer from this painter.
|
void |
viewObjectAnchorPointSFCT(TLspLabelID aLabel,
ALspLabelLocations aLabelLocations,
TLspPaintState aPaintState,
TLspContext aContext,
ILcd3DEditablePoint aObjectAnchorPointSFCT)
Calculates the object anchor point for the given label in view coordinates.
|
void |
worldObjectAnchorPointSFCT(TLspLabelID aLabel,
ALspLabelLocations aLabelLocations,
TLspPaintState aPaintState,
TLspContext aContext,
ILcd3DEditablePoint aObjectAnchorPointSFCT)
Calculates the object anchor point for the given label in world coordinates.
|
public void setOverlayLabels(boolean aOverlayLabels)
By default, this is disabled and is only necessary in specific cases.
In particular, it can be enabled if the labels need to be above other transparent objects without blending.
aOverlayLabels
- whether labels should be overlayed.isOverlayLabels()
public boolean isOverlayLabels()
setOverlayLabels(boolean)
public void setDefaultOpacityFadeDuration(long aDefaultOpacityFadeDuration)
By default, this is 500
milliseconds. When set to 0
, fade in/out animations are disabled.
aDefaultOpacityFadeDuration
- a duration in milliseconds, use 0
to disable
animations.getDefaultOpacityFadeDuration()
public long getDefaultOpacityFadeDuration()
setDefaultOpacityFadeDuration(long)
public void setHorizonFading(boolean aDistanceBasedFading)
Sets if horizon fading is enabled. When it is enabled, labels that are close to the horizon fade out (become more transparent) until they become invisible. This effect is only enabled:
Horizon fading is enabled by default.
aDistanceBasedFading
- true
to enable horizon fading.public boolean isHorizonFading()
setHorizonFading(boolean)
public void setUseTerrainForCulling(boolean aUseTerrainForCulling)
Sets if culling based on the terrain is enabled in 3D. If true
, labels will be dropped when their anchor
is hidden by terrain, or by the horizon. If false
, labels will only be dropped when their anchor is behind
the horizon.
The default is true
.
aUseTerrainForCulling
- true to enable using terrain for cullingpublic boolean isUseTerrainForCulling()
setUseTerrainForCulling(boolean)
public void setStyler(TLspPaintState aPaintState, ILspStyler aStyler)
ILspEditableStyledPainter
PaintState
.setStyler
in interface ILspEditableStyledPainter
aPaintState
- the paint state for which to set a styleraStyler
- the new styler for the painterpublic void viewObjectAnchorPointSFCT(TLspLabelID aLabel, ALspLabelLocations aLabelLocations, TLspPaintState aPaintState, TLspContext aContext, ILcd3DEditablePoint aObjectAnchorPointSFCT) throws TLcdNoBoundsException
ILspStampLocationLabelPainter
Note : the returned point should not depend on the given label location. I.e. it should be the same point for every stamp label location.
viewObjectAnchorPointSFCT
in interface ILspStampLocationLabelPainter
aLabel
- the identifier of the label for which to calculate the anchor point.aLabelLocations
- context information. Can be used when a label depends on an other label.aPaintState
- the paint state.aContext
- the context.aObjectAnchorPointSFCT
- the point in which to store the object anchor point.TLcdNoBoundsException
- when the object anchor point could not be calculated.public void worldObjectAnchorPointSFCT(TLspLabelID aLabel, ALspLabelLocations aLabelLocations, TLspPaintState aPaintState, TLspContext aContext, ILcd3DEditablePoint aObjectAnchorPointSFCT) throws TLcdNoBoundsException
ILspStampLocationLabelPainter
Calculates the object anchor point for the given label in world coordinates.
Note : the returned point should not depend on the given label location. I.e. it should be the same point for every stamp label location.
If the given label is anchored to another label, i.e. getAnchorObject
returns a TLspLabelID
, this method will throw a TLcdNoBoundsException
.
worldObjectAnchorPointSFCT
in interface ILspStampLocationLabelPainter
aLabel
- the identifier of the label for which to calculate the anchor point.aLabelLocations
- context information. Can be used when a label depends on an other label.aPaintState
- the paint state.aContext
- the context.aObjectAnchorPointSFCT
- the point in which to store the object anchor point.TLcdNoBoundsException
- when the label is anchored to a
TLspLabelID
or when the object anchor point could not be calculated.public void labelDimensionSFCT(TLspLabelID aLabelID, TLspPaintState aPaintState, TLspContext aContext, Dimension2D aDimensionSFCT) throws TLcdNoBoundsException
ILspStampLocationLabelPainter
ALspLabelLocation
is passed in this method.labelDimensionSFCT
in interface ILspStampLocationLabelPainter
aLabelID
- the identifier of the label for which to calculate the dimension.aPaintState
- the paint state.aContext
- the context.aDimensionSFCT
- the object in which to store the dimension.TLcdNoBoundsException
- when the dimension of the label could not be calculated.public void labelAnchorPointOffsetSFCT(TLspLabelID aLabel, Dimension2D aDimension, TLspPaintState aPaintState, TLspContext aContext, ILcd2DEditablePoint aOffsetSFCT)
ILspStampLocationLabelPainter
0
. By default this
method returns an offset of (width / 2, height / 2)
. Since the anchor offset
shouldn't depend on the location of the label, no ALspLabelLocation
is passed in
this method.
labelAnchorPointOffsetSFCT
in interface ILspStampLocationLabelPainter
aLabel
- a label.aDimension
- the dimension of the label.aPaintState
- the paint state.aContext
- the context.aOffsetSFCT
- the point in which the anchor point offset will be stored.public Iterable<TLspLabelID> getLabelIDs(Object aObject, TLspPaintRepresentationState aPaintRepresentationState, TLspContext aContext)
ILspLabelPainter
getLabelIDs
in interface ILspLabelPainter
aObject
- the domain objectaPaintRepresentationState
- the paint representationaContext
- the contextpublic double labelBoundsSFCT(TLspLabelID aLabel, ALspLabelLocation aLabelLocation, ALspLabelLocations aLocations, TLspPaintState aPaintState, TLspContext aContext, ILcd3DEditableBounds aBoundsSFCT) throws TLcdNoBoundsException
ILspLabelPainter
Calculates the bounds of the given label for the given label location.
This method returns the axis aligned bounds using aBoundsSFCT
and returns
a rotation. This rotation rotates the bounds around its origin. The rotation of the bounds
is defined in radians, clockwise, with 0 at 3 'o clock.
It is possible that the bounds of this label depends on the location
of an other label. In that case, it is possible to use the given view
locations to retrieve an other location. Note that the given ALspLabelLocations
should not be modified in this method.
labelBoundsSFCT
in interface ILspLabelPainter
aLabel
- the label for which to calculate the bounds.aLabelLocation
- the location of the label.aLocations
- possible context information. This object can for example be used when
these bounds depend on bounds of an other label.aPaintState
- the paint state.aContext
- the context.aBoundsSFCT
- the object in which to store the axis aligned bounds.TLcdNoBoundsException
- when the bounds could not be calculated.public final void labelAnchorPointSFCT(TLspLabelID aLabel, ALspLabelLocation aLabelLocation, ALspLabelLocations aLabelLocations, TLspPaintState aPaintState, TLspContext aContext, ILcd3DEditablePoint aAnchorPointSFCT) throws TLcdNoBoundsException
ILspLabelPainter
labelAnchorPointSFCT
in interface ILspLabelPainter
aLabel
- the label for which to calculate the bounds.aLabelLocation
- the location of the label.aLabelLocations
- possible context information. This object can for example be used when
these bounds depend on bounds of an other label.aPaintState
- the paint state.aContext
- the context.aAnchorPointSFCT
- the point in which to store the anchor point.TLcdNoBoundsException
- when the anchor point could not be calculated.public final Object getAnchorObject(TLspLabelID aLabel, TLspPaintState aPaintState, TLspContext aContext) throws TLcdNoBoundsException
ILspLabelPainter
TLspLabelID
, an ILcdShape
, and ALspStyleTargetProvider
or null
. In the latter case, the painter interprets the anchor itself,
i.e. by using the focus point of the domain object.
The various labeling algorithms use this anchor object to determine the label's location.
You can specify this anchor object using a ALspLabelStyler
:
ALspLabelStyleCollector.anchorLabel(java.lang.Object)
to make place label relative to another label.ALspLabelStyleCollector.geometry(ILcdShape)
to specify a specific geometry to be used.ALspLabelStyleCollector.geometry(ALspStyleTargetProvider)
to specify a style target provider to be used. Using
this method has the advantage that it is possible to specify a different shape reference than the model reference.null
, and the algorithms use the domain
object itself to determine the location.getAnchorObject
in interface ILspLabelPainter
aLabel
- the label.aPaintState
- the paint state.aContext
- the context.TLcdNoBoundsException
- if there is no anchor object for the given label.public void prepareChanges(List<TLspPaintGroupsChangedEvent> aEvents, Object aEventId, ILspPaintGroupsChangeListener.Callback aCallback)
ILspPaintGroupsChangeListener
ILspPaintGroupsChangeListener.Callback.changesReady(java.lang.Object)
method must be invoked when the listener is
ready to commit the changes.
If aEventId
is null
then the changes may be committed immediately. In this case
there will be no call to ILspPaintGroupsChangeListener.commitChanges(Object)
.
Note that it is not mandatory to do this two-phased commit cycle. You may commit or apply the changes immediately, but you still must invoke the callback.
prepareChanges
in interface ILspPaintGroupsChangeListener
aEvents
- the changesaEventId
- the event id or null
aCallback
- the callback or null
public void commitChanges(Object aEventId)
ILspPaintGroupsChangeListener
commitChanges
in interface ILspPaintGroupsChangeListener
aEventId
- the event idpublic ILspStyler getStyler(TLspPaintState aPaintState)
ILspPainter
PaintState
. Can return null
in case the painter does not use or expose a styler.getStyler
in interface ILspPainter
aPaintState
- the paint state for which a styler is requestedpublic void registerLayer(ILspInteractivePaintableLayer aLayer, TLspPaintRepresentation aPaintRepresentation)
ILspPainter
ILspPainter.unregisterLayer(ILspInteractivePaintableLayer, com.luciad.view.lightspeed.layer.TLspPaintRepresentation)
.registerLayer
in interface ILspPainter
aLayer
- A layer with which this painter will be used.aPaintRepresentation
- The paint representation for which this painter will be used.public void unregisterLayer(ILspInteractivePaintableLayer aLayer, TLspPaintRepresentation aPaintRepresentation)
ILspPainter
ILspPainter.registerLayer(ILspInteractivePaintableLayer, com.luciad.view.lightspeed.layer.TLspPaintRepresentation)
.unregisterLayer
in interface ILspPainter
aLayer
- A layer that needs to be unregisteredaPaintRepresentation
- The paint representation for which this painter was used with
aLayerpublic TLspPaintProgress paintObjects(ILcdGLDrawable aGLDrawable, List<TLspPaintGroup> aPaintGroups, TLspPaintPass aPass, TLspContext aContext)
ILspPainter
Paints the specified groups of objects into a view. The objects are partitioned into
TLspPaintGroup
s, which are created by the layer which invoked this painter.
Painters are advised to also implement ILspPaintGroupsChangeListener
,
which allows them to keep track of changes to the supplied list of paint groups. This
way, the painter can exploit temporal coherence and perform its work in the most optimal
way.
This method returns a TLspPaintProgress
which describes the completeness of the
paint operation. If the painter scheduled one or more tasks to be executed asynchronously,
it may return from its paintObjects()
method before having rendered all the objects
it was given. In this case, the returned progress object can describe the amount of work that
has been done and the work that is still remaining.
paintObjects
in interface ILspPainter
aGLDrawable
- the ILcdGLDrawable
in which the objects are to be paintedaPaintGroups
- the objects to be paintedaPass
- the current paint passaContext
- provides context information to the painterTLspPaintProgress
object describing the completeness of the paint operationpublic <T> boolean query(List<TLspPaintGroup> aPaintGroups, ALspPaintQuery<T> aQuery, TLspPaintRepresentationState aPaintRepresentationState, TLspContext aContext)
ILspPainter
query
in interface ILspPainter
aPaintGroups
- the paint groupsaQuery
- the queryaPaintRepresentationState
- the paint representation state for which the query should be
performedaContext
- the contexttrue
if the query completed, false
if it was aborted.public TLspOpenGLProfile getRequiredOpenGLProfile()
ILspPainter
getRequiredOpenGLProfile
in interface ILspPainter
TLspGLProfile
public void addPropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILspPainter
PropertyChangeListener
to the list of listeners that must be notified when
any of the properties of this ILspPainter
changes.addPropertyChangeListener
in interface ILspPainter
aPropertyChangeListener
- the listener that from now on will be notified of all changes
to
properties of this painterpublic void removePropertyChangeListener(PropertyChangeListener aPropertyChangeListener)
ILspPainter
PropertyChangeListener
from the list of listeners.
This listener will no longer be notified of any changes to the properties
of this ILspPainter
removePropertyChangeListener
in interface ILspPainter
aPropertyChangeListener
- the listener that no longer will be notified of any changes to
properties of this painter