KickJava   Java API By Example, From Geeks To Geeks.

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


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.wizard;
21
22 import javax.swing.event.DocumentEvent JavaDoc;
23 import org.netbeans.modules.apisupport.project.ui.UIUtil;
24 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
25 import org.openide.WizardDescriptor;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.NbBundle;
28
29 /**
30  * The first panel in the <em>New Wizard Wizard</em>.
31  *
32  * @author Martin Krauskopf
33  */

34 final class WizardTypePanel extends BasicWizardIterator.Panel {
35
36     private DataModel data;
37     private boolean firstTime = true;
38     private boolean lastStaticValue = true;
39     
40     public WizardTypePanel(final WizardDescriptor setting, final DataModel data) {
41         super(setting);
42         this.data = data;
43         initComponents();
44         initAccessibility();
45         putClientProperty("NewFileWizard_Title", getMessage("LBL_WizardWizardTitle"));
46         numberOfSteps.getDocument().addDocumentListener(new UIUtil.DocumentAdapter() {
47             public void insertUpdate(DocumentEvent JavaDoc e) {
48                 checkValidity();
49             }
50         });
51     }
52     
53     protected String JavaDoc getPanelName() {
54         return getMessage("LBL_WizardType_Title");
55     }
56     
57     protected void storeToDataModel() {
58         data.setBranching(dynamic.isSelected());
59         data.setFileTemplateType(newFile.isSelected());
60         data.setNumberOfSteps(getNumberOfSteps());
61     }
62     
63     private int getNumberOfSteps() {
64         return Integer.parseInt(numberOfSteps.getText().trim());
65     }
66     
67     protected void readFromDataModel() {
68         if (firstTime) {
69             firstTime = false;
70             markInvalid();
71         } else {
72             checkValidity();
73         }
74     }
75     
76     private void checkValidity() {
77         if (!isNumberOfStepsValid()) {
78             setError(getMessage("MSG_IncorrectNumberOfSteps"));
79         } else {
80             markValid();
81         }
82     }
83     
84     private boolean isNumberOfStepsValid() {
85         try {
86             return getNumberOfSteps() > 0;
87         } catch (NumberFormatException JavaDoc nfe) {
88             return false;
89         }
90     }
91     
92     protected HelpCtx getHelp() {
93         return new HelpCtx(WizardTypePanel.class);
94     }
95     
96     private void initAccessibility() {
97         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_WizardTypePanel"));
98         custom.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Custom"));
99         newFile.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_NewFile"));
100         statik.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Static"));
101         dynamic.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_Dynamic"));
102         numberOfStepsTxt.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_NumberOfSteps"));
103     }
104     
105     private static String JavaDoc getMessage(String JavaDoc key) {
106         return NbBundle.getMessage(WizardTypePanel.class, key);
107     }
108     
109     /** This method is called from within the constructor to
110      * initialize the form.
111      * WARNING: Do NOT modify this code. The content of this method is
112      * always regenerated by the Form Editor.
113      */

114     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
115
private void initComponents() {
116         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
117
118         registrationType = new javax.swing.ButtonGroup JavaDoc();
119         wizardSteps = new javax.swing.ButtonGroup JavaDoc();
120         registrationTypeTxt = new javax.swing.JLabel JavaDoc();
121         custom = new javax.swing.JRadioButton JavaDoc();
122         newFile = new javax.swing.JRadioButton JavaDoc();
123         wizardStepsTxt = new javax.swing.JLabel JavaDoc();
124         statik = new javax.swing.JRadioButton JavaDoc();
125         dynamic = new javax.swing.JRadioButton JavaDoc();
126         numberOfStepsTxt = new javax.swing.JLabel JavaDoc();
127         numberOfSteps = new javax.swing.JTextField JavaDoc();
128         filler = new javax.swing.JLabel JavaDoc();
129
130         setLayout(new java.awt.GridBagLayout JavaDoc());
131
132         org.openide.awt.Mnemonics.setLocalizedText(registrationTypeTxt, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "LBL_RegistrationType"));
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 0;
135         gridBagConstraints.gridy = 0;
136         gridBagConstraints.gridwidth = 2;
137         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
138         add(registrationTypeTxt, gridBagConstraints);
139
140         registrationType.add(custom);
141         custom.setSelected(true);
142         org.openide.awt.Mnemonics.setLocalizedText(custom, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "CTL_Custom"));
143         custom.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
144         custom.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
145         custom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
146             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
147                 typeChanged(evt);
148             }
149         });
150
151         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
152         gridBagConstraints.gridx = 0;
153         gridBagConstraints.gridy = 1;
154         gridBagConstraints.gridwidth = 2;
155         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
156         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 0, 0);
157         add(custom, gridBagConstraints);
158
159         registrationType.add(newFile);
160         org.openide.awt.Mnemonics.setLocalizedText(newFile, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "CTL_NewFile"));
161         newFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
162         newFile.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
163         newFile.addActionListener(new java.awt.event.ActionListener JavaDoc() {
164             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
165                 typeChanged(evt);
166             }
167         });
168
169         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 2;
172         gridBagConstraints.gridwidth = 2;
173         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
174         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 0, 0);
175         add(newFile, gridBagConstraints);
176
177         org.openide.awt.Mnemonics.setLocalizedText(wizardStepsTxt, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "LBL_WizardSteps"));
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
179         gridBagConstraints.gridx = 0;
180         gridBagConstraints.gridy = 3;
181         gridBagConstraints.gridwidth = 2;
182         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
183         gridBagConstraints.insets = new java.awt.Insets JavaDoc(24, 0, 0, 0);
184         add(wizardStepsTxt, gridBagConstraints);
185
186         wizardSteps.add(statik);
187         statik.setSelected(true);
188         org.openide.awt.Mnemonics.setLocalizedText(statik, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "CTL_Static"));
189         statik.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
190         statik.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
191         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
192         gridBagConstraints.gridx = 0;
193         gridBagConstraints.gridy = 4;
194         gridBagConstraints.gridwidth = 2;
195         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 0, 0);
197         add(statik, gridBagConstraints);
198
199         wizardSteps.add(dynamic);
200         org.openide.awt.Mnemonics.setLocalizedText(dynamic, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "CTL_Dynamic"));
201         dynamic.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
202         dynamic.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 0;
205         gridBagConstraints.gridy = 5;
206         gridBagConstraints.gridwidth = 2;
207         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
208         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 18, 24, 0);
209         add(dynamic, gridBagConstraints);
210
211         numberOfStepsTxt.setLabelFor(numberOfSteps);
212         org.openide.awt.Mnemonics.setLocalizedText(numberOfStepsTxt, org.openide.util.NbBundle.getMessage(WizardTypePanel.class, "LBL_NumberOfSteps"));
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
214         gridBagConstraints.gridx = 0;
215         gridBagConstraints.gridy = 6;
216         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
217         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 0, 3, 0);
218         add(numberOfStepsTxt, gridBagConstraints);
219
220         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
221         gridBagConstraints.gridx = 1;
222         gridBagConstraints.gridy = 6;
223         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
224         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
225         gridBagConstraints.weightx = 1.0;
226         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 6, 3, 0);
227         add(numberOfSteps, gridBagConstraints);
228
229         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
230         gridBagConstraints.gridx = 0;
231         gridBagConstraints.gridy = 7;
232         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
233         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
234         gridBagConstraints.weightx = 1.0;
235         gridBagConstraints.weighty = 1.0;
236         add(filler, gridBagConstraints);
237
238     }
239     // </editor-fold>//GEN-END:initComponents
240

