Search this API

y.layout
Class RotatedDiscreteEdgeLabelModel

java.lang.Object
  extended by y.layout.RotatedDiscreteEdgeLabelModel
All Implemented Interfaces:
EdgeLabelModel

public class RotatedDiscreteEdgeLabelModel
extends Object
implements EdgeLabelModel

An rotated edge label model that allows placement of rotated labels at some positions along an edge.

It's possible to specify a distance value that controls the distance between the 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 by OR-ing allowed label candidates to a user defined mask.


Field Summary
static int CENTER
          Symbolic position specifier.
static int CENTERED
          Position mask that constrains allowed positions to CENTER.
static int HEAD
          Symbolic position specifier.
static int SCENTER
          Symbolic position specifier.
static int SHEAD
          Symbolic position specifier.
static int SIX_POS
          Position mask that constrains allowed positions to a set of six positions on the "head" and "tail" sides of an edge.
static int STAIL
          Symbolic position specifier.
static int TAIL
          Symbolic position specifier.
static int TCENTER
          Symbolic position specifier.
static int THEAD
          Symbolic position specifier.
static int THREE_CENTER
          Position mask that constrains allowed positions to a set of three positions directly on the edge's path.
static int TTAIL
          Symbolic position specifier.
static int TWO_POS
          Position mask that constrains allowed positions to the two near the edge's end points.
 
Constructor Summary
RotatedDiscreteEdgeLabelModel()
          Returns a new instance of RotatedDiscreteEdgeLabelModel.
RotatedDiscreteEdgeLabelModel(int candidateMask)
          Returns a new instance of RotatedDiscreteEdgeLabelModel.
 
Method Summary
 Object createModelParameter(OrientedRectangle labelBounds, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode)
          Creates a model parameter that represents the given edge label context best within this model.
static Object createPositionParameter(int position)
          Returns a model parameter that encodes the specified position.
 double getAngle()
          Returns the angle (measured in radians) of the label model.
 int getCandidateMask()
          Returns the bit mask specifying the valid positions for edge labels.
 Object getDefaultParameter()
          Returns a model parameter that encodes the default position of this model's allowed edge label positions.
 double getDistance()
          Returns the distance between the label's box and the edge's path.
 YList getLabelCandidates(EdgeLabelLayout label, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode)
          Returns a list of EdgeLabelCandidate objects each of which describes a valid label position within this model.
protected  OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode, int pos)
          Returns the coordinates of the upper-left corner of the given label position.
 OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode, Object param)
          Returns the bounds of the label for the position encoded by the given model parameter.
static int getPosition(Object parameter)
          Returns the symbolic position specifier that is encoded by the specified model parameter.
 boolean isAutoFlippingEnabled()
          Determines whether or not edge labels get flipped if they would be upside down in their current position.
 boolean isAutoRotationEnabled()
          Returns whether or not edge labels are automatically rotated according to the angle of the corresponding reference edge segment.
 boolean isParameterValid(Object parameter)
          Checks if the given model parameter encodes an edge label position that is valid in this model.
 boolean isPositionRelativeToSegment()
          Returns whether or not the label position mask should be interpreted relative to the edge segment.
 void setAngle(double angle)
          Sets the angle (measured in radians) of the label model.
 void setAutoFlippingEnabled(boolean autoFlippingEnabled)
          Specifies whether or not edge labels get flipped if they would be upside down in their current position.
 void setAutoRotationEnabled(boolean enabled)
          Specifies whether or not edge labels have to be automatically rotated according to the angle of the corresponding reference edge segment.
 void setDistance(double value)
          Sets the distance between the label's box and the edge's path.
 void setPositionRelativeToSegment(boolean positionRelativeToSegment)
          Sets whether or not the label position mask should be interpreted relative to the edge segment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHEAD

public static final int SHEAD
Symbolic position specifier. Places the label near the source node. The label's position is to the left of or above the edge's path.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

HEAD

public static final int HEAD
Symbolic position specifier. Places the label near the middle of the edge's path. The label's position is to the left of or above the edge's path.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

THEAD

public static final int THEAD
Symbolic position specifier. Places the label near the target node. The label's position is to the left of or above the edge's path. Places the label near the target node on the "head" side of the edge.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

STAIL

public static final int STAIL
Symbolic position specifier. Places the label near the source node. The label's position is to the right of or below the edge's path.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

TAIL

