Search this API

y.layout
Class DiscreteNodeLabelModel

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

public class DiscreteNodeLabelModel
extends java.lang.Object
implements NodeLabelModel

DiscreteNodeLabelModel allows placing labels at eight positions around a node and at nine positions inside the node.


The predefined positions in this model

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

 

Field Summary
static int BOTTOM
          Position specifier that describes a label placement at the bottom inside the node.
static int BOTTOM_LEFT
          Position specifier that describes a label placement at the bottom-left inside the node.
static int BOTTOM_RIGHT
          Position specifier that describes a label placement at the bottom-right inside the node.
static int CENTER
          Position specifier that describes a label placement at the center of the node.
static int CORNER_MASK
          Position mask that constrains the positions to the corners outside the node.
static int EAST
          Position specifier that describes a label placement east of the node.
static int EIGHT_POS_MASK
          Position mask that constraints the positions to the eight node-external positions.
static int INTERNAL_MASK
          Position mask that constrains the positions to the nine node-internal positions.
static int LEFT
          Position specifier that describes a label placement at the left inside the node.
static int NORTH
          Position specifier that describes a label placement north of the node.
static int NORTH_EAST
          Position specifier that describes a label placement north-east of the node.
static int NORTH_WEST
          Position specifier that describes a label placement north-west of the node.
static int RIGHT
          Position specifier that describes a label placement at the right inside the node.
static int SANDWICH_MASK
          Position mask that constrains the positions to above and below the node.
static int SIDES_MASK
          Position mask that constrains the positions to the node's four sides.
static int SOUTH
          Position specifier that describes a label placement south of the node.
static int SOUTH_EAST
          Position specifier that describes a label placement south-east of the node.
static int SOUTH_WEST
          Position specifier that describes a label placement south-west of the node.
static int TOP
          Position specifier that describes a label placement at the top inside the node.
static int TOP_LEFT
          Position specifier that describes a label placement at the top-left inside the node.
static int TOP_RIGHT
          Position specifier that describes a label placement at the top-right inside the node.
static int WEST
          Position specifier that describes a label placement west of the node.
 
Constructor Summary
DiscreteNodeLabelModel()
          Creates a new instance of DiscreteNodeLabelModel with default settings.
DiscreteNodeLabelModel(int candidateMask)
          Creates a new instance of DiscreteNodeLabelModel using the given candidate mask.
DiscreteNodeLabelModel(int candidateMask, double inset)
          Creates a new instance of DiscreteNodeLabelModel using the given candidate mask and insets.
 
Method Summary
 java.lang.Object createModelParameter(OrientedRectangle labelBounds, NodeLayout nodeLayout)
          Creates a model parameter that represents the given node label position within this model.
 int getCandidateMask()
          Returns the candidate mask which specifies the valid positions for node labels.
 java.lang.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 label's bounding box and the node.
 YList getLabelCandidates(NodeLabelLayout labelLayout, NodeLayout nodeLayout)
          Returns all NodeLabelCandidates that describe valid label positions within this model.
protected  OrientedRectangle getLabelPlacement(YDimension labelSize, NodeLayout nodeLayout, int position)
          Returns the oriented box of the label for the given label position.
 OrientedRectangle getLabelPlacement(YDimension labelSize, NodeLayout nodeLayout, java.lang.Object parameter)
          Returns the bounds 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 node label position for this model.
 void setDistance(double distance)
          Specifies the distance between the label's bounding box and the node.
 
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
Position specifier that describes a label placement north of the node.

 
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 north position

NORTH_WEST

public static final int NORTH_WEST
Position specifier that describes a label placement north-west of the node.

 
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 north-west position

NORTH_EAST

public static final int NORTH_EAST
Position specifier that describes a label placement north-east of the node.

 
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 north-east position

EAST

public static final int EAST
Position specifier that describes a label placement east of the node.

 
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 east position

WEST

public static final int WEST
Position specifier that describes a label placement west of the node.

 
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 west position

SOUTH

public static final int SOUTH
Position specifier that describes a label placement south of the node.

 
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 south position

SOUTH_WEST

public static final int SOUTH_WEST
Position specifier that describes a label placement south-west of the node.

 
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 south-west position

SOUTH_EAST

public static final int SOUTH_EAST
Position specifier that describes a label placement south-east of the node.

 
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 south-east position

CENTER

public static final int CENTER
Position specifier that describes a label placement at the center of the node.

 
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

BOTTOM

public static final int BOTTOM
Position specifier that describes a label placement at the bottom inside the node.

 
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 bottom position

TOP

public static final int TOP
Position specifier that describes a label placement at the top inside the node.

 
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 top position

LEFT

public static final int LEFT
Position specifier that describes a label placement at the left inside the node.

 
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 left position

RIGHT

