Public Member Functions | |
TreeDrawing () | |
Constructs a drawing of an empty tree. | |
TreeDrawing (ITree tree, int maxHeight) | |
Constructs a drawing of the given tree. | |
TreeDrawing (ITree tree, int maxHeight, IColorizer col) | |
Constructs a colorized drawing of the given tree. | |
IEnumerator | GetEnumerator () |
Returns an IEnumerator giving the children, in order. | |
TreePanel | GetDrawing () |
Returns a TreePanel displaying this drawing using TreePanel.DefaultFont. | |
TreePanel | GetDrawing (Font fnt) |
Returns a TreePanel displaying this drawing using the given Font. | |
Public Attributes | |
const int | HorizontalSeparation = 1 |
The width in characters of the horizontal separation between two nodes. | |
const int | VerticalSeparation = 1 |
The height in lines of text of the vertical separation between parents and children. | |
Properties | |
string | Root [get] |
The root of the tree. | |
int | Width [get] |
The width of this tree in characters. | |
int | Height [get] |
The height of this tree in text lines. | |
int | RootWidth [get] |
The width of the root in characters. | |
int | ChildrenWidth [get] |
The total width of the children in characters. | |
Color | RootColor [get] |
The color of the root. |
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 using a given font.
A TreeDrawing can be constructed from an implementation of ITree and optionally an implementation of IColorizer. 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 TreePanel containing a graphical representation can be efficiently obtained from either the GetDrawing() or the GetDrawing(Font) method. These methods return a new TreePanel each time they are 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.
The children, each of which is a TreeDrawing, can be obtained using the GetEnumerator() method. This method returns a System.Collections.IEnumerator of the children. This method allows a C# foreach
construct to iterate through the chidlren.
TreeDrawing | ( | ) |
Constructs a drawing of an empty tree.
TreeDrawing | ( | ITree | tree, | |
int | maxHeight | |||
) |
Constructs a drawing of the given tree.
The foreground of the drawing is black. The contents of nodes are obtained using the System.Object.ToString() method. If the root of the tree is null, the string "null" is used.
tree | The tree to be drawn | |
maxHeight | The maximum height to display. If this value is negative, no nodes will be displayed. |
TreeDrawing | ( | ITree | tree, | |
int | maxHeight, | |||
IColorizer | col | |||
) |
Constructs a colorized drawing of the given tree.
The contents of nodes are obtained using the System.Object.ToString() method. If the root of the tree is null, the string "null" is used.
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 IColorizer used to obtain the color of each node. If null, each node is colored black. |
IEnumerator GetEnumerator | ( | ) |
Returns an IEnumerator giving the children, in order.
Each element in the System.Collections.IEnumerator is a TreeDrawing.
TreePanel GetDrawing | ( | ) |
Returns a TreePanel displaying this drawing using TreePanel.DefaultFont.
TreePanel GetDrawing | ( | Font | fnt | ) |
Returns a TreePanel displaying this drawing using the given Font.
NullReferenceException | if fnt is null |
const int HorizontalSeparation = 1 |
The width in characters of the horizontal separation between two nodes.
const int VerticalSeparation = 1 |
The height in lines of text of the vertical separation between parents and children.
string Root [get] |
The root of the tree.
int Width [get] |
The width of this tree in characters.
int Height [get] |
The height of this tree in text lines.
int RootWidth [get] |
The width of the root in characters.
int ChildrenWidth [get] |
The total width of the children in characters.
Color RootColor [get] |