Class TLcdGXYCompositeLabelingAlgorithm
- All Implemented Interfaces:
ILcdCloneable
,ILcdGXYLabelingAlgorithm
,Cloneable
ILcdGXYLabelingAlgorithm
s. It works
by assigning labeling algorithms to labels using getLabelingAlgorithmProvider()
. Labels
that have the same labeling algorithm are grouped, and then handled by this labeling algorithm.
The order in which the labeling algorithms are executed is determined by the
sortLabelingAlgorithms
method. By default it sorts
the labeling algorithms based on the priorities of the labels that are placed by
them. The highest priority of all of its labels is assigned to each labeling algorithm
(see TLcdCollectedLabelInfo.PRIORITY_KEY
).
The labeling algorithms are then sorted based on this priority. When two algorithms have the
same priority assigned, the original order in which the algorithms are given is respected.
The default labeling order can be customized by overriding the
sortLabelingAlgorithms
method.
The implementation of this labeling algorithm is thread-safe, as long as the set
ILcdGXYLabelLabelingAlgorithmProvider
is thread-safe.
- Since:
- 10.1
-
Constructor Summary
ConstructorDescriptionTLcdGXYCompositeLabelingAlgorithm
(ILcdGXYLabelLabelingAlgorithmProvider<? extends ILcdGXYLabelingAlgorithm> aAlgorithmProvider) Creates a composite labeling algorithm that uses the givenILcdGXYLabelLabelingAlgorithmProvider
to assign labeling algorithms to labels. -
Method Summary
Modifier and TypeMethodDescriptionclone()
MakesObject.clone()
public.collectLabelInfo
(List<TLcdLabelIdentifier> aLabelsToCollect, Graphics aGraphics, ILcdGXYView aGXYView) This method returns aTLcdCollectedLabelInfoList
object based on the given list ofTLcdLabelIdentifier
s.computeLabelPlacements
(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aLabelConflictChecker, ILcdGXYView aView) This method computes a list ofTLcdLabelPlacement
s using the givenTLcdCollectedLabelInfoList
.Returns the used labeling algorithm provider.protected void
sortLabelingAlgorithms
(List<ILcdGXYLabelingAlgorithm> aLabelingAlgorithmsSFCT, TLcdCollectedLabelInfoList aLabelInfoList) This method sorts the givenList
of labeling algorithms.
-
Constructor Details
-
TLcdGXYCompositeLabelingAlgorithm
public TLcdGXYCompositeLabelingAlgorithm(ILcdGXYLabelLabelingAlgorithmProvider<? extends ILcdGXYLabelingAlgorithm> aAlgorithmProvider) Creates a composite labeling algorithm that uses the givenILcdGXYLabelLabelingAlgorithmProvider
to assign labeling algorithms to labels.- Parameters:
aAlgorithmProvider
- a labeling algorithm provider that returns algorithms for a given label.
-
-
Method Details
-
getLabelingAlgorithmProvider
public ILcdGXYLabelLabelingAlgorithmProvider<? extends ILcdGXYLabelingAlgorithm> getLabelingAlgorithmProvider()Returns the used labeling algorithm provider.- Returns:
- the used labeling algorithm provider.
-
sortLabelingAlgorithms
protected void sortLabelingAlgorithms(List<ILcdGXYLabelingAlgorithm> aLabelingAlgorithmsSFCT, TLcdCollectedLabelInfoList aLabelInfoList) This method sorts the givenList
of labeling algorithms. The labeling algorithms will be used in this order to place labels. The original order of the labeling algorithms is determined by the order of the labels in the givenTLcdCollectedLabelInfoList
.The default implementation sorts the labeling algorithms based on the priorities of the labels that are placed by them. The highest priority of all of its labels is assigned to each labeling algorithm (see
TLcdCollectedLabelInfo.PRIORITY_KEY
). The labeling algorithms are then sorted based on this priority. When two algorithms have the same priority assigned, the original order in which the algorithms are given is respected.Override this method to provide a custom label placing order.
- Parameters:
aLabelingAlgorithmsSFCT
- theList
of labeling algorithms to be sorted.aLabelInfoList
- the label info list containing the labels to be placed the labeling algorithms in the givenList
.
-
clone
Description copied from interface:ILcdCloneable
Makes
When for example extending fromObject.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 ); } }
- Specified by:
clone
in interfaceILcdCloneable
- Overrides:
clone
in classObject
- See Also:
-
collectLabelInfo
public TLcdCollectedLabelInfoList collectLabelInfo(List<TLcdLabelIdentifier> aLabelsToCollect, Graphics aGraphics, ILcdGXYView aGXYView) Description copied from interface:ILcdGXYLabelingAlgorithm
This method returns aTLcdCollectedLabelInfoList
object based on the given list ofTLcdLabelIdentifier
s. The returnedTLcdCollectedLabelInfoList
should contain aTLcdCollectedLabelInfo
object for each label that should be placed.Each
TLcdCollectedLabelInfo
should also contain all information needed bycomputeLabelPlacements
to place the labels. In order to enable correct asynchronous label placing, all calls to the layer and the (label) painters should be done in this method. The results should then be stored in the info objects.It is possible that the returned
TLcdCollectedLabelInfoList
doesn't contain aTLcdCollectedLabelInfo
object for every givenTLcdLabelIdentifier
. In that case the missing labels are not placed.- Specified by:
collectLabelInfo
in interfaceILcdGXYLabelingAlgorithm
- Parameters:
aLabelsToCollect
- the labels for which aTLcdCollectedLabelInfoList
should be created.aGraphics
- the graphics.aGXYView
- the view.- Returns:
- a
TLcdCollectedLabelInfoList
which contains all the information needed to place the labels.
-
computeLabelPlacements
public List<TLcdLabelPlacement> computeLabelPlacements(TLcdCollectedLabelInfoList aLabelInfoList, ILcdLabelConflictChecker aLabelConflictChecker, ILcdGXYView aView) Description copied from interface:ILcdGXYLabelingAlgorithm
This method computes a list ofTLcdLabelPlacement
s using the givenTLcdCollectedLabelInfoList
. The returned label placements should contain a validTLcdLabelLocation
and label bounds. They should also point to their correspondingTLcdCollectedLabelInfo
, which in turn should point to its correspondingTLcdCollectedLabeledObjectInfo
.The given
TLcdCollectedLabelInfoList
should always be an object created or returned bycollectLabelInfo
.The returned
List
ofTLcdLabelPlacement
s contains label placements that are either visible or invisible. When a placement is present in the list, it means that the location should be stored. When a placement in the list is marked as visible, it means that its location should be marked as to-be-painted.The labels should by preference be placed in the order in which the labels are returned by
TLcdCollectedLabelInfoList.getLabels()
.- Specified by:
computeLabelPlacements
in interfaceILcdGXYLabelingAlgorithm
- Parameters:
aLabelInfoList
- the info object that contains all information needed to place the labels.aLabelConflictChecker
- the bounds conflict checker that can be used to detect conflicts between labels.aView
- the view.- Returns:
- a list of labels to be rendered.
-