KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.gui.*;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.io.*;
31 import java.util.*;
32 import java.util.List JavaDoc;
33 import javax.swing.*;
34 import javax.swing.event.*;
35
36 import com.sun.jdi.*;
37
38 // aspect ClassInsightAspectSupport {
39

40 // /** The static list of classes. */
41
// static Vector classes = null;
42

43 // /** The current class index in classes. */
44
// static int index = 0;
45

46 // /**
47
// * Move <i>up</i> one slot in the <code>classes</code> history and
48
// * insert that class into the text field.
49
// */
50
// static void superUp() {
51
// lazyInit();
52
// if (--index < 0) {
53
// index = classes.size() - 1;
54
// }
55
// }
56

57 // /**
58
// * Move <i>down</i> one slot in the <code>classes</code> history and
59
// * insert that class into the text field.
60
// */
61
// static void superDown() {
62
// lazyInit();
63
// index = (index + 1) % classes.size();
64
// }
65

66 // static String currentClass() {
67
// return classes.get(index) + "";
68
// }
69

70 // /* -------------------------------------------------------
71
// * Getting Classes
72
// * -------------------------------------------------------
73
// */
74

75 // /**
76
// * The pointcut <code>PointCuts.getClass(Object)</code> defines
77
// * all instances in the execution in the program where the user
78
// * can enter a class. Therefore, whenever this occurs, we want
79
// * to grab this class and put it in the global list
80
// * <code>classes</code>.
81
// */
82
// static around(Object clazz) returns void: PointCuts.getClass(clazz) {
83
// thisJoinPoint.runNext(clazz);
84
// lazyInit();
85
// String classID = clazz + "";
86
// add(classID);
87
// }
88

89 // /**
90
// * Add a class to the list of <code>classes</code>. If it already exists,
91
// * then remove the other entry and put this one at the top.
92
// */
93
// static void add(String classID) {
94
// classID = translate(classID);
95
// if (classes.contains(classID)) {
96
// classes.remove(classID);
97
// } else {
98
// index++;
99
// }
100
// classes.add(classID);
101
// }
102

103 // static String translate(String classWithPossibleGarbageCharacters) {
104
// char[] chars = classWithPossibleGarbageCharacters.toCharArray();
105
// for (int i = 0; i < chars.length; i++) {
106
// if (!Character.isJavaIdentifierPart(chars[i])) {
107
// chars[i] = '.';
108
// }
109
// }
110
// return new String(chars);
111
// }
112

113
114 // /**
115
// * We also want to get classes named after files, so we will advise
116
// * the pointcut <code>PointCuts.getSource(Object)</code> and strip off
117
// * the '.java' ending.
118
// */
119
// static around(Object source) returns void: PointCuts.getSource(source) {
120
// thisJoinPoint.runNext(source);
121
// lazyInit();
122
// String classID = source + "";
123
// int ijava = classID.lastIndexOf(".java");
124
// if (ijava != -1) {
125
// classID = classID.substring(0, ijava);
126
// }
127
// add(classID);
128
// }
129

130 // /**
131
// * Allow a blank space in the class list, so the user can scroll
132
// * to empty instead of having to delete if s/he wants to enter a
133
// * new class and has been scrolling.
134
// */
135
// static void lazyInit() {
136
// if (classes == null) {
137
// classes = new Vector();
138
// classes.add("");
139
// }
140
// }
141

142 // /**
143
// * Returns the lastest class used.
144
// */
145
// static String latest() {
146
// lazyInit();
147
// return classes.get(classes.size() - 1) + "";
148
// }
149
// }
150

151 // /**
152
// * This aspect provides contextual information to text boxes
153
// * expecting class information as input.
154
// */
155
// aspect ClassInsightAspect extends ClassInsightAspectSupport
156
// of eachobject(instanceof(ClassTextField)) {
157

158 // /** The text field to which this aspect is attached. */
159
// private ClassTextField field = null;
160

161 // /* -------------------------------------------------------
162
// * Insight
163
// * -------------------------------------------------------
164
// */
165

166 // /**
167
// * When a <code>ClassTextField</code> is created, make it this
168
// * aspect's <code>field</code>.
169
// */
170
// pointcut ctr(ClassTextField f): receptions(new(..)) && instanceof(f);
171
// after(ClassTextField f) returning (): ctr(f) {
172
// field = f;
173
// prepare(field);
174
// index = 0;
175
// }
176

