01: package persistence.antlr.debug.misc;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.jGuru.com
05: * Software rights: http://www.antlr.org/license.html
06: *
07: */
08:
09: import persistence.antlr.*;
10: import persistence.antlr.collections.AST;
11:
12: import java.awt.*;
13: import java.awt.event.*;
14: import javax.swing.*;
15: import javax.swing.event.*;
16: import javax.swing.tree.*;
17:
18: public class ASTFrame extends JFrame {
19: // The initial width and height of the frame
20: static final int WIDTH = 200;
21: static final int HEIGHT = 300;
22:
23: class MyTreeSelectionListener implements TreeSelectionListener {
24: public void valueChanged(TreeSelectionEvent event) {
25: TreePath path = event.getPath();
26: System.out.println("Selected: "
27: + path.getLastPathComponent());
28: Object elements[] = path.getPath();
29: for (int i = 0; i < elements.length; i++) {
30: System.out.print("->" + elements[i]);
31: }
32: System.out.println();
33: }
34: }
35:
36: public ASTFrame(String lab, AST r) {
37: super (lab);
38:
39: // Create the TreeSelectionListener
40: TreeSelectionListener listener = new MyTreeSelectionListener();
41: JTreeASTPanel tp = new JTreeASTPanel(new JTreeASTModel(r), null);
42: Container content = getContentPane();
43: content.add(tp, BorderLayout.CENTER);
44: addWindowListener(new WindowAdapter() {
45: public void windowClosing(WindowEvent e) {
46: Frame f = (Frame) e.getSource();
47: f.setVisible(false);
48: f.dispose();
49: // System.exit(0);
50: }
51: });
52: setSize(WIDTH, HEIGHT);
53: }
54:
55: public static void main(String args[]) {
56: // Create the tree nodes
57: ASTFactory factory = new ASTFactory();
58: CommonAST r = (CommonAST) factory.create(0, "ROOT");
59: r.addChild((CommonAST) factory.create(0, "C1"));
60: r.addChild((CommonAST) factory.create(0, "C2"));
61: r.addChild((CommonAST) factory.create(0, "C3"));
62:
63: ASTFrame frame = new ASTFrame("AST JTree Example", r);
64: frame.setVisible(true);
65: }
66: }
|