KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
26
27 import javax.swing.text.BadLocationException JavaDoc;
28 import org.openide.text.CloneableEditorSupport;
29
30 /**
31  *
32  * @author
33  * @version
34  */

35 public class StandardTagPanel extends TagPanel implements JavaTagNames {
36
37     private static final String JavaDoc cardName = "CRD_STANDARD"; // NOI18N
38

39     private static final String JavaDoc[] classTags = {
40         TAG_AUTHOR,
41         TAG_DEPRECATED,
42         TAG_SINCE,
43         TAG_VERSION };
44
45     private static final String JavaDoc[] fieldTags = {
46         TAG_DEPRECATED,
47         TAG_SERIAL,
48         TAG_SINCE };
49
50     private static final String JavaDoc[] methodTags = {
51         TAG_DEPRECATED,
52         TAG_RETURN,
53         TAG_SERIALDATA,
54         TAG_SINCE };
55
56
57
58     static final long serialVersionUID =134652804415020896L;
59     /** Initializes the Form */
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)); // NOI18N
65
jLabel1.setDisplayedMnemonic(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("CTL_StandardTagPanel.jLabel1.text_Mnemonic").charAt(0)); // NOI18N
66

67         addHTMLComponent( descriptionTextArea );
68         editorPanel.registerComponent( descriptionTextArea );
69
70         nameComboBox.getEditor().getEditorComponent().addFocusListener(
71             new java.awt.event.FocusAdapter JavaDoc () {
72                 public void focusLost (java.awt.event.FocusEvent JavaDoc 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( "" ); // NOI18N
91
}
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( "" ); // NOI18N
97
}
98         if ( element instanceof JavaClass ) {
99             for( int i = 0; i < classTags.length; i++ ) {
100                 nameComboBox.addItem( classTags[i] );
101             }
102             nameComboBox.setSelectedItem( "" ); // NOI18N
103
}
104     }
105     
106     private void initAccessibility()
107     {
108         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.jLabel2.textA11yDesc")); // NOI18N
109
nameComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.nameComboBox.textA11yName")); // NOI18N
110
jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.jLabel1.textA11yDesc")); // NOI18N
111
descriptionTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(StandardTagPanel.class).getString("ACS_StandardTagPanel.descriptionTextArea.textA11yName")); // NOI18N
112
}
113     
114     /** This method is called from within the constructor to
115      * initialize the form.
116      * WARNING: Do NOT modify this code. The content of this method is
117      * always regenerated by the FormEditor.
118      */

119     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
120
private void initComponents() {
121         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
122
123         jLabel2 = new javax.swing.JLabel JavaDoc();
124         nameComboBox = new javax.swing.JComboBox JavaDoc();
125         jLabel1 = new javax.swing.JLabel JavaDoc();
126         descriptionScrollPane = new javax.swing.JScrollPane JavaDoc();
127         descriptionTextArea = new javax.swing.JEditorPane JavaDoc(); descriptionTextArea.setEditorKit(CloneableEditorSupport.getEditorKit("text/html"));
128
129         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc();
135         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
136         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
143         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
144         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
145         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
152         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
158             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
159                 descriptionTextAreaFocusGained(evt);
160             }
161             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
162                 descriptionTextAreaFocusLost(evt);
163             }
164         });
165
166         descriptionScrollPane.setViewportView(descriptionTextArea);
167
168         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(2, 1, 2, 2);
175         add(descriptionScrollPane, gridBagConstraints);
176
177     }// </editor-fold>//GEN-END:initComponents
178

179     private void descriptionTextAreaFocusGained (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_descriptionTextAreaFocusGained
180
enableHTMLButtons( true );
181     }//GEN-LAST:event_descriptionTextAreaFocusGained
182

183
184     private void descriptionTextAreaFocusLost (java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_descriptionTextAreaFocusLost
185
enableHTMLButtons( false );
186         commitTagChange();
187     }//GEN-LAST:event_descriptionTextAreaFocusLost
188

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

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