1 19 20 package org.netbeans.modules.javadoc.comments; 21 22 import java.lang.reflect.Modifier ; 23 import java.util.ResourceBundle ; 24 import javax.swing.*; 25 import javax.swing.event.ListSelectionListener ; 26 import javax.swing.event.ListSelectionEvent ; 27 import java.awt.*; 28 29 import org.openide.ErrorManager; 30 import org.openide.DialogDisplayer; 31 import org.openide.NotifyDescriptor; 32 33 import org.netbeans.modules.javadoc.settings.DocumentationSettings; 34 import org.netbeans.api.javahelp.Help; 35 import org.openide.src.JavaDoc; 36 import org.openide.util.*; 37 38 40 public class AutoCommentPanel 41 extends javax.swing.JPanel 42 implements ListSelectionListener , AutoCommenter.AutoCommentChangeListener { 43 44 AutoCommenter autoCommenter; 45 46 private JavaDocEditorPanel javaDocEditor = new JavaDocEditorPanel(); 47 private boolean resetingAll = false; 48 private boolean updatingBadList = false; 49 50 private final DefaultListModel EMPTY_MODEL = new DefaultListModel(); 51 static final String WAIT_STRING = "WAIT.MODEL"; private final DefaultListModel WAIT_MODEL = new DefaultListModel(); 53 54 private int modifierMask; 55 private int errorMask; 56 57 DocumentationSettings dss = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true)); 58 59 static final long serialVersionUID =1845033305150331568L; 60 61 private Object [] LAST_SELECTION; 62 63 65 public AutoCommentPanel() { 66 WAIT_MODEL.addElement( WAIT_STRING ); 67 initComponents (); 68 69 this.errorListBox.setCellRenderer(new DefaultListCellRenderer() { 71 public Component getListCellRendererComponent( 72 JList list, 73 Object value, 74 int index, 75 boolean isSelected, 76 boolean cellHasFocus) { 77 return super.getListCellRendererComponent(list, value, index, false, false); 78 } 79 80 }); 81 82 javaDocEditor.setEnabled(false); 83 84 ResourceBundle b = org.openide.util.NbBundle.getBundle(AutoCommentPanel.class); 85 defaultButton.setMnemonic( b.getString("CTL_AutoCommentPanel.defaultButton.text_Mnemonic").charAt(0) ); 86 sourceButton.setMnemonic( b.getString("CTL_AutoCommentPanel.sourceButton.text_Mnemonic").charAt(0) ); 87 refreshButton.setMnemonic( b.getString("CTL_AutoCommentPanel.refreshButton.text_Mnemonic").charAt(0) ); 88 helpButton.setMnemonic( b.getString("CTL_AutoCommentPanel.helpButton.text_Mnemonic").charAt(0) ); 89 90 okButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.okButton").charAt(0)); 91 errButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.errButton").charAt(0)); 92 missButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.missButton").charAt(0)); 93 publicButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.publicButton").charAt(0)); 94 packageButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.packageButton").charAt(0)); 95 protectedButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.protectedButton").charAt(0)); 96 privateButton.setMnemonic(b.getString("MNEMO_AutoCommentPanel.privateButton").charAt(0)); 97 98 splittedPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, classInfoPanel, javaDocEditor); 99 splittedPanel.setDividerSize(5); 100 add(splittedPanel); 101 102 okButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/ok.gif"))); errButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/error.gif"))); missButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/missing.gif"))); 106 publicButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/public.gif"))); packageButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/package.gif"))); protectedButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/protected.gif"))); privateButton.setIcon(new ImageIcon(Utilities.loadImage("org/netbeans/modules/javadoc/comments/resources/private.gif"))); 111 resolveButtonState(); 112 113 badList.setCellRenderer( new AutoCommentListCellRenderer() ); 114 badList.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 115 116 elementSelection( new ListSelectionEvent ( badList.getModel(), -1, -1, false ) ); 117 initAccessibility(b); 118 } 119 120 private void initAccessibility(ResourceBundle b) 121 { 122 badList.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.methodListA11yName")); badList.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.methodListA11yDesc")); nameLabel.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.nameLabel.textA11yDesc")); classTextField.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.nameTextField.textA11yName")); errorListBox.getAccessibleContext().setAccessibleName(b.getString("ACS_AutoCommentPanel.commentList.textA11yName")); errorListBox.getAccessibleContext().setAccessibleDescription(b.getString("ACS_AutoCommentPanel.commentList.textA11yDesc")); } 129 130 135 private void initComponents() { 137 java.awt.GridBagConstraints gridBagConstraints; 138 139 classInfoPanel = new javax.swing.JPanel (); 140 filterPanel = new javax.swing.JPanel (); 141 okButton = new javax.swing.JToggleButton (); 142 errButton = new javax.swing.JToggleButton (); 143 missButton = new javax.swing.JToggleButton (); 144 publicButton = new javax.swing.JToggleButton (); 145 packageButton = new javax.swing.JToggleButton (); 146 protectedButton = new javax.swing.JToggleButton (); 147 privateButton = new javax.swing.JToggleButton (); 148 jPanel2 = new javax.swing.JPanel (); 149 jScrollPane1 = new javax.swing.JScrollPane (); 150 badList = new javax.swing.JList (); 151 buttonPanel = new javax.swing.JPanel (); 152 defaultButton = new javax.swing.JButton (); 153 sourceButton = new javax.swing.JButton (); 154 refreshButton = new javax.swing.JButton (); 155 helpButton = new javax.swing.JButton (); 156 jPanel3 = new javax.swing.JPanel (); 157 detailsPanel = new javax.swing.JPanel (); 158 nameLabel = new javax.swing.JLabel (); 159 classTextField = new javax.swing.JTextField (); 160 jScrollPane2 = new javax.swing.JScrollPane (); 161 errorListBox = new javax.swing.JList (); 162 163 FormListener formListener = new FormListener(); 164 165 setLayout(new java.awt.BorderLayout ()); 166 167 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (0, 0, 0, 0))); 168 classInfoPanel.setLayout(new java.awt.GridBagLayout ()); 169 170 classInfoPanel.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (6, 6, 5, 5))); 171 classInfoPanel.setName("classInfoPanel"); 172 filterPanel.setLayout(new java.awt.GridBagLayout ()); 173 174 okButton.setSelected(true); 175 okButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.okButton.toolTipText")); 176 okButton.setActionCommand("ALL"); 177 okButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 178 okButton.addActionListener(formListener); 179 180 filterPanel.add(okButton, new java.awt.GridBagConstraints ()); 181 182 errButton.setSelected(true); 183 errButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.errButton.toolTipText")); 184 errButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 185 errButton.addActionListener(formListener); 186 187 filterPanel.add(errButton, new java.awt.GridBagConstraints ()); 188 189 missButton.setSelected(true); 190 missButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.missButton.toolTipText")); 191 missButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 192 missButton.addActionListener(formListener); 193 194 gridBagConstraints = new java.awt.GridBagConstraints (); 195 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 6); 196 filterPanel.add(missButton, gridBagConstraints); 197 198 publicButton.setSelected(true); 199 publicButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.publicButton.toolTipText")); 200 publicButton.setActionCommand("PUBLIC"); 201 publicButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 202 publicButton.addActionListener(formListener); 203 204 filterPanel.add(publicButton, new java.awt.GridBagConstraints ()); 205 206 packageButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.packageButton.toolTipText")); 207 packageButton.setActionCommand("PACKAGE"); 208 packageButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 209 packageButton.addActionListener(formListener); 210 211 filterPanel.add(packageButton, new java.awt.GridBagConstraints ()); 212 213 protectedButton.setSelected(true); 214 protectedButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.protectedButton.toolTipText")); 215 protectedButton.setActionCommand("PROTECTED"); 216 protectedButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 217 protectedButton.addActionListener(formListener); 218 219 filterPanel.add(protectedButton, new java.awt.GridBagConstraints ()); 220 221 privateButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.privateButton.toolTipText")); 222 privateButton.setActionCommand("PRIVATE"); 223 privateButton.setMargin(new java.awt.Insets (2, 2, 2, 2)); 224 privateButton.addActionListener(formListener); 225 226 filterPanel.add(privateButton, new java.awt.GridBagConstraints ()); 227 228 gridBagConstraints = new java.awt.GridBagConstraints (); 229 gridBagConstraints.weightx = 1.0; 230 filterPanel.add(jPanel2, gridBagConstraints); 231 232 gridBagConstraints = new java.awt.GridBagConstraints (); 233 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 234 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 6); 237 classInfoPanel.add(filterPanel, gridBagConstraints); 238 239 badList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 240 badList.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.methodListA11yDesc")); 241 jScrollPane1.setViewportView(badList); 242 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 245 gridBagConstraints.weightx = 0.6; 246 gridBagConstraints.weighty = 1.0; 247 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 0); 248 classInfoPanel.add(jScrollPane1, gridBagConstraints); 249 250 buttonPanel.setLayout(new java.awt.GridBagLayout ()); 251 252 buttonPanel.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (0, 5, 0, 0))); 253 defaultButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.defaultButton.text")); 254 defaultButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.defaultButton.textA11yDesc")); 255 defaultButton.setActionCommand("Default Comment"); 256 defaultButton.setMargin(new java.awt.Insets (2, 4, 2, 4)); 257 defaultButton.addActionListener(formListener); 258 259 gridBagConstraints = new java.awt.GridBagConstraints (); 260 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 261 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 262 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 263 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 264 buttonPanel.add(defaultButton, gridBagConstraints); 265 266 sourceButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.sourceButton.text")); 267 sourceButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.sourceButton.textA11yDesc")); 268 sourceButton.setMargin(new java.awt.Insets (2, 4, 2, 4)); 269 sourceButton.addActionListener(formListener); 270 271 gridBagConstraints = new java.awt.GridBagConstraints (); 272 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 273 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 274 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 275 buttonPanel.add(sourceButton, gridBagConstraints); 276 277 refreshButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutoCommentPanel.refreshButton.text")); 278 refreshButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.refreshButton.textA11yDesc")); 279 refreshButton.setMargin(new java.awt.Insets (2, 4, 2, 4)); 280 refreshButton.addActionListener(formListener); 281 282 gridBagConstraints = new java.awt.GridBagConstraints (); 283 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 284 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 285 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 286 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 287 buttonPanel.add(refreshButton, gridBagConstraints); 288 289 helpButton.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.text")); 290 helpButton.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("CTL_AutocommentPanel.helpButton.tooltipText")); 291 helpButton.addActionListener(formListener); 292 293 gridBagConstraints = new java.awt.GridBagConstraints (); 294 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 295 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 296 gridBagConstraints.insets = new java.awt.Insets (11, 0, 0, 0); 297 buttonPanel.add(helpButton, gridBagConstraints); 298 299 gridBagConstraints = new java.awt.GridBagConstraints (); 300 gridBagConstraints.weighty = 1.0; 301 buttonPanel.add(jPanel3, gridBagConstraints); 302 303 gridBagConstraints = new java.awt.GridBagConstraints (); 304 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 305 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 306 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 307 gridBagConstraints.weighty = 0.6; 308 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 6); 309 classInfoPanel.add(buttonPanel, gridBagConstraints); 310 311 detailsPanel.setLayout(new java.awt.GridBagLayout ()); 312 313 nameLabel.setLabelFor(classTextField); 314 nameLabel.setText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("AutoCommentPanel.nameLabel.text")); 315 gridBagConstraints = new java.awt.GridBagConstraints (); 316 gridBagConstraints.gridx = 0; 317 gridBagConstraints.gridy = 0; 318 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 319 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 320 gridBagConstraints.insets = new java.awt.Insets (12, 0, 11, 0); 321 detailsPanel.add(nameLabel, gridBagConstraints); 322 323 classTextField.setEditable(false); 324 classTextField.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.nameTextField.textA11yDesc")); 325 gridBagConstraints = new java.awt.GridBagConstraints (); 326 gridBagConstraints.gridx = 1; 327 gridBagConstraints.gridy = 0; 328 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 329 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 330 gridBagConstraints.weightx = 1.0; 331 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 0); 332 detailsPanel.add(classTextField, gridBagConstraints); 333 334 errorListBox.setToolTipText(org.openide.util.NbBundle.getBundle(AutoCommentPanel.class).getString("ACS_AutoCommentPanel.commentList.textA11yDesc")); 335 jScrollPane2.setViewportView(errorListBox); 336 337 gridBagConstraints = new java.awt.GridBagConstraints (); 338 gridBagConstraints.gridx = 0; 339 gridBagConstraints.gridy = 1; 340 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 341 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 342 gridBagConstraints.weightx = 1.0; 343 gridBagConstraints.weighty = 1.0; 344 detailsPanel.add(jScrollPane2, gridBagConstraints); 345 346 gridBagConstraints = new java.awt.GridBagConstraints (); 347 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 348 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 349 gridBagConstraints.weightx = 1.0; 350 gridBagConstraints.weighty = 0.4; 351 gridBagConstraints.insets = new java.awt.Insets (0, 5, 5, 6); 352 classInfoPanel.add(detailsPanel, gridBagConstraints); 353 354 add(classInfoPanel, java.awt.BorderLayout.CENTER); 355 356 } 357 358 360 private class FormListener implements java.awt.event.ActionListener { 361 public void actionPerformed(java.awt.event.ActionEvent evt) { 362 if (evt.getSource() == okButton) { 363 AutoCommentPanel.this.okButtonActionPerformed(evt); 364 } 365 else if (evt.getSource() == errButton) { 366 AutoCommentPanel.this.errButtonActionPerformed(evt); 367 } 368 else if (evt.getSource() == missButton) { 369 AutoCommentPanel.this.missButtonActionPerformed(evt); 370 } 371 else if (evt.getSource() == publicButton) { 372 AutoCommentPanel.this.publicButtonActionPerformed(evt); 373 } 374 else if (evt.getSource() == packageButton) { 375 AutoCommentPanel.this.packageButtonActionPerformed(evt); 376 } 377 else if (evt.getSource() == protectedButton) { 378 AutoCommentPanel.this.protectedButtonActionPerformed(evt); 379 } 380 else if (evt.getSource() == privateButton) { 381 AutoCommentPanel.this.privateButtonActionPerformed(evt); 382 } 383 else if (evt.getSource() == defaultButton) { 384 AutoCommentPanel.this.defaultButtonActionPerformed(evt); 385 } 386 else if (evt.getSource() == sourceButton) { 387 AutoCommentPanel.this.sourceButtonActionPerformed(evt); 388 } 389 else if (evt.getSource() == refreshButton) { 390 AutoCommentPanel.this.refreshButtonActionPerformed(evt); 391 } 392 else if (evt.getSource() == helpButton) { 393 AutoCommentPanel.this.helpButtonActionPerformed(evt); 394 } 395 } 396 } 397 399 private void helpButtonActionPerformed(java.awt.event.ActionEvent evt) { Help help=(Help)Lookup.getDefault().lookup(Help.class); 401 402 help.showHelp( 403 new org.openide.util.HelpCtx(AutoCommentTopComponent.AUTO_COMMENT_HELP_CTX_KEY)); 404 } 406 private void missButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 408 } 410 private void errButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 412 } 414 private void okButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 416 } 418 private void refreshButtonActionPerformed (java.awt.event.ActionEvent evt) { resetingAll = true; 420 updateForClosing(); 421 resetState(); 422 } 424 425 private void privateButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 427 } 429 private void protectedButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 431 } 433 private void packageButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 435 } 437 private void publicButtonActionPerformed (java.awt.event.ActionEvent evt) { refreshState(); 439 } 441 442 private void defaultButtonActionPerformed (java.awt.event.ActionEvent evt) { int sel = badList.getMinSelectionIndex(); 444 445 if ( sel == -1 ) 446 return; 447 448 AutoCommenter.Element[] elements = getSelectedElements(); 449 if (elements.length == 1) { 450 JavaDoc doc = null; 451 javaDocEditor.commitTagChange(); 452 if (javaDocEditor.isDirty()) { 453 doc = javaDocEditor.getUpdatedJavaDoc(); 454 } 455 this.autoCommenter.autoCorrectJavadoc(elements[0], doc); 456 } else { 457 this.autoCommenter.autoCorrectJavadoc(elements); 458 } 459 } 461 private void sourceButtonActionPerformed (java.awt.event.ActionEvent evt) { int sel = badList.getMinSelectionIndex(); 463 464 if ( sel == -1 || !badList.isEnabled()) 465 return; 466 467 final AutoCommenter.Element element = (AutoCommenter.Element) badList.getModel().getElementAt( sel ); 468 if (element.isValid()) { 469 element.viewSource(); 470 } 471 472 } 474 475 private javax.swing.JList badList; 477 private javax.swing.JPanel buttonPanel; 478 private javax.swing.JPanel classInfoPanel; 479 private javax.swing.JTextField classTextField; 480 private javax.swing.JButton defaultButton; 481 private javax.swing.JPanel detailsPanel; 482 private javax.swing.JToggleButton errButton; 483 private javax.swing.JList errorListBox; 484 private javax.swing.JPanel filterPanel; 485 private javax.swing.JButton helpButton; 486 private javax.swing.JPanel jPanel2; 487 private javax.swing.JPanel jPanel3; 488 private javax.swing.JScrollPane jScrollPane1; 489 private javax.swing.JScrollPane jScrollPane2; 490 private javax.swing.JToggleButton missButton; 491 private javax.swing.JLabel nameLabel; 492 private javax.swing.JToggleButton okButton; 493 private javax.swing.JToggleButton packageButton; 494 private javax.swing.JToggleButton privateButton; 495 private javax.swing.JToggleButton protectedButton; 496 private javax.swing.JToggleButton publicButton; 497 private javax.swing.JButton refreshButton; 498 private javax.swing.JButton sourceButton; 499 private JSplitPane splittedPanel; 501 502 public void updateForClosing() { 503 int sel = badList.getMinSelectionIndex(); 504 boolean isNotMultiselect = sel == badList.getMaxSelectionIndex(); 505 if (sel >= 0 && isNotMultiselect) { 506 if( !(badList.getModel().getElementAt( 0 ) instanceof AutoCommenter.Element) ) 507 return; 508 javaDocEditor.updateForClosing(); 509 AutoCommenter.Element el = (AutoCommenter.Element) badList.getModel().getElementAt(sel); 510 if (el.isValid() && badList.isEnabled()) { 511 modifyJavaDoc(el); 512 } 513 } 514 } 515 516 private void showCommentEditor( final AutoCommenter.Element el ) { 517 javaDocEditor.setElement(el); 518 javaDocEditor.setJavaDoc(el.getJavaDoc()); 519 } 520 521 private void modifyJavaDoc(final AutoCommenter.Element el) { 522 javaDocEditor.commitTagChange(); 523 if (! javaDocEditor.isDirty()) { 524 return; 525 } 526 this.autoCommenter.modifyJavadoc(el, javaDocEditor.getUpdatedJavaDoc()); 527 javaDocEditor.setDirty(false); 528 } 529 530 private void elementSelection( ListSelectionEvent evt ) { 531 if (updatingBadList || (evt != null && evt.getValueIsAdjusting())) { 534 return; 535 } 536 537 int sel = badList.getMinSelectionIndex(); 538 boolean isMultiselect = sel != badList.getMaxSelectionIndex(); 539 ListModel badModel = badList.getModel(); 540 541 if (LAST_SELECTION != null && LAST_SELECTION.length == 1) { 544 if(!(badModel.getElementAt(0) instanceof AutoCommenter.Element)) 547 return; 548 549 AutoCommenter.Element element = (AutoCommenter.Element) findLastObject(); 550 if (element != null && element.isValid() && badList.isEnabled()) { 551 modifyJavaDoc(element); 552 } else { 553 badList.setEnabled(false); 554 DialogDisplayer.getDefault().notify( 555 new NotifyDescriptor.Message( 556 NbBundle.getMessage(AutoCommentPanel.class, "MSG_IvalidSource"), 557 NotifyDescriptor.WARNING_MESSAGE)); 558 return; 559 } 560 } 561 562 if ( sel < 0 ) { 563 LAST_SELECTION = null; 564 errorListBox.setModel(EMPTY_MODEL); 565 defaultButton.setEnabled( false ); 566 sourceButton.setEnabled( false ); 567 classTextField.setText( "" ); javaDocEditor.clear(); 569 javaDocEditor.setEnabled(false); 570 } else if (isMultiselect) { 571 LAST_SELECTION = badList.getSelectedValues(); 572 errorListBox.setModel(EMPTY_MODEL); 573 sourceButton.setEnabled(false); 574 classTextField.setText(""); javaDocEditor.clear(); 576 javaDocEditor.setEnabled(false); 577 boolean canCorrect = isCorrectable(getSelectedElements()); 578 defaultButton.setEnabled(canCorrect); 579 } else { 580 if( !(badModel.getElementAt(0) instanceof AutoCommenter.Element) ) { 582 LAST_SELECTION = null; 583 return; 584 } 585 LAST_SELECTION = badList.getSelectedValues(); 586 587 AutoCommenter.Element element = (AutoCommenter.Element) LAST_SELECTION[0]; 588 String dcName = element.getDescriptor().getDeclaringClassName(); 589 if (dcName == null) { 590 dcName = element.getDescriptor().getName(); 591 } 592 classTextField.setText(dcName); 593 594 defaultButton.setEnabled( element.isCorrectable() ); 595 sourceButton.setEnabled( true ); 596 javaDocEditor.setEnabled( true ); 597 598 errorListBox.setModel( element.getErrorList() ); 599 showCommentEditor(element); 600 } 601 } 602 603 606 private AutoCommenter.Element[] getSelectedElements() { 607 if(!(badList.getModel().getElementAt(0) instanceof AutoCommenter.Element)) { 608 return new AutoCommenter.Element[0]; 609 } 610 Object [] objs = badList.getSelectedValues(); 611 AutoCommenter.Element[] els = new AutoCommenter.Element[objs.length]; 612 for (int i = 0; i < objs.length; i++) { 613 els[i] = (AutoCommenter.Element) objs[i]; 614 } 615 return els; 616 } 617 618 619 private static boolean isCorrectable(AutoCommenter.Element[] els) { 620 assert els != null; 621 for (int i = 0; i < els.length; i++) { 622 if (!els[i].isCorrectable() || !els[i].isValid()) { 623 return false; 624 } 625 } 626 return els.length > 0; 627 } 628 629 void setAutoCommenter( AutoCommenter autoCommenter ) { 630 if (this.autoCommenter != null) { 631 this.autoCommenter.removeAutoCommentChangeListener(this); 632 } 633 this.autoCommenter = autoCommenter; 634 if (this.autoCommenter != null) { 635 resolveMask(); 636 activate(); 637 } else { 638 this.LAST_SELECTION = null; 639 } 640 } 641 642 645 public void activate() { 646 if (this.autoCommenter == null) return; 647 try{ 648 this.autoCommenter.addAutoCommentChangeListener(this); 649 resetState(); 650 } catch(java.util.TooManyListenersException tooEx){ 651 ErrorManager.getDefault().notify(tooEx); 652 } 653 } 654 655 658 public void deactivate() { 659 if (this.autoCommenter == null) return; 660 this.autoCommenter.removeAutoCommentChangeListener(this); 661 updateForClosing(); 662 } 663 664 private void resetState() { 665 if (this.autoCommenter == null) return; 666 resetingAll = true; 667 badList.getSelectionModel().removeListSelectionListener(this); 668 badList.setModel( WAIT_MODEL ); 669 autoCommenter.refreshFromSource(); 670 } 671 672 private void resolveMask() { 673 modifierMask = 0; 674 errorMask = 0; 675 676 if ( publicButton.isSelected() ) 677 modifierMask |= Modifier.PUBLIC; 678 if ( protectedButton.isSelected() ) 679 modifierMask |= Modifier.PROTECTED; 680 if ( privateButton.isSelected() ) 681 modifierMask |= Modifier.PRIVATE; 682 683 if ( okButton.isSelected() ) 684 errorMask |= AutoCommenter.JDC_OK; 685 if ( errButton.isSelected() ) 686 errorMask |= AutoCommenter.JDC_ERROR; 687 if ( missButton.isSelected() ) 688 errorMask |= AutoCommenter.JDC_MISSING; 689 690 DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true)); 691 692 ds.setAutocommentModifierMask( modifierMask ); 693 ds.setAutocommentPackage( packageButton.isSelected() ); 694 ds.setAutocommentErrorMask( errorMask ); 695 696 697 } 698 699 private void refreshState(){ 700 resolveMask(); 701 resetState(); 702 } 703 704 private void replaceModel(ListModel lm) { 705 updatingBadList = true; 706 resetingAll = false; 707 ListSelectionModel lsm = badList.getSelectionModel(); 708 lsm.removeListSelectionListener(this); 709 badList.setEnabled(true); 710 badList.setModel(lm); 711 lsm.addListSelectionListener(this); 712 713 errorListBox.setModel( EMPTY_MODEL ); 714 updatingBadList = false; 715 716 int[] lasts = findIndicies(lm, LAST_SELECTION); 717 LAST_SELECTION = null; 718 if (lasts != null && lasts.length > 0) { 719 badList.setSelectedIndices(lasts); 720 } else { 721 elementSelection(new ListSelectionEvent (lm, -1, -1, false)); 722 } 723 } 724 725 731 private static int[] findIndicies(ListModel lm, Object [] items) { 732 int[] indecies = null; 733 if (items != null) { 734 indecies = new int[items.length]; 735 int count = 0; 736 for (int i = 0; i < lm.getSize(); i++) { 737 Object el = lm.getElementAt(i); 738 for (int j = 0; j < items.length; j++) { 739 Object last = items[j]; 740 if (last.equals(el)) { 741 indecies[count++] = i; 742 break; 743 } 744 } 745 } 746 747 if (count != items.length) { 748 int[] temp = indecies; 749 indecies = new int[count]; 750 for (int i = 0; i < indecies.length; i++) { 751 indecies[i] = temp[i]; 752 } 753 } 754 } 755 return indecies; 756 } 757 758 private Object findLastObject() { 759 ListModel lm = badList.getModel(); 760 if (LAST_SELECTION != null && LAST_SELECTION.length == 1) { 761 for (int i = 0; i < lm.getSize(); i++) { 762 Object el = lm.getElementAt(i); 763 if (LAST_SELECTION[0].equals(el)) { 764 return el; 765 } 766 } 767 } 768 return null; 769 } 770 771 773 public void resolveButtonState() { 774 775 DocumentationSettings ds = ((DocumentationSettings)SharedClassObject.findObject(DocumentationSettings.class, true)); 776 777 final int modifierMask = ds.getAutocommentModifierMask(); 778 final boolean pckg = ds.getAutocommentPackage(); 779 final int errorMask = ds.getAutocommentErrorMask(); 780 781 publicButton.setSelected( (modifierMask & Modifier.PUBLIC) != 0 ); 782 protectedButton.setSelected( (modifierMask & Modifier.PROTECTED) != 0 ); 783 privateButton.setSelected( (modifierMask & Modifier.PRIVATE) != 0 ); 784 packageButton.setSelected( pckg ); 785 786 okButton.setSelected( ( errorMask & AutoCommenter.JDC_OK ) != 0 ); 787 errButton.setSelected( ( errorMask & AutoCommenter.JDC_ERROR ) != 0 ); 788 missButton.setSelected( ( errorMask & AutoCommenter.JDC_MISSING) != 0 ); 789 } 790 791 792 795 public void valueChanged(final ListSelectionEvent evt) { 796 elementSelection( evt ); 797 } 798 799 public void listChanged() { 801 final ListModel lm = autoCommenter.prepareListModel(modifierMask, packageButton.isSelected(), errorMask); 802 EventQueue.invokeLater(new Runnable () { 803 public void run() { 804 replaceModel(lm); 805 } 806 }); 807 } 808 809 public void elementUpdated(final AutoCommenter.Element el) { 810 if (resetingAll) return; 811 EventQueue.invokeLater(new Runnable () { 812 public void run() { 813 DefaultListModel badModel = (DefaultListModel) badList.getModel(); 814 int index = badModel.indexOf(el); 815 if (index < 0) return; 816 817 boolean reselect = false; 818 int sel = badList.getSelectedIndex(); 819 try { 820 updatingBadList = true; 821 if (AutoCommenter.acceptElement(el, modifierMask, packageButton.isSelected(), errorMask)) { 822 badModel.setElementAt(el, index); 823 } else { 824 reselect = true; 825 badModel.removeElement(el); 826 } 827 } finally { 828 updatingBadList = false; 829 } 830 if (reselect && sel == index) { 831 int size = badModel.getSize(); 833 LAST_SELECTION = null; 834 if (size == 0) { 835 elementSelection(new ListSelectionEvent (badModel, -1, -1, false)); 836 } else { 837 sel = (sel >= size)? size - 1: sel; 838 badList.setSelectedIndex(sel); 839 } 840 } else if (!reselect && sel == index) { 841 LAST_SELECTION = null; 843 elementSelection(new ListSelectionEvent (badModel, sel, sel, false)); 844 } 845 } 846 }); 847 } 848 849 850 } 851 | Popular Tags |