de.sciss.jcollider.gui
Class NodeTreeManager

java.lang.Object
  extended by de.sciss.jcollider.gui.NodeTreeManager
All Implemented Interfaces:
NodeListener

public class NodeTreeManager
extends java.lang.Object
implements NodeListener

A class that helps to set up a JTree with a view of a node graph. Since Node already implements the TreeNode interface, what we do here is to install a NodeListener on a provided NodeWatcher and keep a TreeModel up-to-date. In many cases you will not need to set up a JTree yourself, but simply create an instance of NodeTreePanel.

Because of the asynchronous nature of node manipulation, we have decided to not use the MutableTreeNode interface which cannot account for method failures, for example. The proposed implementation therefore is, to call the node's methods like free or run directly, and the tree will be updated as soon as the "/n_go", "/n_off" etc. messages arrive.

Version:
0.31, 08-Oct-07
Author:
Hanns Holger Rutz
See Also:
NodeTreePanel, NodeWatcher
Todo:
seems to miss /n_end when fired very quickly after /n_go ...

Field Summary
 boolean VERBOSE
          Set this to true for debugging the incoming node notifications and tree model updates
 
Constructor Summary
NodeTreeManager(NodeWatcher nw)
           
NodeTreeManager(NodeWatcher nw, Node rootNode)
          Creates a new NodeTreeManager for a given NodeWatcher instance and root Node.
 
Method Summary
 void dispose()
          Disposes all resources associated with the tree manager.
static void dumpTree(java.io.PrintStream stream, javax.swing.tree.TreeNode rootNode)
          Dumps a list of nodes to the given stream.
 javax.swing.tree.TreeModel getModel()
          Returns a TreeModel suitable to creating a JTree gadget.
 void nodeAction(NodeEvent e)
          This method is part of the NodeListener interface.
 void setRoot(Node rootNode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERBOSE

public boolean VERBOSE
Set this to true for debugging the incoming node notifications and tree model updates

Constructor Detail

NodeTreeManager

public NodeTreeManager(NodeWatcher nw,
                       Node rootNode)
Creates a new NodeTreeManager for a given NodeWatcher instance and root Node.

Parameters:
nw - the nodewatcher to listen to for node updates. the tree manager copies the current list of registered nodes from the watcher and continuously updates the tree when node notfication messages arrive.
rootNode - the supposed root element in the tree display. can be something like server.getDefaultGroup().

NodeTreeManager

public NodeTreeManager(NodeWatcher nw)
Method Detail

setRoot

public void setRoot(Node rootNode)

dispose

public void dispose()
Disposes all resources associated with the tree manager. This clears the node backup list and stops listening to the node watcher. Call this method before calling dispose on the node watcher.


getModel

public javax.swing.tree.TreeModel getModel()
Returns a TreeModel suitable to creating a JTree gadget.

Returns:
a tree model that reflects the node graph monitored by this manager

dumpTree

public static void dumpTree(java.io.PrintStream stream,
                            javax.swing.tree.TreeNode rootNode)
Dumps a list of nodes to the given stream. Starts at the provided root node and traverses all child elements. Usefull for debugging.

Parameters:
stream - a stream to print on, such as System.err
rootNode - the top element of the tree, or null (no action)

nodeAction

public void nodeAction(NodeEvent e)
This method is part of the NodeListener interface. Do not call this method.

Specified by:
nodeAction in interface NodeListener
Parameters:
e - the event describing the type of change and the node's context.