KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javadoc > comments > ThrowsTagPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
30 import javax.jmi.reflect.JmiException;
31 import java.util.List JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import org.netbeans.modules.javacore.api.JavaModel;
34 import org.openide.text.CloneableEditorSupport;
35
36 /**
37  *
38  * @author
39  * @version
40  */

41 public class ThrowsTagPanel extends TagPanel {
42     
43     private static final String JavaDoc cardName = "CRD_THROWS"; // NOI18N
44

45     static final long serialVersionUID =2048140086381465545L;
46     /** Initializes the Form */
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)); // NOI18N
52
jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("CTL_ThrowsTagPanel.jLabel1.text_Mnemonic").charAt(0)); // NOI18N
53

54         editorPanel.registerComponent( descriptionTextArea );
55         addHTMLComponent( descriptionTextArea );
56         
57         exceptionComboBox.getEditor().getEditorComponent().addFocusListener(
58         new java.awt.event.FocusAdapter JavaDoc () {
59             public void focusLost (java.awt.event.FocusEvent JavaDoc 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 JavaDoc exceptions = ((CallableFeature) element).getExceptions();
78                     for (Iterator JavaDoc 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( "" ); // NOI18N
89
}
90     }
91     
92     private void initAccessibility()
93     {
94         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.jLabel2.textA11yDesc")); // NOI18N
95
exceptionComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.exceptionComboBox.textA11yName")); // NOI18N
96
jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.jLabel1.textA11yDesc")); // NOI18N
97
descriptionTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(ThrowsTagPanel.class).getString("ACS_ThrowsTagPanel.descriptionTextArea.textA11yName")); // NOI18N
98
}
99     
100     /** This method is called from within the constructor to
101      * initialize the form.
102      * WARNING: Do NOT modify this code. The content of this method is
103      * always regenerated by the FormEditor.
104      */

105     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
106
private void initComponents() {
107         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
108
109         jLabel2 = new javax.swing.JLabel JavaDoc();
110         exceptionComboBox = new javax.swing.JComboBox JavaDoc();
111         jLabel1 = new javax.swing.JLabel JavaDoc();
112         descriptionScrollPane = new javax.swing.JScrollPane JavaDoc();
113         descriptionTextArea = new javax.swing.JEditorPane JavaDoc(); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html"));
114
115         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
129             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
130                 exceptionComboBoxActionPerformed(evt);
131             }
132         });
133
134         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
151             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
152                 descriptionTextAreaFocusGained(evt);
153             }
154             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
155                 descriptionTextAreaFocusLost(evt);
156             }
157         });
158
159         descriptionScrollPane.setViewportView(descriptionTextArea);
160
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(2, 1, 2, 2);
168         add(descriptionScrollPane, gridBagConstraints);
169
170     }// </editor-fold>//GEN-END:initComponents
171

172     private void descriptionTextAreaFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_descriptionTextAreaFocusGained
173
enableHTMLButtons( true );
174     }//GEN-LAST:event_descriptionTextAreaFocusGained
175

176     private void descriptionTextAreaFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_descriptionTextAreaFocusLost
177
enableHTMLButtons( false );
178         commitTagChange();
179     }//GEN-LAST:event_descriptionTextAreaFocusLost
180

181     private void exceptionComboBoxActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_exceptionComboBoxActionPerformed
182
// Add your handling code here:
183
}//GEN-LAST:event_exceptionComboBoxActionPerformed
184

185     
186     // Variables declaration - do not modify//GEN-BEGIN:variables
187
private javax.swing.JScrollPane JavaDoc descriptionScrollPane;
188     private javax.swing.JEditorPane JavaDoc descriptionTextArea;
189     private javax.swing.JComboBox JavaDoc exceptionComboBox;
190     private javax.swing.JLabel JavaDoc jLabel1;
191     private javax.swing.JLabel JavaDoc jLabel2;
192     // End of variables declaration//GEN-END:variables
193

194     void setData( JavaDocTag tag ) {
195         exceptionComboBox.setSelectedItem(((JavaDocTag.Throws)tag).exceptionName());
196         String JavaDoc exceptionComment = ((JavaDocTag.Throws)tag).exceptionComment().trim();
197         if ((exceptionComment != null) && (! "".equals(exceptionComment))) { //NOI18N
198
descriptionTextArea.setText( exceptionComment );
199         } else {
200             try {
201                 descriptionTextArea.getDocument().remove(0, descriptionTextArea.getDocument().getLength());
202             } catch (BadLocationException JavaDoc e) {
203                 ErrorManager.getDefault().annotate(e, "Failed to remove the text in the descriptionTextArea."); //NOI18N
204
}
205         }
206     }
207     
208     JavaDocTag getTag( String JavaDoc tagName ) {
209         return JavaDocSupport.createThrowsTag( tagName,
210         exceptionComboBox.getEditor().getItem().toString() + " " + // NOI18N
211
descriptionTextArea.getText() );
212     }
213     
214     String JavaDoc getCardName() {
215         return cardName;
216     }
217     
218     void grabFirstFocus() {
219         // JHK 9/29/2000 - cause focus to default to description if the name combo box is filled
220
if (( exceptionComboBox.getSelectedIndex() == -1 && exceptionComboBox.getSelectedItem() != null && exceptionComboBox.getSelectedItem().equals( "" ) ) || ("".equals((String JavaDoc)exceptionComboBox.getEditor().getItem()))) { //NOI18N
221
exceptionComboBox.requestFocus();
222         } else {
223             descriptionTextArea.requestFocus();
224         }
225     }
226     
227 }
228
Popular Tags