KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashMap JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.Map JavaDoc;
25 import java.util.TreeMap JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JOptionPane JavaDoc;
28 import org.netbeans.api.debugger.DebuggerManager;
29
30 import org.netbeans.api.debugger.jpda.ExceptionBreakpoint;
31 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
32 import org.netbeans.spi.debugger.ui.Controller;
33 import org.openide.util.NbBundle;
34
35
36 /**
37  * @author Jan Jancura
38  */

39 // <RAVE>
40
// Implement HelpCtx.Provider interface to provide help ids for help system
41
// public class ExceptionBreakpointPanel extends JPanel implements Controller {
42
// ====
43
public class ExceptionBreakpointPanel extends JPanel JavaDoc implements Controller, org.openide.util.HelpCtx.Provider {
44 // </RAVE>
45

46     private ActionsPanel actionsPanel;
47     private ExceptionBreakpoint breakpoint;
48     private boolean createBreakpoint = false;
49     private static Map JavaDoc exceptions = new TreeMap JavaDoc ();
50     
51     static {
52         exceptions.put ("ArrayIndexOutOfBoundsException", "java.lang");
53         exceptions.put ("AssertionError", "java.lang");
54         exceptions.put ("ClassCastException", "java.lang");
55         exceptions.put ("ClassNotFoundException", "java.lang");
56         exceptions.put ("IllegalAccessException", "java.lang");
57         exceptions.put ("IllegalArgumentException", "java.lang");
58         exceptions.put ("IndexOutOfBoundsException", "java.lang");
59         exceptions.put ("NullPointerException", "java.lang");
60         exceptions.put ("RuntimeException", "java.lang");
61         exceptions.put ("SecurityException", "java.lang");
62         exceptions.put ("StringIndexOutOfBoundsException", "java.lang");
63         exceptions.put ("UnsupportedOperationException", "java.lang");
64         exceptions.put ("IOException", "java.io");
65     }
66     
67     private static ExceptionBreakpoint creteBreakpoint () {
68         ExceptionBreakpoint mb = ExceptionBreakpoint.create (
69             EditorContextBridge.getCurrentClassName (),
70             ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED_UNCATCHED
71         );
72         mb.setPrintText (
73             NbBundle.getBundle (ExceptionBreakpointPanel.class).getString
74                 ("CTL_Exception_Breakpoint_Print_Text")
75         );
76         return mb;
77     }
78     
79     
80     /** Creates new form LineBreakpointPanel */
81     public ExceptionBreakpointPanel () {
82         this (creteBreakpoint ());
83         createBreakpoint = true;
84     }
85     
86     /** Creates new form LineBreakpointPanel */
87     public ExceptionBreakpointPanel (ExceptionBreakpoint b) {
88         breakpoint = b;
89         initComponents ();
90         Iterator JavaDoc it = exceptions.keySet ().iterator ();
91         while (it.hasNext ())
92             cbExceptionClassName.addItem (it.next ());
93         
94         String JavaDoc className = b.getExceptionClassName ();
95         int i = className.lastIndexOf ('.');
96         if (i < 0) {
97             tfPackageName.setText ("");
98             cbExceptionClassName.setSelectedItem (className);
99         } else {
100             tfPackageName.setText (className.substring (0, i));
101             cbExceptionClassName.setSelectedItem (className.substring (i + 1, className.length ()));
102         }
103         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Exception_Breakpoint_Type_Catched"));
104         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Exception_Breakpoint_Type_Uncatched"));
105         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Exception_Breakpoint_Type_Catched_or_Uncatched"));
106         switch (b.getCatchType ()) {
107             case ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED:
108                 cbBreakpointType.setSelectedIndex (0);
109                 break;
110             case ExceptionBreakpoint.TYPE_EXCEPTION_UNCATCHED:
111                 cbBreakpointType.setSelectedIndex (1);
112                 break;
113             case ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED_UNCATCHED:
114                 cbBreakpointType.setSelectedIndex (2);
115                 break;
116         }
117         tfCondition.setText (b.getCondition ());
118         
119         actionsPanel = new ActionsPanel (b);
120         pActions.add (actionsPanel, "Center");
121         // <RAVE>
122
// The help IDs for the AddBreakpointPanel panels have to be different from the
123
// values returned by getHelpCtx() because they provide different help
124
// in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view
125
putClientProperty("HelpID_AddBreakpointPanel", "debug.add.breakpoint.java.exception"); // NOI18N
126
// </RAVE>
127
}
128     
129     // <RAVE>
130
// Implement getHelpCtx() with the correct helpID
131
public org.openide.util.HelpCtx getHelpCtx() {
132         return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointExceptionJPDA"); // NOI18N
133
}
134     // </RAVE>
135

136     /** This method is called from within the constructor to
137      * initialize the form.
138      * WARNING: Do NOT modify this code. The content of this method is
139      * always regenerated by the Form Editor.
140      */

141     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
142
private void initComponents() {
143         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
144
145         pSettings = new javax.swing.JPanel JavaDoc();
146         jLabel1 = new javax.swing.JLabel JavaDoc();
147         jLabel2 = new javax.swing.JLabel JavaDoc();
148         jLabel3 = new javax.swing.JLabel JavaDoc();
149         jLabel4 = new javax.swing.JLabel JavaDoc();
150         cbBreakpointType = new javax.swing.JComboBox JavaDoc();
151         jLabel5 = new javax.swing.JLabel JavaDoc();
152         tfCondition = new javax.swing.JTextField JavaDoc();
153         cbExceptionClassName = new javax.swing.JComboBox JavaDoc();
154         tfPackageName = new javax.swing.JTextField JavaDoc();
155         pActions = new javax.swing.JPanel JavaDoc();
156         jPanel1 = new javax.swing.JPanel JavaDoc();
157
158         setLayout(new java.awt.GridBagLayout JavaDoc());
159
160         pSettings.setLayout(new java.awt.GridBagLayout JavaDoc());
161
162         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle"); // NOI18N
163
pSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("L_Exception_Breakpoint_BorderTitle"))); // NOI18N
164
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("L_Exception_Breakpoint_filter_hint")); // NOI18N
165
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
167         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
170         pSettings.add(jLabel1, gridBagConstraints);
171         jLabel1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_filter_hint")); // NOI18N
172

