exe
Class Tree

java.lang.Object
  extended by exe.Tree
Direct Known Subclasses:
GAIGStree

public class Tree
extends java.lang.Object

This class provides support for binary and general trees, with methods to output these trees in both GAIGS formats. A Tree object contains a reference to the root of the tree, and children can be added to this root using the various methods in the TreeNode class. The methods of this class are used to set whether the Tree is binary or general and to control the way the Tree is output in a GAIGS animation.

In order to use any of these tree classes in a script-producing program, the script-producing program must import the package exe.

Author:
Sven Moen (original author), Ethan Dereszynski (adaptations), Ben Tidman (GAIGS adaptations), Andrew Jungwirth (more GAIGS adaptations and Javadoc comments), Myles McNally (changed access status of instance variables)

Field Summary
protected  boolean binary
          Maintains the binary status of this Tree.
protected  double font_size
          Holds the minimum font size for this Tree when drawn in the new GAIGS XML format.
protected  int lines_per_node
          Keeps track of the number of lines of text for each TreeNode's label.
protected  java.io.PrintWriter out
          Holds a reference to the PrintWriter output stream to which this Tree should output its snapshots when its write methods are called.
protected  TreeNode root
          Contains a reference to the root of this Tree.
protected  double x_spacing
          Contains the horizontal spacing of this Tree.
protected  double x1
          Stores the left-most x-bound for this Tree within the normalized [0,1] space.
protected  double x2
          Stores the right-most x-bound for this Tree within the normalized [0,1] space.
protected  double y_spacing
          Contains the vertical spacing of this Tree.
protected  double y1
          Stores the lower y-bound for this Tree within the normalized [0,1] space.
protected  double y2
          Stores the upper y-bound for this Tree within the normalized [0,1] space.
 
Constructor Summary
Tree(boolean isBinary)
          Constructs a new Tree by specifying whether it is a binary or general Tree.
Tree(boolean isBinary, int lines_per_node)
          Constructs a new Tree by specifying whether it is a binary or general Tree and by giving the number of lines for node labels.
 
Method Summary
 TreeNode getRoot()
          Returns the root of this Tree.
 boolean isBinary()
          Indicates if this Tree is binary or general.
 void setBinary(boolean isBinary)
          Specifies whether this Tree is binary or general.
 void setBounds(double x1, double y1, double x2, double y2)
          Sets the bounds in which this Tree is to be drawn.
 void setFontSize(double size)
          Sets the minimum font size to keep the fonts in this Tree readable.
 void setLinesPerNode(int lines_per_node)
          Modifies the number of lines used for node labels.
 void setOut(java.io.PrintWriter out)
          Stores a reference to the PrintWriter output stream to which this Tree is to output its information.
 void setRoot(TreeNode r)
          Sets the root TreeNode for this Tree.
 void setSpacing(double x, double y)
          Sets the spacing between nodes on the vertical and horizontal axes.
 void writeGAIGSTree(java.lang.String title)
          Writes this Tree to the specified PrintWriter output stream as an old GAIGS format snapshot.
 void writeGAIGSXMLTree()
          Writes this Tree to the specified PrintWriter output stream in the new GAIGS XML format.
 void writeGAIGSXMLTree(java.lang.String name)
          Writes this Tree to the specified PrintWriter output stream in the new GAIGS XML format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected TreeNode root
Contains a reference to the root of this Tree.


binary

protected boolean binary
Maintains the binary status of this Tree. A value of true means this Tree is binary, and a value of false means this Tree is general. Defaults to false, making the default a general Tree.


x1

protected double x1
Stores the left-most x-bound for this Tree within the normalized [0,1] space. Defaults to 0.0 if no bounds are set. The bounds variables can be used to localize this Tree in a section of the drawing window in the new GAIGS XML format to allow multiple structures to appear in the same snapshot.


y1

protected double y1
Stores the lower y-bound for this Tree within the normalized [0,1] space. Defaults to 0.0 if no bounds are set. The bounds variables can be used to localize this Tree in a section of the drawing window in the new GAIGS XML format to allow multiple structures to appear in the same snapshot.


x2

protected double x2
Stores the right-most x-bound for this Tree within the normalized [0,1] space. Defaults to 1.0 if no bounds are set. The bounds variables can be used to localize this Tree in a section of the drawing window in the new GAIGS XML format to allow multiple structures to appear in the same snapshot.


y2

protected double y2
Stores the upper y-bound for this Tree within the normalized [0,1] space. Defaults to 1.0 if no bounds are set. The bounds variables can be used to localize this Tree in a section of the drawing window in the new GAIGS XML format to allow multiple structures to appear in the same snapshot.


font_size

protected double font_size
Holds the minimum font size for this Tree when drawn in the new GAIGS XML format. Used to specify a font size that will be readable when this Tree is drawn in a smaller portion of the screen.


x_spacing

protected double x_spacing
Contains the horizontal spacing of this Tree. Used to define how many node widths are between nodes on the x-axis when this Tree is drawn in either GAIGS format. Defaults to a value of 1.25, which produces just about as tight a tree as is readable.


y_spacing

