org.sbml.jsbml
public abstract class AbstractTreeNode extends java.lang.Object implements TreeNodeWithChangeSupport
TreeNode
interface.Modifier and Type | Field and Description |
---|---|
protected java.util.List<TreeNodeChangeListener> |
listOfListeners
List of listeners for this component |
private static org.apache.log4j.Logger |
logger
A
Logger for this class. |
protected javax.swing.tree.TreeNode |
parent
The parent element of this
Annotation . |
private static long |
serialVersionUID
Generated serial version identifier.
|
static java.lang.String |
UNKNOWN_ATTRIBUTES |
static java.lang.String |
UNKNOWN_ELEMENTS |
private java.util.Map<java.lang.Object,java.lang.Object> |
userObjects
Any kind of
Object that can be stored in addition to all other
features of this AbstractTreeNode in form of key-value pairs. |
Constructor and Description |
---|
AbstractTreeNode()
Creates an empty
AbstractTreeNode without child nodes and an
empty list of TreeNodeChangeListener s. |
AbstractTreeNode(javax.swing.tree.TreeNode node)
Constructor for cloning.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addAllChangeListeners(java.util.Collection<TreeNodeChangeListener> listeners)
Adds recursively all given
TreeNodeChangeListener instances to
this element. |
void |
addTreeNodeChangeListener(TreeNodeChangeListener listener)
Adds recursively a listener to the
TreeNodeWithChangeSupport
object and all of its sub-elements. |
void |
addTreeNodeChangeListener(TreeNodeChangeListener listener,
boolean recursive)
Adds a listener to this
TreeNodeWithChangeSupport object and
optionally also to all of its child nodes. |
java.util.Enumeration<javax.swing.tree.TreeNode> |
children() |
void |
clearUserObjects()
Removes all of the mappings from the map of user objects (optional
operation).
|
abstract javax.swing.tree.TreeNode |
clone() |
boolean |
containsUserObjectKey(java.lang.Object key) |
boolean |
equals(java.lang.Object object) |
java.util.List<? extends javax.swing.tree.TreeNode> |
filter(Filter filter)
Filters this tree data structure recursively and returns a list of all
TreeNode s that are accepted by the Filter . |
java.util.List<? extends javax.swing.tree.TreeNode> |
filter(Filter filter,
boolean retainInternalNodes)
Filters this tree data structure recursively and returns a list of all
TreeNode s that are accepted by the Filter . |
java.util.List<? extends javax.swing.tree.TreeNode> |
filter(Filter filter,
boolean retainInternalNodes,
boolean prune)
Filters this tree data structure recursively and returns a list of all
TreeNode s that are accepted by the Filter . |
void |
fireNodeAddedEvent()
All
TreeNodeChangeListener instances linked to this
TreeNode are informed about the adding of this Object to
an owning parent Object . |
void |
fireNodeRemovedEvent()
All
TreeNodeChangeListener instances linked to this
TreeNode are informed about the deletion of this TreeNode
from a parent Object . |
void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
All
TreeNodeChangeListener s are informed about the change in this
TreeNodeWithChangeSupport . |
int |
getIndex(javax.swing.tree.TreeNode node) |
java.util.List<TreeNodeChangeListener> |
getListOfTreeNodeChangeListeners()
Returns all
TreeNodeChangeListener s that are assigned to this
element. |
int |
getNumChildren()
Deprecated.
use
TreeNode.getChildCount() |
javax.swing.tree.TreeNode |
getParent() |
javax.swing.tree.TreeNode |
getRoot() |
int |
getTreeNodeChangeListenerCount() |
java.lang.Object |
getUserObject(java.lang.Object key) |
int |
hashCode() |
static int |
indexOf(javax.swing.tree.TreeNode parent,
javax.swing.tree.TreeNode child)
Searches the given child in the list of sub-nodes of the parent element.
|
boolean |
isLeaf() |
boolean |
isRoot()
Opposite of
TreeNodeWithChangeSupport.isSetParent() . |
boolean |
isSetParent() |
boolean |
isSetUserObjects()
Checks whether any user-defined key-value pairs have been attached
to this object.
|
protected void |
notifyChildChange(javax.swing.tree.TreeNode oldChild,
javax.swing.tree.TreeNode newChild)
This method is called when one child has been swapped with another one
and can be used to check certain properties of the resulting changed
tree.
|
void |
putUserObject(java.lang.Object key,
java.lang.Object userObject) |
void |
removeAllTreeNodeChangeListeners()
Removes all tree node change listeners from this element.
|
boolean |
removeFromParent()
This method is designed to be overridden for non-independent child nodes
|
void |
removeTreeNodeChangeListener(TreeNodeChangeListener listener)
Removes recursively the given change listener from this element.
|
void |
removeTreeNodeChangeListener(TreeNodeChangeListener listener,
boolean recursive)
Removes the given change listener from this element.
|
java.lang.Object |
removeUserObject(java.lang.Object key) |
protected void |
setParent(javax.swing.tree.TreeNode parent) |
java.lang.String |
toString() |
java.util.Set<java.lang.Object> |
userObjectKeySet() |
private static final long serialVersionUID
public static final java.lang.String UNKNOWN_ATTRIBUTES
public static final java.lang.String UNKNOWN_ELEMENTS
private static final org.apache.log4j.Logger logger
Logger
for this class.protected java.util.List<TreeNodeChangeListener> listOfListeners
List
of listeners for this componentprotected javax.swing.tree.TreeNode parent
Annotation
.private java.util.Map<java.lang.Object,java.lang.Object> userObjects
Object
that can be stored in addition to all other
features of this AbstractTreeNode
in form of key-value pairs.
Note that things stored here will not be written to SBML files. This
only provides a possibility to attach some in-memory information to
derived classes.public AbstractTreeNode()
AbstractTreeNode
without child nodes and an
empty list of TreeNodeChangeListener
s. The pointer to the parent
of this node is set to null
.public AbstractTreeNode(javax.swing.tree.TreeNode node)
AbstractTreeNode
has two properties:
parent
and listOfListeners
. Both of them are not cloned
by this method, for two reasons:
parent
is not cloned and is left as null
because the new AbstractTreeNode
will get a parent set as soon as
it is added/linked again to a Model
. Note that only the top-level
element of the cloned sub-tree will have a null
value as its
parent. All sub-element will point to their correct parent element.listOfListeners
is needed in all other setXX() methods.
Cloning these might lead to strange and unexpected behavior, because when
doing a deep cloning, the listeners of the old object would suddenly be
informed about all value changes within this new object. Since we do
cloning, all values of all child elements have to be touched, i.e., all
listeners would be informed many times, but each time receive the identical
value as it was before. Since it is totally unclear of which type listeners
are, a deep cloning of these is not possible.TreeNodeChangeListener
s.node
- The original TreeNode
to be cloned.public static int indexOf(javax.swing.tree.TreeNode parent, javax.swing.tree.TreeNode child)
parent
- child
- public boolean addAllChangeListeners(java.util.Collection<TreeNodeChangeListener> listeners)
TreeNodeWithChangeSupport
TreeNodeChangeListener
instances to
this element.addAllChangeListeners
in interface TreeNodeWithChangeSupport
listeners
- the set of listeners to addtrue
if the set of listeners is added with success.public void addTreeNodeChangeListener(TreeNodeChangeListener listener)
TreeNodeWithChangeSupport
TreeNodeWithChangeSupport
object and all of its sub-elements. Calling this method is effectively
identical to the call
TreeNodeWithChangeSupport.addTreeNodeChangeListener(TreeNodeChangeListener, boolean)
where
recursively = true
.addTreeNodeChangeListener
in interface TreeNodeWithChangeSupport
listener
- the listener to addTreeNodeWithChangeSupport.addTreeNodeChangeListener(TreeNodeChangeListener, boolean)
public void addTreeNodeChangeListener(TreeNodeChangeListener listener, boolean recursive)
TreeNodeWithChangeSupport
TreeNodeWithChangeSupport
object and
optionally also to all of its child nodes.addTreeNodeChangeListener
in interface TreeNodeWithChangeSupport
listener
- the listener to addrecursive
- if true
the given listener will be added to this node and
also recursively to all of its child nodes. If false
, the
listener will only be added to the current node.TreeNodeWithChangeSupport.addTreeNodeChangeListener(TreeNodeChangeListener)
public java.util.Enumeration<javax.swing.tree.TreeNode> children()
children
in interface javax.swing.tree.TreeNode
public void clearUserObjects()
TreeNodeWithChangeSupport
clearUserObjects
in interface TreeNodeWithChangeSupport
Map.clear()
public abstract javax.swing.tree.TreeNode clone()
clone
in class java.lang.Object
public boolean containsUserObjectKey(java.lang.Object key)
containsUserObjectKey
in interface TreeNodeWithChangeSupport
Map.containsKey(java.lang.Object)
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
public java.util.List<? extends javax.swing.tree.TreeNode> filter(Filter filter)
TreeNodeWithChangeSupport
TreeNode
s that are accepted by the Filter
. Although
internal nodes that do not satisfy the filter criterion by themselves
are not contained in the resulting list, the recursion continues at
their children.filter
in interface TreeNodeWithChangeSupport
filter
- A criterion to select a sub-set of nodes of this tree.List
of TreeNode
s that do all satisfy the
criterion of the given Filter
.TreeNodeWithChangeSupport.filter(Filter, boolean)
public java.util.List<? extends javax.swing.tree.TreeNode> filter(Filter filter, boolean retainInternalNodes)
TreeNodeWithChangeSupport
TreeNode
s that are accepted by the Filter
. The second
argument decides whether or not internal nodes that do not by themselves
satisfy the filter criterion should still be retained in the result list.filter
in interface TreeNodeWithChangeSupport
filter
- A criterion to select a sub-set of nodes of this tree.retainInternalNodes
- Decides if internal nodes should also be included in the
resulting List
if they do not by themselves satisfy
the Filter
but if these do have child elements that do
so. This might be useful in order to obtain a complete tree
path to interesting sub-elements.List
representing a subset of TreeNode
s that
satisfy the Filter
's criterion, or whose child nodes do
so.TreeNodeWithChangeSupport.filter(Filter)
public java.util.List<? extends javax.swing.tree.TreeNode> filter(Filter filter, boolean retainInternalNodes, boolean prune)
TreeNodeWithChangeSupport
TreeNode
s that are accepted by the Filter
. The two
boolean switches let you decide if internal nodes that do not by
themselves satisfy the filter criterion should be retained in the list,
and if the recursion should be aborted as soon as the first hit is
discovered.filter
in interface TreeNodeWithChangeSupport
retainInternalNodes
- decides whether or not internal nodes should be added to the
list of results even though these might not by themselves
satisfy the filter's criterion, but whose children do. This
feature can be useful, e.g., in order to keep the full tree
path to nodes of interestprune
- if this argument is true
, the recursive search is
aborted upon the discovery of the first hit.List
representing a subset of TreeNode
s that
satisfy the Filter
's criterion, or whose child nodes do
so.TreeNodeWithChangeSupport.filter(Filter, boolean)
public void fireNodeAddedEvent()
TreeNodeWithChangeSupport
TreeNodeChangeListener
instances linked to this
TreeNode
are informed about the adding of this Object
to
an owning parent Object
.fireNodeAddedEvent
in interface TreeNodeWithChangeSupport
public void fireNodeRemovedEvent()
TreeNodeWithChangeSupport
TreeNodeChangeListener
instances linked to this
TreeNode
are informed about the deletion of this TreeNode
from a parent Object
.fireNodeRemovedEvent
in interface TreeNodeWithChangeSupport
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
TreeNodeWithChangeSupport
TreeNodeChangeListener
s are informed about the change in this
TreeNodeWithChangeSupport
.firePropertyChange
in interface TreeNodeWithChangeSupport
propertyName
- Tells the TreeNodeChangeListener
the name of the
property whose value has been changed.oldValue
- This is the value before the change.newValue
- This gives the new value that is now the new value for the
given property..public int getIndex(javax.swing.tree.TreeNode node)
getIndex
in interface javax.swing.tree.TreeNode
public java.util.List<TreeNodeChangeListener> getListOfTreeNodeChangeListeners()
TreeNodeWithChangeSupport
TreeNodeChangeListener
s that are assigned to this
element.getListOfTreeNodeChangeListeners
in interface TreeNodeWithChangeSupport
TreeNodeChangeListener
s that are assigned to this
element.@Deprecated public int getNumChildren()
TreeNode.getChildCount()
TreeNode
.public javax.swing.tree.TreeNode getParent()
getParent
in interface javax.swing.tree.TreeNode
public javax.swing.tree.TreeNode getRoot()
getRoot
in interface TreeNodeWithChangeSupport
TreeNode
without parent, which is the top-most ancestor
of this node.public int getTreeNodeChangeListenerCount()
getTreeNodeChangeListenerCount
in interface TreeNodeWithChangeSupport
TreeNodeChangeListener
s currently assigned to
this TreeNodeWithChangeSupport
public java.lang.Object getUserObject(java.lang.Object key)
getUserObject
in interface TreeNodeWithChangeSupport
public int hashCode()
hashCode
in class java.lang.Object
public boolean isLeaf()
isLeaf
in interface javax.swing.tree.TreeNode
public boolean isRoot()
TreeNodeWithChangeSupport
TreeNodeWithChangeSupport.isSetParent()
.
Returns true
if this AbstractTreeNode
is the root
node of a tree, false
otherwise.isRoot
in interface TreeNodeWithChangeSupport
true
if this AbstractTreeNode
is the root
node of a tree, false
otherwise.TreeNodeWithChangeSupport.isSetParent()
public boolean isSetParent()
isSetParent
in interface TreeNodeWithChangeSupport
public boolean isSetUserObjects()
TreeNodeWithChangeSupport
isSetUserObjects
in interface TreeNodeWithChangeSupport
true
if at least one user-defined key-value pair has
been attached to this object.protected void notifyChildChange(javax.swing.tree.TreeNode oldChild, javax.swing.tree.TreeNode newChild)
oldChild
- the element that was a child of this node before the change.newChild
- the new child whose new parent is this node.public void putUserObject(java.lang.Object key, java.lang.Object userObject)
putUserObject
in interface TreeNodeWithChangeSupport
key
- some user-defined key under which the given userObject can be
found.userObject
- the userObject to setpublic void removeAllTreeNodeChangeListeners()
TreeNodeWithChangeSupport
removeAllTreeNodeChangeListeners
in interface TreeNodeWithChangeSupport
public boolean removeFromParent()
removeFromParent
in interface TreeNodeWithChangeSupport
false
if this element is a root node, true
otherwise.TreeNodeWithChangeSupport.removeFromParent()
public void removeTreeNodeChangeListener(TreeNodeChangeListener listener)
TreeNodeWithChangeSupport
TreeNodeWithChangeSupport.removeTreeNodeChangeListener(TreeNodeChangeListener, boolean)
where the second argument is true
.removeTreeNodeChangeListener
in interface TreeNodeWithChangeSupport
listener
- the listener to remove.TreeNodeWithChangeSupport.removeTreeNodeChangeListener(TreeNodeChangeListener, boolean)
public void removeTreeNodeChangeListener(TreeNodeChangeListener listener, boolean recursive)
TreeNodeWithChangeSupport
removeTreeNodeChangeListener
in interface TreeNodeWithChangeSupport
listener
- the listener to remove.recursive
- switch to decide whether or not the given listener should be removed
in a recursive manner.TreeNodeWithChangeSupport.removeTreeNodeChangeListener(TreeNodeChangeListener)
public java.lang.Object removeUserObject(java.lang.Object key)
removeUserObject
in interface TreeNodeWithChangeSupport
protected void setParent(javax.swing.tree.TreeNode parent)
parent
- the parent to setpublic java.lang.String toString()
toString
in class java.lang.Object
public java.util.Set<java.lang.Object> userObjectKeySet()
userObjectKeySet
in interface TreeNodeWithChangeSupport
Map.keySet()