1 19 20 package org.netbeans.modules.javadoc.comments; 21 22 import org.openide.ErrorManager; 23 import org.openide.src.JavaDocTag; 24 import org.openide.src.JavaDocSupport; 25 import org.netbeans.jmi.javamodel.*; 26 27 import javax.swing.text.BadLocationException ; 28 import org.openide.text.CloneableEditorSupport; 29 30 35 public class StandardTagPanel extends TagPanel implements JavaTagNames { 36 37 private static final String cardName = "CRD_STANDARD"; 39 private static final String [] classTags = { 40 TAG_AUTHOR, 41 TAG_DEPRECATED, 42 TAG_SINCE, 43 TAG_VERSION }; 44 45 private static final String [] fieldTags = { 46 TAG_DEPRECATED, 47 TAG_SERIAL, 48 TAG_SINCE }; 49 50 private static final String [] methodTags = { 51 TAG_DEPRECATED, 52 TAG_RETURN, 53 TAG_SERIALDATA, 54 TAG_SINCE }; 55 56 57 58 static final long serialVersionUID =134652804415020896L; 59 60 public StandardTagPanel ( JavaDocEditorPanel editorPanel ) { 61 super( editorPanel ); 62 63 initComponents ( ); 64 jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("CTL_StandardTagPanel.jLabel2.text_Mnemonic").charAt(0)); jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("CTL_StandardTagPanel.jLabel1.text_Mnemonic").charAt(0)); 67 addHTMLComponent( descriptionTextArea ); 68 editorPanel.registerComponent( descriptionTextArea ); 69 70 nameComboBox.getEditor().getEditorComponent().addFocusListener( 71 new java.awt.event.FocusAdapter () { 72 public void focusLost (java.awt.event.FocusEvent evt) { 73 commitTagChange(); 74 } 75 }); 76 initAccessibility(); 77 } 78 79 public StandardTagPanel( ClassMember element, JavaDocEditorPanel editorPanel ) { 80 this( editorPanel ); 81 setElement( element ); 82 } 83 84 public void setElement( ClassMember element ) { 85 nameComboBox.removeAllItems(); 86 if ( element instanceof CallableFeature ) { 87 for( int i = 0; i < methodTags.length; i++ ) { 88 nameComboBox.addItem( methodTags[i] ); 89 } 90 nameComboBox.setSelectedItem( "" ); } 92 else if ( element instanceof Field || element instanceof Attribute) { 93 for( int i = 0; i < fieldTags.length; i++ ) { 94 nameComboBox.addItem( fieldTags[i] ); 95 } 96 nameComboBox.setSelectedItem( "" ); } 98 if ( element instanceof JavaClass ) { 99 for( int i = 0; i < classTags.length; i++ ) { 100 nameComboBox.addItem( classTags[i] ); 101 } 102 nameComboBox.setSelectedItem( "" ); } 104 } 105 106 private void initAccessibility() 107 { 108 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.jLabel2.textA11yDesc")); nameComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.nameComboBox.textA11yName")); jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.jLabel1.textA11yDesc")); descriptionTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.descriptionTextArea.textA11yName")); } 113 114 119 private void initComponents() { 121 java.awt.GridBagConstraints gridBagConstraints; 122 123 jLabel2 = new javax.swing.JLabel (); 124 nameComboBox = new javax.swing.JComboBox (); 125 jLabel1 = new javax.swing.JLabel (); 126 descriptionScrollPane = new javax.swing.JScrollPane (); 127 descriptionTextArea = new javax.swing.JEditorPane (); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html")); 128 129 setLayout(new java.awt.GridBagLayout ()); 130 131 jLabel2.setText(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("CTL_StandardTagPanel.jLabel2.text")); 132 jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 133 jLabel2.setLabelFor(nameComboBox); 134 gridBagConstraints = new java.awt.GridBagConstraints (); 135 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 136 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 137 add(jLabel2, gridBagConstraints); 138 139 nameComboBox.setMaximumRowCount(4); 140 nameComboBox.setToolTipText(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.nameComboBox.textA11yDesc")); 141 nameComboBox.setEditable(true); 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 144 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 145 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 146 add(nameComboBox, gridBagConstraints); 147 148 jLabel1.setText(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("CTL_StandardTagPanel.jLabel1.text")); 149 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 150 jLabel1.setLabelFor(descriptionTextArea); 151 gridBagConstraints = new java.awt.GridBagConstraints (); 152 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 153 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 154 add(jLabel1, gridBagConstraints); 155 156 descriptionTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.descriptionTextArea.textA11yDesc")); 157 descriptionTextArea.addFocusListener(new java.awt.event.FocusAdapter () { 158 public void focusGained(java.awt.event.FocusEvent evt) { 159 descriptionTextAreaFocusGained(evt); 160 } 161 public void focusLost(java.awt.event.FocusEvent evt) { 162 descriptionTextAreaFocusLost(evt); 163 } 164 }); 165 166 descriptionScrollPane.setViewportView(descriptionTextArea); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 170 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 171 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 172 gridBagConstraints.weightx = 1.0; 173 gridBagConstraints.weighty = 1.0; 174 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 175 add(descriptionScrollPane, gridBagConstraints); 176 177 } 179 private void descriptionTextAreaFocusGained (java.awt.event.FocusEvent evt) { enableHTMLButtons( true ); 181 } 183 184 private void descriptionTextAreaFocusLost (java.awt.event.FocusEvent evt) { enableHTMLButtons( false ); 186 commitTagChange(); 187 } 189 190 private javax.swing.JScrollPane descriptionScrollPane; 192 private javax.swing.JEditorPane descriptionTextArea; 193 private javax.swing.JLabel jLabel1; 194 private javax.swing.JLabel jLabel2; 195 private javax.swing.JComboBox nameComboBox; 196 198 void setData( JavaDocTag tag ) { 199 nameComboBox.getEditor().setItem( tag.name() ); 200 if ((tag.text() != null) && (! "".equals(tag.text().trim()))) { descriptionTextArea.setText( tag.text() ); 202 } else { 203 try { 204 descriptionTextArea.getDocument().remove(0, descriptionTextArea.getDocument().getLength()); 205 } catch (BadLocationException e) { 206 ErrorManager.getDefault().annotate(e, "Failed to remove the text in the descriptionTextArea."); } 208 } 209 } 210 211 JavaDocTag getTag( String tagName ) { 212 return JavaDocSupport.createTag( (String ) nameComboBox.getEditor().getItem(), 213 descriptionTextArea.getText() ); 214 } 215 216 String getCardName() { 217 return cardName; 218 } 219 220 void grabFirstFocus() { 221 if ( nameComboBox.getSelectedIndex() == -1 && nameComboBox.getSelectedItem().equals( "" ) ) nameComboBox.requestFocus(); 224 else 225 descriptionTextArea.requestFocus(); 226 } 228 } 229 | Popular Tags |