KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > CustomizerDisplay


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.apisupport.project.ui.customizer;
21
22 import java.awt.EventQueue JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.SortedSet JavaDoc;
26 import javax.swing.DefaultComboBoxModel JavaDoc;
27 import org.netbeans.modules.apisupport.project.ui.UIUtil;
28 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo;
29 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
30 import org.openide.util.NbBundle;
31
32 /**
33  * Represents <em>Display</em> panel in Netbeans Module customizer.
34  *
35  * @author mkrauskopf
36  */

37 final class CustomizerDisplay extends NbPropertyPanel.Single {
38     
39     private boolean noBundle;
40     private ProjectCustomizer.Category cat;
41     
42     /** Creates new form CustomizerDisplay */
43     CustomizerDisplay(final SingleModuleProperties props, ProjectCustomizer.Category cat) {
44         super(props, CustomizerDisplay.class);
45         initComponents();
46         initAccesibility();
47         refresh();
48         this.cat = cat;
49         checkValidity();
50     }
51     
52     void refresh() {
53         this.noBundle = getBundle() == null;
54         if (noBundle) {
55             nameValue.setEnabled(false);
56             categoryValue.setEnabled(false);
57             shortDescValue.setEnabled(false);
58             longDescValue.setEnabled(false);
59         } else {
60             readFromProperties();
61         }
62     }
63     
64     private void checkValidity() {
65         if (this.noBundle) {
66             cat.setErrorMessage(getMessage("MSG_NoBundleForModule"));
67         } else {
68             cat.setErrorMessage(null);
69         }
70     }
71     
72     public void store() {
73         if (!noBundle) {
74             getBundle().setDisplayName(nameValue.getText());
75             getBundle().setCategory(getSelectedCategory());
76             getBundle().setShortDescription(shortDescValue.getText());
77             getBundle().setLongDescription(longDescValue.getText());
78         }
79     }
80     
81     private LocalizedBundleInfo getBundle() {
82         return getProperties().getBundleInfo();
83     }
84     
85     private void readFromProperties() {
86         UIUtil.setText(nameValue, getBundle().getDisplayName());
87         UIUtil.setText(shortDescValue, getBundle().getShortDescription());
88         longDescValue.setText(getBundle().getLongDescription());
89         fillUpCategoryValue();
90     }
91     
92     private void fillUpCategoryValue() {
93         categoryValue.setEnabled(false);
94         categoryValue.setModel(CustomizerComponentFactory.createComboWaitModel());
95         categoryValue.setSelectedItem(CustomizerComponentFactory.WAIT_VALUE);
96         ModuleProperties.RP.post(new Runnable JavaDoc() {
97             public void run() {
98                 final SortedSet JavaDoc moduleCategories = getProperties().getModuleCategories();
99                 EventQueue.invokeLater(new Runnable JavaDoc() {
100                     public void run() {
101                         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
102                         categoryValue.removeAllItems();
103                         for (Iterator JavaDoc it = moduleCategories.iterator(); it.hasNext(); ) {
104                             model.addElement(it.next());
105                         }
106                         if (!moduleCategories.contains(getCategory())) {
107                             // put module's own category at the beginning
108
model.insertElementAt(getCategory(), 0);
109                         }
110                         categoryValue.setModel(model);
111                         categoryValue.setSelectedItem(getCategory());
112                         categoryValue.setEnabled(true);
113                     }
114                 });
115             }
116         });
117     }
118     
119     private String JavaDoc getCategory() {
120         LocalizedBundleInfo bundle = getBundle();
121         String JavaDoc category = bundle != null ? bundle.getCategory() : null;
122         return category != null ? category : ""; // NOI18N
123
}
124     
125     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
126         super.propertyChange(evt);
127         if (SingleModuleProperties.NB_PLATFORM_PROPERTY == evt.getPropertyName()) {
128             fillUpCategoryValue();
129         }
130     }
131     
132     private String JavaDoc getSelectedCategory() {
133         String JavaDoc cat = (String JavaDoc) categoryValue.getSelectedItem();
134         return CustomizerComponentFactory.WAIT_VALUE == cat ? getCategory() : cat;
135     }
136     
137     /** This method is called from within the constructor to
138      * initialize the form.
139      * WARNING: Do NOT modify this code. The content of this method is
140      * always regenerated by the Form Editor.
141      */

