Class ALcdLabelLocations
- Direct Known Subclasses:
TLcdLabelLocations
ALcdLabelLocations is the central place where information is kept about the
position of labels and whether or not they were drawn. It is specific to a single
ILcdLayer, for example a ILcdGXYEditableLabelsLayer. Refer to the
documentation of that class how this information is used in other classes.
For a single label, this information is updated and retrieved using the methods putLabelLocation and getLabelLocationSFCT respectively.
It is also possible to consult all
stored label location information using the methods
applyOnAllLabelLocations and
applyOnPaintedLabelLocations
It is up to the implementation of this class how this information is stored. One implementation may store the information inside the domain objects, while another implementation may store this information external to the domain object in some sort of a map.
All classes that contain label painting logic, such as the implementations of ILcdGXYLayer, ILcdGXYLayerLabelPainter and
ILcdGXYViewLabelPainter, must inform this information store on which
labels have been painted.
Implementations can use TLcdLabelLocationEventSupport to facilitate
the handling of events.
- Since:
- 7.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIterator to iterate over label locations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidAdds the specified listener to this information store.abstract voidaddLabelPaintedListener(ILcdLabelPaintedListener aListener) Adds the specified listener to this information store.abstract voidapplyOnAllLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction) Iterates over all stored label locations by callingapplyOnLabelLocationfor every label location.abstract voidapplyOnPaintedLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction) Iterates over all label locations for the labels that were painted by callingapplyOnLabelLocationfor every painted label location.abstract voidclearAllPainted(ILcdView aView, int aFireEventMode) Clears the painted status of all labels for the givenILcdView.abstract TLcdLabelLocationCreates a new instance of (an extension of)TLcdLabelLocation.abstract voidfireCollectedChanges(ILcdView aView) Informs the label location listeners of the changes that were collected inputLabelLocation.abstract voidInforms the listeners registered usingaddLabelPaintedListener(ILcdLabelPaintedListener)of the changes that were collected insetPainted(Object, int, int, ILcdView, boolean, int)andclearAllPainted(ILcdView, int).voidgetDefaultLabelLocationSFCT(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocationSFCT) Retrieves the default label location information of the specified label and puts that information inaLocationSFCT.abstract booleangetLabelLocationSFCT(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocationSFCT) Retrieves the label location information of the specified label and puts that information inaLocationSFCT.abstract ILcdLayergetLayer()Returns the layer to which thisALcdLabelLocationsinstance belongs.abstract booleanReturns whether or not the specified label is currently painted.abstract voidputLabelLocation(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocation, int aFireEventMode) Stores the given information so it can beretrievedlater on.abstract voidRemoves the specified listener.abstract voidRemoves the specified listener.abstract voidsetPainted(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, boolean aPainted, int aFireEventMode) Marks the specified label as painted or not painted according toaPainted.
-
Constructor Details
-
ALcdLabelLocations
public ALcdLabelLocations()
-
-
Method Details
-
addLabelLocationListener
Adds the specified listener to this information store. This listener will be notified of changes in the label information.- Parameters:
aListener- The listener that should be informed when there are changes in the label information.- See Also:
-
removeLabelLocationListener
Removes the specified listener. This listener will no longer be notified of changes in the label information.- Parameters:
aListener- The listener to remove.
-
addLabelPaintedListener
Adds the specified listener to this information store. The listener will be notified of changes in the label painted status with aTLcdLabelPaintedEvent.- Parameters:
aListener- The listener that should be informed when there are changes in the painted status of a label.- See Also:
-
removeLabelPaintedListener
Removes the specified listener. This listener will no longer be notified of changes in the painted label information.- Parameters:
aListener- The listener to remove.
-
fireCollectedChanges
Informs the label location listeners of the changes that were collected in
putLabelLocation. These changes were only collected when theaEventModeparameter of this method wasILcdFireEventMode#FIRE_LATER.The queue of collected changes is empty when this method returns.
- Parameters:
aView- TheILcdViewfor which to fire the collected changes.- See Also:
-
putLabelLocation
public abstract void putLabelLocation(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, TLcdLabelLocation aLocation, int aFireEventMode) Stores the given information so it can be
retrievedlater on.This method also allows to remove the information: just let the TLcdLabelLocation be
null.If you specify
ILcdFireEventMode#FIRE_LATERforaEventMode, you must either callfireCollectedChanges(ILcdView)sometime afterward or call this method withILcdFireEventMode#FIRE_NOWas 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 (seeILcdGXYViewLabelPlacer), the label editor, or other code that manually adjusts offset labels.- Parameters:
aObject- The domain object to which this label information applies. This object should be contained in theILcdModelof the associatedILcdLayeraLabelIndex- 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 isnull, any label information already present in this instance about the given domain object, label index and sublabel index is removed from this class.aFireEventMode- A code indicating if and when the listeners should be informed of this change. This code should be one ofILcdFireEventMode.FIRE_NOW,ILcdFireEventMode.FIRE_LATERorILcdFireEventMode.NO_EVENT- See Also:
-
getLabelLocationSFCT
public abstract 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 inaLocationSFCT. The return value indicates whether or not the requested information was available in this store.aObjectshould be contained in the ILcdModel of the ILcdLayer to which this ALcdLabelLocations belongs.- Parameters:
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- TheTLcdLabelLocationinstance 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 usecreateLabelLocationto create a valid instance for this parameter.- Returns:
trueif the requested label location information was available,falseotherwise.
-
getDefaultLabelLocationSFCT
public 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 inaLocationSFCT.aObjectshould be contained in the ILcdModel of the ILcdLayer to which this ALcdLabelLocations belongs.- Parameters:
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- TheTLcdLabelLocationinstance that will be updated with the default label location information. One should usecreateLabelLocationto create a valid instance for this parameter.
-
applyOnAllLabelLocations
public abstract void applyOnAllLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction) Iterates over all stored label locations by calling
applyOnLabelLocationfor every label location.If
applyOnLabelLocationreturnstrue, the iteration continues, if it returnsfalsethe iteration is aborted.- Parameters:
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.
-
applyOnPaintedLabelLocations
public abstract void applyOnPaintedLabelLocations(ILcdView aView, ALcdLabelLocations.LabelLocationFunction aLabelLocationFunction) Iterates over all label locations for the labels that were painted by calling
applyOnLabelLocationfor every painted label location. The iteration order is preferably the order in which they were marked as painted.If
applyOnLabelLocationreturnstrue, the iteration continues, if it returnsfalsethe iteration is aborted.- Parameters:
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.
-
fireCollectedLabelPaintedChanges
Informs the listeners registered using
addLabelPaintedListener(ILcdLabelPaintedListener)of the changes that were collected insetPainted(Object, int, int, ILcdView, boolean, int)andclearAllPainted(ILcdView, int). These changes were only collected when theaEventModeparameter of this method wasILcdFireEventMode#FIRE_LATER.The queue of collected changes is empty when this method returns.
- Parameters:
aView- TheILcdViewfor which to fire the collected changes.- See Also:
-
setPainted
public abstract void setPainted(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView, boolean aPainted, int aFireEventMode) 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.
- Parameters:
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 toaPainted.aPainted- Whether or not the label should be marked as painted.aFireEventMode- A code indicating if and when the listeners should be informed of this change. This code should be one ofILcdFireEventMode.FIRE_NOW,ILcdFireEventMode.FIRE_LATERorILcdFireEventMode.NO_EVENT- See Also:
-
isPainted
public abstract boolean isPainted(Object aObject, int aLabelIndex, int aSubLabelIndex, ILcdView aView) Returns whether or not the specified label is currently painted.- Parameters:
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.- Returns:
- Whether or not the specified label was marked as painted for the given
ILcdView. - See Also:
-
clearAllPainted
Clears the painted status of all labels for the givenILcdView. This is typically done right before a layer (or layer label painter or view label painter etc) starts painting the labels.- Parameters:
aView- The view for which to clear all painted labels, or null to clear the status for all views.aFireEventMode- A code indicating if and when the listeners should be informed of this change. This code should be one ofILcdFireEventMode.FIRE_NOW,ILcdFireEventMode.FIRE_LATERorILcdFireEventMode.NO_EVENT
-
getLayer
Returns the layer to which thisALcdLabelLocationsinstance belongs.- Returns:
- The layer to which this
ALcdLabelLocationsinstance belongs.
-
createLabelLocation
Creates a new instance of (an extension of)TLcdLabelLocation. Use this method to have a workingTLcdLabelLocationinstance that can for example be passed togetLabelLocationSFCT.- Returns:
- A new
TLcdLabelLocationinstance. - See Also:
-