Class ::tycho::EditForest


Inherits: ::tycho::EditDAG - Source File - Contents: itk_options - public methods - protected methods
A forest is a data structure that includes any number of trees. A tree is a data structure with nodes that are either a root or have exactly one parent, and that have any number of children. This class provides a widget to interactively build, view, and edit such a data structure. The forest is displayed in outline form with root nodes listed alphabetically at the left of the canvas and children below each parent, indented, and also organized alphabetically. The alphabetical ordering is based on the node name, which may not be the label that is displayed.

This class is meant to serve as a base class for such tools as class browsers for object-oriented languages, program structure displays for hierarchical programs, navigation maps for hypertext documents, etc. The EditForest top-level window class provides a convenient container for this widget.

Data stored on the nodes of the trees are (almost) arbitrary strings. The only constraint is that there for every open brace "{" there must be a close brace "}". I.e., the string must be recognizable as a Tcl list. However, if the data takes a certain form, then the display and behavior of the editor can be controlled very precisely. In particular, the contents of the node can be a list, with items in the list being lists lists of the form "{keyword value}". The following keywords are currently understood:

label
The value field gives the label used to show the node in the display. If this is not present, then the node name is used.
color
The value field gives the color used to show the node in the display. If this is not present, then the node color is black. The color name is processed to make sure it is valid, and if not, black is used.
font
The value field gives the font used to show the node in the display. If this is not present, then the default variable-spacing font is chosen. The value can take any form understood by the getFont method of the FontManager class.
link
The value field gives a list with two elements, a filename and a point within the file, in the standard Tycho hyperlink format. Double clicking on the node will activate the hyperlink. The filename may be absolute or relative, and may begin with an environment variable (such as $TYCHO), or a user directory (~username). If the filename is relative, then the reference directory is that of the file of the top-level editor that contains this EditForest. The point may be a string identifying a named anchor in an HTML file, or "{line linenumber}" or "{range start end}" for text files, or any other destination that is understood by the seeFragment method of the widget that will display the hyperlink.
html
The value field gives HTML source code that will be rendered and displayed in a message window in response to a double click on the node. If both this field and the "link" field are given, then both will be activated by a double click.

Here is an example of how to use the EditForest:

    ::tycho::view EditForest

The widget has a number of options. The -graph option gives the name of an object of type Forest to display and edit. If it is not given, the widget creates its own object of type Forest, and destroys that object on exiting. The -indent option gives the indentation of children with respect to their parents (in pixels, default 30). The -readonly option disables changes, making the widget a display only. The -vertspacing option gives the vertical spacing as a multiplier of the height of the font(s). The -startx and -starty options gives the position of the upper left corner of the first node (in pixels, default 10 and 5). This upper left corner will be placed below the title information, if there is any.

Below is an example:

   catch {delete object ff}
   ::tycho::Forest ff
   ff add a {label {A Node} color red font {times 16 bold r}}
   ff add b {label {B Node} color green}
   ff add c {label {C Node} font {times 40 bold r}}
   ff add d {label {D Node}}
   ff roots
   ff add e {e e} b
   set descr [ff describe]
   set view [::tycho::view EditForest [list -graph ff]]
   set win [$view displayer windowName]
   wm deiconify $win
.

Itk_options

-indent 30
Default horizontal offset for children (in pixels).
-vertspacing 1.2
Default vertical spacing (as a multiplier of font height).

Public constructs

Public Methods

contract node
Close the specified node, hiding its children.
help
Open a help window.
expand node
Open the specified node showing its children.
redrawGraph
Redraw the forest. FIXME: Merge with base class version, allowing vertical or horizontal aspects in both cases.

Protected constructs

Protected Methods

drawParentLines node
Disabled.
drawSubgraph root xcoord ycoord {pntloc {}}
Draw a subtree rooted at the given root started at the given position. Return a list with the ycoordinate of the next space below this subtree (for vertically stacking trees) and the next space to the right of the subtree (for horizontally stacking them).
drawSubgraphVertically root xcoord
Disabled.
structClass
Return the name of the data structure class being edited.

Index of classes



Author: Edward A. Lee
Version: @(#)EditForest.itcl 1.16 12/14/96
Copyright: (c) 1995-1996 The Regents of the University of California.