public class AspectRatioNodePlacer extends AbstractNodePlacer implements IFromSketchNodePlacer
INodePlacer
places the subtrees such that the overall aspect ratio of the arranged subtree will be close to
a preferred aspect ratio.
INodePlacer
divides the child TreeLayout.SubtreeShape
s into as much rows as
needed. The edges are either routed along the rows or along the columns.
Aspect ratio 1
Aspect ratio 0.5
Aspect ratio 2
graph
Constructor and Description |
---|
AspectRatioNodePlacer()
Creates a new instance of
AspectRatioNodePlacer with default settings. |
Modifier and Type | Method and Description |
---|---|
Comparator<Object> |
createFromSketchComparator()
Creates an
edge comparator which takes the initial coordinates of the nodes into account. |
protected ParentConnectorDirection |
determineChildConnector(Node child)
Determines a connector direction for the given child node depending on whether or not the child nodes are arranged
horizontally . |
double |
getAspectRatio()
Gets the preferred aspect ratio (width/height) for the subtrees.
|
FillStyle |
getFillStyle()
Gets how rows/columns are aligned with each other.
|
double |
getHorizontalDistance()
Gets the horizontal distance between the
TreeLayout.SubtreeShape s. |
double |
getVerticalDistance()
Gets the vertical distance between the
TreeLayout.SubtreeShape s. |
boolean |
isHorizontal()
Gets whether child nodes are distributed in horizontal rows or vertical columns.
|
protected TreeLayout.SubtreeShape |
placeSubtree(Node localRoot,
ParentConnectorDirection parentConnectorDirection)
Arranges the
SubtreeShapes of children of the local root node in rows or columns that
fit the specified aspect ratio . |
void |
setAspectRatio(double value)
Sets the preferred aspect ratio (width/height) for the subtrees.
|
void |
setFillStyle(FillStyle value)
Sets how rows/columns are aligned with each other.
|
void |
setHorizontal(boolean value)
Sets whether child nodes are distributed in horizontal rows or vertical columns.
|
void |
setHorizontalDistance(double value)
Sets the horizontal distance between the
TreeLayout.SubtreeShape s. |
void |
setVerticalDistance(double value)
Sets the vertical distance between the
TreeLayout.SubtreeShape s. |
clone, createProcessor, determineChildConnectors, getNodeShape, getSubtreeShape, placeSubtree
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createProcessor, determineChildConnectors, placeSubtree
public AspectRatioNodePlacer()
AspectRatioNodePlacer
with default settings.public Comparator<Object> createFromSketchComparator()
edge comparator
which takes the initial coordinates of the nodes into account.
This Comparator
defines the order of the outgoing edges of a node before the actual placement of the node's
subtree is calculated. It also considers whether or not the rows are placed horiontally
.
createFromSketchComparator
in interface IFromSketchNodePlacer
Comparator
for the edgesprotected ParentConnectorDirection determineChildConnector(Node child)
horizontally
.
If the child nodes are distributed horizontally, the edge should connect north
,
otherwise it should connect west
.
determineChildConnector
in class AbstractNodePlacer
child
- the child nodeParentConnectorDirection.NORTH
if nodes are placed in rows, ParentConnectorDirection.WEST
otherwisepublic double getAspectRatio()
This ratio determines among how many rows/columns the nodes will be distributed.
The aspect ratio needs to be positive.
IllegalArgumentException
- if the specified aspect ratio is 0
or negativesetAspectRatio(double)
public FillStyle getFillStyle()
IllegalArgumentException
- if an unknown fill style is specifiedFillStyle.LEADING
setFillStyle(FillStyle)
public double getHorizontalDistance()
TreeLayout.SubtreeShape
s.
The nodes will be placed next to each other, keeping this distance.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativesetHorizontalDistance(double)
public double getVerticalDistance()
TreeLayout.SubtreeShape
s.
The nodes will be placed below each other, keeping this distance.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativesetVerticalDistance(double)
public boolean isHorizontal()
false
. The child nodes are placed in vertical columns.true
for horizontal rows, false
for vertical columnssetHorizontal(boolean)
protected TreeLayout.SubtreeShape placeSubtree(Node localRoot, ParentConnectorDirection parentConnectorDirection)
SubtreeShapes
of children of the local root node in rows or columns that
fit the specified aspect ratio
.placeSubtree
in class AbstractNodePlacer
localRoot
- the local root nodeparentConnectorDirection
- the direction of the connectorTreeLayout.SubtreeShape
containing the local root and all its subtreespublic void setAspectRatio(double value)
This ratio determines among how many rows/columns the nodes will be distributed.
The aspect ratio needs to be positive.
IllegalArgumentException
- if the specified aspect ratio is 0
or negativevalue
- the preferred ratio between width and heightgetAspectRatio()
public void setFillStyle(FillStyle value)
IllegalArgumentException
- if an unknown fill style is specifiedFillStyle.LEADING
value
- one of the predefined fill stylesgetFillStyle()
public void setHorizontal(boolean value)
false
. The child nodes are placed in vertical columns.value
- true
for horizontal rows, false
for vertical columnsisHorizontal()
public void setHorizontalDistance(double value)
TreeLayout.SubtreeShape
s.
The nodes will be placed next to each other, keeping this distance.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativevalue
- the horizontal distance between elementsgetHorizontalDistance()
public void setVerticalDistance(double value)
TreeLayout.SubtreeShape
s.
The nodes will be placed below each other, keeping this distance.
The distance needs to be non-negative.
IllegalArgumentException
- if the specified distance is negativevalue
- the vertical distance between elementsgetVerticalDistance()