1 package org.objectweb.kilim.tools; 2 3 import java.util.LinkedList ; 4 import java.util.Stack ; 5 6 import javax.swing.event.TreeModelListener ; 7 import javax.swing.tree.TreeModel ; 8 import javax.swing.tree.TreePath ; 9 10 import org.objectweb.kilim.description.KILIM; 11 12 15 public class KilimTraceTreeModel implements TreeModel { private String rootStr = "trace start"; 17 private KilimTraceTreeNode root = new KilimTraceTreeNode(rootStr); 18 private Stack nodeStack = new Stack (); 19 private KilimTraceTreeNode current; 20 21 24 public KilimTraceTreeModel() { 25 super(); 26 root = new KilimTraceTreeNode(rootStr); 27 nodeStack.push(root); 28 current = root; 29 } 30 31 34 public Object getRoot() { 35 return root; 36 } 37 38 41 public Object getChild(Object aParent, int index) { 42 if (aParent == null) { 43 return null; 44 } 45 46 LinkedList 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 59 public int getChildCount(Object aParent) { 60 if (aParent == null) { 61 return 0; 62 } 63 64 LinkedList list = ((KilimTraceTreeNode) aParent).getChildren(); 65 if (list == null || list == KILIM.EMPTY_LIST) { 66 return 0; 67 } 68 return list.size(); 69 } 70 71 74 public boolean isLeaf(Object node) { 75 return (getChildCount(node) == 0); 76 } 77 78 81 public void valueForPathChanged(TreePath path, Object newValue) { 82 } 83 84 87 public int getIndexOfChild(Object aParent, Object child) { 88 if (aParent == null) { 89 return -1; 90 } 91 92 LinkedList 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 108 public void addTreeModelListener(TreeModelListener l) { 109 } 110 111 114 public void removeTreeModelListener(TreeModelListener l) { 115 } 116 117 122 public void addChild(Object aParent, Object aChild) { 123 KilimTraceTreeNode node1 = new KilimTraceTreeNode(aChild); 124 current.addChild(node1); 125 nodeStack.push(node1); 126 current = node1; 127 } 128 129 135 public void setSeqNumberAndMode(Object 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 value; 146 private LinkedList children; 147 148 public KilimTraceTreeNode(Object 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 (); 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 getChildren() { 180 if (children == null) { 181 return KILIM.EMPTY_LIST; 182 } 183 return children; 184 } 185 186 public Object getValue() { 187 return value; 188 } 189 } | Popular Tags |