javax.swing.tree
Class VariableHeightLayoutCache.TreeStateNode

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

private class VariableHeightLayoutCache.TreeStateNode
extends DefaultMutableTreeNode

TreeStateNode is used to keep track of each of the nodes that have been expanded. This will also cache the preferred size of the value it represents.


Nested Class Summary
 
Nested classes inherited from class javax.swing.tree.DefaultMutableTreeNode
DefaultMutableTreeNode.BreadthFirstEnumeration, DefaultMutableTreeNode.PathBetweenNodesEnumeration, DefaultMutableTreeNode.PostorderEnumeration, DefaultMutableTreeNode.PreorderEnumeration
 
Field Summary
protected  boolean expanded
          Is this node currently expanded?
protected  boolean hasBeenExpanded
          Has this node been expanded at least once?
protected  TreePath path
          Path of this node.
protected  int preferredHeight
           
protected  int preferredWidth
          Preferred size needed to draw the user object.
protected  int xOrigin
          X location that the user object will be drawn at.
protected  int yOrigin
          Y location that the user object will be drawn at.
 
Fields inherited from class javax.swing.tree.DefaultMutableTreeNode
allowsChildren, children, EMPTY_ENUMERATION, parent, userObject
 
Constructor Summary
VariableHeightLayoutCache.TreeStateNode(Object value)
           
 
Method Summary
 Enumeration children()
          Returns the children of the receiver.
 void collapse()
          Collapses the receiver.
protected  void collapse(boolean adjustTree)
          Collapses this node in the tree.
protected  void deepMarkSizeInvalid()
          Marks the receivers size, and all its descendants sizes, as invalid.
protected  void didAdjustTree()
          Messaged from expand and collapse.
 void expand()
          Expands the receiver.
protected  void expand(boolean adjustTree)
          Expands this node in the tree.
protected  void expandParentAndReceiver()
          Invokes expandParentAndReceiver on the parent, and expands the receiver.
 VariableHeightLayoutCache.TreeStateNode getLastVisibleNode()
          Returns the last visible node that is a child of this instance.
protected  Enumeration getLoadedChildren(boolean createIfNeeded)
          Returns the children of the receiver.
 int getModelChildCount()
          Returns the number of children this will have.
 Rectangle getNodeBounds(Rectangle placeIn)
          Returns the location and size of this node.
 int getPreferredHeight()
          Returns the preferred height of the receiver.
 int getPreferredWidth()
          Returns the preferred width of the receiver.
 int getRow()
          Returns the row of the receiver.
 TreePath getTreePath()
          Returns a TreePath instance for this node.
 Object getValue()
          Returns the value the receiver is representing.
 int getVisibleChildCount()
          Returns the number of visible children, that is the number of children that are expanded, or leafs.
 int getXOrigin()
           
 int getYOrigin()
          Returns the y origin the user object will be drawn at.
 boolean hasBeenExpanded()
          Returns true if this node has been expanded at least once.
 boolean hasValidSize()
          Returns true if this node has a valid size.
 boolean isExpanded()
          Returns true if the receiver has been expanded.
 boolean isLeaf()
          Returns true if the receiver is a leaf.
 boolean isVisible()
          Returns true if the receiver is currently visible.
 void makeVisible()
          Makes the receiver visible, but invoking expandParentAndReceiver on the superclass.
protected  void markSizeInvalid()
          Marks the receivers size as invalid.
 void remove(int childIndex)
          Messaged when this node is removed from its parent, this messages removedFromMapping to remove all the children.
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.
 void setParent(MutableTreeNode parent)
          Messaged when this node is added somewhere, resets the path and adds a mapping from path to this node.
 void setUserObject(Object o)
          Messaged to set the user object.
protected  void setYOrigin(int newYOrigin)
          Sets y origin the user object will be drawn at to newYOrigin.
protected  void shiftYOriginBy(int offset)
          Shifts the y origin by offset.
 void toggleExpanded()
          Toggles the receiver between expanded and collapsed.
protected  void updatePreferredSize()
          Updates the receivers preferredSize by invoking updatePreferredSize with an argument of -1.
protected  void updatePreferredSize(int index)
          Updates the preferred size by asking the current renderer for the Dimension needed to draw the user object this instance represents.
 
