Search this API

y.layout
Class DiscreteEdgeLabelModel

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

public class DiscreteEdgeLabelModel
extends java.lang.Object
implements EdgeLabelModel

DiscreteEdgeLabelModel describes the placement of 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 a combination of valid positions of this model using a logical or-operation.

 
Your browser does not support SVG content.

Field Summary
static int CENTER
          Position specifier that describes a label placement near the middle of the edge, directly on the edge's path.
static int CENTERED
          Position mask that constrains the allowed positions to the CENTER of the edge's path.
static int HEAD
          Position specifier that describes a label placement near the middle of the edge, left/above the edge's path.
static int SCENTER
          Position specifier that describes a label placement near the source, directly on the edge's path.
static int SHEAD
          Position specifier that describes a label placement near the source, left/above the edge's path.
static int SIX_POS
          Position mask that constrains the allowed positions to a set of six positions beside the edge path.
static int STAIL
          Position specifier that describes a label placement near the source, right/below the edge's path.
static int TAIL
          Position specifier that describes a label placement near the middle of the edge, right/below the edge's path.
static int TCENTER
          Position specifier that describes a label placement near the target, directly on the edge's path.
static int THEAD
          Position specifier that describes a label placement near the target, left/above the edge's path.
static int THREE_CENTER
          Position mask that constrains the allowed positions to a set of three positions directly on the edge's path.
static int TTAIL
          Position specifier that describes a label placement near the target, right/below the edge's path.
static int TWO_POS
          Position mask that constrains the allowed positions to the two locations near the middle of the edge beside the edge's path.
 
Constructor Summary
DiscreteEdgeLabelModel()
          Creates a new instance of DiscreteEdgeLabelModel with default settings.
DiscreteEdgeLabelModel(int candidateMask)
          Creates a new instance of DiscreteEdgeLabelModel using the given candidate mask.
 
Method Summary
 java.lang.Object createModelParameter(OrientedRectangle labelBounds, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode)
          Creates a model parameter that represents the given edge label position within this model.
static java.lang.Object createPositionParameter(int position)
          Returns a model parameter that encodes the specified position.
 int getCandidateMask()
          Returns the candidate mask which specifies the valid positions for edge labels.
 java.lang.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 path.
 YList getLabelCandidates(EdgeLabelLayout labelLayout, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Returns all EdgeLabelCandidates that describe valid label positions within this model considering the current candidate mask.
protected  OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout, int position)
          Returns the oriented box of the label for the given label position.
 OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceNode, NodeLayout targetNode, java.lang.Object parameter)
          Returns the oriented box of the label for the position encoded by the given model parameter.
 boolean isParameterValid(java.lang.Object parameter)
          Checks whether or not the given model parameter encodes a valid edge label position for this model.
 void setDistance(double value)
          Specifies the distance between the label's bounding box and the edge 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
Position specifier that describes a label placement near the source, left/above the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the source head position

HEAD

public static final int HEAD
Position specifier that describes a label placement near the middle of the edge, left/above the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the head position

THEAD

public static final int THEAD
Position specifier that describes a label placement near the target, left/above the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the target head position

STAIL

public static final int STAIL
Position specifier that describes a label placement near the source, right/below the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the source tail position

TAIL

public static final int TAIL
Position specifier that describes a label placement near the middle of the edge, right/below the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the tail position

TTAIL

public static final int TTAIL
Position specifier that describes a label placement near the target, right/below the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the target tail position

SCENTER

public static final int SCENTER
Position specifier that describes a label placement near the source, directly on the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the source center position

CENTER

public static final int CENTER
Position specifier that describes a label placement near the middle of the edge, directly on the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at the center position

TCENTER

public static final int TCENTER
Position specifier that describes a label placement near the target, directly on the edge's path.

 
To define multiple valid placements for a label, all position specifiers can be combined with a logical or-operation.
See Also:
Constant Field Values
Sample Graph:

Label at tail center position

TWO_POS

public static final int TWO_POS
Position mask that constrains the allowed positions to the two locations near the middle of the edge beside the edge's path.

See Also:
HEAD, TAIL, Constant Field Values
Sample Graph:

The two center positions are valid

CENTERED

public static final int CENTERED
Position mask that constrains the allowed positions to the CENTER of the edge's path.

See Also:
CENTER, Constant Field Values
Sample Graph:

Only the center position is valid

SIX_POS

