public class DiscreteNodeLabelLayoutModel extends Object implements INodeLabelLayoutModel
DiscreteNodeLabelLayoutModel
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.
Constructor and Description |
---|
DiscreteNodeLabelLayoutModel()
Creates a new instance of
DiscreteNodeLabelLayoutModel with default settings. |
DiscreteNodeLabelLayoutModel(DiscreteNodeLabelPositions candidateMask)
Creates a new instance of
DiscreteNodeLabelLayoutModel using the given candidate mask and insets. |
DiscreteNodeLabelLayoutModel(DiscreteNodeLabelPositions candidateMask,
double inset)
Creates a new instance of
DiscreteNodeLabelLayoutModel using the given candidate mask and insets. |
Modifier and Type | Method and Description |
---|---|
Object |
createModelParameter(YOrientedRectangle labelBounds,
INodeLayout nodeLayout)
Creates a model parameter that represents the given node label position within this model.
|
DiscreteNodeLabelPositions |
getCandidateMask()
Gets the candidate mask which specifies the valid positions for node labels.
|
Object |
getDefaultParameter()
Gets a model parameter that encodes the default position of this model's allowed node label positions.
|
double |
getDistance()
Gets the distance between the label's bounding box and the node.
|
YList |
getLabelCandidates(INodeLabelLayout labelLayout,
INodeLayout nodeLayout)
Returns all
NodeLabelCandidate s that describe valid label positions within this model. |
protected YOrientedRectangle |
getLabelPlacement(YDimension labelSize,
INodeLayout nodeLayout,
DiscreteNodeLabelPositions position)
Returns the oriented box of the label for the given label position.
|
YOrientedRectangle |
getLabelPlacement(YDimension labelSize,
INodeLayout nodeLayout,
Object parameter)
Returns the bounds of the label for the position encoded by the given model parameter.
|
boolean |
isParameterValid(Object parameter)
Checks whether or not the given model parameter encodes a valid node label position for this model.
|
void |
setDistance(double value)
Sets the distance between the label's bounding box and the node.
|
public DiscreteNodeLabelLayoutModel()
DiscreteNodeLabelLayoutModel
with default settings.public DiscreteNodeLabelLayoutModel(DiscreteNodeLabelPositions candidateMask)
DiscreteNodeLabelLayoutModel
using the given candidate mask and insets.
The specified mask can also describe a single position.
candidateMask
- the position mask that defines the allowed positions for a node labelpublic DiscreteNodeLabelLayoutModel(DiscreteNodeLabelPositions candidateMask, double inset)
DiscreteNodeLabelLayoutModel
using the given candidate mask and insets.
The specified mask can also describe a single position.
candidateMask
- the position mask that defines the allowed positions for a node labelinset
- the inset value that defines the internal label distance to the node's borderpublic Object createModelParameter(YOrientedRectangle labelBounds, INodeLayout nodeLayout)
INodeLabelLayoutModel
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 INodeLabelLayoutModel.getLabelPlacement(YDimension, INodeLayout, 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 INodeLabelLayoutModel
.
createModelParameter
in interface INodeLabelLayoutModel
labelBounds
- the box of the label, encoding the label location for which the parameter should be creatednodeLayout
- the layout of the node to which the label belongsINodeLabelLayoutModel.getLabelPlacement(YDimension, INodeLayout, Object)
public DiscreteNodeLabelPositions getCandidateMask()
DiscreteNodeLabelPositions.INTERNAL_MASK
public Object getDefaultParameter()
Default positions are (in descending order):
DiscreteNodeLabelPositions.CENTER
DiscreteNodeLabelPositions.NORTH_EAST
DiscreteNodeLabelPositions.NORTH
DiscreteNodeLabelPositions.EAST
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.
getDefaultParameter
in interface INodeLabelLayoutModel
DiscreteNodeLabelPositions.CENTER
when none of the above default positions is part
of the allowed positions.public double getDistance()
The distance must be a non-negative value.
setDistance(double)
public YList getLabelCandidates(INodeLabelLayout labelLayout, INodeLayout nodeLayout)
INodeLabelLayoutModel
NodeLabelCandidate
s that describe valid label positions within this model.
In case the implementing INodeLabelLayoutModel
allows every possible location, this method always returns the
current location as a LabelCandidate
.
getLabelCandidates
in interface INodeLabelLayoutModel
labelLayout
- the label for which candidates should be generatednodeLayout
- the layout of the node to which the label belongsNodeLabelCandidate
instancesprotected YOrientedRectangle getLabelPlacement(YDimension labelSize, INodeLayout nodeLayout, DiscreteNodeLabelPositions position)
This method is called by getLabelPlacement(YDimension, INodeLayout, Object)
and getLabelCandidates(INodeLabelLayout, INodeLayout)
to retrieve a valid position.
labelSize
- the size of the label that should be placednodeLayout
- the layout of the node to which the label belongsposition
- the label position that is valid in this modelpublic YOrientedRectangle getLabelPlacement(YDimension labelSize, INodeLayout nodeLayout, Object parameter)
INodeLabelLayoutModel
getLabelPlacement
in interface INodeLabelLayoutModel
labelSize
- the width and height of the labelnodeLayout
- the layout of the node to which the label belongsparameter
- the model parameter that describes the abstract position of the label within this modelpublic boolean isParameterValid(Object parameter)
If the model parameter describes a position that is accepted by the candidate mask, this is a valid parameter.
parameter
- the model parametertrue
if the label position described by the given model parameter is allowed, false
otherwisepublic void setDistance(double value)
The distance must be a non-negative value.
value
- the distance between the node and the associated labelgetDistance()