KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > breakpoints > MethodBreakpointPanel


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.debugger.jpda.ui.breakpoints;
21
22 import javax.swing.JPanel JavaDoc;
23 import javax.swing.JOptionPane JavaDoc;
24 import org.netbeans.api.debugger.DebuggerManager;
25
26 import org.netbeans.api.debugger.jpda.MethodBreakpoint;
27 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
28 import org.netbeans.spi.debugger.ui.Controller;
29 import org.openide.util.NbBundle;
30
31 /**
32  * @author Jan Jancura
33  */

34 // <RAVE>
35
// Implement HelpCtx.Provider interface to provide help ids for help system
36
// public class MethodBreakpointPanel extends JPanel implements Controller {
37
// ====
38
public class MethodBreakpointPanel extends JPanel JavaDoc implements Controller, org.openide.util.HelpCtx.Provider {
39 // </RAVE>
40

41     private ActionsPanel actionsPanel;
42     private MethodBreakpoint breakpoint;
43     private boolean createBreakpoint = false;
44     
45     
46     private static MethodBreakpoint createBreakpoint () {
47         MethodBreakpoint mb = MethodBreakpoint.create (
48             EditorContextBridge.getCurrentClassName (),
49             EditorContextBridge.getCurrentMethodName ()
50         );
51         mb.setPrintText (
52             NbBundle.getBundle (MethodBreakpointPanel.class).getString
53                 ("CTL_Method_Breakpoint_Print_Text")
54         );
55         return mb;
56     }
57     
58     
59     /** Creates new form LineBreakpointPanel */
60     public MethodBreakpointPanel () {
61         this (createBreakpoint ());
62         createBreakpoint = true;
63     }
64     
65     /** Creates new form LineBreakpointPanel */
66     public MethodBreakpointPanel (MethodBreakpoint b) {
67         breakpoint = b;
68         initComponents ();
69         
70         String JavaDoc className = "";
71         String JavaDoc[] fs = b.getClassFilters ();
72         if (fs.length > 0) className = fs [0];
73         int i = className.lastIndexOf ('.');
74         if (i < 0) {
75             tfPackageName.setText ("");
76             tfClassName.setText (className);
77         } else {
78             tfPackageName.setText (className.substring (0, i));
79             tfClassName.setText (className.substring (i + 1, className.length ()));
80         }
81         if ("".equals (b.getMethodName ())) {
82             tfMethodName.setText (org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "Method_Breakpoint_ALL_METHODS"));
83             cbAllMethods.setSelected (true);
84             tfMethodName.setEnabled (false);
85         } else {
86             if (b.getMethodName().equals(tfClassName.getText()))
87                 tfMethodName.setText ("<init>");
88             else
89                 tfMethodName.setText (b.getMethodName ());
90         }
91         cbStopOnEntry.setSelected((b.getBreakpointType() & b.TYPE_METHOD_ENTRY) != 0);
92         cbStopOnExit.setSelected((b.getBreakpointType() & b.TYPE_METHOD_EXIT) != 0);
93         
94         tfCondition.setText (b.getCondition ());
95         
96         actionsPanel = new ActionsPanel (b);
97         pActions.add (actionsPanel, "Center");
98         // <RAVE>
99
// The help IDs for the AddBreakpointPanel panels have to be different from the
100
// values returned by getHelpCtx() because they provide different help
101
// in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view
102
putClientProperty("HelpID_AddBreakpointPanel", "debug.add.breakpoint.java.method"); // NOI18N
103
// </RAVE>
104
}
105     
106     // <RAVE>
107
// Implement getHelpCtx() with the correct helpID
108
public org.openide.util.HelpCtx getHelpCtx() {
109         return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointMethodJPDA"); // NOI18N
110
}
111     // </RAVE>
112

113     /** This method is called from within the constructor to
114      * initialize the form.
115      * WARNING: Do NOT modify this code. The content of this method is
116      * always regenerated by the Form Editor.
117      */

