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.CallableFeature; 26 import org.netbeans.jmi.javamodel.ClassMember; 27 import org.netbeans.jmi.javamodel.JavaClass; 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 ThrowsTagPanel extends TagPanel { 42 43 private static final String cardName = "CRD_THROWS"; 45 static final long serialVersionUID =2048140086381465545L; 46 47 public ThrowsTagPanel( JavaDocEditorPanel editorPanel ) { 48 super( editorPanel ); 49 50 initComponents (); 51 jLabel2.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("CTL_ThrowsTagPanel.jLabel2.text_Mnemonic").charAt(0)); jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("CTL_ThrowsTagPanel.jLabel1.text_Mnemonic").charAt(0)); 54 editorPanel.registerComponent( descriptionTextArea ); 55 addHTMLComponent( descriptionTextArea ); 56 57 exceptionComboBox.getEditor().getEditorComponent().addFocusListener( 58 new java.awt.event.FocusAdapter () { 59 public void focusLost (java.awt.event.FocusEvent evt) { 60 commitTagChange(); 61 } 62 }); 63 initAccessibility(); 64 } 65 66 public ThrowsTagPanel( ClassMember element, JavaDocEditorPanel editorPanel ) { 67 this( editorPanel ); 68 setElement(element); 69 } 70 71 public void setElement( ClassMember element ) { 72 exceptionComboBox.removeAllItems(); 73 if ( element instanceof CallableFeature ) { 74 try { 75 JavaModel.getJavaRepository().beginTrans(false); 76 try { 77 List exceptions = ((CallableFeature) element).getExceptions(); 78 for (Iterator it = exceptions.iterator(); it.hasNext();) { 79 JavaClass exception = (JavaClass) it.next(); 80 exceptionComboBox.addItem(exception.getName()); 81 } 82 } finally { 83 JavaModel.getJavaRepository().endTrans(); 84 } 85 } catch (JmiException e) { 86 ErrorManager.getDefault().notify(e); 87 } 88 exceptionComboBox.setSelectedItem( "" ); } 90 } 91 92 private void initAccessibility() 93 { 94 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.jLabel2.textA11yDesc")); exceptionComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.exceptionComboBox.textA11yName")); jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.jLabel1.textA11yDesc")); descriptionTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.descriptionTextArea.textA11yName")); } 99 100 105 private void initComponents() { 107 java.awt.GridBagConstraints gridBagConstraints; 108 109 jLabel2 = new javax.swing.JLabel (); 110 exceptionComboBox = new javax.swing.JComboBox (); 111 jLabel1 = new javax.swing.JLabel (); 112 descriptionScrollPane = new javax.swing.JScrollPane (); 113 descriptionTextArea = new javax.swing.JEditorPane (); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html")); 114 115 setLayout(new java.awt.GridBagLayout ()); 116 117 jLabel2.setText(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("CTL_ThrowsTagPanel.jLabel2.text")); 118 jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 119 jLabel2.setLabelFor(exceptionComboBox); 120 gridBagConstraints = new java.awt.GridBagConstraints (); 121 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 122 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 123 add(jLabel2, gridBagConstraints); 124 125 exceptionComboBox.setMaximumRowCount(4); 126 exceptionComboBox.setToolTipText(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.exceptionComboBox.textA11yDesc")); 127 exceptionComboBox.setEditable(true); 128 exceptionComboBox.addActionListener(new java.awt.event.ActionListener () { 129 public void actionPerformed(java.awt.event.ActionEvent evt) { 130 exceptionComboBoxActionPerformed(evt); 131 } 132 }); 133 134 gridBagConstraints = new java.awt.GridBagConstraints (); 135 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 136 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 137 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 138 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 139 add(exceptionComboBox, gridBagConstraints); 140 141 jLabel1.setText(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("CTL_ThrowsTagPanel.jLabel1.text")); 142 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 143 jLabel1.setLabelFor(descriptionTextArea); 144 gridBagConstraints = new java.awt.GridBagConstraints (); 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 146 gridBagConstraints.insets = new java.awt.Insets (2, 2, 2, 1); 147 add(jLabel1, gridBagConstraints); 148 149 descriptionTextArea.setToolTipText(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.descriptionTextArea.textA11yDesc")); 150 descriptionTextArea.addFocusListener(new java.awt.event.FocusAdapter () { 151 public void focusGained(java.awt.event.FocusEvent evt) { 152 descriptionTextAreaFocusGained(evt); 153 } 154 public void focusLost(java.awt.event.FocusEvent evt) { 155 descriptionTextAreaFocusLost(evt); 156 } 157 }); 158 159 descriptionScrollPane.setViewportView(descriptionTextArea); 160 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 163 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 164 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 165 gridBagConstraints.weightx = 1.0; 166 gridBagConstraints.weighty = 1.0; 167 gridBagConstraints.insets = new java.awt.Insets (2, 1, 2, 2); 168 add(descriptionScrollPane, gridBagConstraints); 169 170 } 172 private void descriptionTextAreaFocusGained (java.awt.event.FocusEvent evt) { enableHTMLButtons( true ); 174 } 176 private void descriptionTextAreaFocusLost (java.awt.event.FocusEvent evt) { enableHTMLButtons( false ); 178 commitTagChange(); 179 } 181 private void exceptionComboBoxActionPerformed (java.awt.event.ActionEvent evt) { } 185 186 private javax.swing.JScrollPane descriptionScrollPane; 188 private javax.swing.JEditorPane descriptionTextArea; 189 private javax.swing.JComboBox exceptionComboBox; 190 private javax.swing.JLabel jLabel1; 191 private javax.swing.JLabel jLabel2; 192 194 void setData( JavaDocTag tag ) { 195 exceptionComboBox.setSelectedItem(((JavaDocTag.Throws)tag).exceptionName()); 196 String exceptionComment = ((JavaDocTag.Throws)tag).exceptionComment().trim(); 197 if ((exceptionComment != null) && (! "".equals(exceptionComment))) { descriptionTextArea.setText( exceptionComment ); 199 } else { 200 try { 201 descriptionTextArea.getDocument().remove(0, descriptionTextArea.getDocument().getLength()); 202 } catch (BadLocationException e) { 203 ErrorManager.getDefault().annotate(e, "Failed to remove the text in the descriptionTextArea."); } 205 } 206 } 207 208 JavaDocTag getTag( String tagName ) { 209 return JavaDocSupport.createThrowsTag( tagName, 210 exceptionComboBox.getEditor().getItem().toString() + " " + descriptionTextArea.getText() ); 212 } 213 214 String getCardName() { 215 return cardName; 216 } 217 218 void grabFirstFocus() { 219 if (( exceptionComboBox.getSelectedIndex() == -1 && exceptionComboBox.getSelectedItem() != null && exceptionComboBox.getSelectedItem().equals( "" ) ) || ("".equals((String )exceptionComboBox.getEditor().getItem()))) { exceptionComboBox.requestFocus(); 222 } else { 223 descriptionTextArea.requestFocus(); 224 } 225 } 226 227 } 228 | Popular Tags |