KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > options > OptionsPanel0


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.wizard.options;
21
22 import java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import javax.swing.event.DocumentListener JavaDoc;
26 import org.netbeans.modules.apisupport.project.ui.UIUtil;
27 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
28 import org.openide.WizardDescriptor;
29 import org.openide.util.HelpCtx;
30 import org.openide.util.NbBundle;
31
32 /**
33  * @author Radek Matous
34  */

35 final class OptionsPanel0 extends BasicWizardIterator.Panel {
36     private NewOptionsIterator.DataModel data;
37     private DocumentListener JavaDoc fieldsDL;
38     
39     public OptionsPanel0(final WizardDescriptor setting, final NewOptionsIterator.DataModel data) {
40         super(setting);
41         this.data = data;
42         initComponents();
43         initAccessibility();
44         putClientProperty("NewFileWizard_Title",// NOI18N
45
NbBundle.getMessage(OptionsPanel0.class,"LBL_OptionsWizardTitle")); // NOI18N
46

47     }
48     
49     private void addListeners() {
50         if (fieldsDL == null) {
51             fieldsDL = new UIUtil.DocumentAdapter() {
52                 public void insertUpdate(DocumentEvent JavaDoc e) { updateData(); }
53             };
54             
55             categoryNameField.getDocument().addDocumentListener(fieldsDL);
56             displayNameField1.getDocument().addDocumentListener(fieldsDL);
57             iconField.getDocument().addDocumentListener(fieldsDL);
58             titleField.getDocument().addDocumentListener(fieldsDL);
59             tooltipField1.getDocument().addDocumentListener(fieldsDL);
60         }
61     }
62     
63     private void removeListeners() {
64         if (fieldsDL != null) {
65             categoryNameField.getDocument().removeDocumentListener(fieldsDL);
66             displayNameField1.getDocument().removeDocumentListener(fieldsDL);
67             iconField.getDocument().removeDocumentListener(fieldsDL);
68             titleField.getDocument().removeDocumentListener(fieldsDL);
69             tooltipField1.getDocument().removeDocumentListener(fieldsDL);
70             fieldsDL = null;
71         }
72     }
73     
74     
75     protected void storeToDataModel() {
76         removeListeners();
77         updateData();
78     }
79     protected void readFromDataModel() {
80         addListeners();
81     }
82     
83     private void updateData() {
84         int retCode = 0;
85         if (advancedButton.isSelected()) {
86             assert !optionsCategoryButton.isSelected();
87             retCode = data.setDataForAdvanced(displayNameField1.getText(), tooltipField1.getText());
88         } else {
89             assert optionsCategoryButton.isSelected();
90             retCode = data.setDataForOptionCategory(titleField.getText(),
91                     categoryNameField.getText(), iconField.getText());
92         }
93         if (data.isSuccessCode(retCode)) {
94             markValid();
95         } else if (data.isErrorCode(retCode)) {
96             setError(data.getErrorMessage(retCode));
97         } else if (data.isWarningCode(retCode)) {
98             setWarning(data.getWarningMessage(retCode));
99         } else {
100             assert false : retCode;
101         }
102     }
103     
104     protected String JavaDoc getPanelName() {
105         return NbBundle.getMessage(OptionsPanel0.class,"LBL_OptionsPanel0_Title"); // NOI18N
106
}
107     
108     
109     protected HelpCtx getHelp() {
110         return new HelpCtx(OptionsPanel0.class);
111     }
112     
113     private static String JavaDoc getMessage(String JavaDoc key) {
114         return NbBundle.getMessage(OptionsPanel0.class, key);
115     }
116     
117     private void initAccessibility() {
118         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_OptionsPanel0"));
119         advancedButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Advanced"));
120         optionsCategoryButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_OptionsCategory"));
121         titleField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Title"));
122         tooltipField1.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Tooltip"));
123         displayNameField1.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_DisplayName"));
124         categoryNameField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_CategoryName"));
125         iconField.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconPath"));
126         iconButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_IconButton"));
127     }
128     
129     public void addNotify() {
130         super.addNotify();
131         addListeners();
132         updateData();
133     }
134     
135     public void removeNotify() {
136         super.removeNotify();
137         removeListeners();
138     }
139     
140     private void enableDisable() {
141         boolean advancedEnabled = advancedButton.isSelected();
142         assert advancedEnabled != optionsCategoryButton.isSelected();
143         
144         categoryNameField.setEnabled(!advancedEnabled);
145         categoryNameLbl.setEnabled(!advancedEnabled);
146         iconButton.setEnabled(!advancedEnabled);
147         iconField.setEnabled(!advancedEnabled);
148         iconLbl.setEnabled(!advancedEnabled);
149         titleField.setEnabled(!advancedEnabled);
150         titleLbl.setEnabled(!advancedEnabled);
151         
152         displayNameField1.setEnabled(advancedEnabled);
153         displayNameLbl1.setEnabled(advancedEnabled);
154         tooltipField1.setEnabled(advancedEnabled);
155         tooltipLbl1.setEnabled(advancedEnabled);
156     }
157     
158     /** This method is called from within the constructor to
159      * initialize the form.
160      * WARNING: Do NOT modify this code. The content of this method is
161      * always regenerated by the Form Editor.
162      */

163     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
164
private void initComponents() {
165         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
166
167         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
168         advancedButton = new javax.swing.JRadioButton JavaDoc();
169         optionsCategoryButton = new javax.swing.JRadioButton JavaDoc();
170         dummyPanel = new javax.swing.JPanel JavaDoc();
171         categoryNameLbl = new javax.swing.JLabel JavaDoc();
172         categoryNameField = new javax.swing.JTextField JavaDoc();
173         displayNameLbl1 = new javax.swing.JLabel JavaDoc();
174         displayNameField1 = new javax.swing.JTextField JavaDoc();
175         tooltipLbl1 = new javax.swing.JLabel JavaDoc();
176         tooltipField1 = new javax.swing.JTextField JavaDoc();
177         titleLbl = new javax.swing.JLabel JavaDoc();
178         titleField = new javax.swing.JTextField JavaDoc();
179         iconLbl = new javax.swing.JLabel JavaDoc();
180         iconField = new javax.swing.JTextField JavaDoc();
181         iconButton = new javax.swing.JButton JavaDoc();
182
183         setLayout(new java.awt.GridBagLayout JavaDoc());
184
185         buttonGroup1.add(advancedButton);
186         advancedButton.setSelected(true);
187         org.openide.awt.Mnemonics.setLocalizedText(advancedButton, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Advanced"));
188         advancedButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
189         advancedButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
190         advancedButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
191             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
192                 advancedButtonActionPerformed(evt);
193             }
194         });
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
198         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
199         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
200         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
201         add(advancedButton, gridBagConstraints);
202
203         buttonGroup1.add(optionsCategoryButton);
204         org.openide.awt.Mnemonics.setLocalizedText(optionsCategoryButton, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_OptionsCategory"));
205         optionsCategoryButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
206         optionsCategoryButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
207         optionsCategoryButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
208             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
209                 optionsCategoryButtonActionPerformed(evt);
210             }
211         });
212
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
214         gridBagConstraints.gridx = 0;
215         gridBagConstraints.gridy = 3;
216         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
217         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
218         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
219         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
220         add(optionsCategoryButton, gridBagConstraints);
221
222         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
223         gridBagConstraints.gridx = 0;
224         gridBagConstraints.gridy = 7;
225         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
226         gridBagConstraints.weightx = 1.0;
227         gridBagConstraints.weighty = 1.0;
228         add(dummyPanel, gridBagConstraints);
229
230         categoryNameLbl.setLabelFor(categoryNameField);
231         org.openide.awt.Mnemonics.setLocalizedText(categoryNameLbl, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_CategoryName"));
232         categoryNameLbl.setEnabled(false);
233         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
234         gridBagConstraints.gridx = 0;
235         gridBagConstraints.gridy = 5;
236         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
237         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 18, 6, 12);
238         add(categoryNameLbl, gridBagConstraints);
239
240         categoryNameField.setEnabled(false);
241         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
242         gridBagConstraints.gridx = 1;
243         gridBagConstraints.gridy = 5;
244         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
245         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
246         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
247         gridBagConstraints.weightx = 1.0;
248         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
249         add(categoryNameField, gridBagConstraints);
250
251         displayNameLbl1.setLabelFor(displayNameField1);
252         org.openide.awt.Mnemonics.setLocalizedText(displayNameLbl1, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_DisplaName"));
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 1;
256         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
257         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 18, 6, 12);
258         add(displayNameLbl1, gridBagConstraints);
259
260         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
261         gridBagConstraints.gridx = 1;
262         gridBagConstraints.gridy = 1;
263         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
264         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
265         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
266         gridBagConstraints.weightx = 1.0;
267         add(displayNameField1, gridBagConstraints);
268
269         tooltipLbl1.setLabelFor(tooltipField1);
270         org.openide.awt.Mnemonics.setLocalizedText(tooltipLbl1, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Tooltip"));
271         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
272         gridBagConstraints.gridx = 0;
273         gridBagConstraints.gridy = 2;
274         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
275         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 6, 12);
276         add(tooltipLbl1, gridBagConstraints);
277
278         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
279         gridBagConstraints.gridx = 1;
280         gridBagConstraints.gridy = 2;
281         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
282         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
283         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
284         gridBagConstraints.weightx = 1.0;
285         add(tooltipField1, gridBagConstraints);
286
287         titleLbl.setLabelFor(titleField);
288         org.openide.awt.Mnemonics.setLocalizedText(titleLbl, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle").getString("LBL_Title"));
289         titleLbl.setEnabled(false);
290         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
291         gridBagConstraints.gridx = 0;
292         gridBagConstraints.gridy = 4;
293         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
294         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 6, 12);
295         add(titleLbl, gridBagConstraints);
296
297         titleField.setEnabled(false);
298         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
299         gridBagConstraints.gridx = 1;
300         gridBagConstraints.gridy = 4;
301         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
302         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
303         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
304         gridBagConstraints.weightx = 1.0;
305         add(titleField, gridBagConstraints);
306
307         iconLbl.setLabelFor(iconField);
308         org.openide.awt.Mnemonics.setLocalizedText(iconLbl, org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "LBL_Icon"));
309         iconLbl.setEnabled(false);
310         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
311         gridBagConstraints.gridx = 0;
312         gridBagConstraints.gridy = 6;
313         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
314         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 18, 0, 0);
315         add(iconLbl, gridBagConstraints);
316
317         iconField.setEditable(false);
318         iconField.setText(org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "CTL_None"));
319         iconField.setEnabled(false);
320         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
321         gridBagConstraints.gridx = 1;
322         gridBagConstraints.gridy = 6;
323         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
324         gridBagConstraints.weightx = 1.0;
325         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
326         add(iconField, gridBagConstraints);
327
328         org.openide.awt.Mnemonics.setLocalizedText(iconButton, org.openide.util.NbBundle.getMessage(OptionsPanel0.class, "LBL_Icon_Browse"));
329         iconButton.setEnabled(false);
330         iconButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
331             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
332                 iconButtonActionPerformed(evt);
333             }
334         });
335
336         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
337         gridBagConstraints.gridx = 2;
338         gridBagConstraints.gridy = 6;
339         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340         gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
341         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
342         add(iconButton, gridBagConstraints);
343
344     }// </editor-fold>//GEN-END:initComponents
345

