Search this API

y.view
Class SmartNodeLabelModel

java.lang.Object
  extended by y.view.SmartNodeLabelModel
All Implemented Interfaces:
NodeLabelModel

public class SmartNodeLabelModel
extends java.lang.Object
implements NodeLabelModel

A node label model that allows free placement of labels and provides smart dynamic behavior. Labels using this model are anchored to a specific point in their associated nodes. In other words, labels will usually retain the relative position with respect to the bounds of their associated node when the node is resized. E.g. a label anchored to the lower right corner of a node will stay in the lower right when the node is resized.

 

Field Summary
static int ALIGNMENT_BOTTOM
          Symbolic anchor specifier.
static int ALIGNMENT_BOTTOM_LEFT
          Symbolic anchor specifier.
static int ALIGNMENT_BOTTOM_RIGHT
          Symbolic anchor specifier.
static int ALIGNMENT_LEFT
          Symbolic anchor specifier.
static int ALIGNMENT_RIGHT
          Symbolic anchor specifier.
static int ALIGNMENT_TOP
          Symbolic anchor specifier.
static int ALIGNMENT_TOP_LEFT
          Symbolic anchor specifier.
static int ALIGNMENT_TOP_RIGHT
          Symbolic anchor specifier.
static int POSITION_BOTTOM
          Symbolic position specifier.
static int POSITION_BOTTOM_LEFT
          Symbolic position specifier.
static int POSITION_BOTTOM_RIGHT
          Symbolic position specifier.
static int POSITION_CENTER
          Symbolic position specifier.
static int POSITION_EAST
          Symbolic position specifier.
static int POSITION_LEFT
          Symbolic position specifier.
static int POSITION_NORTH
          Symbolic position specifier.
static int POSITION_NORTH_EAST
          Symbolic position specifier.
static int POSITION_NORTH_WEST
          Symbolic position specifier.
static int POSITION_RIGHT
          Symbolic position specifier.
static int POSITION_SOUTH
          Symbolic position specifier.
static int POSITION_SOUTH_EAST
          Symbolic position specifier.
static int POSITION_SOUTH_WEST
          Symbolic position specifier.
static int POSITION_TOP
          Symbolic position specifier.
static int POSITION_TOP_LEFT
          Symbolic position specifier.
static int POSITION_TOP_RIGHT
          Symbolic position specifier.
static int POSITION_WEST
          Symbolic position specifier.
 
Constructor Summary
SmartNodeLabelModel()
          Returns a new instance of SmartNodeLabelModel.
SmartNodeLabelModel(double distance)
          Returns a new instance of SmartNodeLabelModel.
 
Method Summary
 java.lang.Object createAlignedModelParameter(OrientedRectangle labelBox, NodeLayout nodeLayout, int alignment)
          Creates a model parameter which is aligned to the given sides of the node.
 java.lang.Object createDiscreteModelParameter(int position)
          Creates a model parameter for a label at a given position.
 java.lang.Object createModelParameter(OrientedRectangle labelBounds, NodeLayout nodeLayout)
          Creates a model parameter for a free positioned label.
 java.lang.Object createSpecificModelParameter(double nodeRatioX, double nodeRatioY, double labelRatioX, double labelRatioY, double offsetX, double offsetY, double upX, double upY)
          Creates a model parameter where all values are specified manually.
 java.lang.Object getDefaultParameter()
          Returns a model parameter that encodes the default position in the center of the node.
 double getDistance()
          Returns the distance between the bounding boxes of label and node.
 YList getLabelCandidates(NodeLabelLayout nl, NodeLayout nodeLayout)
          Returns a list of candidate candidates for the given node label.
 OrientedRectangle getLabelPlacement(YDimension labelSize, NodeLayout nodeLayout, java.lang.Object param)
          Returns the the oriented label position and bounds encoded by the given model parameter.
 void setDistance(double distance)
          Sets the distance between the bounding boxes of label and node in the manner of an inset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POSITION_CENTER

public static final int POSITION_CENTER
Symbolic position specifier. Places the label in the center of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_LEFT

public static final int POSITION_LEFT
Symbolic position specifier. Places the label at the left inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_RIGHT

public static final int POSITION_RIGHT
Symbolic position specifier. Places the label at the right inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TOP

public static final int POSITION_TOP
Symbolic position specifier. Places the label at the top inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TOP_LEFT

public static final int POSITION_TOP_LEFT
Symbolic position specifier. Places the label at the top-left inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_TOP_RIGHT

public static final int POSITION_TOP_RIGHT
Symbolic position specifier. Places the label at the top-right inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_BOTTOM

