public class FreeNodeLabelModel extends Object implements ILabelModel, ILabelModelParameterFinder
The position of the label is stored relative to the layout of the node the label belongs to.
Modifier and Type | Field and Description |
---|---|
static FreeNodeLabelModel |
INSTANCE
A shared public instance that can be used to obtain parameters.
|
Constructor and Description |
---|
FreeNodeLabelModel() |
Modifier and Type | Method and Description |
---|---|
ILabelModelParameter |
createCanonicalParameter(RectD nodeLayout,
IOrientedRectangle labelLayout)
Creates a parameter instance that anchors the label to the node at the canonical position with respect to the given
reference point.
|
ILabelModelParameter |
createCanonicalParameter(RectD nodeLayout,
IOrientedRectangle labelLayout,
PointD referenceLocation)
Creates a parameter instance that anchors the label to the node at the canonical position with respect to the given
reference point.
|
ILabelModelParameter |
createDefaultParameter()
Creates a parameter that is anchored at the node center and has no rotation.
|
ILabelModelParameter |
createParameter(PointD layoutRatio,
PointD layoutOffset,
PointD labelRatio,
PointD labelOffset,
double angle)
Creates a parameter instance that anchors the label to the node at a given position.
|
ILabelModelParameter |
findBestParameter(ILabel label,
ILabelModel model,
IOrientedRectangle layout)
Tries to find a parameter that best matches the given layout for the provided label instance.
|
ILookup |
getContext(ILabel label,
ILabelModelParameter layoutParameter)
Returns an empty context.
|
IOrientedRectangle |
getGeometry(ILabel label,
ILabelModelParameter layoutParameter)
Calculates the
geometry of the given label using the given model parameter. |
<TLookup> TLookup |
lookup(Class<TLookup> type)
Returns this instance if an instance of
ILabelModelParameterFinder is requested and null otherwise. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createDictionaryLookup, createDynamic, createSingle, createSingle, createWrapped, lookup, lookup, safeLookup
public static final FreeNodeLabelModel INSTANCE
public final ILabelModelParameter createCanonicalParameter(RectD nodeLayout, IOrientedRectangle labelLayout)
This method creates a parameter
with the canonical
settings for the ratios and offsets in the following way. Each coordinate axis is considered independently. If the
reference point coordinate is within the node layout interval, its relative location specifies the layout ratio for this
coordinate. Otherwise, the absolute distance of the reference point and the interval specifies the layout offset and the
layout ratio is either either 0.0
or
1.0
. The parameters for the label ratio and label offset are calculated analogously. If no reference point
is provided, the reference point is determined automatically in the following way: For each coordinate, if the node
layout and label layout do not overlap, the reference is the label corner that is closest to the node. If they overlap
and if in addition the start or end coordinate of the label matches the start, center or end coordinate of the node,
that coordinate is the reference. Otherwise, the center of the label specifies the reference.
nodeLayout
- The node layout.labelLayout
- The label layout.public final ILabelModelParameter createCanonicalParameter(RectD nodeLayout, IOrientedRectangle labelLayout, PointD referenceLocation)
This method creates a parameter
with the canonical
settings for the ratios and offsets in the following way. Each coordinate axis is considered independently. If the
reference point coordinate is within the node layout interval, its relative location specifies the layout ratio for this
coordinate. Otherwise, the absolute distance of the reference point and the interval specifies the layout offset and the
layout ratio is either either 0.0
or
1.0
. The parameters for the label ratio and label offset are calculated analogously. If no reference point
is provided, the reference point is determined automatically in the following way: For each coordinate, if the node
layout and label layout do not overlap, the reference is the label corner that is closest to the node. If they overlap
and if in addition the start or end coordinate of the label matches the start, center or end coordinate of the node,
that coordinate is the reference. Otherwise, the center of the label specifies the reference.
nodeLayout
- The node layout.labelLayout
- The label layout.referenceLocation
- The reference location.public final ILabelModelParameter createDefaultParameter()
createDefaultParameter
in interface ILabelModel
public final ILabelModelParameter createParameter(PointD layoutRatio, PointD layoutOffset, PointD labelRatio, PointD labelOffset, double angle)
The parameter will use the ratio and offset values to determine a point on both the label and the node. It will place the label in such a way that both points coincide.
layoutRatio
- The ratio that describes the point on the node's layout relative to its size.layoutOffset
- The offset to apply to the point on the node after the ratio has been determined.labelRatio
- The ratio that describes the point on the label's layout relative to its size.labelOffset
- The offset to apply to the point on the label after the ratio has been determined.angle
- The angle by which the label should be rotated around the point described using the ratio and offset, measured in
radians.public final ILabelModelParameter findBestParameter(ILabel label, ILabelModel model, IOrientedRectangle layout)
This implementation will match the provided layout perfectly.
findBestParameter
in interface ILabelModelParameterFinder
label
- The label to find a parameter for.model
- The model instance to use. This should be this instance.layout
- The anticipated layout for the label.null
parameter that can be used for the label to approximate the provided layout.public 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 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 <TLookup> TLookup lookup(Class<TLookup> type)
ILabelModelParameterFinder
is requested and null
otherwise.