public class TreePath
extends java.lang.Object
implements java.io.Serializable
For further information and examples of using tree paths, see How to Use Trees in The Java Tutorial.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see XMLEncoder
.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
lastPathComponent
Last path component.
|
private TreePath |
parentPath
Path representing the parent, null if lastPathComponent represents
the root.
|
Modifier | Constructor and Description |
---|---|
protected |
TreePath()
Primarily provided for subclasses
that represent paths in a different manner.
|
|
TreePath(java.lang.Object singlePath)
Constructs a TreePath containing only a single element.
|
|
TreePath(java.lang.Object[] path)
Constructs a path from an array of Objects, uniquely identifying
the path from the root of the tree to a specific node, as returned
by the tree's data model.
|
protected |
TreePath(java.lang.Object[] path,
int length)
Constructs a new TreePath with the identified path components of
length
length . |
protected |
TreePath(TreePath parent,
java.lang.Object lastElement)
Constructs a new TreePath, which is the path identified by
parent ending in lastElement . |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Tests two TreePaths for equality by checking each element of the
paths for equality.
|
java.lang.Object |
getLastPathComponent()
Returns the last component of this path.
|
TreePath |
getParentPath()
Returns a path containing all the elements of this object, except
the last path component.
|
java.lang.Object[] |
getPath()
Returns an ordered array of Objects containing the components of this
TreePath.
|
java.lang.Object |
getPathComponent(int element)
Returns the path component at the specified index.
|
int |
getPathCount()
Returns the number of elements in the path.
|
int |
hashCode()
Returns the hashCode for the object.
|
boolean |
isDescendant(TreePath aTreePath)
Returns true if
aTreePath is a
descendant of this
TreePath. |
TreePath |
pathByAddingChild(java.lang.Object child)
Returns a new path containing all the elements of this object
plus
child . |
private void |
readObject(java.io.ObjectInputStream s) |
java.lang.String |
toString()
Returns a string that displays and identifies this
object's properties.
|
private void |
writeObject(java.io.ObjectOutputStream s) |
private TreePath parentPath
private transient java.lang.Object lastPathComponent
public TreePath(java.lang.Object[] path)
The model is free to return an array of any Objects it needs to represent the path. The DefaultTreeModel returns an array of TreeNode objects. The first TreeNode in the path is the root of the tree, the last TreeNode is the node identified by the path.
path
- an array of Objects representing the path to a nodepublic TreePath(java.lang.Object singlePath)
singlePath
- an Object representing the path to a nodeTreePath(Object[])
protected TreePath(TreePath parent, java.lang.Object lastElement)
parent
ending in lastElement
.protected TreePath(java.lang.Object[] path, int length)
length
.protected TreePath()
getPath
,
getPathCount
, and
getPathComponent
methods,
and possibly the equals
method.public java.lang.Object[] getPath()
TreePath(Object[])
public java.lang.Object getLastPathComponent()
TreePath(Object[])
public int getPathCount()
public java.lang.Object getPathComponent(int element)
element
- an int specifying an element in the path, where
0 is the first element in the pathjava.lang.IllegalArgumentException
- if the index is beyond the length
of the pathTreePath(Object[])
public boolean equals(java.lang.Object o)
.equals
).equals
in class java.lang.Object
o
- the Object to comparepublic int hashCode()
hashCode
in class java.lang.Object
public boolean isDescendant(TreePath aTreePath)
aTreePath
is a
descendant of this
TreePath. A TreePath P1 is a descendant of a TreePath P2
if P1 contains all of the components that make up
P2's path.
For example, if this object has the path [a, b],
and aTreePath
has the path [a, b, c],
then aTreePath
is a descendant of this object.
However, if aTreePath
has the path [a],
then it is not a descendant of this object. By this definition
a TreePath is always considered a descendant of itself. That is,
aTreePath.isDescendant(aTreePath)
returns true.aTreePath
is a descendant of this pathpublic TreePath pathByAddingChild(java.lang.Object child)
child
. child
will be the last element
of the newly created TreePath.
This will throw a NullPointerException
if child is null.public TreePath getParentPath()
public java.lang.String toString()
toString
in class java.lang.Object
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
Copyright © 2005-2013 java.net. All Rights Reserved.