1 19 20 package org.netbeans.modules.debugger.jpda.ui.breakpoints; 21 22 import javax.swing.JPanel ; 23 import javax.swing.JOptionPane ; 24 import org.netbeans.api.debugger.DebuggerManager; 25 26 import org.netbeans.api.debugger.jpda.MethodBreakpoint; 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 34 public class MethodBreakpointPanel extends JPanel implements Controller, org.openide.util.HelpCtx.Provider { 39 41 private ActionsPanel actionsPanel; 42 private MethodBreakpoint breakpoint; 43 private boolean createBreakpoint = false; 44 45 46 private static MethodBreakpoint createBreakpoint () { 47 MethodBreakpoint mb = MethodBreakpoint.create ( 48 EditorContextBridge.getCurrentClassName (), 49 EditorContextBridge.getCurrentMethodName () 50 ); 51 mb.setPrintText ( 52 NbBundle.getBundle (MethodBreakpointPanel.class).getString 53 ("CTL_Method_Breakpoint_Print_Text") 54 ); 55 return mb; 56 } 57 58 59 60 public MethodBreakpointPanel () { 61 this (createBreakpoint ()); 62 createBreakpoint = true; 63 } 64 65 66 public MethodBreakpointPanel (MethodBreakpoint b) { 67 breakpoint = b; 68 initComponents (); 69 70 String className = ""; 71 String [] fs = b.getClassFilters (); 72 if (fs.length > 0) className = fs [0]; 73 int i = className.lastIndexOf ('.'); 74 if (i < 0) { 75 tfPackageName.setText (""); 76 tfClassName.setText (className); 77 } else { 78 tfPackageName.setText (className.substring (0, i)); 79 tfClassName.setText (className.substring (i + 1, className.length ())); 80 } 81 if ("".equals (b.getMethodName ())) { 82 tfMethodName.setText (org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "Method_Breakpoint_ALL_METHODS")); 83 cbAllMethods.setSelected (true); 84 tfMethodName.setEnabled (false); 85 } else { 86 if (b.getMethodName().equals(tfClassName.getText())) 87 tfMethodName.setText ("<init>"); 88 else 89 tfMethodName.setText (b.getMethodName ()); 90 } 91 cbStopOnEntry.setSelected((b.getBreakpointType() & b.TYPE_METHOD_ENTRY) != 0); 92 cbStopOnExit.setSelected((b.getBreakpointType() & b.TYPE_METHOD_EXIT) != 0); 93 94 tfCondition.setText (b.getCondition ()); 95 96 actionsPanel = new ActionsPanel (b); 97 pActions.add (actionsPanel, "Center"); 98 putClientProperty("HelpID_AddBreakpointPanel", "debug.add.breakpoint.java.method"); } 105 106 public org.openide.util.HelpCtx getHelpCtx() { 109 return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointMethodJPDA"); } 111 113 118 private void initComponents() { 120 java.awt.GridBagConstraints gridBagConstraints; 121 122 pSettings = new javax.swing.JPanel (); 123 jLabel2 = new javax.swing.JLabel (); 124 jLabel3 = new javax.swing.JLabel (); 125 jLabel5 = new javax.swing.JLabel (); 126 tfCondition = new javax.swing.JTextField (); 127 tfPackageName = new javax.swing.JTextField (); 128 tfClassName = new javax.swing.JTextField (); 129 cbAllMethods = new javax.swing.JCheckBox (); 130 jLabel1 = new javax.swing.JLabel (); 131 tfMethodName = new javax.swing.JTextField (); 132 cbStopOnEntry = new javax.swing.JCheckBox (); 133 cbStopOnExit = new javax.swing.JCheckBox (); 134 pActions = new javax.swing.JPanel (); 135 jPanel1 = new javax.swing.JPanel (); 136 137 setLayout(new java.awt.GridBagLayout ()); 138 139 pSettings.setLayout(new java.awt.GridBagLayout ()); 140 141 pSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_BorderTitle"))); jLabel2.setLabelFor(tfPackageName); 143 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Package_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 146 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 147 pSettings.add(jLabel2, gridBagConstraints); 148 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Package_Name")); 150 jLabel3.setLabelFor(tfClassName); 151 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Class_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.gridx = 0; 154 gridBagConstraints.gridy = 1; 155 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 156 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 157 pSettings.add(jLabel3, gridBagConstraints); 158 jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Class_Name")); 160 jLabel5.setLabelFor(tfCondition); 161 org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Condition")); gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 0; 164 gridBagConstraints.gridy = 7; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 167 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 168 pSettings.add(jLabel5, gridBagConstraints); 169 jLabel5.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Condition")); 171 tfCondition.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Condition")); gridBagConstraints = new java.awt.GridBagConstraints (); 173 gridBagConstraints.gridx = 1; 174 gridBagConstraints.gridy = 7; 175 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 176 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 177 pSettings.add(tfCondition, gridBagConstraints); 178 tfCondition.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Condition")); 180 tfPackageName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Package_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 1; 183 gridBagConstraints.gridy = 0; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 185 gridBagConstraints.weightx = 1.0; 186 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 187 pSettings.add(tfPackageName, gridBagConstraints); 188 tfPackageName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Package_Name")); 190 tfClassName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Class_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 192 gridBagConstraints.gridx = 1; 193 gridBagConstraints.gridy = 1; 194 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 195 gridBagConstraints.weightx = 1.0; 196 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 197 pSettings.add(tfClassName, gridBagConstraints); 198 tfClassName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Class_Name")); 200 org.openide.awt.Mnemonics.setLocalizedText(cbAllMethods, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "CB_Method_Breakpoint_All_Methods")); cbAllMethods.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_Method_Breakpoint_All_Methods")); cbAllMethods.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 203 cbAllMethods.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(java.awt.event.ActionEvent evt) { 205 cbAllMethodsActionPerformed(evt); 206 } 207 }); 208 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridx = 0; 211 gridBagConstraints.gridy = 3; 212 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 213 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 214 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 215 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 216 pSettings.add(cbAllMethods, gridBagConstraints); 217 cbAllMethods.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_CB_Method_Breakpoint_All_Methods")); 219 jLabel1.setLabelFor(tfMethodName); 220 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "L_Method_Breakpoint_Method_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.gridx = 0; 223 gridBagConstraints.gridy = 4; 224 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 225 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 226 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 227 pSettings.add(jLabel1, gridBagConstraints); 228 jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_L_Method_Breakpoint_Method_Name")); 230 tfMethodName.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_TF_Method_Breakpoint_Method_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 232 gridBagConstraints.gridx = 1; 233 gridBagConstraints.gridy = 4; 234 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 237 pSettings.add(tfMethodName, gridBagConstraints); 238 tfMethodName.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "ACSD_TF_Method_Breakpoint_Method_Name")); 240 org.openide.awt.Mnemonics.setLocalizedText(cbStopOnEntry, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "LBL_CB_MethodEntry")); cbStopOnEntry.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_MethodEntry")); cbStopOnEntry.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 243 cbStopOnEntry.addActionListener(new java.awt.event.ActionListener () { 244 public void actionPerformed(java.awt.event.ActionEvent evt) { 245 cbStopOnEntryActionPerformed(evt); 246 } 247 }); 248 249 gridBagConstraints = new java.awt.GridBagConstraints (); 250 gridBagConstraints.gridy = 5; 251 gridBagConstraints.gridwidth = 2; 252 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 253 gridBagConstraints.weightx = 1.0; 254 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 255 pSettings.add(cbStopOnEntry, gridBagConstraints); 256 257 org.openide.awt.Mnemonics.setLocalizedText(cbStopOnExit, org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "LBL_CB_MethodExit")); cbStopOnExit.setToolTipText(org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "TTT_CB_MethodExit")); cbStopOnExit.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 260 cbStopOnExit.addActionListener(new java.awt.event.ActionListener () { 261 public void actionPerformed(java.awt.event.ActionEvent evt) { 262 cbStopOnExitActionPerformed(evt); 263 } 264 }); 265 266 gridBagConstraints = new java.awt.GridBagConstraints (); 267 gridBagConstraints.gridy = 6; 268 gridBagConstraints.gridwidth = 2; 269 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 270 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 271 pSettings.add(cbStopOnExit, gridBagConstraints); 272 273 gridBagConstraints = new java.awt.GridBagConstraints (); 274 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 275 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 276 gridBagConstraints.weightx = 1.0; 277 add(pSettings, gridBagConstraints); 278 279 pActions.setLayout(new java.awt.BorderLayout ()); 280 281 gridBagConstraints = new java.awt.GridBagConstraints (); 282 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 283 gridBagConstraints.weightx = 1.0; 284 add(pActions, gridBagConstraints); 285 286 gridBagConstraints = new java.awt.GridBagConstraints (); 287 gridBagConstraints.gridx = 0; 288 gridBagConstraints.gridy = 2; 289 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 290 gridBagConstraints.weightx = 1.0; 291 gridBagConstraints.weighty = 1.0; 292 add(jPanel1, gridBagConstraints); 293 294 } 296 private void cbStopOnExitActionPerformed(java.awt.event.ActionEvent evt) { if (!cbStopOnExit.isSelected() && !cbStopOnEntry.isSelected()) { 299 cbStopOnEntry.setSelected(true); 300 } 301 } 303 private void cbStopOnEntryActionPerformed(java.awt.event.ActionEvent evt) { if (!cbStopOnEntry.isSelected() && !cbStopOnExit.isSelected()) { 306 cbStopOnExit.setSelected(true); 307 } 308 } 310 private void cbAllMethodsActionPerformed (java.awt.event.ActionEvent evt) { if (cbAllMethods.isSelected ()) { 313 tfMethodName.setText (org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "Method_Breakpoint_ALL_METHODS")); 314 tfMethodName.setEnabled (false); 315 } else { 316 tfMethodName.setText (""); 317 tfMethodName.setEnabled (true); 318 } 319 } 321 322 324 329 public boolean ok () { 330 if (! isFilled()) { 331 JOptionPane.showMessageDialog(this, 332 org.openide.util.NbBundle.getMessage(MethodBreakpointPanel.class, "MSG_No_Class_or_Method_Name_Spec")); 333 return false; 334 } 335 actionsPanel.ok (); 336 String className = ((String ) tfPackageName.getText ()).trim (); 337 if (className.length () > 0) 338 className += '.'; 339 className += tfClassName.getText ().trim (); 340 breakpoint.setClassFilters (new String [] {className}); 341 if (!cbAllMethods.isSelected ()) 342 breakpoint.setMethodName (tfMethodName.getText ().trim ()); 343 else 344 breakpoint.setMethodName (""); 345 breakpoint.setCondition (tfCondition.getText ()); 346 int bpType = 0; 347 if (cbStopOnEntry.isSelected()) { 348 bpType |= breakpoint.TYPE_METHOD_ENTRY; 349 } 350 if (cbStopOnExit.isSelected()) { 351 bpType |= breakpoint.TYPE_METHOD_EXIT; 352 } 353 breakpoint.setBreakpointType(bpType); 354 355 if (createBreakpoint) 356 DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint); 357 return true; 358 } 359 360 365 public boolean cancel () { 366 return true; 367 } 368 369 376 public boolean isValid () { 377 return true; 378 } 379 380 boolean isFilled () { 381 if (tfClassName.getText().trim().length() > 0 && 382 (tfMethodName.getText().trim().length() > 0 || 383 cbAllMethods.isSelected())) 384 return true; 385 return false; 386 } 387 388 389 private javax.swing.JCheckBox cbAllMethods; 391 private javax.swing.JCheckBox cbStopOnEntry; 392 private javax.swing.JCheckBox cbStopOnExit; 393 private javax.swing.JLabel jLabel1; 394 private javax.swing.JLabel jLabel2; 395 private javax.swing.JLabel jLabel3; 396 private javax.swing.JLabel jLabel5; 397 private javax.swing.JPanel jPanel1; 398 private javax.swing.JPanel pActions; 399 private javax.swing.JPanel pSettings; 400 private javax.swing.JTextField tfClassName; 401 private javax.swing.JTextField tfCondition; 402 private javax.swing.JTextField tfMethodName; 403 private javax.swing.JTextField tfPackageName; 404 406 } 407 | Popular Tags |