001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2me.cdc.project.ui.wizards;
043:
044: import java.awt.BorderLayout;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.beans.PropertyChangeEvent;
048: import java.beans.PropertyChangeListener;
049: import java.text.MessageFormat;
050: import java.util.Properties;
051: import java.util.StringTokenizer;
052: import javax.swing.JPanel;
053: import javax.swing.event.DocumentEvent;
054: import javax.swing.event.DocumentListener;
055: import org.netbeans.api.java.platform.JavaPlatform;
056: import org.netbeans.api.java.platform.JavaPlatformManager;
057: import org.netbeans.api.java.platform.Specification;
058: import org.netbeans.modules.j2me.cdc.platform.CDCPlatform;
059: import org.openide.WizardDescriptor;
060: import org.openide.util.NbBundle;
061:
062: /**
063: *
064: * @author phrebejk
065: */
066: public class PanelOptionsVisual extends SettingsPanel implements
067: ActionListener, PropertyChangeListener {
068:
069: private static boolean lastMainClassCheck = true; // XXX Store somewhere
070:
071: protected PanelConfigureProject panel;
072: private boolean valid;
073: private int type;
074:
075: //private ProjectTypeProvider provider;
076: private PropertyChangeListener pcl;
077:
078: /** Creates new form PanelOptionsVisual */
079: public PanelOptionsVisual(final PanelConfigureProject panel,
080: int type) {
081: initComponents();
082: this .type = type;
083: this .panel = panel;
084:
085: pcl = new PropertyChangeListener() {
086: public void propertyChange(PropertyChangeEvent evt) {
087: panel.fireChangeEvent();
088: }
089: };
090:
091: switch (type) {
092: case NewCDCProjectWizardIterator.TYPE_LIB:
093: setAsMainCheckBox.setVisible(false);
094: createMainCheckBox.setVisible(false);
095: mainClassTextField.setVisible(false);
096: separator.setVisible(false);
097: break;
098: case NewCDCProjectWizardIterator.TYPE_APP:
099: createMainCheckBox.addActionListener(this );
100: createMainCheckBox.setSelected(lastMainClassCheck);
101: mainClassTextField.setEnabled(lastMainClassCheck);
102: separator.setVisible(true);
103: break;
104: case NewCDCProjectWizardIterator.TYPE_EXT:
105: setAsMainCheckBox.setVisible(true);
106: createMainCheckBox.setVisible(false);
107: mainClassTextField.setVisible(false);
108: break;
109: case NewCDCProjectWizardIterator.TYPE_SAMPLE:
110: createMainCheckBox.setVisible(false);
111: mainClassTextField.setVisible(false);
112: separator.setVisible(true);
113: break;
114: }
115:
116: this .mainClassTextField.getDocument().addDocumentListener(
117: new DocumentListener() {
118:
119: public void insertUpdate(DocumentEvent e) {
120: mainClassChanged();
121: }
122:
123: public void removeUpdate(DocumentEvent e) {
124: mainClassChanged();
125: }
126:
127: public void changedUpdate(DocumentEvent e) {
128: mainClassChanged();
129: }
130:
131: });
132:
133: }
134:
135: public void actionPerformed(ActionEvent e) {
136: if (e.getSource() == createMainCheckBox) {
137: lastMainClassCheck = createMainCheckBox.isSelected();
138: mainClassTextField.setEnabled(lastMainClassCheck);
139: this .panel.fireChangeEvent();
140: }
141: }
142:
143: public void propertyChange(PropertyChangeEvent event) {
144: if (PanelProjectLocationVisual.PROP_PROJECT_NAME.equals(event
145: .getPropertyName())) {
146: String newProjectName = NewCDCProjectWizardIterator
147: .getPackageName((String) event.getNewValue());
148: this .mainClassTextField.setText(MessageFormat.format(
149: NbBundle.getMessage(PanelOptionsVisual.class,
150: "TXT_ClassName"),
151: new Object[] { newProjectName }));
152: }
153: }
154:
155: /** This method is called from within the constructor to
156: * initialize the form.
157: * WARNING: Do NOT modify this code. The content of this method is
158: * always regenerated by the Form Editor.
159: */
160: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
161: private void initComponents() {
162: java.awt.GridBagConstraints gridBagConstraints;
163:
164: setAsMainCheckBox = new javax.swing.JCheckBox();
165: createMainCheckBox = new javax.swing.JCheckBox();
166: mainClassTextField = new javax.swing.JTextField();
167: separator = new javax.swing.JSeparator();
168: containerPanel = new javax.swing.JPanel();
169:
170: setLayout(new java.awt.GridBagLayout());
171:
172: setAsMainCheckBox.setSelected(true);
173: org.openide.awt.Mnemonics.setLocalizedText(setAsMainCheckBox,
174: org.openide.util.NbBundle.getBundle(
175: PanelOptionsVisual.class).getString(
176: "LBL_setAsMainCheckBox")); // NOI18N
177: setAsMainCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
178: gridBagConstraints = new java.awt.GridBagConstraints();
179: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
180: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
181: gridBagConstraints.weightx = 1.0;
182: gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
183: add(setAsMainCheckBox, gridBagConstraints);
184: setAsMainCheckBox.getAccessibleContext().setAccessibleName(
185: org.openide.util.NbBundle.getBundle(
186: PanelOptionsVisual.class).getString(
187: "ACSN_setAsMainCheckBox")); // NOI18N
188: setAsMainCheckBox.getAccessibleContext()
189: .setAccessibleDescription(
190: org.openide.util.NbBundle.getBundle(
191: PanelOptionsVisual.class).getString(
192: "ACSD_setAsMainCheckBox")); // NOI18N
193:
194: createMainCheckBox.setSelected(true);
195: org.openide.awt.Mnemonics.setLocalizedText(createMainCheckBox,
196: org.openide.util.NbBundle.getBundle(
197: PanelOptionsVisual.class).getString(
198: "LBL_createMainCheckBox")); // NOI18N
199: createMainCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
200: gridBagConstraints = new java.awt.GridBagConstraints();
201: gridBagConstraints.gridx = 0;
202: gridBagConstraints.gridy = 1;
203: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
204: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
205: add(createMainCheckBox, gridBagConstraints);
206: createMainCheckBox.getAccessibleContext().setAccessibleName(
207: org.openide.util.NbBundle.getBundle(
208: PanelOptionsVisual.class).getString(
209: "ACSN_createMainCheckBox")); // NOI18N
210: createMainCheckBox.getAccessibleContext()
211: .setAccessibleDescription(
212: org.openide.util.NbBundle.getBundle(
213: PanelOptionsVisual.class).getString(
214: "ACSD_createMainCheckBox")); // NOI18N
215:
216: mainClassTextField.setText("com.myapp.Main");
217: gridBagConstraints = new java.awt.GridBagConstraints();
218: gridBagConstraints.gridx = 1;
219: gridBagConstraints.gridy = 1;
220: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
221: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222: gridBagConstraints.weightx = 1.0;
223: gridBagConstraints.insets = new java.awt.Insets(0, 6, 5, 0);
224: add(mainClassTextField, gridBagConstraints);
225: mainClassTextField.getAccessibleContext().setAccessibleName(
226: org.openide.util.NbBundle.getBundle(
227: PanelOptionsVisual.class).getString(
228: "ASCN_mainClassTextFiled")); // NOI18N
229: mainClassTextField.getAccessibleContext()
230: .setAccessibleDescription(
231: org.openide.util.NbBundle.getBundle(
232: PanelOptionsVisual.class).getString(
233: "ASCD_mainClassTextFiled")); // NOI18N
234:
235: gridBagConstraints = new java.awt.GridBagConstraints();
236: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
237: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
238: add(separator, gridBagConstraints);
239:
240: containerPanel.setLayout(new java.awt.BorderLayout());
241: gridBagConstraints = new java.awt.GridBagConstraints();
242: gridBagConstraints.gridx = 0;
243: gridBagConstraints.gridy = 4;
244: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
245: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
246: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
247: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
248: add(containerPanel, gridBagConstraints);
249:
250: getAccessibleContext().setAccessibleName(
251: org.openide.util.NbBundle.getMessage(
252: PanelOptionsVisual.class,
253: "ACSN_PanelOptionsVisual")); // NOI18N
254: getAccessibleContext().setAccessibleDescription(
255: org.openide.util.NbBundle.getMessage(
256: PanelOptionsVisual.class,
257: "ACSD_PanelOptionsVisual")); // NOI18N
258: }// </editor-fold>//GEN-END:initComponents
259:
260: boolean valid(WizardDescriptor settings) {
261: if (mainClassTextField.isVisible()
262: && mainClassTextField.isEnabled()) {
263: if (!valid) {
264: settings.putProperty("WizardPanel_errorMessage", // NOI18N
265: NbBundle.getMessage(PanelOptionsVisual.class,
266: "ERROR_IllegalMainClassName")); //NOI18N
267: }
268: return this .valid;
269: }
270: return true;
271: }
272:
273: void read(WizardDescriptor d) {
274:
275: JavaPlatform platforms[] = JavaPlatformManager.getDefault()
276: .getPlatforms(
277: null,
278: new Specification(CDCPlatform.PLATFORM_CDC,
279: null)); //NOI18N
280: if (platforms.length != 0
281: && platforms[0] instanceof CDCPlatform) {
282: CDCPlatform platform = (CDCPlatform) platforms[0];
283: assert platform != null;
284: }
285: }
286:
287: void validate(WizardDescriptor d) {
288: // nothing to validate
289: }
290:
291: void store(WizardDescriptor d) {
292: d.putProperty( /*XXX Define somewhere */"setAsMain",
293: setAsMainCheckBox.isSelected()
294: && setAsMainCheckBox.isVisible() ? Boolean.TRUE
295: : Boolean.FALSE); // NOI18N
296: d
297: .putProperty(
298: /*XXX Define somewhere */"mainClass",
299: createMainCheckBox.isSelected()
300: && createMainCheckBox.isVisible() ? mainClassTextField
301: .getText()
302: : null); // NOI18N
303: }
304:
305: // Variables declaration - do not modify//GEN-BEGIN:variables
306: private javax.swing.JPanel containerPanel;
307: private javax.swing.JCheckBox createMainCheckBox;
308: private javax.swing.JTextField mainClassTextField;
309: private javax.swing.JSeparator separator;
310: private javax.swing.JCheckBox setAsMainCheckBox;
311:
312: // End of variables declaration//GEN-END:variables
313:
314: protected void mainClassChanged() {
315: String mainClassName = this .mainClassTextField.getText();
316: StringTokenizer tk = new StringTokenizer(mainClassName, "."); //NOI18N
317: boolean valid = true;
318: out: while (tk.hasMoreTokens()) {
319: String token = tk.nextToken();
320: if (token.length() == 0) {
321: valid = false;
322: break out;
323: }
324: for (int i = 0; i < token.length(); i++) {
325: if ((i == 0 && !Character.isJavaIdentifierStart(token
326: .charAt(0)))
327: || (i != 0 && !Character
328: .isJavaIdentifierPart(token.charAt(i)))) {
329: valid = false;
330: break out;
331: }
332: }
333: }
334: this.valid = valid;
335: this.panel.fireChangeEvent();
336: }
337: }
|