KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > VariablesTreePane


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.gui;
24
25 import com.sun.jdi.*;
26 import com.sun.jdi.event.*;
27 import com.sun.jdi.request.*;
28 import org.aspectj.debugger.base.*;
29 import org.aspectj.debugger.request.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.util.*;
33 import java.util.List JavaDoc;
34 import javax.swing.*;
35 import javax.swing.event.*;
36 import javax.swing.tree.*;
37 import javax.swing.plaf.*;
38 import javax.swing.plaf.basic.*;
39
40 public class VariablesTreePane
41     extends AJPanel
42     implements StopListener
43 {
44
45     private VariablesTree tree = null;
46
47     public VariablesTreePane(Frame frame, GUIDebugger guid) {
48         super(guid);
49         debugger().addStopListener(this);
50         setLayout(new BorderLayout());
51         add(new JScrollPane(tree = new VariablesTree(frame)),
52             BorderLayout.CENTER);
53
54     }
55
56     /****************************** StopListener ******************************/
57     public void accessWatchpointEvent(AccessWatchpointEvent e) {
58         updateLocals();
59     }
60     public void breakpointEvent(BreakpointEvent e) {
61         updateLocals();
62     }
63     public void exceptionEvent(ExceptionEvent e) {
64         updateLocals();
65     }
66     public void modificationWatchpointEvent(ModificationWatchpointEvent e) {
67         updateLocals();
68     }
69     public void stepEvent(StepEvent e) {
70         updateLocals();
71     }
72
73     private DefaultMutableTreeNode getRoot() {
74         return (DefaultMutableTreeNode) tree.getModel().getRoot();
75     }
76
77     private void newRoot() {
78         model().setRoot(new VariablesRootTreeNode());
79     }
80
81     private DefaultTreeModel model() {
82         return (DefaultTreeModel) tree.getModel();
83     }
84     
85     private void updateLocals() {
86         newRoot();
87         List JavaDoc locals = debugger().locals();
88         Iterator iter;
89         iter = locals.iterator();
90         while (iter.hasNext()) {
91             try {
92                 add(AJValueNodeFactory.make((LocalVariable) iter.next(),
93                                             debugger.getDefaultFrame()));
94             } catch (Exception JavaDoc e) { AJUtil.ex(e);
95             }
96         }
97         try {
98             ObjectReference oref = debugger().getDefaultThisObject();
99             ReferenceType refType = debugger().getDefaultFrame().location().declaringType();
100             List JavaDoc fields = refType.fields();
101             iter = fields.iterator();
102             while (iter.hasNext()) {
103                 Field field = (Field) iter.next();
104                 if (shouldAddField(field)) {
105                     if (oref != null) {
106                         add(AJValueNodeFactory.make(oref, field));
107                     } else if (field.isStatic()) {
108                         add(AJValueNodeFactory.make(refType, field));
109                     }
110                 }
111             }
112         } catch (Exception JavaDoc e) { AJUtil.ex(e);
113         }
114         tree.expandRow(0);
115     }
116
117     private boolean shouldAddField(Field field) {
118         return field != null && (field.name().indexOf("$ajc") == -1);
119     }
120
121     private void add(MutableTreeNode node) {
122         boolean expand = getRoot().getChildCount() == 0;
123         getRoot().add(node);
124         // This was messing it up some how...
125
//if (expand) tree.expandRow(0);
126
}
127
128     public static String JavaDoc d() { return "Variables Tree Pane"; }
129     public String JavaDoc toString() { return d(); }
130 }
131
132 class VariablesTree extends AJTree {
133     private Frame frame = null;
134     public VariablesTree(Frame frame) {
135         super(new VariablesTreeModel());
136         this.frame = frame;
137         setCellRenderer(new VariablesTreeCellRenderer());
138         addTreeWillExpandListener(new NoCollapsingRootExpansionListener(this));
139     }
140     public void clear() {
141         setModel(new VariablesTreeModel());
142     }
143 }
144
145 class VariablesTreeCellRenderer extends AJTreeCellRenderer {
146 }
147
148 class VariablesTreeModel extends DefaultTreeModel {
149     public VariablesTreeModel() {
150         super(new VariablesRootTreeNode());
151     }
152 }
153
154 class VariablesRootTreeNode extends AJRootNode {
155     public VariablesRootTreeNode() {
156         super(Titles.VARIABLES, AJIcons.VARIABLES_ICON);
157     }
158 }
159
160
161
162 class VariablesTreeNode extends AJTreeNode {
163     public VariablesTreeNode(Object JavaDoc o) {
164         super(AJIcons.BAD_ICON);
165     }
166 }
167
Popular Tags