118     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
119
private void initComponents() {
120         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
121
122         pSettings = new javax.swing.JPanel JavaDoc();
123         jLabel2 = new javax.swing.JLabel JavaDoc();
124         jLabel3 = new javax.swing.JLabel JavaDoc();
125         jLabel5 = new javax.swing.JLabel JavaDoc();
126         tfCondition = new javax.swing.JTextField JavaDoc();
127         tfPackageName = new javax.swing.JTextField JavaDoc();
128         tfClassName = new javax.swing.JTextField JavaDoc();
129         cbAllMethods = new javax.swing.JCheckBox JavaDoc();
130         jLabel1 = new javax.swing.JLabel JavaDoc();
131         tfMethodName = new javax.swing.JTextField JavaDoc();
132         cbStopOnEntry = new javax.swing.JCheckBox JavaDoc();
133         cbStopOnExit = new javax.swing.JCheckBox JavaDoc();
134         pActions = new javax.swing.JPanel JavaDoc();
135         jPanel1 = new javax.swing.JPanel JavaDoc();
136
137         setLayout(new java.awt.GridBagLayout JavaDoc());
138
139         pSettings.setLayout(new java.awt.GridBagLayout JavaDoc());
140
141         pSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_BorderTitle"))); // NOI18N
142
jLabel2.setLabelFor(tfPackageName);
143         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Package_Name")); // NOI18N
144
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
147         pSettings.add(jLabel2, gridBagConstraints);
148         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Package_Name")); // NOI18N
149

150         jLabel3.setLabelFor(tfClassName);
151         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Class_Name")); // NOI18N
152
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 0;
154         gridBagConstraints.gridy = 1;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
157         pSettings.add(jLabel3, gridBagConstraints);
158         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Class_Name")); // NOI18N
159

160         jLabel5.setLabelFor(tfCondition);
161         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Condition")); // NOI18N
162
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints.gridx = 0;
164         gridBagConstraints.gridy = 7;
165         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
168         pSettings.add(jLabel5, gridBagConstraints);
169         jLabel5.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Condition")); // NOI18N
170

171         tfCondition.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Condition")); // NOI18N
172
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 1;
174         gridBagConstraints.gridy = 7;
175         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
177         pSettings.add(tfCondition, gridBagConstraints);
178         tfCondition.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Condition")); // NOI18N
179

180         tfPackageName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Package_Name")); // NOI18N
181
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
182         gridBagConstraints.gridx = 1;
183         gridBagConstraints.gridy = 0;
184         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185         gridBagConstraints.weightx = 1.0;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
187         pSettings.add(tfPackageName, gridBagConstraints);
188         tfPackageName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Package_Name")); // NOI18N
189

190         tfClassName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Class_Name")); // NOI18N
191
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
192         gridBagConstraints.gridx = 1;
193         gridBagConstraints.gridy = 1;
194         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
195         gridBagConstraints.weightx = 1.0;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
197         pSettings.add(tfClassName, gridBagConstraints);
198         tfClassName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Class_Name")); // NOI18N
199

200         org.openide.awt.Mnemonics.setLocalizedText(cbAllMethods, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "CB_Method_Breakpoint_All_Methods")); // NOI18N
201
cbAllMethods.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_Method_Breakpoint_All_Methods")); // NOI18N
202
cbAllMethods.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
203         cbAllMethods.addActionListener(new java.awt.event.ActionListener JavaDoc() {
204             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
205                 cbAllMethodsActionPerformed(evt);
206             }
207         });
208
209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridx = 0;
211         gridBagConstraints.gridy = 3;
212         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
213         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
214         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
216         pSettings.add(cbAllMethods, gridBagConstraints);
217         cbAllMethods.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_CB_Method_Breakpoint_All_Methods")); // NOI18N
218

219         jLabel1.setLabelFor(tfMethodName);
220         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Method_Name")); // NOI18N
221
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
222         gridBagConstraints.gridx = 0;
223         gridBagConstraints.gridy = 4;
224         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
225         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
226         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
227         pSettings.add(jLabel1, gridBagConstraints);
228         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Method_Name")); // NOI18N
229

230         tfMethodName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Method_Name")); // NOI18N
231
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
232         gridBagConstraints.gridx = 1;
233         gridBagConstraints.gridy = 4;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
237         pSettings.add(tfMethodName, gridBagConstraints);
238         tfMethodName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Method_Name")); // NOI18N
239

240         org.openide.awt.Mnemonics.setLocalizedText(cbStopOnEntry, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "LBL_CB_MethodEntry")); // NOI18N
241
cbStopOnEntry.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_MethodEntry")); // NOI18N
242
cbStopOnEntry.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
243         cbStopOnEntry.addActionListener(new java.awt.event.ActionListener JavaDoc() {
244             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
245                 cbStopOnEntryActionPerformed(evt);
246             }
247         });
248
249         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
250         gridBagConstraints.gridy = 5;
251         gridBagConstraints.gridwidth = 2;
252         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
253         gridBagConstraints.weightx = 1.0;
254         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
255         pSettings.add(cbStopOnEntry, gridBagConstraints);
256
257         org.openide.awt.Mnemonics.setLocalizedText(cbStopOnExit, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "LBL_CB_MethodExit")); // NOI18N
258
cbStopOnExit.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_MethodExit")); // NOI18N
259
cbStopOnExit.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
260         cbStopOnExit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
261             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
262                 cbStopOnExitActionPerformed(evt);
263             }
264         });
265
266         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
267         gridBagConstraints.gridy = 6;
268         gridBagConstraints.gridwidth = 2;
269         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
270         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
271         pSettings.add(cbStopOnExit, gridBagConstraints);
272
273         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
274         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
275         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
276         gridBagConstraints.weightx = 1.0;
277         add(pSettings, gridBagConstraints);
278
279         pActions.setLayout(new java.awt.BorderLayout JavaDoc());
280
281         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
282         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283         gridBagConstraints.weightx = 1.0;
284         add(pActions, gridBagConstraints);
285
286         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
287         gridBagConstraints.gridx = 0;
288         gridBagConstraints.gridy = 2;
289         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
290         gridBagConstraints.weightx = 1.0;
291         gridBagConstraints.weighty = 1.0;
292         add(jPanel1, gridBagConstraints);
293
294     }// </editor-fold>//GEN-END:initComponents
295

296     private void cbStopOnExitActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbStopOnExitActionPerformed
297
// Assure that at least one checkbox is selected
298
if (!cbStopOnExit.isSelected() && !cbStopOnEntry.isSelected()) {
299             cbStopOnEntry.setSelected(true);
300         }
301     }//GEN-LAST:event_cbStopOnExitActionPerformed
302

303     private void cbStopOnEntryActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbStopOnEntryActionPerformed
304
// Assure that at least one checkbox is selected
305
if (!cbStopOnEntry.isSelected() && !cbStopOnExit.isSelected()) {
306             cbStopOnExit.setSelected(true);
307         }
308     }//GEN-LAST:event_cbStopOnEntryActionPerformed
309

310     private void cbAllMethodsActionPerformed (java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cbAllMethodsActionPerformed
311
{//GEN-HEADEREND:event_cbAllMethodsActionPerformed
312
if (cbAllMethods.isSelected ()) {
313             tfMethodName.setText (org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "Method_Breakpoint_ALL_METHODS"));
314             tfMethodName.setEnabled (false);
315         } else {
316             tfMethodName.setText ("");
317             tfMethodName.setEnabled (true);
318         }
319     }//GEN-LAST:event_cbAllMethodsActionPerformed
320

321     
322     // Controller implementation ...............................................
323

324     /**
325      * Called when "Ok" button is pressed.
326      *
327      * @return whether customizer can be closed
328      */

329     public boolean ok () {
330         if (! isFilled()) {
331             JOptionPane.showMessageDialog(this,
332                 org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "MSG_No_Class_or_Method_Name_Spec"));
333             return false;
334         }
335         actionsPanel.ok ();
336         String JavaDoc className = ((String JavaDoc) tfPackageName.getText ()).trim ();
337         if (className.length () > 0)
338             className += '.';
339         className += tfClassName.getText ().trim ();
340         breakpoint.setClassFilters (new String JavaDoc[] {className});
341         if (!cbAllMethods.isSelected ())
342             breakpoint.setMethodName (tfMethodName.getText ().trim ());
343         else
344             breakpoint.setMethodName ("");
345         breakpoint.setCondition (tfCondition.getText ());
346         int bpType = 0;
347         if (cbStopOnEntry.isSelected()) {
348             bpType |= breakpoint.TYPE_METHOD_ENTRY;
349         }
350         if (cbStopOnExit.isSelected()) {
351             bpType |= breakpoint.TYPE_METHOD_EXIT;
352         }
353         breakpoint.setBreakpointType(bpType);
354         
355         if (createBreakpoint)
356             DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint);
357         return true;
358     }
359     
360     /**
361      * Called when "Cancel" button is pressed.
362      *
363      * @return whether customizer can be closed
364      */

365     public boolean cancel () {
366         return true;
367     }
368     
369     /**
370      * Return <code>true</code> whether value of this customizer
371      * is valid (and OK button can be enabled).
372      *
373      * @return <code>true</code> whether value of this customizer
374      * is valid
375      */

376     public boolean isValid () {
377         return true;
378     }
379     
380      boolean isFilled () {
381         if (tfClassName.getText().trim().length() > 0 &&
382                 (tfMethodName.getText().trim().length() > 0 ||
383                     cbAllMethods.isSelected()))
384             return true;
385         return false;
386     }
387     
388     
389     // Variables declaration - do not modify//GEN-BEGIN:variables
390
private javax.swing.JCheckBox JavaDoc cbAllMethods;
391     private javax.swing.JCheckBox JavaDoc cbStopOnEntry;
392     private javax.swing.JCheckBox JavaDoc cbStopOnExit;
393     private javax.swing.JLabel JavaDoc jLabel1;
394     private javax.swing.JLabel JavaDoc jLabel2;
395     private javax.swing.JLabel JavaDoc jLabel3;
396     private javax.swing.JLabel JavaDoc jLabel5;
397     private javax.swing.JPanel JavaDoc jPanel1;
398     private javax.swing.JPanel JavaDoc pActions;
399     private javax.swing.JPanel JavaDoc pSettings;
400     private javax.swing.JTextField JavaDoc tfClassName;
401     private javax.swing.JTextField JavaDoc tfCondition;
402     private javax.swing.JTextField JavaDoc tfMethodName;
403     private javax.swing.JTextField JavaDoc tfPackageName;
404     // End of variables declaration//GEN-END:variables
405

406 }
407
Popular Tags