Search this API

y.layout
Class DiscreteNodeLabelModel

java.lang.Object
  extended by y.layout.DiscreteNodeLabelModel
All Implemented Interfaces:
NodeLabelModel

public class DiscreteNodeLabelModel
extends Object
implements NodeLabelModel

A node label model that allows placement of labels at eight positions around a node and at nine positions inside the node.

It's possible to specify an insets value that controls the distance between label and node.
Furthermore, there's the possibility to mask out arbitrary node label candidates. This can either be done by specifying predefined candidate masks or by OR-ing allowed node label candidates to a user defined mask.


Field Summary
static int BOTTOM
          Symbolic position specifier.
static int BOTTOM_LEFT
          Symbolic position specifier.
static int BOTTOM_RIGHT
          Symbolic position specifier.
static int CENTER
          Symbolic position specifier.
static int CORNER_MASK
          Position mask that constrains the positions to NORTH_EAST, NORTH_WEST, SOUTH_EAST, and SOUTH_WEST.
static int EAST
          Symbolic position specifier.
static int EIGHT_POS_MASK
          Position mask that allows only the eight node-external positions.
static int INTERNAL_MASK
          Position mask that allows only the nine node-internal positions.
static int LEFT
          Symbolic position specifier.
static int NORTH
          Symbolic position specifier.
static int NORTH_EAST
          Symbolic position specifier.
static int NORTH_WEST
          Symbolic position specifier.
static int RIGHT
          Symbolic position specifier.
static int SANDWICH_MASK
          Position mask that constrains the positions to NORTH and SOUTH.
static int SIDES_MASK
          Position mask that constrains the positions to EAST, WEST, NORTH, and SOUTH.
static int SOUTH
          Symbolic position specifier.
static int SOUTH_EAST
          Symbolic position specifier.
static int SOUTH_WEST
          Symbolic position specifier.
static int TOP
          Symbolic position specifier.
static int TOP_LEFT
          Symbolic position specifier.
static int TOP_RIGHT
          Symbolic position specifier.
static int WEST
          Symbolic position specifier.
 
Constructor Summary
DiscreteNodeLabelModel()
          Returns a new instance of DiscreteNodeLabelModel.
DiscreteNodeLabelModel(int candidateMask)
          Returns a new instance of DiscreteNodeLabelModel.
DiscreteNodeLabelModel(int candidateMask, double inset)
          Returns a new instance of DiscreteNodeLabelModel.
 
Method Summary
 Object createModelParameter(OrientedRectangle labelBounds, NodeLayout nodeLayout)
          Creates a model parameter that represents the given node label context best within this model.
 int getCandidateMask()
          Allowed candidate positions, default is all positions.
 Object getDefaultParameter()
          Returns a model parameter that encodes the default position of this model's allowed node label positions.
 double getDistance()
          Returns the distance between the bounding boxes of label and node.
 YList getLabelCandidates(NodeLabelLayout nl, NodeLayout nodeLayout)
          Returns a list of candidate positions for the given node label.
protected  OrientedRectangle getLabelPlacement(YDimension labelSize, NodeLayout nodeLayout, int pos)
          Returns the oriented label position and bounds for a node label of the specified size.
 OrientedRectangle getLabelPlacement(YDimension labelSize, NodeLayout nodeLayout, Object param)
          Returns the the oriented label position and bounds encoded by the given model parameter.
 boolean isParameterValid(Object parameter)
          Checks if the given model parameter encodes a node label position that is valid in this model.
 void setDistance(double distance)
          Sets the distance between the bounding boxes of label and node in the manner of an insets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
Symbolic position specifier. Places the label north of the node.

See Also:
Constant Field Values

NORTH_WEST

public static final int NORTH_WEST
Symbolic position specifier. Places the label north-west of the node.

See Also:
Constant Field Values

NORTH_EAST

public static final int NORTH_EAST
Symbolic position specifier. Places the label north-east of the node.

See Also:
Constant Field Values

EAST

public static final int EAST
Symbolic position specifier. Places the label east of the node.

See Also:
Constant Field Values

WEST

public static final int WEST
Symbolic position specifier. Places the label west of the node.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Symbolic position specifier. Places the label south of the node.

