Class JGraphTreeLayout
java.lang.Object
com.jgraph.layout.tree.JGraphAbstractTreeLayout
com.jgraph.layout.tree.JGraphTreeLayout
- All Implemented Interfaces:
JGraphLayout
- Direct Known Subclasses:
OrganizationalChart
An implementation of a basic tree layout. The layout is created using the
internal
TreeNode structure with appropriate interfaces to the
actual graph model. The layout can be configured by orientation, the
alignment of the nodes per level, the minimum distance between-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classADT of a straight part of a polylineprotected classAn ADT representing a node in a tree structure.Nested classes/interfaces inherited from class JGraphAbstractTreeLayout
JGraphAbstractTreeLayout.TreeNodeNested classes/interfaces inherited from interface JGraphLayout
JGraphLayout.Stoppable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intalignment indicates what part of the vertices will be lined up on each row (level) of the tree.protected booleanWhether or not to bring all nodes on the same level to the same height in the treeFields inherited from class JGraphAbstractTreeLayout
graph, levelDistance, lowerLevelValues, nodeDistance, nodes, oldOrigin, orientation, positionMultipleTrees, routeTreeEdges, treeBoundary, treeDistance, upperLevelValuesFields inherited from interface JGraphLayout
VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intdistance(JGraphTreeLayout.PolyLine right, JGraphTreeLayout.PolyLine left) intprotected JGraphTreeLayout.StandardTreeNodeObtains the left most point on the sub-tree under the specified tree nodeprotected JGraphTreeLayout.StandardTreeNodeObtains the right most point on the sub-tree under the specified tree nodeprotected JGraphTreeLayout.StandardTreeNodegetTreeNode(Object cell) Obtains the tree node corresponding to the specified cellbooleanprotected voidJoins nodes underneath the specified tree nodeprotected voidTop-level method that performs actual layout of tree for a specific node.protected voidmerge(JGraphTreeLayout.PolyLine main, JGraphTreeLayout.PolyLine left, double distance) Merges two parts of a polyline togethervoidrun(JGraphFacade graph) The API method used to exercise the layout upon the facade description and produce a separate description of the vertex position and edge routing changes made.voidsetAlignment(int alignment) SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM are valid inputs to this methodvoidsetCombineLevelNodes(boolean combineLevelNodes) protected voidSets the heights of the level under the specified nodeprotected voidsetPosition(List roots) Sets the position of the tree nodes specifiedprotected voidEnsures that the specified root is spaced far enough from previous trees so not to overlap any cells.toString()ReturnsTree, the name of this algorithm.
-
Field Details
-
alignment
protected int alignmentalignment indicates what part of the vertices will be lined up on each row (level) of the tree. Valid values are SwingConstants.TOP, SwingConstants.CENTER and SwingConstants.BOTTOM. The default is TOP, i.e. the top of vertices on any one row line up. It should be noted that the alignment can sound confusing when the orientation changes. The alignment is always taken that you are looking at the tree with the root node at the top. If the root node were at the bottom ( orientation is SOUTH ) then SwingConstants.TOP would actually align the bottoms of the vertices up as you look at the graph. EAST and WEST orientations follow the same pattern. If it's confusing have a play with the values, it soon becomes clear. -
combineLevelNodes
protected boolean combineLevelNodesWhether or not to bring all nodes on the same level to the same height in the tree
-
-
Constructor Details
-
JGraphTreeLayout
public JGraphTreeLayout()
-
-
Method Details
-
run
The API method used to exercise the layout upon the facade description and produce a separate description of the vertex position and edge routing changes made. It first builds a representation of the tree using the inner tree class by doing a depth first search of the graph from the root. It then lays out the graph using the obtained data- Specified by:
runin interfaceJGraphLayout- Overrides:
runin classJGraphAbstractTreeLayout- Parameters:
graph- the facade describing the graph and its configuration
-
getTreeNode
Obtains the tree node corresponding to the specified cell- Parameters:
cell- the cell whose tree node is to be found- Returns:
- the matching tree node, if any
-
layout
Top-level method that performs actual layout of tree for a specific node. Note this acts upon the internal tree node structure- Parameters:
node- the tree node to be laid out
-
join
Joins nodes underneath the specified tree node- Parameters:
node- the node under which the tree is to be formed
-
getLeftMostX
Obtains the left most point on the sub-tree under the specified tree node- Parameters:
node- the start of the sub-tree to be analysed- Returns:
- the left-most tree node in the sub-tree
-
getRightMostX
Obtains the right most point on the sub-tree under the specified tree node- Parameters:
node- the start of the sub-tree to be analysed- Returns:
- the right-most tree node in the sub-tree
-
merge
protected void merge(JGraphTreeLayout.PolyLine main, JGraphTreeLayout.PolyLine left, double distance) Merges two parts of a polyline together- Parameters:
main- the main part of the polylineleft- the polyline to be addeddistance-
-
distance
- Parameters:
right- first part of polylineleft- second part of polyline- Returns:
- the distance between the two polylines
-
setPosition
Sets the position of the tree nodes specified- Parameters:
roots- the tree node whose position is to be set
-
setLevelHeights
Sets the heights of the level under the specified node- Parameters:
root- the node under which level heights will be set
-
spaceMultipleTrees
Ensures that the specified root is spaced far enough from previous trees so not to overlap any cells.- Parameters:
root- the root of the tree to be spaced correctly
-
getAlignment
public int getAlignment()- Returns:
- Returns the alignment.
-
setAlignment
public void setAlignment(int alignment) SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM are valid inputs to this method- Parameters:
alignment-
-
isCombineLevelNodes
public boolean isCombineLevelNodes()- Returns:
- Returns the combineLevelNodes.
-
setCombineLevelNodes
public void setCombineLevelNodes(boolean combineLevelNodes) - Parameters:
combineLevelNodes- The combineLevelNodes to set.
-
toString
-