KickJava   Java API By Example, From Geeks To Geeks.

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


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.ClassMember;
26 import org.netbeans.jmi.javamodel.CallableFeature;
27 import org.netbeans.jmi.javamodel.Parameter;
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 ParamTagPanel extends TagPanel {
42     
43     private static final String JavaDoc cardName = "CRD_PARAM"; // NOI18N
44

45     static final long serialVersionUID =-8780867931455925203L;
46     /** Initializes the Form */
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)); // NOI18N
54
jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(ParamTagPanel.class).getString("CTL_ParamTagPanel.jLabel1.text_Mnemonic").charAt(0)); // NOI18N
55

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

107     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
108
private void initComponents() {
109         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
110
111         jLabel2 = new javax.swing.JLabel JavaDoc();
112         parameterComboBox = new javax.swing.JComboBox JavaDoc();
113         jLabel1 = new javax.swing.JLabel JavaDoc();
114         descriptionScrollPane = new javax.swing.JScrollPane JavaDoc();
115         descriptionTextArea = new javax.swing.JEditorPane JavaDoc(); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html"));
116
117         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
123         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
131             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
132                 parameterComboBoxActionPerformed(evt);
133             }
134         });
135
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
147         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
153             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
154                 descriptionTextAreaFocusGained(evt);
155             }
156             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
157                 descriptionTextAreaFocusLost(evt);
158             }
159         });
160
161         descriptionScrollPane.setViewportView(descriptionTextArea);
162
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(2, 1, 2, 2);
170         add(descriptionScrollPane, gridBagConstraints);
171
172     }// </editor-fold>//GEN-END:initComponents
173

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

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

183     private void parameterComboBoxActionPerformed (java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_parameterComboBoxActionPerformed
184
// Add your handling code here:
185
}//GEN-LAST:event_parameterComboBoxActionPerformed
186

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

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