1 19 20 package org.netbeans.modules.javadoc.comments; 21 22 import java.awt.CardLayout ; 23 import java.awt.event.KeyEvent ; 24 import java.awt.event.InputEvent ; 25 import javax.swing.DefaultListModel ; 26 import javax.swing.event.DocumentEvent ; 27 import javax.swing.event.DocumentListener ; 28 import javax.swing.event.ListDataEvent ; 29 import javax.swing.event.ListDataListener ; 30 import javax.jmi.reflect.InvalidObjectException; 31 32 import org.openide.src.JavaDoc; 33 import org.openide.src.JavaDocTag; 34 import org.openide.src.JavaDocSupport; 35 import org.openide.src.SourceException; 36 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; 37 import org.openide.util.NbBundle; 38 import org.openide.DialogDescriptor; 39 import org.openide.ErrorManager; 40 import org.openide.text.CloneableEditorSupport; 41 42 46 public class JavaDocEditorPanel extends javax.swing.JPanel 47 implements EnhancedCustomPropertyEditor { 48 49 private JavaDoc javaDoc; 50 private DefaultListModel listModel; 51 private int lastSelection = -1; 52 53 54 private EmptyTagPanel emptyTagPanel; 55 private StandardTagPanel standardTagPanel; 56 private SeeTagPanel seeTagPanel; 57 private ParamTagPanel paramTagPanel; 58 private ThrowsTagPanel throwsTagPanel; 59 private SerialFieldTagPanel serialFieldTagPanel; 60 61 private NewTagDialog newTagDialog; 62 63 private AutoCommenter.Element element; 64 65 private MnemonicsDistributor mnemonicsDistributor; 66 67 static final long serialVersionUID =7005703844831686911L; 68 69 private boolean dirty; 70 private boolean updatingTagList; 71 private boolean grabFocusAfterNewButton = false; 72 73 75 public JavaDocEditorPanel() { 76 initComponents (); 77 78 newButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.newButton_Mnemonic").charAt(0) ); deleteButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.deleteButton_Mnemonic").charAt(0) ); moveUpButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveUpButton_Mnemonic").charAt(0) ); moveDownButton.setMnemonic( org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveDownButton_Mnemonic").charAt(0) ); boldButton.setMnemonic( NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.boldButton").charAt(0)); 84 italicButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.italicButton").charAt(0)); 85 underlineButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.underlineButton").charAt(0)); 86 codeButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.codeButton").charAt(0)); 87 preButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.preButton").charAt(0)); 88 linkButton.setMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.linkButton").charAt(0)); 89 90 commentLabel.setDisplayedMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.textPane").charAt(0)); 91 tagListLabel.setDisplayedMnemonic(NbBundle.getBundle(JavaDocEditorPanel.class).getString("MNEMO_JavaDocEditorPanel.tagPanel").charAt(0)); 92 93 enableButtons( false ); 94 95 mnemonicsDistributor = new MnemonicsDistributor(); 96 97 commentTextArea.getDocument().addDocumentListener( 98 new DocumentListener () { 99 public void changedUpdate( DocumentEvent evt) { 100 dirty = true; 101 } 102 public void insertUpdate( DocumentEvent evt) { 103 dirty = true; 104 } 105 public void removeUpdate( DocumentEvent evt) { 106 dirty = true; 107 } 108 } ); 109 mnemonicsDistributor.registerComponent( commentTextArea ); 110 111 112 113 115 tagList.setVisibleRowCount(4); 116 tagList.getSelectionModel().setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION ); 117 118 120 122 emptyTagPanel = new EmptyTagPanel( this ); 123 tagParamPanel.add( emptyTagPanel, emptyTagPanel.getCardName() ); 124 125 standardTagPanel = new StandardTagPanel( this ); 126 tagParamPanel.add( standardTagPanel, standardTagPanel.getCardName() ); 127 128 seeTagPanel = new SeeTagPanel( this ); 129 tagParamPanel.add( seeTagPanel, seeTagPanel.getCardName() ); 130 131 132 paramTagPanel = new ParamTagPanel( this ); 133 tagParamPanel.add( paramTagPanel, paramTagPanel.getCardName() ); 134 135 throwsTagPanel = new ThrowsTagPanel( this ); 136 tagParamPanel.add( throwsTagPanel, throwsTagPanel.getCardName() ); 137 138 serialFieldTagPanel = new SerialFieldTagPanel( this ); 139 tagParamPanel.add( serialFieldTagPanel, serialFieldTagPanel.getCardName() ); 140 141 initAccessibility(); 142 } 143 144 146 public JavaDocEditorPanel(AutoCommenter.Element element, JavaDoc doc) { 147 this(); 148 setElement(element); 149 setJavaDoc(doc); 150 } 151 152 154 public void clear() { 155 commentTextArea.setText(""); newButton.setEnabled(false); 157 setTagListModel(); 158 } 159 160 public void setEnabled(boolean enable) { 161 super.setEnabled(enable); 162 tagList.setEnabled(enable); 163 commentTextArea.setEnabled(enable); 164 newButton.setEnabled(enable); 165 } 166 167 public void updateForClosing() { 168 commitTagChange(); 169 } 170 171 private void setTagListModel() { 172 lastSelection = -1; 173 listModel = new DefaultListModel (); 174 tagList.setModel( listModel ); 175 deleteButton.setEnabled(false); 176 moveUpButton.setEnabled(false); 177 moveDownButton.setEnabled(false); 178 listModel.addListDataListener( 179 new ListDataListener () { 180 public void intervalAdded(ListDataEvent e) { 181 dirty = true; 182 } 183 public void intervalRemoved(ListDataEvent e) { 184 dirty = true; 185 } 186 public void contentsChanged(ListDataEvent e) { 187 dirty = true; 188 } 189 } ); 190 } 191 192 public void setJavaDoc(JavaDoc javaDoc) { 193 this.javaDoc = javaDoc; 194 195 if ( javaDoc != null ) { 196 this.javaDoc = javaDoc; 197 commentTextArea.setText( javaDoc.getText() ); 198 commentTextArea.setCaretPosition(0); 199 } else { 200 commentTextArea.setText( null ); 201 } 202 203 205 setTagListModel(); 206 207 if ( javaDoc != null ) { 208 JavaDocTag tags[] = javaDoc.getTags(); 209 for( int i = 0; i < tags.length; i++ ) { 210 listModel.addElement( tags[i] ); 211 } 212 213 if ( listModel.getSize() < 0 ) { 214 tagList.setSelectedIndex( 0 ); 215 } 216 } 217 218 220 try { 221 standardTagPanel.setElement(element.getSrcElement()); 222 paramTagPanel.setElement(element.getSrcElement()); 223 throwsTagPanel.setElement(element.getSrcElement()); 224 } catch (InvalidObjectException e) { 225 } 227 228 setDirty(false); 229 230 revalidate(); 231 repaint(); 232 } 233 234 public void setElement(AutoCommenter.Element element) { 235 this.element = element; 236 } 237 238 public AutoCommenter.Element getElement() { 239 return this.element; 240 } 241 242 private void initAccessibility() 243 { 244 commentTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.commentTextAreaA11yName")); tagList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.tagListA11yName")); } 247 248 253 private void initComponents() { 255 java.awt.GridBagConstraints gridBagConstraints; 256 257 textPanel = new javax.swing.JPanel (); 258 commentScrollPane = new javax.swing.JScrollPane (); 259 commentTextArea = new javax.swing.JEditorPane (); commentTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html")); 260 tagPanel = new javax.swing.JPanel (); 261 newButton = new javax.swing.JButton (); 262 deleteButton = new javax.swing.JButton (); 263 moveUpButton = new javax.swing.JButton (); 264 moveDownButton = new javax.swing.JButton (); 265 tagScrollPane = new javax.swing.JScrollPane (); 266 tagList = new javax.swing.JList (); 267 tagParamPanel = new javax.swing.JPanel (); 268 tagListLabel = new javax.swing.JLabel (); 269 htmlToolBar = new javax.swing.JPanel (); 270 boldButton = new javax.swing.JButton (); 271 italicButton = new javax.swing.JButton (); 272 underlineButton = new javax.swing.JButton (); 273 codeButton = new javax.swing.JButton (); 274 preButton = new javax.swing.JButton (); 275 linkButton = new javax.swing.JButton (); 276 commentLabel = new javax.swing.JLabel (); 277 278 FormListener formListener = new FormListener(); 279 280 setLayout(new java.awt.GridBagLayout ()); 281 282 setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 0)); 283 textPanel.setLayout(new java.awt.GridBagLayout ()); 284 285 commentScrollPane.setMinimumSize(new java.awt.Dimension (22, 60)); 286 commentTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.commentTextAreaA11yDesc")); 287 commentTextArea.addFocusListener(formListener); 288 289 commentScrollPane.setViewportView(commentTextArea); 290 291 gridBagConstraints = new java.awt.GridBagConstraints (); 292 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 293 gridBagConstraints.weightx = 1.0; 294 gridBagConstraints.weighty = 1.0; 295 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 296 textPanel.add(commentScrollPane, gridBagConstraints); 297 298 gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.gridx = 0; 300 gridBagConstraints.gridy = 1; 301 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 302 gridBagConstraints.weighty = 1.0; 303 gridBagConstraints.insets = new java.awt.Insets (0, 3, 5, 7); 304 add(textPanel, gridBagConstraints); 305 306 tagPanel.setLayout(new java.awt.GridBagLayout ()); 307 308 newButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.newButton.text")); 309 newButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.newButton.textA11yDesc")); 310 newButton.setMargin(new java.awt.Insets (2, 12, 2, 12)); 311 newButton.addActionListener(formListener); 312 313 gridBagConstraints = new java.awt.GridBagConstraints (); 314 gridBagConstraints.gridx = 1; 315 gridBagConstraints.gridy = 2; 316 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 317 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 318 tagPanel.add(newButton, gridBagConstraints); 319 320 deleteButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.deleteButton.text")); 321 deleteButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.deleteButton.textA11yDesc")); 322 deleteButton.setMargin(new java.awt.Insets (2, 12, 2, 12)); 323 deleteButton.setEnabled(false); 324 deleteButton.addActionListener(formListener); 325 326 gridBagConstraints = new java.awt.GridBagConstraints (); 327 gridBagConstraints.gridx = 1; 328 gridBagConstraints.gridy = 3; 329 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 330 tagPanel.add(deleteButton, gridBagConstraints); 331 332 moveUpButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveUpButton.text")); 333 moveUpButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.moveUpButton.textA11yDesc")); 334 moveUpButton.setActionCommand("UP"); 335 moveUpButton.setMargin(new java.awt.Insets (2, 12, 2, 12)); 336 moveUpButton.setEnabled(false); 337 moveUpButton.addActionListener(formListener); 338 339 gridBagConstraints = new java.awt.GridBagConstraints (); 340 gridBagConstraints.gridx = 1; 341 gridBagConstraints.gridy = 4; 342 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 343 gridBagConstraints.insets = new java.awt.Insets (12, 0, 5, 0); 344 tagPanel.add(moveUpButton, gridBagConstraints); 345 346 moveDownButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.moveDownButton.text")); 347 moveDownButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.moveDownButton.textA11yDesc")); 348 moveDownButton.setActionCommand("DOWN"); 349 moveDownButton.setMargin(new java.awt.Insets (2, 12, 2, 12)); 350 moveDownButton.setEnabled(false); 351 moveDownButton.addActionListener(formListener); 352 353 gridBagConstraints = new java.awt.GridBagConstraints (); 354 gridBagConstraints.gridx = 1; 355 gridBagConstraints.gridy = 5; 356 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 357 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 0); 358 tagPanel.add(moveDownButton, gridBagConstraints); 359 360 tagList.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.tagListA11yDesc")); 361 tagList.addListSelectionListener(formListener); 362 363 tagScrollPane.setViewportView(tagList); 364 365 gridBagConstraints = new java.awt.GridBagConstraints (); 366 gridBagConstraints.gridx = 0; 367 gridBagConstraints.gridy = 1; 368 gridBagConstraints.gridheight = 5; 369 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 370 gridBagConstraints.weightx = 1.0; 371 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 372 tagPanel.add(tagScrollPane, gridBagConstraints); 373 374 tagParamPanel.setLayout(new java.awt.CardLayout ()); 375 376 gridBagConstraints = new java.awt.GridBagConstraints (); 377 gridBagConstraints.gridx = 0; 378 gridBagConstraints.gridy = 6; 379 gridBagConstraints.gridwidth = 2; 380 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 381 gridBagConstraints.weightx = 1.0; 382 gridBagConstraints.weighty = 1.0; 383 gridBagConstraints.insets = new java.awt.Insets (0, 6, 0, 5); 384 tagPanel.add(tagParamPanel, gridBagConstraints); 385 386 tagListLabel.setLabelFor(tagList); 387 tagListLabel.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.tagPanel.title")); 388 gridBagConstraints = new java.awt.GridBagConstraints (); 389 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 390 tagPanel.add(tagListLabel, gridBagConstraints); 391 392 gridBagConstraints = new java.awt.GridBagConstraints (); 393 gridBagConstraints.gridx = 0; 394 gridBagConstraints.gridy = 2; 395 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 396 gridBagConstraints.weighty = 1.0; 397 gridBagConstraints.insets = new java.awt.Insets (0, 3, 11, 7); 398 add(tagPanel, gridBagConstraints); 399 400 htmlToolBar.setLayout(new java.awt.GridLayout (1, 6)); 401 402 boldButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.boldButton.text")); 403 boldButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.boldButton.textA11yDesc")); 404 boldButton.setActionCommand("B"); 405 boldButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 406 boldButton.setMinimumSize(new java.awt.Dimension (32, 27)); 407 boldButton.setRequestFocusEnabled(false); 408 boldButton.addActionListener(formListener); 409 410 htmlToolBar.add(boldButton); 411 412 italicButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.italicButton.text")); 413 italicButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.italicButton.textA11yDesc")); 414 italicButton.setActionCommand("I"); 415 italicButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 416 italicButton.setMinimumSize(new java.awt.Dimension (32, 27)); 417 italicButton.setRequestFocusEnabled(false); 418 italicButton.addActionListener(formListener); 419 420 htmlToolBar.add(italicButton); 421 422 underlineButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.underlineButton.text")); 423 underlineButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.underlineButton.textA11yDesc")); 424 underlineButton.setActionCommand("U"); 425 underlineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 426 underlineButton.setMinimumSize(new java.awt.Dimension (32, 27)); 427 underlineButton.setRequestFocusEnabled(false); 428 underlineButton.addActionListener(formListener); 429 430 htmlToolBar.add(underlineButton); 431 432 codeButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.codeButton.text")); 433 codeButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.codeButton.textA11yDesc")); 434 codeButton.setActionCommand("CODE"); 435 codeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 436 codeButton.setMinimumSize(new java.awt.Dimension (32, 27)); 437 codeButton.setRequestFocusEnabled(false); 438 codeButton.addActionListener(formListener); 439 440 htmlToolBar.add(codeButton); 441 442 preButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.preButton.text")); 443 preButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.preButton.textA11yDesc")); 444 preButton.setActionCommand("PRE"); 445 preButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 446 preButton.setMinimumSize(new java.awt.Dimension (32, 27)); 447 preButton.setRequestFocusEnabled(false); 448 preButton.addActionListener(formListener); 449 450 htmlToolBar.add(preButton); 451 452 linkButton.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.linkButton.text")); 453 linkButton.setToolTipText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("ACS_JavaDocEditorPanel.linkButton.textA11yDesc")); 454 linkButton.setActionCommand("link"); 455 linkButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 456 linkButton.setMinimumSize(new java.awt.Dimension (32, 27)); 457 linkButton.setRequestFocusEnabled(false); 458 linkButton.addActionListener(formListener); 459 460 htmlToolBar.add(linkButton); 461 462 gridBagConstraints = new java.awt.GridBagConstraints (); 463 gridBagConstraints.gridx = 0; 464 gridBagConstraints.gridy = 3; 465 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 466 gridBagConstraints.weightx = 1.0; 467 gridBagConstraints.insets = new java.awt.Insets (5, 7, 11, 7); 468 add(htmlToolBar, gridBagConstraints); 469 470 commentLabel.setLabelFor(commentTextArea); 471 commentLabel.setText(org.openide.util.NbBundle.getBundle(JavaDocEditorPanel.class).getString("CTL_JavaDocEditorPanel.textPanel.title")); 472 gridBagConstraints = new java.awt.GridBagConstraints (); 473 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 474 gridBagConstraints.insets = new java.awt.Insets (12, 3, 0, 0); 475 add(commentLabel, gridBagConstraints); 476 477 } 478 479 481 private class FormListener implements java.awt.event.ActionListener , java.awt.event.FocusListener , javax.swing.event.ListSelectionListener { 482 public void actionPerformed(java.awt.event.ActionEvent evt) { 483 if (evt.getSource() == newButton) { 484 JavaDocEditorPanel.this.newTagButtonActionPerformed(evt); 485 } 486 else if (evt.getSource() == deleteButton) { 487 JavaDocEditorPanel.this.delTagButtonActionPerformed(evt); 488 } 489 else if (evt.getSource() == moveUpButton) { 490 JavaDocEditorPanel.this.moveTagButtonActionPerformed(evt); 491 } 492 else if (evt.getSource() == moveDownButton) { 493 JavaDocEditorPanel.this.moveTagButtonActionPerformed(evt); 494 } 495 else if (evt.getSource() == boldButton) { 496 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 497 } 498 else if (evt.getSource() == italicButton) { 499 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 500 } 501 else if (evt.getSource() == underlineButton) { 502 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 503 } 504 else if (evt.getSource() == codeButton) { 505 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 506 } 507 else if (evt.getSource() == preButton) { 508 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 509 } 510 else if (evt.getSource() == linkButton) { 511 JavaDocEditorPanel.this.formatButtonActionPerformed(evt); 512 } 513 } 514 515 public void focusGained(java.awt.event.FocusEvent evt) { 516 if (evt.getSource() == commentTextArea) { 517 JavaDocEditorPanel.this.commentTextAreaFocusGained(evt); 518 } 519 } 520 521 public void focusLost(java.awt.event.FocusEvent evt) { 522 if (evt.getSource() == commentTextArea) { 523 JavaDocEditorPanel.this.commentTextAreaFocusLost(evt); 524 } 525 } 526 527 public void valueChanged(javax.swing.event.ListSelectionEvent evt) { 528 if (evt.getSource() == tagList) { 529 JavaDocEditorPanel.this.tagListValueChanged(evt); 530 } 531 } 532 } 534 private void tagListValueChanged(javax.swing.event.ListSelectionEvent evt) { if (!updatingTagList) { 536 deleteButton.setEnabled(true); 537 moveUpButton.setEnabled(true); 538 moveDownButton.setEnabled(true); 539 } 540 541 TagPanel tagPanel; 542 int sel = tagList.getMinSelectionIndex(); 543 544 if (lastSelection >= 0 && lastSelection != sel && lastSelection<listModel.getSize()) { 545 JavaDocTag tag = (JavaDocTag)listModel.get( lastSelection ); 546 tagPanel = getPanelForTag( tag ); 547 JavaDocTag newTag = tagPanel.getTag( tag.name() ); 548 listModel.setElementAt(newTag, lastSelection); 549 } 550 lastSelection = sel; 551 552 if ( sel < 0 ) { 553 tagPanel = emptyTagPanel; 554 enableButtons( false ); 555 } 556 else { 557 JavaDocTag tag = (JavaDocTag)listModel.get( sel ) ; 559 560 tagPanel = getPanelForTag( tag ); 561 tagPanel.setData( tag ); 562 } 563 CardLayout layout = (CardLayout )tagParamPanel.getLayout(); 564 layout.show( tagParamPanel, tagPanel.getCardName() ); 565 if ( tagPanel != emptyTagPanel && this.grabFocusAfterNewButton 569 && evt.getFirstIndex() != evt.getLastIndex() 570 && !evt.getValueIsAdjusting() ) { 571 this.grabFocusAfterNewButton = false; 572 tagPanel.grabFirstFocus(); 573 } 574 } 577 private void commentTextAreaFocusLost (java.awt.event.FocusEvent evt) { enableButtons( false ); 579 } 581 private void commentTextAreaFocusGained (java.awt.event.FocusEvent evt) { enableButtons( true ); 583 } 585 private void newTagButtonActionPerformed (java.awt.event.ActionEvent evt) { newTagDialog = new NewTagDialog(element.getSrcElement()); 588 589 DialogDescriptor desc = new DialogDescriptor(newTagDialog, 590 NbBundle.getMessage(JavaDocEditorPanel.class, "NewTagDialog.Form.title"), 591 true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, null); 592 Object result = org.openide.DialogDisplayer.getDefault().notify(desc); 593 JavaDocTag tag = null; 594 595 if (result == DialogDescriptor.OK_OPTION && (tag = newTagDialog.getResult()) != null) { 596 listModel.addElement( tag ); 597 tagList.ensureIndexIsVisible( listModel.getSize() ); 598 this.grabFocusAfterNewButton = true; 599 tagList.setSelectedIndex( listModel.getSize() - 1 ); 600 } 601 602 } 604 private void delTagButtonActionPerformed (java.awt.event.ActionEvent evt) { int sel = tagList.getMinSelectionIndex(); 606 607 if ( sel != -1 ) { 608 lastSelection = -1; 609 listModel.removeElementAt( sel ); 610 } 611 612 if ( listModel.getSize() > 0 ) 613 tagList.setSelectedIndex( sel == listModel.getSize() ? sel - 1 : sel ); 614 else { 615 CardLayout layout = (CardLayout )tagParamPanel.getLayout(); 616 layout.show( tagParamPanel, emptyTagPanel.getCardName() ); 617 } 618 } 620 private void chgTagButtonActionPerformed (java.awt.event.ActionEvent evt) { commitTagChange(); 622 } 624 625 private void moveTagButtonActionPerformed (java.awt.event.ActionEvent evt) { if ( evt.getActionCommand().equals( "UP" ) ) { int selIndex = tagList.getMinSelectionIndex(); 629 if ( selIndex > 0 ) { 630 Object tag = listModel.get( selIndex ); 631 lastSelection = -1; 632 listModel.removeElementAt( selIndex ); 633 listModel.insertElementAt( tag, selIndex - 1 ); 634 tagList.setSelectedIndex( selIndex - 1 ); 635 } 636 } 637 else if ( evt.getActionCommand().equals( "DOWN" ) ) { int selIndex = tagList.getMinSelectionIndex(); 639 if ( selIndex >= 0 && selIndex < listModel.getSize() - 1 ) { 640 Object tag = listModel.get( selIndex ); 641 lastSelection = -1; 642 listModel.removeElementAt( selIndex ); 643 listModel.insertElementAt( tag, selIndex + 1 ); 644 tagList.setSelectedIndex( selIndex + 1 ); 645 } 646 } 647 } 649 private void formatButtonActionPerformed (java.awt.event.ActionEvent evt) { String begTag; 651 String endTag; 652 String command = evt.getActionCommand(); 653 654 if ( command.equals( "link" ) ) { begTag = "{@link "; endTag = "}"; } 658 else { 659 begTag = "<" + command + ">"; endTag = "</" + command + ">"; } 662 663 if ( commentTextArea.hasFocus() ) { 664 int caretPosition = commentTextArea.getCaretPosition(); 665 671 try { 672 commentTextArea.getDocument().insertString( commentTextArea.getSelectionStart(), begTag, null ); 673 commentTextArea.getDocument().insertString( commentTextArea.getSelectionEnd(), endTag, null ); 674 commentTextArea.setCaretPosition( caretPosition + 2 + evt.getActionCommand().length() ); 675 } 676 catch ( javax.swing.text.BadLocationException e ) { 677 } 679 } 680 else { 681 JavaDocTag tag = (JavaDocTag)listModel.get( tagList.getMinSelectionIndex() ) ; 682 TagPanel tagPanel = getPanelForTag( tag ); 683 tagPanel.handleFormatButton( begTag, endTag ); 684 } 685 } 687 688 private javax.swing.JButton boldButton; 690 private javax.swing.JButton codeButton; 691 private javax.swing.JLabel commentLabel; 692 private javax.swing.JScrollPane commentScrollPane; 693 private javax.swing.JEditorPane commentTextArea; 694 private javax.swing.JButton deleteButton; 695 private javax.swing.JPanel htmlToolBar; 696 private javax.swing.JButton italicButton; 697 private javax.swing.JButton linkButton; 698 private javax.swing.JButton moveDownButton; 699 private javax.swing.JButton moveUpButton; 700 private javax.swing.JButton newButton; 701 private javax.swing.JButton preButton; 702 private javax.swing.JList tagList; 703 private javax.swing.JLabel tagListLabel; 704 private javax.swing.JPanel tagPanel; 705 private javax.swing.JPanel tagParamPanel; 706 private javax.swing.JScrollPane tagScrollPane; 707 private javax.swing.JPanel textPanel; 708 private javax.swing.JButton underlineButton; 709 711 712 String getRawText() { 713 JavaDoc jd = getUpdatedJavaDoc(); 714 return jd.getRawText(); 715 } 716 717 JavaDoc getUpdatedJavaDoc() { 718 JavaDoc jd = JavaDocSupport.createJavaDoc(""); 719 JavaDocTag tags[]; 720 721 try { 722 jd.setText(commentTextArea.getDocument().getText( 0, commentTextArea.getDocument().getLength())); 723 tags = new JavaDocTag[listModel.getSize()]; 724 listModel.copyInto(tags); 725 jd.changeTags(tags,JavaDoc.SET); 726 } catch (Exception e) { 727 ErrorManager.getDefault().notify(e); 728 } 729 return jd; 730 } 731 732 733 738 public Object getPropertyValue () throws IllegalStateException { 739 740 try { 741 javaDoc.setRawText( getRawText() ); 742 } 743 catch ( SourceException ex ) { 744 throw new IllegalStateException (); 745 746 } 747 748 return javaDoc; 749 } 750 751 TagPanel getPanelForTag( JavaDocTag tag ) { 752 753 if ( tag instanceof JavaDocTag.Param ) 754 return paramTagPanel; 755 else if ( tag instanceof JavaDocTag.Throws ) 756 return throwsTagPanel; 757 else if ( tag instanceof JavaDocTag.SerialField ) 758 return serialFieldTagPanel; 759 else if ( tag instanceof JavaDocTag.See ) 760 return seeTagPanel; 761 else 762 return standardTagPanel; 763 764 } 765 766 767 void commitTagChange() { 768 updatingTagList = true; 769 TagPanel tagPanel; 770 int sel = tagList.getMinSelectionIndex(); 771 if ( sel >= 0 ) { 772 JavaDocTag tag = (JavaDocTag)listModel.get( sel ); 773 tagPanel = getPanelForTag( tag ); 774 JavaDocTag newTag = tagPanel.getTag( tag.name() ); 775 listModel.setElementAt( newTag, sel ); 776 dirty = true; 777 } 778 updatingTagList = false; 779 } 780 781 void enableButtons( boolean enable ) { 782 boldButton.setEnabled( enable ); 783 italicButton.setEnabled( enable ); 784 underlineButton.setEnabled( enable ); 785 codeButton.setEnabled( enable ); 786 preButton.setEnabled( enable ); 787 linkButton.setEnabled( enable ); 788 } 789 790 void registerComponent( java.awt.Component component) { 791 mnemonicsDistributor.registerComponent( component ); 792 } 793 794 795 798 public boolean isDirty() { 799 return dirty; 800 } 801 802 805 public void setDirty(boolean dirty) { 806 this.dirty = dirty; 807 } 808 809 811 class MnemonicsDistributor extends java.awt.event.KeyAdapter { 812 813 MnemonicsDistributor() { 814 } 815 816 private static final int ALT_LESS_MASK = InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_GRAPH_DOWN_MASK | 817 InputEvent.SHIFT_DOWN_MASK | InputEvent.META_DOWN_MASK; 818 819 public void keyPressed( java.awt.event.KeyEvent e ) { 820 821 javax.swing.KeyStroke ks = javax.swing.KeyStroke.getKeyStrokeForEvent( e ); 822 823 final int modifiers = ks.getModifiers(); 824 if ( ( modifiers & InputEvent.ALT_MASK ) != 0 && (modifiers & ALT_LESS_MASK) == 0) { 825 826 switch ( ks.getKeyCode() ) { 827 case KeyEvent.VK_B: 828 boldButton.doClick(); 829 e.consume(); 830 break; 831 case KeyEvent.VK_I: 832 italicButton.doClick(); 833 e.consume(); 834 break; 835 case KeyEvent.VK_U: 836 underlineButton.doClick(); 837 e.consume(); 838 break; 839 case KeyEvent.VK_C: 840 codeButton.doClick(); 841 e.consume(); 842 break; 843 case KeyEvent.VK_P: 844 preButton.doClick(); 845 e.consume(); 846 break; 847 case KeyEvent.VK_L: 848 linkButton.doClick(); 849 e.consume(); 850 break; 851 } 852 } 853 } 854 855 void registerComponent( java.awt.Component component ) { 856 component.addKeyListener(this); 857 } 858 859 } 860 861 } 862 | Popular Tags |