Search this API

y.view
Class SmartEdgeLabelModel

java.lang.Object
  extended by y.view.SmartEdgeLabelModel
All Implemented Interfaces:
EdgeLabelModel, MoveLabelMode.MoveLabelHelperProvider

public class SmartEdgeLabelModel
extends java.lang.Object
implements EdgeLabelModel, MoveLabelMode.MoveLabelHelperProvider

An edge label model that allows the placement of labels at arbitrary positions. In the move label mode (see MoveLabelMode) it allows to snap to suitable label positions.

 

Field Summary
static int POSITION_CENTER
          Symbolic position specifier.
static int POSITION_LEFT
          Symbolic position specifier.
static int POSITION_RIGHT
          Symbolic position specifier.
static int POSITION_SOURCE_CENTER
          Symbolic position specifier.
static int POSITION_SOURCE_LEFT
          Symbolic position specifier.
static int POSITION_SOURCE_RIGHT
          Symbolic position specifier.
static int POSITION_TARGET_CENTER
          Symbolic position specifier.
static int POSITION_TARGET_LEFT
          Symbolic position specifier.
static int POSITION_TARGET_RIGHT
          Symbolic position specifier.
 
Constructor Summary
SmartEdgeLabelModel()
          Initializes a new SmartEdgeLabelModel instance.
 
Method Summary
 java.lang.Object createDiscreteModelParameter(int position)
          Creates a model parameter for a label at a given position.
 java.lang.Object createModelParameter(OrientedRectangle labelBounds, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Creates a model parameter that represents the given label bounds best within this model.
 MoveLabelMode.MoveLabelHelper createMoveLabelHelper()
          Creates a move helper for labels that use this SmartEdgeLabelModel instance.
 java.lang.Object createRelativeModelParameter(OrientedRectangle labelBounds, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Creates a model parameter that represents the given label bounds best within this model.
static double getAngle(java.lang.Object modelParameter)
          Returns the angle (measured in radians) encoded in the specified model parameter.
 double getDefaultAngle()
          Returns the default angle (measured in radians) of the label model which is used to create the default parameter.
 double getDefaultDistance()
          Returns the default distance which is used to create the default parameter.
 java.lang.Object getDefaultParameter()
          Returns the default parameter which uses the specified default angle and distance.
 YList getLabelCandidates(EdgeLabelLayout labelLayout, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout)
          Returns a list of EdgeLabelCandidate objects each of which describes a valid label position within this model.
 OrientedRectangle getLabelPlacement(YDimension labelSize, EdgeLayout edgeLayout, NodeLayout sourceLayout, NodeLayout targetLayout, java.lang.Object param)
          Returns the bounds of the label for the position encoded by the given 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.
 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 setDefaultAngle(double defaultAngle)
          Sets the default angle (measured in radians) of the label model which is used to create the default parameter.
 void setDefaultDistance(double defaultDistance)
          Sets the default distance which is used to create the default parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_SOURCE_CENTER

public static final int POSITION_SOURCE_CENTER
Symbolic position specifier. Places the label centered on the edge at the edge's source end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_SOURCE_LEFT

public static final int POSITION_SOURCE_LEFT
Symbolic position specifier. Places the label to the left of the edge at the edge's source end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_SOURCE_RIGHT

public static final int POSITION_SOURCE_RIGHT
Symbolic position specifier. Places the label to the right of the edge at the edge's source end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TARGET_CENTER

public static final int POSITION_TARGET_CENTER
Symbolic position specifier. Places the label centered on the edge at the edge's target end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TARGET_LEFT

public static final int POSITION_TARGET_LEFT
Symbolic position specifier. Places the label to the left of the edge at the edge's target end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TARGET_RIGHT

public static final int POSITION_TARGET_RIGHT
Symbolic position specifier. Places the label to the right of the edge at the edge's target end.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_CENTER

public static final int POSITION_CENTER
Symbolic position specifier. Places the label centered on the edge. The relative position along the edge depends on the number of edge segments. If there is only a single segment, the label will be placed in the middle of said segment. If there are multiple segments, the placement along the first segment depends on the label's size and the segment's length.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_LEFT

public static final int POSITION_LEFT
Symbolic position specifier. Places the label to the left of the edge. The relative position along the edge depends on the number of edge segments. If there is only a single segment, the label will be placed in the middle of said segment. If there are multiple segments, the placement along the first segment depends on the label's size and the segment's length.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_RIGHT

public static final int POSITION_RIGHT
Symbolic position specifier. Places the label to the right of the edge. The relative position along the edge depends on the number of edge segments. If there is only a single segment, the label will be placed in the middle of said segment. If there are multiple segments, the placement along the first segment depends on the label's size and the segment's length.

See Also:
createDiscreteModelParameter(int), Constant Field Values
Constructor Detail

SmartEdgeLabelModel

public SmartEdgeLabelModel()
Initializes a new SmartEdgeLabelModel instance.

Method Detail

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 disabled.

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 disabled.

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()

getDefaultAngle

public double getDefaultAngle()
Returns the default angle (measured in radians) of the label model which is used to create the default parameter. The angle is applied in clockwise direction.

Returns:
the default angle of the label model.
See Also:
getDefaultParameter()

setDefaultAngle

public void setDefaultAngle(double defaultAngle)
Sets the default angle (measured in radians) of the label model which is used to create the default parameter. The angle is applied in clockwise direction.

Parameters:
defaultAngle - the angle of the label model.
See Also:
getDefaultParameter()

getDefaultDistance

public double getDefaultDistance()
Returns the default distance which is used to create the default parameter. It specifies the distance between the label's box and the edge's path for the side slider positions.

Returns:
the default distance.
See Also:
getDefaultParameter()

setDefaultDistance

public void setDefaultDistance(double defaultDistance)
Sets the default distance which is used to create the default parameter. It specifies the distance between the label's box and the edge's path for the side slider positions.

Parameters:
defaultDistance - the used default distance.
See Also:
getDefaultParameter()

getDefaultParameter

public java.lang.Object getDefaultParameter()
Returns the default parameter which uses the specified default angle and distance.

Specified by:
getDefaultParameter in interface EdgeLabelModel
Returns:
the model parameter describing the default placement of the edge label
See Also:
setDefaultAngle(double), setDefaultDistance(double)

createDiscreteModelParameter

public java.lang.Object createDiscreteModelParameter(int position)
Creates a model parameter for a label at a given position. There are three positions at the source end, three positions at the target end, and three positions along the first segment of the edge.

Parameters:
position - one of the following positions: POSITION_SOURCE_CENTER, POSITION_TARGET_CENTER, POSITION_CENTER, POSITION_SOURCE_LEFT, POSITION_TARGET_LEFT, POSITION_LEFT, POSITION_SOURCE_RIGHT, POSITION_TARGET_RIGHT, and POSITION_RIGHT.
Returns:
the new model parameter
See Also:
DiscreteEdgeLabelModel.THREE_CENTER, DiscreteEdgeLabelModel.SIX_POS

getLabelPlacement

public OrientedRectangle getLabelPlacement(YDimension labelSize,
                                           EdgeLayout edgeLayout,
                                           NodeLayout sourceLayout,
                                           NodeLayout targetLayout,
                                           java.lang.Object param)
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.
sourceLayout - The layout of the source node of the label owning edge.
targetLayout - 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. Note: the parameter must have been generated by this model.
Returns:
The bounds of the label.

getLabelCandidates

public YList getLabelCandidates(EdgeLabelLayout labelLayout,
                                EdgeLayout edgeLayout,
                                NodeLayout sourceLayout,
                                NodeLayout targetLayout)
Returns a list of EdgeLabelCandidate objects each of which describes a valid label position within this model.

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 objects.

createModelParameter

public java.lang.Object createModelParameter(OrientedRectangle labelBounds,
                                             EdgeLayout edgeLayout,
                                             NodeLayout sourceLayout,
                                             NodeLayout targetLayout)
Creates a model parameter that represents the given label bounds best within this model. This model always creates a parameter that exactly encodes the position of the given label bounds, i.e., the OrientedRectangle returned by getLabelPlacement(y.geom.YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) is equal to labelBounds. The only exception to this rule is if an edge has no visible path, i.e., if the source node overlaps with the target node.

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.
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 model parameter that can be passed to the getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) method.
See Also:
EdgeLabelModel.getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object)

