KickJava   Java API By Example, From Geeks To Geeks.

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


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.ClassLoadUnloadBreakpoint;
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 ClassBreakpointPanel extends JPanel implements Controller {
37
// ====
38
public class ClassBreakpointPanel extends JPanel JavaDoc implements Controller, org.openide.util.HelpCtx.Provider {
39 // </RAVE>
40

41     private ActionsPanel actionsPanel;
42     private ClassLoadUnloadBreakpoint breakpoint;
43     private boolean createBreakpoint = false;
44     
45     
46     private static ClassLoadUnloadBreakpoint creteBreakpoint () {
47         ClassLoadUnloadBreakpoint mb = ClassLoadUnloadBreakpoint.create (
48             EditorContextBridge.getCurrentClassName (),
49             false,
50             ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED_UNLOADED
51         );
52         mb.setPrintText (
53             NbBundle.getBundle (ClassBreakpointPanel.class).getString
54                 ("CTL_Class_Breakpoint_Print_Text")
55         );
56         return mb;
57     }
58     
59     
60     /** Creates new form LineBreakpointPanel */
61     public ClassBreakpointPanel () {
62         this (creteBreakpoint ());
63         createBreakpoint = true;
64     }
65     
66     /** Creates new form LineBreakpointPanel */
67     public ClassBreakpointPanel (ClassLoadUnloadBreakpoint b) {
68         breakpoint = b;
69         initComponents ();
70         
71         String JavaDoc[] cf = b.getClassExclusionFilters ();
72         String JavaDoc className = "";
73         if (cf.length > 0) {
74             cbExclusionFilter.setSelected (true);
75             className = cf [0];
76         } else {
77             cbExclusionFilter.setSelected (false);
78             cf = b.getClassFilters ();
79             if (cf.length > 0)
80                 className = cf [0];
81         }
82         int i = className.lastIndexOf ('.');
83         if (i < 0) {
84             tfPackageName.setText ("");
85             tfClassName.setText (className);
86         } else {
87             tfPackageName.setText (className.substring (0, i));
88             tfClassName.setText (className.substring (i + 1, className.length ()));
89         }
90         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Class_Breakpoint_Type_Prepare"));
91         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Class_Breakpoint_Type_Unload"));
92         cbBreakpointType.addItem (java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle").getString("LBL_Class_Breakpoint_Type_Prepare_or_Unload"));
93         switch (b.getBreakpointType ()) {
94             case ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED:
95                 cbBreakpointType.setSelectedIndex (0);
96                 break;
97             case ClassLoadUnloadBreakpoint.TYPE_CLASS_UNLOADED:
98                 cbBreakpointType.setSelectedIndex (1);
99                 break;
100             case ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED_UNLOADED:
101                 cbBreakpointType.setSelectedIndex (2);
102                 break;
103         }
104         
105         actionsPanel = new ActionsPanel (b);
106         pActions.add (actionsPanel, "Center");
107         // <RAVE>
108
// The help IDs for the AddBreakpointPanel panels have to be different from the
109
// values returned by getHelpCtx() because they provide different help
110
// in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view
111
putClientProperty("HelpID_AddBreakpointPanel", "debug.add.breakpoint.java.class"); // NOI18N
112
// </RAVE>
113
}
114
115     // <RAVE>
116
// Implement getHelpCtx() with the correct helpID
117
public org.openide.util.HelpCtx getHelpCtx() {
118        return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointClassJPDA"); // NOI18N
119
}
120     // </RAVE>
121

122     /** This method is called from within the constructor to
123      * initialize the form.
124      * WARNING: Do NOT modify this code. The content of this method is
125      * always regenerated by the Form Editor.
126      */

127     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
128
private void initComponents() {
129         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
130
131         pSettings = new javax.swing.JPanel JavaDoc();
132         jLabel1 = new javax.swing.JLabel JavaDoc();
133         jLabel2 = new javax.swing.JLabel JavaDoc();
134         tfPackageName = new javax.swing.JTextField JavaDoc();
135         jLabel3 = new javax.swing.JLabel JavaDoc();
136         tfClassName = new javax.swing.JTextField JavaDoc();
137         cbExclusionFilter = new javax.swing.JCheckBox JavaDoc();
138         jLabel4 = new javax.swing.JLabel JavaDoc();
139         cbBreakpointType = new javax.swing.JComboBox JavaDoc();
140         pActions = new javax.swing.JPanel JavaDoc();
141         jPanel1 = new javax.swing.JPanel JavaDoc();
142
143         setLayout(new java.awt.GridBagLayout JavaDoc());
144
145         pSettings.setLayout(new java.awt.GridBagLayout JavaDoc());
146
147         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle"); // NOI18N
148
pSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("L_Class_Breakpoint_BorderTitle"))); // NOI18N
149
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("L_Class_Breakpoint_filter_hint")); // NOI18N
150
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
151         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
152         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
153         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
155         pSettings.add(jLabel1, gridBagConstraints);
156         jLabel1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Class_Breakpoint_filter_hint")); // NOI18N
157

158         jLabel2.setLabelFor(tfPackageName);
159         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle.getString("L_Class_Breakpoint_Package_Name")); // NOI18N
160
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
161         gridBagConstraints.gridx = 0;
162         gridBagConstraints.gridy = 1;
163         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
164         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
165         pSettings.add(jLabel2, gridBagConstraints);
166         jLabel2.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Class_Breakpoint_Package_Name")); // NOI18N
167