protected double y_spacing
Contains the vertical spacing of this Tree. Used to define how many node widths are between nodes on the y-axis when this Tree is drawn in either GAIGS format. Defaults to a value of 1.25, which produces just about as tight a tree as is readable.


lines_per_node

protected int lines_per_node
Keeps track of the number of lines of text for each TreeNode's label. This is used in the old GAIGS format, but it is not necessary in the new GAIGS XML format because the number of lines for each node can be determined from the XML script file. Default value is 1.


out

protected java.io.PrintWriter out
Holds a reference to the PrintWriter output stream to which this Tree should output its snapshots when its write methods are called.

Constructor Detail

Tree

public Tree(boolean isBinary)
Constructs a new Tree by specifying whether it is a binary or general Tree.

Parameters:
isBinary - Indicates if this Tree is binary or general. A value of true makes a binary Tree, and false results in a general Tree.

Tree

public Tree(boolean isBinary,
            int lines_per_node)
Constructs a new Tree by specifying whether it is a binary or general Tree and by giving the number of lines for node labels. This is only necessary when outputting the Tree in the old GAIGS format since the number of lines per node can be determined from an XML script file in the new GAIGS XML format.

Parameters:
isBinary - Indicates if this Tree is binary or general. A value of true makes a binary Tree, and false results in a general Tree.
lines_per_node - Sets the number of lines for node labels.
Method Detail

setRoot

public void setRoot(TreeNode r)
Sets the root TreeNode for this Tree. This method completely resets the root for this Tree, and any old data will be lost. Children can then be added to this root by calling the appropriate methods in the TreeNode class.

Parameters:
r - Specifies the new root for this Tree. The variable root is set to equal the value of r.

setBinary

public void setBinary(boolean isBinary)
Specifies whether this Tree is binary or general. If this Tree's root is not equal to null, the value of binary will not be changed because this Tree is already binary or general.

Parameters:
isBinary - Sets the value of binary. A value of true results in a binary Tree, and a value of false produces a general Tree. The value of binary is not changed if this Tree already has nodes.

setBounds

public void setBounds(double x1,
                      double y1,
                      double x2,
                      double y2)
Sets the bounds in which this Tree is to be drawn. These bounds specify the area within the normalized [0,1] space within which this Tree should appear in the snapshot. Used to draw this Tree in a portion of the viewing window so that multiple structures can appear in a snapshot in the new GAIGS XML format.

Parameters:
x1 - Sets the left-most bound on the horizontal axis.
y1 - Sets the lower bound on the vertical axis.
x2 - Sets the right-most bound on the horizontal axis.
y2 - Sets the upper bound on the vertical axis.

setFontSize

public void setFontSize(double size)
Sets the minimum font size to keep the fonts in this Tree readable. Used to upsize the font when drawing this Tree in a portion of the viewing window in the new GAIGS XML format.

Parameters:
size - Indicates the minimum font size for the fonts in this Tree.

setSpacing

public void setSpacing(double x,
                       double y)
Sets the spacing between nodes on the vertical and horizontal axes.

Parameters:
x - Specifies the number of node widths between nodes on the horizontal axis.
y - Specifies the number of node widths between nodes on the vertical axis.

setOut

public void setOut(java.io.PrintWriter out)
Stores a reference to the PrintWriter output stream to which this Tree is to output its information.

Parameters:
out - Indicates the output stream to which this Tree should print its information when its write methods are called.

setLinesPerNode

public void setLinesPerNode(int lines_per_node)
Modifies the number of lines used for node labels. This value is only used in old GAIGS snapshot specifications so it is not necessary to change lines_per_node in a script-producing program that uses the new GAIGS XML format.

Parameters:
lines_per_node - Sets the number of lines needed for node labels in this Tree.

getRoot

public TreeNode getRoot()
Returns the root of this Tree.

Returns:
Gives a reference to the root of this Tree. If the root has not been set, null is returned.

isBinary

public boolean isBinary()
Indicates if this Tree is binary or general.

Returns:
Yields true if this Tree is binary or false if this Tree is general.

writeGAIGSTree

public void writeGAIGSTree(java.lang.String title)
Writes this Tree to the specified PrintWriter output stream as an old GAIGS format snapshot. If the value of out has not been set using the setOut(PrintWriter) method, an Exception will be thrown.

Parameters:
title - Specifies the title for the snapshot so that it can be properly inserted into the snapshot specification.

writeGAIGSXMLTree

public void writeGAIGSXMLTree()
Writes this Tree to the specified PrintWriter output stream in the new GAIGS XML format. If the value of out has not been set using the setOut(PrintWriter) method, an Exception will be thrown.


writeGAIGSXMLTree

public void writeGAIGSXMLTree(java.lang.String name)
Writes this Tree to the specified PrintWriter output stream in the new GAIGS XML format. If the value of out has not been set using the setOut(PrintWriter) method, an Exception will be thrown.

This method is identical to writeGAIGSXMLTree, except that it prints the optional name element that gives this Tree a label in the snapshot.

Parameters:
name - Specifies the label/title for this Tree in the snapshot. This is a title that appears only above this structure and is smaller than the title for the entire snapshot. If an individual title for this Tree is not desired, use writeGAIGSXMLTree().