177 // /**
178
// * Prepare any component to respond accordingly to up and down
179
// * buttons presses, and mouse clicks.
180
// */
181
// void prepare(JComponent c) {
182
// reg(c, new UpAction(), KeyEvent.VK_UP, 0);
183
// reg(c, new DownAction(), KeyEvent.VK_DOWN, 0);
184
// c.addMouseListener(new MouseAdapter() {
185
// public void mouseClicked(MouseEvent e) {
186
// if (e.getClickCount() == 2) {
187
// showAllClasses();
188
// } else if (SwingUtilities.isRightMouseButton(e)) {
189
// showHistory();
190
// }
191
// }});
192
// }
193

194 // void reg(JComponent c, Action a, int key, int mods) {
195
// FocusAspect.reg(c, a, key, mods, JComponent.WHEN_FOCUSED);
196
// }
197

198 // /**
199
// * The action to perform upon an <i>up</i> button press.
200
// */
201
// private class UpAction extends AbstractAction {
202
// public void actionPerformed(ActionEvent e) {
203
// up();
204
// }
205
// }
206

207 // /**
208
// * The action to perform upon <i>down</i> button press.
209
// */
210
// private class DownAction extends AbstractAction {
211
// public void actionPerformed(ActionEvent e) {
212
// down();
213
// }
214
// }
215

216 // /**
217
// * Move <i>up</i> one slot in the <code>classes</code> history and
218
// * insert that class into the text field.
219
// */
220
// private void up() {
221
// superUp();
222
// field.setText(currentClass());
223
// }
224

225 // /**
226
// * Move <i>down</i> one slot in the <code>classes</code> history and
227
// * insert that class into the text field.
228
// */
229
// private void down() {
230
// superDown();
231
// field.setText(currentClass());
232
// }
233

234 // /**
235
// * Create a pop-up menu in which to display the classes
236
// * previously entered by the user.
237
// */
238
// void showHistory() {
239
// AJPopupMenu menu = new AJPopupMenu("Classes", classes) {
240
// public void doSomething(Object o) {
241
// setClassText(o + "");
242
// }};
243
// field.transferFocus();
244
// menu.show(field, 10, 10);
245
// menu.requestFocus();
246
// }
247

248 // /**
249
// * Create a pop-up menu in which to display all classes currently
250
// * loaded by the VM.
251
// */
252
// void showAllClasses() {
253
// Vector vec = new Vector();
254
// Iterator iter = null;
255
// try {
256
// iter = ComponentRepository.vm().allClasses().iterator();
257
// } catch (NoVMException e) {
258
// return;
259
// }
260

261 // while (iter.hasNext()) {
262
// vec.add(((ReferenceType) iter.next()).name());
263
// }
264
// AJPopupMenu menu = new AJPopupMenu("All Classes", vec) {
265
// public void doSomething(Object o) {
266
// setClassText(o + "");
267
// }};
268
// field.transferFocus();
269
// menu.show(field, 10, 10);
270
// menu.requestFocus();
271
// }
272

273 // /**
274
// * Method to set the text in <code>field</code>.
275
// */
276
// void setClassText(String clazz) {
277
// field.setText(clazz);
278
// }
279
// }
280

281 // aspect SourceInsightAspectSupport {
282

283 // /** The static list of sources. */
284
// static Vector sources = null;
285

286 // /** The current source index in sources. */
287
// static int index = 0;
288

289 // /**
290
// * Move <i>up</i> one slot in the <code>sources</code> history and
291
// * insert that source into the text field.
292
// */
293
// static void superUp() {
294
// lazyInit();
295
// if (--index < 0) {
296
// index = sources.size() - 1;
297
// }
298
// }
299

300 // /**
301
// * Move <i>down</i> one slot in the <code>sources</code> history and
302
// * insert that source into the text field.
303
// */
304
// static void superDown() {
305
// lazyInit();
306
// index = (index + 1) % sources.size();
307
// }
308

309 // static String currentSource() {
310
// return sources.get(index) + "";
311
// }
312

313 // /* -------------------------------------------------------
314
// * Getting Sources
315
// * -------------------------------------------------------
316
// */
317

318 // /**
319
// * The pointcut <code>PointCuts.getClass(Object)</code> defines
320
// * all instances in the execution in the program where the user
321
// * can enter a class. Therefore, whenever this occurs, we want
322
// * to grab this class and put it in the global list
323
// * <code>classes</code>.
324
// */
325
// static around(Object source) returns void: PointCuts.getSource(source) {
326
// thisJoinPoint.runNext(source);
327
// lazyInit();
328
// String sourceID = AJLineMapper.removeRoot(source + "");
329
// add(sourceID);
330
// }
331