168         tfPackageName.setToolTipText(bundle.getString("TTT_TF_Class_Breakpoint_Package_Name")); // NOI18N
169
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 1;
171         gridBagConstraints.gridy = 1;
172         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173         gridBagConstraints.weightx = 1.0;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
175         pSettings.add(tfPackageName, gridBagConstraints);
176         tfPackageName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Class_Breakpoint_Package_Name")); // NOI18N
177

178         jLabel3.setLabelFor(tfClassName);
179         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("L_Class_Breakpoint_Class_Name")); // NOI18N
180
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 0;
182         gridBagConstraints.gridy = 2;
183         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
184         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
185         pSettings.add(jLabel3, gridBagConstraints);
186         jLabel3.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Class_Breakpoint_Class_Name")); // NOI18N
187

188         tfClassName.setToolTipText(bundle.getString("TTT_TF_Class_Breakpoint_Class_Name")); // NOI18N
189
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
190         gridBagConstraints.gridx = 1;
191         gridBagConstraints.gridy = 2;
192         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
193         gridBagConstraints.weightx = 1.0;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
195         pSettings.add(tfClassName, gridBagConstraints);
196         tfClassName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Class_Breakpoint_Class_Name")); // NOI18N
197

198         org.openide.awt.Mnemonics.setLocalizedText(cbExclusionFilter, bundle.getString("CB_Class_Breakpoint_Exclusion_Filter")); // NOI18N
199
cbExclusionFilter.setToolTipText(bundle.getString("TTT_CB_Class_Breakpoint_Exclusion_Filter")); // NOI18N
200
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
201         gridBagConstraints.gridx = 0;
202         gridBagConstraints.gridy = 3;
203         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
207         pSettings.add(cbExclusionFilter, gridBagConstraints);
208         cbExclusionFilter.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Class_Breakpoint_Exclusion_Filter")); // NOI18N
209

210         jLabel4.setLabelFor(cbBreakpointType);
211         org.openide.awt.Mnemonics.setLocalizedText(jLabel4, bundle.getString("L_Class_Breakpoint_Type")); // NOI18N
212
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213         gridBagConstraints.gridx = 0;
214         gridBagConstraints.gridy = 4;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
216         pSettings.add(jLabel4, gridBagConstraints);
217         jLabel4.getAccessibleContext().setAccessibleDescription(bundle.getString("ASCD_L_Class_Breakpoint_Type")); // NOI18N
218

