javax.swing.tree
Class FixedHeightLayoutCache.FHTreeStateNode

java.lang.Object
  extended byjavax.swing.tree.DefaultMutableTreeNode
      extended byjavax.swing.tree.FixedHeightLayoutCache.FHTreeStateNode
All Implemented Interfaces:
Cloneable, MutableTreeNode, Serializable, TreeNode
Enclosing class:
FixedHeightLayoutCache

private class FixedHeightLayoutCache.FHTreeStateNode
extends DefaultMutableTreeNode

FHTreeStateNode is used to track what has been expanded. FHTreeStateNode differs from VariableHeightTreeState.TreeStateNode in that it is highly model intensive. That is almost all queries to a FHTreeStateNode result in the TreeModel being queried. And it obviously does not support variable sized row heights.


Nested Class Summary
 
Nested classes inherited from class javax.swing.tree.DefaultMutableTreeNode
DefaultMutableTreeNode.BreadthFirstEnumeration, DefaultMutableTreeNode.PathBetweenNodesEnumeration, DefaultMutableTreeNode.PostorderEnumeration, DefaultMutableTreeNode.PreorderEnumeration
 
Field Summary
protected  int childCount
          Child count of the receiver.
protected  int childIndex
          Index of this node from the model.
protected  boolean isExpanded
          Is this node expanded?
protected  TreePath path
          Path of this node.
protected  int row
          Row of the receiver.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
FixedHeightLayoutCache.FHTreeStateNode(Object userObject, int childIndex, int row)
           
 
Method Summary
protected  void addNode(FixedHeightLayoutCache.FHTreeStateNode newChild)
          Adds newChild to this nodes children at the appropriate location.
protected  void adjustChildIndexs(int index, int amount)
          Adjusts the child indexs of the receivers children by amount, starting at index.
protected  void adjustRowBy(int amount)
          Adjusts the receiver, and all its children rows by amount.
protected  void adjustRowBy(int amount, int startIndex)
          Adjusts this node, its child, and its parent starting at an index of index index is the index of the child to start adjusting from, which is not necessarily the model index.
protected  void childInsertedAtModelIndex(int index, boolean isExpandedAndVisible)
          Messaged when a child has been inserted at index.
protected  void collapse(boolean adjustRows)
          Collapses the receiver.
protected  FixedHeightLayoutCache.FHTreeStateNode createChildFor(Object userObject)
          Creates a new node to represent userObject.
protected  void didAdjustTree()
          Messaged when this node either expands or collapses.
protected  void didExpand()
          Messaged when the node has expanded.
protected  void expand()
          Expands the receiver.
protected  void expandParentAndReceiver()
          Invokes expandParentAndReceiver on the parent, and expands the receiver.
 FixedHeightLayoutCache.FHTreeStateNode getChildAtModelIndex(int index)
          Returns the child for the passed in model index, this will return null if the child for index has not yet been created (expanded).
 int getChildIndex()
          Returns the index of the receiver in the model.
protected  int getCountTo(int stopIndex)
          Asks all the children of the receiver for their totalChildCount and returns this value (plus stopIndex).
protected  int getNumExpandedChildrenTo(int stopIndex)
          Returns the number of children that are expanded to stopIndex.
protected  boolean getPathForRow(int row, int nextRow, FixedHeightLayoutCache.SearchInfo info)
          Returns true if there is a row for row.
 int getRow()
          Returns the row of the receiver.
 int getRowToModelIndex(int index)
          Returns the row of the child with a model index of index.
 int getTotalChildCount()
          Returns the number of children in the receiver by descending all expanded nodes and messaging them with getTotalChildCount.
 TreePath getTreePath()
          Returns the TreePath of the receiver.
 int getVisibleLevel()
          The highest visible nodes have a depth of 0.
 boolean isExpanded()
          Returns true if this node is expanded.
 boolean isLeaf()
          Returns true if the receiver is a leaf.
 boolean isVisible()
          Returns true if this node is visible.
protected  void makeVisible()
          Makes the receiver visible, but invoking expandParentAndReceiver on the superclass.
 void remove(int childIndex)
          Messaged when this node is removed from its parent, this messages removedFromMapping to remove all the children.
protected  void removeChildAtModelIndex(int modelIndex, boolean isChildVisible)
          Removes the child at modelIndex.
protected  void removeFromMapping()
          Removes the receiver, and all its children, from the mapping table.
protected  void resetChildrenPaths(TreePath parentPath)
          Recreates the receivers path, and all its childrens paths.
protected  void resetChildrenRowsFrom(int newRow, int childIndex, int modelIndex)
          Resets the receivers childrens rows.
 void setParent(MutableTreeNode parent)
          Messaged when this node is added somewhere, resets the path and adds a mapping from path to this node.
protected  int setRowAndChildren(int nextRow)
          Sets the receivers row to nextRow and recursively updates all the children of the receivers rows.
 void setUserObject(Object o)
          Messaged to set the user object.
 
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, removeAllChildren, removeFromParent, setAllowsChildren, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

isExpanded

protected boolean isExpanded
Is this node expanded?


childIndex

protected int childIndex
Index of this node from the model.


childCount

protected int childCount
Child count of the receiver.


row

protected int row
Row of the receiver. This is only valid if the row is expanded.


path

protected TreePath path
Path of this node.

Constructor Detail

FixedHeightLayoutCache.FHTreeStateNode

public FixedHeightLayoutCache.FHTreeStateNode(Object userObject,
                                              int childIndex,
                                              int row)
Method Detail

setParent