332 // /**
333
// * Add a class to the list of <code>sources</code>. If it already exists,
334
// * then remove the other entry and put this one at the top.
335
// */
336
// static void add(String sourceID) {
337
// if (sources.contains(sourceID)) {
338
// sources.remove(sourceID);
339
// } else {
340
// index++;
341
// }
342
// sources.add(sourceID);
343
// }
344

345 // /**
346
// * We will also try to get source from classes using the pointcut
347
// * <code>PointCuts.getSource(Object)</code> by trying to append a
348
// * '.java' ending and seeing if the file exists.
349
// */
350
// static around(Object clazz) returns void: PointCuts.getClass(clazz) {
351
// thisJoinPoint.runNext(clazz);
352
// lazyInit();
353
// String sourceID = clazz + ".java";
354
// String fullSource = AJLineMapper.getFullFileNameFromFile(sourceID, false);
355
// try {
356
// File file = new File(fullSource);
357
// if (file == null || !file.exists()) {
358
// return;
359
// }
360
// } catch (Exception e) {
361
// }
362
// String strippedSource = AJLineMapper.removeRoot(fullSource);
363
// add(strippedSource);
364
// }
365

366 // /**
367
// * Allow a blank space in the class list, so the user can scroll
368
// * to empty instead of having to delete if s/he wants to enter a
369
// * new class and has been scrolling.
370
// */
371
// static void lazyInit() {
372
// if (sources == null) {
373
// sources = new Vector();
374
// sources.add("");
375
// }
376
// }
377

378 // /**
379
// * Returns the latest source file.
380
// */
381
// static String latest() {
382
// lazyInit();
383
// return sources.get(sources.size() - 1) + ""; }
384
// }
385

386 // /**
387
// * This aspect provides contextual information to text boxes
388
// * expecting source information as input.
389
// */
390
// aspect SourceInsightAspect
391
// extends SourceInsightAspectSupport
392
// of eachobject(instanceof(SourceTextField)) {
393

394
395 // /** The text field to which this aspect is attached. */
396
// private SourceTextField field = null;
397

398 // /* -------------------------------------------------------
399
// * Insight
400
// * -------------------------------------------------------
401
// */
402

403 // /**
404
// * When a <code>ClassTextField</code> is created, make it this
405
// * aspect's <code>field</code>.
406
// */
407
// pointcut ctr(SourceTextField f): receptions(new(..)) && instanceof(f);
408
// after(SourceTextField f) returning (): ctr(f) {
409
// field = f;
410
// prepare(field);
411
// index = 0;
412
// }
413

414 // /**
415
// * Prepare any component to respond accordingly to up and down
416
// * buttons presses, and mouse clicks.
417
// */
418
// void prepare(JComponent c) {
419
// reg(c, new UpAction(), KeyEvent.VK_UP, 0);
420
// reg(c, new DownAction(), KeyEvent.VK_DOWN, 0);
421
// c.addMouseListener(new MouseAdapter() {
422
// public void mouseClicked(MouseEvent e) {
423
// if (e.getClickCount() == 2) {
424
// showAllSources();
425
// } else if (SwingUtilities.isRightMouseButton(e)) {
426
// showHistory();
427
// }
428
// }});
429
// }
430

431 // void reg(JComponent c, Action a, int key, int mods) {
432
// FocusAspect.reg(c, a, key, mods, JComponent.WHEN_FOCUSED);
433
// }
434

435 // /**
436
// * The action to perform upon an <i>up</i> button press.
437
// */
438
// private class UpAction extends AbstractAction {
439
// public void actionPerformed(ActionEvent e) {
440
// up();
441
// }
442
// }
443

444 // /**
445
// * The action to perform upon <i>down</i> button press.
446
// */
447
// private class DownAction extends AbstractAction {
448
// public void actionPerformed(ActionEvent e) {
449
// down();
450
// }
451
// }
452

453 // /**
454
// * Move <i>up</i> one slot in the <code>sources</code> history and
455
// * insert that source into the text field.
456
// */
457
// private void up() {
458
// superUp();
459
// field.setText(currentSource());
460
// }
461

462 // /**
463
// * Move <i>down</i> one slot in the <code>sources</code> history and
464
// * insert that source into the text field.
465
// */
466
// private void down() {
467
// superDown();
468
// field.setText(currentSource());
469
// }
470

