public class XdevTreeNode extends DefaultMutableTreeNode implements Copyable<XdevTreeNode>
DefaultMutableTreeNode
.
The XdevTree
provides methods to modify tree
s from a
node
s perspective.
DefaultMutableTreeNode
,
Serialized FormallowsChildren, children, EMPTY_ENUMERATION, parent, userObject
Constructor and Description |
---|
XdevTreeNode(Object userObject)
Creates a tree node with no parent, no children, but which allows
children, and initializes it with the specified user object.
|
XdevTreeNode(Object userObject,
String caption)
Creates a tree node with no parent, no children, but which allows
children, and initializes it with the specified user object.
|
XdevTreeNode(Object userObject,
String caption,
Icon icon)
Creates a tree node with no parent, no children, but which allows
children, and initializes it with the specified user object.
|
Modifier and Type | Method and Description |
---|---|
void |
add(MutableTreeNode node) |
XdevTreeNode |
add(XdevTreeNode... nodes)
Removes
nodes from their parent and makes them a child of
this node by adding it to the end of this node's child array. |
XdevTreeNode |
clone()
Returns a field-for-field copy of this instance.
|
XdevTreeNode |
cloneTree()
Clones a
XdevTreeNode and all its children (deep clone). |
String |
getCaption()
Returns the caption of this
XdevTreeNode . |
TreeNode |
getChildAt(int index) |
<T extends TreeNode> |
getChildren()
Returns a
XdevList containing the children of this
XdevTreeNode . |
Icon |
getIcon()
Returns the
Icon of this XdevTreeNode . |
DefaultTreeModel |
getModel()
Returns the
TreeModel for this XdevTreeNode . |
<T extends TreeNode> |
getPathAsList()
Returns the path from the root, to get to this node.
|
<T extends TreeNode> |
getSubTree()
Creates and returns an
XdevList that traverses the subtree rooted
at this node in preorder. |
XdevTreeNode |
getXdevParent()
Returns this node's parent or null if this node has no parent.
|
void |
insert(MutableTreeNode node,
int index) |
void |
remove(int index) |
void |
remove(MutableTreeNode node) |
void |
removeAllChildren() |
void |
removeFromParent() |
XdevTreeNode |
removeNode(XdevTreeNode node)
Removes
node from this node's child array, giving it a null
parent. |
XdevTreeNode |
removeNodeAt(int index)
Removes the node at the specified index from this node's children and
sets that node's parent to null.
|
XdevTreeNode |
searchNode(Object userObject,
String caption)
Searches the tree below (including) this
XdevTreeNode for the
first node matching the given userObject
and/or the given caption . |
<T extends TreeNode> |
searchNodes(Object userObject,
String caption)
Searches the tree below (including) this
XdevTreeNode for the
all node matching the given userObject
and/or the given caption . |
void |
setCaption(String caption)
Sets the caption of this
XdevTreeNode . |
void |
setIcon(Icon icon)
Sets the
Icon of this XdevTreeNode . |
void |
setModel(DefaultTreeModel model)
Sets the
TreeModel for this XdevTreeNode . |
void |
setUserObject(Object o) |
String |
toString() |
breadthFirstEnumeration, children, depthFirstEnumeration, getAllowsChildren, getChildAfter, 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, setAllowsChildren, setParent
public XdevTreeNode(Object userObject)
userObject
- an Object provided by the user that constitutes the node's
datapublic XdevTreeNode(Object userObject, String caption)
userObject
- an Object provided by the user that constitutes the node's
datacaption
- the caption of this XdevTreeNode
public XdevTreeNode(Object userObject, String caption, Icon icon)
userObject
- an Object provided by the user that constitutes the node's
datacaption
- the caption of this XdevTreeNode
icon
- Icon
of this XdevTreeNode
public XdevTreeNode add(XdevTreeNode... nodes) throws IllegalArgumentException
nodes
from their parent and makes them a child of
this node by adding it to the end of this node's child array.nodes
- nodes to add as a children of this nodeXdevTreeNode
after the nodes have been addedIllegalArgumentException
- if one element of nodes
is nullinsert(javax.swing.tree.MutableTreeNode, int)
public XdevTreeNode getXdevParent()
XdevTreeNode
, or null if this node has
no parentpublic TreeNode getChildAt(int index)
getChildAt
in interface TreeNode
getChildAt
in class DefaultMutableTreeNode
public <T extends TreeNode> List<T> getChildren()
XdevList
containing the children of this
XdevTreeNode
.
Only the children of this XdevTreeNode
are returned. The children
of the children are not returned.
XdevList
containing the children of this
XdevTreeNode
.public void setUserObject(Object o)
setUserObject
in interface MutableTreeNode
setUserObject
in class DefaultMutableTreeNode
public void add(MutableTreeNode node)
add
in class DefaultMutableTreeNode
public void insert(MutableTreeNode node, int index)
insert
in interface MutableTreeNode
insert
in class DefaultMutableTreeNode
public XdevTreeNode removeNode(XdevTreeNode node) throws IllegalArgumentException
node
from this node's child array, giving it a null
parent.node
- a child of this node to removeIllegalArgumentException
- if node
is null or is not a child of this
nodepublic void remove(MutableTreeNode node)
remove
in interface MutableTreeNode
remove
in class DefaultMutableTreeNode
public XdevTreeNode removeNodeAt(int index) throws ArrayIndexOutOfBoundsException
index
- the index in this node's child array of the child to remove * @return
the removed nodeArrayIndexOutOfBoundsException
- if childIndex
is out of boundspublic void remove(int index)
remove
in interface MutableTreeNode
remove
in class DefaultMutableTreeNode
public void removeAllChildren()
removeAllChildren
in class DefaultMutableTreeNode
public void removeFromParent()
removeFromParent
in interface MutableTreeNode
removeFromParent
in class DefaultMutableTreeNode
public <T extends TreeNode> List<T> getPathAsList()
XdevList
of TreeNode objects giving the path, where
the first element in the path is the root and the last element is
this node.public String toString()
toString
in class DefaultMutableTreeNode
public String getCaption()
XdevTreeNode
.XdevTreeNode
.public void setCaption(String caption)
XdevTreeNode
.caption
- the caption of this XdevTreeNode
.public Icon getIcon()
Icon
of this XdevTreeNode
.Icon
of this XdevTreeNode
.public void setIcon(Icon icon)
Icon
of this XdevTreeNode
.icon
- the Icon
of this XdevTreeNode
.public <T extends TreeNode> List<T> getSubTree()
XdevList
that traverses the subtree rooted
at this node in preorder. The first node of the XdevList
is this
node.public XdevTreeNode searchNode(Object userObject, String caption)
XdevTreeNode
for the
first node matching the given userObject
and/or the given caption
.userObject
- to search for. If userObject
is null
, the searched for node must only match caption
.caption
- to search for. If caption
is null
,
the searched for node must only match userObject
.userObject
and/or the given
caption
.public <T extends TreeNode> List<T> searchNodes(Object userObject, String caption)
XdevTreeNode
for the
all node matching the given userObject
and/or the given caption
.userObject
- to search for. If userObject
is null
, the searched for node must only match caption
.caption
- to search for. If caption
is null
,
the searched for node must only match userObject
.userObject
and/or the given
caption
.public void setModel(DefaultTreeModel model)
TreeModel
for this XdevTreeNode
.model
- the TreeModel
for this XdevTreeNode
.public DefaultTreeModel getModel()
TreeModel
for this XdevTreeNode
.TreeModel
for this XdevTreeNode
.public XdevTreeNode clone()
clone
in interface Copyable<XdevTreeNode>
clone
in class DefaultMutableTreeNode
public XdevTreeNode cloneTree()
XdevTreeNode
and all its children (deep clone).XdevTreeNode
.Copyright © 2003–2021 XDEV Software. All rights reserved.