public class TLspFixedOnPathLabelLocationProvider extends ALspLabelLocationProvider
This label location provider positions points on a specific location on a line. This algorithm works for all shapes
that implement ILcdCurve
. To retrieve this curve, the anchor object of a label is used.
When the anchor object of the label is a composite shape, like an ILcdShapeList
or
ILcdComplexPolygon
, this label location provider first tries to find the largest sub-shape
and then finds a location for this sub-shape.
This label location provider only calculates a single label location. So if this label overlaps with an other
label, no alternative locations are available. If this functionality is needed, it can be done by creating a
composite TLspFixedOnPathLabelLocationProvider
.
Unlike TLspOnPathLabelingAlgorithm
, this label location provider doesn't try to keep the label inside the
view. When navigating away from the label location, no label location within the view bounds is
calculated. Because of this, this labeling location provider works more efficiently CPU-wise. On top of
that, this label location provider works by specifying a specific location on the line.
The used label painter must be an ILspStampLocationLabelPainter
.
If not, the label will not be placed. The placed label location will be a
ALspStampLabelLocation
.
To use this label location provider to create a labeling algorithm, the following code can be used:
TLspFixedOnPathLabelLocationProvider provider = new TLspFixedOnPathLabelLocationProvider();
TLspLabelingAlgorithm algorithm = new TLspLabelingAlgorithm(provider);
Modifier and Type | Class and Description |
---|---|
static class |
TLspFixedOnPathLabelLocationProvider.HorizontalAlignment
Represents the horizontal alignment, i.e. the offset of the label parallel to the path, relative to
the chosen point on the path.
|
static class |
TLspFixedOnPathLabelLocationProvider.VerticalAlignment
Represents the vertical alignment, i.e. the offset of the label perpendicular to the line.
|
Constructor and Description |
---|
TLspFixedOnPathLabelLocationProvider(double aRelativeLocation,
TLspFixedOnPathLabelLocationProvider.VerticalAlignment aVerticalAlignment,
TLspFixedOnPathLabelLocationProvider.HorizontalAlignment aHorizontalAlignment,
double aVerticalOffset,
double aHorizontalOffset)
Creates a new
TLspFixedOnPathLabelLocationProvider . |
Modifier and Type | Method and Description |
---|---|
TLspLabelPlacement |
getLocation(TLspLabelID aLabel,
int aLocationIndex,
ALspLabelLocations aCurrentLabelLocations,
TLspPaintState aPaintState,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspView aView)
This method returns a location for the given label using the given location index.
|
int |
getMaxLocationCount(TLspLabelID aLabel,
TLspPaintState aPaintState,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspView aView)
Returns the maximal number of locations to be tried for the given label.
|
boolean |
isAllowUpsideDown()
Returns if it is allowed for this location provider to place labels upside down.
|
boolean |
isValidLocation(TLspLabelPlacement aLocation,
ALspLabelLocations aCurrentLabelLocations,
TLspPaintState aPaintState,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspView aView)
Checks if the given location is a valid location.
|
void |
setAllowUpsideDown(boolean aAllowUpsideDown)
Sets if it is allowed for this location provider to place labels upside down.
|
String |
toString() |
public TLspFixedOnPathLabelLocationProvider(double aRelativeLocation, TLspFixedOnPathLabelLocationProvider.VerticalAlignment aVerticalAlignment, TLspFixedOnPathLabelLocationProvider.HorizontalAlignment aHorizontalAlignment, double aVerticalOffset, double aHorizontalOffset)
TLspFixedOnPathLabelLocationProvider
.aRelativeLocation
- the location of the label, relative on the line. Values should lie in the interval [0, 1].
If not, an IllegalArgumentException
is thrown.aVerticalAlignment
- the alignment of the label perpendicular to the lineaHorizontalAlignment
- the alignment of the label with respect to the location on the line (parallel to the line):aVerticalOffset
- vertical space between the location on the line and the label in pixelsaHorizontalOffset
- horizontal space between the location and the label in pixelspublic boolean isAllowUpsideDown()
setAllowUpsideDown(boolean)
public void setAllowUpsideDown(boolean aAllowUpsideDown)
true
, there is no restriction on the rotation of the labels.
If set to false
, labels that are rotated upside down are rotated
180 degrees around their center. In this context, upside down means that the rotation of the
label lies between 90 and 270 degrees, assuming that 0 degrees lies at 3 'o clock.
The default value is false
.
aAllowUpsideDown
- true
to allow labels being painted upside
done, and false
otherwise.isAllowUpsideDown()
public int getMaxLocationCount(TLspLabelID aLabel, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView)
ALspLabelLocationProvider
getLocation
method can create the same number of
locations as returned by this method. By default, this method returns 1
.getMaxLocationCount
in class ALspLabelLocationProvider
aLabel
- the label.aPaintState
- the paint state.aLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.public boolean isValidLocation(TLspLabelPlacement aLocation, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView)
ALspLabelLocationProvider
true
.isValidLocation
in class ALspLabelLocationProvider
aLocation
- the location to check.aCurrentLabelLocations
- an ALspLabelLocations object containing locations for the
currently placed labels.aPaintState
- the paint state.aLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.public TLspLabelPlacement getLocation(TLspLabelID aLabel, int aLocationIndex, ALspLabelLocations aCurrentLabelLocations, TLspPaintState aPaintState, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspView aView)
ALspLabelLocationProvider
getLocation
in class ALspLabelLocationProvider
aLabel
- a label.aLocationIndex
- the location index.aCurrentLabelLocations
- an ALspLabelLocations object containing locations for the
currently placed labels.aPaintState
- the paint stateaLabelContext
- provides context information, such as priorities, PaintState, ...aView
- the view.null
if no location
could be calculated.