Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.greenstone.gatherer.util
Class SynchronizedTreeModel  view SynchronizedTreeModel download SynchronizedTreeModel.java

java.lang.Object
  extended byjavax.swing.tree.DefaultTreeModel
      extended byorg.greenstone.gatherer.util.SynchronizedTreeModel
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable, javax.swing.tree.TreeModel

public class SynchronizedTreeModel
extends javax.swing.tree.DefaultTreeModel
implements java.lang.Runnable

This synchronized TreeModel is comprised of two seperate models. The extended model is used to paint the screen, and can only be updated on the AWTEvent Thread. The second, private, model contains the current actual state of the model with changes made immediately. If such changes occur then a task is queued in the AWTEvent Thread to update the 'painted' model. This model depends on the TreeNodes used having these properties: TreeNode x_node = new TreeNode("x"); TreeNode y_node = x_node.cloneNode(); for(int i = 0; i < x_node.getChildCount(); i++) { x_node.getChildAt(i) != y_node.getChildAt(i); x_node.getChildAt(i).equals(y_node.getChildAt(i)); } x_node != y_node; (new TreeNode("x")).equals(new TreeNode("x")); In other words, any two different instances of the tree node must be equal according to the equals method. Methods which need data from the tree should also use the model methods (ie model.getChildCount(node) rather than node.getChildCount()) and should not be in the AWTEvent Thread (as such calls will see the possibly out of date 'visual' model, not the actual underlying model).


Field Summary
private  boolean changed
           
private  javax.swing.tree.DefaultTreeModel offscreen
           
private  TreeModelTest test
           
 
Fields inherited from class javax.swing.tree.DefaultTreeModel
asksAllowsChildren, listenerList, root
 
Constructor Summary
(package private) SynchronizedTreeModel(SynchronizedTreeNode root)
           
(package private) SynchronizedTreeModel(SynchronizedTreeNode root, TreeModelTest test)
           
 
Method Summary
 java.lang.Object getChild(java.lang.Object parent, int index)
          Returns the child of parent at index index in the parent's child array.
 int getChildCount(java.lang.Object parent)
          Returns the number of children of parent.
 javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
          Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.
 java.lang.Object getRoot()
          getRoot
 void insertNodeInto(javax.swing.tree.MutableTreeNode newChild, javax.swing.tree.MutableTreeNode parent, int index)
          Invoked this to insert newChild at location index in parents children.
private  boolean isEventThread()
          Determine if this call is happening on the AWTEvent Dispatch Thread.
private  void queueUpdate()
           
 void removeNodeFromParent(javax.swing.tree.MutableTreeNode node)
          Message this to remove node from its parent.
 void run()
          This method will be called by whoever wishes to run your class implementing Runnable.
 
Methods inherited from class javax.swing.tree.DefaultTreeModel
addTreeModelListener, asksAllowsChildren, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeStructureChanged, getIndexOfChild, getListeners, getPathToRoot, getTreeModelListeners, isLeaf, nodeChanged, nodesChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, reload, reload, removeTreeModelListener, setAsksAllowsChildren, setRoot, valueForPathChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changed

private boolean changed

offscreen

private javax.swing.tree.DefaultTreeModel offscreen

test

private TreeModelTest test
Constructor Detail

SynchronizedTreeModel

SynchronizedTreeModel(SynchronizedTreeNode root)

SynchronizedTreeModel

SynchronizedTreeModel(SynchronizedTreeNode root,
                      TreeModelTest test)
Method Detail

getChild

public java.lang.Object getChild(java.lang.Object parent,
                                 int index)
Returns the child of parent at index index in the parent's child array.

Specified by:
getChild in interface javax.swing.tree.TreeModel

getChildCount

public int getChildCount(java.lang.Object parent)
Returns the number of children of parent.

Specified by:
getChildCount in interface javax.swing.tree.TreeModel

getPathToRoot

public javax.swing.tree.TreeNode[] getPathToRoot(javax.swing.tree.TreeNode aNode)
Builds the parents of node up to and including the root node, where the original node is the last element in the returned array. This is probably the most 'expensive' method we make synchronized, but it isn't called often so thats ok.


getRoot

public java.lang.Object getRoot()
Description copied from class: javax.swing.tree.DefaultTreeModel
getRoot

Specified by:
getRoot in interface javax.swing.tree.TreeModel

insertNodeInto

public void insertNodeInto(javax.swing.tree.MutableTreeNode newChild,
                           javax.swing.tree.MutableTreeNode parent,
                           int index)
Invoked this to insert newChild at location index in parents children.


removeNodeFromParent

public void removeNodeFromParent(javax.swing.tree.MutableTreeNode node)
Message this to remove node from its parent.


run

public void run()
Description copied from interface: java.lang.Runnable
This method will be called by whoever wishes to run your class implementing Runnable. Note that there are no restrictions on what you are allowed to do in the run method, except that you cannot throw a checked exception.

Specified by:
run in interface java.lang.Runnable

isEventThread

private boolean isEventThread()
Determine if this call is happening on the AWTEvent Dispatch Thread.


queueUpdate

private void queueUpdate()