KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > debugger > tree > DBParseTreePanel


1 package org.antlr.works.debugger.tree;
2
3 import org.antlr.xjlib.appkit.gview.GView;
4 import org.antlr.runtime.Token;
5 import org.antlr.works.awtree.AWTreePanel;
6 import org.antlr.works.awtree.AWTreePanelDelegate;
7 import org.antlr.works.debugger.Debugger;
8 import org.antlr.works.swing.DetachablePanel;
9
10 import javax.swing.*;
11 import javax.swing.tree.DefaultTreeModel JavaDoc;
12 import javax.swing.tree.TreeNode JavaDoc;
13 import java.awt.*;
14 /*
15
16 [The "BSD licence"]
17 Copyright (c) 2005-2006 Jean Bovet
18 All rights reserved.
19
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions
22 are met:
23
24 1. Redistributions of source code must retain the above copyright
25 notice, this list of conditions and the following disclaimer.
26 2. Redistributions in binary form must reproduce the above copyright
27 notice, this list of conditions and the following disclaimer in the
28 documentation and/or other materials provided with the distribution.
29 3. The name of the author may not be used to endorse or promote products
30 derived from this software without specific prior written permission.
31
32 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
33 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
34 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
35 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
36 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
37 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
41 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
43 */

44
45 public class DBParseTreePanel extends DetachablePanel implements DBParseTreeModelListener, AWTreePanelDelegate {
46
47     protected Debugger debugger;
48     protected DBParseTreeModel model;
49     protected AWTreePanel treePanel;
50
51     public DBParseTreePanel(Debugger debugger) {
52         super("Parse Tree", debugger);
53
54         this.debugger = debugger;
55
56         model = new DBParseTreeModel(debugger);
57         model.addListener(this);
58         
59         treePanel = new AWTreePanel(new DefaultTreeModel JavaDoc(null));
60         treePanel.setDelegate(this);
61
62         mainPanel.add(treePanel, BorderLayout.CENTER);
63     }
64
65     public DBParseTreeModel getModel() {
66         return model;
67     }
68
69     public void clear() {
70         model.clear();
71         treePanel.clear();
72     }
73
74     public void updateOnBreakEvent() {
75         model.fireDataChanged();
76     }
77     
78     public void selectToken(Token token) {
79         DBTreeNode root = (DBTreeNode) treePanel.getRoot();
80         DBTreeNode node = root.findNodeWithToken(token);
81         if(node != null)
82             treePanel.selectNode(node);
83     }
84
85     public void updateParseTree() {
86         treePanel.refresh();
87         treePanel.scrollNodeToVisible(model.getLastNode());
88     }
89
90     public GView getGraphView() {
91         return treePanel.getGraphView();
92     }
93
94     public void modelChanged(DBParseTreeModel model) {
95         treePanel.setRoot(model.getRootRule());
96         updateParseTree();
97     }
98
99     public void modelUpdated(DBParseTreeModel model) {
100         updateParseTree();
101     }
102
103     public void awTreeDidSelectTreeNode(TreeNode JavaDoc node, boolean shiftKey) {
104         DBTreeNode n = (DBTreeNode) node;
105         debugger.selectToken(n.token, n.line, n.pos);
106     }
107
108     public JPopupMenu awTreeGetContextualMenu() {
109         return debugger.treeGetContextualMenu();
110     }
111
112 }
113
Popular Tags