Class TreeLayoutAlgorithm<V>
- java.lang.Object
 - 
- org.jungrapht.visualization.layout.algorithms.AbstractLayoutAlgorithm<V>
 - 
- org.jungrapht.visualization.layout.algorithms.AbstractTreeLayoutAlgorithm<V>
 - 
- org.jungrapht.visualization.layout.algorithms.TreeLayoutAlgorithm<V>
 
 
 
 
- 
- Type Parameters:
 V- vertex type
- All Implemented Interfaces:
 Consumer<Function<V,Rectangle>>,LayoutAlgorithm<V>,TreeLayout<V>,AfterRunnable,VertexBoundsFunctionConsumer<V>
- Direct Known Subclasses:
 BalloonLayoutAlgorithm,EdgeAwareTreeLayoutAlgorithm,MultiRowTreeLayoutAlgorithm,RadialTreeLayoutAlgorithm
public class TreeLayoutAlgorithm<V> extends AbstractTreeLayoutAlgorithm<V> implements LayoutAlgorithm<V>, TreeLayout<V>
A simple tree layout algorithm that will allow multiple roots. Will also layouy any directed graph for which a root or roots can be discerned. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTreeLayoutAlgorithm.Builder<V,T extends TreeLayoutAlgorithm<V>,B extends TreeLayoutAlgorithm.Builder<V,T,B>>ABuilderto create instances ofTreeLayoutAlgorithm- 
Nested classes/interfaces inherited from interface org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm
LayoutAlgorithm.NoOp<V> 
 - 
 
- 
Field Summary
- 
Fields inherited from class org.jungrapht.visualization.layout.algorithms.AbstractTreeLayoutAlgorithm
baseBounds, correctOverlap, defaultRootPredicate, expandLayout, horizontalVertexSpacing, neighborCache, rootComparator, rootPredicate, vertexBoundsFunction, verticalVertexSpacing, visitedVertices 
- 
Fields inherited from class org.jungrapht.visualization.layout.algorithms.AbstractLayoutAlgorithm
after 
- 
Fields inherited from interface org.jungrapht.visualization.layout.algorithms.TreeLayout
TREE_LAYOUT_HORIZONTAL_SPACING, TREE_LAYOUT_VERTICAL_SPACING 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description TreeLayoutAlgorithm()protectedTreeLayoutAlgorithm(TreeLayoutAlgorithm.Builder<V,?,?> builder)Create aTreeLayoutAlgorithminstance with the passedBuilder 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <V> TreeLayoutAlgorithm.Builder<V,?,?>builder()protected Set<V>buildTree(LayoutModel<V> layoutModel)protected voidbuildTree(LayoutModel<V> layoutModel, V vertex, int x, int y, Set<V> seen)Place the passed vertex and descend into the child vertices, recursively placing each child vertexprotected intcalculateHeight(LayoutModel<V> layoutModel, Collection<V> roots, Set<V> seen)Calculate the height of the forest as the max height of all of its subtreesprotected intcalculateHeight(LayoutModel<V> layoutModel, V vertex, Set<V> seen)Calculate the height of the subtree under the passed vertexprotected intcalculateWidth(LayoutModel<V> layoutModel, Collection<V> roots, Set<V> seen)Calculate the width of the forest as the sum of the width of each tree (plus offsets)protected intcalculateWidth(LayoutModel<V> layoutModel, V vertex, Set<V> seen)calculate the width of the subtree descended from the passed vertexbooleanconstrained()Map<V,Rectangle>getBaseBounds()PointgetCenter(LayoutModel<V> layoutModel)protected intgetInitialPosition(int initialPosition, int layoutSpan, int treeSpan)static <V,E>
org.jgrapht.Graph<V,E>getSpanningTree(org.jgrapht.Graph<V,E> graph)protected voidmerge(LayoutModel<V> layoutModel, V vertex)update the baseBounds Map value for the passed vertex, with the (x,y) position of this vertexvoidvisit(LayoutModel<V> layoutModel)visit aLayoutModelto set all of the graph vertex positions according to the LayoutAlgorithm logic.- 
Methods inherited from class org.jungrapht.visualization.layout.algorithms.AbstractTreeLayoutAlgorithm
adjustToFill, expandToFill, moveVerticesThatOverlapVerticalEdges, setRootComparator, setRootPredicate, setVertexBoundsFunction 
- 
Methods inherited from class org.jungrapht.visualization.layout.algorithms.AbstractLayoutAlgorithm
computeAverageVertexDimension, computeLayoutExtent, expandToFill, runAfter, setAfter 
- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface org.jungrapht.visualization.layout.algorithms.util.AfterRunnable
runAfter, setAfter 
- 
Methods inherited from interface org.jungrapht.visualization.layout.algorithms.LayoutAlgorithm
cancel 
- 
Methods inherited from interface org.jungrapht.visualization.layout.algorithms.TreeLayout
setRootComparator, setRootPredicate 
- 
Methods inherited from interface org.jungrapht.visualization.layout.algorithms.util.VertexBoundsFunctionConsumer
accept, setVertexBoundsFunction 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
TreeLayoutAlgorithm
public TreeLayoutAlgorithm()
 
