Class TLcdGXYCompositeLabelPainter
- All Implemented Interfaces:
ILcdPropertyChangeSource,ILcdGXYLabelEditor,ILcdGXYLabelEditorProvider,ILcdGXYLabelPainter,ILcdGXYLabelPainter2,ILcdGXYLabelPainterProvider,ILcdGXYMultiLabelPainter,Serializable,Cloneable
ILcdGXYLabelPainters into 1 label painter.
It does so by remapping the label and sublabel indices of the delegate label painters to get
consistent indices.
An advantage of using this class is that labels of the same object can be easily represented in
different ways. For example one of the labels of an object can be represented by an icon (e.g. by
using TLcdGXYLabelPainterAdapter) while another label can be
represented textually (e.g by using TLcdGXYLabelPainter).
This label painter can also be used as ILcdLabelGXYEditor. It is not necessary to add
a label editor for each label painter. In case no label editor is added for a label painter, no
editing will be performed for those labels.
The remapping of the indices can be done in two ways.
When using this mode the label indices are shifted. For example label painter P1 has 2 labels, each with 2 sublabels, label painter P2 has 3 labels, each with one sublabel. Then the composite label painter has the following labels and sublabels :
| label | sublabel | target label painter | target label | target sublabel |
|---|---|---|---|---|
| 0 | 0 | P1 | 0 | 0 |
| 0 | 1 | P1 | 0 | 1 |
| 1 | 0 | P1 | 1 | 0 |
| 1 | 1 | P1 | 1 | 1 |
| 2 | 0 | P2 | 0 | 0 |
| 3 | 0 | P2 | 1 | 0 |
| 4 | 0 | P2 | 2 | 0 |
When using this mode the sublabel indices are shifted. For example label painter P1 has 2 labels, each with 2 sublabels, label painter P2 has 3 labels, each with one sublabel. Then the composite label painter has the following labels and sublabels :
| label | sublabel | target label painter | target label | target sublabel |
|---|---|---|---|---|
| 0 | 0 | P1 | 0 | 0 |
| 0 | 1 | P1 | 0 | 1 |
| 0 | 2 | P2 | 0 | 0 |
| 1 | 0 | P1 | 1 | 0 |
| 1 | 1 | P1 | 1 | 1 |
| 1 | 2 | P2 | 1 | 0 |
| 2 | 0 | P2 | 2 | 0 |
Note :
This painter passes ( null, null ) to the delegate label painter's
getLabelCount method. The delegate label painter should take this into account.
- Since:
- 10.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPossible index remapping modes. -
Field Summary
Fields inherited from interface com.luciad.view.gxy.ILcdGXYLabelEditor
CREATING, END_CREATION, RESHAPED, START_CREATION, TRANSLATEDFields inherited from interface com.luciad.view.gxy.ILcdGXYLabelPainter
DEFAULT, SELECTEDFields inherited from interface com.luciad.view.gxy.ILcdGXYLabelPainter2
BODY, CREATING, HANDLES, RESHAPING, SNAPS, TRANSLATING -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new composite label painter.TLcdGXYCompositeLabelPainter(TLcdGXYCompositeLabelPainter.IndexRemappingMode aIndexRemappingMode) Creates a new composite label painter using the given index remapping mode. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacceptSnapTargetForLabel(Graphics aGraphics, ILcdGXYContext aGXYContext) Returns whether the label specified bysetObject,setLabelIndexandsetSubLabelIndexaccepts the snap target in the givenILcdGXYContext.voidaddLabelPainter(ILcdGXYLabelPainter aLabelPainter) Adds the given label painter to this composite label painter.voidaddLabelPainter(ILcdGXYLabelPainter aLabelPainter, int aIndex) Adds the given label painter to this composite label painter at the given index.voidaddLabelPainter(ILcdGXYLabelPainter aLabelPainter, ILcdGXYLabelEditor aLabelEditor) Adds the given label painter and editor to this composite label painter.voidaddLabelPainter(ILcdGXYLabelPainter aLabelPainter, ILcdGXYLabelEditor aLabelEditor, int aIndex) Adds the given label painter and editor to this composite label painter at the given index.clone()Returns a new instance of thisALcdGXYLabelPainter.booleaneditLabel(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Adapts the setTLcdLabelLocationaccording to the information present in aGXYContext.getGXYLabelEditor(Object aObject) Returns a validILcdGXYLabelEditorfor editing the labels of aObject.getGXYLabelPainter(Object aObject) Finds anILcdGXYLabelPainterthat can be used to label the object passed.Returns the index remapping mode used by this composite label painter.intgetLabelCount(Graphics aGraphics, ILcdGXYContext aGXYContext) Return the number of labels for the currently set object.intReturns the number of points required to initialize the label of the setObject.getLabelCursor(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Returns aCursorto indicate the type of editingaModeandaGXYContext.Returns a list of label editors that are used in this composite label painter.Returns a list of label painters that are used in this composite label painter.intgetPossibleLocationCount(Graphics aGraphics) Returns the number of possible locations where thisILcdGXYLabelPaintercan paint/draw the labels of the set domainObject.intgetSubLabelCount(int aLabelIndex) Returns the number of sublabels for the set object and the given label index.booleanisLabelTouched(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Tests if the label specified bysetObject,setLabelIndexandsetSubLabelIndexis touched at view location(specified by aGXYContext.getX()andaGXYContext.getY()), considering the mode and theILcdGXYContextinstance.voidlabelAnchorPointSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Point aPointSFCT) SetsaPointSFCTto the anchor point of the label specified bysetObject,setLabelIndexandsetSubLabelIndex.doublelabelBoundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) Calculates the bounds of the label that can be painted.voidpaintLabel(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Paints the label specified bysetObject,setLabelIndexandsetSubLabelIndexonaGraphics.intremoveLabelPainter(ILcdGXYLabelPainter aLabelPainter) Removes the given label painter from this composite label painter.voidsetIndexRemappingMode(TLcdGXYCompositeLabelPainter.IndexRemappingMode aRemappingMode) Sets the index remapping mode to be used by this composite label painter.Methods inherited from class com.luciad.view.gxy.ALcdGXYLabelPainter
addPropertyChangeListener, firePropertyChangeEvent, getDisplayName, getLabelIndex, getLabelLocation, getLocationIndex, getObject, getSubLabelIndex, labelSnapTarget, removePropertyChangeListener, setDisplayName, setLabelIndex, setLabelLocation, setLocationIndex, setObject, setSubLabelIndex, supportLabelSnapMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.luciad.view.gxy.ILcdGXYLabelEditor
getDisplayName, getLabelIndex, getLabelLocation, getObject, getSubLabelIndex, setLabelIndex, setLabelLocation, setObject, setSubLabelIndexMethods inherited from interface com.luciad.util.ILcdPropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
-
Constructor Details
-
TLcdGXYCompositeLabelPainter
public TLcdGXYCompositeLabelPainter()Creates a new composite label painter. The delegate label painters should first be set usingaddLabelPainter(ILcdGXYLabelPainter). When using this constructor, the index remapping mode is set toTLcdGXYCompositeLabelPainter.IndexRemappingMode.SHIFT_LABEL_INDEX. -
TLcdGXYCompositeLabelPainter
public TLcdGXYCompositeLabelPainter(TLcdGXYCompositeLabelPainter.IndexRemappingMode aIndexRemappingMode) Creates a new composite label painter using the given index remapping mode. The delegate label painters should first be set usingaddLabelPainter(ILcdGXYLabelPainter).- Parameters:
aIndexRemappingMode- an index remapping mode.
-
-
Method Details
-
getIndexRemappingMode
Returns the index remapping mode used by this composite label painter.- Returns:
- the index remapping mode used by this composite label painter.
- See Also:
-
setIndexRemappingMode
Sets the index remapping mode to be used by this composite label painter.- Parameters:
aRemappingMode- the index remapping mode to be used by this composite label painter.- See Also:
-
addLabelPainter
Adds the given label painter to this composite label painter.- Parameters:
aLabelPainter- a label painter.
-
addLabelPainter
Adds the given label painter to this composite label painter at the given index.- Parameters:
aLabelPainter- a label painter.aIndex- a given index.
-
addLabelPainter
Adds the given label painter and editor to this composite label painter.- Parameters:
aLabelPainter- a label painter.aLabelEditor- a label editor.
-
addLabelPainter
public void addLabelPainter(ILcdGXYLabelPainter aLabelPainter, ILcdGXYLabelEditor aLabelEditor, int aIndex) Adds the given label painter and editor to this composite label painter at the given index.- Parameters:
aLabelPainter- a label painter.aLabelEditor- a label editor.aIndex- a given index.
-
removeLabelPainter
Removes the given label painter from this composite label painter.- Parameters:
aLabelPainter- a label painter.- Returns:
- the index at which the removed label painter was stored or
-1if this composite label painter didn't contain the given label painter.
-
getLabelPainters
Returns a list of label painters that are used in this composite label painter. Modifying this list will have no effect on this composite label painter.- Returns:
- a list of label painters that are used in this composite label painter.
-
getLabelEditors
Returns a list of label editors that are used in this composite label painter. Modifying this list will have no effect on this composite label painter.- Returns:
- a list of label editors that are used in this composite label painter.
-
getLabelCount
Description copied from class:ALcdGXYLabelPainterReturn the number of labels for the currently set object. The default implementation returns
1. Override this method if you need to support multiple labels.- Specified by:
getLabelCountin interfaceILcdGXYLabelEditor- Specified by:
getLabelCountin interfaceILcdGXYMultiLabelPainter- Overrides:
getLabelCountin classALcdGXYLabelPainter- Parameters:
aGraphics- TheGraphicsinstance on which the labels would be painted.aGXYContext- The context containing information about the layer and the view for which the label would be drawn.- Returns:
- The number of labels for the set object. This should be greater than
0.
-
getSubLabelCount
public int getSubLabelCount(int aLabelIndex) Description copied from class:ALcdGXYLabelPainterReturns the number of sublabels for the set object and the given label index. The default implementation returns
1. Override this method if you need to support multiple sublabels.- Specified by:
getSubLabelCountin interfaceILcdGXYLabelEditor- Specified by:
getSubLabelCountin interfaceILcdGXYMultiLabelPainter- Overrides:
getSubLabelCountin classALcdGXYLabelPainter- Parameters:
aLabelIndex- The label index for which you need to know the number of sublabels.- Returns:
- The number of sublabels. This should be greater than
0. - See Also:
-
getLabelCursor
Description copied from class:ALcdGXYLabelPainterReturns aCursorto indicate the type of editingaModeandaGXYContext.This default implementation always returns
null. Override this method if you want to display custom cursors.- Specified by:
getLabelCursorin interfaceILcdGXYLabelPainter2- Overrides:
getLabelCursorin classALcdGXYLabelPainter- Parameters:
aGraphics- TheGraphicsinstance on which the label is painted.aMode- The mode to consider. SeeILcdGXYLabelPainter2.paintLabel(java.awt.Graphics, int, ILcdGXYContext)for more information.aGXYContext- TheILcdGXYContextcontaining extra information, such as the layer, the view and the mouse position.- Returns:
- a
Cursorto indicate the type of editingaModeandaGXYContext. Returnsnullif no particularCursoris required.
-
isLabelTouched
Description copied from interface:ILcdGXYLabelPainter2Tests if the label specified bysetObject,setLabelIndexandsetSubLabelIndexis touched at view location(specified by aGXYContext.getX()andaGXYContext.getY()), considering the mode and theILcdGXYContextinstance.Before calling this method, the domain object, the label index, the sublabel index and the location of the label should be set using the respective methods.
- Specified by:
isLabelTouchedin interfaceILcdGXYLabelPainter2- Parameters:
aGraphics- TheGraphicsinstance on which the label is painted.aMode- the mode to consider. This is a bitwise combinations of several constants. SeeILcdGXYLabelPainter2.paintLabel(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)for more information.aGXYContext- theILcdGXYContextto consider.- Returns:
- true if the representation of the Object returned by getObject() is touched, false otherwise
- See Also:
-
labelAnchorPointSFCT
public void labelAnchorPointSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Point aPointSFCT) throws TLcdNoBoundsException Description copied from interface:ILcdGXYLabelPainter2Sets
aPointSFCTto the anchor point of the label specified bysetObject,setLabelIndexandsetSubLabelIndex.If the location index is less than 0, the label anchor point is unambiguously determined by the
label location. The actual label is to be painted somewhere around this anchor point. This method is typically called to compare the result with the label bounds, thus determining the exact relation between thelabeland itslocation.Before calling this method, the domain object, the label index, the sublabel index and the location of the label should be set using the respective methods.
- Specified by:
labelAnchorPointSFCTin interfaceILcdGXYLabelPainter2- Parameters:
aGraphics- TheGraphicsinstance on which the label is painted.aMode- The mode to consider. This can be a bitwise combination of several constants. SeeILcdGXYLabelPainter2.paintLabel(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)for more information.aGXYContext- TheILcdGXYContextthat can be used to retrieve extra information.aPointSFCT- The point which will be updated to reflect the location of the anchor point.- Throws:
TLcdNoBoundsException- if the Object doesn't have any valid anchor point, e.g. if it is always invisible in the current projection.- See Also:
-
labelBoundsSFCT
public double labelBoundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) throws TLcdNoBoundsException Description copied from interface:ILcdGXYLabelPainter2Calculates the bounds of the label that can be painted. The bounds are set as a side effect in
aRectangleSFCT, the orientation ofaRectangleSFCTis returned as an angle.The bounds represent the upper left point of the label, and a width and a height. The rotation value represents the rotation of the label bounds around the upper left point.
The domain object, the label index, the sublabel index and the location of the label for which the bounds are retrieved should be set before calling this method using the respective methods.
Note that if this label painter is used in conjunction with a labeling algorithm, the bounds should preferably be independent of the location, as this will yield the best results.
- Specified by:
labelBoundsSFCTin interfaceILcdGXYLabelPainter- Specified by:
labelBoundsSFCTin interfaceILcdGXYLabelPainter2- Parameters:
aGraphics- theaGraphicsto consider.aMode- the representation mode of the label.aGXYContext- theILcdGXYContextthe drawing depends on.aRectangleSFCT- theRectanglecontaining the bounds of the label in view / graphics coordinates as side effect.- Returns:
- the angle orientation of the rectangle around the labels in RADIANs, clockwise, 0 at 3 o'clock.
- Throws:
TLcdNoBoundsException- if the Object doesn't have any valid bounds, e.g. if it is always invisible in the current projection.- See Also:
-
paintLabel
Description copied from interface:ILcdGXYLabelPainter2Paints the label specified by
setObject,setLabelIndexandsetSubLabelIndexonaGraphics.aGXYContextshould contain theILcdGXYViewfor which the label is painted andILcdGXYLayerto which the object belongsThe implementation of this method shall define how to paint the specified label in the given mode, considering
aGXYContextand the setTLcdLabelLocation.The domain object, label index, sublabel index and the label location should be set before calling this method using the respective methods.
This interface extends the original contract of the paintLabel method to allow for more modes. Where in the super interface the mode could only be one of
ILcdGXYLabelPainter.DEFAULTorILcdGXYLabelPainter.SELECTED, the mode now can be a bitwise combination of several constants- Specified by:
paintLabelin interfaceILcdGXYLabelPainter- Specified by:
paintLabelin interfaceILcdGXYLabelPainter2- Parameters:
aGraphics- The graphics object to paint the label onaMode- A bitwise combination ofaGXYContext- the drawing context for the label- See Also:
-
getPossibleLocationCount
Description copied from interface:ILcdGXYLabelPainterReturns the number of possible locations where thisILcdGXYLabelPaintercan paint/draw the labels of the set domainObject.The domain
Objectfor which the location count is retrieved should be set before calling this method using theILcdGXYLabelPainter.setObject(java.lang.Object)method.- Specified by:
getPossibleLocationCountin interfaceILcdGXYLabelPainter- Parameters:
aGraphics- the Graphics the label will be painted on.- Returns:
- the number of possible locations where this
ILcdGXYLabelPaintercan paint/draw the labels of the set Object. - See Also:
-
clone
Description copied from class:ALcdGXYLabelPainterReturns a new instance of thisALcdGXYLabelPainter. The label location of the clone is a clone of the label location of the original. No other objects are cloned.- Specified by:
clonein interfaceILcdGXYLabelEditor- Specified by:
clonein interfaceILcdGXYLabelEditorProvider- Specified by:
clonein interfaceILcdGXYLabelPainter- Specified by:
clonein interfaceILcdGXYLabelPainter2- Specified by:
clonein interfaceILcdGXYLabelPainterProvider- Overrides:
clonein classALcdGXYLabelPainter- Returns:
- A new instance of this
ALcdGXYLabelPainterof which the label location is a deep clone.
-
getGXYLabelPainter
Description copied from interface:ILcdGXYLabelPainterProviderFinds anILcdGXYLabelPainterthat can be used to label the object passed.The label painter provider is responsible for setting the object to the label painter before returning the label painter. An implementation should therefore have the following structure:
public ILcdGXYLabelPainter getGXYLabelPainter(Object aObject) { ILcdGXYLabelPainter labelPainter = ... // find the label painter for the object if (labelPainter != null) { labelPainter.setObject(aObject); } return labelPainter; }- Specified by:
getGXYLabelPainterin interfaceILcdGXYLabelPainterProvider- Parameters:
aObject- the object to find a label painter for- Returns:
- a label painter that can be used to label the object; or null if no label painter could be found for the given object, or the object could not be set on the retrieved label painter.
-
editLabel
Description copied from interface:ILcdGXYLabelEditorAdapts the set
TLcdLabelLocationaccording to the information present in aGXYContext. If the method returnstrue, theTLcdLabelLocationwas modified, iffalseis returned, it wasn't changed.The implementation of this method shall define how to edit the label specified by the set domain
Object, label index and sublabel index, considering the given mode andaGXYContext. These should all be set before calling this method. Note that ifaModeis one of the creating modes, the (sub) label indices are irrelevant.- Specified by:
editLabelin interfaceILcdGXYLabelEditor- Parameters:
aGraphics- TheGraphicson which the label is painted.aMode- the mode to consider when editing aObject: aMode shall be a combination ofILcdGXYLabelEditor.TRANSLATED,ILcdGXYLabelEditor.RESHAPED,ILcdGXYLabelEditor.START_CREATION,ILcdGXYLabelEditor.CREATING,ILcdGXYLabelEditor.END_CREATION.
aGXYContext- contains the information to consider when editing the set Object.- Returns:
- true if the label of the set Object has changed, false otherwise.
- See Also:
-
getLabelCreationClickCount
public int getLabelCreationClickCount()Description copied from interface:ILcdGXYLabelEditorReturns the number of points required to initialize the label of the setObject.- Specified by:
getLabelCreationClickCountin interfaceILcdGXYLabelEditor- Returns:
- the number of points required to initialize the label of the set
Objector -1 if this is undefined like for a polyline or a polygon. 0 means graphical creation of labels is not supported.
-
acceptSnapTargetForLabel
Description copied from interface:ILcdGXYLabelEditorReturns whether the label specified by
setObject,setLabelIndexandsetSubLabelIndexaccepts the snap target in the givenILcdGXYContext.The snap target is the
Objectreturned byaGXYContext.getSnapTarget(), and is on theILcdGXYLayerreturned byaGXYContext.getSnapTargetLayer().- Specified by:
acceptSnapTargetForLabelin interfaceILcdGXYLabelEditor- Parameters:
aGraphics- TheGraphicson which the label is painted.aGXYContext- TheILcdGXYContextcontaining the snapping information.- Returns:
trueif the label accepts the snap target,falseotherwise.- See Also:
-
getGXYLabelEditor
Description copied from interface:ILcdGXYLabelEditorProviderReturns a valid
ILcdGXYLabelEditorfor editing the labels of aObject. The returnedILcdGXYLabelEditormust haveaObjectset on it. The TLcdLabelLocation must not yet be set on it.- Specified by:
getGXYLabelEditorin interfaceILcdGXYLabelEditorProvider- Parameters:
aObject- the Object for which to obtain aILcdGXYLabelEditor.- Returns:
- a valid
ILcdGXYLabelEditorfor editing the labels ofaObjectwithaObjectset on it. - See Also:
-