Class TLcdGXYLabelPainterAdapter
- All Implemented Interfaces:
ILcdPropertyChangeSource
,ILcdGXYLabelEditor
,ILcdGXYLabelEditorProvider
,ILcdGXYLabelPainter
,ILcdGXYLabelPainter2
,ILcdGXYLabelPainterProvider
,ILcdGXYMultiLabelPainter
,Serializable
,Cloneable
ILcdGXYPainter
into an ILcdGXYLabelPainter2
.
It uses a set of fixed label positions to position the label. It also offers the possibility
to place a pin.
If an ILcdGXYEditor
is passed in the constructor, this class will also implement
the ILcdGXYLabelEditor
behaviour.
- Since:
- 10.1
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Integer code to place label at center of the anchor point.static final int
Integer code to place label at east of the anchor point.static int
Maximum number of available locations.static final int
Integer code to place label at north of the anchor point.static final int
Integer code to place label at north east of the anchor point.static final int
Integer code to place label at north west of the anchor point.static final int
Integer code to place label at south of the anchor point.static final int
Integer code to place label at south east of the anchor point.static final int
Integer code to place label at south west of the anchor point.static final int
Integer code to place label at west of the anchor point.Fields inherited from interface com.luciad.view.gxy.ILcdGXYLabelEditor
CREATING, END_CREATION, RESHAPED, START_CREATION, TRANSLATED
Fields inherited from interface com.luciad.view.gxy.ILcdGXYLabelPainter
DEFAULT, SELECTED
Fields inherited from interface com.luciad.view.gxy.ILcdGXYLabelPainter2
BODY, CREATING, HANDLES, RESHAPING, SNAPS, TRANSLATING
-
Constructor Summary
ConstructorDescriptionTLcdGXYLabelPainterAdapter
(ILcdGXYPainter aDelegatePainter) Creates a new label painter adapter that makes a label painter out of anILcdGXYPainter
.TLcdGXYLabelPainterAdapter
(ILcdGXYPainter aDelegatePainter, ILcdGXYEditor aDelegateEditor) Creates a new label painter adapter that makes a label painter out of anILcdGXYPainter
and aILcdGXYEditor
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
acceptSnapTargetForLabel
(Graphics aGraphics, ILcdGXYContext aGXYContext) Returns whether the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
accepts the snap target in the givenILcdGXYContext
.protected void
anchorPointSFCT
(Graphics aGraphics, int aMode, ILcdGXYContext aContext, Point aPointSFCT) This method retrieves an anchor point using the correspondingILcdGXYPainter
for the Object to be painted (aGXYContext.getGXYLayer().getGXYPainter( aObject )
).clone()
Returns a new instance of thisALcdGXYLabelPainter
.boolean
editLabel
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Adapts the setTLcdLabelLocation
according to the information present in aGXYContext.Returns the delegate painter.getGXYLabelEditor
(Object aObject) Returns a validILcdGXYLabelEditor
for editing the labels of aObject.getGXYLabelPainter
(Object aObject) Finds anILcdGXYLabelPainter
that can be used to label the object passed.int
getLabelCount
(Graphics aGraphics, ILcdGXYContext aGXYContext) Return the number of labels for the currently set object.int
Returns the number of points required to initialize the label of the setObject
.getLabelCursor
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Returns aCursor
to indicate the type of editingaMode
andaGXYContext
.Returns the painter style that is used when drawing the pin.int[]
Returns the list of possible positions to place the labels.int
getPossibleLocationCount
(Graphics aGraphics) Returns the number of possible locations where thisILcdGXYLabelPainter
can paint/draw the labels of the set domainObject
.int
Returns how many pixels the label must be removed from the anchor point of the domain object when labels are not placed freely (i.e.int
getSubLabelCount
(int aLabelIndex) Returns the number of sublabels for the set object and the given label index.boolean
isLabelTouched
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Tests if the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
is touched at view location(specified by aGXYContext.getX()
andaGXYContext.getY()
), considering the mode and theILcdGXYContext
instance.boolean
Returns whether this editor makes a label sticky when it edits this label.boolean
Returns whether or not this painter draws a line (the "pin") from the label to the anchor point of the domain object.void
labelAnchorPointSFCT
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Point aPointSFCT) SetsaPointSFCT
to the anchor point of the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
.double
labelBoundsSFCT
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) Calculates the bounds of the label that can be painted.void
paintLabel
(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext) Paints the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
onaGraphics
.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setMakeLabelsStickyOnEdit
(boolean aMakeLabelsStickyOnEdit) Determines whether this editor makes a label sticky when it edits this label.void
setPinStyle
(ILcdGXYPainterStyle aPinStyle) Sets the painter style to be used when painting the pin.void
setPositionList
(int[] aPositionList) Sets a new position list.void
setShiftLabelPosition
(int aShift) Sets how many pixels the label must be removed from the anchor point of the domain object when labels are not placed freely (i.e.void
setWithPin
(boolean aWithPin) Specifies whether or not a line (the "pin") should be drawn from the label to the anchor point of the domain object.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, supportLabelSnap
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.view.gxy.ILcdGXYLabelEditor
getDisplayName, getLabelIndex, getLabelLocation, getObject, getSubLabelIndex, setLabelIndex, setLabelLocation, setObject, setSubLabelIndex
Methods inherited from interface com.luciad.util.ILcdPropertyChangeSource
addPropertyChangeListener, removePropertyChangeListener
-
Field Details
-
SOUTH_EAST
public static final int SOUTH_EASTInteger code to place label at south east of the anchor point.- See Also:
-
NORTH_WEST
public static final int NORTH_WESTInteger code to place label at north west of the anchor point.- See Also:
-
NORTH_EAST
public static final int NORTH_EASTInteger code to place label at north east of the anchor point.- See Also:
-
SOUTH_WEST
public static final int SOUTH_WESTInteger code to place label at south west of the anchor point.- See Also:
-
EAST
public static final int EASTInteger code to place label at east of the anchor point.- See Also:
-
WEST
public static final int WESTInteger code to place label at west of the anchor point.- See Also:
-
NORTH
public static final int NORTHInteger code to place label at north of the anchor point.- See Also:
-
SOUTH
public static final int SOUTHInteger code to place label at south of the anchor point.- See Also:
-
CENTER
public static final int CENTERInteger code to place label at center of the anchor point.- See Also:
-
MAXIMUM_AVAILABLE_LOCATIONS
public static int MAXIMUM_AVAILABLE_LOCATIONSMaximum number of available locations.
-
-
Constructor Details
-
TLcdGXYLabelPainterAdapter
Creates a new label painter adapter that makes a label painter out of anILcdGXYPainter
. NoILcdGXYEditor
is set.- Parameters:
aDelegatePainter
- the delegate painter.
-
TLcdGXYLabelPainterAdapter
Creates a new label painter adapter that makes a label painter out of anILcdGXYPainter
and aILcdGXYEditor
.- Parameters:
aDelegatePainter
- the delegate painter.aDelegateEditor
- the delegate editor.
-
-
Method Details
-
getDelegatePainter
Returns the delegate painter.- Returns:
- the delegate painter.
-
isWithPin
public boolean isWithPin()Returns whether or not this painter draws a line (the "pin") from the label to the anchor point of the domain object.- Returns:
true
if the pin is drawn,false
if not.
-
setWithPin
public void setWithPin(boolean aWithPin) Specifies whether or not a line (the "pin") should be drawn from the label to the anchor point of the domain object.- Parameters:
aWithPin
-true
if the pin should be drawn,false
if not.
-
setPinStyle
Sets the painter style to be used when painting the pin. ItssetupGraphics
method will be called right before the pin is drawn.- Parameters:
aPinStyle
- The pin style to use when drawing the pin. This must not benull
.
-
getPinStyle
Returns the painter style that is used when drawing the pin.- Returns:
- The painter style that is used when drawing the pin. This is never
null
.
-
isMakeLabelsStickyOnEdit
public boolean isMakeLabelsStickyOnEdit()Returns whether this editor makes a label sticky when it edits this label. The default isfalse
- Returns:
true
if this label editor makes a label sticky when it edits this label,false
otherwise.- See Also:
-
setMakeLabelsStickyOnEdit
public void setMakeLabelsStickyOnEdit(boolean aMakeLabelsStickyOnEdit) Determines whether this editor makes a label sticky when it edits this label.- Parameters:
aMakeLabelsStickyOnEdit
-true
if the label should be made sticky,false
otherwise.- See Also:
-
paintLabel
Description copied from interface:ILcdGXYLabelPainter2
Paints the label specified by
setObject
,setLabelIndex
andsetSubLabelIndex
onaGraphics
.aGXYContext
should contain theILcdGXYView
for which the label is painted andILcdGXYLayer
to which the object belongsThe implementation of this method shall define how to paint the specified label in the given mode, considering
aGXYContext
and 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.DEFAULT
orILcdGXYLabelPainter.SELECTED
, the mode now can be a bitwise combination of several constants- Specified by:
paintLabel
in interfaceILcdGXYLabelPainter
- Specified by:
paintLabel
in interfaceILcdGXYLabelPainter2
- Parameters:
aGraphics
- The graphics object to paint the label onaMode
- A bitwise combination ofaGXYContext
- the drawing context for the label- See Also:
-
anchorPointSFCT
protected void anchorPointSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aContext, Point aPointSFCT) throws TLcdNoBoundsException This method retrieves an anchor point using the correspondingILcdGXYPainter
for the Object to be painted (aGXYContext.getGXYLayer().getGXYPainter( aObject )
).When the set
TLcdLabelLocation
can retrieve an anchor point, this anchor point should be returned.- Parameters:
aGraphics
- the Graphics for which the labels anchor point should be calculated.aMode
- the mode for the which the label anchor point should be calculated. Can be ILcdGXYLabelPainter.SELECTED or ILcdGXYLabelPainter.DEFAULT.aContext
- the context in which this label will be painted.aPointSFCT
- the point that will be moved to the anchor point computed.- Throws:
TLcdNoBoundsException
- if the Object doesn't have any valid anchor point, e.g. if it is always invisible in the current projection.
-
getPossibleLocationCount
Description copied from interface:ILcdGXYLabelPainter
Returns the number of possible locations where thisILcdGXYLabelPainter
can paint/draw the labels of the set domainObject
.The domain
Object
for which the location count is retrieved should be set before calling this method using theILcdGXYLabelPainter.setObject(java.lang.Object)
method.- Specified by:
getPossibleLocationCount
in interfaceILcdGXYLabelPainter
- Parameters:
aGraphics
- the Graphics the label will be painted on.- Returns:
- the number of possible locations where this
ILcdGXYLabelPainter
can paint/draw the labels of the set Object. - See Also:
-
labelBoundsSFCT
public double labelBoundsSFCT(Graphics aGraphics, int aMode, ILcdGXYContext aGXYContext, Rectangle aRectangleSFCT) throws TLcdNoBoundsException Calculates the bounds of the label that can be painted. The bounds are set as a side effect in
aRectangleSFCT
, the orientation ofaRectangleSFCT
is 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.
Please refer to
paintLabel
for documentation on which information is passed to the delegate painters.- Specified by:
labelBoundsSFCT
in interfaceILcdGXYLabelPainter
- Specified by:
labelBoundsSFCT
in interfaceILcdGXYLabelPainter2
- Parameters:
aGraphics
- theaGraphics
to consider.aMode
- the representation mode of the label.aGXYContext
- theILcdGXYContext
the drawing depends on.aRectangleSFCT
- theRectangle
containing 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:
-
isLabelTouched
Tests if the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
is touched at view location(specified by aGXYContext.getX()
andaGXYContext.getY()
), considering the mode and theILcdGXYContext
instance.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.
Please refer to
paintLabel
for documentation on which information is passed to the delegate painters.- Specified by:
isLabelTouched
in interfaceILcdGXYLabelPainter2
- Parameters:
aGraphics
- TheGraphics
instance 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
- theILcdGXYContext
to 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 Sets
aPointSFCT
to the anchor point of the label specified bysetObject
,setLabelIndex
andsetSubLabelIndex
.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 thelabel
and 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.
Please refer to
paintLabel
for documentation on which information is passed to the delegate painters.- Specified by:
labelAnchorPointSFCT
in interfaceILcdGXYLabelPainter2
- Parameters:
aGraphics
- TheGraphics
instance 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
- TheILcdGXYContext
that 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:
-
getLabelCursor
Description copied from class:ALcdGXYLabelPainter
Returns aCursor
to indicate the type of editingaMode
andaGXYContext
.This default implementation always returns
null
. Override this method if you want to display custom cursors.- Specified by:
getLabelCursor
in interfaceILcdGXYLabelPainter2
- Overrides:
getLabelCursor
in classALcdGXYLabelPainter
- Parameters:
aGraphics
- TheGraphics
instance on which the label is painted.aMode
- The mode to consider. SeeILcdGXYLabelPainter2.paintLabel(java.awt.Graphics, int, ILcdGXYContext)
for more information.aGXYContext
- TheILcdGXYContext
containing extra information, such as the layer, the view and the mouse position.- Returns:
- a
Cursor
to indicate the type of editingaMode
andaGXYContext
. Returnsnull
if no particularCursor
is required.
-
getLabelCount
Return the number of labels for the currently set object. The default implementation returns
1
. Override this method if you need to support multiple labels.This implementation always returns 1.
- Specified by:
getLabelCount
in interfaceILcdGXYLabelEditor
- Specified by:
getLabelCount
in interfaceILcdGXYMultiLabelPainter
- Overrides:
getLabelCount
in classALcdGXYLabelPainter
- Parameters:
aGraphics
- TheGraphics
instance 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) Returns 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.This implementation always returns 1.
- Specified by:
getSubLabelCount
in interfaceILcdGXYLabelEditor
- Specified by:
getSubLabelCount
in interfaceILcdGXYMultiLabelPainter
- Overrides:
getSubLabelCount
in 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:
-
getGXYLabelEditor
Description copied from interface:ILcdGXYLabelEditorProvider
Returns a valid
ILcdGXYLabelEditor
for editing the labels of aObject. The returnedILcdGXYLabelEditor
must haveaObject
set on it. The TLcdLabelLocation must not yet be set on it.- Specified by:
getGXYLabelEditor
in interfaceILcdGXYLabelEditorProvider
- Parameters:
aObject
- the Object for which to obtain aILcdGXYLabelEditor
.- Returns:
- a valid
ILcdGXYLabelEditor
for editing the labels ofaObject
withaObject
set on it. - See Also:
-
getGXYLabelPainter
Description copied from interface:ILcdGXYLabelPainterProvider
Finds anILcdGXYLabelPainter
that 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:
getGXYLabelPainter
in 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:ILcdGXYLabelEditor
Adapts the set
TLcdLabelLocation
according to the information present in aGXYContext. If the method returnstrue
, theTLcdLabelLocation
was modified, iffalse
is 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 ifaMode
is one of the creating modes, the (sub) label indices are irrelevant.- Specified by:
editLabel
in interfaceILcdGXYLabelEditor
- Parameters:
aGraphics
- TheGraphics
on 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()Returns the number of points required to initialize the label of the setObject
.This implementation always returns
0
.- Specified by:
getLabelCreationClickCount
in interfaceILcdGXYLabelEditor
- Returns:
- the number of points required to initialize the label of the set
Object
or -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:ILcdGXYLabelEditor
Returns whether the label specified by
setObject
,setLabelIndex
andsetSubLabelIndex
accepts the snap target in the givenILcdGXYContext
.The snap target is the
Object
returned byaGXYContext.getSnapTarget()
, and is on theILcdGXYLayer
returned byaGXYContext.getSnapTargetLayer()
.- Specified by:
acceptSnapTargetForLabel
in interfaceILcdGXYLabelEditor
- Parameters:
aGraphics
- TheGraphics
on which the label is painted.aGXYContext
- TheILcdGXYContext
containing the snapping information.- Returns:
true
if the label accepts the snap target,false
otherwise.- See Also:
-
clone
Description copied from class:ALcdGXYLabelPainter
Returns 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:
clone
in interfaceILcdGXYLabelEditor
- Specified by:
clone
in interfaceILcdGXYLabelEditorProvider
- Specified by:
clone
in interfaceILcdGXYLabelPainter
- Specified by:
clone
in interfaceILcdGXYLabelPainter2
- Specified by:
clone
in interfaceILcdGXYLabelPainterProvider
- Overrides:
clone
in classALcdGXYLabelPainter
- Returns:
- A new instance of this
ALcdGXYLabelPainter
of which the label location is a deep clone.
-
setPositionList
public void setPositionList(int[] aPositionList) Sets a new position list. This list is only used when the labels are not placed freely.
- Parameters:
aPositionList
- the list of possible positions to place the labels.- See Also:
-
getPositionList
public int[] getPositionList()Returns the list of possible positions to place the labels.- Returns:
- the list of possible positions to place the labels.
- See Also:
-
setShiftLabelPosition
public void setShiftLabelPosition(int aShift) Sets how many pixels the label must be removed from the anchor point of the domain object when labels are not placed freely (i.e.
getLabelLocation().getLocationIndex() != -1
). If the position of the label iseast
orwest
, this shift is applied in horizontal direction; if the position isnorth
orsouth
, this shift is applied in vertical direction. In case ofnorth east
,south east
,south west
ornorth west
, this shift is applied in both directions. If the location of the label iscenter
, the shift is ignored.The default for this value is
20
pixels.- Parameters:
aShift
- the distance, expressed in pixels, that the label must be removed from the domain object.- See Also:
-
getShiftLabelPosition
public int getShiftLabelPosition()Returns how many pixels the label must be removed from the anchor point of the domain object when labels are not placed freely (i.e.getLabelLocation().getLocationIndex() != -1
).- Returns:
- the distance, expressed in pixels, that the label must be removed from the domain object.
- See Also:
-
setClassTraceOn
public static void setClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for all instances of this class. If the argument istrue
then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.- Parameters:
aClassTraceOn
- if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
-