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-2007 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: package org.netbeans.modules.visualweb.samples.bundled.wizard;
042:
043: import java.io.File;
044: import javax.swing.JFileChooser;
045: import javax.swing.JPanel;
046: import javax.swing.event.DocumentEvent;
047: import javax.swing.event.DocumentListener;
048: import javax.swing.text.Document;
049:
050: import org.netbeans.spi.project.ui.support.ProjectChooser;
051: import org.openide.WizardDescriptor;
052: import org.openide.filesystems.FileUtil;
053: import org.openide.util.NbBundle;
054:
055: public final class SamplesWebVisualPanel extends JPanel implements
056: DocumentListener {
057: private SamplesWebWizardPanel panel;
058:
059: /**
060: * Creates new form SamplesWebVisualPanel
061: */
062: public SamplesWebVisualPanel(SamplesWebWizardPanel panel) {
063: initComponents();
064: this .panel = panel;
065: // Register listener on the textFields to make the automatic updates
066: this .projectNameField.getDocument().addDocumentListener(this );
067: this .projectLocationField.getDocument().addDocumentListener(
068: this );
069: }
070:
071: public String getName() {
072: return "Name and Location";
073: }
074:
075: // Implementation of DocumentListener --------------------------------------
076:
077: public void changedUpdate(DocumentEvent e) {
078: update(e);
079: }
080:
081: public void insertUpdate(DocumentEvent e) {
082: update(e);
083: }
084:
085: public void removeUpdate(DocumentEvent e) {
086: update(e);
087: }
088:
089: private void update(DocumentEvent de) {
090: if (this .projectNameField.getDocument() == de.getDocument()) {
091: firePropertyChange(WizardProperties.NAME, null,
092: projectNameField.getText());
093: }
094: if (this .projectLocationField.getDocument() == de.getDocument()) {
095: firePropertyChange(WizardProperties.PROJ_DIR, null,
096: projectLocationField.getText());
097: }
098: Document doc = de.getDocument();
099: if (doc == projectNameField.getDocument()
100: || doc == projectLocationField.getDocument()) {
101: // Change in the project name
102: String projectName = projectNameField.getText();
103: String projectFolder = projectLocationField.getText();
104: projectFolderField.setText(projectFolder
105: + File.separatorChar + projectName);
106: }
107: this .panel.fireChangeEvent();
108: }
109:
110: void read(WizardDescriptor settings) {
111: File projectLocation = (File) settings
112: .getProperty(WizardProperties.PROJ_DIR);
113: if (projectLocation == null
114: || projectLocation.getParentFile() == null
115: || !projectLocation.getParentFile().isDirectory()) {
116: projectLocation = ProjectChooser.getProjectsFolder();
117: } else {
118: projectLocation = projectLocation.getParentFile();
119: }
120: this .projectLocationField.setText(projectLocation
121: .getAbsolutePath());
122: String projectName = (String) settings
123: .getProperty(WizardProperties.NAME);
124: if (projectName == null) {
125: projectName = "Sample"; //NOI18N
126: }
127: this .projectNameField.setText(projectName);
128: this .projectNameField.selectAll();
129: Boolean isSetMainProject = (Boolean) settings
130: .getProperty(WizardProperties.SET_MAIN_PROJ);
131: this .setAsMainProject.setSelected(isSetMainProject
132: .booleanValue());
133: }
134:
135: void store(WizardDescriptor settings) {
136: String name = projectNameField.getText().trim();
137: settings.putProperty(WizardProperties.NAME, name);
138: String folder = projectFolderField.getText().trim();
139: settings.putProperty(WizardProperties.PROJ_DIR,
140: new File(folder));
141: boolean isSetMainProject = setAsMainProject.isSelected();
142: settings.putProperty(WizardProperties.SET_MAIN_PROJ, Boolean
143: .valueOf(isSetMainProject));
144: }
145:
146: public String getProjectName() {
147: return this .projectNameField.getText();
148: }
149:
150: public String getProjectFolder() {
151: return this .projectFolderField.getText();
152: }
153:
154: public String getProjectLocation() {
155: return this .projectLocationField.getText();
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:
166: projectNameLabel = new javax.swing.JLabel();
167: projectNameField = new javax.swing.JTextField();
168: projectLocationLabel = new javax.swing.JLabel();
169: projectLocationField = new javax.swing.JTextField();
170: projectFolderLabel = new javax.swing.JLabel();
171: projectFolderField = new javax.swing.JTextField();
172: browseButton = new javax.swing.JButton();
173: jSeparator1 = new javax.swing.JSeparator();
174: setAsMainProject = new javax.swing.JCheckBox();
175:
176: projectNameLabel
177: .setDisplayedMnemonic(org.openide.util.NbBundle
178: .getMessage(SamplesWebVisualPanel.class,
179: "LBL_NWP1_ProjectName_LabelMnemonic")
180: .charAt(0));
181: projectNameLabel.setLabelFor(projectNameField);
182: projectNameLabel.setText(org.openide.util.NbBundle.getMessage(
183: SamplesWebVisualPanel.class,
184: "LBL_NWP1_ProjectName_Label")); // NOI18N
185:
186: projectLocationLabel
187: .setDisplayedMnemonic(org.openide.util.NbBundle
188: .getMessage(SamplesWebVisualPanel.class,
189: "LBL_NWP1_ProjectLocation_LabelMnemonic")
190: .charAt(0));
191: projectLocationLabel.setLabelFor(projectLocationField);
192: projectLocationLabel.setText(org.openide.util.NbBundle
193: .getMessage(SamplesWebVisualPanel.class,
194: "LBL_NWP1_ProjectLocation_Label")); // NOI18N
195:
196: projectFolderLabel
197: .setDisplayedMnemonic(org.openide.util.NbBundle
198: .getMessage(SamplesWebVisualPanel.class,
199: "LBL_NWP1_CreatedProjectFolder_LabelMnemonic")
200: .charAt(0));
201: projectFolderLabel.setLabelFor(projectFolderField);
202: projectFolderLabel.setText(org.openide.util.NbBundle
203: .getMessage(SamplesWebVisualPanel.class,
204: "LBL_NWP1_CreatedProjectFolder_Label")); // NOI18N
205:
206: projectFolderField.setEnabled(false);
207:
208: browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(
209: SamplesWebVisualPanel.class,
210: "LBL_NWP1_Browse_LabelMnemonic").charAt(0));
211: browseButton.setText(org.openide.util.NbBundle.getMessage(
212: SamplesWebVisualPanel.class,
213: "LBL_NWP1_BrowseLocation_Button")); // NOI18N
214: browseButton
215: .addActionListener(new java.awt.event.ActionListener() {
216: public void actionPerformed(
217: java.awt.event.ActionEvent evt) {
218: browseButtonActionPerformed(evt);
219: }
220: });
221:
222: setAsMainProject.setMnemonic(org.openide.util.NbBundle
223: .getMessage(SamplesWebVisualPanel.class,
224: "LBL_NWP1_SetAsMain_CheckBoxMnemonic")
225: .charAt(0));
226: setAsMainProject.setSelected(true);
227: setAsMainProject.setText(org.openide.util.NbBundle.getMessage(
228: SamplesWebVisualPanel.class,
229: "LBL_NWP1_SetAsMain_CheckBox")); // NOI18N
230: setAsMainProject.setBorder(javax.swing.BorderFactory
231: .createEmptyBorder(0, 0, 0, 0));
232: setAsMainProject.setMargin(new java.awt.Insets(0, 0, 0, 0));
233:
234: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
235: this );
236: this .setLayout(layout);
237: layout
238: .setHorizontalGroup(layout
239: .createParallelGroup(
240: org.jdesktop.layout.GroupLayout.LEADING)
241: .add(
242: layout
243: .createSequentialGroup()
244: .addContainerGap()
245: .add(
246: layout
247: .createParallelGroup(
248: org.jdesktop.layout.GroupLayout.LEADING)
249: .add(
250: jSeparator1,
251: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
252: 482,
253: Short.MAX_VALUE)
254: .add(
255: layout
256: .createSequentialGroup()
257: .add(
258: layout
259: .createParallelGroup(
260: org.jdesktop.layout.GroupLayout.LEADING)
261: .add(
262: projectNameLabel)
263: .add(
264: projectLocationLabel)
265: .add(
266: projectFolderLabel))
267: .addPreferredGap(
268: org.jdesktop.layout.LayoutStyle.RELATED)
269: .add(
270: layout
271: .createParallelGroup(
272: org.jdesktop.layout.GroupLayout.LEADING)
273: .add(
274: projectNameField,
275: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
276: 287,
277: Short.MAX_VALUE)
278: .add(
279: projectFolderField,
280: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
281: 287,
282: Short.MAX_VALUE)
283: .add(
284: org.jdesktop.layout.GroupLayout.TRAILING,
285: layout
286: .createSequentialGroup()
287: .addPreferredGap(
288: org.jdesktop.layout.LayoutStyle.RELATED)
289: .add(
290: projectLocationField,
291: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
292: 287,
293: Short.MAX_VALUE)))
294: .addPreferredGap(
295: org.jdesktop.layout.LayoutStyle.RELATED)
296: .add(
297: browseButton))
298: .add(
299: setAsMainProject))
300: .addContainerGap()));
301: layout
302: .setVerticalGroup(layout
303: .createParallelGroup(
304: org.jdesktop.layout.GroupLayout.LEADING)
305: .add(
306: layout
307: .createSequentialGroup()
308: .addContainerGap()
309: .add(
310: layout
311: .createParallelGroup(
312: org.jdesktop.layout.GroupLayout.BASELINE)
313: .add(
314: projectNameLabel)
315: .add(
316: projectNameField,
317: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
318: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
319: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
320: .addPreferredGap(
321: org.jdesktop.layout.LayoutStyle.RELATED)
322: .add(
323: layout
324: .createParallelGroup(
325: org.jdesktop.layout.GroupLayout.BASELINE)
326: .add(
327: projectLocationLabel)
328: .add(
329: browseButton)
330: .add(
331: projectLocationField,
332: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
333: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
334: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
335: .addPreferredGap(
336: org.jdesktop.layout.LayoutStyle.RELATED)
337: .add(
338: layout
339: .createParallelGroup(
340: org.jdesktop.layout.GroupLayout.BASELINE)
341: .add(
342: projectFolderLabel)
343: .add(
344: projectFolderField,
345: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
346: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
347: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
348: .add(17, 17, 17)
349: .add(
350: jSeparator1,
351: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
352: 10,
353: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
354: .addPreferredGap(
355: org.jdesktop.layout.LayoutStyle.RELATED)
356: .add(setAsMainProject)
357: .addContainerGap(176,
358: Short.MAX_VALUE)));
359:
360: projectNameLabel.getAccessibleContext().setAccessibleName(
361: org.openide.util.NbBundle.getMessage(
362: SamplesWebVisualPanel.class,
363: "ACSN_projectNameLabel")); // NOI18N
364: projectNameLabel.getAccessibleContext()
365: .setAccessibleDescription(
366: org.openide.util.NbBundle.getMessage(
367: SamplesWebVisualPanel.class,
368: "ACSD_projectNameLabel")); // NOI18N
369: projectNameField.getAccessibleContext().setAccessibleName(
370: org.openide.util.NbBundle.getMessage(
371: SamplesWebVisualPanel.class,
372: "ACSN_projectNameTextfield")); // NOI18N
373: projectNameField.getAccessibleContext()
374: .setAccessibleDescription(
375: org.openide.util.NbBundle.getMessage(
376: SamplesWebVisualPanel.class,
377: "ACSD_projectNameTextfield")); // NOI18N
378: projectLocationLabel.getAccessibleContext().setAccessibleName(
379: org.openide.util.NbBundle.getMessage(
380: SamplesWebVisualPanel.class,
381: "ACSN_projectLocationLabel")); // NOI18N
382: projectLocationLabel.getAccessibleContext()
383: .setAccessibleDescription(
384: org.openide.util.NbBundle.getMessage(
385: SamplesWebVisualPanel.class,
386: "ACSD_projectLocationLabel")); // NOI18N
387: projectLocationField.getAccessibleContext().setAccessibleName(
388: org.openide.util.NbBundle.getMessage(
389: SamplesWebVisualPanel.class,
390: "ACSN_projectLocationTextfield")); // NOI18N
391: projectLocationField.getAccessibleContext()
392: .setAccessibleDescription(
393: org.openide.util.NbBundle.getMessage(
394: SamplesWebVisualPanel.class,
395: "ACSD_projectLocationTextfield")); // NOI18N
396: projectFolderLabel.getAccessibleContext().setAccessibleName(
397: org.openide.util.NbBundle.getMessage(
398: SamplesWebVisualPanel.class,
399: "ACSN_createdFolderLabel")); // NOI18N
400: projectFolderLabel.getAccessibleContext()
401: .setAccessibleDescription(
402: org.openide.util.NbBundle.getMessage(
403: SamplesWebVisualPanel.class,
404: "ACSD_createdFolderLabel")); // NOI18N
405: projectFolderField.getAccessibleContext().setAccessibleName(
406: org.openide.util.NbBundle.getMessage(
407: SamplesWebVisualPanel.class,
408: "ACSN_createdFolderTextfield")); // NOI18N
409: projectFolderField.getAccessibleContext()
410: .setAccessibleDescription(
411: org.openide.util.NbBundle.getMessage(
412: SamplesWebVisualPanel.class,
413: "ACSD_createdFolderTextfield")); // NOI18N
414: browseButton.getAccessibleContext().setAccessibleName(
415: org.openide.util.NbBundle.getMessage(
416: SamplesWebVisualPanel.class,
417: "ACSN_browseButton")); // NOI18N
418: browseButton.getAccessibleContext().setAccessibleDescription(
419: org.openide.util.NbBundle.getMessage(
420: SamplesWebVisualPanel.class,
421: "ACSD_browseButton")); // NOI18N
422: setAsMainProject.getAccessibleContext().setAccessibleName(
423: org.openide.util.NbBundle.getMessage(
424: SamplesWebVisualPanel.class,
425: "ACSN_SetAsMain_CheckBox")); // NOI18N
426: setAsMainProject.getAccessibleContext()
427: .setAccessibleDescription(
428: org.openide.util.NbBundle.getMessage(
429: SamplesWebVisualPanel.class,
430: "ACSD_SetAsMain_CheckBox")); // NOI18N
431: }// </editor-fold>//GEN-END:initComponents
432:
433: private void browseButtonActionPerformed(
434: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
435: // TODO add your handling code here:
436: JFileChooser chooser = new JFileChooser();
437: FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
438: chooser.setDialogTitle(NbBundle.getMessage(
439: SamplesWebVisualPanel.class, "LBL_TITLE"));
440: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
441: String path = this .projectLocationField.getText();
442: if (path.length() > 0) {
443: File f = new File(path);
444: if (f.exists()) {
445: chooser.setSelectedFile(f);
446: }
447: }
448: if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this )) {
449: File projectDir = chooser.getSelectedFile();
450: this .projectLocationField.setText(FileUtil.normalizeFile(
451: projectDir).getAbsolutePath());
452: }
453: panel.fireChangeEvent();
454: }//GEN-LAST:event_browseButtonActionPerformed
455:
456: // Variables declaration - do not modify//GEN-BEGIN:variables
457: private javax.swing.JButton browseButton;
458: private javax.swing.JSeparator jSeparator1;
459: private javax.swing.JTextField projectFolderField;
460: private javax.swing.JLabel projectFolderLabel;
461: private javax.swing.JTextField projectLocationField;
462: private javax.swing.JLabel projectLocationLabel;
463: private javax.swing.JTextField projectNameField;
464: private javax.swing.JLabel projectNameLabel;
465: private javax.swing.JCheckBox setAsMainProject;
466: // End of variables declaration//GEN-END:variables
467:
468: }
|