KickJava   Java API By Example, From Geeks To Geeks.

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


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
27 import java.awt.*;
28 import java.awt.event.*;
29 import java.util.*;
30 import javax.swing.*;
31
32 public class ClassMethodBreakpointDialog extends JDialog {
33
34     static final int TEXT_COLS = 20;
35     static final int METHOD_COLS = 20;
36     static final int PARAMS_COLS = 42;
37
38     private String JavaDoc mainMsg = "Create a class-line breakpoint";
39     private JTextField classText = new JTextField(TEXT_COLS);
40     private JTextField methodText = new JTextField(METHOD_COLS);
41     private JTextField paramsText = new JTextField(PARAMS_COLS);
42
43     public ClassMethodBreakpointDialog(Frame frame) {
44         super(frame, "Set a Breakpoint", true);
45         KeyListener george = new KeyAdapter() {
46             public void keyPressed(KeyEvent e) {
47                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
48                     setBreakpoint();
49                 }
50             }};
51         classText.addKeyListener(george);
52         methodText.addKeyListener(george);
53         paramsText.addKeyListener(george);
54
55         JPanel classTextPanel = new JPanel();
56         classTextPanel.add(classText);
57         classTextPanel.setBorder(BorderFactory.createTitledBorder(
58                                     BorderFactory.createEmptyBorder(0,0,0,0), "Class"));
59         JPanel methodTextPanel = new JPanel();
60         methodTextPanel.add(methodText);
61         methodTextPanel.setBorder(BorderFactory.createTitledBorder(
62                                     BorderFactory.createEmptyBorder(0,0,0,0), "Method"));
63         JPanel topPanel = new JPanel();
64         topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
65         topPanel.add(classTextPanel);
66         topPanel.add(methodTextPanel);
67
68         JPanel paramsTextPanel = new JPanel();
69         paramsTextPanel.add(paramsText);
70         paramsTextPanel.setBorder(BorderFactory.createTitledBorder(
71                                     BorderFactory.createEmptyBorder(0,0,0,0), "Parameters"));
72         JPanel bottomPanel = new JPanel();
73         bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
74         bottomPanel.add(paramsTextPanel);
75
76         Object JavaDoc[] components = { mainMsg, topPanel, bottomPanel };
77
78         JButton setButton = new JButton("Set");
79         setButton.addActionListener(new ActionListener() {
80             public void actionPerformed(ActionEvent e) {
81                 setBreakpoint();
82             }});
83         JButton clearButton = new JButton("Clear");
84         clearButton.addActionListener(new ActionListener() {
85             public void actionPerformed(ActionEvent e) {
86                 clear();
87             }});
88         JButton cancelButton = new JButton("Cancel");
89         cancelButton.addActionListener(new ActionListener() {
90             public void actionPerformed(ActionEvent e) {
91                 cancel();
92             }});
93         Object JavaDoc[] buttons = { setButton, clearButton, cancelButton };
94
95         JOptionPane optionPane =
96             new JOptionPane
97                 (components,
98                  JOptionPane.QUESTION_MESSAGE,
99                  JOptionPane.YES_NO_OPTION,
100                  null,
101                  buttons,
102                  buttons[0]);
103         this.setContentPane(optionPane);
104         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
105     }
106
107     public ClassMethodBreakpointDialog() {
108         this(null);
109     }
110
111     public void show() {
112         pack();
113         super.show();
114         classText.requestFocus();
115     }
116
117     private void setBreakpoint() {
118         String JavaDoc cmd = "stop in ";
119         String JavaDoc className = classText.getText();
120         String JavaDoc method = methodText.getText();
121         String JavaDoc params = "";
122         StringTokenizer tok = new StringTokenizer(paramsText.getText(), " ;,");
123         if (tok.hasMoreTokens()) {
124             params += "(";
125         }
126         while (tok.hasMoreTokens()) {
127             params += tok.nextToken();
128             params += (tok.hasMoreTokens() ? "," : ")");
129         }
130         cmd += className + "." + method + params;
131         ComponentRepository.getCommandLine().executeCommand(cmd);
132         clear();
133         hide();
134     }
135
136     private void clear() {
137         classText.setText("");
138         methodText.setText("");
139         paramsText.setText("");
140     }
141
142     private void cancel() {
143         hide();
144     }
145 }
Popular Tags