173         jLabel2.setLabelFor(tfPackageName);
174         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle.getString("L_Exception_Breakpoint_Package_Name")); // NOI18N
175
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 0;
177         gridBagConstraints.gridy = 1;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
181         pSettings.add(jLabel2, gridBagConstraints);
182         jLabel2.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Package_Name")); // NOI18N
183

184         jLabel3.setLabelFor(cbExceptionClassName);
185         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("L_Exception_Breakpoint_Class_Name")); // NOI18N
186
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints.gridx = 0;
188         gridBagConstraints.gridy = 2;
189         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
190         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
191         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
192         pSettings.add(jLabel3, gridBagConstraints);
193         jLabel3.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Class_Name")); // NOI18N
194

195         jLabel4.setLabelFor(cbBreakpointType);
196         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, bundle.getString("L_Exception_Breakpoint_Type")); // NOI18N
197
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 0;
199         gridBagConstraints.gridy = 3;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
201         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
203         pSettings.add(jLabel4, gridBagConstraints);
204         jLabel4.getAccessibleContext().setAccessibleDescription(bundle.getString("ASCD_L_Exception_Breakpoint_Type")); // NOI18N
205

206         cbBreakpointType.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Type")); // NOI18N
207
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.gridx = 1;
209         gridBagConstraints.gridy = 3;
210         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
211         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
212         pSettings.add(cbBreakpointType, gridBagConstraints);
213         cbBreakpointType.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Exception_Breakpoint_Type")); // NOI18N
214

215         jLabel5.setLabelFor(tfCondition);
216         org.openide.awt.Mnemonics.setLocalizedText(jLabel5, bundle.getString("L_Exception_Breakpoint_Condition")); // NOI18N
217
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridx = 0;
219         gridBagConstraints.gridy = 4;
220         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
221         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
222         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
223         pSettings.add(jLabel5, gridBagConstraints);
224         jLabel5.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Condition")); // NOI18N
225

226         tfCondition.setToolTipText(bundle.getString("TTT_TF_Exception_Breakpoint_Condition")); // NOI18N
227
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints.gridx = 1;
229         gridBagConstraints.gridy = 4;
230         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
231         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
232         pSettings.add(tfCondition, gridBagConstraints);
233         tfCondition.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Exception_Breakpoint_Condition")); // NOI18N
234

235         cbExceptionClassName.setEditable(true);
236         cbExceptionClassName.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Class_Name")); // NOI18N
237
cbExceptionClassName.addActionListener(new java.awt.event.ActionListener JavaDoc() {
238             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
239                 cbExceptionClassNameActionPerformed(evt);
240             }
241         });
242
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 1;
245         gridBagConstraints.gridy = 2;
246         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
247         gridBagConstraints.weightx = 1.0;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
249         pSettings.add(cbExceptionClassName, gridBagConstraints);
250         cbExceptionClassName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Exception_Breakpoint_Class_Name")); // NOI18N
251