471 // /**
472
// * Create a pop-up menu in which to display the classes
473
// * previously entered by the user.
474
// */
475
// void showHistory() {
476
// AJPopupMenu menu = new AJPopupMenu("Sources", sources) {
477
// public void doSomething(Object o) {
478
// setSourceText(o + "");
479
// }};
480
// field.transferFocus();
481
// menu.show(field, 10, 10);
482
// menu.requestFocus();
483
// }
484

485 // /**
486
// * Create a pop-up menu in which to display all classes currently
487
// * loaded by the VM.
488
// */
489
// void showAllSources() {
490
// Vector vec = new Vector();
491
// String sourcePath = ComponentRepository.getSourcePane().getSourcePath() + "";
492
// String[] files = null;
493
// try {
494
// File file = new File(sourcePath);
495
// if (!file.isDirectory()) {
496
// return;
497
// }
498
// FilenameFilter filter = new FilenameFilter() {
499
// public boolean accept(File dir, String name) {
500
// if (name.endsWith(".java")) {
501
// return true;
502
// }
503
// return false;
504
// }
505
// };
506
// files = file.list(filter);
507
// } catch (Exception e) {
508
// return;
509
// }
510

511 // if (files == null || files.length == 0) {
512
// return;
513
// }
514
// for (int i = 0; i < files.length; i++) {
515
// vec.add(files[i]);
516
// }
517

518 // AJPopupMenu menu = new AJPopupMenu("All Sources", vec) {
519
// public void doSomething(Object o) {
520
// setSourceText(o + "");
521
// }};
522
// field.transferFocus();
523
// menu.show(field, 10, 10);
524
// menu.requestFocus();
525
// }
526

527 // /**
528
// * Method to set the text in <code>field</code>.
529
// */
530
// void setSourceText(String clazz) {
531
// field.setText(clazz);
532
// }
533
// }
534

535 // /**
536
// * This aspect provides contextual information to text boxes
537
// * expecting class information as input.
538
// */
539
// aspect MethodInsightAspect of eachobject(instanceof(BreakpointDialog)) {
540

541 // /** The field that will receive new key bindings. */
542
// private JTextField methodText = null;
543

544 // /** The field from which class context is gathered. */
545
// private JTextField classText = null;
546

547 // /** The field to which parameters are placed. */
548
// private JTextField paramsText = null;
549

550 // /* -------------------------------------------------------
551
// * Insight
552
// * -------------------------------------------------------
553
// */
554

555 // /**
556
// * Capture the trio of text fields are created in breakpoint dialog.
557
// */
558
// pointcut ctr(BreakpointDialog bp):
559
// receptions(new(..)) && instanceof(bp);
560
// after(BreakpointDialog bp) returning (): ctr(bp) {
561
// classText = bp.classText2;
562
// methodText = bp.methodText;
563
// paramsText = bp.paramsText;
564
// prepare(methodText);
565
// }
566

567 // /**
568
// * Add keybinds to a component.
569
// */
570
// void prepare(JComponent c) {
571
// reg(c, new UpAction(), KeyEvent.VK_UP, 0);
572
// reg(c, new DownAction(), KeyEvent.VK_DOWN, 0);
573
// c.addMouseListener(new MouseAdapter() {
574
// public void mouseClicked(MouseEvent e) {
575
// if (SwingUtilities.isRightMouseButton(e)) {
576
// down();
577
// }
578
// }});
579
// }
580

581 // void reg(JComponent c, Action a, int key, int mods) {
582
// FocusAspect.reg(c, a, key, mods, JComponent.WHEN_FOCUSED);
583
// }
584

585 // private class UpAction extends AbstractAction {
586
// public void actionPerformed(ActionEvent e) {
587
// up();
588
// }
589
// }
590

591 // private class DownAction extends AbstractAction {
592
// public void actionPerformed(ActionEvent e) {
593
// down();
594
// }
595
// }
596

597 // /**
598
// * The action to perform upon an <i>up</i> button press.
599
// */
600
// void up() {
601
// String clazz = classText.getText();
602
// String start = methodText.getText();
603
// ReferenceType refType = null;
604
// try {
605
// refType = ComponentRepository.getAJDebugger().getReferenceTypeFromToken(clazz);
606
// } catch (NoVMException e) {
607
// return;
608
// }
609
// if (refType == null) {
610
// return;
611
// }
612
// List methods = refType.methodsByName(start);
613
// showMenu(methods, clazz);
614
// }
615

