public class EdgeSegmentLabelModel extends Object implements ILabelModel, ILabelModelParameterProvider, ILabelModelParameterFinder
sides of the edge path
.
The set of positions can be influenced by specifying the SideOfEdge
value that controls on
which side of the edge labels positions should be considered. Furthermore, it's possible to specify distance values that
control the distance between label and edge and between label and nodes.
If a label model parameter is created EdgeSides.ON_EDGE
, the label's center is usually placed on the edge. It
can be shifted by specifying a Offset
value but the Distance
value is
ignored. For all other values of EdgeSides
the total distance between the label bounds and the edge path is the
sum of Offset
and Distance
.
The label placements use a specified segment index from the source
or target
side and a ratio on this segment. This is the main
difference to the EdgePathLabelModel
which only uses a ratio value of the full edge path.
Constructor and Description |
---|
EdgeSegmentLabelModel()
Returns a new instance of
EdgeSegmentLabelModel . |
EdgeSegmentLabelModel(double distance,
double offset,
double angle,
boolean autoRotationEnabled,
EdgeSides sideOfEdge)
Initializes a new instance of the
EdgeSegmentLabelModel class. |
Modifier and Type | Method and Description |
---|---|
ILabelModelParameter |
createDefaultParameter()
A model parameter that encodes the default position of this model's allowed edge label positions.
|
ILabelModelParameter |
createParameterFromCenter(double segmentRatio,
EdgeSides sideOfEdge)
Creates a parameter where the label is attached to the edge segment that contains the edge's midpoint.
|
ILabelModelParameter |
createParameterFromSource(int segmentIndex,
double segmentRatio,
EdgeSides sideOfEdge)
Creates a parameter that measures the provided segment index from the source side of the edge path.
|
ILabelModelParameter |
createParameterFromTarget(int segmentIndex,
double segmentRatio,
EdgeSides sideOfEdge)
Creates a parameter that measures the provided segment index from the target side of the edge path.
|
ILabelModelParameter |
findBestParameter(ILabel label,
ILabelModel model,
IOrientedRectangle layout)
Tries to find a parameter that best matches the given layout for the provided label instance.
|
double |
getAngle()
Gets the rotation angle of all labels with this model in radians.
|
ILookup |
getContext(ILabel label,
ILabelModelParameter layoutParameter)
Returns an empty context.
|
double |
getDistance()
Gets the distance between the label box and the edge path.
|
IOrientedRectangle |
getGeometry(ILabel label,
ILabelModelParameter layoutParameter)
Calculates the
geometry of the given label using the given model parameter. |
double |
getOffset()
Gets the offset of the label box and the edge path relative to the default placement.
|
IEnumerable<ILabelModelParameter> |
getParameters(ILabel label,
ILabelModel model)
Returns an enumerator over a set of possible
ILabelModelParameter instances that can be used for the given label
and model. |
EdgeSides |
getSideOfEdge()
Gets the side placement specifiers for edge labels.
|
boolean |
isAutoRotationEnabled()
Gets whether edge labels are automatically rotated according to the angle of the corresponding reference edge segment.
|
<TLookup> TLookup |
lookup(Class<TLookup> type)
Returns an instance that implements the given type or
null . |
void |
setAngle(double value)
Sets the rotation angle of all labels with this model in radians.
|
void |
setAutoRotationEnabled(boolean value)
Sets whether edge labels are automatically rotated according to the angle of the corresponding reference edge segment.
|
void |
setDistance(double value)
Sets the distance between the label box and the edge path.
|
void |
setOffset(double value)
Sets the offset of the label box and the edge path relative to the default placement.
|
void |
setSideOfEdge(EdgeSides value)
Sets the side placement specifiers for edge labels.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
public EdgeSegmentLabelModel()
EdgeSegmentLabelModel
.public EdgeSegmentLabelModel(double distance, double offset, double angle, boolean autoRotationEnabled, EdgeSides sideOfEdge)
EdgeSegmentLabelModel
class.distance
- the distance to the edge.offset
- the offset to the default placement.angle
- the angle of the label's rotation in radians.autoRotationEnabled
- if set to true
auto rotation is enabled.sideOfEdge
- the side of the edge labels.public final ILabelModelParameter createDefaultParameter()
Returns a model parameter that encodes the default position of this model's allowed edge label positions.
createDefaultParameter
in interface ILabelModel
public final ILabelModelParameter createParameterFromCenter(double segmentRatio, EdgeSides sideOfEdge)
segmentRatio
- The ratio at which to place the label at the segment. A ratio of 0.0 will place the label at the source side of the
segment, a ratio of 1.0 at the target side. Ratios < 0.0 or > 1.0 will be interpreted as absolute values in world
coordinates.sideOfEdge
- The side of the edge the label is placed on. Note that only single enum values but no combined ones are allowed.public final ILabelModelParameter createParameterFromSource(int segmentIndex, double segmentRatio, EdgeSides sideOfEdge)
segmentIndex
- The zero-based index of the segment beginning from the source side.segmentRatio
- The ratio at which to place the label at the segment. A ratio of 0.0 will place the label at the source side of the
segment, a ratio of 1.0 at the target side. Ratios < 0.0 or > 1.0 will be interpreted as absolute values in world
coordinates.sideOfEdge
- The side of the edge the label is placed on. Note that only single enum values but no combined ones are allowed.public final ILabelModelParameter createParameterFromTarget(int segmentIndex, double segmentRatio, EdgeSides sideOfEdge)
segmentIndex
- The zero-based index of the segment beginning from the target side.segmentRatio
- The ratio at which to place the label at the segment. A ratio of 0.0 will place the label at the target side of the
segment, a ratio of 1.0 at the source side. Ratios < 0.0 or > 1.0 will be interpreted as absolute values in world
coordinates.sideOfEdge
- The side of the edge the label is placed on. Note that only single enum values but no combined ones are allowed.public final ILabelModelParameter findBestParameter(ILabel label, ILabelModel model, IOrientedRectangle layout)
ILabelModelParameterFinder
This method may not necessarily find a parameter that matches the provided layout exactly. Implementations may choose to
simply return the model's default parameter
but may never return
null
.
findBestParameter
in interface ILabelModelParameterFinder
label
- The label to find a parameter for.model
- The model instance to use. This should be the instance this instance has been obtained from.layout
- The anticipated layout for the label.null
parameter that can be used for the label to approximate the provided layout.public final double getAngle()
setAngle(double)
public final ILookup getContext(ILabel label, ILabelModelParameter layoutParameter)
getContext
in interface ILabelModel
label
- The label to use in the context.layoutParameter
- The parameter to use for the label in the context.ILookup.EMPTY
public final double getDistance()
The interpretation of the values depends on the SideOfEdge
of the individual
ILabelModelParameter
.
Note that for EdgeSides.ON_EDGE
this property is ignored. For all other values of EdgeSides
the Offset
property is added to this distance.
getSideOfEdge()
,
EdgeSides
,
getOffset()
,
setDistance(double)
public final IOrientedRectangle getGeometry(ILabel label, ILabelModelParameter layoutParameter)
ILabelModel
geometry
of the given label using the given model parameter.getGeometry
in interface ILabelModel
label
- The label to calculate the geometry for.layoutParameter
- A parameter that is compatible with this model. Typically, this is a parameter that has been created by this model, and
its property Model
returns this instance.IOrientedRectangle
that describes the geometry of the label. This is typically designed as a flyweight,
therefore clients should not cache the instance but store the values if they need a snapshot for later use.public final double getOffset()
For EdgeSides.ON_EDGE
this is the offset between the center of the label box and the edge path. For all other EdgeSides
values this offset is added to the Distance
property which results in the total distance between
the label box and the edge path.
getSideOfEdge()
,
EdgeSides
,
setOffset(double)
public final IEnumerable<ILabelModelParameter> getParameters(ILabel label, ILabelModel model)
ILabelModelParameterProvider
ILabelModelParameter
instances that can be used for the given label
and model.getParameters
in interface ILabelModelParameterProvider
label
- The label instance to use.model
- The model to provide parameters for.public final EdgeSides getSideOfEdge()
The label model parameter finder
and provider
returned by lookup(Class)
consider the specified sides.
EdgeSides
,
setSideOfEdge(EdgeSides)
public final boolean isAutoRotationEnabled()
By default, this feature is enabled.
true
if edge labels are automatically rotated; false
otherwise.setAutoRotationEnabled(boolean)
public final <TLookup> TLookup lookup(Class<TLookup> type)
ILookup
null
.
Typically, this method will be called in order to obtain a different view or
aspect of the current instance. This is quite similar to casting or using
a super type or interface of this instance, but is not limited to inheritance or
compile time constraints. An instance implementing this method is not
required to return non-null
implementations for the types, nor does it
have to return the same instance any time. Also it depends on the
type and context whether the instance returned stays up to date or needs to
be reobtained for subsequent use.public final void setAngle(double value)
value
- The rotation angle of all labels with this model in radians.getAngle()
public final void setAutoRotationEnabled(boolean value)
By default, this feature is enabled.
value
- true
if edge labels are automatically rotated; false
otherwise.isAutoRotationEnabled()
public final void setDistance(double value)
The interpretation of the values depends on the SideOfEdge
of the individual
ILabelModelParameter
.
Note that for EdgeSides.ON_EDGE
this property is ignored. For all other values of EdgeSides
the Offset
property is added to this distance.
value
- The distance between the label box and the edge path.getSideOfEdge()
,
EdgeSides
,
getOffset()
,
getDistance()
public final void setOffset(double value)
For EdgeSides.ON_EDGE
this is the offset between the center of the label box and the edge path. For all other EdgeSides
values this offset is added to the Distance
property which results in the total distance between
the label box and the edge path.
value
- The offset of the label box and the edge path relative to the default placement.getSideOfEdge()
,
EdgeSides
,
getOffset()
public final void setSideOfEdge(EdgeSides value)
The label model parameter finder
and provider
returned by lookup(Class)
consider the specified sides.
value
- The SideOfEdge to set.EdgeSides
,
getSideOfEdge()