KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.aspectj.debugger.base.*;
28 import org.aspectj.debugger.request.*;
29 import org.aspectj.tools.ide.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.io.*;
33 import java.util.*;
34 import java.util.List JavaDoc;
35 import javax.swing.*;
36
37 /**
38  * A class encapsulating the abstract behavior of a source file viewer. This class'
39  * abstract methods are teh basic behavior required by a graphical debugger.
40  *
41  * @author <a HREF="mailto:palm@parc.xerox.com"Jeffrey Palm</a>
42  */

43 public abstract class AbstractSourcePane
44     extends AJPanel
45     implements DebuggerListener,
46                VMListener,
47                StopListener {
48
49     protected ComponentDirector director;
50
51     public AbstractSourcePane(GUIDebugger guid) {
52         super(guid);
53         debugger().addDebuggerListener(this);
54         debugger().addVMListener(this);
55         debugger().addStopListener(this);
56         this.director = guid.getGui();
57     }
58
59     /**
60      * Displays the source file with relative path <code>relativePath</code>.
61      *
62      * @param relativePath The relative path of the source we want to view.
63      */

64     public abstract boolean showSource(String JavaDoc relativePath);
65
66     /**
67      * This method will display the current source file at line number <code>line</code>
68      * and display a breakpoint token if <code>isAtBreakpoint</code> is <code>true</code>.
69      *
70      * @param line Line number from 1 to N to display.
71      * @param isAtBreakpoint Whether the program is broken at line <code>line</code>.
72      */

73     public abstract void showLineForCurrentModel(int line, boolean isAtBreakpoint);
74
75     /**
76      * Returns the name of the current source file.
77      *
78      * @return The name of the currrent source file.
79      */

80     public abstract String JavaDoc getSourceName();
81
82     /**
83      * This method is invoked by the debugger when a breakpoint is set at line number
84      * <code>line</code> in file <code>filename</code>. The implementing source pane
85      * should take the necessary steps when this occurs.
86      *
87      * @param filename The file at which the program broke.
88      * @param line The line number at which the program broke.
89      * @param ba The <code>org.aspectj.debugger.base.BreakpointRequestAction</code>
90      * that describes the breakpoint.
91      * @see #org.aspectj.debugger.base.BreakpointRequestAction
92      */

93     public abstract void requestSet(String JavaDoc filename, int line,
94                                     BreakpointRequestAction ba);
95
96     /**
97      * This method is invoked by the debugger when a breakpoint is cleared at line number
98      * <code>line</code> in file <code>filename</code>. The implementing source pane
99      * should take the necessary steps when this occurs.
100      *
101      * @param filename The file at which the program broke.
102      * @param line The line number at which the program broke.
103      * @param ba The <code>org.aspectj.debugger.base.BreakpointRequestAction</code>
104      * that describes the breakpoint.
105      * @see #org.aspectj.debugger.base.BreakpointRequestAction
106      */

107     public abstract void requestClear(String JavaDoc filename, int line,
108                                       BreakpointRequestAction ba);
109
110     /**
111      * This method is invoked by the debugger when a breakpoint is deferred at line number
112      * <code>line</code> in file <code>filename</code>. The implementing source pane
113      * should take the necessary steps when this occurs.
114      *
115      * @param filename The file at which the program broke.
116      * @param line The line number at which the program broke.
117      * @param ba The <code>org.aspectj.debugger.base.BreakpointRequestAction</code>
118      * that describes the breakpoint.
119      * @see #org.aspectj.debugger.base.BreakpointRequestAction
120      */

121     public abstract void requestDeferred(String JavaDoc filename, int line,
122                                          BreakpointRequestAction ba);
123
124
125     // ---------------------------------- Access methods ---------------------------------
126

127     /**
128      * Returns whether the file exists or not.
129      *
130      * @param relativePath The relative path name of the file.
131      * @return Whether the file exists.
132      */

133     public /*abstract*/ boolean fileExists(String JavaDoc relativePath) {
134         String JavaDoc fullPath = debugger().getFullSourcePath(relativePath);
135         File file = new File(fullPath);
136         if (file != null && file.exists()) {
137             return true;
138         }
139         return false;
140     }
141
142     public String JavaDoc getSourcePath() {
143         return debugger().getSourceManager().getSourcePath();
144     }
145
146     public SourceManager getSourceManager() {
147         return debugger.getSourceManager();
148     }
149
150     public void showSourceForFrame(StackFrame frame, boolean isAtBreakpoint) {
151         try {
152             showSourceForLocation(frame.location(), isAtBreakpoint);
153         } catch (InvalidStackFrameException isfe) {
154         }
155     }
156
157     public void showSourceForLocation(Location loc, boolean isAtBreakpoint) {
158         SourceLine sl = null;
159         try {
160             sl = debugger().sourceLine(loc);
161         } catch (AbsentInformationException aie) {
162             return;
163         }
164         if (sl == null) {
165             return;
166         }
167         if (sl.line < 0) {
168             return;
169         }
170         if (fileExists(sl.filename)) {
171             if (showSource(sl.filename)) {
172                 showLineForCurrentModel(sl.line, isAtBreakpoint);
173             }
174         }
175         director.makeTopLevel();
176     }
177
178     public void showSourceForLocation(Location loc) {
179         showSourceForLocation(loc, false);
180     }
181
182     public void showSourceForFileAndLine(String JavaDoc relativePath, int line) {
183         if (line < 0) {
184             return;
185         }
186         if (!(new File(relativePath).exists()) &&
187             !(new File(AJLineMapper.removeRoot(relativePath)).exists())) {
188             return;
189         }
190         if (fileExists(relativePath)) {
191             if (showSource(relativePath)) {
192                 showLineForCurrentModel(line);
193             }
194         }
195         director.makeTopLevel();
196     }
197
198     protected void showLineForCurrentModel(int line) {
199         showLineForCurrentModel(line, false);
200     }
201
202     public File getPath() {
203         return new File(getSourceName());
204     }
205
206     /****************************** DebuggerListener ******************************/
207
208     public void requestSetEvent(RequestEvent re) {
209         Request request = re.getRequest();
210         if (request instanceof BreakpointRequestAction) {
211             BreakpointRequestAction ba = (BreakpointRequestAction) request;
212             SourceLine sl = debugger().getSourceLine(ba);
213             requestSet(sl.filename, sl.line, ba);
214         }
215     }
216     public void requestClearEvent(RequestEvent re) {
217         Request request = re.getRequest();
218         if (request instanceof BreakpointRequestAction) {
219             BreakpointRequestAction ba = (BreakpointRequestAction) request;
220             SourceLine sl = debugger().getSourceLine(ba);
221             requestClear(sl.filename, sl.line, ba);
222         }
223     }
224     public void requestDeferredEvent(RequestEvent re) {
225         Request request = re.getRequest();
226         if (request instanceof BreakpointRequestAction) {
227             BreakpointRequestAction ba = (BreakpointRequestAction) request;
228             SourceLine sl = debugger().getSourceLine(ba);
229             requestDeferred(sl.filename, sl.line, ba);
230         }
231     }
232     public void requestFailedEvent(RequestEvent re) {
233     }
234
235     /****************************** VMListener ******************************/
236
237     public void vmStartEvent(VMStartEvent e) {
238     }
239     public void vmDeathEvent(VMDeathEvent e) {
240     }
241     public void vmDisconnectEvent(VMDisconnectEvent e) {
242     }
243
244     /****************************** StopListener ******************************/
245     public void accessWatchpointEvent(AccessWatchpointEvent e) {
246         showSourceForLocation(e.location());
247     }
248     public void breakpointEvent(BreakpointEvent e) {
249         showSourceForLocation(e.location());
250     }
251     public void exceptionEvent(ExceptionEvent e) {
252         showSourceForLocation(e.location());
253     }
254     public void modificationWatchpointEvent(ModificationWatchpointEvent e) {
255         showSourceForLocation(e.location());
256     }
257     public void stepEvent(StepEvent e) {
258         showSourceForLocation(e.location());
259     }
260
261     public static String JavaDoc d() { return "Source Pane"; }
262     public String JavaDoc toString() { return d(); }
263
264
265 }
266
Popular Tags