KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > kilim > tools > KilimTraceTreeModel


1 package org.objectweb.kilim.tools;
2
3 import java.util.LinkedList JavaDoc;
4 import java.util.Stack JavaDoc;
5
6 import javax.swing.event.TreeModelListener JavaDoc;
7 import javax.swing.tree.TreeModel JavaDoc;
8 import javax.swing.tree.TreePath JavaDoc;
9
10 import org.objectweb.kilim.description.KILIM;
11
12 /**
13  * @author horn
14  */

15 public class KilimTraceTreeModel implements TreeModel JavaDoc { //extends DefaultTreeModel {
16
private String JavaDoc rootStr = "trace start";
17     private KilimTraceTreeNode root = new KilimTraceTreeNode(rootStr);
18     private Stack JavaDoc nodeStack = new Stack JavaDoc();
19     private KilimTraceTreeNode current;
20
21     /**
22      * Method KilimComponentTreeModel.
23      */

24     public KilimTraceTreeModel() {
25         super();
26         root = new KilimTraceTreeNode(rootStr);
27         nodeStack.push(root);
28         current = root;
29     }
30
31     /**
32      * @see javax.swing.tree.TreeModel#getRoot()
33      */

34     public Object JavaDoc getRoot() {
35         return root;
36     }
37
38     /**
39      * @see javax.swing.tree.TreeModel#getChild(Object, int)
40      */

41     public Object JavaDoc getChild(Object JavaDoc aParent, int index) {
42         if (aParent == null) {
43             return null;
44         }
45
46         LinkedList JavaDoc list = ((KilimTraceTreeNode) aParent).getChildren();
47         if (list == null || list == KILIM.EMPTY_LIST) {
48             return null;
49         }
50         if (index < 0 || index >= list.size()) {
51             return null;
52         }
53         return list.get(index);
54     }
55
56     /**
57      * @see javax.swing.tree.TreeModel#getChildCount(Object)
58      */

59     public int getChildCount(Object JavaDoc aParent) {
60         if (aParent == null) {
61             return 0;
62         }
63
64         LinkedList JavaDoc list = ((KilimTraceTreeNode) aParent).getChildren();
65         if (list == null || list == KILIM.EMPTY_LIST) {
66             return 0;
67         }
68         return list.size();
69     }
70
71     /**
72      * @see javax.swing.tree.TreeModel#isLeaf(Object)
73      */

74     public boolean isLeaf(Object JavaDoc node) {
75         return (getChildCount(node) == 0);
76     }
77
78     /**
79      * @see javax.swing.tree.TreeModel#valueForPathChanged(TreePath, Object)
80      */

81     public void valueForPathChanged(TreePath JavaDoc path, Object JavaDoc newValue) {
82     }
83
84     /**
85      * @see javax.swing.tree.TreeModel#getIndexOfChild(Object, Object)
86      */

87     public int getIndexOfChild(Object JavaDoc aParent, Object JavaDoc child) {
88         if (aParent == null) {
89             return -1;
90         }
91
92         LinkedList JavaDoc list = ((KilimTraceTreeNode) aParent).getChildren();
93         if (list == null || list == KILIM.EMPTY_LIST) {
94             return -1;
95         }
96         int lSize = list.size();
97         for (int i = 0; i < lSize; i++) {
98             if (list.get(i) == child) {
99                 return i;
100             }
101         }
102         return -1;
103     }
104
105     /**
106      * @see javax.swing.tree.TreeModel#addTreeModelListener(TreeModelListener)
107      */

108     public void addTreeModelListener(TreeModelListener JavaDoc l) {
109     }
110
111     /**
112      * @see javax.swing.tree.TreeModel#removeTreeModelListener(TreeModelListener)
113      */

114     public void removeTreeModelListener(TreeModelListener JavaDoc l) {
115     }
116     
117     /**
118      * Method addChild.
119      * @param aParent :
120      * @param aChild :
121      */

122     public void addChild(Object JavaDoc aParent, Object JavaDoc aChild) {
123         KilimTraceTreeNode node1 = new KilimTraceTreeNode(aChild);
124         current.addChild(node1);
125         nodeStack.push(node1);
126         current = node1;
127     }
128     
129     /**
130      * Method setSeqNumber.
131      * @param aObject :
132      * @param aNumber :
133      * @param aMode :
134      */

135     public void setSeqNumberAndMode(Object JavaDoc aObject, int aNumber, int aMode) {
136         KilimTraceTreeNode node = (KilimTraceTreeNode) nodeStack.pop();
137         node.setSeqNumberAndMode(aNumber, aMode);
138         current = (KilimTraceTreeNode) nodeStack.lastElement();
139     }
140 }
141
142 class KilimTraceTreeNode {
143     private int seqNumber;
144     private int mode;
145     private Object JavaDoc value;
146     private LinkedList JavaDoc children;
147     
148     public KilimTraceTreeNode(Object JavaDoc aValue) {
149         value = aValue;
150     }
151     
152     public void setSeqNumberAndMode(int aNumber, int aMode) {
153         seqNumber = aNumber;
154         mode = aMode;
155     }
156     
157     public int getSeqNumber() {
158         return seqNumber;
159     }
160     
161     public int getMode() {
162         return mode;
163     }
164     
165     public void addChild(KilimTraceTreeNode aNode) {
166         if (children == null) {
167             children = new LinkedList JavaDoc();
168         }
169         children.addLast(aNode);
170     }
171     
172     public int getChildCount() {
173         if (children == null) {
174             return 0;
175         }
176         return children.size();
177     }
178     
179     public LinkedList JavaDoc getChildren() {
180         if (children == null) {
181             return KILIM.EMPTY_LIST;
182         }
183         return children;
184     }
185     
186     public Object JavaDoc getValue() {
187         return value;
188     }
189 }
Popular Tags