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