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.ClassMember; 26 import org.netbeans.jmi.javamodel.CallableFeature; 27 import org.netbeans.jmi.javamodel.Parameter; 28 29 import javax.swing.text.BadLocationException ; 30 import javax.jmi.reflect.JmiException; 31 import java.util.List ; 32 import java.util.Iterator ; 33 import org.netbeans.modules.javacore.api.JavaModel; 34 import org.openide.text.CloneableEditorSupport; 35 36 41 public class ParamTagPanel extends TagPanel { 42 43 private static final String cardName = "CRD_PARAM"; 45 static final long serialVersionUID =-8780867931455925203L; 46 47 48 public ParamTagPanel( final JavaDocEditorPanel editorPanel ) { 49 super( editorPanel ); 50 51 initComponents(); 52 initAccessibility(); 53 jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("CTL_ParamTagPanel.jLabel2.text_Mnemonic").charAt(0)); jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("CTL_ParamTagPanel.jLabel1.text_Mnemonic").charAt(0)); 56 addHTMLComponent( descriptionTextArea ); 57 58 editorPanel.registerComponent( descriptionTextArea ); 59 60 parameterComboBox.getEditor().getEditorComponent().addFocusListener( 61 new java.awt.event.FocusAdapter () { 62 public void focusLost(java.awt.event.FocusEvent evt) { 63 commitTagChange(); 64 } 65 }); 66 } 67 68 public ParamTagPanel( ClassMember element, JavaDocEditorPanel editorPanel ) { 69 this( editorPanel ); 70 setElement( element ); 71 } 72 73 public void setElement( final ClassMember element ) { 74 parameterComboBox.removeAllItems(); 75 if ( element instanceof CallableFeature ) { 76 try { 77 JavaModel.getJavaRepository().beginTrans(false); 78 try { 79 List params = ((CallableFeature) element).getParameters(); 80 for (Iterator it = params.iterator(); it.hasNext();) { 81 Parameter param = (Parameter) it.next(); 82 parameterComboBox.addItem( param.getName() ); 83 } 84 } finally { 85 JavaModel.getJavaRepository().endTrans(); 86 } 87 } catch (JmiException e) { 88 ErrorManager.getDefault().notify(e); 89 } 90 parameterComboBox.setSelectedItem( "" ); } 92 } 93 94 private void initAccessibility() 95 { 96 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.jLabel2.textA11yDesc")); parameterComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.parameterComboBox.textA11yName")); jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.jLabel1.textA11yDesc")); descriptionTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.descriptionTextArea.textA11yName")); } 101 102 107 private void initComponents() { 109 java.awt.GridBagConstraints gridBagConstraints; 110 111 jLabel2 = new javax.swing.JLabel (); 112 parameterComboBox = new javax.swing.JComboBox (); 113 jLabel1 = new javax.swing.JLabel (); 114 descriptionScrollPane = new javax.swing.JScrollPane (); 115 descriptionTextArea = new javax.swing.JEditorPane (); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html")); 116 117 setLayout(new java.awt.GridBagLayout ()); 118 119 jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 120 jLabel2.setLabelFor(parameterComboBox); 121 jLabel2.setText(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("CTL_ParamTagPanel.jLabel2.text")); 122 gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 124 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 125 add(jLabel2, gridBagConstraints); 126 127 parameterComboBox.setEditable(true); 128 parameterComboBox.setMaximumRowCount(4); 129 parameterComboBox.setToolTipText(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.parameterComboBox.textA11yDesc")); 130 parameterComboBox.addActionListener(new java.awt.event.ActionListener () { 131 public void actionPerformed(java.awt.event.ActionEvent evt) { 132 parameterComboBoxActionPerformed(evt); 133 } 134 }); 135 136 gridBagConstraints = new java.awt.GridBagConstraints (); 137 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 138 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 140 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 141 add(parameterComboBox, gridBagConstraints); 142 143 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 144 jLabel1.setLabelFor(descriptionTextArea); 145 jLabel1.setText(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("CTL_ParamTagPanel.jLabel1.text")); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 148 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 149 add(jLabel1, gridBagConstraints); 150 151 descriptionTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("ACS_ParamTagPanel.descriptionTextArea.textA11yDesc")); 152 descriptionTextArea.addFocusListener(new java.awt.event.FocusAdapter () { 153 public void focusGained(java.awt.event.FocusEvent evt) { 154 descriptionTextAreaFocusGained(evt); 155 } 156 public void focusLost(java.awt.event.FocusEvent evt) { 157 descriptionTextAreaFocusLost(evt); 158 } 159 }); 160 161 descriptionScrollPane.setViewportView(descriptionTextArea); 162 163 gridBagConstraints = new java.awt.GridBagConstraints (); 164 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 165 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 166 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 167 gridBagConstraints.weightx = 1.0; 168 gridBagConstraints.weighty = 1.0; 169 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 170 add(descriptionScrollPane, gridBagConstraints); 171 172 } 174 private void descriptionTextAreaFocusGained (java.awt.event.FocusEvent evt) { enableHTMLButtons( true ); 176 } 178 private void descriptionTextAreaFocusLost (java.awt.event.FocusEvent evt) { enableHTMLButtons( false ); 180 commitTagChange(); 181 } 183 private void parameterComboBoxActionPerformed (java.awt.event.ActionEvent evt) { } 187 188 private javax.swing.JScrollPane descriptionScrollPane; 190 private javax.swing.JEditorPane descriptionTextArea; 191 private javax.swing.JLabel jLabel1; 192 private javax.swing.JLabel jLabel2; 193 private javax.swing.JComboBox parameterComboBox; 194 196 void setData(final JavaDocTag tag ) { 197 parameterComboBox.setSelectedItem(((JavaDocTag.Param)tag).parameterName()); 198 String paramComment = ((JavaDocTag.Param)tag).parameterComment().trim(); 199 if ((paramComment != null) && (! "".equals(paramComment))) { descriptionTextArea.setText( paramComment ); 201 } else { 202 try { 203 descriptionTextArea.getDocument().remove(0, descriptionTextArea.getDocument().getLength()); 204 } catch (BadLocationException e) { 205 ErrorManager.getDefault().annotate(e, "Failed to remove the text in the descriptionTextArea."); } 207 } 208 } 209 210 JavaDocTag getTag( String tagName ) { 211 return JavaDocSupport.createParamTag( tagName, 212 parameterComboBox.getEditor().getItem().toString() + " " + descriptionTextArea.getText() ); 214 } 215 216 String getCardName() { 217 return cardName; 218 } 219 220 void grabFirstFocus() { 221 if (( parameterComboBox.getSelectedIndex() == -1 && parameterComboBox.getSelectedItem() != null && parameterComboBox.getSelectedItem().equals( "" ) ) || ("".equals(parameterComboBox.getEditor().getItem()))) { parameterComboBox.requestFocus(); 225 } else { 226 descriptionTextArea.requestFocus(); 227 } 228 } 229 230 } 231 | Popular Tags |