KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > wizards > PanelOptionsVisual


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
21 package org.netbeans.modules.java.j2seproject.ui.wizards;
22
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import javax.swing.event.DocumentEvent JavaDoc;
31 import org.openide.WizardDescriptor;
32 import org.openide.WizardValidationException;
33 import org.openide.util.NbBundle;
34 import org.openide.util.Utilities;
35
36 /**
37  * @author phrebejk
38  */

39 public class PanelOptionsVisual extends SettingsPanel implements ActionListener JavaDoc, PropertyChangeListener JavaDoc {
40     
41     private static boolean lastMainClassCheck = true; // XXX Store somewhere
42

43     private PanelConfigureProject panel;
44     private boolean valid;
45     
46     public PanelOptionsVisual(PanelConfigureProject panel, NewJ2SEProjectWizardIterator.WizardType type) {
47         initComponents();
48         this.panel = panel;
49
50         switch (type) {
51             case LIB:
52                 setAsMainCheckBox.setVisible( false );
53                 createMainCheckBox.setVisible( false );
54                 mainClassTextField.setVisible( false );
55                 break;
56             case APP:
57                 createMainCheckBox.addActionListener( this );
58                 createMainCheckBox.setSelected( lastMainClassCheck );
59                 mainClassTextField.setEnabled( lastMainClassCheck );
60                 break;
61             case EXT:
62                 setAsMainCheckBox.setVisible( true );
63                 createMainCheckBox.setVisible( false );
64                 mainClassTextField.setVisible( false );
65                 break;
66         }
67         
68         this.mainClassTextField.getDocument().addDocumentListener( new DocumentListener JavaDoc () {
69             
70             public void insertUpdate(DocumentEvent JavaDoc e) {
71                 mainClassChanged ();
72             }
73             
74             public void removeUpdate(DocumentEvent JavaDoc e) {
75                 mainClassChanged ();
76             }
77             
78             public void changedUpdate(DocumentEvent JavaDoc e) {
79                 mainClassChanged ();
80             }
81             
82         });
83     }
84
85     public void actionPerformed( ActionEvent JavaDoc e ) {
86         if ( e.getSource() == createMainCheckBox ) {
87             lastMainClassCheck = createMainCheckBox.isSelected();
88             mainClassTextField.setEnabled( lastMainClassCheck );
89             this.panel.fireChangeEvent();
90         }
91     }
92     
93     public void propertyChange (PropertyChangeEvent JavaDoc event) {
94         if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event.getPropertyName())) {
95             String JavaDoc newProjectName = NewJ2SEProjectWizardIterator.getPackageName((String JavaDoc) event.getNewValue());
96             if (!Utilities.isJavaIdentifier(newProjectName)) {
97                 newProjectName = NbBundle.getMessage (PanelOptionsVisual.class, "TXT_PackageNameSuffix", newProjectName);
98             }
99             this.mainClassTextField.setText (MessageFormat.format(
100                 NbBundle.getMessage (PanelOptionsVisual.class,"TXT_ClassName"), new Object JavaDoc[] {newProjectName}
101             ));
102         }
103     }
104     
105     /** This method is called from within the constructor to
106      * initialize the form.
107      * WARNING: Do NOT modify this code. The content of this method is
108      * always regenerated by the Form Editor.
109      */

110     private void initComponents() {//GEN-BEGIN:initComponents
111
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
112
113         setAsMainCheckBox = new javax.swing.JCheckBox JavaDoc();
114         createMainCheckBox = new javax.swing.JCheckBox JavaDoc();
115         mainClassTextField = new javax.swing.JTextField JavaDoc();
116         jPanel1 = new javax.swing.JPanel JavaDoc();
117
118         setLayout(new java.awt.GridBagLayout JavaDoc());
119
120         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSN_PanelOptionsVisual"));
121         getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(PanelOptionsVisual.class, "ACSD_PanelOptionsVisual"));
122         setAsMainCheckBox.setSelected(true);
123         org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_setAsMainCheckBox"));
124         setAsMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
127         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
128         gridBagConstraints.weightx = 1.0;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
130         add(setAsMainCheckBox, gridBagConstraints);
131         setAsMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_setAsMainCheckBox"));
132         setAsMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_setAsMainCheckBox"));
133
134         createMainCheckBox.setSelected(true);
135         org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox, org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("LBL_createMainCheckBox"));
136         createMainCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
139         gridBagConstraints.weighty = 1.0;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
141         add(createMainCheckBox, gridBagConstraints);
142         createMainCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_createMainCheckBox"));
143         createMainCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSD_createMainCheckBox"));
144
145         mainClassTextField.setText("com.myapp.Main");
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
148         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
149         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
150         gridBagConstraints.weightx = 1.0;
151         gridBagConstraints.weighty = 1.0;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 0);
153         add(mainClassTextField, gridBagConstraints);
154         mainClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCN_mainClassTextFiled"));
155         mainClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_mainClassTextFiled"));
156
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
159         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
160         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
161         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
162         gridBagConstraints.weightx = 1.0;
163         gridBagConstraints.weighty = 1.0;
164         add(jPanel1, gridBagConstraints);
165         jPanel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ACSN_jPanel1"));
166         jPanel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(PanelOptionsVisual.class).getString("ASCD_jPanel1"));
167
168     }//GEN-END:initComponents
169

170     boolean valid(WizardDescriptor settings) {
171         if (mainClassTextField.isVisible () && mainClassTextField.isEnabled ()) {
172             if (!valid) {
173                 settings.putProperty( "WizardPanel_errorMessage", // NOI18N
174
NbBundle.getMessage(PanelOptionsVisual.class,"ERROR_IllegalMainClassName")); //NOI18N
175
}
176             return this.valid;
177         }
178         else {
179             return true;
180         }
181     }
182     
183     void read (WizardDescriptor d) {
184         //TODO:
185
}
186     
187     void validate (WizardDescriptor d) throws WizardValidationException {
188         // nothing to validate
189
}
190
191     void store( WizardDescriptor d ) {
192         d.putProperty( /*XXX Define somewhere */ "setAsMain", setAsMainCheckBox.isSelected() && setAsMainCheckBox.isVisible() ? Boolean.TRUE : Boolean.FALSE ); // NOI18N
193
d.putProperty( /*XXX Define somewhere */ "mainClass", createMainCheckBox.isSelected() && createMainCheckBox.isVisible() ? mainClassTextField.getText() : null ); // NOI18N
194
}
195     
196     // Variables declaration - do not modify//GEN-BEGIN:variables
197
private javax.swing.JCheckBox JavaDoc createMainCheckBox;
198     private javax.swing.JPanel JavaDoc jPanel1;
199     private javax.swing.JTextField JavaDoc mainClassTextField;
200     private javax.swing.JCheckBox JavaDoc setAsMainCheckBox;
201     // End of variables declaration//GEN-END:variables
202

203     private void mainClassChanged () {
204         String JavaDoc mainClassName = this.mainClassTextField.getText ();
205         StringTokenizer JavaDoc tk = new StringTokenizer JavaDoc (mainClassName, "."); //NOI18N
206
boolean valid = true;
207         while (tk.hasMoreTokens()) {
208             String JavaDoc token = tk.nextToken();
209             if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) {
210                 valid = false;
211                 break;
212             }
213         }
214         this.valid = valid;
215         this.panel.fireChangeEvent();
216     }
217 }
218
219
Popular Tags