Class TreeLayout<TreeNode>
- java.lang.Object
-
- org.abego.treelayout.TreeLayout<TreeNode>
-
- Type Parameters:
TreeNode
- Type of elements used as nodes in the tree
public class TreeLayout<TreeNode> extends Object
Implements the actual tree layout algorithm.The nodes with their final layout can be retrieved through
See this summary to get an overview how to use TreeLayout.getNodeBounds()
.- Author:
- Udo Borkowski (ub@abego.org)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TreeLayout.DumpConfiguration
-
Constructor Summary
Constructors Constructor Description TreeLayout(TreeForTreeLayout<TreeNode> tree, NodeExtentProvider<TreeNode> nodeExtentProvider, Configuration<TreeNode> configuration)
TreeLayout(TreeForTreeLayout<TreeNode> tree, NodeExtentProvider<TreeNode> nodeExtentProvider, Configuration<TreeNode> configuration, boolean useIdentity)
Creates a TreeLayout for a given tree.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkTree()
Check if the tree is a "valid" tree.void
dumpTree(PrintStream printStream)
void
dumpTree(PrintStream printStream, TreeLayout.DumpConfiguration dumpConfiguration)
Prints a dump of the tree to the given printStream, using the node's "toString" method.Rectangle2D
getBounds()
Returns the bounds of the tree layout.Configuration<TreeNode>
getConfiguration()
Returns the Configuration used by thisTreeLayout
.int
getLevelCount()
Returns the number of levels of the tree.Map<TreeNode,Rectangle2D.Double>
getNodeBounds()
Returns the layout of the tree nodes by mapping each node of the tree to its bounds (position and size).NodeExtentProvider<TreeNode>
getNodeExtentProvider()
Returns theNodeExtentProvider
used by thisTreeLayout
.double
getSizeOfLevel(int level)
Returns the size of a level.TreeForTreeLayout<TreeNode>
getTree()
Returns the Tree the layout is created for.
-
-
-
Constructor Detail
-
TreeLayout
public TreeLayout(TreeForTreeLayout<TreeNode> tree, NodeExtentProvider<TreeNode> nodeExtentProvider, Configuration<TreeNode> configuration, boolean useIdentity)
Creates a TreeLayout for a given tree.In addition to the tree the
NodeExtentProvider
and theConfiguration
must be given.- Parameters:
tree
-nodeExtentProvider
-configuration
-useIdentity
- [default: false] when true, identity ("==") is used instead of equality ("equals(...)") when checking nodes. Within a tree each node must only exist once (using this check).
-
TreeLayout
public TreeLayout(TreeForTreeLayout<TreeNode> tree, NodeExtentProvider<TreeNode> nodeExtentProvider, Configuration<TreeNode> configuration)
-
-
Method Detail
-
getTree
public TreeForTreeLayout<TreeNode> getTree()
Returns the Tree the layout is created for.- Returns:
- the Tree the layout is created for
-
getNodeExtentProvider
public NodeExtentProvider<TreeNode> getNodeExtentProvider()
Returns theNodeExtentProvider
used by thisTreeLayout
.- Returns:
- the
NodeExtentProvider
used by thisTreeLayout
-
getConfiguration
public Configuration<TreeNode> getConfiguration()
Returns the Configuration used by thisTreeLayout
.- Returns:
- the Configuration used by this
TreeLayout
-
getBounds
public Rectangle2D getBounds()
Returns the bounds of the tree layout.The bounds of a TreeLayout is the smallest rectangle containing the bounds of all nodes in the layout. It always starts at (0,0).
- Returns:
- the bounds of the tree layout
-
getLevelCount
public int getLevelCount()
Returns the number of levels of the tree.- Returns:
- [level > 0]
-
getSizeOfLevel
public double getSizeOfLevel(int level)
Returns the size of a level.When the root is located at the top or bottom the size of a level is the maximal height of the nodes of that level. When the root is located at the left or right the size of a level is the maximal width of the nodes of that level.
- Parameters:
level
-- Returns:
- the size of the level [level >= 0 && level < levelCount]
-
getNodeBounds
public Map<TreeNode,Rectangle2D.Double> getNodeBounds()
Returns the layout of the tree nodes by mapping each node of the tree to its bounds (position and size).For each rectangle x and y will be >= 0. At least one rectangle will have an x == 0 and at least one rectangle will have an y == 0.
- Returns:
- maps each node of the tree to its bounds (position and size).
-
checkTree
public void checkTree()
Check if the tree is a "valid" tree.Typically you will use this method during development when you get an unexpected layout from your trees.
The following checks are performed:
- Each node must only occur once in the tree.
-
dumpTree
public void dumpTree(PrintStream printStream, TreeLayout.DumpConfiguration dumpConfiguration)
Prints a dump of the tree to the given printStream, using the node's "toString" method.- Parameters:
printStream
-dumpConfiguration
- [default: new DumpConfiguration()]
-
dumpTree
public void dumpTree(PrintStream printStream)
-
-