KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > actions > AddBreakpointPanel


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.ui.actions;
21
22 import java.awt.Window JavaDoc;
23 import java.util.*;
24 import java.beans.*;
25 import javax.swing.*;
26 import java.awt.event.*;
27 import java.util.Set JavaDoc;
28 import java.util.TreeSet JavaDoc;
29
30 import org.openide.awt.Mnemonics;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33
34 import org.netbeans.api.debugger.*;
35 import org.netbeans.api.debugger.Breakpoint.*;
36 import org.netbeans.spi.debugger.ui.BreakpointType;
37 import org.netbeans.spi.debugger.ui.Controller;
38
39
40 /**
41 * New Breakpint Dialog panel.
42 *
43 * @author Jan Jacura
44 */

45 // <RAVE>
46
// Make the class implement HelpCtx.Provider to be able to get Help for it
47
// public class AddBreakpointPanel extends javax.swing.JPanel {
48
// ====
49
public class AddBreakpointPanel extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider {
50 // </RAVE>
51

52     public static final String JavaDoc PROP_TYPE = "type";
53     
54     private static Object JavaDoc lastSelectedCategory;
55     
56     // variables ...............................................................
57

58     private boolean doNotRefresh = false;
59     /** List of cathegories. */
60     private Set JavaDoc cathegories = new TreeSet JavaDoc ();
61     /** Types in currently selected cathegory. */
62     private ArrayList types = new ArrayList ();
63     /** Currently selected type. */
64     private BreakpointType type;
65     private JComponent customizer;
66
67     private javax.swing.JLabel JavaDoc jLabel1;
68     private javax.swing.JLabel JavaDoc jLabel2;
69     private javax.swing.JComboBox JavaDoc cbCathegory;
70     private javax.swing.JComboBox JavaDoc cbEvents;
71     private javax.swing.JPanel JavaDoc pEvent;
72     /** <CODE>HelpCtx</CODE> of the selected breakpoint type's customizer */
73     private HelpCtx helpCtx;
74     private List breakpointTypes;
75
76
77     // init ....................................................................
78

79     /** Creates new form AddBreakpointPanel */
80     public AddBreakpointPanel () {
81         breakpointTypes = DebuggerManager.getDebuggerManager ().lookup
82             (null, BreakpointType.class);
83         int i, k = breakpointTypes.size ();
84         String JavaDoc def = null;
85         for (i = 0; i < k; i++) {
86             BreakpointType bt = (BreakpointType) breakpointTypes.get (i);
87             String JavaDoc dn = bt.getCategoryDisplayName ();
88             if (!cathegories.contains (dn)) {
89                 cathegories.add (dn);
90             }
91             if (bt.isDefault ())
92                 def = dn;
93         }
94         cbCathegory = new javax.swing.JComboBox JavaDoc(cathegories.toArray());
95         
96         initComponents ();
97         if (def != null) {
98             cbCathegory.setSelectedItem(def);
99             selectCathegory (def);
100         } else if (breakpointTypes.size () > 0) {
101             if (cathegories.contains(lastSelectedCategory)) {
102                 cbCathegory.setSelectedItem(lastSelectedCategory);
103             } else {
104                 cbCathegory.setSelectedIndex(0);
105             }
106             selectCathegory ((String JavaDoc) cbCathegory.getSelectedItem ());
107         }
108     }
109
110
111     // public interface ........................................................
112

113     public BreakpointType getType () {
114         return type;
115     }
116     
117     public Controller getController () {
118         return (Controller) customizer;
119     }
120     
121     
122     // other methods ...........................................................
123

124     private void initComponents () {
125         getAccessibleContext().setAccessibleDescription(NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_AddBreakpointPanel")); // NOI18N
126
setLayout (new java.awt.GridBagLayout JavaDoc ());
127         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
128
129         if (cathegories.size () > 1) {
130                 jLabel1 = new javax.swing.JLabel JavaDoc ();
131                 Mnemonics.setLocalizedText(jLabel1, NbBundle.getBundle (AddBreakpointPanel.class).
132                     getString ("CTL_Breakpoint_cathegory")); // NOI18N
133
gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
134                 gridBagConstraints1.gridwidth = 2;
135                 gridBagConstraints1.insets = new java.awt.Insets JavaDoc (12, 12, 0, 0);
136             add (jLabel1, gridBagConstraints1);
137
138                 cbCathegory.addActionListener (new java.awt.event.ActionListener JavaDoc () {
139                     public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
140                         cbCathegoryActionPerformed (evt);
141                     }
142                 });
143                 cbCathegory.getAccessibleContext().setAccessibleDescription(
144                 NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_CTL_Breakpoint_cathegory")); // NOI18N
145
jLabel1.setLabelFor (cbCathegory);
146                 gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
147                 gridBagConstraints1.gridwidth = 2;
148                 gridBagConstraints1.insets = new java.awt.Insets JavaDoc (12, 12, 0, 0);
149                 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
150             add (cbCathegory, gridBagConstraints1);
151         }
152
153             jLabel2 = new javax.swing.JLabel JavaDoc ();
154             Mnemonics.setLocalizedText(jLabel2, NbBundle.getBundle (AddBreakpointPanel.class).
155                 getString ("CTL_Breakpoint_type")); // NOI18N
156
gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
157             gridBagConstraints1.gridwidth = 2;
158             gridBagConstraints1.insets = new java.awt.Insets JavaDoc (12, 12, 0, 0);
159         add (jLabel2, gridBagConstraints1);
160             
161             cbEvents = new javax.swing.JComboBox JavaDoc ();
162             cbEvents.addActionListener (new java.awt.event.ActionListener JavaDoc () {
163                 public void actionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
164                     cbEventsActionPerformed ();
165                 }
166             });
167             cbEvents.getAccessibleContext().setAccessibleDescription(
168                 NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_CTL_Breakpoint_type")); // NOI18N
169
cbEvents.setMaximumRowCount (12);
170             gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
171             gridBagConstraints1.gridwidth = 0;
172             gridBagConstraints1.insets = new java.awt.Insets JavaDoc (12, 12, 0, 12);
173             gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
174         add (cbEvents, gridBagConstraints1);
175             jLabel2.setLabelFor (cbEvents);
176             pEvent = new javax.swing.JPanel JavaDoc ();
177             pEvent.setLayout (new java.awt.BorderLayout JavaDoc ());
178             gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc ();
179             gridBagConstraints1.gridwidth = 0;
180             gridBagConstraints1.insets = new java.awt.Insets JavaDoc (9, 9, 0, 9);
181             gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
182             gridBagConstraints1.weightx = 1.0;
183             gridBagConstraints1.weighty = 1.0;
184         add (pEvent, gridBagConstraints1);
185     }
186
187     private void cbEventsActionPerformed () {
188         // Add your handling code here:
189
if (doNotRefresh) return;
190         SwingUtilities.invokeLater (new Runnable JavaDoc () {
191             public void run () {
192                 boolean pv = cbEvents.isPopupVisible ();
193                 int j = cbEvents.getSelectedIndex ();
194                 if (j < 0) return;
195                 update ((BreakpointType) types.get (j));
196                 if (pv)
197                     SwingUtilities.invokeLater (new Runnable JavaDoc () {
198                         public void run () {
199                             cbEvents.setPopupVisible (true);
200                         }
201                     });
202                     //cbEvents.setPopupVisible (true);
203
}
204         });
205     }
206
207     private void cbCathegoryActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {
208         // Add your handling code here:
209
if (doNotRefresh) return;
210         String JavaDoc c = (String JavaDoc) cbCathegory.getSelectedItem ();
211         if (c == null) return;
212         selectCathegory (c);
213     }
214     
215     private void selectCathegory (String JavaDoc c) {
216         lastSelectedCategory = c;
217         doNotRefresh = true;
218         cbEvents.removeAllItems ();
219         types = new ArrayList ();
220         int i, k = breakpointTypes.size (), defIndex = 0;
221         for (i = 0; i < k; i++) {
222             BreakpointType bt = (BreakpointType) breakpointTypes.get (i);
223             if (!bt.getCategoryDisplayName ().equals (c))
224                 continue;
225             cbEvents.addItem (bt.getTypeDisplayName ());
226             types.add (bt);
227             if (bt.isDefault ())
228                 defIndex = cbEvents.getItemCount () - 1;
229         }
230         doNotRefresh = false;
231         if (defIndex < cbEvents.getItemCount ())
232             cbEvents.setSelectedIndex (defIndex);
233     }
234     
235     /**
236      * Returns <CODE>HelpCtx</CODE> of the selected breakpoint type's customizer.
237      * It is used in {@link AddBreakpointAction.AddBreakpointDialogManager}.
238      */

239     // <RAVE>
240
// Make getHelpCtx() method public to correctly implement HelpCtx.Provider
241
// HelpCtx getHelpCtx() {
242
// ====
243
public HelpCtx getHelpCtx() {
244     // </RAVE>
245
return helpCtx;
246     }
247
248     private void update (BreakpointType t) {
249         if (type == t) return ;
250         pEvent.removeAll ();
251         DebuggerManager d = DebuggerManager.getDebuggerManager ();
252         BreakpointType old = type;
253         type = t;
254         customizer = type.getCustomizer ();
255         if (customizer == null) return;
256
257         //Set HelpCtx. This method must be called _before_ the customizer
258
//is added to some container, otherwise HelpCtx.findHelp(...) would
259
//query also the customizer's parents.
260
// <RAVE>
261
// The help IDs for the customizer panels have to be different from the
262
// values returned by getHelpCtx() because they provide different help
263
// in the 'Add Breakpoint' dialog and when invoked in the 'Breakpoints' view
264
// helpCtx = HelpCtx.findHelp (customizer);
265
// ====
266
String JavaDoc hid = (String JavaDoc) customizer.getClientProperty("HelpID_AddBreakpointPanel"); // NOI18N
267
if (hid != null) {
268             helpCtx = new HelpCtx(hid);
269         } else {
270             helpCtx = HelpCtx.findHelp (customizer);
271         }
272         // </RAVE>
273

274         pEvent.add (customizer, "Center"); // NOI18N
275
pEvent.getAccessibleContext ().setAccessibleDescription (
276             customizer.getAccessibleContext ().getAccessibleDescription ()
277         );
278         customizer.getAccessibleContext ().setAccessibleName (
279             pEvent.getAccessibleContext ().getAccessibleName ()
280         );
281         revalidate ();
282         Window JavaDoc w = SwingUtilities.windowForComponent (this);
283         if (w == null) return;
284         w.pack ();
285         firePropertyChange (PROP_TYPE, old, type);
286     }
287 }
288
289
Popular Tags