Xj3D 2.0 VRML/X3D Code API

org.web3d.x3d.dom.swing
Class DOMTreeNode

java.lang.Object
  extended by org.web3d.x3d.dom.swing.DOMTreeNode
All Implemented Interfaces:
javax.swing.tree.MutableTreeNode, javax.swing.tree.TreeNode

public class DOMTreeNode
extends java.lang.Object
implements javax.swing.tree.MutableTreeNode

An implementation of the MutableTreeNode that represents a single DOM node within a JTree.

The model is specifically tailored to display DOM objects. The model is configured so that it should always ask if it allows children as some DOM nodes cannot have children. This class does not add event listeners as it assumes that the TreeModel it is a part of will do that for us.

Our basic assumption is that this tree node is dumb. It only looks after its tree node children. If the DOM node it represents changes underneath it then someone needs to tell it that.

Version:
$Revision: 1.3 $
Author:
Justin Couch

Constructor Summary
DOMTreeNode(org.w3c.dom.Node node, DOMTreeNode parent)
          Create an instance of the tree node that represents the given DOM Node.
 
Method Summary
 java.util.Enumeration children()
          Get the list of children of this node as an enumeration.
 boolean getAllowsChildren()
          Check to see if this node allows children.
 javax.swing.tree.TreeNode getChildAt(int index)
          Get the child at the given index position.
 int getChildCount()
          Get the number of children of this node.
 int getIndex(javax.swing.tree.TreeNode node)
          Get the index of the given tree node.
 org.w3c.dom.Node getNode()
          Get the DOM node that this tree node represents.
 javax.swing.tree.TreeNode getParent()
          Get the parent node of this node.
 java.lang.Object getUserData()
          Get the user data stored in this object.
 void insert(javax.swing.tree.MutableTreeNode child, int index)
          Insert the child at the given position.
 boolean isLeaf()
          Check to see if this instance is a leaf node
 void remove(int index)
          Remove the child at the given index position.
 void remove(javax.swing.tree.MutableTreeNode child)
          Remove the given tree node from the list of children of this node.
 void removeFromParent()
          Remove this node from it's parent.
 void setParent(javax.swing.tree.MutableTreeNode parent)
          Set the parent node of this node to the new value.
 void setUserObject(java.lang.Object obj)
          Add some user data to this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMTreeNode

public DOMTreeNode(org.w3c.dom.Node node,
                   DOMTreeNode parent)
Create an instance of the tree node that represents the given DOM Node. If the node allows events, then this will register itself as a listener.

Parameters:
node - The DOM node this tree node represents
Method Detail

insert

public void insert(javax.swing.tree.MutableTreeNode child,
                   int index)
Insert the child at the given position.

Specified by:
insert in interface javax.swing.tree.MutableTreeNode
Parameters:
child - The new child to insert
index - The position to insert the child into

remove

public void remove(int index)
Remove the child at the given index position. If there is no child there it will do nothing.

Specified by:
remove in interface javax.swing.tree.MutableTreeNode

remove

public void remove(javax.swing.tree.MutableTreeNode child)
Remove the given tree node from the list of children of this node.

Specified by:
remove in interface javax.swing.tree.MutableTreeNode
Parameters:
child - The node to remove

removeFromParent

public void removeFromParent()
Remove this node from it's parent. If this is the root node then this will ignore the request.

Specified by:
removeFromParent in interface javax.swing.tree.MutableTreeNode

setParent

public void setParent(javax.swing.tree.MutableTreeNode parent)
Set the parent node of this node to the new value.

Specified by:
setParent in interface javax.swing.tree.MutableTreeNode
Parameters:
parent - The new node to use as a parent

setUserObject

public void setUserObject(java.lang.Object obj)
Add some user data to this object.

Specified by:
setUserObject in interface javax.swing.tree.MutableTreeNode
Parameters:
obj - The data to be stored

children

public java.util.Enumeration children()
Get the list of children of this node as an enumeration. If the node could have children, but does not at the moment, it will return an empty enumeration.

Specified by:
children in interface javax.swing.tree.TreeNode
Returns:
An enumeration, possibly empty of the children

getAllowsChildren

public boolean getAllowsChildren()
Check to see if this node allows children. For the purposes of the DOM view of the world, a leaf and allowing children are the same thing. We do not consider whether the node is an X3D node type or not.

Specified by:
getAllowsChildren in interface javax.swing.tree.TreeNode
Returns:
true if this node allows children

getChildAt

public javax.swing.tree.TreeNode getChildAt(int index)
Get the child at the given index position. If there is no child there it will return null.

Specified by:
getChildAt in interface javax.swing.tree.TreeNode
Parameters:
index - The position to check
Returns:
The tree node at the index

getChildCount

public int getChildCount()
Get the number of children of this node. The children count is of the tree node children, not the DOM children. Tree children includes the attributes as well

Specified by:
getChildCount in interface javax.swing.tree.TreeNode
Returns:
The number of children of this child

getIndex

public int getIndex(javax.swing.tree.TreeNode node)
Get the index of the given tree node.

Specified by:
getIndex in interface javax.swing.tree.TreeNode
Parameters:
node - The node to find the index of
Returns:
The index of the given node or -1 if not found

getParent

public javax.swing.tree.TreeNode getParent()
Get the parent node of this node. If this is the root of the tree, the return value is null.

Specified by:
getParent in interface javax.swing.tree.TreeNode
Returns:
The parent node

isLeaf

public boolean isLeaf()
Check to see if this instance is a leaf node

Specified by:
isLeaf in interface javax.swing.tree.TreeNode
Returns:
true if this is a leaf and cannot have children

getNode

public org.w3c.dom.Node getNode()
Get the DOM node that this tree node represents. Used by the renderer to build custom information about the node type.

Returns:
The DOM node

getUserData

public java.lang.Object getUserData()
Get the user data stored in this object.

Returns:
The currently set user data

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium