KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > debug > JspBreakpointPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.debug;
21
22 import org.openide.*;
23 //import org.openide.NotifyDescriptor.Message;
24
import org.openide.util.NbBundle;
25
26 import java.net.URI JavaDoc;
27 import javax.swing.*;
28
29 import org.netbeans.spi.debugger.ui.Controller;
30 import org.netbeans.api.debugger.DebuggerManager;
31
32 import org.netbeans.modules.web.debug.util.Utils;
33 import org.netbeans.modules.web.debug.breakpoints.*;
34
35 /**
36 * Customizer of JspLineBreakpoint
37 *
38 * @author Martin Grebac
39 */

40 public class JspBreakpointPanel extends JPanel implements Controller {
41
42     static final long serialVersionUID =-8164649328980808272L;
43
44     private ActionsPanel actionsPanel;
45     private JspLineBreakpoint breakpoint;
46     private boolean createBreakpoint = false;
47
48     public JspBreakpointPanel() {
49         this(JspLineBreakpoint.create(Context.getCurrentURL(), Context.getCurrentLineNumber()));
50         createBreakpoint = true;
51     }
52     
53     /** Creates new form JspBreakpointPanel */
54     public JspBreakpointPanel(JspLineBreakpoint b) {
55
56         breakpoint = b;
57         initComponents ();
58         putClientProperty("HelpID", "jsp_breakpoint");//NOI18N
59

60         // a11y
61
getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(JspBreakpointPanel.class, "ACSD_LineBreakpointPanel")); // NOI18N
62

63         String JavaDoc url = b.getURL();
64         try {
65             URI JavaDoc uri = new URI JavaDoc(url);
66             cboxJspSourcePath.setText(uri.getPath());
67         } catch (Exception JavaDoc e) {
68             cboxJspSourcePath.setText(url);
69         }
70
71         int lnum = b.getLineNumber();
72         if (lnum < 1) {
73             tfLineNumber.setText(""); //NOI18N
74
} else {
75             tfLineNumber.setText(Integer.toString(lnum));
76         }
77         
78         actionsPanel = new ActionsPanel(b);
79         pActions.add(actionsPanel, "Center");
80     }
81
82     /** This method is called from within the constructor to
83      * initialize the form.
84      * WARNING: Do NOT modify this code. The content of this method is
85      * always regenerated by the FormEditor.
86      */

87     private void initComponents() {
88         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
89
90         pSettings = new javax.swing.JPanel JavaDoc();
91         lblJspSourcePath = new javax.swing.JLabel JavaDoc();
92         cboxJspSourcePath = new javax.swing.JTextField JavaDoc();
93         lblLineNumber = new javax.swing.JLabel JavaDoc();
94         tfLineNumber = new javax.swing.JTextField JavaDoc();
95         pActions = new javax.swing.JPanel JavaDoc();
96         jPanel1 = new javax.swing.JPanel JavaDoc();
97
98         setLayout(new java.awt.GridBagLayout JavaDoc());
99
100         pSettings.setLayout(new java.awt.GridBagLayout JavaDoc());
101
102         pSettings.setBorder(new javax.swing.border.TitledBorder JavaDoc("Settings"));
103         lblJspSourcePath.setText(NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Source_name"));
104         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
105         gridBagConstraints.gridx = 0;
106         gridBagConstraints.gridy = 1;
107         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
108         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 4, 2, 2);
109         pSettings.add(lblJspSourcePath, gridBagConstraints);
110         lblJspSourcePath.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSN_CTL_Source_name"));
111
112         cboxJspSourcePath.setEditable(false);
113
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.gridx = 1;
116         gridBagConstraints.gridy = 1;
117         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
118         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
119         gridBagConstraints.weightx = 1.0;
120         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 2);
121         pSettings.add(cboxJspSourcePath, gridBagConstraints);
122         cboxJspSourcePath.getAccessibleContext().setAccessibleName(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSN_CTL_Source_name"));
123         cboxJspSourcePath.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSD_CTL_Source_name"));
124
125         lblLineNumber.setLabelFor(tfLineNumber);
126         lblLineNumber.setText(NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Line_number"));
127         lblLineNumber.setDisplayedMnemonic(NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Line_number_mnemonic").charAt(0));
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 2;
131         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 4, 2, 2);
133         pSettings.add(lblLineNumber, gridBagConstraints);
134         lblLineNumber.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSD_CTL_Line_number"));
135
136         tfLineNumber.setColumns(7);
137         tfLineNumber.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
138             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
139                 tfLineNumberFocusGained(evt);
140             }
141             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
142                 tfLineNumberFocusLost(evt);
143             }
144         });
145         tfLineNumber.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
146             public void keyTyped(java.awt.event.KeyEvent JavaDoc evt) {
147                 tfLineNumberKeyTyped(evt);
148             }
149         });
150
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 1;
153         gridBagConstraints.gridy = 2;
154         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         gridBagConstraints.weightx = 1.0;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 2);
158         pSettings.add(tfLineNumber, gridBagConstraints);
159         tfLineNumber.getAccessibleContext().setAccessibleName(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSN_CTL_Line_number"));
160         tfLineNumber.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(JspBreakpointPanel.class).getString("ACSD_CTL_Line_number"));
161
162         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
164         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165         gridBagConstraints.weightx = 1.0;
166         add(pSettings, gridBagConstraints);
167
168         pActions.setLayout(new java.awt.BorderLayout JavaDoc());
169
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172         gridBagConstraints.weightx = 1.0;
173         add(pActions, gridBagConstraints);
174
175         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 0;
177         gridBagConstraints.gridy = 2;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
179         gridBagConstraints.weightx = 1.0;
180         gridBagConstraints.weighty = 1.0;
181         add(jPanel1, gridBagConstraints);
182
183     }
184
185     private void tfLineNumberKeyTyped(java.awt.event.KeyEvent JavaDoc evt) {
186         // Add your handling code here:
187
}
188
189     private void tfLineNumberFocusGained(java.awt.event.FocusEvent JavaDoc evt) {
190         if (!evt.isTemporary()) {
191             ((JTextField) evt.getComponent()).selectAll();
192         }
193     }
194
195     private void tfLineNumberFocusLost(java.awt.event.FocusEvent JavaDoc evt) {
196 // if (!evt.isTemporary()) {
197
// if (tfLineNumber.getText().trim().length() > 0) {
198
// try {
199
// int i = Integer.parseInt(tfLineNumber.getText ());
200
// if (i < 1) {
201
// DialogDisplayer.getDefault().notify (
202
// new Message (
203
// NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Bad_line_number"), //NOI18N
204
// NotifyDescriptor.ERROR_MESSAGE
205
// )
206
// );
207
// } else if (event != null) {
208
// event.setLineNumber(i);
209
// }
210
// } catch (NumberFormatException e) {
211
// DialogDisplayer.getDefault().notify (
212
// new Message (
213
// NbBundle.getBundle(JspBreakpointPanel.class).getString("CTL_Bad_line_number"), //NOI18N
214
// NotifyDescriptor.ERROR_MESSAGE
215
// )
216
// );
217
// }
218
// }
219
// }
220
}
221     
222     /******************************/
223     /* CONTROLLER: */
224     /******************************/
225     
226     //interface org.netbeans.modules.debugger.Controller
227
public boolean ok() {
228         if (!isValid()) {
229             return false;
230         }
231         
232         actionsPanel.ok ();
233         breakpoint.setLineNumber(Integer.parseInt(tfLineNumber.getText().trim()));
234         
235         if (createBreakpoint) {
236             DebuggerManager.getDebuggerManager().addBreakpoint(breakpoint);
237         }
238         return true;
239     }
240     
241     //interface org.netbeans.modules.debugger.Controller
242
public boolean cancel() {
243         return true;
244     }
245     
246     //interface org.netbeans.modules.debugger.Controller
247
public boolean isValid() {
248         try {
249             int line = Integer.parseInt(tfLineNumber.getText().trim());
250             return line > 0;
251         } catch (NumberFormatException JavaDoc e) {
252             return false;
253         }
254     }
255         
256     // Variables declaration - do not modify
257
private javax.swing.JTextField JavaDoc cboxJspSourcePath;
258     private javax.swing.JPanel JavaDoc jPanel1;
259     private javax.swing.JLabel JavaDoc lblJspSourcePath;
260     private javax.swing.JLabel JavaDoc lblLineNumber;
261     private javax.swing.JPanel JavaDoc pActions;
262     private javax.swing.JPanel JavaDoc pSettings;
263     private javax.swing.JTextField JavaDoc tfLineNumber;
264     // End of variables declaration
265

266 }
267
Popular Tags