Code with Finding: |
class TreeBrowser {
/**
* Inserts new node.
*
* @param parent the parent node.
* @item the abstract object this node refers to. may be null.
* @handler the node handler, that will receive notifications for this node
* @label the label displayed in the list.
* @icon the icon displayed in the list.
*/
public void insert(TreeNode parent, Object item, NodeHandler handler,
String label, Image icon) {
boolean done;
int j;
if(parent == null) throw new IllegalArgumentException("null parent");
if((handler == null) && (label == null)) {
throw new IllegalArgumentException("non-null item required");
}
if(handler == null) {
handler = parent.handler;
}
if(label == null) {
label = handler.toString();
}
if(parent.children == TreeNode.NOCHILD) {
parent.children = 1;
} else {
parent.children += 1;
}
done = false;
TreeNode node = null;
int i = items.indexOf(parent)+parent.children;
for (; (i < items.size() &&
((TreeNode) items.elementAt(i)).level > parent.level);
i++) {}
items.insertElementAt(node=new TreeNode(item, label, handler, icon,
parent.level+1), i);
// hscroll
hierarchyChanged = true;
return;
}
}
|