219         cbBreakpointType.setToolTipText(bundle.getString("TTT_CB_Class_Breakpoint_Type")); // NOI18N
220
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 1;
222         gridBagConstraints.gridy = 4;
223         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
224         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 3, 3, 3);
225         pSettings.add(cbBreakpointType, gridBagConstraints);
226         cbBreakpointType.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Class_Breakpoint_Type")); // NOI18N
227

228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
230         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
231         gridBagConstraints.weightx = 1.0;
232         add(pSettings, gridBagConstraints);
233
234         pActions.setLayout(new java.awt.BorderLayout JavaDoc());
235
236         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
237         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
238         gridBagConstraints.weightx = 1.0;
239         add(pActions, gridBagConstraints);
240
241         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
242         gridBagConstraints.gridx = 0;
243         gridBagConstraints.gridy = 2;
244         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
245         gridBagConstraints.weightx = 1.0;
246         gridBagConstraints.weighty = 1.0;
247         add(jPanel1, gridBagConstraints);
248
249     }// </editor-fold>//GEN-END:initComponents
250

251     
252     // Controller implementation ...............................................
253

254     /**
255      * Called when "Ok" button is pressed.
256      *
257      * @return whether customizer can be closed
258      */

259     public boolean ok () {
260         if (! isFilled()) {
261             JOptionPane.showMessageDialog(this,
262                 java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle")
263                     .getString("MSG_No_Class_Name_Spec"));
264             return false;
265         }
266         actionsPanel.ok ();
267         String JavaDoc className = tfPackageName.getText ().trim ();
268         if (className.length () > 0)
269             className += '.';
270         className += tfClassName.getText ().trim ();
271         if (cbExclusionFilter.isSelected ()) {
272             breakpoint.setClassFilters (new String JavaDoc [0]);
273             breakpoint.setClassExclusionFilters (new String JavaDoc [] {className});
274         } else {
275             breakpoint.setClassFilters (new String JavaDoc [] {className});
276             breakpoint.setClassExclusionFilters (new String JavaDoc [0]);
277         }
278         
279         switch (cbBreakpointType.getSelectedIndex ()) {
280             case 0:
281                 breakpoint.setBreakpointType (ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED);
282                 break;
283             case 1:
284                 breakpoint.setBreakpointType (ClassLoadUnloadBreakpoint.TYPE_CLASS_UNLOADED);
285                 break;
286             case 2:
287                 breakpoint.setBreakpointType (ClassLoadUnloadBreakpoint.TYPE_CLASS_LOADED_UNLOADED);
288                 break;
289         }
290         if (createBreakpoint)
291             DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint);
292         return true;
293     }
294     
295     /**
296      * Called when "Cancel" button is pressed.
297      *
298      * @return whether customizer can be closed
299      */

300     public boolean cancel () {
301         return true;
302     }
303     
304     /**
305      * Return <code>true</code> whether value of this customizer
306      * is valid (and OK button can be enabled).
307      *
308      * @return <code>true</code> whether value of this customizer
309      * is valid
310      */

311     public boolean isValid () {
312         return true;
313     }
314     
315     boolean isFilled () {
316         if (tfClassName.getText().trim ().length() > 0)
317             return true;
318         return false;
319     }
320     
321     // Variables declaration - do not modify//GEN-BEGIN:variables
322
private javax.swing.JComboBox JavaDoc cbBreakpointType;
323     private javax.swing.JCheckBox JavaDoc cbExclusionFilter;
324     private javax.swing.JLabel JavaDoc jLabel1;
325     private javax.swing.JLabel JavaDoc jLabel2;
326     private javax.swing.JLabel JavaDoc jLabel3;
327     private javax.swing.JLabel JavaDoc jLabel4;
328     private javax.swing.JPanel JavaDoc jPanel1;
329     private javax.swing.JPanel JavaDoc pActions;
330     private javax.swing.JPanel JavaDoc pSettings;
331     private javax.swing.JTextField JavaDoc tfClassName;
332     private javax.swing.JTextField JavaDoc tfPackageName;
333     // End of variables declaration//GEN-END:variables
334

335 }
336
Popular Tags