public static final int RIGHT
Position specifier that describes a label placement at the right inside the node.

 
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 right position

TOP_LEFT

public static final int TOP_LEFT
Position specifier that describes a label placement at the top-left inside the node.

 
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 top-left position

TOP_RIGHT

public static final int TOP_RIGHT
Position specifier that describes a label placement at the top-right inside the node.

 
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 top-right position

BOTTOM_LEFT

public static final int BOTTOM_LEFT
Position specifier that describes a label placement at the bottom-left inside the node.

 
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 bottom-left position

BOTTOM_RIGHT

public static final int BOTTOM_RIGHT
Position specifier that describes a label placement at the bottom-right inside the node.

 
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 bottom-right position

SANDWICH_MASK

public static final int SANDWICH_MASK
Position mask that constrains the positions to above and below the node.

See Also:
NORTH, SOUTH, Constant Field Values
Sample Graph:

The positions above and below the node are valid

INTERNAL_MASK

public static final int INTERNAL_MASK
Position mask that constrains the positions to the nine node-internal positions.

See Also:
CENTER, TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, Constant Field Values
Sample Graph:

All positions inside the node are valid

SIDES_MASK

public static final int SIDES_MASK
Position mask that constrains the positions to the node's four sides.

See Also:
EAST, WEST, NORTH, SOUTH, Constant Field Values
Sample Graph:

Only positions on the sides are valid

CORNER_MASK

public static final int CORNER_MASK
Position mask that constrains the positions to the corners outside the node.

See Also:
NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST, Constant Field Values
Sample Graph:

Label positions at the corners of the node are valid

EIGHT_POS_MASK

public static final int EIGHT_POS_MASK
Position mask that constraints the positions to the eight node-external positions.

See Also:
NORTH, EAST, SOUTH, WEST, NORTH_EAST, NORTH_WEST, SOUTH_EAST, SOUTH_WEST, Constant Field Values
Sample Graph:

Positions outside the node are valid
Constructor Detail

DiscreteNodeLabelModel

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


DiscreteNodeLabelModel

public DiscreteNodeLabelModel(int candidateMask)
Creates a new instance of DiscreteNodeLabelModel 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 a node label

DiscreteNodeLabelModel

public DiscreteNodeLabelModel(int candidateMask,
                              double inset)
Creates a new instance of DiscreteNodeLabelModel using the given candidate mask and insets.

The specified mask can also describe a single position.

Parameters:
candidateMask - the position mask that defines the allowed positions for a node label
inset - the inset value that defines the internal label distance to the node's border
Method Detail

getCandidateMask

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

Default Value:
The default value is INTERNAL_MASK
Returns:
the position mask that defines the allowed positions for a node label

getDistance

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

The distance must be a non-negative value.

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

setDistance

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

The distance must be a non-negative value.

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

4

10

getDefaultParameter

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

Specified by:
getDefaultParameter in interface NodeLabelModel
 
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 node label

isParameterValid

public boolean isParameterValid(java.lang.Object parameter)
Checks whether or not the given model parameter encodes a valid node 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,
                                           NodeLayout nodeLayout,
                                           java.lang.Object parameter)
Description copied from interface: NodeLabelModel
Returns the bounds of the label for the position encoded by the given model parameter.

Specified by:
getLabelPlacement in interface NodeLabelModel
Parameters:
labelSize - the width and height of the label
nodeLayout - the layout of the node to which the label belongs
parameter - the model parameter that describes the abstract position of the label within this model
Returns:
the oriented box of the label

getLabelCandidates

public YList getLabelCandidates(NodeLabelLayout labelLayout,
                                NodeLayout nodeLayout)
Description copied from interface: NodeLabelModel
Returns all NodeLabelCandidates that describe valid label positions within this model.

In case the implementing NodeLabelModel allows every possible location, this method always returns the current location as a LabelCandidate.

Specified by:
getLabelCandidates in interface NodeLabelModel
Parameters:
labelLayout - 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

getLabelPlacement

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

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

Parameters:
labelSize - the size of the label that should be placed
nodeLayout - the layout of the node to which the label belongs
position - the label position that is valid in this model
Returns:
the oriented box of the label

createModelParameter

public java.lang.Object createModelParameter(OrientedRectangle labelBounds,
                                             NodeLayout nodeLayout)
Description copied from interface: NodeLabelModel
Creates a model parameter that represents the given node 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 NodeLabelModel.getLabelPlacement(YDimension, 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 NodeLabelModel.

Specified by:
createModelParameter in interface NodeLabelModel
Parameters:
labelBounds - the box of the label, encoding the label location for which the parameter should be created
nodeLayout - the layout of the node to which the label belongs
Returns:
the model parameter representing the given label location
See Also:
NodeLabelModel.getLabelPlacement(YDimension, NodeLayout, Object)

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