public static final int TAIL
Symbolic position specifier. Places the label near the middle of the edge's path. The label's position is to the right of or below the edge's path.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

TTAIL

public static final int TTAIL
Symbolic position specifier. Places the label near the target node. The label's position is to the right of or below the edge's path.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

SCENTER

public static final int SCENTER
Symbolic position specifier. Places the label near the source node directly on the edge path.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Symbolic position specifier. Places the label near the middle of an edge directly on its path.

See Also:
Constant Field Values

TCENTER

public static final int TCENTER
Symbolic position specifier. Places the label near the target node directly on the edge path.

See Also:
Constant Field Values

TWO_POS

public static final int TWO_POS
Position mask that constrains allowed positions to the two near the edge's end points. Namely, these are HEAD and TAIL.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

CENTERED

public static final int CENTERED
Position mask that constrains allowed positions to CENTER.

See Also:
Constant Field Values

SIX_POS

public static final int SIX_POS
Position mask that constrains allowed positions to a set of six positions on the "head" and "tail" sides of an edge. Namely, these are SHEAD, HEAD, THEAD, STAIL, TAIL, and TTAIL.

See Also:
setPositionRelativeToSegment(boolean), Constant Field Values

THREE_CENTER

public static final int THREE_CENTER
Position mask that constrains allowed positions to a set of three positions directly on the edge's path. Namely, these are SCENTER, CENTER, and TCENTER.

See Also:
Constant Field Values
Constructor Detail

RotatedDiscreteEdgeLabelModel

public RotatedDiscreteEdgeLabelModel()
Returns a new instance of RotatedDiscreteEdgeLabelModel. Position mask SIX_POS is used to define the allowed positions for an edge label.


RotatedDiscreteEdgeLabelModel

public RotatedDiscreteEdgeLabelModel(int candidateMask)
Returns a new instance of RotatedDiscreteEdgeLabelModel.

Parameters:
candidateMask - Position mask that defines the allowed positions for an edge label.
Method Detail

getCandidateMask

public int getCandidateMask()
Returns the bit mask specifying the valid positions for edge labels.

Defaults to SIX_POS.

Returns:
the bit mask specifying the valid positions for edge labels.

isPositionRelativeToSegment

public boolean isPositionRelativeToSegment()
Returns whether or not the label position mask should be interpreted relative to the edge segment. If this value is set to false (default value), the position mask is interpreted in a geometric sense. Note: this option is only relevant for non-center positions.


setPositionRelativeToSegment

public void setPositionRelativeToSegment(boolean positionRelativeToSegment)
Sets whether or not the label position mask should be interpreted relative to the edge segment. If this value is set to false (default value), the position mask is interpreted in a geometric sense. Note: this option is only relevant for non-center positions.


isAutoRotationEnabled

public boolean isAutoRotationEnabled()
Returns whether or not edge labels are automatically rotated according to the angle of the corresponding reference edge segment.

By default, this feature is enabled.

Returns:
true if edge labels are automatically rotated according to the angle of the corresponding reference edge segment and false if they are not.
See Also:
setAutoRotationEnabled(boolean)

setAutoRotationEnabled

public void setAutoRotationEnabled(boolean enabled)
Specifies whether or not edge labels have to be automatically rotated according to the angle of the corresponding reference edge segment.

By default, this feature is enabled.

Parameters:
enabled - if true edge labels are automatically rotated according to the angle of the corresponding reference edge segment.
See Also:
isAutoRotationEnabled()

isAutoFlippingEnabled

public boolean isAutoFlippingEnabled()
Determines whether or not edge labels get flipped if they would be upside down in their current position.

By default, this feature is disabled.

Returns:
true if edge labels get flipped if they would be upside down in their current position, false otherwise.
See Also:
setAutoFlippingEnabled(boolean)

setAutoFlippingEnabled

public void setAutoFlippingEnabled(boolean autoFlippingEnabled)
Specifies whether or not edge labels get flipped if they would be upside down in their current position.

By default, this feature is disabled.

Parameters:
autoFlippingEnabled - true if edge labels get flipped if they would be upside down in their current position.
See Also:
isAutoFlippingEnabled()

getAngle

public double getAngle()
Returns the angle (measured in radians) of the label model. The angle is applied in clockwise direction.

Returns:
the angle of the label model.

setAngle

public void setAngle(double angle)
Sets the angle (measured in radians) of the label model. The angle is applied in clockwise direction.

Parameters:
angle - the angle of the label model.

getDistance