public void setParent(MutableTreeNode parent)
Messaged when this node is added somewhere, resets the path and adds a mapping from path to this node.

Specified by:
setParent in interface MutableTreeNode
Overrides:
setParent in class DefaultMutableTreeNode
Parameters:
parent - this node's new parent

remove

public void remove(int childIndex)
Messaged when this node is removed from its parent, this messages removedFromMapping to remove all the children.

Specified by:
remove in interface MutableTreeNode
Overrides:
remove in class DefaultMutableTreeNode
Parameters:
childIndex - the index in this node's child array of the child to remove

setUserObject

public void setUserObject(Object o)
Messaged to set the user object. This resets the path.

Specified by:
setUserObject in interface MutableTreeNode
Overrides:
setUserObject in class DefaultMutableTreeNode
Parameters:
o - the Object that constitutes this node's user-specified data
See Also:
DefaultMutableTreeNode.getUserObject(), DefaultMutableTreeNode.toString()

getChildIndex

public int getChildIndex()
Returns the index of the receiver in the model.


getTreePath

public TreePath getTreePath()
Returns the TreePath of the receiver.


getChildAtModelIndex

public FixedHeightLayoutCache.FHTreeStateNode getChildAtModelIndex(int index)
Returns the child for the passed in model index, this will return null if the child for index has not yet been created (expanded).


isVisible

public boolean isVisible()
Returns true if this node is visible. This is determined by asking all the parents if they are expanded.


getRow

public int getRow()
Returns the row of the receiver.


getRowToModelIndex

public int getRowToModelIndex(int index)
Returns the row of the child with a model index of index.


getTotalChildCount

public int getTotalChildCount()
Returns the number of children in the receiver by descending all expanded nodes and messaging them with getTotalChildCount.


isExpanded

public boolean isExpanded()
Returns true if this node is expanded.


getVisibleLevel

public int getVisibleLevel()
The highest visible nodes have a depth of 0.


resetChildrenPaths

protected void resetChildrenPaths(TreePath parentPath)
Recreates the receivers path, and all its childrens paths.


removeFromMapping

protected void removeFromMapping()
Removes the receiver, and all its children, from the mapping table.


createChildFor

protected FixedHeightLayoutCache.FHTreeStateNode createChildFor(Object userObject)
Creates a new node to represent userObject. This does NOT check to ensure there isn't already a child node to manage userObject.


adjustRowBy

protected void adjustRowBy(int amount)
Adjusts the receiver, and all its children rows by amount.


adjustRowBy

protected void adjustRowBy(int amount,
                           int startIndex)
Adjusts this node, its child, and its parent starting at an index of index index is the index of the child to start adjusting from, which is not necessarily the model index.


didExpand

protected void didExpand()
Messaged when the node has expanded. This updates all of the receivers children rows, as well as the total row count.


setRowAndChildren

protected int setRowAndChildren(int nextRow)
Sets the receivers row to nextRow and recursively updates all the children of the receivers rows. The index the next row is to be placed as is returned.


resetChildrenRowsFrom

protected void resetChildrenRowsFrom(int newRow,
                                     int childIndex,
                                     int modelIndex)
Resets the receivers childrens rows. Starting with the child at childIndex (and modelIndex) to newRow. This uses setRowAndChildren to recursively descend children, and uses resetRowSelection to ascend parents.


makeVisible

protected void makeVisible()
Makes the receiver visible, but invoking expandParentAndReceiver on the superclass.


expandParentAndReceiver

protected void expandParentAndReceiver()
Invokes expandParentAndReceiver on the parent, and expands the receiver.


expand

protected void expand()
Expands the receiver.


collapse

protected void collapse(boolean adjustRows)
Collapses the receiver. If adjustRows is true, the rows of nodes after the receiver are adjusted.


isLeaf

public boolean isLeaf()
Returns true if the receiver is a leaf.

Specified by:
isLeaf in interface TreeNode
Overrides:
isLeaf in class DefaultMutableTreeNode
Returns:
true if this node has no children
See Also:
DefaultMutableTreeNode.getAllowsChildren()

addNode

protected void addNode(FixedHeightLayoutCache.FHTreeStateNode newChild)
Adds newChild to this nodes children at the appropriate location. The location is determined from the childIndex of newChild.


removeChildAtModelIndex

protected void removeChildAtModelIndex(int modelIndex,
                                       boolean isChildVisible)
Removes the child at modelIndex. isChildVisible should be true if the receiver is visible and expanded.


adjustChildIndexs

protected void adjustChildIndexs(int index,
                                 int amount)
Adjusts the child indexs of the receivers children by amount, starting at index.


childInsertedAtModelIndex

protected void childInsertedAtModelIndex(int index,
                                         boolean isExpandedAndVisible)
Messaged when a child has been inserted at index. For all the children that have a childIndex >= index their index is incremented by one.


getPathForRow

protected boolean getPathForRow(int row,
                                int nextRow,
                                FixedHeightLayoutCache.SearchInfo info)
Returns true if there is a row for row. nextRow gives the bounds of the receiver. Information about the found row is returned in info. This should be invoked on root with nextRow set to getRowCount().


getCountTo

protected int getCountTo(int stopIndex)
Asks all the children of the receiver for their totalChildCount and returns this value (plus stopIndex).


getNumExpandedChildrenTo

protected int getNumExpandedChildrenTo(int stopIndex)
Returns the number of children that are expanded to stopIndex. This does not include the number of children that the child at stopIndex might have.


didAdjustTree

protected void didAdjustTree()
Messaged when this node either expands or collapses.