public class DiscreteEdgeLabelLayoutModel extends Object implements IEdgeLabelLayoutModel
DiscreteEdgeLabelLayoutModel
describes the placement of rotated labels at some predefined positions along the
edge.
The predefined positions in this model
It's possible to specify a distance value that controls the distance between label and edge.
Furthermore, there's the possibility to mask out arbitrary edge label candidates. This can either be done by specifying
predefined candidate masks or combining several label positions with a logical
or
-operation to a user-defined mask.
Constructor and Description |
---|
DiscreteEdgeLabelLayoutModel()
Creates a new instance of
DiscreteEdgeLabelLayoutModel with default settings. |
DiscreteEdgeLabelLayoutModel(DiscreteEdgeLabelPositions candidateMask)
Creates a new instance of
DiscreteEdgeLabelLayoutModel using the given candidate mask. |
Modifier and Type | Method and Description |
---|---|
Object |
createModelParameter(YOrientedRectangle labelBounds,
IEdgeLayout edgeLayout,
INodeLayout sourceNode,
INodeLayout targetNode)
Creates a model parameter that represents the given edge label position within this model.
|
static Object |
createPositionParameter(int position)
Returns a model parameter that encodes the specified position.
|
double |
getAngle()
Gets the angle (measured in radians) of the label model.
|
DiscreteEdgeLabelPositions |
getCandidateMask()
Gets the candidate mask which specifies the valid positions for edge labels.
|
Object |
getDefaultParameter()
Gets a model parameter that encodes the default position of this model's allowed edge label positions.
|
double |
getDistance()
Gets the distance between the label's bounding box and the edge path.
|
YList |
getLabelCandidates(IEdgeLabelLayout label,
IEdgeLayout edgeLayout,
INodeLayout sourceNode,
INodeLayout targetNode)
Returns all
EdgeLabelCandidate s that describe valid label positions within this model. |
protected YOrientedRectangle |
getLabelPlacement(YDimension labelSize,
IEdgeLayout edgeLayout,
INodeLayout sourceLayout,
INodeLayout targetLayout,
DiscreteEdgeLabelPositions position)
Returns the oriented box of the label for the given label position.
|
YOrientedRectangle |
getLabelPlacement(YDimension labelSize,
IEdgeLayout edgeLayout,
INodeLayout sourceNode,
INodeLayout targetNode,
Object param)
Returns the oriented box of the label for the position encoded by the given model parameter.
|
static int |
getPosition(Object parameter)
Returns the position specifier that is encoded by the given model parameter.
|
boolean |
isAutoFlippingEnabled()
Gets whether or not edge labels get flipped if they would be upside down in their current position.
|
boolean |
isAutoRotationEnabled()
Gets whether or not edge labels are automatically rotated according to the angle of the corresponding reference edge
segment.
|
boolean |
isParameterValid(Object parameter)
Checks whether or not the given model parameter encodes a valid edge label position for this model.
|
boolean |
isPositionRelativeToSegment()
Gets whether or not the label position mask should be interpreted relative to the edge segment.
|
void |
setAngle(double value)
Sets the angle (measured in radians) of the label model.
|
void |
setAutoFlippingEnabled(boolean value)
Sets whether or not edge labels get flipped if they would be upside down in their current position.
|
void |
setAutoRotationEnabled(boolean value)
Sets whether or not 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's bounding box and the edge path.
|
void |
setPositionRelativeToSegment(boolean value)
Sets whether or not the label position mask should be interpreted relative to the edge segment.
|
public DiscreteEdgeLabelLayoutModel()
DiscreteEdgeLabelLayoutModel
with default settings.public DiscreteEdgeLabelLayoutModel(DiscreteEdgeLabelPositions candidateMask)
DiscreteEdgeLabelLayoutModel
using the given candidate mask.
The candidates mask can either describe multiple or single valid positions.
candidateMask
- the position mask that defines the allowed positions for an edge labelpublic Object createModelParameter(YOrientedRectangle labelBounds, IEdgeLayout edgeLayout, INodeLayout sourceNode, INodeLayout targetNode)
IEdgeLabelLayoutModel
The created model parameter is the closest parameter representation of the given label location that can be achieved within this model.
This parameter can be passed to IEdgeLabelLayoutModel.getLabelPlacement(YDimension, IEdgeLayout, INodeLayout, INodeLayout, Object)
to
retrieve the current label box.
A model parameter can be an arbitrary Object
. However it must contain all information to allow restoring of the
encoded location with this IEdgeLabelLayoutModel
.
createModelParameter
in interface IEdgeLabelLayoutModel
labelBounds
- the oriented box of the label, encoding the label location for which the parameter should be creatededgeLayout
- the layout of the edge to which the label belongssourceNode
- the layout of the source node of the label-owning edgetargetNode
- the layout of the target node of the label-owning edgeIEdgeLabelLayoutModel.getLabelPlacement(YDimension, IEdgeLayout, INodeLayout, INodeLayout, Object)
public static final Object createPositionParameter(int position)
This model parameter can be passed to getLabelPlacement(YDimension, IEdgeLayout, INodeLayout, INodeLayout, Object)
to determine the label's position.
IllegalArgumentException
- if the specified position is unknownposition
- one of the valid positionspublic double getAngle()
The angle is applied in clockwise direction.
setAngle(double)
public DiscreteEdgeLabelPositions getCandidateMask()
DiscreteEdgeLabelPositions.SIX_POS
public Object getDefaultParameter()
Default positions are (in descending order):
DiscreteEdgeLabelPositions.CENTER
DiscreteEdgeLabelPositions.SOURCE_CENTER
DiscreteEdgeLabelPositions.TAIL
DiscreteEdgeLabelPositions.SOURCE_TAIL
Descending order means that whenever two or more of the above default positions are part of the allowed positions, then the model parameter encodes the one that is listed first.
getDefaultParameter
in interface IEdgeLabelLayoutModel
DiscreteEdgeLabelPositions.CENTER
when none of the above default positions is part
of the allowed positions.public double getDistance()
The distance must be a non-negative value.
setDistance(double)
public YList getLabelCandidates(IEdgeLabelLayout label, IEdgeLayout edgeLayout, INodeLayout sourceNode, INodeLayout targetNode)
IEdgeLabelLayoutModel
EdgeLabelCandidate
s that describe valid label positions within this model.
In case the implementing IEdgeLabelLayoutModel
allows every possible location, this method always returns the
current location as a LabelCandidate
.
getLabelCandidates
in interface IEdgeLabelLayoutModel
label
- the label for which candidates should be generatededgeLayout
- the layout of the edge to which the label belongssourceNode
- the layout of the source node of the label-owning edgetargetNode
- the layout of the target node of the label-owning edgeEdgeLabelCandidate
instancesprotected YOrientedRectangle getLabelPlacement(YDimension labelSize, IEdgeLayout edgeLayout, INodeLayout sourceLayout, INodeLayout targetLayout, DiscreteEdgeLabelPositions position)
This method is called by getLabelPlacement(YDimension, IEdgeLayout, INodeLayout, INodeLayout, Object)
and getLabelCandidates(IEdgeLabelLayout, IEdgeLayout, INodeLayout, INodeLayout)
to retrieve a valid position.
labelSize
- the size of the label that should be placededgeLayout
- the layout of the edge to which the label belongssourceLayout
- the layout of the source node of the label-owning edgetargetLayout
- the layout of the target node of the label-owning edgeposition
- the label position that is valid in this modelpublic YOrientedRectangle getLabelPlacement(YDimension labelSize, IEdgeLayout edgeLayout, INodeLayout sourceNode, INodeLayout targetNode, Object param)
IEdgeLabelLayoutModel
getLabelPlacement
in interface IEdgeLabelLayoutModel
labelSize
- the width and height of the labeledgeLayout
- the layout of the edge to which the label belongssourceNode
- the layout of the source node of the label-owning edgetargetNode
- the layout of the target node of the label-owning edgeparam
- the model parameter that describes the abstract position of the label within this modelpublic static final int getPosition(Object parameter)
IllegalArgumentException
- if the specified model parameter is not valid for this modelparameter
- the model parameterpublic boolean isAutoFlippingEnabled()
false
. Edge labels keep their orientation.true
if edge labels get flipped if they would be upside down in their current position, false
otherwisesetAutoFlippingEnabled(boolean)
public boolean isAutoRotationEnabled()
true
. Labels are rotated with their edge segment.true
if edge labels are automatically rotated according to the angle of the corresponding reference edge
segment, false
otherwisesetAutoRotationEnabled(boolean)
public boolean isParameterValid(Object parameter)
If the model parameter describes a position that is accepted by the candidate mask, this is a valid parameter.
parameter
- the model parametertrue
if the label position described by the given model parameter is allowed, false
otherwisepublic boolean isPositionRelativeToSegment()
If this option is disabled, the position mask is interpreted in a geometric sense.
false
. Positions are interpreted geometrically.true
if the position mask is interpreted relative to the edge segment, false
otherwisesetPositionRelativeToSegment(boolean)
public void setAngle(double value)
The angle is applied in clockwise direction.
value
- the angle of the label modelgetAngle()
public void setAutoFlippingEnabled(boolean value)
false
. Edge labels keep their orientation.value
- true
if edge labels get flipped if they would be upside down in their current position, false
otherwiseisAutoFlippingEnabled()
public void setAutoRotationEnabled(boolean value)
true
. Labels are rotated with their edge segment.value
- true
if edge labels are automatically rotated according to the angle of the corresponding reference edge
segment, false
otherwiseisAutoRotationEnabled()
public void setDistance(double value)
The distance must be a non-negative value.
value
- the distance between the edge and the associated labelgetDistance()
public void setPositionRelativeToSegment(boolean value)
If this option is disabled, the position mask is interpreted in a geometric sense.
false
. Positions are interpreted geometrically.value
- true
if the position mask is interpreted relative to the edge segment, false
otherwiseisPositionRelativeToSegment()