346     private void optionsCategoryButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_optionsCategoryButtonActionPerformed
347
enableDisable();
348         updateData();
349     }//GEN-LAST:event_optionsCategoryButtonActionPerformed
350

351     private void advancedButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_advancedButtonActionPerformed
352
enableDisable();
353         updateData();
354     }//GEN-LAST:event_advancedButtonActionPerformed
355

356     private void iconButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_iconButtonActionPerformed
357
JFileChooser JavaDoc chooser = UIUtil.getIconFileChooser(iconField.getText());
358         int ret = chooser.showDialog(this, getMessage("LBL_Select")); // NOI18N
359
if (ret == JFileChooser.APPROVE_OPTION) {
360             File JavaDoc iconFile = chooser.getSelectedFile();
361             iconField.setText(iconFile.getAbsolutePath());
362             //updateData();
363
}
364     }//GEN-LAST:event_iconButtonActionPerformed
365

366     // Variables declaration - do not modify//GEN-BEGIN:variables
367
private javax.swing.JRadioButton JavaDoc advancedButton;
368     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
369     private javax.swing.JTextField JavaDoc categoryNameField;
370     private javax.swing.JLabel JavaDoc categoryNameLbl;
371     private javax.swing.JTextField JavaDoc displayNameField1;
372     private javax.swing.JLabel JavaDoc displayNameLbl1;
373     private javax.swing.JPanel JavaDoc dummyPanel;
374     private javax.swing.JButton JavaDoc iconButton;
375     private javax.swing.JTextField JavaDoc iconField;
376     private javax.swing.JLabel JavaDoc iconLbl;
377     private javax.swing.JRadioButton JavaDoc optionsCategoryButton;
378     private javax.swing.JTextField JavaDoc titleField;
379     private javax.swing.JLabel JavaDoc titleLbl;
380     private javax.swing.JTextField JavaDoc tooltipField1;
381     private javax.swing.JLabel JavaDoc tooltipLbl1;
382     // End of variables declaration//GEN-END:variables
383

384 }
385
Popular Tags