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