public static final int POSITION_BOTTOM
Symbolic position specifier. Places the label at the bottom inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_BOTTOM_LEFT

public static final int POSITION_BOTTOM_LEFT
Symbolic position specifier. Places the label at the bottom-left inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_BOTTOM_RIGHT

public static final int POSITION_BOTTOM_RIGHT
Symbolic position specifier. Places the label at the bottom right inside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_EAST

public static final int POSITION_EAST
Symbolic position specifier. Places the label at the right outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_WEST

public static final int POSITION_WEST
Symbolic position specifier. Places the label at the left outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_NORTH

public static final int POSITION_NORTH
Symbolic position specifier. Places the label at the top outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_NORTH_EAST

public static final int POSITION_NORTH_EAST
Symbolic position specifier. Places the label at the top right outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_NORTH_WEST

public static final int POSITION_NORTH_WEST
Symbolic position specifier. Places the label at the top left outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_SOUTH

public static final int POSITION_SOUTH
Symbolic position specifier. Places the label at the bottom outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_SOUTH_EAST

public static final int POSITION_SOUTH_EAST
Symbolic position specifier. Places the label at the bottom right outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

POSITION_SOUTH_WEST

public static final int POSITION_SOUTH_WEST
Symbolic position specifier. Places the label at the bottom left outside of the node.

See Also:
createDiscreteModelParameter(int), Constant Field Values

ALIGNMENT_TOP

public static final int ALIGNMENT_TOP
Symbolic anchor specifier. Aligns the label in relation to the top side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_BOTTOM

public static final int ALIGNMENT_BOTTOM
Symbolic anchor specifier. Aligns the label in relation to the bottom side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_LEFT

public static final int ALIGNMENT_LEFT
Symbolic anchor specifier. Aligns the label in relation to the left side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_RIGHT

public static final int ALIGNMENT_RIGHT
Symbolic anchor specifier. Aligns the label in relation to the right side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_TOP_LEFT

public static final int ALIGNMENT_TOP_LEFT
Symbolic anchor specifier. Aligns the label in relation to the top and the left side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_TOP_RIGHT

public static final int ALIGNMENT_TOP_RIGHT
Symbolic anchor specifier. Aligns the label in relation to the top and the right side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_BOTTOM_LEFT

public static final int ALIGNMENT_BOTTOM_LEFT
Symbolic anchor specifier. Aligns the label in relation to the bottom and the left side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values

ALIGNMENT_BOTTOM_RIGHT

public static final int ALIGNMENT_BOTTOM_RIGHT
Symbolic anchor specifier. Aligns the label in relation to the bottom and the right side of the node.

See Also:
createAlignedModelParameter(y.geom.OrientedRectangle, y.layout.NodeLayout, int), Constant Field Values
Constructor Detail

SmartNodeLabelModel

public SmartNodeLabelModel()
Returns a new instance of SmartNodeLabelModel. The distance between label and node is set to 4.0 [pixel].

See Also:
setDistance(double)

SmartNodeLabelModel

public SmartNodeLabelModel(double distance)
Returns a new instance of SmartNodeLabelModel.

Parameters:
distance - The distance between label and node
See Also:
setDistance(double)
Method Detail

getLabelPlacement

public OrientedRectangle getLabelPlacement(YDimension labelSize,
                                           NodeLayout nodeLayout,
                                           java.lang.Object param)
Returns the the oriented label position and bounds encoded by the given model parameter.

Specified by:
getLabelPlacement in interface NodeLabelModel
Parameters:
labelSize - The size of the label
nodeLayout - The geometric description of the label's node
param - A model parameter that encodes a label position that is valid in this model
Returns:
the oriented box of the label

getLabelCandidates

public YList getLabelCandidates(NodeLabelLayout nl,
                                NodeLayout nodeLayout)
Returns a list of candidate candidates for the given node label. The candidates are eight external and nine internal candidates as they are described in the DiscreteNodeLabelModel.

Specified by:
getLabelCandidates in interface NodeLabelModel
Parameters:
nl - the label for which candidates should be generated
nodeLayout - the layout of the node to which the label belongs
Returns:
a list of NodeLabelCandidate instances

createModelParameter

public java.lang.Object createModelParameter(OrientedRectangle labelBounds,
                                             NodeLayout nodeLayout)
Creates a model parameter for a free positioned label.

Specified by:
createModelParameter in interface NodeLabelModel
Parameters:
labelBounds - The bounds of the label for which a parameter representation is sought.
nodeLayout - The layout of the node to which the label belongs.
Returns:
the model parameter
See Also:
NodeLabelModel.getLabelPlacement(YDimension, NodeLayout, Object)

