edu.iastate.metnet.graphmodel
Class MyTreeAlgorithm

java.lang.Object
  extended by org.jgraph.layout.JGraphLayoutAlgorithm
      extended by edu.iastate.metnet.graphmodel.MyTreeAlgorithm

public class MyTreeAlgorithm
extends org.jgraph.layout.JGraphLayoutAlgorithm

copy from JGraph, modified for pathway category. Add comments since original code do not contain any comment. I try to make the tree more compact and easy for navigation

Author:
www.jgraph.com, Jie Li

Nested Class Summary
protected  class MyTreeAlgorithm.PolyLine
          the polyline structure
protected  class MyTreeAlgorithm.TreeNode
          tree node contains the relative position in the tree
 
Field Summary
protected  int alignment
          default alignment
protected  java.util.Map cell2node
          CellView -> TreeNode
protected  boolean centerRoot
          center root, if we put the root in the center of the screen border, depending on the orientation of the root
protected  boolean combineLevelNodes
          combine level, if align same level nodes, if false, may save spaces
protected  org.jgraph.JGraph graph
          graph to be layout
protected  int levelDistance
          default level distance
(package private) static org.apache.log4j.Logger logger
          log4j facility
protected  int nodeDistance
          default node distance
protected  int orientation
          default orientation, this decide the position of the root in the whole screen
 
Fields inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
LAYOUT_ATTRIBUTES
 
Constructor Summary
MyTreeAlgorithm()
           
 
Method Summary
protected  MyTreeAlgorithm.TreeNode buildTree(org.jgraph.graph.CellView view)
          build the tree for one cell view recursively
protected  java.util.List buildTrees(java.util.List roots)
          build tree for each root
protected  int distance(MyTreeAlgorithm.PolyLine right, MyTreeAlgorithm.PolyLine left)
          accumulate the delta x of both contour
 int getAlignment()
           
protected  java.util.List getChildren(org.jgraph.graph.CellView view)
          get the children cell view of one cell view
 java.lang.String getHint()
          Get a human readable hint for using this layout.
protected  MyTreeAlgorithm.TreeNode getLeftMostX(MyTreeAlgorithm.TreeNode node)
          get the most left child tree node in this tree specified by the root node
 int getLevelDistance()
           
 int getNodeDistance()
           
 int getOrientation()
           
protected  MyTreeAlgorithm.TreeNode getRightMostX(MyTreeAlgorithm.TreeNode node)
          get the most right child tree node in this tree specified by the root node
protected  MyTreeAlgorithm.TreeNode getTreeNode(org.jgraph.graph.CellView view)
          get the tree node of cell view, which contains the position and children node information
 boolean isCenterRoot()
           
 boolean isCombineLevelNodes()
           
protected  void join(MyTreeAlgorithm.TreeNode node)
          joining tree contour
protected  void layout(MyTreeAlgorithm.TreeNode node)
          layout a group of cell views which compose of a tree structure
protected  void layoutTrees(java.util.List roots)
          layout the trees
protected  void merge(MyTreeAlgorithm.PolyLine main, MyTreeAlgorithm.PolyLine left, int distance)
           
 void run(org.jgraph.JGraph graph, java.lang.Object[] dynamic_cells, java.lang.Object[] static_cells)
          main entry point of the layout algorithm
 void setAlignment(int alignment)
          set alignment as SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM
 void setCenterRoot(boolean b)
          if put the root in the center of the screen border
 void setCombineLevelNodes(boolean combineLevelNodes)
           
 void setLevelDistance(int distance)
          set distance between the tree level
protected  void setLevelHeights(java.util.List roots)
          change the level height to make it more compact.
 void setNodeDistance(int distance)
          set distance between the nodes
 void setOrientation(int orientation)
          SwingConstants.NORTH SwingConstants.EAST SwingConstants.SOUTH SwingConstants.WEST
protected  void setPosition(java.util.List roots)
          set position for a list of trees
 java.lang.String toString()
          Returns the name of this algorithm in human readable form.
 
Methods inherited from class org.jgraph.layout.JGraphLayoutAlgorithm
applyLayout, applyLayout, createDialog, createDialog, createSettings, getMaximumProgress, getProgress, isAllowedToRun, populateDialog, run, setAllowedToRun, setMaximumProgress, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger
log4j facility


alignment

protected int alignment
default alignment


orientation

protected int orientation
default orientation, this decide the position of the root in the whole screen


levelDistance

protected int levelDistance
default level distance


nodeDistance

protected int nodeDistance
default node distance


centerRoot

protected boolean centerRoot
center root, if we put the root in the center of the screen border, depending on the orientation of the root


combineLevelNodes

protected boolean combineLevelNodes
combine level, if align same level nodes, if false, may save spaces


