edu.princeton.wordnet.browser.tree
Class LazyDefaultMutableTreeNode

java.lang.Object
  extended by javax.swing.tree.DefaultMutableTreeNode
      extended by edu.princeton.wordnet.browser.tree.LazyDefaultMutableTreeNode
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode
Direct Known Subclasses:
LinksTreeNode

public abstract class LazyDefaultMutableTreeNode
extends javax.swing.tree.DefaultMutableTreeNode

Lazy loading default mutable node

Author:
Thierry LEFORT 3 mars 08, Bernard BOU
See Also:
Serialized Form

Nested Class Summary
protected static class LazyDefaultMutableTreeNode.CancelWorkersAction
          ActionMap can only store one Action for the same key, This Action Stores the list of SwingWorker to be canceled if the escape key is pressed.
 
Field Summary
private static java.lang.String ESCAPE_ACTION_NAME
           
private static javax.swing.KeyStroke ESCAPE_KEY
           
private static long serialVersionUID
           
static boolean suicide
          Whether parent node kills itself when expanded to children
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
LazyDefaultMutableTreeNode()
          Default Constructor
 
Method Summary
protected  boolean areChildrenLoaded()
          Whether children are loaded
protected  javax.swing.tree.MutableTreeNode createLoadingNode()
          Create loading node
protected  javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],java.lang.Void> createSwingWorker(javax.swing.JTree thisTree)
          Create worker that will load the nodes
 boolean isLeaf()
          Whether the node is leaf
 void load(javax.swing.JTree thisTree)
          Perform the loading
abstract  javax.swing.tree.MutableTreeNode[] loadChildren(javax.swing.JTree thisTree)
          This method will be executed in a background thread.
protected  void registerSwingWorkerForCancel(javax.swing.JTree thisTree, javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],?> thisWorker)
          If the node is cancelable, an escape Action is registered in the tree's InputMap and ActionMap that will cancel the execution
protected  void reset(javax.swing.JTree thisTree)
          Reset node
protected  void setChildren(javax.swing.JTree thisTree, javax.swing.tree.MutableTreeNode... theseChildren)
          Define node children
private  void setLoading(javax.swing.JTree thisTree)
          Set the loading state
protected  void setSiblings(javax.swing.JTree thisTree, javax.swing.tree.MutableTreeNode... theseSiblings)
          Define siblings and suicide
protected  void unRegisterSwingWorkerForCancel(javax.swing.JTree thisTree, javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],?> thisWorker)
          Remove the swingWorker from the cancelable task of the tree
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPathToRoot, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObject, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

suicide

public static boolean suicide
Whether parent node kills itself when expanded to children


ESCAPE_ACTION_NAME

private static final java.lang.String ESCAPE_ACTION_NAME
See Also:
Constant Field Values

ESCAPE_KEY

private static final javax.swing.KeyStroke ESCAPE_KEY
Constructor Detail

LazyDefaultMutableTreeNode

public LazyDefaultMutableTreeNode()
Default Constructor

Method Detail

loadChildren

public abstract javax.swing.tree.MutableTreeNode[] loadChildren(javax.swing.JTree thisTree)
This method will be executed in a background thread.

Parameters:
thisTree - tree
Returns:
the Created nodes

load

public void load(javax.swing.JTree thisTree)
Perform the loading

Parameters:
thisTree - tree (needed to perform changes)

setSiblings

protected void setSiblings(javax.swing.JTree thisTree,
                           javax.swing.tree.MutableTreeNode... theseSiblings)
Define siblings and suicide

Parameters:
thisTree - tree
theseSiblings - new sibling nodes

setChildren

protected void setChildren(javax.swing.JTree thisTree,
                           javax.swing.tree.MutableTreeNode... theseChildren)
Define node children

Parameters:
thisTree - tree
theseChildren - new children nodes

isLeaf

public boolean isLeaf()
Whether the node is leaf

Specified by:
isLeaf in interface javax.swing.tree.TreeNode
Overrides:
isLeaf in class javax.swing.tree.DefaultMutableTreeNode
Returns:
false, this node can't be a leaf

areChildrenLoaded

protected boolean areChildrenLoaded()
Whether children are loaded

Returns:
true if there are some children

createLoadingNode

protected javax.swing.tree.MutableTreeNode createLoadingNode()
Create loading node

Returns:
a new loading node

setLoading

private void setLoading(javax.swing.JTree thisTree)
Set the loading state


reset

protected void reset(javax.swing.JTree thisTree)
Reset node


createSwingWorker

protected javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],java.lang.Void> createSwingWorker(javax.swing.JTree thisTree)
Create worker that will load the nodes

Parameters:
thisTree - tree
Returns:
the newly created SwingWorker

registerSwingWorkerForCancel

protected void registerSwingWorkerForCancel(javax.swing.JTree thisTree,
                                            javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],?> thisWorker)
If the node is cancelable, an escape Action is registered in the tree's InputMap and ActionMap that will cancel the execution

Parameters:
thisTree - tree
thisWorker - the worker to cancel

unRegisterSwingWorkerForCancel

protected void unRegisterSwingWorkerForCancel(javax.swing.JTree thisTree,
                                              javax.swing.SwingWorker<javax.swing.tree.MutableTreeNode[],?> thisWorker)
Remove the swingWorker from the cancelable task of the tree

Parameters:
thisTree - tree
thisWorker - worker thread