public static final int SIX_POS
Position mask that constrains the allowed positions to a set of six positions beside the edge path.

Two of the positions are near the source and two others are near the target. The remaining positions are in the middle of the edge.

See Also:
SHEAD, STAIL, HEAD, TAIL, THEAD, TTAIL, Constant Field Values
Sample Graph:

The six positions beside the edge are valid

THREE_CENTER

public static final int THREE_CENTER
Position mask that constrains the allowed positions to a set of three positions directly on the edge's path.

See Also:
SCENTER, CENTER, TCENTER, Constant Field Values
Sample Graph:

The three positions on the edge are valid
Constructor Detail

DiscreteEdgeLabelModel

public DiscreteEdgeLabelModel()
Creates a new instance of DiscreteEdgeLabelModel with default settings.


DiscreteEdgeLabelModel

public DiscreteEdgeLabelModel(int candidateMask)
Creates a new instance of DiscreteEdgeLabelModel using the given candidate mask.

The specified mask can also describe a single position.

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

getCandidateMask

public int getCandidateMask()
Returns the candidate mask which specifies the valid positions for edge labels.

This mask can also describe a single position.

Default Value:
The default value is SIX_POS
Returns:
the position mask that defines the allowed positions for an edge label

getDistance

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

The distance must be a non-negative value.

Returns:
the distance between the edge and the associated label
See Also:
setDistance(double)

setDistance

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

The distance must be a non-negative value.

Default Value:
The default value is 2.
Parameters:
value - the distance between the edge and the associated label
Sample Graphs:

2

10

getDefaultParameter

public java.lang.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.

Specified by:
getDefaultParameter in interface EdgeLabelModel
 
The model parameter encodes CENTER when none of the above default positions is part of the allowed positions.
Returns:
the model parameter describing the default placement of the edge label

createModelParameter

public java.lang.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 position within this model.

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 EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, 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 EdgeLabelModel.

Specified by:
createModelParameter in interface EdgeLabelModel
Parameters:
labelBounds - the oriented box of the label, encoding the label location for which the parameter should be created
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:
the model parameter representing the given label location
See Also:
EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object)

createPositionParameter

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

This model parameter can be passed to getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) to determine the label's position.

Parameters:
position - one of the valid positions
Returns:
a model parameter that encodes the specified position
Throws:
java.lang.IllegalArgumentException - if the specified position is unknown

isParameterValid

public boolean isParameterValid(java.lang.Object parameter)
Checks whether or not the given model parameter encodes a valid edge label position for this model.

If the model parameter describes a position that is accepted by the candidate mask, this is a valid parameter.

 
In order to be valid, the parameter should be created by this label model.
Parameters:
parameter - the model parameter
Returns:
true if the label position described by the given model parameter is allowed, false otherwise

getLabelPlacement

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

Specified by:
getLabelPlacement in interface EdgeLabelModel
Parameters:
labelSize - the width and height of the label
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
parameter - the model parameter that describes the abstract position of the label within this model
Returns:
the oriented bounds of the label

getLabelCandidates

public YList getLabelCandidates(EdgeLabelLayout labelLayout,
                                EdgeLayout edgeLayout,
                                NodeLayout sourceLayout,
                                NodeLayout targetLayout)
Returns all EdgeLabelCandidates that describe valid label positions within this model considering the current candidate mask.

Specified by:
getLabelCandidates in interface EdgeLabelModel
Parameters:
labelLayout - the label for which candidates should be generated
edgeLayout - the layout of the edge to which the label belongs
sourceLayout - the layout of the source node of the label-owning edge
targetLayout - the layout of the target node of the label-owning edge
Returns:
a list of EdgeLabelCandidate instances describing valid label positions
See Also:
getCandidateMask()

getLabelPlacement

protected OrientedRectangle getLabelPlacement(YDimension labelSize,
                                              EdgeLayout edgeLayout,
                                              NodeLayout sourceLayout,
                                              NodeLayout targetLayout,
                                              int position)
Returns the oriented box of the label for the given label position.

This method is called by getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) and getLabelCandidates(EdgeLabelLayout, EdgeLayout, NodeLayout, NodeLayout) to retrieve a valid position.

Parameters:
labelSize - the size of the label that should be placed
edgeLayout - the layout of the edge to which the label belongs
sourceLayout - the layout of the source node of the label-owning edge
targetLayout - the layout of the target node of the label-owning edge
position - the label position that is valid in this model
Returns:
the oriented box of the label

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