public class TLcdGXYCompositeViewLabelPlacer extends Object implements ILcdGXYViewLabelPlacer
A consequence of this is that there can be overlap between labels from layers of different labeling groups.
Because all delegate label placers place their labels independently, it is possible to avoid
label placement computations when only layers of one group are invalidated. This class does
this using an ILcdGXYViewLabelPlacer
. The delegate label placers are only called
when at least one of their layers was invalidated. Otherwise, the delegate label placers is not
called, and the previous labeling results are reused during painting.
The advantage of using this class is that groups of layers can be labeled completely independently. This makes it possible for example to place labels for a group of fast layers and for a group of slow layers by two different label placers. In that case, the labeling can be executed on two different threads, so they don't block each other. Because of this, the labels of the fast layers will always be up to date. An other advantage is that this class makes it possible to mix synchronous and asynchronous label placing for different groups of layers.
Note: This class will only work correctly when using one of the following ILcdGXYView implementations :
TLcdGXYViewBufferedImage
TLcdGXYViewJPanel
TLcdGXYViewJPanelLightWeight
ILcdGXYViewLabelPlacer.ViewLabelPlacerCallback
Constructor and Description |
---|
TLcdGXYCompositeViewLabelPlacer() |
Modifier and Type | Method and Description |
---|---|
void |
addStatusListener(ILcdStatusListener aListener)
Adds the given status listener to this view label placer.
|
void |
clearViewLabelPlacerCache()
This method clears all
ILcdGXYViewLabelPlacer s which are currently used. |
TLcdGXYCompositeViewLabelPlacer |
clone()
Makes
Object.clone() public. |
protected ILcdGXYViewLabelPlacer |
createViewLabelPlacer(String aGroupID,
ILcdGXYView aGXYView)
Creates a new view label placer for the given group ID in the given view.
|
protected String |
getGroupID(ILcdGXYLayer aGXYLayer,
ILcdGXYView aGXYView)
This method returns a group ID for the given layer.
|
boolean |
isBusyPlacing()
Checks if any asynchronous label placers are busy label placing or if label placing is scheduled.
|
void |
placeLabels(Graphics aGraphics,
ILcdGXYView aGXYView,
ILcdGXYViewLabelPlacer.ViewLabelPlacerCallback aCallback)
The implementation of this method shall define how to place the labels of all objects in
the various
ILcdGXYLayer s of the given ILcdGXYView . |
void |
placeLabels(Graphics aGraphics,
List<ILcdGXYLayer> aGXYLayers,
ILcdGXYView aGXYView,
ILcdGXYViewLabelPlacer.ViewLabelPlacerCallback aCallback)
The implementation of this method shall define how to place the labels of all objects in
the various
ILcdGXYLayer s from the given List . |
void |
removeStatusListener(ILcdStatusListener aListener)
Removes the given status listener from this view label placer.
|
public boolean isBusyPlacing()
true
if the label placer is still label placing, and false
otherwise.protected String getGroupID(ILcdGXYLayer aGXYLayer, ILcdGXYView aGXYView)
By default this method returns the same group ID for every layers.
aGXYLayer
- a given gxy layer.aGXYView
- the gxy view which contains the given layernull
.protected ILcdGXYViewLabelPlacer createViewLabelPlacer(String aGroupID, ILcdGXYView aGXYView)
null
, layers associated with the given group ID never have
their labels placed.
Override this method to return a custom view label placer.
By default this method creates a TLcdGXYLabelPlacer
which uses a
TLcdGXYLabelPainterLocationLabelingAlgorithm
.
aGroupID
- a group ID.aGXYView
- a gxy view.ILcdGXYViewLabelPlacer
for the given group ID. Can be null
.public TLcdGXYCompositeViewLabelPlacer 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 class Object
Object.clone()
public void clearViewLabelPlacerCache()
ILcdGXYViewLabelPlacer
s which are currently used.
After this method is called, this composite view label placer will create other
ILcdGXYViewLabelPlacer
s again when labels are placed, see
createViewLabelPlacer
.public void placeLabels(Graphics aGraphics, ILcdGXYView aGXYView, ILcdGXYViewLabelPlacer.ViewLabelPlacerCallback aCallback)
ILcdGXYViewLabelPlacer
ILcdGXYLayer
s of the given ILcdGXYView
. Here one can
implement or use various smart algorithms to check whether or not to place a label at a
certain location.
Layers for which labels are placed should be ILcdGXYEditableLabelsLayer
s. This
method should then inform the ALcdLabelLocations
associated with that layer
which labels were placed, and where they were placed.
This method should only be called once every time the view is invalidated.
placeLabels
in interface ILcdGXYViewLabelPlacer
aGraphics
- The current Graphics
instance.aGXYView
- The view for which to place the labels.aCallback
- Will be invoked when labels are updated, and when the label placing has ended.ILcdGXYEditableLabelsLayer
,
ALcdLabelLocations.putLabelLocation(java.lang.Object, int, int, com.luciad.view.ILcdView, com.luciad.view.TLcdLabelLocation, int)
,
ALcdLabelLocations.setPainted(java.lang.Object, int, int, com.luciad.view.ILcdView, boolean, int)
public void placeLabels(Graphics aGraphics, List<ILcdGXYLayer> aGXYLayers, ILcdGXYView aGXYView, ILcdGXYViewLabelPlacer.ViewLabelPlacerCallback aCallback)
ILcdGXYViewLabelPlacer
ILcdGXYLayer
s from the given List
. Here one can
implement or use various smart algorithms to check whether or not to place a label at a certain
location.
Layers for which labels are placed should be ILcdGXYEditableLabelsLayer
s. This
method should then inform the ALcdLabelLocations
associated with that layer
which labels were placed, and where they were placed.
This method should only be called once every time the view is invalidated.
placeLabels
in interface ILcdGXYViewLabelPlacer
aGraphics
- The current Graphics
instance.aGXYLayers
- Only the labels for the layers in this List
will be placed.aGXYView
- The view for which to place the labels.aCallback
- Will be invoked when labels are updated, and when the label placing has ended.ILcdGXYEditableLabelsLayer
,
ALcdLabelLocations.putLabelLocation(java.lang.Object, int, int, com.luciad.view.ILcdView, com.luciad.view.TLcdLabelLocation, int)
,
ALcdLabelLocations.setPainted(java.lang.Object, int, int, com.luciad.view.ILcdView, boolean, int)
public void addStatusListener(ILcdStatusListener aListener)
ILcdGXYViewLabelPlacer
addStatusListener
in interface ILcdGXYViewLabelPlacer
aListener
- a labeling listener.public void removeStatusListener(ILcdStatusListener aListener)
ILcdGXYViewLabelPlacer
removeStatusListener
in interface ILcdGXYViewLabelPlacer
aListener
- a labeling listener.