KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.aspectj.debugger.base.*;
26 import org.aspectj.debugger.request.*;
27 import org.aspectj.debugger.tty.*;
28
29 import com.sun.jdi.*;
30 import com.sun.jdi.request.*;
31 import com.sun.jdi.event.*;
32 import java.awt.event.*;
33 import java.util.*;
34
35 /**
36  * GUIDebugger.java
37  *
38  *
39  * Created: Tue Sep 05 14:38:25 2000
40  *
41  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
42  */

43
44 public class GUIDebugger extends CommandLineDebugger {
45
46     private final static String JavaDoc[] emptyArgs = new String JavaDoc[0];
47
48     protected GUIDebugger() {
49         this(emptyArgs);
50     }
51
52     protected GUIDebugger(String JavaDoc[] args) {
53         super(args, false);
54     }
55
56     public GUIDebugger(ComponentDirector gui, String JavaDoc[] args) {
57         super(args, false);
58         setGui(gui);
59     }
60
61     public boolean isGUI() {
62         return true;
63     }
64
65     private ComponentDirector gui;
66     public ComponentDirector getGui() {
67         return gui;
68     }
69     public void setGui(ComponentDirector gui) {
70         this.gui = gui;
71     }
72
73     public String JavaDoc getClassNameToRun() {
74         return null;
75     }
76
77     public String JavaDoc getClasspath() {
78         return null;
79     }
80
81     public String JavaDoc getVMParameters() {
82         return null;
83     }
84
85
86     /************************** Over-ridden commands **************************/
87
88     public void viewCommand(String JavaDoc sourceName, List sourceLines)
89         throws NoVMException, DebuggerException {
90         ComponentRepository.getSourcePane().showSource(sourceName);
91     }
92
93     public void whereCommand(String JavaDoc threadName, List frames)
94         throws NoVMException, DebuggerException {
95         if (frames == null || frames.size() == 0) return;
96         StackFrame frame = (StackFrame) frames.get(0);
97         if (frame == null) return;
98         expand(frame);
99         ComponentRepository.getSourcePane().
100             showSourceForFrame(frame, false);
101         ThreadReference threadRef = getDebugger().getThread(threadName);
102         ComponentRepository.getStackTablePane().
103             showForThread(threadRef);
104     }
105
106     public void localsCommand(List locals)
107         throws NoVMException, DebuggerException {
108         super.localsCommand(locals);
109         expandToLocals();
110     }
111
112     public void printCommand(Object JavaDoc valueRep, Value value)
113         throws NoVMException, DebuggerException {
114         super.printCommand(valueRep, value);
115         expandToValue(value, valueRep);
116     }
117
118     public void dumpCommand(Object JavaDoc valueRep, Value value)
119         throws NoVMException, DebuggerException {
120         super.dumpCommand(valueRep, value);
121         expandToValue(value, valueRep);
122     }
123
124     public void evalCommand(Object JavaDoc valueRep, Value value)
125         throws NoVMException, DebuggerException {
126         super.evalCommand(valueRep, value);
127         expandToValue(value, valueRep);
128     }
129
130     public void listCommand(List sourceLines)
131         throws NoVMException, DebuggerException {
132         if (sourceLines.size() == 0) {
133             return;
134         }
135         SourceManager.SourceLine slFirst =
136             (SourceManager.SourceLine)sourceLines.get(0);
137         SourceManager.SourceLine slLast =
138             (SourceManager.SourceLine)sourceLines.get(sourceLines.size()-1);
139         String JavaDoc sourceName = slFirst.getSourceName();
140         int first = slFirst.getLineNumber();
141         int last = slLast.getLineNumber();
142         if (first > 0 && last > 0) {
143             int middle = first;
144             ComponentRepository.getSourcePane().
145                 showSourceForFileAndLine(sourceName, middle);
146         } else {
147             ComponentRepository.getSourcePane().
148                 showSource(sourceName);
149         }
150     }
151
152     public void listCommand(String JavaDoc sourceName, List sourceLines)
153         throws NoVMException, DebuggerException {
154         listCommand(sourceLines);
155     }
156
157     public void listCommand(String JavaDoc sourceName,
158                             int lineNumber,
159                             SourceManager.SourceLine sl)
160         throws NoVMException, DebuggerException {
161         List sourceLines = new Vector();
162         sourceLines.add(sl);
163         listCommand(sourceLines);
164     }
165
166     public void listCommand(String JavaDoc sourceName,
167                             int startLine,
168                             int endLine,
169                             List sourceLines)
170         throws NoVMException, DebuggerException {
171         listCommand(sourceLines);
172     }
173
174     public void useCommand(String JavaDoc sourcePath, String JavaDoc newSourcePath)
175         throws NoVMException, DebuggerException {
176         super.useCommand(sourcePath, newSourcePath);
177 // ComponentRepository.setRoot(newSourcePath);
178
// ComponentRepository.getClassTreePane().loadAJCClasses(newSourcePath);
179
}
180
181     public void connectCommand(VirtualMachine vm)
182         throws NoVMException, DebuggerException {
183         if (vm != null) {
184             result("Connected to " + vm.name());
185         }
186     }
187
188     private void expand(LocatableEvent e) {
189         try {
190             expand(e.thread().frame(0));
191         } catch (IncompatibleThreadStateException itse) {
192         }
193     }
194
195     private void expand(StackFrame frame) {
196         ComponentRepository.getThreadGroupTreePane().expandToFrame(frame);
197         //XXX Something's forcing us to do this twice, figure it out later...
198
//ComponentRepository.getThreadGroupTreePane().expandToFrame(frame);
199
}
200
201     private void expandToLocals() {
202         try {
203             ComponentRepository.getThreadGroupTreePane().
204                 expandToLocals(getDebugger().getDefaultFrame());
205         } catch (NoVMException nvme) {
206         }
207     }
208
209     private void expandToValue(Value value, Object JavaDoc valueRep) {
210         ComponentRepository.getThreadGroupTreePane().
211             expandToValue(value, valueRep + "");
212     }
213
214     public boolean wantsToExit() {
215         return false;
216     }
217
218     public void exit() {
219         gui.shutDown();
220         debugger.shutDown();
221         super.exit();
222     }
223
224     public boolean canRestart() {
225         return true;
226     }
227
228     public static String JavaDoc d() { return "GUI Debugger"; }
229     public String JavaDoc toString() { return d(); }
230
231     public VirtualMachine connect(String JavaDoc vmArgs,
232                                   String JavaDoc className,
233                                   String JavaDoc commandLine) {
234         return ConnectFrame.vm(this, vmArgs, className, commandLine);
235     }
236 }
237
Popular Tags