|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.ksu.cis.viewer.TreeDrawing
An immutable high-level representation of a drawing of a tree. This
representation contains a font-independent description of the size of
the drawing along with all the information necessary to draw the tree
on a given graphics context. The paint
method is used to
draw the tree.
There are two general ways of constructing a TreeDrawing. The
first is to recursively build it from Node
s. Drawings of
BinaryTree
s are build in this way. The second way is
to build it from an implementation of TreeInterface
and optionally
an implementation of Colorizer
. When this way is used, no
attempt is made to detect cycles or overlapping subtrees; instead,
a parameter to the constructor specifies the maximum height of the tree
drawn.
A TreeComponent
containing a graphical representation
can be
efficiently obtained from the getDrawing()
method. This method
returns a new TreeComponent
each time it is called, so they can be used in multiple containers. These
components will all share the same TreeDrawing.
Empty trees are not drawn, but if a node contains both empty and nonempty children, the horizontal padding that would surround a node is included for empty children. Consequently, in a binary tree, the line drawn from a node to its left child always angles to the left, and the line drawn from a node to its right child always angles to the right, even when the other child is empty. On the other hand, it may be more difficult to tell which children may be empty in trees with other branching factors.
BinaryTree
,
TreeInterface
,
Colorizer
Field Summary | |
static int |
HORIZONTAL_SEPARATION
The width in characters of the horizontal separation between two nodes. |
static char |
STANDARD_CHARACTER
The character used as the standard for determining the character width. |
static int |
VERTICAL_SEPARATION
The height in lines of text of the vertical separation between parents and children. |
Constructor Summary | |
TreeDrawing()
Constructs a drawing of an empty tree. |
|
TreeDrawing(Node root,
TreeDrawing[] children)
Constructs a drawing of a tree with the given root and children. |
|
TreeDrawing(TreeInterface tree,
int maxHeight)
Constructs a drawing of the given tree. |
|
TreeDrawing(TreeInterface tree,
int maxHeight,
Colorizer col)
Constructs a colorized drawing of the given tree. |
Method Summary | |
TreeComponent |
getDrawing()
Returns a TreeComponent displaying this drawing using TreeComponent.DEFAULT_FONT . |
TreeComponent |
getDrawing(Font fnt)
Returns a TreeComponent displaying this drawing using the given Font. |
int |
getHeight()
Returns the height of this tree in text lines. |
int |
getWidth()
Returns the width of this tree in characters. |
void |
paint(Graphics g)
Paints the TreeDrawing on the given graphics context. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int HORIZONTAL_SEPARATION
public static final int VERTICAL_SEPARATION
public static final char STANDARD_CHARACTER
Constructor Detail |
public TreeDrawing()
public TreeDrawing(Node root, TreeDrawing[] children)
root
- a drawing of the root without borderschildren
- drawings of each of the children
NullPointerException
- if either argument is nullpublic TreeDrawing(TreeInterface tree, int maxHeight)
tree
- The tree to be drawnmaxHeight
- The maximum height to display. If this value is
negative, no nodes will be displayed.String.valueOf(Object)
public TreeDrawing(TreeInterface tree, int maxHeight, Colorizer col)
tree
- The tree to be drawn. If null, no tree is
drawn.maxHeight
- The maximum height to display. If this value is
negative, no nodes will be displayed.col
- The Colorizer used to obtain the color of each node.
If null, each node is colored black.
RuntimeException
- if col throws a RuntimeException on
any node of treeString.valueOf(Object)
Method Detail |
public int getWidth()
public int getHeight()
public TreeComponent getDrawing()
TreeComponent.DEFAULT_FONT
.
public TreeComponent getDrawing(Font fnt) throws NullPointerException
NullPointerException
- if fnt is nullpublic void paint(Graphics g)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |