Methods Summary |
---|
public void | addTreeModelListener(javax.swing.event.TreeModelListener l)Adds a listener for the TreeModelEvent posted after the tree changes.
treeModelListeners.addElement(l);
|
protected void | fireTreeStructureChanged(Person oldRoot)The only event raised by this model is TreeStructureChanged with the
root as path, i.e. the whole tree has changed.
int len = treeModelListeners.size();
TreeModelEvent e = new TreeModelEvent(this,
new Object[] {oldRoot});
for (int i = 0; i < len; i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeStructureChanged(e);
}
|
public java.lang.Object | getChild(java.lang.Object parent, int index)Returns the child of parent at index index in the parent's child array.
Person p = (Person)parent;
if (showAncestors) {
if ((index > 0) && (p.getFather() != null)) {
return p.getMother();
}
return p.getFather();
}
return p.getChildAt(index);
|
public int | getChildCount(java.lang.Object parent)Returns the number of children of parent.
Person p = (Person)parent;
if (showAncestors) {
int count = 0;
if (p.getFather() != null) {
count++;
}
if (p.getMother() != null) {
count++;
}
return count;
}
return p.getChildCount();
|
public int | getIndexOfChild(java.lang.Object parent, java.lang.Object child)Returns the index of child in parent.
Person p = (Person)parent;
if (showAncestors) {
int count = 0;
Person father = p.getFather();
if (father != null) {
count++;
if (father == child) {
return 0;
}
}
if (p.getMother() != child) {
return count;
}
return -1;
}
return p.getIndexOfChild((Person)child);
|
public java.lang.Object | getRoot()Returns the root of the tree.
return rootPerson;
|
public boolean | isLeaf(java.lang.Object node)Returns true if node is a leaf.
Person p = (Person)node;
if (showAncestors) {
return ((p.getFather() == null)
&& (p.getMother() == null));
}
return p.getChildCount() == 0;
|
public void | removeTreeModelListener(javax.swing.event.TreeModelListener l)Removes a listener previously added with addTreeModelListener().
treeModelListeners.removeElement(l);
|
public void | showAncestor(boolean b, java.lang.Object newRoot)Used to toggle between show ancestors/show descendant and
to change the root of the tree.
showAncestors = b;
Person oldRoot = rootPerson;
if (newRoot != null) {
rootPerson = (Person)newRoot;
}
fireTreeStructureChanged(oldRoot);
|
public void | valueForPathChanged(javax.swing.tree.TreePath path, java.lang.Object newValue)Messaged when the user has altered the value for the item
identified by path to newValue. Not used by this model.
System.out.println("*** valueForPathChanged : "
+ path + " --> " + newValue);
|