142     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
143
private void initComponents() {
144         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
145
146         name = new javax.swing.JLabel JavaDoc();
147         nameValue = new javax.swing.JTextField JavaDoc();
148         category = new javax.swing.JLabel JavaDoc();
149         categoryValue = new javax.swing.JComboBox JavaDoc();
150         shortDesc = new javax.swing.JLabel JavaDoc();
151         shortDescValue = new javax.swing.JTextField JavaDoc();
152         longDesc = new javax.swing.JLabel JavaDoc();
153         hackPanel = new javax.swing.JPanel JavaDoc();
154         longDescValueSP = new javax.swing.JScrollPane JavaDoc();
155         longDescValue = new javax.swing.JTextArea JavaDoc();
156
157         setLayout(new java.awt.GridBagLayout JavaDoc());
158
159         name.setLabelFor(nameValue);
160         org.openide.awt.Mnemonics.setLocalizedText(name, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_DisplayName"));
161         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
162         gridBagConstraints.gridx = 0;
163         gridBagConstraints.gridy = 0;
164         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
166         add(name, gridBagConstraints);
167
168         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
169         gridBagConstraints.gridx = 1;
170         gridBagConstraints.gridy = 0;
171         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
174         add(nameValue, gridBagConstraints);
175
176         category.setLabelFor(categoryValue);
177         org.openide.awt.Mnemonics.setLocalizedText(category, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_DisplayCategory"));
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridx = 0;
180         gridBagConstraints.gridy = 1;
181         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
182         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
183         add(category, gridBagConstraints);
184
185         categoryValue.setEditable(true);
186         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
187         gridBagConstraints.gridx = 1;
188         gridBagConstraints.gridy = 1;
189         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
190         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
191         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
192         add(categoryValue, gridBagConstraints);
193
194         shortDesc.setLabelFor(shortDescValue);
195         org.openide.awt.Mnemonics.setLocalizedText(shortDesc, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_ShortDescription"));
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 0;
198         gridBagConstraints.gridy = 2;
199         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
201         add(shortDesc, gridBagConstraints);
202
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 1;
205         gridBagConstraints.gridy = 2;
206         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
208         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
209         add(shortDescValue, gridBagConstraints);
210
211         longDesc.setLabelFor(longDescValue);
212         org.openide.awt.Mnemonics.setLocalizedText(longDesc, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_LongDescription"));
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
214         gridBagConstraints.gridx = 0;
215         gridBagConstraints.gridy = 3;
216         gridBagConstraints.gridwidth = 2;
217         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
218         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 6);
219         add(longDesc, gridBagConstraints);
220
221         hackPanel.setLayout(new java.awt.BorderLayout JavaDoc());
222
223         longDescValue.setLineWrap(true);
224         longDescValue.setRows(10);
225         longDescValue.setWrapStyleWord(true);
226         longDescValueSP.setViewportView(longDescValue);
227
228         hackPanel.add(longDescValueSP, java.awt.BorderLayout.NORTH);
229
230         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
231         gridBagConstraints.gridx = 0;
232         gridBagConstraints.gridy = 4;
233         gridBagConstraints.gridwidth = 2;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.weighty = 1.0;
237         add(hackPanel, gridBagConstraints);
238
239     }
240     // </editor-fold>//GEN-END:initComponents
241

242     
243     // Variables declaration - do not modify//GEN-BEGIN:variables
244
private javax.swing.JLabel JavaDoc category;
245     private javax.swing.JComboBox JavaDoc categoryValue;
246     private javax.swing.JPanel JavaDoc hackPanel;
247     private javax.swing.JLabel JavaDoc longDesc;
248     private javax.swing.JTextArea JavaDoc longDescValue;
249     private javax.swing.JScrollPane JavaDoc longDescValueSP;
250     private javax.swing.JLabel JavaDoc name;
251     private javax.swing.JTextField JavaDoc nameValue;
252     private javax.swing.JLabel JavaDoc shortDesc;
253     private javax.swing.JTextField JavaDoc shortDescValue;
254     // End of variables declaration//GEN-END:variables
255

256     private static String JavaDoc getMessage(String JavaDoc key) {
257         return NbBundle.getMessage(CustomizerDisplay.class, key);
258     }
259     
260     private void initAccesibility() {
261         longDescValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_LongDescValue"));
262         nameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_NameValue"));
263         shortDescValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ShortDescValue"));
264     }
265     
266 }
267
Popular Tags