public class SmartEdgeLabelModel extends Object implements ILabelModel, ILabelModelParameterFinder
Similar to
EdgeSegmentLabelModel
, a position is specified by an edge segment and a ratio on that segment, amongst
others. During changes of the edge path, the label keeps its relative location with respect to the bends of the
reference segment in a similar way.
In contrast to EdgeSegmentLabelModel
, the distance from the edge path is not a property of the model but of the
particular parameter. In addition, this class does not implement ILabelModelParameterProvider
and therefore,
labels with this model can be moved freely and are not restricted to a fixed set of candidates at a given distance from
the edge.
If AutoRotationEnabled
is enabled, labels are automatically rotated according to the
angle of the corresponding reference edge segment.
During movements, labels with this model snap to noteable positions if the MoveLabelInputMode
provides a LabelSnapContext
that is enabled and has a suitable configuration.
Constructor and Description |
---|
SmartEdgeLabelModel()
Initializes a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
ILabelModelParameter |
createDefaultParameter()
Creates a default parameter that can be used for this model.
|
ILabelModelParameter |
createParameterFromSource(int segmentIndex,
double distance,
double segmentRatio)
Creates a parameter that measures the provided segment index from the source side of the edge path.
|
ILabelModelParameter |
createParameterFromTarget(int segmentIndex,
double distance,
double segmentRatio)
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.
|
ILookup |
getContext(ILabel label,
ILabelModelParameter layoutParameter)
Provides a
lookup context for the given combination of label and parameter. |
double |
getDistance(ILabelModelParameter layoutParameter)
Gets the distance from the edge path described by the specified parameter.
|
IOrientedRectangle |
getGeometry(ILabel label,
ILabelModelParameter layoutParameter)
Calculates the
geometry of the given label using the given model parameter. |
boolean |
isAutoRotationEnabled()
Gets whether or not 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.
|
void |
setAutoRotationEnabled(boolean value)
Sets whether or not edge labels are automatically rotated according to the angle of the corresponding reference edge
segment.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
public SmartEdgeLabelModel()
public final ILabelModelParameter createDefaultParameter()
ILabelModel
createDefaultParameter
in interface ILabelModel
public final ILabelModelParameter createParameterFromSource(int segmentIndex, double distance, double segmentRatio)
segmentIndex
- The zero-based index of the segment beginning from the source side.distance
- The distance between the label's box and the edge's path.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 lesser than 0.0
or greater than 1.0
will
be interpreted as absolute values in world coordinates.public final ILabelModelParameter createParameterFromTarget(int segmentIndex, double distance, double segmentRatio)
segmentIndex
- The zero-based index of the segment beginning from the target side.distance
- The distance between the label's box and the edge's path.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 lesser than 0.0
or greater than 1.0
will
be interpreted as absolute values in world coordinates.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 double getAngle()
setAngle(double)
public final ILookup getContext(ILabel label, ILabelModelParameter layoutParameter)
ILabelModel
lookup context
for the given combination of label and parameter.getContext
in interface ILabelModel
label
- The label to use in the context.layoutParameter
- The parameter to use for the label in the context.ILookup
interface that can be used to query additional aspects of the label/parameter
combination.ILookup.EMPTY
public final double getDistance(ILabelModelParameter layoutParameter)
layoutParameter
- The parameter to get the edge path distance for.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 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 void setAngle(double value)
value
- The rotation angle of all labels with this model.getAngle()
public void setAutoRotationEnabled(boolean value)
By default, this feature is enabled.
value
- true
if edge labels are automatically rotated; false
otherwise.isAutoRotationEnabled()