org.graffiti.plugins.algorithms.reingoldtilford
Class TreeCombinationStack

java.lang.Object
  extended by org.graffiti.plugins.algorithms.reingoldtilford.TreeCombinationStack

public class TreeCombinationStack
extends Object

TreeCombinationStack is used to compose a Tree layout from the layouts of its children. The subtrees may be pushed ( push(Tree, boolean)) on the right or the left side of the combination. Pushing a tree onto the stack can be reverted by pop() in a LIFO manner. A tree pushed onto the stack is locked {see @link Tree#isLocked()} until it is popped from the stack.

Version:
$Revision$ $Date$
Author:
Andreas Gleißner

Constructor Summary
TreeCombinationStack(LinkedList<Tree> trees, ReingoldTilfordAlgorithm algorithm)
          Creates a new TreeCombinationStack an pushes the trees in trees onto it (subsequently on the right sight).
TreeCombinationStack(ReingoldTilfordAlgorithm algorithm)
          Creates an empty TreeCombinationStack.
TreeCombinationStack(Tree tree, ReingoldTilfordAlgorithm algorithm)
          Creates a TreeCombinationStack an pushes tree onto it.
 
Method Summary
 void apply(Tree parent)
          Applies the combined tree layout composed by this TreeCombinationStack to the tree layout of parent.
 double calculateCombinedWidth(TreeCombinationStack rightStack)
          Returns the width of the combined tree layout if all tree layouts of rightStack were added to this stack.
 int getTreeCount()
          Returns the count of tree layouts in this stack.
 LinkedList<Tree> getTrees()
          Returns the tree layouts contained in this stack.
 double getWidth()
          Returns the width of the combined tree layout.
 Tree peek()
          Returns the top element of this stack.
 void pop()
          Pops the last added tree from the stack.
 void push(Tree tree, boolean right)
          Pushes tree onto the stack.
 double testInsertion(Tree tree, boolean right)
          Returns the width of the combined tree layout if tree was added to this stack.
 void writeToDebugSession(org.graffiti.plugins.tools.debug.DebugSession session, ReingoldTilfordAlgorithm algorithm)
          Writes information about this stack to a DebugSession.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeCombinationStack

public TreeCombinationStack(ReingoldTilfordAlgorithm algorithm)
Creates an empty TreeCombinationStack.

Parameters:
algorithm - the Reingold-Tilford algorithm.

TreeCombinationStack

public TreeCombinationStack(Tree tree,
                            ReingoldTilfordAlgorithm algorithm)
Creates a TreeCombinationStack an pushes tree onto it.

Parameters:
tree - the tree to be pushed onto the stack.
algorithm - the Reingold-Tilford algorithm.
Throws:
LockedTreeException - if tree is locked.
See Also:
Tree.isLocked()

TreeCombinationStack

public TreeCombinationStack(LinkedList<Tree> trees,
                            ReingoldTilfordAlgorithm algorithm)
Creates a new TreeCombinationStack an pushes the trees in trees onto it (subsequently on the right sight).

Parameters:
trees - the trees to be pushed onto the stack.
algorithm - the Reingold-Tilford algorithm.
Throws:
LockedTreeException - if on of the trees is locked.
See Also:
Tree.isLocked()
Method Detail

push

public void push(Tree tree,
                 boolean right)
Pushes tree onto the stack. The contour lines of the stack and the tree are combined. This operation can be reverted by a call to pop().

Parameters:
tree - the tree to be pushed onto the stack.
right - true if the tree is added to the right side.
false if the tree is added to the left side.
Throws:
LockedTreeException - if tree is locked.
See Also:
Tree.isLocked()

pop

public void pop()
Pops the last added tree from the stack. Unlocks that tree.

Throws:
NoSuchElementException - if there is no tree to pop, i.e. the stack is empty.

apply

public void apply(Tree parent)
Applies the combined tree layout composed by this TreeCombinationStack to the tree layout of parent.

Parameters:
parent - the tree layout the combined tree layout composed by this TreeCombinationStack is applied to. It must be the parent of the tree layouts inserted into this list.

getWidth

public double getWidth()
Returns the width of the combined tree layout.

Returns:
the width of the combined tree layout.
See Also:
width

getTrees

public LinkedList<Tree> getTrees()
Returns the tree layouts contained in this stack.

Returns:
the tree layouts contained in this stack.
See Also:
trees

testInsertion

public double testInsertion(Tree tree,
                            boolean right)
Returns the width of the combined tree layout if tree was added to this stack.

Parameters:
tree - the tree layout whose insertion is to be tested.
Returns:
the width of the combined tree layout if tree was added to this stack.
Throws:
LockedTreeException - if tree is locked.
See Also:
Tree.isLocked()

calculateCombinedWidth

public double calculateCombinedWidth(TreeCombinationStack rightStack)
Returns the width of the combined tree layout if all tree layouts of rightStack were added to this stack.

Parameters:
rightStack - the other TreeCombinationStack.
Returns:
the width of the combined tree layout if all tree layouts of rightStack were added to this stack.

getTreeCount

public int getTreeCount()
Returns the count of tree layouts in this stack.

Returns:
the count of tree layouts in this stack.

peek

public Tree peek()
Returns the top element of this stack.

Returns:
the top element of this stack;
null if this stack is empty.

writeToDebugSession

public void writeToDebugSession(org.graffiti.plugins.tools.debug.DebugSession session,
                                ReingoldTilfordAlgorithm algorithm)
Writes information about this stack to a DebugSession.

Parameters:
session - the DebugSession written to.
algorithm - the Reingold-Tilford algorithm.


Generated at 2012-05-30 11:01:25 PM CEST