- 
TreeLayoutAlgorithm
protected TreeLayoutAlgorithm(TreeLayoutAlgorithm.Builder<V,?,?> builder)
Create aTreeLayoutAlgorithminstance with the passedBuilder- Parameters:
 builder- theBuilderwith configuration properties
 
 - 
 
- 
Method Detail
- 
builder
public static <V> TreeLayoutAlgorithm.Builder<V,?,?> builder()
- Type Parameters:
 V- the vertex type- Returns:
 - a 
Builderready to configure 
 
- 
visit
public void visit(LayoutModel<V> layoutModel)
visit aLayoutModelto set all of the graph vertex positions according to the LayoutAlgorithm logic.- Specified by:
 visitin interfaceLayoutAlgorithm<V>- Overrides:
 visitin classAbstractTreeLayoutAlgorithm<V>- Parameters:
 layoutModel- the mediator between the container for vertices (the Graph) and the mapping
 
- 
getBaseBounds
public Map<V,Rectangle> getBaseBounds()
- Specified by:
 getBaseBoundsin interfaceTreeLayout<V>- Overrides:
 getBaseBoundsin classAbstractTreeLayoutAlgorithm<V>- Returns:
 - the 
Mapof vertex toRectanglethat will hold all of the subtree rooted at the vertex 
 
- 
buildTree
protected Set<V> buildTree(LayoutModel<V> layoutModel)
- Parameters:
 layoutModel- the model to hold vertex positions- Returns:
 - the roots vertices of the tree
 
 
- 
getInitialPosition
protected int getInitialPosition(int initialPosition, int layoutSpan, int treeSpan)- Parameters:
 initialPosition- default initial position for when the layoutSpan is greater than the tree spanlayoutSpan- the dimension (width or height) of the layouttreeSpan- the dimension (width or height) of the current subtree- Returns:
 - the average of the layoutSpan and treeSpan or the passed initial position
 
 
- 
buildTree
protected void buildTree(LayoutModel<V> layoutModel, V vertex, int x, int y, Set<V> seen)
Place the passed vertex and descend into the child vertices, recursively placing each child vertex- Parameters:
 layoutModel- theLayoutModelto hold the vertex positionsvertex- the vertex to place in positionx- the x positiony- the y positionseen- a set of vertices that were already 'seen' (and placed in the layoutModel)
 
- 
merge
protected void merge(LayoutModel<V> layoutModel, V vertex)
update the baseBounds Map value for the passed vertex, with the (x,y) position of this vertex- Parameters:
 layoutModel- the source of the vertex coordinatesvertex- the vertex key to update in the baseBounds map
 
- 
calculateWidth
protected int calculateWidth(LayoutModel<V> layoutModel, V vertex, Set<V> seen)
calculate the width of the subtree descended from the passed vertex- Parameters:
 layoutModel- the source of the graph verticesvertex- the vertex at the root of the current subtreeseen- a set of vertices that were already measured- Returns:
 - the width of the subtree rooted at the passed vertex
 
 
- 
calculateWidth
protected int calculateWidth(LayoutModel<V> layoutModel, Collection<V> roots, Set<V> seen)
Calculate the width of the forest as the sum of the width of each tree (plus offsets)- Parameters:
 layoutModel- the source of the graph and its verticesroots- the root vertices of the forestseen- a set of vertices that were already placed- Returns:
 - the overall width
 
 
- 
calculateHeight
protected int calculateHeight(LayoutModel<V> layoutModel, V vertex, Set<V> seen)
Calculate the height of the subtree under the passed vertex- Parameters:
 layoutModel- the source of the Graph and its verticesvertex- the vertex at the top of the current subtreeseen- a set of vertices that were already counted- Returns:
 - the height of the subtree rooted at the passed vertex
 
 
- 
calculateHeight
protected int calculateHeight(LayoutModel<V> layoutModel, Collection<V> roots, Set<V> seen)
Calculate the height of the forest as the max height of all of its subtrees- Parameters:
 layoutModel- the source of the graph and verticesroots- the root vertices of the forestseen- a set of vertices that were already measured- Returns:
 - the height that will accomodate the entire forest
 
 
- 
getCenter
public Point getCenter(LayoutModel<V> layoutModel)
- Returns:
 - the center of this layout's area.
 
 
- 
getSpanningTree
public static <V,E> org.jgrapht.Graph<V,E> getSpanningTree(org.jgrapht.Graph<V,E> graph)
 
- 
constrained
public boolean constrained()
- Specified by:
 constrainedin interfaceLayoutAlgorithm<V>- Overrides:
 constrainedin classAbstractTreeLayoutAlgorithm<V>
 
 - 
 
 -