.useful Home Page

org.dotuseful.ui.tree
Class SortedTreeNode

java.lang.Object
  extended byjavax.swing.tree.DefaultMutableTreeNode
      extended byorg.dotuseful.ui.tree.AutomatedTreeNode
          extended byorg.dotuseful.ui.tree.SortedTreeNode
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, javax.swing.tree.MutableTreeNode, java.io.Serializable, javax.swing.event.TreeModelListener, javax.swing.tree.TreeNode

public class SortedTreeNode
extends AutomatedTreeNode

A tree node which keeps its children sorted. It must be supplied with Comparator by which the list is ordered, or its children must implement Comparable interface.

SortedTreeNode must be notified on its child's change which could have effect on child's sorting order. SortedTreeNode must be notified on change BEFORE some other operation which depend on children order or could have effect on sorting order.

Author:
dkrukovsky
See Also:
Serialized Form

Field Summary
protected  java.util.Comparator comparator
          The Comparator by which the list is ordered.
 
Fields inherited from class org.dotuseful.ui.tree.AutomatedTreeNode
listenerList
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
SortedTreeNode()
          Creates a SortedTreeNode that has no parent and no children, but which allows children.
SortedTreeNode(java.lang.Object userObject)
          Creates a SortedTreeNode node with no parent, no children, but which allows children, and initializes it with the specified user object.
SortedTreeNode(java.lang.Object userObject, boolean allowsChildren)
          Creates a SortedTreeNode with no parent, no children, initialized with the specified user object, and that allows children only if specified.
SortedTreeNode(java.lang.Object userObject, boolean allowsChildren, java.util.Comparator newComparator)
          Creates a SortedTreeNode with no parent, no children, initialized with the specified user object, that allows children only if specified, and sets the comparator by which its children are ordered.
SortedTreeNode(java.lang.Object userObject, java.util.Comparator newComparator)
          Creates a SortedTreeNode node with no parent, no children, but which allows children, initializes it with the specified user object, and sets the comparator by which its children are ordered.
 
Method Summary
 void add(javax.swing.tree.MutableTreeNode newChild)
          Removes newChild from its parent and makes it a child of this node by adding it to this node's child array in a sorted order.
 void setComparator(java.util.Comparator newComparator)
          Sets the comparator for this node to newComparator, and re-sorts children.
protected  void sortChildren(java.lang.Object[] changedChildren)
           Keeps children in sorted order by removing given children and adding them back.
 void treeNodesChanged(javax.swing.event.TreeModelEvent e)
          The node need to re-sort its changed children.
 void treeStructureChanged(javax.swing.event.TreeModelEvent e)
          The node need to re-sort its changed children.
 
Methods inherited from class org.dotuseful.ui.tree.AutomatedTreeNode
addTreeModelListener, fireTreeNodesChanged, fireTreeNodesChanged, fireTreeNodesChanged, fireTreeNodesInserted, fireTreeNodesInserted, fireTreeNodesRemoved, fireTreeNodesRemoved, fireTreeStructureChanged, fireTreeStructureChanged, fireTreeStructureChanged, insert, nodeChanged, nodeStructureChanged, nodesWereInserted, nodesWereRemoved, remove, removeTreeModelListener, setUserObject, treeNodesInserted, treeNodesRemoved
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
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, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comparator

protected java.util.Comparator comparator
The Comparator by which the list is ordered.

Constructor Detail

SortedTreeNode

public SortedTreeNode()
Creates a SortedTreeNode that has no parent and no children, but which allows children. Its children must implement Comparable interface if no comparator is set.


SortedTreeNode

public SortedTreeNode(java.lang.Object userObject)
Creates a SortedTreeNode node with no parent, no children, but which allows children, and initializes it with the specified user object. Its children must implement Comparable interface if no comparator is set.

Parameters:
userObject - an Object provided by the user that constitutes the node's data

SortedTreeNode

public SortedTreeNode(java.lang.Object userObject,
                      boolean allowsChildren)
Creates a SortedTreeNode with no parent, no children, initialized with the specified user object, and that allows children only if specified. Its children must implement Comparable interface if no comparator is set.

Parameters:
userObject - an Object provided by the user that constitutes the node's data
allowsChildren - if true, the node is allowed to have child nodes -- otherwise, it is always a leaf node

SortedTreeNode

public SortedTreeNode(java.lang.Object userObject,
                      java.util.Comparator newComparator)
Creates a SortedTreeNode node with no parent, no children, but which allows children, initializes it with the specified user object, and sets the comparator by which its children are ordered.

Parameters:
userObject - an Object provided by the user that constitutes the node's data
newComparator - The comparator by which its children are ordered. A null value indicates that the elements' natural ordering should be used.

SortedTreeNode

public SortedTreeNode(java.lang.Object userObject,
                      boolean allowsChildren,
                      java.util.Comparator newComparator)
Creates a SortedTreeNode with no parent, no children, initialized with the specified user object, that allows children only if specified, and sets the comparator by which its children are ordered.

Parameters:
userObject - an Object provided by the user that constitutes the node's data
allowsChildren - if true, the node is allowed to have child nodes -- otherwise, it is always a leaf node
newComparator - The comparator by which its children are ordered. A null value indicates that the elements' natural ordering should be used.
Method Detail

setComparator

public void setComparator(java.util.Comparator newComparator)
Sets the comparator for this node to newComparator, and re-sorts children.

Parameters:
newComparator - The comparator to set.

add

public void add(javax.swing.tree.MutableTreeNode newChild)
Removes newChild from its parent and makes it a child of this node by adding it to this node's child array in a sorted order.

Parameters:
newChild - node to add as a child of this node
Throws:
java.lang.IllegalArgumentException - if newChild is null
java.lang.IllegalStateException - if this node does not allow children
See Also:
AutomatedTreeNode.insert(javax.swing.tree.MutableTreeNode, int)

treeNodesChanged

public void treeNodesChanged(javax.swing.event.TreeModelEvent e)
The node need to re-sort its changed children.

Specified by:
treeNodesChanged in interface javax.swing.event.TreeModelListener
Overrides:
treeNodesChanged in class AutomatedTreeNode

treeStructureChanged

public void treeStructureChanged(javax.swing.event.TreeModelEvent e)
The node need to re-sort its changed children.

Specified by:
treeStructureChanged in interface javax.swing.event.TreeModelListener
Overrides:
treeStructureChanged in class AutomatedTreeNode

sortChildren

protected void sortChildren(java.lang.Object[] changedChildren)

Keeps children in sorted order by removing given children and adding them back.


© 2004 .useful community

SourceForge.net-Logo