public class NodeTreeManager extends Object implements NodeListener
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.
NodeTreePanel
,
NodeWatcher
Modifier and Type | Field and Description |
---|---|
boolean |
VERBOSE
Set this to
true for debugging
the incoming node notifications and tree model updates |
Constructor and Description |
---|
NodeTreeManager(NodeWatcher nw) |
NodeTreeManager(NodeWatcher nw,
Node rootNode)
Creates a new
NodeTreeManager for a given
NodeWatcher instance and root Node . |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Disposes all resources associated with the tree
manager.
|
static void |
dumpTree(PrintStream stream,
TreeNode rootNode)
Dumps a list of nodes to the given stream.
|
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) |
public boolean VERBOSE
true
for debugging
the incoming node notifications and tree model updatespublic NodeTreeManager(NodeWatcher nw, Node rootNode)
NodeTreeManager
for a given
NodeWatcher
instance and root Node
.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()
.public NodeTreeManager(NodeWatcher nw)
public void setRoot(Node rootNode)
public void dispose()
dispose
on
the node watcher.public TreeModel getModel()
TreeModel
suitable to
creating a JTree
gadget.public static void dumpTree(PrintStream stream, TreeNode rootNode)
stream
- a stream to print on, such as System.err
rootNode
- the top element of the tree, or null
(no action)public void nodeAction(NodeEvent e)
NodeListener
interface.
Do not call this method.nodeAction
in interface NodeListener
e
- the event describing the type of change and
the node's context.Copyright © 2015–2022 SciJava. All rights reserved.