AccordionTreeDrawer
Class TreeNode

java.lang.Object
  |
  +--AccordionTreeDrawer.TreeNode
All Implemented Interfaces:
CellGeom, java.lang.Comparable

public class TreeNode
extends java.lang.Object
implements CellGeom, java.lang.Comparable

A class representing a node of a (phylognenetic) tree. The tree that this node belongs to is of type Tree. Nodes have fields that store a pre- and post-ordering. A TreeNode has a list of children, a unique key, a leftmostleaf and a rightmost leaf

Version:
Author:
Tamara Munzner, Li Zhang, Yunhong Zhou
See Also:
Tree, GridCell

Field Summary
 java.awt.Color cachedColor
           
 int cachedFrame
           
 GridCell cell
          The GridCell that this node is attached to
 int key
          key is unique for nodes in one tree
 java.lang.String label
           
 TreeNode leftmostLeaf
           
 int lindex
          leaf index
 TreeNode next
          next leaf added by Li
 int numberLeaves
           
 TreeNode parent
           
 TreeNode posorderNext
           
 TreeNode preorderNext
           
 TreeNode rightmostLeaf
           
 float weight
          weight is actually edge length for the edge immediately above the node
 
Constructor Summary
TreeNode()
          Children list initial capacity 2 as in most case binary.
TreeNode(java.lang.String s)
           
TreeNode(java.lang.String s, float w)
          Allocate a new TreeNode object with node name and weight.
 
Method Summary
 void addChild(TreeNode n)
           
 void addEdge(TreeEdge edge, int xy)
          Add edge in either X/horizontal (xy==0) direction, or Y/vertical (xy==1)direction.
 void close()
          clean the node itself and the tree edge attached with it.
 int compareTo(java.lang.Object o)
          implement Comparable interface - sort on key field
 void drawInCell(java.awt.Color col, float plane, AccordionDrawer d)
          Draws this node inside cell, the GridCell that it is attached to, if cell is drawn large enough Prints the label of the node if the GridCell is drawn large enough
 boolean equals(TreeNode n)
           
 TreeNode firstChild()
           
 java.lang.Double getBcnScore()
           
 java.awt.Color getCachedColor()
           
 int getCachedFrame()
           
 GridCell getCell()
           
 TreeNode getChild(int i)
           
 AccordionTreeDrawer getDrawer()
           
 TreeEdge getEdge(int xy)
           
 int getFontSize()
           
 int getKey()
           
 int getLeafCount()
           
 TreeNode getLeftmostLeaf()
           
 int getMax()
           
 int getMin()
           
 java.lang.String getName()
           
 float getPos(int xy)
          compute the real position of the node
 TreeNode getRightmostLeaf()
           
 float getWeight()
           
 boolean isAncestorOf(TreeNode that)
           
 boolean isInteriorNode()
           
 boolean isLeaf()
           
 boolean isRoot()
           
 TreeNode lastChild()
           
 TreeNode lca(TreeNode that)
          Compute the lowest common ancestor between this node and that.
 TreeNode leafLca(TreeNode that)
          Compute the lowest common ancestor between this leaf and "that" The two nodes must belong to the same tree and must be leaves
 int numberChildren()
           
 TreeNode parent()
           
 boolean pick(int x, int y)
           
 void print()
           
 void printSubtree()
           
 void setBcnScore(float n)
           
 void setCachedColor(java.awt.Color c)
           
 void setCachedFrame(int framenum)
           
 void setCell(GridCell c)
           
 void setFontSize(int fs)
           
 void setName(java.lang.String s)
           
 void setSubtreeExtremeLeaves()
           
 void setWeight(double w)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

key

public int key
key is unique for nodes in one tree


cell

public GridCell cell
The GridCell that this node is attached to


cachedColor

public java.awt.Color cachedColor

cachedFrame

public int cachedFrame

parent

public TreeNode parent

label

public java.lang.String label

weight

public float weight
weight is actually edge length for the edge immediately above the node


leftmostLeaf

public TreeNode leftmostLeaf

rightmostLeaf

public TreeNode rightmostLeaf

numberLeaves

public int numberLeaves

preorderNext

public TreeNode preorderNext

posorderNext

public TreeNode posorderNext

lindex

