public class TLcdLabelLocation extends Object implements Cloneable
Instances of this class contain the location information about a specific label. It is used as
the data transfer object between ALcdLabelLocations
and the various parties that
need to know the location of a label.
This class can be sub-classed if you want to add extra properties about the
location of a label. When doing so, also overwrite the
copyFrom(com.luciad.view.TLcdLabelLocation)
method to make sure your extra properties are copied. By overwriting
ALcdLabelLocations.createLabelLocation()
to return instances of your subclass,
all classes will use the extension to exchange the label location information.
When using free placement (getLocationIndex()
== -1
), the label location
represents a label using a location and a rotation. This location is the
label anchor point
of
the label. The label is then rotated around this label anchor point, see illustration :
ALcdLabelLocations
,
ILcdGXYEditableLabelsLayer
,
ILcdGXYLabelPainter2
,
ILcdGXYLabelEditor
Modifier and Type | Field and Description |
---|---|
static int |
ABSOLUTE_POSITION
When the
label edit mode contains this flag, getLocationX()
and getLocationY() return absolute values, otherwise they return values relative to
the anchor point of the domain object that is labeled (determined by
ILcdGXYPainter.anchorPointSFCT(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext, java.awt.Point) ), or the anchor point returned by
getAnchorPoint(java.awt.Point) . |
static int |
EDITED_BY_LABEL_EDITOR
When the
label edit mode contains this flag, the label position was
edited by for example a ILcdGXYLabelEditor . |
static int |
EDITED_BY_LAYER_OR_VIEW_LABEL_PAINTER
When the
label edit mode contains this flag, the label position was
edited by for example a ILcdGXYLayerLabelPainter or a
ILcdGXYViewLabelPainter . |
static int |
STICKY_LABEL_LOCATION
This flag indicates that the label position is sticky.
|
static int |
TEMPORARY_STICKY_LABEL_LOCATION
This flag indicates that the label position is temporarily sticky, for instance to
facilitate the selection of a label.
|
Constructor and Description |
---|
TLcdLabelLocation()
Creates a new
TLcdLabelLocation . |
TLcdLabelLocation(int aLocationX,
int aLocationY,
double aRotation,
int aLocationIndex)
Creates a new
TLcdLabelLocation with the given initial values. |
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Redefines the clone method to be public.
|
void |
copyFrom(TLcdLabelLocation aSourceLabelLocation)
Copies the properties of
aSourceLabelLocation into this object. |
boolean |
getAnchorPoint(Point aAnchorPointSFCT)
This method computes an anchor point for this label.
|
int |
getLabelEditMode()
Returns the label edit mode.
|
int |
getLocationIndex()
This property determines the location index of the label, as specified in
ILcdGXYLabelPainter.setLocationIndex(int) . |
float |
getLocationX()
Returns the horizontal location information of the label, specified in view coordinates
(pixels).
|
float |
getLocationY()
Returns the vertical location information of the label, specified in view coordinates
(pixels).
|
Rectangle |
getParentBoundsRectangle()
Returns the rectangle of the parent bounds.
|
double |
getParentBoundsRotation()
Returns the rotation of the parent bounds.
|
TLcdLabelIdentifier |
getParentLabel()
Retrieve a label identifier that references the label on which this label depends.
|
double |
getRotation()
Returns the rotation of the label around its label anchor point.
|
boolean |
isBodyLabel()
This flag indicates that this label is used as the representation for its domain object.
|
boolean |
isInteractiveLabel()
This field is used to indicate that a label is interactive.
|
boolean |
isSticky()
Returns whether or not one of the sticky flags was set.
|
void |
setBodyLabel(boolean aBodyLabel)
Sets if this label will be used as the representation for its domain object.
|
void |
setInteractiveLabel(boolean aInteractiveLabel)
Set to
true to indicate that this label is interactive. |
void |
setLabelEditMode(int aLabelEditMode)
Sets the label edit mode.
|
void |
setLocationIndex(int aLocationIndex)
Sets the location index.
|
void |
setLocationX(float aLocationX)
Sets the horizontal location information.
|
void |
setLocationY(float aLocationY)
Sets the vertical location information
|
void |
setParentBounds(Rectangle aParentBoundsRectangle,
double aParentBoundsRotation)
Sets the bounds of the parent label (see
getParentLabel() . |
void |
setParentLabel(TLcdLabelIdentifier aParentLabel)
Sets the parent label.
|
void |
setRotation(double aRotation)
Sets the rotation of the label around its label anchor point.
|
String |
toString() |
public static final int EDITED_BY_LABEL_EDITOR
label edit mode
contains this flag, the label position was
edited by for example a ILcdGXYLabelEditor
.public static final int EDITED_BY_LAYER_OR_VIEW_LABEL_PAINTER
label edit mode
contains this flag, the label position was
edited by for example a ILcdGXYLayerLabelPainter
or a
ILcdGXYViewLabelPainter
.public static final int STICKY_LABEL_LOCATION
This flag indicates that the label position is sticky. It indicates a more permanent
stickiness than TEMPORARY_STICKY_LABEL_LOCATION
. For instance, when the label editor
has moved a label, it could have indicated that the label should remain sticky afterward.
When the label edit mode
contains this flag, the label position
should not be altered by for example a ILcdGXYLayerLabelPainter
or
ILcdGXYViewLabelPainter
.
A ILcdGXYLabelEditor
however may still change the location
public static final int TEMPORARY_STICKY_LABEL_LOCATION
This flag indicates that the label position is temporarily sticky, for instance to facilitate the selection of a label.
When the label edit mode
contains this flag, the label position
should not be altered by for example a ILcdGXYLayerLabelPainter
or
ILcdGXYViewLabelPainter
.
A ILcdGXYLabelEditor
however may still change the location
STICKY_LABEL_LOCATION
,
Constant Field Valuespublic static final int ABSOLUTE_POSITION
label edit mode
contains this flag, getLocationX()
and getLocationY()
return absolute values, otherwise they return values relative to
the anchor point of the domain object that is labeled (determined by
ILcdGXYPainter.anchorPointSFCT(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext, java.awt.Point)
), or the anchor point returned by
getAnchorPoint(java.awt.Point)
.public TLcdLabelLocation()
TLcdLabelLocation
.public TLcdLabelLocation(int aLocationX, int aLocationY, double aRotation, int aLocationIndex)
TLcdLabelLocation
with the given initial values.aLocationX
- the X-location, see setLocationX(float)
.aLocationY
- the Y-location, see setLocationY(float)
.aRotation
- the rotation, see setRotation(double)
.aLocationIndex
- the location index, see setLocationIndex(int)
.public void copyFrom(TLcdLabelLocation aSourceLabelLocation)
aSourceLabelLocation
into this object. No reference to
aSourceLabelLocation
is kept when this method returns.
In other words, this method creates a clone in an already existing instance, hence
avoiding the overhead of creating a new instance.aSourceLabelLocation
- The TLcdLabelLocation
whose properties you wish to
copy.clone()
public int getLocationIndex()
This property determines the location index of the label, as specified in ILcdGXYLabelPainter.setLocationIndex(int)
. Unlike that specification however,
this location index can be less than 0, to indicate free label placement.
-1
to indicate free label placement.public void setLocationIndex(int aLocationIndex)
aLocationIndex
- An integer larger than or equal to 0 to indicate a predefined label
location, -1
to indicate free label placement.getLocationIndex()
public float getLocationX()
Returns the horizontal location information of the label, specified in view coordinates (pixels). This location represents the position of the label anchor point of the label. Although specified as a float, users of this method can simply cast the value to an integer.
If the label edit mode
indicates that this information is
relative, this property determines the horizontal offset relative the anchor point of the
labeled object or the anchor point retrieved using getAnchorPoint(java.awt.Point)
.
If the label edit mode indicates this information is absolute, this property defines the
absolute horizontal position in the view.
This value is only relevant if the location index indicates that the label is freely placed,
ie. the location index is smaller than 0
.
public void setLocationX(float aLocationX)
aLocationX
- The horizontal position.getLocationX()
public float getLocationY()
Returns the vertical location information of the label, specified in view coordinates (pixels). This location represents the position of the label anchor point of the label. Although specified as a float, users of this method can simply cast the value to an integer.
If the label edit mode
indicates that this information is
relative, this property determines the vertical offset relative the anchor point of the
labeled object or the anchor point retrieved using getAnchorPoint(java.awt.Point)
.
If the label edit mode indicates this information is absolute, this property defines the
absolute vertical position in the view.
This value is only relevant if the location index indicates that the label is freely placed,
ie. the location index is smaller than 0
.
public void setLocationY(float aLocationY)
aLocationY
- The vertical position.getLocationY()
public double getRotation()
Returns the rotation of the label around its label anchor point. This rotation is given in radians, clockwise and with 0 radians at 3 o'clock.
This value is only relevant if the location index indicates that the label is freely placed,
ie. the location index is smaller than 0
.
setRotation(double)
public void setRotation(double aRotation)
Sets the rotation of the label around its label anchor point. This rotation is given in radians, clockwise and with 0 radians at 3 o'clock. Since the y-axis points down in AWT, it means that rotating with a positive angle rotates points on the positive x axis toward the positive y axis, which is clockwise visually.
This value is only relevant if the location index indicates that the label is freely placed,
ie. the location index is smaller than 0
.
aRotation
- The rotation of the label.getRotation()
public int getLabelEditMode()
Returns the label edit mode. This mode is a bitwise combination of the static constants in this class.
For example, to check if this TLcdLabelLocation
contains absolute information,
you should check if the ABSOLUTE_POSITION flag is set in the label edit mode:
boolean absolute = ( ABSOLUTE_POSITION & getLabelEditMode() ) != 0;
ABSOLUTE_POSITION
,
STICKY_LABEL_LOCATION
,
TEMPORARY_STICKY_LABEL_LOCATION
,
EDITED_BY_LABEL_EDITOR
,
EDITED_BY_LAYER_OR_VIEW_LABEL_PAINTER
public void setLabelEditMode(int aLabelEditMode)
aLabelEditMode
- A bitwise or of the constants in this classgetLabelEditMode()
public TLcdLabelIdentifier getParentLabel()
null
, it doesn't depend on an other label.
Before storing this label location in an ALcdLabelLocations
, one should make sure
that the bounds of the parent label are set (see setParentBounds(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.
By default the returned label identifier is null
.
setParentLabel(TLcdLabelIdentifier)
,
setParentBounds(java.awt.Rectangle, double)
public void setParentLabel(TLcdLabelIdentifier aParentLabel)
aParentLabel
- a TLcdLabelIdentifier
referencing the parent label.getParentLabel()
public Rectangle getParentBoundsRectangle()
If the label edit mode
indicates that this information is
relative, the bounds are relative to the anchor point of the labeled object. If the
label edit mode indicates this information is absolute, the bounds are absolute in
the view.
setParentBounds(java.awt.Rectangle, double)
public double getParentBoundsRotation()
setParentBounds(java.awt.Rectangle, double)
public boolean getAnchorPoint(Point aAnchorPointSFCT)
getParentBoundsRectangle()
and
getParentBoundsRotation()
).
Code that alters a TLcdLabelLocation
should always make sure that this method
returns a correct anchor point. This can be done by setting the parent bounds to a correct
value, see setParentBounds(java.awt.Rectangle, double)
.
If the label edit mode
indicates that this information is
relative, the retrieved anchor point is relative to the anchor point of the labeled
object. If the label edit mode indicates this information is absolute, anchor point
is absolute in the view.
If this label has no parent label, this method returns false
and the user of
this object should compute an anchor point.
aAnchorPointSFCT
- the point in which the anchor point will be stored.true
if an anchor point could be calculated, and false
otherwise.setParentBounds(java.awt.Rectangle, double)
public void setParentBounds(Rectangle aParentBoundsRectangle, double aParentBoundsRotation)
getParentLabel()
. These bounds should be set
before storing this label location in an ALcdLabelLocations
instance. Examples of
code that should do this are the label placer (see ILcdGXYViewLabelPlacer
),
the label editor, or other code that manually adjusts offset labels. Not setting these bounds
to the correct value for a TLcdLabelLocation
causes getAnchorPoint(java.awt.Point)
to return an incorrect anchor point for this label location.
If the label edit mode
indicates that this information is
relative, the bounds should be relative to the anchor point of the labeled object.
If the label edit mode indicates this information is absolute, the parent bounds
are absolute in the view.
aParentBoundsRectangle
- the rectangle of the parent bounds.aParentBoundsRotation
- the rotation of the parent bounds.public boolean isBodyLabel()
true
if this label is used a the representation for its domain object, and
false
otherwise.setBodyLabel(boolean)
public void setBodyLabel(boolean aBodyLabel)
aBodyLabel
- true
if this label will be used as the representation for
its domain object and false
otherwise.isBodyLabel()
public boolean isInteractiveLabel()
setInteractiveLabel(boolean)
,
TLcdGXYInteractiveLabelsController
public void setInteractiveLabel(boolean aInteractiveLabel)
true
to indicate that this label is interactive. Label painters should
respect this field by not painting interactive labels. This value is false
by default.aInteractiveLabel
- true
for interactive labels, or false
otherwise.isInteractiveLabel()
,
TLcdGXYInteractiveLabelsController
public boolean isSticky()
Returns whether or not one of the sticky flags was set. This method can be overridden to take extra parameters into consideration.
true
if the label edit mode contained STICKY_LABEL_LOCATION
or
TEMPORARY_STICKY_LABEL_LOCATION
, false
otherwise.public Object clone() throws CloneNotSupportedException
clone
in class Object
TLcdLabelLocation
instance.CloneNotSupportedException