616 // /**
617
// * The action to perform upon a <i>down</i> button press.
618
// */
619
// void down() {
620
// String clazz = classText.getText();
621
// ReferenceType refType = null;
622
// try {
623
// //refType = Env.getReferenceTypeFromToken(clazz);
624
// refType = ComponentRepository.getAJDebugger().getReferenceTypeFromToken(clazz);
625
// } catch (NoVMException e) {
626
// return;
627
// }
628
// if (refType == null) {
629
// return;
630
// }
631
// List methods = refType.methods();
632
// showMenu(methods, clazz);
633
// }
634

635 // /**
636
// * Create a pop-up menu in which to display the methods available
637
// * in the currently-selected class.
638
// */
639
// void showMenu(List methods, String clazz) {
640
// Iterator iter = methods.iterator();
641
// Vector vec = new Vector();
642
// while (iter.hasNext()) {
643
// Method method = (Method) iter.next();
644
// vec.add(new FormattedMethod(method));
645
// }
646
// AJPopupMenu menu = new AJPopupMenu("Methods for " + clazz, vec) {
647
// public void doSomething(Object o) {
648
// Method m = ((FormattedMethod) o).method;
649
// //
650
// // Had to use String version because AJC will only allow
651
// // one version of stripTypeFomMethod
652
// //
653
// String meth = AJUtil.stripTypeFromMethod(m + "");
654
// String params = AJUtil.getParamsFromMethod(m);
655
// setMethodText(meth, params);
656
// }};
657
// methodText.transferFocus();
658
// menu.show(methodText, 10, 10);
659
// menu.requestFocus();
660
// }
661

662 // /**
663
// * A convenience class used to display methods in the method list.
664
// */
665
// private class FormattedMethod {
666
// Method method = null;
667
// FormattedMethod(Method method) {
668
// this.method = method;
669
// }
670
// public String toString() {
671
// //
672
// // Had to use String version because AJC will only allow
673
// // one version of stripTypeFomMethod
674
// //
675
// return AJUtil.stripTypeFromMethod(method + "");
676
// }
677
// }
678

679 // /**
680
// * Method to set the method and params for a given
681
// * <code>method</code> and <code>params</code>.
682
// */
683
// private void setMethodText(String method, String params) {
684
// int iParen = method.indexOf("(");
685
// if (iParen != -1) {
686
// method = method.substring(0, iParen);
687
// }
688
// methodText.setText(method);
689
// paramsText.setText(params);
690
// }
691
// }
692

