KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > export > ExportWizardPanel1


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 package org.netbeans.bluej.export;
20
21 import java.awt.Component JavaDoc;
22 import java.io.File JavaDoc;
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.openide.WizardDescriptor;
29 import org.openide.filesystems.FileObject;
30 import org.openide.util.HelpCtx;
31
32 public class ExportWizardPanel1 implements WizardDescriptor.Panel {
33
34     private String JavaDoc path;
35     /**
36      * The visual component that displays this panel. If you need to access the
37      * component from this class, just use getComponent().
38      */

39     private Component JavaDoc component;
40
41     private FileObject dir;
42     private boolean valid = false;
43     private WizardDescriptor settings;
44     
45     ExportWizardPanel1(FileObject fo) {
46         dir = fo;
47     }
48     
49     // Get the visual component for the panel. In this template, the component
50
// is kept separate. This can be more efficient: if the wizard is created
51
// but never displayed, or not all panels are displayed, it is better to
52
// create only those which really need to be visible.
53
public Component JavaDoc getComponent() {
54         if (component == null) {
55             component = new ExportPanel(dir, this);
56         }
57         return component;
58     }
59     
60     public HelpCtx getHelp() {
61         // Show no Help button for this panel:
62
return HelpCtx.DEFAULT_HELP;
63         // If you have context help:
64
// return new HelpCtx(SampleWizardPanel1.class);
65
}
66     
67     public boolean isValid() {
68         return valid;
69     }
70     
71     private final Set JavaDoc listeners = new HashSet JavaDoc(1);
72     public final void addChangeListener(ChangeListener JavaDoc l) {
73         synchronized (listeners) {
74             listeners.add(l);
75         }
76     }
77     public final void removeChangeListener(ChangeListener JavaDoc l) {
78         synchronized (listeners) {
79             listeners.remove(l);
80         }
81     }
82     protected final void fireChangeEvent() {
83         Iterator JavaDoc it;
84         synchronized (listeners) {
85             it = new HashSet JavaDoc(listeners).iterator();
86         }
87         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
88         while (it.hasNext()) {
89             ((ChangeListener JavaDoc)it.next()).stateChanged(ev);
90         }
91     }
92     
93     // You can use a settings object to keep track of state. Normally the
94
// settings object will be the WizardDescriptor, so you can use
95
// WizardDescriptor.getProperty & putProperty to store information entered
96
// by the user.
97
public void readSettings(Object JavaDoc sets) {
98         this.settings = (WizardDescriptor)sets;
99         File JavaDoc fil = (File JavaDoc)settings.getProperty("NewProjectLocation");
100         String JavaDoc path = fil != null ? fil.getAbsolutePath() : "";
101         updateValue(path);
102     }
103     public void storeSettings(Object JavaDoc set) {
104         WizardDescriptor wiz = (WizardDescriptor)set;
105         if (path != null) {
106             //#79637 can be null when immediately cancelling the wizard.
107
wiz.putProperty("NewProjectLocation", new File JavaDoc(path.trim())); // NOI18N
108
}
109     }
110
111     void updateValue(String JavaDoc value) {
112         path = value;
113         if (path == null || path.trim().length() == 0) {
114             settings.putProperty("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(ExportWizardPanel1.class, "ERROR_noFolder"));
115             valid = false;
116         } else {
117             File JavaDoc fil = new File JavaDoc(path.trim());
118             if (fil.exists() && (fil.isFile() || (fil.isDirectory() && fil.listFiles().length > 0))) {
119                 settings.putProperty("WizardPanel_errorMessage", org.openide.util.NbBundle.getMessage(ExportWizardPanel1.class, "ERROR_WrongFolder"));
120                 valid = false;
121             } else {
122                 settings.putProperty("WizardPanel_errorMessage", null);
123                 valid = true;
124             }
125         }
126         
127         fireChangeEvent();
128     }
129     
130 }
131
132
Popular Tags