01: package antlr.debug.misc;
02:
03: /* ANTLR Translator Generator
04: * Project led by Terence Parr at http://www.cs.usfca.edu
05: * Software rights: http://www.antlr.org/license.html
06: */
07:
08: import java.awt.*;
09: import javax.swing.*;
10: import javax.swing.tree.*;
11: import javax.swing.event.*;
12:
13: public class JTreeASTPanel extends JPanel {
14: JTree tree;
15:
16: public JTreeASTPanel(TreeModel tm, TreeSelectionListener listener) {
17: // use a layout that will stretch tree to panel size
18: setLayout(new BorderLayout());
19:
20: // Create tree
21: tree = new JTree(tm);
22:
23: // Change line style
24: tree.putClientProperty("JTree.lineStyle", "Angled");
25:
26: // Add TreeSelectionListener
27: if (listener != null)
28: tree.addTreeSelectionListener(listener);
29:
30: // Put tree in a scrollable pane's viewport
31: JScrollPane sp = new JScrollPane();
32: sp.getViewport().add(tree);
33:
34: add(sp, BorderLayout.CENTER);
35: }
36: }
|