Methods inherited from class javax.swing.tree.DefaultMutableTreeNode
add, breadthFirstEnumeration, 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

preferredWidth

protected int preferredWidth
Preferred size needed to draw the user object.


preferredHeight

protected int preferredHeight

xOrigin

protected int xOrigin
X location that the user object will be drawn at.


yOrigin

protected int yOrigin
Y location that the user object will be drawn at.


expanded

protected boolean expanded
Is this node currently expanded?


hasBeenExpanded

protected boolean hasBeenExpanded
Has this node been expanded at least once?


path

protected TreePath path
Path of this node.

Constructor Detail

VariableHeightLayoutCache.TreeStateNode

public VariableHeightLayoutCache.TreeStateNode(Object value)
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()

children

public Enumeration children()
Returns the children of the receiver. If the receiver is not currently expanded, this will return an empty enumeration.

Specified by:
children in interface TreeNode
Overrides:
children in class DefaultMutableTreeNode
Returns:
an Enumeration of this node's children

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()

getNodeBounds

public Rectangle getNodeBounds(Rectangle placeIn)
Returns the location and size of this node.


getXOrigin

public int getXOrigin()
Returns:
x location to draw node at.

getYOrigin

public int getYOrigin()
Returns the y origin the user object will be drawn at.


getPreferredHeight

public int getPreferredHeight()
Returns the preferred height of the receiver.


getPreferredWidth

public int getPreferredWidth()
Returns the preferred width of the receiver.


hasValidSize

public boolean hasValidSize()
Returns true if this node has a valid size.


getRow

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


hasBeenExpanded

public boolean hasBeenExpanded()
Returns true if this node has been expanded at least once.


isExpanded

public boolean isExpanded()
Returns true if the receiver has been expanded.


getLastVisibleNode

public VariableHeightLayoutCache.TreeStateNode getLastVisibleNode()
Returns the last visible node that is a child of this instance.


isVisible

public boolean isVisible()
Returns true if the receiver is currently visible.


getModelChildCount

public int getModelChildCount()
Returns the number of children this will have. If the children have not yet been loaded, this messages the model.


getVisibleChildCount

public int getVisibleChildCount()
Returns the number of visible children, that is the number of children that are expanded, or leafs.


toggleExpanded

public void toggleExpanded()
Toggles the receiver between expanded and collapsed.


makeVisible

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


expand

public void expand()
Expands the receiver.


collapse

public void collapse()
Collapses the receiver.


getValue

public Object getValue()
Returns the value the receiver is representing. This is a cover for getUserObject.


getTreePath

public TreePath getTreePath()
Returns a TreePath instance for this node.


resetChildrenPaths

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


setYOrigin

protected void setYOrigin(int newYOrigin)
Sets y origin the user object will be drawn at to newYOrigin.


shiftYOriginBy

protected void shiftYOriginBy(int offset)
Shifts the y origin by offset.


updatePreferredSize

protected void updatePreferredSize()
Updates the receivers preferredSize by invoking updatePreferredSize with an argument of -1.


updatePreferredSize

protected void updatePreferredSize(int index)
Updates the preferred size by asking the current renderer for the Dimension needed to draw the user object this instance represents.


markSizeInvalid

protected void markSizeInvalid()
Marks the receivers size as invalid. Next time the size, location is asked for it will be obtained.


deepMarkSizeInvalid

protected void deepMarkSizeInvalid()
Marks the receivers size, and all its descendants sizes, as invalid.


getLoadedChildren

protected Enumeration getLoadedChildren(boolean createIfNeeded)
Returns the children of the receiver. If the children haven't been loaded from the model and createIfNeeded is true, the children are first loaded.


didAdjustTree

protected void didAdjustTree()
Messaged from expand and collapse. This is meant for subclassers that may wish to do something interesting with this.


expandParentAndReceiver

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


expand

protected void expand(boolean adjustTree)
Expands this node in the tree. This will load the children from the treeModel if this node has not previously been expanded. If adjustTree is true the tree and selection are updated accordingly.


collapse

protected void collapse(boolean adjustTree)
Collapses this node in the tree. If adjustTree is true the tree and selection are updated accordingly.


removeFromMapping

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