1 package persistence.antlr.debug.misc; 2 3 8 9 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 static final int WIDTH = 200; 21 static final int HEIGHT = 300; 22 23 class MyTreeSelectionListener 24 implements TreeSelectionListener { 25 public void valueChanged(TreeSelectionEvent event) { 26 TreePath path = event.getPath(); 27 System.out.println("Selected: " + 28 path.getLastPathComponent()); 29 Object elements[] = path.getPath(); 30 for (int i = 0; i < elements.length; i++) { 31 System.out.print("->" + elements[i]); 32 } 33 System.out.println(); 34 } 35 } 36 37 public ASTFrame(String lab, AST r) { 38 super(lab); 39 40 TreeSelectionListener listener = new MyTreeSelectionListener(); 42 JTreeASTPanel tp = new JTreeASTPanel(new JTreeASTModel(r), null); 43 Container content = getContentPane(); 44 content.add(tp, BorderLayout.CENTER); 45 addWindowListener(new WindowAdapter() { 46 public void windowClosing(WindowEvent e) { 47 Frame f = (Frame)e.getSource(); 48 f.setVisible(false); 49 f.dispose(); 50 } 52 }); 53 setSize(WIDTH, HEIGHT); 54 } 55 56 public static void main(String args[]) { 57 ASTFactory factory = new ASTFactory(); 59 CommonAST r = (CommonAST)factory.create(0, "ROOT"); 60 r.addChild((CommonAST)factory.create(0, "C1")); 61 r.addChild((CommonAST)factory.create(0, "C2")); 62 r.addChild((CommonAST)factory.create(0, "C3")); 63 64 ASTFrame frame = new ASTFrame("AST JTree Example", r); 65 frame.setVisible(true); 66 } 67 } 68 | Popular Tags |