public class TLcdLabelLocations extends ALcdLabelLocations
Implementation of ALcdLabelLocations
that stores the label locations external
from the domain objects.
This implementation returns the default location (specified in the constructor) when the requested information is not present.
This implementation relies on the identity of the object that is passed to
the methods, so ==
instead of equals
.
ALcdLabelLocations.LabelLocationFunction
Constructor and Description |
---|
TLcdLabelLocations(ILcdLayer aLayer,
TLcdLabelLocation aDefaultLabelLocation)
Constructs a new instance with the specified default location and belonging to the specified
layer.
|
TLcdLabelLocations(ILcdLayer aLayer,
TLcdLabelLocation aDefaultLabelLocation,
ILcdLabelDependencyProvider aLabelDependencyProvider)
Constructs a new instance with the specified default location and belonging to the specified
layer.
|
Modifier and Type | Method and Description |
---|---|
void |
addLabelLocationListener(ILcdLabelLocationListener aListener)
Adds the specified listener to this information store.
|
void |
addLabelPaintedListener(ILcdLabelPaintedListener aListener)
Adds the specified listener to this information store.
|
void |
applyOnAllLabelLocations(ILcdView aView,
ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction)
Iterates over all stored label locations by calling
applyOnLabelLocation
for every label location. |
void |
applyOnPaintedLabelLocations(ILcdView aView,
ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction)
Iterates over all label locations for the labels that were painted by calling
applyOnLabelLocation for
every painted label location. |
void |
clearAllPainted(ILcdView aView,
int aEventMode)
Clears the painted status of all labels for the given
ILcdView . |
TLcdLabelLocation |
createLabelLocation()
Creates a new
TLcdLabelLocation by cloning the given
default label location. |
void |
fireCollectedChanges(ILcdView aView)
Informs the label location listeners of the changes that were collected in
putLabelLocation . |
void |
fireCollectedLabelPaintedChanges(ILcdView aView)
Informs the listeners registered using
ALcdLabelLocations.addLabelPaintedListener(ILcdLabelPaintedListener)
of the changes that were collected in ALcdLabelLocations.setPainted(Object, int, int, ILcdView, boolean, int) and
ALcdLabelLocations.clearAllPainted(ILcdView, int) . |
void |
getDefaultLabelLocationSFCT(Object aObject,
int aLabelIndex,
int aSubLabelIndex,
ILcdView aView,
TLcdLabelLocation aLocationSFCT)
Retrieves the default label location information of the specified label and puts that information
in
aLocationSFCT . |
boolean |
getLabelLocationSFCT(Object aObject,
int aLabelIndex,
int aSubLabelIndex,
ILcdView aView,
TLcdLabelLocation aLocationSFCT)
Retrieves the label location information of the specified label and puts that information in
aLocationSFCT . |
ILcdLayer |
getLayer()
Returns the layer to which this
ALcdLabelLocations instance belongs. |
boolean |
isPainted(Object aObject,
int aLabelIndex,
int aSubLabelIndex,
ILcdView aView)
Returns whether or not the specified label is currently painted.
|
void |
putLabelLocation(Object aObject,
int aLabelIndex,
int aSubLabelIndex,
ILcdView aView,
TLcdLabelLocation aLocation,
int aEventMode)
Stores the given information so it can be
retrieved later on. |
void |
removeLabelLocationListener(ILcdLabelLocationListener aListener)
Removes the specified listener.
|
void |
removeLabelPaintedListener(ILcdLabelPaintedListener aListener)
Removes the specified listener.
|
void |
setLayer(ILcdLayer aLayer)
Sets the layer to which this instance belongs.
|
void |
setPainted(Object aObject,
int aLabelIndex,
int aSubLabelIndex,
ILcdView aView,
boolean aPainted,
int aEventMode)
Marks the specified label as painted or not painted according to
aPainted . |
public TLcdLabelLocations(ILcdLayer aLayer, TLcdLabelLocation aDefaultLabelLocation)
aLayer
- The layer to which this instance belongs. This can be
null
, but the layer must be set with setLayer(ILcdLayer)
before any other method
of this class is called.aDefaultLabelLocation
- The default location information to return when the requested
label location is not available. See ALcdLabelLocations.getLabelLocationSFCT(Object, int, int, ILcdView, TLcdLabelLocation)
public TLcdLabelLocations(ILcdLayer aLayer, TLcdLabelLocation aDefaultLabelLocation, ILcdLabelDependencyProvider aLabelDependencyProvider)
When this constructor is used, the given label dependency provider is used to place a reference
to an other label in the TLcdLabelLocation
instances when a requested label
location is not available, see ALcdLabelLocations.getLabelLocationSFCT(java.lang.Object, int, int, com.luciad.view.ILcdView, com.luciad.view.TLcdLabelLocation)
.
The given label dependency provider should not contain cyclic dependencies, i.e. a label should not depend on itself (directly or indirectly). It should also return at most one parent label for each label. This parent should be a label of the same object as the the given label. So labels should not reference labels from other objects.
aLayer
- The layer to which this instance belongs. This can be
null
, but the layer must be set with setLayer(ILcdLayer)
before any other method
of this class is called.aDefaultLabelLocation
- The default location information to return when the requested
label location is not available. See ALcdLabelLocations.getLabelLocationSFCT(Object, int, int, ILcdView, TLcdLabelLocation)
aLabelDependencyProvider
- a label dependency provider.public void addLabelLocationListener(ILcdLabelLocationListener aListener)
ALcdLabelLocations
addLabelLocationListener
in class ALcdLabelLocations
aListener
- The listener that should be informed when there are changes in the label
information.ALcdLabelLocations.putLabelLocation(Object, int, int, ILcdView, TLcdLabelLocation, int)
public void removeLabelLocationListener(ILcdLabelLocationListener aListener)
ALcdLabelLocations
removeLabelLocationListener
in class ALcdLabelLocations
aListener
- The listener to remove.public void addLabelPaintedListener(ILcdLabelPaintedListener aListener)
ALcdLabelLocations
TLcdLabelPaintedEvent
.addLabelPaintedListener
in class ALcdLabelLocations
aListener
- The listener that should be informed when there are changes in the
painted status of a label.ALcdLabelLocations.setPainted(Object, int, int, ILcdView, boolean, int)
,
ALcdLabelLocations.clearAllPainted(ILcdView, int)
public void removeLabelPaintedListener(ILcdLabelPaintedListener aListener)
ALcdLabelLocations
removeLabelPaintedListener
in class ALcdLabelLocations
aListener
- The listener to remove.public void fireCollectedChanges(ILcdView aView)
ALcdLabelLocations
Informs the label location listeners of the changes that were collected in putLabelLocation
. These changes
were only collected when the aEventMode
parameter of this method was
ILcdFireEventMode#FIRE_LATER
.
The queue of collected changes is empty when this method returns.
fireCollectedChanges
in class ALcdLabelLocations
aView
- The ILcdView
for which to fire the collected changes.ALcdLabelLocations.addLabelLocationListener(ILcdLabelLocationListener)
,
ALcdLabelLocations.putLabelLocation(Object, int, int, ILcdView, TLcdLabelLocation, int)
public void putLabelLocation(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocation, int aEventMode)
ALcdLabelLocations
Stores the given information so it can be retrieved
later on.
This method also allows to remove the information: just let the TLcdLabelLocation be
null
.
If you specify ILcdFireEventMode#FIRE_LATER
for aEventMode
, you
must either call ALcdLabelLocations.fireCollectedChanges(ILcdView)
sometime afterward or call this method with
ILcdFireEventMode#FIRE_NOW
as event mode. This allows you to make multiple changes
to the label locations and inform the listeners afterward in one go, which can be more
efficient than informing them at each change.
Before storing the given label location, one should make sure that the bounds of the parent
label are set (see TLcdLabelLocation.setParentBounds(java.awt.Rectangle, double)
. Examples
of code that should do this are the label placer (see ILcdGXYViewLabelPlacer
),
the label editor, or other code that manually adjusts offset labels.
putLabelLocation
in class ALcdLabelLocations
aObject
- The domain object to which this label information applies. This object
should be contained in the ILcdModel
of the associated
ILcdLayer
aLabelIndex
- The label to which this label information applies.aSubLabelIndex
- The sub label to which this label information applies.aView
- The view for which the location applies.aLocation
- The label information. No reference to this object is kept within the
implementations of this class. This allows the client of this class to
reuse the same object. If this location is null
, any
label information already present in this instance about the given
domain object, label index and sublabel index is removed from this class.aEventMode
- A code indicating if and when the listeners should be informed of this
change. This code should be one of ILcdFireEventMode.FIRE_NOW
,
ILcdFireEventMode.FIRE_LATER
or ILcdFireEventMode.NO_EVENT
ALcdLabelLocations.getLabelLocationSFCT(java.lang.Object, int, int, com.luciad.view.ILcdView, com.luciad.view.TLcdLabelLocation)
public boolean getLabelLocationSFCT(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocationSFCT)
aLocationSFCT
. The return value indicates whether or not the requested information
was available in this store.
aObject
should be contained in the ILcdModel of the ILcdLayer
to which this ALcdLabelLocations belongs.
This implementation loads the default values in aLocationSFCT
in case the
requested information is not present. This is done by calling
getDefaultLabelLocationSFCT
.
getLabelLocationSFCT
in class ALcdLabelLocations
aObject
- The domain object for which you want to retrieve the label location
information.aLabelIndex
- The label for which you want to retrieve the label location information.aSubLabelIndex
- The sub label for which you want to retrieve the label location
information.aView
- The view for which the location is retrieved.aLocationSFCT
- The TLcdLabelLocation
instance that will be updated with the
label location information. It is up to the implementation of this class
to decide what happens when the information was not available.
One should use createLabelLocation
to create a valid
instance for this parameter.true
if the requested label location information was available,
false
otherwise.TLcdLabelLocations(ILcdLayer, TLcdLabelLocation)
public void getDefaultLabelLocationSFCT(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocationSFCT)
aLocationSFCT
.
aObject
should be contained in the ILcdModel of the ILcdLayer
to which this ALcdLabelLocations belongs.
This implementation copies the properties of the default label location (given in the
constructor) to the given label location. It also tries to add a parent label if an
ILcdLabelDependencyProvider
was passed in the constructor.
getDefaultLabelLocationSFCT
in class ALcdLabelLocations
aObject
- The domain object for which you want to retrieve the label location
information.aLabelIndex
- The label for which you want to retrieve the label location information.aSubLabelIndex
- The sub label for which you want to retrieve the label location
information.aView
- The view for which the location is retrieved.aLocationSFCT
- The TLcdLabelLocation
instance that will be updated with the default
label location information. One should use createLabelLocation
to
create a valid instance for this parameter.public void applyOnAllLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction)
ALcdLabelLocations
Iterates over all stored label locations by calling
applyOnLabelLocation
for every label location.
If applyOnLabelLocation
returns
true
, the iteration continues, if it returns false
the iteration is
aborted.
applyOnAllLabelLocations
in class ALcdLabelLocations
aView
- Iterate over the labels for this view.aLabelLocationFunction
- The label iterator. This label iterator contains the logic of what to do
with each label.public void applyOnPaintedLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction)
ALcdLabelLocations
Iterates over all label locations for the labels that were painted by calling
applyOnLabelLocation
for
every painted label location. The iteration order is preferably the order in which they were marked as
painted.
If applyOnLabelLocation
returns
true
, the iteration continues, if it returns false
the iteration is
aborted.
applyOnPaintedLabelLocations
in class ALcdLabelLocations
aView
- Iterate over the labels painter for this view.aLabelLocationFunction
- The label iterator. This label iterator contains the logic of what to do
with each label.public void fireCollectedLabelPaintedChanges(ILcdView aView)
ALcdLabelLocations
Informs the listeners registered using ALcdLabelLocations.addLabelPaintedListener(ILcdLabelPaintedListener)
of the changes that were collected in ALcdLabelLocations.setPainted(Object, int, int, ILcdView, boolean, int)
and
ALcdLabelLocations.clearAllPainted(ILcdView, int)
. These changes were only collected when the
aEventMode
parameter of this method was ILcdFireEventMode#FIRE_LATER
.
The queue of collected changes is empty when this method returns.
fireCollectedLabelPaintedChanges
in class ALcdLabelLocations
aView
- The ILcdView
for which to fire the collected changes.ALcdLabelLocations.addLabelPaintedListener(ILcdLabelPaintedListener)
,
ALcdLabelLocations.setPainted(Object, int, int, ILcdView, boolean, int)
,
ALcdLabelLocations.clearAllPainted(ILcdView, int)
public void setPainted(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, boolean aPainted, int aEventMode)
ALcdLabelLocations
Marks the specified label as painted or not painted according to aPainted
.
All code that paints a label should call this method when they actually paint a label. For instance implementations of ILcdGXYEditableLabelsLayer, ILcdGXYLayerLabelPainter and ILcdGXYViewLabelPainter should call this method when they paint a label.
setPainted
in class ALcdLabelLocations
aObject
- The domain object for which the label was painted.aLabelIndex
- The label index of the label that was painted.aSubLabelIndex
- The sub label index of the label that was painted.aView
- Mark the label painted or not painted on this view, according to
aPainted
.aPainted
- Whether or not the label should be marked as painted.aEventMode
- A code indicating if and when the listeners should be informed of this
change. This code should be one of ILcdFireEventMode.FIRE_NOW
,
ILcdFireEventMode.FIRE_LATER
or ILcdFireEventMode.NO_EVENT
ALcdLabelLocations.clearAllPainted(ILcdView, int)
public boolean isPainted(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView)
ALcdLabelLocations
isPainted
in class ALcdLabelLocations
aObject
- The domain objectaLabelIndex
- The label index of the label for which you want to know if it was
painted.aSubLabelIndex
- The sub label index of the label for which you want to know if it was
painted.aView
- The view for which we want to know if the label was painted on it.ILcdView
.ALcdLabelLocations.applyOnPaintedLabelLocations(com.luciad.view.ILcdView, com.luciad.view.ALcdLabelLocations.LabelLocationFunction)
public void clearAllPainted(ILcdView aView, int aEventMode)
ALcdLabelLocations
ILcdView
. This is typically
done right before a layer (or layer label painter or view label painter etc) starts painting
the labels.clearAllPainted
in class ALcdLabelLocations
aView
- The view for which to clear all painted labels, or null to clear the status for all views.aEventMode
- A code indicating if and when the listeners should be informed of this
change. This code should be one of ILcdFireEventMode.FIRE_NOW
,
ILcdFireEventMode.FIRE_LATER
or ILcdFireEventMode.NO_EVENT
public ILcdLayer getLayer()
ALcdLabelLocations
ALcdLabelLocations
instance belongs.getLayer
in class ALcdLabelLocations
ALcdLabelLocations
instance belongs.public void setLayer(ILcdLayer aLayer)
aLayer
- The layer to which this instance belongs.public TLcdLabelLocation createLabelLocation()
TLcdLabelLocation
by cloning the given
default label location.createLabelLocation
in class ALcdLabelLocations
TLcdLabelLocation
.TLcdLabelLocation