241     private void typeChanged(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_typeChanged
242
boolean isCustom = custom.isSelected();
243         statik.setEnabled(isCustom);
244         dynamic.setEnabled(isCustom);
245         if (isCustom) {
246             statik.setSelected(lastStaticValue);
247         } else {
248             lastStaticValue = statik.isSelected();
249             dynamic.setSelected(true);
250         }
251     }//GEN-LAST:event_typeChanged
252

253     // Variables declaration - do not modify//GEN-BEGIN:variables
254
private javax.swing.JRadioButton JavaDoc custom;
255     private javax.swing.JRadioButton JavaDoc dynamic;
256     private javax.swing.JLabel JavaDoc filler;
257     private javax.swing.JRadioButton JavaDoc newFile;
258     private javax.swing.JTextField JavaDoc numberOfSteps;
259     private javax.swing.JLabel JavaDoc numberOfStepsTxt;
260     private javax.swing.ButtonGroup JavaDoc registrationType;
261     private javax.swing.JLabel JavaDoc registrationTypeTxt;
262     private javax.swing.JRadioButton JavaDoc statik;
263     private javax.swing.ButtonGroup JavaDoc wizardSteps;
264     private javax.swing.JLabel JavaDoc wizardStepsTxt;
265     // End of variables declaration//GEN-END:variables
266

267 }
268
Popular Tags