createRelativeModelParameter

public java.lang.Object createRelativeModelParameter(OrientedRectangle labelBounds,
                                                     EdgeLayout edgeLayout,
                                                     NodeLayout sourceLayout,
                                                     NodeLayout targetLayout)
Creates a model parameter that represents the given label bounds best within this model. This method interprets the angle of the label bounds to be relative with respect to the related edge segment. This is especially useful if auto rotation is enabled (see setAutoRotationEnabled(boolean)).

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.
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 model parameter that can be passed to the getLabelPlacement(YDimension, EdgeLayout, NodeLayout, NodeLayout, Object) method.

createMoveLabelHelper

public MoveLabelMode.MoveLabelHelper createMoveLabelHelper()
Creates a move helper for labels that use this SmartEdgeLabelModel instance. The helper supports snapping.

Specified by:
createMoveLabelHelper in interface MoveLabelMode.MoveLabelHelperProvider
Returns:
a move helper for this model instance.

getAngle

public static double getAngle(java.lang.Object modelParameter)
Returns the angle (measured in radians) encoded in the specified model parameter. The angle has to be interpreted in clockwise direction.

Parameters:
modelParameter - the model parameter from which the angle has to be extracted.
Returns:
the angle encoded in the specified model parameter.
Throws:
java.lang.IllegalArgumentException - if the specified model parameter is not valid for this model.

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