com.jgraph.example
Class GraphTreeModel

java.lang.Object
  extended by javax.swing.tree.DefaultTreeModel
      extended by com.jgraph.example.GraphTreeModel
All Implemented Interfaces:
java.io.Serializable, java.util.EventListener, javax.swing.tree.TreeModel, org.jgraph.event.GraphModelListener

public class GraphTreeModel
extends javax.swing.tree.DefaultTreeModel
implements org.jgraph.event.GraphModelListener

JGraph gives you the opportunity to define whatever graph model you want. Since trees are only special cases of graph, we will here show a fairly simple new graph model: a tree model. So we build a new type inheriting most of its behavior from DefaultTreeModel and adding the minimal requirements to be a GraphModel also. To achieve this, we hold a GraphModel reference in GraphModelTreeNode which implements TreeModel and we use GraphModelTreeNode as the TreeModel to construct the DefaultTreeModel. Finally, don't believe graph models are limited to trees. Rather the GraphModel interface provides you lots of hooks to detail your model. For instance you could define custome implemetations to decide wether or not some connections are allowed...

See Also:
Serialized Form

Nested Class Summary
static class GraphTreeModel.GraphModelTreeNode
           
 
Constructor Summary
GraphTreeModel(org.jgraph.graph.GraphModel model)
          Look how we wrapp the GraphModel into a GraphModelTreeNode to construct the GraphTreeModel and satisfy both the GraphModel and the TreeModel interfaces.
 
Method Summary
 void graphChanged(org.jgraph.event.GraphModelEvent e)
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, getChild, getChildCount, getIndexOfChild, getListeners, getPathToRoot, getRoot, getTreeModelListeners, insertNodeInto, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeNodeFromParent, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphTreeModel

public GraphTreeModel(org.jgraph.graph.GraphModel model)
Look how we wrapp the GraphModel into a GraphModelTreeNode to construct the GraphTreeModel and satisfy both the GraphModel and the TreeModel interfaces.

Parameters:
model -
Method Detail

main

public static void main(java.lang.String[] args)

graphChanged

public void graphChanged(org.jgraph.event.GraphModelEvent e)
Specified by:
graphChanged in interface org.jgraph.event.GraphModelListener