Search this API

y.layout
Class DiscreteEdgeLabelModel

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

public class DiscreteEdgeLabelModel
extends Object
implements EdgeLabelModel

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

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 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
DiscreteEdgeLabelModel()
          Returns a new instance of DiscreteEdgeLabelModel.
DiscreteEdgeLabelModel(int candidateMask)
          Returns a new instance of DiscreteEdgeLabelModel.
 
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.
 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 bounding 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 para)
          Returns the bounds of the label for the position encoded by the given model parameter.
 boolean isParameterValid(Object parameter)
          Checks if the given model parameter encodes an edge label position that is valid in this model.
 void setDistance(double value)
          Sets the distance between the label's bounding box and the edge's path.
 
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:
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:
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:
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:
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:
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:
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:
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:
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

DiscreteEdgeLabelModel

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


DiscreteEdgeLabelModel

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

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.

getDistance

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

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

setDistance

public void setDistance(double value)
Sets the distance between the label's bounding 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.

isParameterValid

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

Returns:
Whether the label position encoded by the given model parameter is among the allowed positions.

getLabelPlacement

public OrientedRectangle getLabelPlacement(YDimension labelSize,
                                           EdgeLayout edgeLayout,
                                           NodeLayout sourceNode,
                                           NodeLayout targetNode,
                                           Object para)
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.
para - 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.