TkTreeWidget

Guido Tack

A tree drawing widget for Mozart/Tk


The TkTreeWidget provides a class TreeWidget (derived from Tk.frame) that can be used to draw trees (what a surprise!).
The tree layout algorithm is borrowed from the Oz Explorer.

Usage

The TreeWidget has to be created by calling something like
MyTreeWidget = {New {MakeTreeWidget Helper}}
The Helper contains all the information you want to provide about what your nodes should look like. You can find the specification for a helper here. The creation of the widget and an example helper can be found in the examples subdirectory.

For the nodes the tree is built of, the object oriented syntax of Oz has been used. That means that the tree you want to display must be built of objects of some node class. The TreeWidget provides a node class that your objects must inherit (it contains all the necessary methods for layout and visualization).
In addition, your nodes have to match a certain interface:
Every node must provide a getChildren($) - Method.

In the examples subdirectory you will find a functor in the file node.oz that you can use as a skeleton for your node class.

Drawing the tree is then easy - just call
{MyTreeWidget redrawTree(RootNode)}
with the root node of your tree as an argument.

The layout and drawing work incrementally. That means that you can built a partial tree, display it, and then add subtrees. These changes can only be displayed if you tell the TreeWidget so! This is how you can do that:
For every new node N, call
{N dirtyUp}
(which marks the new node and all its parents as "dirty" - to be redrawn.) Then call
{MyTreeWidget redrawTree(RootNode)} again - thats it!

There are several other things you can do with nodes, e.g. hide subtrees, select nodes etc. Please take a look at the examples that make use of all the features.


Guido Tack
Last modified: Thu May 2 20:47:02 CEST 2002