1 package antlr.debug.misc; 2 3 9 10 import antlr.collections.AST; 11 12 import javax.swing.*; 13 import javax.swing.event.*; 14 import javax.swing.tree.*; 15 16 public class JTreeASTModel implements TreeModel { 17 18 AST root = null; 19 20 public JTreeASTModel(AST t) { 21 if (t == null) { 22 throw new IllegalArgumentException ("root is null"); 23 } 24 root = t; 25 } 26 27 public void addTreeModelListener(TreeModelListener l) { 28 } 29 30 public Object getChild(Object parent, int index) { 31 if (parent == null) { 32 return null; 33 } 34 AST p = (AST)parent; 35 AST c = p.getFirstChild(); 36 if (c == null) { 37 throw new ArrayIndexOutOfBoundsException ("node has no children"); 38 } 39 int i = 0; 40 while (c != null && i < index) { 41 c = c.getNextSibling(); 42 i++; 43 } 44 return c; 45 } 46 47 public int getChildCount(Object parent) { 48 if (parent == null) { 49 throw new IllegalArgumentException ("root is null"); 50 } 51 AST p = (AST)parent; 52 AST c = p.getFirstChild(); 53 int i = 0; 54 while (c != null) { 55 c = c.getNextSibling(); 56 i++; 57 } 58 return i; 59 } 60 61 public int getIndexOfChild(Object parent, Object child) { 62 if (parent == null || child == null) { 63 throw new IllegalArgumentException ("root or child is null"); 64 } 65 AST p = (AST)parent; 66 AST c = p.getFirstChild(); 67 if (c == null) { 68 throw new ArrayIndexOutOfBoundsException ("node has no children"); 69 } 70 int i = 0; 71 while (c != null && c != child) { 72 c = c.getNextSibling(); 73 i++; 74 } 75 if (c == child) { 76 return i; 77 } 78 throw new java.util.NoSuchElementException ("node is not a child"); 79 } 80 81 public Object getRoot() { 82 return root; 83 } 84 85 public boolean isLeaf(Object node) { 86 if (node == null) { 87 throw new IllegalArgumentException ("node is null"); 88 } 89 AST t = (AST)node; 90 return t.getFirstChild() == null; 91 } 92 93 public void removeTreeModelListener(TreeModelListener l) { 94 } 95 96 public void valueForPathChanged(TreePath path, Object newValue) { 97 System.out.println("heh, who is calling this mystery method?"); 98 } 99 } 100 | Popular Tags |