KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.*;
30
31 public class ClassLineBreakpointDialog extends JDialog {
32
33     static final int TEXT_COLS = 20;
34     static final int LINE_COLS = 5;
35
36     private String JavaDoc mainMsg = "Create a class-line breakpoint";
37     private JTextField classText = new JTextField(TEXT_COLS);
38     private JTextField lineText = new JTextField(LINE_COLS);
39
40     public ClassLineBreakpointDialog(Frame frame) {
41         super(frame, "Set a Breakpoint", true);
42         classText.addKeyListener(new KeyAdapter() {
43             public void keyPressed(KeyEvent e) {
44                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
45                     setBreakpoint();
46                 }
47             }});
48         lineText.addKeyListener(new KeyAdapter() {
49             public void keyPressed(KeyEvent e) {
50                 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
51                     setBreakpoint();
52                 }
53             }});
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 lineTextPanel = new JPanel();
60         lineTextPanel.add(lineText);
61         lineTextPanel.setBorder(BorderFactory.createTitledBorder(
62                                     BorderFactory.createEmptyBorder(0,0,0,0), "Line"));
63         JPanel mainPanel = new JPanel();
64         mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
65         mainPanel.add(classTextPanel);
66         mainPanel.add(lineTextPanel);
67         Object JavaDoc[] components = { mainMsg, mainPanel };
68
69         JButton setButton = new JButton("Set");
70         setButton.addActionListener(new ActionListener() {
71             public void actionPerformed(ActionEvent e) {
72                 setBreakpoint();
73             }});
74         JButton clearButton = new JButton("Clear");
75         clearButton.addActionListener(new ActionListener() {
76             public void actionPerformed(ActionEvent e) {
77                 clear();
78             }});
79         JButton cancelButton = new JButton("Cancel");
80         cancelButton.addActionListener(new ActionListener() {
81             public void actionPerformed(ActionEvent e) {
82                 cancel();
83             }});
84         Object JavaDoc[] buttons = { setButton, clearButton, cancelButton };
85
86         JOptionPane optionPane =
87             new JOptionPane
88                 (components,
89                  JOptionPane.QUESTION_MESSAGE,
90                  JOptionPane.YES_NO_OPTION,
91                  null,
92                  buttons,
93                  buttons[0]);
94         this.setContentPane(optionPane);
95         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
96     }
97
98     public ClassLineBreakpointDialog() {
99         this(null);
100     }
101
102     public void show() {
103         pack();
104         super.show();
105         classText.requestFocus();
106     }
107
108     private void setBreakpoint() {
109         String JavaDoc className = classText.getText();
110         int line = -1;
111         try {
112             line = Integer.parseInt(lineText.getText());
113         } catch (NumberFormatException JavaDoc e) {
114             AJUtil.warn("The line field must contain a number");
115             return;
116         }
117         String JavaDoc cmd = "stop at " + className + ":" + line;
118         ComponentRepository.getCommandLine().executeCommand(cmd);
119         clear();
120         hide();
121     }
122
123     private void clear() {
124         classText.setText("");
125         lineText.setText("");
126     }
127
128     private void cancel() {
129         hide();
130     }
131 }
Popular Tags