1 19 20 package org.netbeans.modules.debugger.jpda.ui.breakpoints; 21 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 import java.util.Map ; 25 import java.util.TreeMap ; 26 import javax.swing.JPanel ; 27 import javax.swing.JOptionPane ; 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 39 public class ExceptionBreakpointPanel extends JPanel implements Controller, org.openide.util.HelpCtx.Provider { 44 46 private ActionsPanel actionsPanel; 47 private ExceptionBreakpoint breakpoint; 48 private boolean createBreakpoint = false; 49 private static Map exceptions = new TreeMap (); 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 81 public ExceptionBreakpointPanel () { 82 this (creteBreakpoint ()); 83 createBreakpoint = true; 84 } 85 86 87 public ExceptionBreakpointPanel (ExceptionBreakpoint b) { 88 breakpoint = b; 89 initComponents (); 90 Iterator it = exceptions.keySet ().iterator (); 91 while (it.hasNext ()) 92 cbExceptionClassName.addItem (it.next ()); 93 94 String 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 putClientProperty("HelpID_AddBreakpointPanel", "debug.add.breakpoint.java.exception"); } 128 129 public org.openide.util.HelpCtx getHelpCtx() { 132 return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointExceptionJPDA"); } 134 136 141 private void initComponents() { 143 java.awt.GridBagConstraints gridBagConstraints; 144 145 pSettings = new javax.swing.JPanel (); 146 jLabel1 = new javax.swing.JLabel (); 147 jLabel2 = new javax.swing.JLabel (); 148 jLabel3 = new javax.swing.JLabel (); 149 jLabel4 = new javax.swing.JLabel (); 150 cbBreakpointType = new javax.swing.JComboBox (); 151 jLabel5 = new javax.swing.JLabel (); 152 tfCondition = new javax.swing.JTextField (); 153 cbExceptionClassName = new javax.swing.JComboBox (); 154 tfPackageName = new javax.swing.JTextField (); 155 pActions = new javax.swing.JPanel (); 156 jPanel1 = new javax.swing.JPanel (); 157 158 setLayout(new java.awt.GridBagLayout ()); 159 160 pSettings.setLayout(new java.awt.GridBagLayout ()); 161 162 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/debugger/jpda/ui/breakpoints/Bundle"); pSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("L_Exception_Breakpoint_BorderTitle"))); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("L_Exception_Breakpoint_filter_hint")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 170 pSettings.add(jLabel1, gridBagConstraints); 171 jLabel1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_filter_hint")); 173 jLabel2.setLabelFor(tfPackageName); 174 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, bundle.getString("L_Exception_Breakpoint_Package_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 181 pSettings.add(jLabel2, gridBagConstraints); 182 jLabel2.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Package_Name")); 184 jLabel3.setLabelFor(cbExceptionClassName); 185 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("L_Exception_Breakpoint_Class_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 192 pSettings.add(jLabel3, gridBagConstraints); 193 jLabel3.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Class_Name")); 195 jLabel4.setLabelFor(cbBreakpointType); 196 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, bundle.getString("L_Exception_Breakpoint_Type")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 203 pSettings.add(jLabel4, gridBagConstraints); 204 jLabel4.getAccessibleContext().setAccessibleDescription(bundle.getString("ASCD_L_Exception_Breakpoint_Type")); 206 cbBreakpointType.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Type")); gridBagConstraints = new java.awt.GridBagConstraints (); 208 gridBagConstraints.gridx = 1; 209 gridBagConstraints.gridy = 3; 210 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 211 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 212 pSettings.add(cbBreakpointType, gridBagConstraints); 213 cbBreakpointType.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Exception_Breakpoint_Type")); 215 jLabel5.setLabelFor(tfCondition); 216 org.openide.awt.Mnemonics.setLocalizedText(jLabel5, bundle.getString("L_Exception_Breakpoint_Condition")); gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 223 pSettings.add(jLabel5, gridBagConstraints); 224 jLabel5.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Exception_Breakpoint_Condition")); 226 tfCondition.setToolTipText(bundle.getString("TTT_TF_Exception_Breakpoint_Condition")); gridBagConstraints = new java.awt.GridBagConstraints (); 228 gridBagConstraints.gridx = 1; 229 gridBagConstraints.gridy = 4; 230 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 231 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 232 pSettings.add(tfCondition, gridBagConstraints); 233 tfCondition.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Exception_Breakpoint_Condition")); 235 cbExceptionClassName.setEditable(true); 236 cbExceptionClassName.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Class_Name")); cbExceptionClassName.addActionListener(new java.awt.event.ActionListener () { 238 public void actionPerformed(java.awt.event.ActionEvent evt) { 239 cbExceptionClassNameActionPerformed(evt); 240 } 241 }); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (3, 3, 3, 3); 249 pSettings.add(cbExceptionClassName, gridBagConstraints); 250 cbExceptionClassName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CB_Exception_Breakpoint_Class_Name")); 252 tfPackageName.setToolTipText(bundle.getString("TTT_CB_Exception_Breakpoint_Package_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 254 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 255 gridBagConstraints.weightx = 1.0; 256 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 257 pSettings.add(tfPackageName, gridBagConstraints); 258 tfPackageName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Exception_Breakpoint_Package_Name")); 260 gridBagConstraints = new java.awt.GridBagConstraints (); 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 ()); 267 268 gridBagConstraints = new java.awt.GridBagConstraints (); 269 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 270 gridBagConstraints.weightx = 1.0; 271 add(pActions, gridBagConstraints); 272 273 gridBagConstraints = new java.awt.GridBagConstraints (); 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 } 283 private void cbExceptionClassNameActionPerformed(java.awt.event.ActionEvent evt) { String pkg = (String ) exceptions.get (cbExceptionClassName.getSelectedItem ()); 286 if (pkg != null) 287 tfPackageName.setText (pkg); 288 } 290 291 293 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 className = ((String ) tfPackageName.getText ()).trim (); 307 if (className.length () > 0) 308 className += '.'; 309 className += ((String ) 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 335 public boolean cancel () { 336 return true; 337 } 338 339 346 public boolean isValid () { 347 return true; 348 } 349 350 boolean isFilled () { 351 if (((String ) cbExceptionClassName.getSelectedItem ()) 352 .trim ().length() > 0) 353 return true; 354 return false; 355 } 356 357 358 private javax.swing.JComboBox cbBreakpointType; 360 private javax.swing.JComboBox cbExceptionClassName; 361 private javax.swing.JLabel jLabel1; 362 private javax.swing.JLabel jLabel2; 363 private javax.swing.JLabel jLabel3; 364 private javax.swing.JLabel jLabel4; 365 private javax.swing.JLabel jLabel5; 366 private javax.swing.JPanel jPanel1; 367 private javax.swing.JPanel pActions; 368 private javax.swing.JPanel pSettings; 369 private javax.swing.JTextField tfCondition; 370 private javax.swing.JTextField tfPackageName; 371 373 } 374 | Popular Tags |