693 abstract class AJPopupMenu extends JPopupMenu
694   implements ListSelectionListener,
695              AdjustmentListener
696 {
697
698     private boolean scrolling = false;
699     private JList list;
700     private Object JavaDoc selection;
701
702     public AJPopupMenu(String JavaDoc s, Vector v) {
703         this(s, v.toArray());
704     }
705
706     public AJPopupMenu(String JavaDoc s, Object JavaDoc[] items) {
707         super(s);
708
709         list = new JList(items);
710         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
711         list.addListSelectionListener(this);
712
713         JScrollPane scroll = new JScrollPane(list);
714         scroll.getVerticalScrollBar().addAdjustmentListener(this);
715         add(scroll);
716     }
717
718     public abstract void doSomething(Object JavaDoc s);
719
720     public Object JavaDoc getSelection() {
721         return selection;
722     }
723
724     public void valueChanged(ListSelectionEvent e) {
725         if (e.getValueIsAdjusting()) {
726             int index = list.getMaxSelectionIndex();
727             selection = list.getModel().getElementAt(index);
728             scrolling = false;
729         } else {
730             doSomething(selection);
731             setVisible(false);
732         }
733     }
734
735     public void adjustmentValueChanged(AdjustmentEvent e) {
736         scrolling = true;
737     }
738 }
739
740 class ClassTextField extends JTextField {
741     ClassTextField(int i) {
742         super(i);
743     }
744 }
745
746 class SourceTextField extends JTextField {
747     SourceTextField(int i) {
748         super(i);
749     }
750 }
751
752 public /*abstract*/ class BreakpointDialog extends CenteredJDialog {
753
754     public /*abstract*/ boolean isSetting() { return true; }
755
756
757     static final int CLASS1_COLS = 20;
758     static final int LINE_COLS = 5;
759
760     final String JavaDoc job = isSetting() ? "Set" : "Clear";
761
762     String JavaDoc classMethodMsg = job + " a method breakpoint";
763     ClassTextField classText1 = new ClassTextField(CLASS1_COLS);
764     JTextField lineText = new JTextField(LINE_COLS);
765
766     static final int CLASS2_COLS = 20;
767     static final int METHOD_COLS = 20;
768     static final int PARAMS_COLS = 42;
769
770     String JavaDoc classLineMsg = job + " a class-line breakpoint";
771     JTextField classText2 = new JTextField(CLASS2_COLS);
772     JTextField methodText = new JTextField(METHOD_COLS);
773     JTextField paramsText = new JTextField(PARAMS_COLS);
774
775     static final int SOURCE_COLS = 20;
776
777     String JavaDoc sourceLineMsg = job + " a source-line breakpoint";
778     SourceTextField sourceText = new SourceTextField(SOURCE_COLS);
779     JTextField lineText2 = new JTextField(LINE_COLS);
780
781     public BreakpointDialog(Frame frame) {
782         super(frame, "", true);
783         setTitle(job + " a Breakpoint");
784
785         JPanel mainPanel = new JPanel();
786         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
787         mainPanel.add(classMethodPanel());
788         mainPanel.add(classLinePanel());
789         mainPanel.add(sourceLinePanel());
790         mainPanel.add(buttonPanel());
791
792         setResizable(false);
793         setContentPane(mainPanel);
794         setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
795     }
796
797     JPanel classLinePanel() {
798         KeyListener potato = new KeyAdapter() {
799             public void keyPressed(KeyEvent e) {
800                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
801                     setClassLineBreakpoint();
802                 }
803             }};
804         classText1.addKeyListener(potato);
805         lineText.addKeyListener(potato);
806
807         JPanel classTextPanel1 = new JPanel();
808         classTextPanel1.setLayout(new BoxLayout(classTextPanel1, BoxLayout.Y_AXIS));
809         classTextPanel1.add(Box.createHorizontalGlue());
810         classTextPanel1.add(classText1);
811         classTextPanel1.setBorder(BorderFactory.createTitledBorder(
812             BorderFactory.createEmptyBorder(0,0,0,0), "Class"));
813         JPanel lineTextPanel = new JPanel();
814         lineTextPanel.setLayout(new BoxLayout(lineTextPanel, BoxLayout.Y_AXIS));
815         lineTextPanel.add(Box.createHorizontalGlue());
816         lineTextPanel.add(lineText);
817         lineTextPanel.setBorder(BorderFactory.createTitledBorder(
818             BorderFactory.createEmptyBorder(0,0,0,0), "Line"));
819         JPanel mainPanel1 = new JPanel();
820         mainPanel1.setLayout(new BoxLayout(mainPanel1, BoxLayout.X_AXIS));
821         mainPanel1.add(classTextPanel1);
822         mainPanel1.add(lineTextPanel);
823         JButton jobButton = null;
824         if (isSetting()) {
825             jobButton = new JButton("Set");
826             jobButton.addActionListener(new ActionListener() {
827                 public void actionPerformed(ActionEvent e) {
828                     setClassLineBreakpoint();
829                 }});
830         } else {
831             jobButton = new JButton("Clear");
832             jobButton.addActionListener(new ActionListener() {
833                 public void actionPerformed(ActionEvent e) {
834                     classLineClear();
835                 }});
836         }
837         JPanel buttonPanel1 = new JPanel();
838         buttonPanel1.setLayout(new BoxLayout(buttonPanel1, BoxLayout.X_AXIS));
839         buttonPanel1.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
840         buttonPanel1.add(Box.createHorizontalGlue());
841         buttonPanel1.add(jobButton);
842         JPanel classLinePanel = new JPanel();
843         classLinePanel.setLayout(new BorderLayout());
844         classLinePanel.add(mainPanel1, BorderLayout.CENTER);
845         classLinePanel.add(buttonPanel1, BorderLayout.SOUTH);
846         classLinePanel.setBorder(BorderFactory.createTitledBorder(classLineMsg));
847         return classLinePanel;
848     }
849
850     JPanel classMethodPanel() {
851         KeyListener george = new KeyAdapter() {
852             public void keyPressed(KeyEvent e) {
853                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
854                     setClassMethodBreakpoint();
855                 }
856             }};
857         classText2.addKeyListener(george);
858         methodText.addKeyListener(george);
859         paramsText.addKeyListener(george);
860
861         JPanel classTextPanel2 = new JPanel();
862         classTextPanel2.setLayout(new BoxLayout(classTextPanel2, BoxLayout.Y_AXIS));
863         classTextPanel2.add(Box.createHorizontalGlue());
864         classTextPanel2.add(classText2);
865         classTextPanel2.setBorder(BorderFactory.createTitledBorder(
866             BorderFactory.createEmptyBorder(0,0,0,0), "Class"));
867         JPanel methodTextPanel = new JPanel();
868         methodTextPanel.setLayout(new BoxLayout(methodTextPanel, BoxLayout.Y_AXIS));
869         methodTextPanel.add(Box.createHorizontalGlue());
870         methodTextPanel.add(methodText);
871         methodTextPanel.setBorder(BorderFactory.createTitledBorder(
872             BorderFactory.createEmptyBorder(0,0,0,0), "Method"));
873         JPanel topPanel = new JPanel();
874         topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
875         topPanel.add(classTextPanel2);
876         topPanel.add(methodTextPanel);
877
878         JPanel paramsTextPanel = new JPanel();
879         paramsTextPanel.setLayout(new BoxLayout(paramsTextPanel, BoxLayout.Y_AXIS));
880         paramsTextPanel.add(Box.createHorizontalGlue());
881         paramsTextPanel.add(paramsText);
882         paramsTextPanel.setBorder(BorderFactory.createTitledBorder(
883             BorderFactory.createEmptyBorder(0,0,0,0), "Parameters"));
884         JPanel bottomPanel = new JPanel();
885         bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
886         bottomPanel.add(paramsTextPanel);
887         JPanel middlePanel = new JPanel();
888         middlePanel.setLayout(new BoxLayout(middlePanel, BoxLayout.Y_AXIS));
889         middlePanel.add(topPanel);
890         middlePanel.add(bottomPanel);
891         JButton jobButton = null;
892         if (isSetting()) {
893             jobButton = new JButton("Set");
894             jobButton.addActionListener(new ActionListener() {
895                 public void actionPerformed(ActionEvent e) {
896                     setClassMethodBreakpoint();
897                 }});
898         } else {
899             jobButton = new JButton("Clear");
900             jobButton.addActionListener(new ActionListener() {
901                 public void actionPerformed(ActionEvent e) {
902                     classMethodClear();
903                 }});
904         }
905         JPanel buttonPanel2 = new JPanel();
906         buttonPanel2.setLayout(new BoxLayout(buttonPanel2, BoxLayout.X_AXIS));
907         buttonPanel2.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
908         buttonPanel2.add(Box.createHorizontalGlue());
909         buttonPanel2.add(jobButton);
910         JPanel classMethodPanel = new JPanel();
911         classMethodPanel.setLayout(new BorderLayout());
912         classMethodPanel.add(middlePanel, BorderLayout.CENTER);
913         classMethodPanel.add(buttonPanel2, BorderLayout.SOUTH);
914         classMethodPanel.setBorder(BorderFactory.createTitledBorder(classMethodMsg));
915         return classMethodPanel;
916     }
917
918     JPanel sourceLinePanel() {
919         KeyListener potato = new KeyAdapter() {
920             public void keyPressed(KeyEvent e) {
921                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
922                     setSourceLineBreakpoint();
923                 }
924             }};
925         sourceText.addKeyListener(potato);
926         lineText2.addKeyListener(potato);
927
928         JPanel classTextPanel1 = new JPanel();
929         classTextPanel1.setLayout(new BoxLayout(classTextPanel1, BoxLayout.Y_AXIS));
930         classTextPanel1.add(Box.createHorizontalGlue());
931         classTextPanel1.add(sourceText);
932         classTextPanel1.setBorder(BorderFactory.createTitledBorder(
933             BorderFactory.createEmptyBorder(0,0,0,0), "Source"));
934         JPanel lineTextPanel = new JPanel();
935         lineTextPanel.setLayout(new BoxLayout(lineTextPanel, BoxLayout.Y_AXIS));
936         lineTextPanel.add(Box.createHorizontalGlue());
937         lineTextPanel.add(lineText2);
938         lineTextPanel.setBorder(BorderFactory.createTitledBorder(
939             BorderFactory.createEmptyBorder(0,0,0,0), "Line"));
940         JPanel mainPanel1 = new JPanel();
941         mainPanel1.setLayout(new BoxLayout(mainPanel1, BoxLayout.X_AXIS));
942         mainPanel1.add(classTextPanel1);
943         mainPanel1.add(lineTextPanel);
944         JButton jobButton = null;
945         if (isSetting()) {
946             jobButton = new JButton("Set");
947             jobButton.addActionListener(new ActionListener() {
948                 public void actionPerformed(ActionEvent e) {
949                     setSourceLineBreakpoint();
950                 }});
951         } else {
952             jobButton = new JButton("Clear");
953             jobButton.addActionListener(new ActionListener() {
954                 public void actionPerformed(ActionEvent e) {
955                     sourceLineClear();
956                 }});
957         }
958         JPanel buttonPanel1 = new JPanel();
959         buttonPanel1.setLayout(new BoxLayout(buttonPanel1, BoxLayout.X_AXIS));
960         buttonPanel1.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
961         buttonPanel1.add(Box.createHorizontalGlue());
962         buttonPanel1.add(jobButton);
963         JPanel sourceLinePanel = new JPanel();
964         sourceLinePanel.setLayout(new BorderLayout());
965         sourceLinePanel.add(mainPanel1, BorderLayout.CENTER);
966         sourceLinePanel.add(buttonPanel1, BorderLayout.SOUTH);
967         sourceLinePanel.setBorder(BorderFactory.createTitledBorder(sourceLineMsg));
968         return sourceLinePanel;
969     }
970
971     JPanel buttonPanel() {
972         JButton cancelButton = new JButton("Cancel");
973         cancelButton.addActionListener(new ActionListener() {
974             public void actionPerformed(ActionEvent e) {
975                 cancel();
976             }});
977         JPanel buttonPanel = new JPanel();
978         buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
979         buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
980         buttonPanel.add(Box.createHorizontalGlue());
981         buttonPanel.add(cancelButton);
982         return buttonPanel;
983     }
984
985
986     public BreakpointDialog() {
987         this(null);
988     }
989
990     public void show() {
991         pack();
992         super.show();
993     }
994
995     String JavaDoc getClass1() {
996         return classText1.getText();
997     }
998
999     String JavaDoc getClass2() {
1000        return classText2.getText();
1001    }
1002
1003    private void setClassLineBreakpoint() {
1004        String JavaDoc className = classText1.getText();
1005        int line = -1;
1006        try {
1007            line = Integer.parseInt(lineText.getText());
1008        } catch (NumberFormatException JavaDoc e) {
1009            AJUtil.warn("The line field must contain a number");
1010            return;
1011        }
1012        String JavaDoc cmd = "stop at " + className + ":" + line;
1013        ComponentRepository.getCommandLine().executeCommand(cmd);
1014        hide();
1015    }
1016
1017    private void classLineClear() {
1018        classText1.setText("");
1019        lineText.setText("");
1020    }
1021
1022    private void setSourceLineBreakpoint() {
1023        String JavaDoc sourceName = sourceText.getText();
1024        int line = -1;
1025        try {
1026            line = Integer.parseInt(lineText2.getText());
1027        } catch (NumberFormatException JavaDoc e) {
1028            AJUtil.warn("The line field must contain a number");
1029            return;
1030        }
1031        String JavaDoc cmd = "stop on " + sourceName + ":" + line;
1032        ComponentRepository.getCommandLine().executeCommand(cmd);
1033        hide();
1034    }
1035
1036    private void sourceLineClear() {
1037        sourceText.setText("");
1038        lineText2.setText("");
1039    }
1040
1041    private void setClassMethodBreakpoint() {
1042        String JavaDoc cmd = "stop in ";
1043        String JavaDoc className = classText2.getText();
1044        String JavaDoc method = methodText.getText();
1045        String JavaDoc params = "";
1046        StringTokenizer tok = new StringTokenizer(paramsText.getText(), " ;,");
1047        params += "(";
1048        while (tok.hasMoreTokens()) {
1049            params += tok.nextToken();
1050            params += (tok.hasMoreTokens() ? "," : "");
1051        }
1052        params += ")";
1053        cmd += className + "." + method + params;
1054        ComponentRepository.getCommandLine().executeCommand(cmd);
1055        hide();
1056    }
1057
1058    private void classMethodClear() {
1059        classText2.setText("");
1060        methodText.setText("");
1061        paramsText.setText("");
1062    }
1063
1064    private void cancel() {
1065        hide();
1066    }
1067
1068    public static void main(String JavaDoc[] args) {
1069        BreakpointDialog d = new BreakpointDialog();
1070        d.show();
1071    }
1072}
1073
Popular Tags