grtree
Class Tree

java.lang.Object
  |
  +--grtree.Tree

public class Tree
extends java.lang.Object

Tree is a class representing a kind of generalized tree that the user wishes to draw on a graphics plane or print on some page (or graphics plane). A tree of this kind has data and any number of children. The data is simply a String and the children is a Vector of Tree's. A Tree can draw itself on any appropriate graphics plane using its drawTree method. A Tree can print itself at TTY (or elsewhere) via its toString method.

Version:
proto2
Author:
jrfisher@csupomona.edu

Field Summary
private  java.awt.Color background
           
 java.util.Vector children
           
 java.lang.String data
          A Tree has data and children.
private  java.awt.Color edgeColor
           
private  java.awt.Font font
           
private  java.awt.Color fontColor
           
private  java.awt.Color leafColor
           
 
Constructor Summary
Tree(java.lang.String s)
          Construct a Tree using (simple) String.
 
Method Summary
 void addChild(Tree t)
          Add a child to this tree.
 void drawNode(java.awt.Graphics g, int x, int y)
           
 void drawTree(java.awt.Graphics g, int x, int y)
          drawTree draws the tree in the Graphics plane using upper-left corner x,y (for box containing the tree).
 int getNodeHeight(java.awt.Graphics g)
           
 int getNodeWidth(java.awt.Graphics g)
          How wide/high is the root node of this tree when drawn?
 int getTreeHeight(java.awt.Graphics g)
           
 int getTreeWidth(java.awt.Graphics g)
           
 boolean isLeaf()
          Is this a leaf?
static void main(java.lang.String[] args)
           
 void removeChild(Tree t)
          Remove a child from this tree.
 java.lang.String toString()
          .toString() .toString(int) Generate a String representation for the entire tree This is the familiar cascaded (tabbed tree) form.
 java.lang.String toString(int tab)
           
 java.lang.String toTreeExpression()
          Return TreeExpression for this tree.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

data

public java.lang.String data
A Tree has data and children.

children

public java.util.Vector children

font

private java.awt.Font font

background

private java.awt.Color background

leafColor

private java.awt.Color leafColor

fontColor

private java.awt.Color fontColor

edgeColor

private java.awt.Color edgeColor
Constructor Detail

Tree

public Tree(java.lang.String s)
Construct a Tree using (simple) String.
Method Detail

addChild

public void addChild(Tree t)
Add a child to this tree.

removeChild

public void removeChild(Tree t)
Remove a child from this tree.

isLeaf

public boolean isLeaf()
Is this a leaf?

toString

public java.lang.String toString()
.toString() .toString(int) Generate a String representation for the entire tree This is the familiar cascaded (tabbed tree) form.
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int tab)

toTreeExpression

public java.lang.String toTreeExpression()
Return TreeExpression for this tree. NOT YET IMPLEMENTED.

getNodeWidth

public int getNodeWidth(java.awt.Graphics g)
How wide/high is the root node of this tree when drawn?

getNodeHeight

public int getNodeHeight(java.awt.Graphics g)

drawNode

public void drawNode(java.awt.Graphics g,
                     int x,
                     int y)

getTreeWidth

public int getTreeWidth(java.awt.Graphics g)

getTreeHeight

public int getTreeHeight(java.awt.Graphics g)

drawTree

public void drawTree(java.awt.Graphics g,
                     int x,
                     int y)
drawTree draws the tree in the Graphics plane using upper-left corner x,y (for box containing the tree).

main

public static void main(java.lang.String[] args)