public double getDistance()
Returns the distance between the label's box and the edge's path.

Returns:
the distance between the label's box and the edge's path.

setDistance

public void setDistance(double value)
Sets the distance between the label's box and the edge's path.

Parameters:
value - A non-negative value.

getDefaultParameter

public Object getDefaultParameter()
Returns a model parameter that encodes the default position of this model's allowed edge label positions.

Default positions are (in descending order):

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.

Note that the model parameter encodes CENTER when none of the above default positions is part of the allowed positions.

Specified by:
getDefaultParameter in interface EdgeLabelModel
Returns:
A model parameter that can be passed to the EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) method.

createModelParameter

public Object createModelParameter(OrientedRectangle labelBounds,
                                   EdgeLayout edgeLayout,
                                   NodeLayout sourceNode,
                                   NodeLayout targetNode)
Description copied from interface: EdgeLabelModel
Creates a model parameter that represents the given edge label context best within this model. The created model parameter represents the closest parameter representation of the given label location that can be achieved within this model.

Specified by:
createModelParameter in interface EdgeLabelModel
Parameters:
labelBounds - The bounds of the label for which a parameter representation is sought.
edgeLayout - The layout of the edge to which the label belongs.
sourceNode - The layout of the source node of the label owning edge.
targetNode - The layout of the target node of the label owning edge.
Returns:
A model parameter that can be passed to the EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) method.

createPositionParameter

public static Object createPositionParameter(int position)
Returns a model parameter that encodes the specified position.

Throws:
IllegalArgumentException - if the specified position is not one of the symbolic position constants defined in this class.
Parameters:
position - one of
Returns:
a model parameter that encodes the specified position.

getPosition

public static int getPosition(Object parameter)
Returns the symbolic position specifier that is encoded by the specified model parameter.

Throws:
IllegalArgumentException - if the specified model parameter is not valid for this model.
Parameters:
parameter - the model parameter that encodes the position.
Returns:
the symbolic position specifier that is encoded by the specified model parameter.

isParameterValid

public boolean isParameterValid(Object parameter)
Checks if the given model parameter encodes an edge label position that is valid in this model.

Parameters:
parameter - the model parameter to check.
Returns:
true if the specified object is a valid parameter for this model and encodes a valid position according to this model's candidate mask; false otherwise.

getLabelPlacement

public OrientedRectangle getLabelPlacement(YDimension labelSize,
                                           EdgeLayout edgeLayout,
                                           NodeLayout sourceNode,
                                           NodeLayout targetNode,
                                           Object param)
Description copied from interface: EdgeLabelModel
Returns the bounds of the label for the position encoded by the given model parameter.

Specified by:
getLabelPlacement in interface EdgeLabelModel
Parameters:
labelSize - The size of the label that should be placed.
edgeLayout - The layout of the edge to which the label belongs.
sourceNode - The layout of the source node of the label owning edge.
targetNode - The layout of the target node of the label owning edge.
param - The model parameter that describes the abstract position of the label within this model. The parameter must have been generated by this model.
Returns:
The bounds of the label.

getLabelCandidates

public YList getLabelCandidates(EdgeLabelLayout label,
                                EdgeLayout edgeLayout,
                                NodeLayout sourceNode,
                                NodeLayout targetNode)
Description copied from interface: EdgeLabelModel
Returns a list of EdgeLabelCandidate objects each of which describes a valid label position within this model.

Specified by:
getLabelCandidates in interface EdgeLabelModel
Parameters:
label - The label for which candidates should be generated.
edgeLayout - The layout of the edge to which the label belongs.
sourceNode - The layout of the source node of the label owning edge.
targetNode - The layout of the target node of the label owning edge.
Returns:
A list of EdgeLabelCandidate objects.

getLabelPlacement

protected OrientedRectangle getLabelPlacement(YDimension labelSize,
                                              EdgeLayout edgeLayout,
                                              NodeLayout sourceNode,
                                              NodeLayout targetNode,
                                              int pos)
Returns the coordinates of the upper-left corner of the given label position.

Parameters:
labelSize - The size of the label that should be placed.
edgeLayout - The layout of the edge to which the label belongs.
sourceNode - The layout of the source node of the label owning edge.
targetNode - The layout of the target node of the label owning edge.
pos - A label position (given by a symbolic position specifier) that is valid in this model.
Returns:
The coordinates of the upper-left corner of a label position.

© Copyright 2000-2013,
yWorks GmbH.
All rights reserved.