com.jgraph.layout.tree

Class JGraphTreeLayout

public class JGraphTreeLayout extends JGraphAbstractTreeLayout

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
protected classJGraphTreeLayout.PolyLine
ADT of a straight part of a polyline
protected classJGraphTreeLayout.StandardTreeNode
An ADT representing a node in a tree structure.
Field Summary
protected intalignment
alignment indicates what part of the vertices will be lined up on each row (level) of the tree.
protected booleancombineLevelNodes
Whether or not to bring all nodes on the same level to the same height in the tree
Method Summary
protected intdistance(JGraphTreeLayout.PolyLine right, JGraphTreeLayout.PolyLine left)
intgetAlignment()
protected JGraphTreeLayout.StandardTreeNodegetLeftMostX(JGraphTreeLayout.StandardTreeNode node)
Obtains the left most point on the sub-tree under the specified tree node
protected JGraphTreeLayout.StandardTreeNodegetRightMostX(JGraphTreeLayout.StandardTreeNode node)
Obtains the right most point on the sub-tree under the specified tree node
protected JGraphTreeLayout.StandardTreeNodegetTreeNode(Object cell)
Obtains the tree node corresponding to the specified cell
booleanisCombineLevelNodes()
protected voidjoin(JGraphTreeLayout.StandardTreeNode node)
Joins nodes underneath the specified tree node
protected voidlayout(JGraphTreeLayout.StandardTreeNode node)
Top-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 together
voidrun(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 method
voidsetCombineLevelNodes(boolean combineLevelNodes)
protected voidsetLevelHeights(JGraphTreeLayout.StandardTreeNode root)
Sets the heights of the level under the specified node
protected voidsetPosition(List roots)
Sets the position of the tree nodes specified
protected voidspaceMultipleTrees(JGraphTreeLayout.StandardTreeNode root)
Ensures that the specified root is spaced far enough from previous trees so not to overlap any cells.
StringtoString()
Returns Tree, the name of this algorithm.

Field Detail

alignment

protected int alignment
alignment 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 combineLevelNodes
Whether or not to bring all nodes on the same level to the same height in the tree

Method Detail

distance

protected int distance(JGraphTreeLayout.PolyLine right, JGraphTreeLayout.PolyLine left)

Parameters: right first part of polyline left second part of polyline

Returns: the distance between the two polylines

getAlignment

public int getAlignment()

Returns: Returns the alignment.

getLeftMostX

protected JGraphTreeLayout.StandardTreeNode getLeftMostX(JGraphTreeLayout.StandardTreeNode node)
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

protected JGraphTreeLayout.StandardTreeNode getRightMostX(JGraphTreeLayout.StandardTreeNode node)
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

getTreeNode

protected JGraphTreeLayout.StandardTreeNode getTreeNode(Object cell)
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

isCombineLevelNodes

public boolean isCombineLevelNodes()

Returns: Returns the combineLevelNodes.

join

protected void join(JGraphTreeLayout.StandardTreeNode node)
Joins nodes underneath the specified tree node

Parameters: node the node under which the tree is to be formed

layout

protected void layout(JGraphTreeLayout.StandardTreeNode node)
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

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 polyline left the polyline to be added distance

run

public void run(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. 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

Parameters: graph the facade describing the graph and its configuration

setAlignment

public void setAlignment(int alignment)
SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM are valid inputs to this method

Parameters: alignment

setCombineLevelNodes

public void setCombineLevelNodes(boolean combineLevelNodes)

Parameters: combineLevelNodes The combineLevelNodes to set.

setLevelHeights

protected void setLevelHeights(JGraphTreeLayout.StandardTreeNode root)
Sets the heights of the level under the specified node

Parameters: root the node under which level heights will be set

setPosition

protected void setPosition(List roots)
Sets the position of the tree nodes specified

Parameters: roots the tree node whose position is to be set

spaceMultipleTrees

protected void spaceMultipleTrees(JGraphTreeLayout.StandardTreeNode root)
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

toString

public String toString()
Returns Tree, the name of this algorithm.
Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.