See Also:
Constant Field Values

SOUTH_WEST

public static final int SOUTH_WEST
Symbolic position specifier. Places the label south-west of the node.

See Also:
Constant Field Values

SOUTH_EAST

public static final int SOUTH_EAST
Symbolic position specifier. Places the label south-east of the node.

See Also:
Constant Field Values

CENTER

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

See Also:
Constant Field Values

BOTTOM

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

See Also:
Constant Field Values

TOP

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

See Also:
Constant Field Values

LEFT

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

See Also:
Constant Field Values

RIGHT

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

See Also:
Constant Field Values

TOP_LEFT

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

See Also:
Constant Field Values

TOP_RIGHT

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

See Also:
Constant Field Values

BOTTOM_LEFT

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

See Also:
Constant Field Values

BOTTOM_RIGHT

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

See Also:
Constant Field Values

SANDWICH_MASK

public static final int SANDWICH_MASK
Position mask that constrains the positions to NORTH and SOUTH.

See Also:
Constant Field Values

INTERNAL_MASK

public static final int INTERNAL_MASK
Position mask that allows only the nine node-internal positions.

See Also:
Constant Field Values

SIDES_MASK

public static final int SIDES_MASK
Position mask that constrains the positions to EAST, WEST, NORTH, and SOUTH.

See Also:
Constant Field Values

CORNER_MASK

public static final int CORNER_MASK
Position mask that constrains the positions to NORTH_EAST, NORTH_WEST, SOUTH_EAST, and SOUTH_WEST.

See Also:
Constant Field Values

EIGHT_POS_MASK

public static final int EIGHT_POS_MASK
Position mask that allows only the eight node-external positions.

See Also:
Constant Field Values
Constructor Detail

DiscreteNodeLabelModel

public DiscreteNodeLabelModel()
Returns a new instance of DiscreteNodeLabelModel. INTERNAL_MASK is used to define the allowed positions for the node label. The distance between label and node is set to 4.0 [pixel].

See Also:
setDistance(double)

DiscreteNodeLabelModel

public DiscreteNodeLabelModel(int candidateMask)
Returns a new instance of DiscreteNodeLabelModel. The given position mask is used to define the allowed positions for the node label. The distance between label and node is set to 4.0 [pixel].

Parameters:
candidateMask - Defines the allowed positions for the node label.
See Also:
setDistance(double)

DiscreteNodeLabelModel

public DiscreteNodeLabelModel(int candidateMask,
                              double inset)
Returns a new instance of DiscreteNodeLabelModel.

Parameters:
candidateMask - Defines the allowed positions for the node label.
inset - The distance between label and node.
See Also:
setDistance(double)
Method Detail

getCandidateMask

public int getCandidateMask()
Allowed candidate positions, default is all positions.


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.
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 insets. It is applied to all label positions, except the CENTER position.

Parameters:
distance - A non-negative value.

getDefaultParameter

public Object getDefaultParameter()
Returns a model parameter that encodes the default position of this model's allowed node 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 NodeLabelModel
Returns:
A model parameter that can be passed to the NodeLabelModel.getLabelPlacement(YDimension, NodeLayout, Object) method.

isParameterValid

public boolean isParameterValid(Object parameter)
Checks if the given model parameter encodes a node 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,
                                           NodeLayout nodeLayout,
                                           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 label position and bounds.

getLabelCandidates

public YList getLabelCandidates(NodeLabelLayout nl,
                                NodeLayout nodeLayout)
Returns a list of candidate positions for the given node label.

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

getLabelPlacement

protected OrientedRectangle getLabelPlacement(YDimension labelSize,
                                              NodeLayout nodeLayout,
                                              int pos)
Returns the oriented label position and bounds for a node label of the specified size.

Parameters:
labelSize - The size of the label.
nodeLayout - The geometric description of the label's node.
pos - A label position that is valid in this model.
Returns:
the oriented label position and bounds.

createModelParameter

public Object createModelParameter(OrientedRectangle labelBounds,
                                   NodeLayout nodeLayout)
Description copied from interface: NodeLabelModel
Creates a model parameter that represents the given node label context best within this model. The created model parameter represents the closest parameter representation of the given oriented label bounds that can be achieved within this model.

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

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