public int lindex
leaf index


next

public TreeNode next
next leaf added by Li

Constructor Detail

TreeNode

public TreeNode()
Children list initial capacity 2 as in most case binary.


TreeNode

public TreeNode(java.lang.String s,
                float w)
Allocate a new TreeNode object with node name and weight.

Parameters:
s - The name of the node given by a string
w - The weight of the edge immediately above the node

TreeNode

public TreeNode(java.lang.String s)
Method Detail

getMin

public int getMin()
Specified by:
getMin in interface CellGeom
Returns:
The index of the smallest descendant node

getMax

public int getMax()
Specified by:
getMax in interface CellGeom
Returns:
The index of the smallest descendant node

getKey

public int getKey()
Specified by:
getKey in interface CellGeom

getName

public java.lang.String getName()
Specified by:
getName in interface CellGeom

setCachedColor

public void setCachedColor(java.awt.Color c)

getCachedColor

public java.awt.Color getCachedColor()

setCachedFrame

public void setCachedFrame(int framenum)

getCachedFrame

public int getCachedFrame()

getDrawer

public AccordionTreeDrawer getDrawer()

pick

public boolean pick(int x,
                    int y)
Specified by:
pick in interface CellGeom

getPos

public float getPos(int xy)
compute the real position of the node


drawInCell

public void drawInCell(java.awt.Color col,
                       float plane,
                       AccordionDrawer d)
Draws this node inside cell, the GridCell that it is attached to, if cell is drawn large enough Prints the label of the node if the GridCell is drawn large enough

Specified by:
drawInCell in interface CellGeom
Parameters:
col - The color to draw this node in
plane - The plane to draw this node in
See Also:
GridCell

setCell

public void setCell(GridCell c)
Specified by:
setCell in interface CellGeom

getCell

public GridCell getCell()
Specified by:
getCell in interface CellGeom

addEdge

public void addEdge(TreeEdge edge,
                    int xy)
Add edge in either X/horizontal (xy==0) direction, or Y/vertical (xy==1)direction. Leaf nodes have no vertical edge.


getEdge

public TreeEdge getEdge(int xy)

compareTo

public int compareTo(java.lang.Object o)
implement Comparable interface - sort on key field

Specified by:
compareTo in interface java.lang.Comparable

close

public void close()
clean the node itself and the tree edge attached with it.

See Also:
TreeEdge.close, Tree.close

setName

public void setName(java.lang.String s)

numberChildren

public int numberChildren()

getChild

public TreeNode getChild(int i)

getLeftmostLeaf

public TreeNode getLeftmostLeaf()

getRightmostLeaf

public TreeNode getRightmostLeaf()

isLeaf

public boolean isLeaf()

isRoot

public boolean isRoot()

getLeafCount

public int getLeafCount()
Returns:
the total number of leaves decedant to this node

equals

public boolean equals(TreeNode n)

addChild

public void addChild(TreeNode n)

parent

public TreeNode parent()

setWeight

public void setWeight(double w)

getWeight

public float getWeight()

firstChild

public TreeNode firstChild()

lastChild

public TreeNode lastChild()

isAncestorOf

public boolean isAncestorOf(TreeNode that)
Parameters:
that - Another TreeNode object
Returns:
true if this is an ancestor of that

lca

public TreeNode lca(TreeNode that)
Compute the lowest common ancestor between this node and that. The two nodes must belong to the same tree.

Parameters:
that - A TreeNode in the Tree that this TreeNode belongs to
Returns:
the lowest common ancestor between this node and "that"

leafLca

public TreeNode leafLca(TreeNode that)
Compute the lowest common ancestor between this leaf and "that" The two nodes must belong to the same tree and must be leaves

Parameters:
that - A TreeNode in the Tree that this TreeNode belongs to
Returns:
the lowest common ancestor between this leaf and that, null if one of the nodes is not a leaf

print

public void print()

printSubtree

public void printSubtree()

setSubtreeExtremeLeaves

public void setSubtreeExtremeLeaves()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setFontSize

public void setFontSize(int fs)

getFontSize

public int getFontSize()

isInteriorNode

public boolean isInteriorNode()

setBcnScore

public void setBcnScore(float n)

getBcnScore

public java.lang.Double getBcnScore()