1	package antlr.debug.misc;
2	
3	import antlr.*;
4	import antlr.collections.AST;
5	import java.awt.*;
6	import java.awt.event.*;
7	import com.sun.java.swing.*;
8	import com.sun.java.swing.event.*;
9	import com.sun.java.swing.tree.*;
10	
11	public class ASTFrame extends JFrame {
12	  // The initial width and height of the frame
13	  static final int WIDTH = 200;
14	  static final int HEIGHT = 300;
15	
16	  class MyTreeSelectionListener 
17		  implements TreeSelectionListener {
18		public void valueChanged (TreeSelectionEvent event) {
19		  TreePath path = event.getPath();
20		  System.out.println ("Selected: " + 
21			path.getLastPathComponent());
22		  Object elements[] = path.getPath();
23		  for (int i=0; i<elements.length; i++) {
24			System.out.print ("->" + elements[i]);
25		  }
26		  System.out.println ();
27		}
28	  }
29	public ASTFrame(String lab, AST r) {
30		super(lab);
31	
32		// Create the TreeSelectionListener
33		TreeSelectionListener listener = new MyTreeSelectionListener();
34		JTreeASTPanel tp = new JTreeASTPanel(new JTreeASTModel(r), null);
35		Container content = getContentPane();
36		content.add(tp, BorderLayout.CENTER);
37		addWindowListener(new WindowAdapter() {
38			public void windowClosing(WindowEvent e) {
39				Frame f = (Frame) e.getSource();
40				f.setVisible(false);
41				f.dispose();
42				// System.exit(0);
43			}
44		});
45		setSize(WIDTH, HEIGHT);
46	}
47	  public static void main(String args[]) {
48		// Create the tree nodes
49		ASTFactory factory = new ASTFactory();
50		CommonAST r = (CommonAST)factory.create(0, "ROOT");
51		r.addChild((CommonAST)factory.create(0, "C1"));
52		r.addChild((CommonAST)factory.create(0, "C2"));
53		r.addChild((CommonAST)factory.create(0, "C3"));
54	
55		ASTFrame frame = new ASTFrame("AST JTree Example", r);
56		frame.setVisible(true);
57	  }      
58	}
59