01: package org.zilonis.tool.ui;
02:
03: import javax.swing.event.TreeModelListener;
04: import javax.swing.tree.TreeModel;
05: import javax.swing.tree.TreePath;
06:
07: import org.zilonis.scope.Scope;
08:
09: public class ScopeTreeModel implements TreeModel {
10:
11: public Object getRoot() {
12: return Scope.ROOT;
13: }
14:
15: public boolean isLeaf(Object node) {
16: Scope scope = (Scope) node;
17: return scope.getChildren().size() == 0;
18: }
19:
20: public int getChildCount(Object parent) {
21: Scope scope = (Scope) parent;
22: return scope.getChildren().size();
23: }
24:
25: public Object getChild(Object parent, int index) {
26: Scope scope = (Scope) parent;
27: return scope.getChildren().get(index);
28: }
29:
30: public int getIndexOfChild(Object parent, Object child) {
31: Scope scope = (Scope) parent;
32: int index = 0;
33: for (Scope childScope : scope.getChildren()) {
34: if (childScope == child) {
35: return index;
36: }
37: index++;
38: }
39: return -1;
40: }
41:
42: public void valueForPathChanged(TreePath path, Object newValue) {
43:
44: }
45:
46: public void addTreeModelListener(TreeModelListener l) {
47:
48: }
49:
50: public void removeTreeModelListener(TreeModelListener l) {
51:
52: }
53: }
|