KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.aspectj.debugger.gui;
23
24 import org.aspectj.debugger.base.*;
25 import org.aspectj.util.gui.*;
26
27 import java.awt.*;
28 import java.awt.event.*;
29 import javax.swing.*;
30 import java.util.*;
31 import java.util.List JavaDoc;
32 import java.io.*;
33
34 import com.sun.jdi.*;
35
36 public class Dialogs {
37
38     public static void showBreakpointDialog() {
39         new BreakpointDialog(ComponentRepository.
40                              getComponentDirector()).show();
41     }
42
43     public static void showSetBreakpointDialog() {
44         new SetBreakpointDialog(ComponentRepository.
45                                 getComponentDirector()).show();
46     }
47
48     public static void showClearBreakpointDialog() {
49         new ClearBreakpointDialog(ComponentRepository.
50                                   getComponentDirector()).show();
51     }
52
53     public static void showNewValueDialog(AJValueNode node) {
54         new AJNewValueDialog(ComponentRepository.
55                              getComponentDirector(), node).popup(node);
56     }
57
58     public static void showRunDialog() {
59         new RunDialog().show();
60     }
61
62     public static void showCatchDialog() {
63         new CatchDialog().show();
64     }
65
66     public static void showWatchDialog() {
67         new WatchDialog().show();
68     }
69
70     public static void showUseDialog() {
71         new UseDialog().show();
72 // new UseFileChooser().use();
73
}
74
75     public static void showDumpDialog() {
76         new DumpDialog().show();
77     }
78
79     public static void showEvalDialog() {
80         new EvalDialog().show();
81     }
82
83     public static void showFieldsDialog() {
84         new FieldsDialog().show();
85     }
86
87     public static void showLocalsDialog() {
88         new LocalsDialog().show();
89     }
90
91     public static void showPrintDialog() {
92         new PrintDialog().show();
93     }
94
95     public static String JavaDoc showSuspendDialog() {
96         return showThreadDialog("suspend", "Suspend");
97     }
98
99     public static String JavaDoc showResumeDialog() {
100         return showThreadDialog("resume", "Ruspend");
101     }
102
103     public static String JavaDoc showWhereDialog() {
104         return showThreadDialog("view", "View");
105     }
106
107     public static void showHelpDialog() {
108
109     }
110
111     public static void showExecuteDialog() {
112         new ExecuteDialog().show();
113     }
114
115     public static void showAboutDialog() {
116         String JavaDoc msg = "by the aspectj.org team (C)";
117         msg += "\n" + ComponentRepository.getAJDebugger().version();
118         int type = JOptionPane.INFORMATION_MESSAGE;
119         String JavaDoc title = "About AJBuilder";
120         JOptionPane.showMessageDialog
121             (ComponentRepository.getComponentDirector(),
122              msg,
123              title,
124              type);
125     }
126
127     static String JavaDoc showThreadDialog(String JavaDoc msg, String JavaDoc action) {
128         try {
129           Iterator iter = ComponentRepository.getAJDebugger().vm().
130               allThreads().iterator();
131             Vector v = new Vector();
132             v.add(new AJToolBar.ThreadPair("All threads", -1));
133             while (iter.hasNext()) {
134                 Object JavaDoc o = iter.next();
135                 ThreadReference thread =
136                     (ThreadReference)iter.next(); //threadInfo.thread;
137
String JavaDoc name = thread.name();
138                 long id = thread.uniqueID();
139                 AJToolBar.ThreadPair pair = new AJToolBar.ThreadPair(name, id);
140                 v.add(pair);
141             }
142             Object JavaDoc[] os = v.toArray();
143             AJToolBar.ThreadPair selected =
144                 (AJToolBar.ThreadPair)
145                 JOptionPane.showInputDialog
146                 (ComponentRepository.getComponentDirector(),
147                  "Please select a thread to " + msg,
148                  action + " a thread",
149                  JOptionPane.QUESTION_MESSAGE,
150                  null,
151                  os,
152                  os[0]);
153             if (selected != null && selected.id != -1) {
154                 return selected.id + "";
155             }
156         } catch (Exception JavaDoc e) {
157         }
158         return null;
159     }
160
161     public void showMonitorDialog() {
162         new MonitorDialog(ComponentRepository.getGUIDebugger()).show();
163     }
164
165     public static void main(String JavaDoc[] args) {
166         String JavaDoc s = showSuspendDialog();
167         System.out.println("> " + s);
168     }
169 }
170
171 class UseFileChooser extends JFileChooser {
172     public UseFileChooser() {
173         super(".");
174     }
175
176     public javax.swing.filechooser.FileFilter JavaDoc getFileFilter() {
177         return new javax.swing.filechooser.FileFilter JavaDoc() {
178             public boolean accept(File file) {
179                 return file.isDirectory();
180             }
181             public String JavaDoc getDescription() {
182                 return "Paths to source files";
183             }
184         };
185     }
186
187     public void use() {
188         int val = showDialog(null, "Use");
189         if (val != APPROVE_OPTION) return;
190         String JavaDoc sourcePath = getSelectedFile().getAbsolutePath();
191         try {
192             ComponentRepository.getAJDebugger().
193                 useCommand(sourcePath);
194         } catch (DebuggerException de) {
195         }
196     }
197 }
198
199 class UseDialog extends SingleCommandDialog {
200     public UseDialog() {
201         super("Use", "Please select the source path",
202               "use", "Set");
203     }
204 }
205
206
207 class RunDialog extends SingleCommandDialog {
208     public RunDialog() {
209         super("Run", "Please select a class to run",
210               "run", "Run");
211     }
212 }
213
214 class CatchDialog extends SingleCommandDialog {
215     public CatchDialog() {
216         super("Catch", "Please select an exception class to catch",
217               "catch", "Catch");
218     }
219 }
220
221 class WatchDialog extends SingleCommandDialog {
222     public WatchDialog() {
223         super("Watch", "Please select a field",
224               "watch access", "Watch");
225     }
226 }
227
228 class DumpDialog extends SingleCommandDialog {
229     public DumpDialog() {
230         super("Dump", "Please select an object to dump",
231               "dump", "Dump");
232     }
233 }
234
235 class PrintDialog extends SingleCommandDialog {
236     public PrintDialog() {
237         super("Print", "Please select a instance of value to print",
238               "print", "Print");
239     }
240 }
241
242 class EvalDialog extends SingleCommandDialog {
243     public EvalDialog() {
244         super("Evaluate", "Please select a instance of value to evaluate",
245               "eval", "Evaluate");
246     }
247 }
248
249 class FieldsDialog extends SingleCommandDialog {
250     public FieldsDialog() {
251         super("Fields", "Please select an object",
252               "fields", "View Fields");
253     }
254 }
255
256 class LocalsDialog extends SingleCommandDialog {
257     public LocalsDialog() {
258         super("Locals", "Please select an object",
259               "locals", "View Locals");
260     }
261 }
262
263 class ExecuteDialog extends SingleCommandDialog {
264     public ExecuteDialog() {
265         super("Execute", "Please enter a command",
266               null, "Execute");
267     }
268 }
269
270
271 class SingleCommandDialog extends CenteredJDialog {
272
273     ClassTextField field = new ClassTextField(30);
274     String JavaDoc commandStr = null;
275
276     public SingleCommandDialog(String JavaDoc titleStr, String JavaDoc labelStr,
277                                String JavaDoc commandStr, String JavaDoc buttonStr) {
278         super(ComponentRepository.getComponentDirector(), titleStr, true);
279         this.commandStr = commandStr;
280         JPanel panel = new JPanel();
281         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
282         JLabel title = new JLabel(labelStr);
283         field.addActionListener(new ActionListener() {
284             public void actionPerformed(ActionEvent e) {
285                 doStuff();
286         }});
287         JPanel buttons = new JPanel();
288         JButton stuffButton = new JButton(buttonStr);
289         stuffButton.addActionListener(new ActionListener() {
290             public void actionPerformed(ActionEvent e) {
291                 doStuff();
292         }});
293         JButton cancelButton = new JButton("Cancel");
294         cancelButton.addActionListener(new ActionListener() {
295             public void actionPerformed(ActionEvent e) {
296                 cancel();
297         }});
298         buttons.add(stuffButton);
299         buttons.add(cancelButton);
300         panel.add(title);
301         panel.add(field);
302         panel.add(buttons);
303         setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
304         setContentPane(panel);
305     }
306
307     private void doStuff() {
308         String JavaDoc cmd = field.getText();
309         String JavaDoc commandPrefix = commandStr != null ? commandStr + " " : "";
310         ComponentRepository.getAJDebugger().execute(commandPrefix + cmd);
311         dispose();
312     }
313
314     private void cancel() {
315         dispose();
316     }
317 }
318
319 class MonitorDialog extends CenteredJFrame {
320
321     GUIDebugger guid;
322
323     public MonitorDialog(GUIDebugger guid) {
324         this.guid = guid;
325     }
326 }
327
Popular Tags