getDistance

public double getDistance()
Returns the distance between the bounding boxes of label and node.

Returns:
The distance between the bounding boxes of label and node

Note: This value has no influence on how the parameter is interpreted. It only affects the placement of the candidate positions when moving the label.

See Also:
setDistance(double)

setDistance

public void setDistance(double distance)
Sets the distance between the bounding boxes of label and node in the manner of an inset. It is applied to all label candidates created in getLabelCandidates(NodeLabelLayout, NodeLayout), except the center position.

Note: This setting has no influence on how the parameter is interpreted. It only affects the placement of the candidate positions when moving the label.

Parameters:
distance - A non-negative value
See Also:
getDistance()

getDefaultParameter

public java.lang.Object getDefaultParameter()
Returns a model parameter that encodes the default position in the center of the node.

Specified by:
getDefaultParameter in interface NodeLabelModel
Returns:
the model parameter describing the default placement of the node label

createSpecificModelParameter

public java.lang.Object createSpecificModelParameter(double nodeRatioX,
                                                     double nodeRatioY,
                                                     double labelRatioX,
                                                     double labelRatioY,
                                                     double offsetX,
                                                     double offsetY,
                                                     double upX,
                                                     double upY)
Creates a model parameter where all values are specified manually.

The placement of the label consists of a relative and an absolute part. The anchor point on the label or the node respectively are specified in relative coordinates (one ratio in x-direction and one in y-direction). In order to calculate the label's position the anchor point of the node will be translated in absolute coordinates and the label's anchor will be placed on it. To be able to position the label in a fixed distance to the node's anchor point an absolute offset can be added between both anchor points.

As labels may be rotated, an up-vector has to be specified. (0, -1) is the up-vector of an unrotated label. When a label is rotated, the ratios and offsets are interpreted in relation to its paraxial bounding box.

Parameters:
nodeRatioX - The relative position of the anchor point on the node in x-direction. The values -0.5 and 0.5 are at the left and right border of the node and 0 lies in the center.
nodeRatioY - The relative position of the anchor point on the node in y-direction. The values -0.5 and 0.5 are at the top and bottom border of the node and 0 lies in the center.
labelRatioX - The relative position of the anchor point on the label in x-direction. The values -0.5 and 0.5 are at the left and right border of the label and 0 lies in the center.
labelRatioY - The relative position of the anchor point on the label in y-direction. The values -0.5 and 0.5 are at the top and bottom border of the label and 0 lies in the center.
offsetX - The absolute distance between the node anchor point and the label anchor point in x-direction.
offsetY - The absolute distance between the node anchor point and the label anchor point in y-direction.
upX - The x-coordinate of the up-vector of the label box
upY - The y-coordinate of the up-vector of the label box
Returns:
the new model parameter

createDiscreteModelParameter

public java.lang.Object createDiscreteModelParameter(int position)
Creates a model parameter for a label at a given position. Nine internal and eight external positions are available.

Parameters:
position - one of the following positions: POSITION_CENTER, POSITION_LEFT, POSITION_RIGHT, POSITION_TOP, POSITION_TOP_LEFT, POSITION_TOP_RIGHT, POSITION_BOTTOM, POSITION_BOTTOM_LEFT, POSITION_BOTTOM_RIGHT, POSITION_WEST, POSITION_EAST, POSITION_NORTH, POSITION_NORTH_WEST, POSITION_NORTH_EAST, POSITION_SOUTH, POSITION_SOUTH_WEST, and POSITION_SOUTH_EAST
Returns:
the new model parameter
See Also:
DiscreteNodeLabelModel.INTERNAL_MASK

createAlignedModelParameter

public java.lang.Object createAlignedModelParameter(OrientedRectangle labelBox,
                                                    NodeLayout nodeLayout,
                                                    int alignment)
Creates a model parameter which is aligned to the given sides of the node. The label will stay at a fixed distance to those sides.

If the given alignment does not match one of the alignment constants the parameter is created without a specific alignment as if createModelParameter(y.geom.OrientedRectangle, NodeLayout) were called.

Parameters:
labelBox - the label geometry
nodeLayout - the node geometry
alignment - one of the following alignments: ALIGNMENT_LEFT, ALIGNMENT_RIGHT, ALIGNMENT_TOP, ALIGNMENT_TOP_LEFT, ALIGNMENT_TOP_RIGHT, ALIGNMENT_BOTTOM, ALIGNMENT_BOTTOM_LEFT, and ALIGNMENT_BOTTOM_RIGHT
Returns:
the new model parameter

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