graph

protected org.jgraph.JGraph graph
graph to be layout


cell2node

protected java.util.Map cell2node
CellView -> TreeNode

Constructor Detail

MyTreeAlgorithm

public MyTreeAlgorithm()
Method Detail

toString

public java.lang.String toString()
Returns the name of this algorithm in human readable form.

Overrides:
toString in class java.lang.Object

getHint

public java.lang.String getHint()
Get a human readable hint for using this layout.

Overrides:
getHint in class org.jgraph.layout.JGraphLayoutAlgorithm

setAlignment

public void setAlignment(int alignment)
set alignment as SwingConstants.TOP SwingConstants.CENTER SwingConstants.BOTTOM

Parameters:
alignment - the alignment of the node

setOrientation

public void setOrientation(int orientation)
SwingConstants.NORTH SwingConstants.EAST SwingConstants.SOUTH SwingConstants.WEST

Parameters:
orientation - the orientation of the root

setLevelDistance

public void setLevelDistance(int distance)
set distance between the tree level

Parameters:
distance - the level distance

setNodeDistance

public void setNodeDistance(int distance)
set distance between the nodes

Parameters:
distance - the node distance

setCenterRoot

public void setCenterRoot(boolean b)
if put the root in the center of the screen border

Parameters:
b - true or false

run

public void run(org.jgraph.JGraph graph,
                java.lang.Object[] dynamic_cells,
                java.lang.Object[] static_cells)
main entry point of the layout algorithm

Specified by:
run in class org.jgraph.layout.JGraphLayoutAlgorithm
Parameters:
graph - JGraph instance
dynamic_cells - List of all nodes the layout should move
static_cells - List of node the layout should not move but allow for rotate?

buildTrees

protected java.util.List buildTrees(java.util.List roots)
build tree for each root

Parameters:
roots - the roots, may be disjoint
Returns:
the tree list

buildTree

protected MyTreeAlgorithm.TreeNode buildTree(org.jgraph.graph.CellView view)
build the tree for one cell view recursively

Parameters:
view - the cell view of the root node
Returns:
the tree node of the tree

getChildren

protected java.util.List getChildren(org.jgraph.graph.CellView view)
get the children cell view of one cell view

Parameters:
view - the cell view to extend
Returns:
the list of child cell view

getTreeNode

protected MyTreeAlgorithm.TreeNode getTreeNode(org.jgraph.graph.CellView view)
get the tree node of cell view, which contains the position and children node information

Parameters:
view - the cell view
Returns:
the corresponding tree node

layoutTrees

protected void layoutTrees(java.util.List roots)
layout the trees

Parameters:
roots - the root of trees

layout

protected void layout(MyTreeAlgorithm.TreeNode node)
layout a group of cell views which compose of a tree structure

Parameters:
node -

join

protected void join(MyTreeAlgorithm.TreeNode node)
joining tree contour

Parameters:
node - unknown

getLeftMostX

protected MyTreeAlgorithm.TreeNode getLeftMostX(MyTreeAlgorithm.TreeNode node)
get the most left child tree node in this tree specified by the root node

Parameters:
node - the root node of this sub tree
Returns:
the most left tree node

getRightMostX

protected MyTreeAlgorithm.TreeNode getRightMostX(MyTreeAlgorithm.TreeNode node)
get the most right child tree node in this tree specified by the root node

Parameters:
node - the root node of this sub tree
Returns:
the most right child tree node

merge

protected void merge(MyTreeAlgorithm.PolyLine main,
                     MyTreeAlgorithm.PolyLine left,
                     int distance)

distance

protected int distance(MyTreeAlgorithm.PolyLine right,
                       MyTreeAlgorithm.PolyLine left)
accumulate the delta x of both contour

Parameters:
right - the right contour
left - the left contour
Returns:
the accumulated distance between two contour

setPosition

protected void setPosition(java.util.List roots)
set position for a list of trees


setLevelHeights

protected void setLevelHeights(java.util.List roots)
change the level height to make it more compact. The demo show that this has no problem.

Parameters:
roots - the root of trees

isCombineLevelNodes

public boolean isCombineLevelNodes()
Returns:
Returns the combineLevelNodes.

setCombineLevelNodes

public void setCombineLevelNodes(boolean combineLevelNodes)
Parameters:
combineLevelNodes - The combineLevelNodes to set.

getAlignment

public int getAlignment()
Returns:
Returns the alignment.

isCenterRoot

public boolean isCenterRoot()
Returns:
Returns the centerRoot.

getLevelDistance

public int getLevelDistance()
Returns:
Returns the levelDistance.

getNodeDistance

public int getNodeDistance()
Returns:
Returns the nodeDistance.

getOrientation

public int getOrientation()
Returns:
Returns the orientation.