JGraph
v5.13.0.0


com.jgraph.layout.tree
Class JGraphTreeLayout

java.lang.Object
  extended by com.jgraph.layout.tree.JGraphAbstractTreeLayout
      extended by com.jgraph.layout.tree.JGraphTreeLayout
All Implemented Interfaces:
JGraphLayout
Direct Known Subclasses:
OrganizationalChart

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  class JGraphTreeLayout.PolyLine
          ADT of a straight part of a polyline
protected  class JGraphTreeLayout.StandardTreeNode
          An ADT representing a node in a tree structure.
 
Nested classes/interfaces inherited from class com.jgraph.layout.tree.JGraphAbstractTreeLayout
JGraphAbstractTreeLayout.TreeNode
 
Nested classes/interfaces inherited from interface com.jgraph.layout.JGraphLayout
JGraphLayout.Stoppable
 
Field Summary
protected  int alignment
          alignment indicates what part of the vertices will be lined up on each row (level) of the tree.
protected  boolean combineLevelNodes
          Whether or not to bring all nodes on the same level to the same height in the tree
 
Fields inherited from class com.jgraph.layout.tree.JGraphAbstractTreeLayout
graph, levelDistance, lowerLevelValues, nodeDistance, nodes, oldOrigin, orientation, positionMultipleTrees, routeTreeEdges, treeBoundary, treeDistance, upperLevelValues
 
Fields inherited from interface com.jgraph.layout.JGraphLayout
VERSION
 
Constructor Summary
JGraphTreeLayout()
           
 
Method Summary
protected  int distance(JGraphTreeLayout.PolyLine right, JGraphTreeLayout.PolyLine left)
           
 int getAlignment()
           
protected  JGraphTreeLayout.StandardTreeNode getLeftMostX(JGraphTreeLayout.StandardTreeNode node)
          Obtains the left most point on the sub-tree under the specified tree node
protected  JGraphTreeLayout.StandardTreeNode getRightMostX(JGraphTreeLayout.StandardTreeNode node)
          Obtains the right most point on the sub-tree under the specified tree node
protected  JGraphTreeLayout.StandardTreeNode getTreeNode(Object cell)
          Obtains the tree node corresponding to the specified cell
 boolean isCombineLevelNodes()
           
protected  void join(JGraphTreeLayout.StandardTreeNode node)
          Joins nodes underneath the specified tree node
protected  void layout(JGraphTreeLayout.StandardTreeNode node)
          Top-level method that performs actual layout of tree for a specific node.
protected  void merge(JGraphTreeLayout.PolyLine main, JGraphTreeLayout.PolyLine left, double distance)
          Merges two parts of a polyline together
 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.
 void setAlignment(int alignment)
          SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM are valid inputs to this method
 void setCombineLevelNodes(boolean combineLevelNodes)
           
protected  void setLevelHeights(JGraphTreeLayout.StandardTreeNode root)
          Sets the heights of the level under the specified node
protected  void setPosition(List roots)
          Sets the position of the tree nodes specified
protected  void spaceMultipleTrees(JGraphTreeLayout.StandardTreeNode root)
          Ensures that the specified root is spaced far enough from previous trees so not to overlap any cells.
 String toString()
          Returns Tree, the name of this algorithm.
 
Methods inherited from class com.jgraph.layout.tree.JGraphAbstractTreeLayout
getLevelDistance, getNodeDistance, getOrientation, getRouteTreeEdges, getTreeDistance, isPositionMultipleTrees, setLevelDistance, setNodeDistance, setOrientation, setPositionMultipleTrees, setRouteTreeEdges, setTreeDistance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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

Constructor Detail

JGraphTreeLayout

public JGraphTreeLayout()
Method Detail

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

Specified by:
run in interface JGraphLayout
Overrides:
run in class JGraphAbstractTreeLayout
Parameters:
graph - the facade describing the graph and its configuration

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

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

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

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

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 -

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

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

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

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

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

public String toString()
Returns Tree, the name of this algorithm.

Overrides:
toString in class Object

JGraph
v5.13.0.0


Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.