1 19 20 package org.netbeans.modules.debugger.ui.actions; 21 22 import java.awt.Window ; 23 import java.util.*; 24 import java.beans.*; 25 import javax.swing.*; 26 import java.awt.event.*; 27 import java.util.Set ; 28 import java.util.TreeSet ; 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 45 public class AddBreakpointPanel extends javax.swing.JPanel implements HelpCtx.Provider { 50 52 public static final String PROP_TYPE = "type"; 53 54 private static Object lastSelectedCategory; 55 56 58 private boolean doNotRefresh = false; 59 60 private Set cathegories = new TreeSet (); 61 62 private ArrayList types = new ArrayList (); 63 64 private BreakpointType type; 65 private JComponent customizer; 66 67 private javax.swing.JLabel jLabel1; 68 private javax.swing.JLabel jLabel2; 69 private javax.swing.JComboBox cbCathegory; 70 private javax.swing.JComboBox cbEvents; 71 private javax.swing.JPanel pEvent; 72 73 private HelpCtx helpCtx; 74 private List breakpointTypes; 75 76 77 79 80 public AddBreakpointPanel () { 81 breakpointTypes = DebuggerManager.getDebuggerManager ().lookup 82 (null, BreakpointType.class); 83 int i, k = breakpointTypes.size (); 84 String def = null; 85 for (i = 0; i < k; i++) { 86 BreakpointType bt = (BreakpointType) breakpointTypes.get (i); 87 String 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 (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 ) cbCathegory.getSelectedItem ()); 107 } 108 } 109 110 111 113 public BreakpointType getType () { 114 return type; 115 } 116 117 public Controller getController () { 118 return (Controller) customizer; 119 } 120 121 122 124 private void initComponents () { 125 getAccessibleContext().setAccessibleDescription(NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_AddBreakpointPanel")); setLayout (new java.awt.GridBagLayout ()); 127 java.awt.GridBagConstraints gridBagConstraints1; 128 129 if (cathegories.size () > 1) { 130 jLabel1 = new javax.swing.JLabel (); 131 Mnemonics.setLocalizedText(jLabel1, NbBundle.getBundle (AddBreakpointPanel.class). 132 getString ("CTL_Breakpoint_cathegory")); gridBagConstraints1 = new java.awt.GridBagConstraints (); 134 gridBagConstraints1.gridwidth = 2; 135 gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 0); 136 add (jLabel1, gridBagConstraints1); 137 138 cbCathegory.addActionListener (new java.awt.event.ActionListener () { 139 public void actionPerformed (java.awt.event.ActionEvent evt) { 140 cbCathegoryActionPerformed (evt); 141 } 142 }); 143 cbCathegory.getAccessibleContext().setAccessibleDescription( 144 NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_CTL_Breakpoint_cathegory")); jLabel1.setLabelFor (cbCathegory); 146 gridBagConstraints1 = new java.awt.GridBagConstraints (); 147 gridBagConstraints1.gridwidth = 2; 148 gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 0); 149 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; 150 add (cbCathegory, gridBagConstraints1); 151 } 152 153 jLabel2 = new javax.swing.JLabel (); 154 Mnemonics.setLocalizedText(jLabel2, NbBundle.getBundle (AddBreakpointPanel.class). 155 getString ("CTL_Breakpoint_type")); gridBagConstraints1 = new java.awt.GridBagConstraints (); 157 gridBagConstraints1.gridwidth = 2; 158 gridBagConstraints1.insets = new java.awt.Insets (12, 12, 0, 0); 159 add (jLabel2, gridBagConstraints1); 160 161 cbEvents = new javax.swing.JComboBox (); 162 cbEvents.addActionListener (new java.awt.event.ActionListener () { 163 public void actionPerformed (java.awt.event.ActionEvent evt) { 164 cbEventsActionPerformed (); 165 } 166 }); 167 cbEvents.getAccessibleContext().setAccessibleDescription( 168 NbBundle.getBundle (AddBreakpointPanel.class).getString ("ACSD_CTL_Breakpoint_type")); cbEvents.setMaximumRowCount (12); 170 gridBagConstraints1 = new java.awt.GridBagConstraints (); 171 gridBagConstraints1.gridwidth = 0; 172 gridBagConstraints1.insets = new java.awt.Insets (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 (); 177 pEvent.setLayout (new java.awt.BorderLayout ()); 178 gridBagConstraints1 = new java.awt.GridBagConstraints (); 179 gridBagConstraints1.gridwidth = 0; 180 gridBagConstraints1.insets = new java.awt.Insets (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 if (doNotRefresh) return; 190 SwingUtilities.invokeLater (new Runnable () { 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 () { 198 public void run () { 199 cbEvents.setPopupVisible (true); 200 } 201 }); 202 } 204 }); 205 } 206 207 private void cbCathegoryActionPerformed (java.awt.event.ActionEvent evt) { 208 if (doNotRefresh) return; 210 String c = (String ) cbCathegory.getSelectedItem (); 211 if (c == null) return; 212 selectCathegory (c); 213 } 214 215 private void selectCathegory (String 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 239 public HelpCtx getHelpCtx() { 244 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 String hid = (String ) customizer.getClientProperty("HelpID_AddBreakpointPanel"); if (hid != null) { 268 helpCtx = new HelpCtx(hid); 269 } else { 270 helpCtx = HelpCtx.findHelp (customizer); 271 } 272 274 pEvent.add (customizer, "Center"); pEvent.getAccessibleContext ().setAccessibleDescription ( 276 customizer.getAccessibleContext ().getAccessibleDescription () 277 ); 278 customizer.getAccessibleContext ().setAccessibleName ( 279 pEvent.getAccessibleContext ().getAccessibleName () 280 ); 281 revalidate (); 282 Window w = SwingUtilities.windowForComponent (this); 283 if (w == null) return; 284 w.pack (); 285 firePropertyChange (PROP_TYPE, old, type); 286 } 287 } 288 289 | Popular Tags |