252         tfPackageName.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Package_Name")); // NOI18N
253
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
255         gridBagConstraints.weightx = 1.0;
256         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
257         pSettings.add(tfPackageName, gridBagConstraints);
258         tfPackageName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Exception_Breakpoint_Package_Name")); // NOI18N
259

260         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
261         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
262         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
263         gridBagConstraints.weightx = 1.0;
264         add(pSettings, gridBagConstraints);
265
266         pActions.setLayout(new java.awt.BorderLayout JavaDoc());
267
268         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
269         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270         gridBagConstraints.weightx = 1.0;
271         add(pActions, gridBagConstraints);
272
273         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
274         gridBagConstraints.gridx = 0;
275         gridBagConstraints.gridy = 2;
276         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
277         gridBagConstraints.weightx = 1.0;
278         gridBagConstraints.weighty = 1.0;
279         add(jPanel1, gridBagConstraints);
280
281     }// </editor-fold>//GEN-END:initComponents
282

283     private void cbExceptionClassNameActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbExceptionClassNameActionPerformed
284
// TODO add your handling code here:
285
String JavaDoc pkg = (String JavaDoc) exceptions.get (cbExceptionClassName.getSelectedItem ());
286         if (pkg != null)
287             tfPackageName.setText (pkg);
288     }//GEN-LAST:event_cbExceptionClassNameActionPerformed
289

290     
291     // Controller implementation ...............................................
292

293     /**
294      * Called when "Ok" button is pressed.
295      *
296      * @return whether customizer can be closed
297      */

298     public boolean ok () {
299         if (! isFilled()) {
300             JOptionPane.showMessageDialog(this,
301                 java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle")
302                     .getString("MSG_No_Exception_Class_Name_Spec"));
303             return false;
304         }
305         actionsPanel.ok ();
306         String JavaDoc className = ((String JavaDoc) tfPackageName.getText ()).trim ();
307         if (className.length () > 0)
308             className += '.';
309         className += ((String JavaDoc) cbExceptionClassName.getSelectedItem ()).trim ();
310         breakpoint.setExceptionClassName (className);
311         
312         switch (cbBreakpointType.getSelectedIndex ()) {
313             case 0:
314                 breakpoint.setCatchType (ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED);
315                 break;
316             case 1:
317                 breakpoint.setCatchType (ExceptionBreakpoint.TYPE_EXCEPTION_UNCATCHED);
318                 break;
319             case 2:
320                 breakpoint.setCatchType (ExceptionBreakpoint.TYPE_EXCEPTION_CATCHED_UNCATCHED);
321                 break;
322         }
323         breakpoint.setCondition (tfCondition.getText ());
324         
325         if (createBreakpoint)
326             DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint);
327         return true;
328     }
329     
330     /**
331      * Called when "Cancel" button is pressed.
332      *
333      * @return whether customizer can be closed
334      */

335     public boolean cancel () {
336         return true;
337     }
338     
339     /**
340      * Return <code>true</code> whether value of this customizer
341      * is valid (and OK button can be enabled).
342      *
343      * @return <code>true</code> whether value of this customizer
344      * is valid
345      */

346     public boolean isValid () {
347         return true;
348     }
349     
350     boolean isFilled () {
351         if (((String JavaDoc) cbExceptionClassName.getSelectedItem ())
352             .trim ().length() > 0)
353             return true;
354         return false;
355     }
356     
357     
358     // Variables declaration - do not modify//GEN-BEGIN:variables
359
private javax.swing.JComboBox JavaDoc cbBreakpointType;
360     private javax.swing.JComboBox JavaDoc cbExceptionClassName;
361     private javax.swing.JLabel JavaDoc jLabel1;
362     private javax.swing.JLabel JavaDoc jLabel2;
363     private javax.swing.JLabel JavaDoc jLabel3;
364     private javax.swing.JLabel JavaDoc jLabel4;
365     private javax.swing.JLabel JavaDoc jLabel5;
366     private javax.swing.JPanel JavaDoc jPanel1;
367     private javax.swing.JPanel JavaDoc pActions;
368     private javax.swing.JPanel JavaDoc pSettings;
369     private javax.swing.JTextField JavaDoc tfCondition;
370     private javax.swing.JTextField JavaDoc tfPackageName;
371     // End of variables declaration//GEN-END:variables
372

373 }
374
Popular Tags