1 19 20 package org.netbeans.modules.debugger.jpda.ui.breakpoints; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import javax.swing.JPanel ; 25 import javax.swing.JOptionPane ; 26 import javax.swing.text.Document ; 27 import javax.swing.text.StyledDocument ; 28 import org.netbeans.api.debugger.DebuggerManager; 29 30 import org.netbeans.api.debugger.jpda.LineBreakpoint; 31 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge; 32 import org.netbeans.modules.debugger.jpda.ui.FilteredKeymap; 33 import org.netbeans.spi.debugger.ui.Controller; 34 35 import java.net.URI ; 36 import org.openide.DialogDisplayer; 37 import org.openide.NotifyDescriptor; 38 import org.openide.cookies.EditorCookie; 39 import org.openide.filesystems.FileObject; 40 import org.openide.filesystems.URLMapper; 41 import org.openide.loaders.DataObject; 42 import org.openide.loaders.DataObjectNotFoundException; 43 import org.openide.text.NbDocument; 44 import org.openide.util.NbBundle; 45 46 51 public class LineBreakpointPanel extends JPanel implements Controller, org.openide.util.HelpCtx.Provider { 56 58 private ActionsPanel actionsPanel; 59 private LineBreakpoint breakpoint; 60 private boolean createBreakpoint = false; 61 62 63 private static LineBreakpoint createBreakpoint () { 64 LineBreakpoint mb = LineBreakpoint.create ( 65 EditorContextBridge.getCurrentURL (), 66 EditorContextBridge.getCurrentLineNumber () 67 ); 68 mb.setPrintText ( 69 NbBundle.getBundle (LineBreakpointPanel.class).getString 70 ("CTL_Line_Breakpoint_Print_Text") 71 ); 72 return mb; 73 } 74 75 76 77 public LineBreakpointPanel () { 78 this (createBreakpoint ()); 79 createBreakpoint = true; 80 } 81 82 83 public LineBreakpointPanel (LineBreakpoint b) { 84 breakpoint = b; 85 initComponents (); 86 87 String url = b.getURL(); 88 try { 89 URI uri = new URI (url); 90 tfFileName.setText(uri.getPath()); 91 } catch (Exception e) { 92 tfFileName.setText(url); 93 } 94 tfLineNumber.setText(Integer.toString(b.getLineNumber())); 95 tfCondition.setText (b.getCondition ()); 96 setupConditionPane(); 97 98 actionsPanel = new ActionsPanel (b); 99 pActions.add (actionsPanel, "Center"); 100 } 101 102 private static int findNumLines(String url) { 103 FileObject file; 104 try { 105 file = URLMapper.findFileObject (new URL (url)); 106 } catch (MalformedURLException e) { 107 return 0; 108 } 109 if (file == null) return 0; 110 DataObject dataObject; 111 try { 112 dataObject = DataObject.find (file); 113 } catch (DataObjectNotFoundException ex) { 114 return 0; 115 } 116 EditorCookie ec = (EditorCookie) dataObject.getCookie(EditorCookie.class); 117 if (ec == null) return 0; 118 ec.prepareDocument().waitFinished(); 119 Document d = ec.getDocument(); 120 if (!(d instanceof StyledDocument )) return 0; 121 StyledDocument sd = (StyledDocument ) d; 122 return NbDocument.findLineNumber(sd, sd.getLength()); 123 } 124 125 private void setupConditionPane() { 126 tfCondition.setKeymap(new FilteredKeymap(tfCondition.getKeymap())); 127 String url = breakpoint.getURL(); 128 DataObject dobj = null; 129 FileObject file; 130 try { 131 file = URLMapper.findFileObject (new URL (url)); 132 if (file != null) { 133 try { 134 dobj = DataObject.find (file); 135 } catch (DataObjectNotFoundException ex) { 136 } 138 } 139 } catch (MalformedURLException e) { 140 } 142 tfCondition.getDocument().putProperty(javax.swing.text.Document.StreamDescriptionProperty, dobj); 143 } 144 145 public org.openide.util.HelpCtx getHelpCtx() { 149 return new org.openide.util.HelpCtx("NetbeansDebuggerBreakpointLineJPDA"); } 151 153 158 private void initComponents() { 160 java.awt.GridBagConstraints gridBagConstraints; 161 162 pSettings = new javax.swing.JPanel (); 163 jLabel3 = new javax.swing.JLabel (); 164 jLabel5 = new javax.swing.JLabel (); 165 tfFileName = new javax.swing.JTextField (); 166 jLabel1 = new javax.swing.JLabel (); 167 tfLineNumber = new javax.swing.JTextField (); 168 spCondition = new javax.swing.JScrollPane (); 169 tfCondition = new javax.swing.JEditorPane (); 170 pActions = new javax.swing.JPanel (); 171 jPanel1 = new javax.swing.JPanel (); 172 173 setLayout(new java.awt.GridBagLayout ()); 174 175 pSettings.setLayout(new java.awt.GridBagLayout ()); 176 177 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_Line_Breakpoint_BorderTitle"))); jLabel3.setLabelFor(tfFileName); 180 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, bundle.getString("L_Line_Breakpoint_File_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 182 gridBagConstraints.gridx = 0; 183 gridBagConstraints.gridy = 1; 184 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 185 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 186 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 187 pSettings.add(jLabel3, gridBagConstraints); 188 jLabel3.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Line_Breakpoint_File_Name")); 190 jLabel5.setLabelFor(tfCondition); 191 org.openide.awt.Mnemonics.setLocalizedText(jLabel5, bundle.getString("L_Line_Breakpoint_Condition")); gridBagConstraints = new java.awt.GridBagConstraints (); 193 gridBagConstraints.gridx = 0; 194 gridBagConstraints.gridy = 5; 195 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 196 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 197 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 198 pSettings.add(jLabel5, gridBagConstraints); 199 jLabel5.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Line_Breakpoint_Condition")); 201 tfFileName.setEditable(false); 202 tfFileName.setToolTipText(bundle.getString("TTT_TF_Line_Breakpoint_File_Name")); gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 1; 205 gridBagConstraints.gridy = 1; 206 gridBagConstraints.gridwidth = 2; 207 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 208 gridBagConstraints.weightx = 1.0; 209 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 210 pSettings.add(tfFileName, gridBagConstraints); 211 tfFileName.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Line_Breakpoint_File_Name")); 213 jLabel1.setLabelFor(tfLineNumber); 214 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, bundle.getString("L_Line_Breakpoint_Line_Number")); gridBagConstraints = new java.awt.GridBagConstraints (); 216 gridBagConstraints.gridx = 0; 217 gridBagConstraints.gridy = 3; 218 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 219 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 220 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 221 pSettings.add(jLabel1, gridBagConstraints); 222 jLabel1.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_L_Line_Breakpoint_Line_Number")); 224 tfLineNumber.setToolTipText(bundle.getString("TTT_TF_Line_Breakpoint_Line_Number")); gridBagConstraints = new java.awt.GridBagConstraints (); 226 gridBagConstraints.gridx = 1; 227 gridBagConstraints.gridy = 3; 228 gridBagConstraints.gridwidth = 2; 229 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 230 gridBagConstraints.weightx = 1.0; 231 gridBagConstraints.insets = new java.awt.Insets (3, 3, 3, 3); 232 pSettings.add(tfLineNumber, gridBagConstraints); 233 tfLineNumber.getAccessibleContext().setAccessibleName("Line number"); 234 tfLineNumber.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_TF_Line_Breakpoint_Line_Number")); 236 spCondition.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); 237 spCondition.setToolTipText(org.openide.util.NbBundle.getMessage(LineBreakpointPanel.class, "ACSD_TF_Line_Breakpoint_Condition")); spCondition.setMinimumSize(spCondition.getPreferredSize()); 239 tfCondition.setContentType("text/x-java"); 240 tfCondition.setToolTipText(org.openide.util.NbBundle.getMessage(LineBreakpointPanel.class, "ACSD_TF_Line_Breakpoint_Condition")); spCondition.setViewportView(tfCondition); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 1; 245 gridBagConstraints.gridy = 5; 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(spCondition, gridBagConstraints); 250 251 gridBagConstraints = new java.awt.GridBagConstraints (); 252 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 253 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 254 gridBagConstraints.weightx = 1.0; 255 add(pSettings, gridBagConstraints); 256 257 pActions.setLayout(new java.awt.BorderLayout ()); 258 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 261 gridBagConstraints.weightx = 1.0; 262 add(pActions, gridBagConstraints); 263 264 gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridx = 0; 266 gridBagConstraints.gridy = 2; 267 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 268 gridBagConstraints.weightx = 1.0; 269 gridBagConstraints.weighty = 1.0; 270 add(jPanel1, gridBagConstraints); 271 272 } 274 275 277 282 public boolean ok () { 283 String msg = valiadateMsg(); 284 if (msg != null) { 285 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(msg)); 286 return false; 287 } 288 actionsPanel.ok (); 289 breakpoint.setLineNumber(Integer.parseInt(tfLineNumber.getText().trim())); 290 breakpoint.setCondition (tfCondition.getText ()); 291 if (createBreakpoint) 292 DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint); 293 return true; 294 } 295 296 301 public boolean cancel () { 302 return true; 303 } 304 305 312 public boolean isValid () { 313 return true; 314 } 315 316 private String valiadateMsg () { 317 try { 318 int line = Integer.parseInt(tfLineNumber.getText().trim()); 319 if (line <= 0) { 320 return NbBundle.getMessage(LineBreakpointPanel.class, "MSG_NonPositive_Line_Number_Spec"); 321 } 322 int maxLine = findNumLines(breakpoint.getURL()); 323 if (maxLine == 0) { maxLine = Integer.MAX_VALUE; } 326 if (line > maxLine) { 327 return NbBundle.getMessage(LineBreakpointPanel.class, "MSG_TooBig_Line_Number_Spec", 328 Integer.toString(line), Integer.toString(maxLine)); 329 } 330 } catch (NumberFormatException e) { 331 return NbBundle.getMessage(LineBreakpointPanel.class, "MSG_No_Line_Number_Spec"); 332 } 333 return null; 334 } 335 336 337 private javax.swing.JLabel jLabel1; 339 private javax.swing.JLabel jLabel3; 340 private javax.swing.JLabel jLabel5; 341 private javax.swing.JPanel jPanel1; 342 private javax.swing.JPanel pActions; 343 private javax.swing.JPanel pSettings; 344 private javax.swing.JScrollPane spCondition; 345 private javax.swing.JEditorPane tfCondition; 346 private javax.swing.JTextField tfFileName; 347 private javax.swing.JTextField tfLineNumber; 348 350 } 351 | Popular Tags |