KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > samples > FreeformWizardPanel


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.ant.freeform.samples;
21
22 import java.awt.Component 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.WizardValidationException;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 public class FreeformWizardPanel implements WizardDescriptor.Panel,
34         WizardDescriptor.ValidatingPanel, WizardDescriptor.FinishablePanel {
35
36     private WizardDescriptor wizardDescriptor;
37     private FreeformPanelVisual component;
38     
39     /** Creates a new instance of templateWizardPanel */
40     public FreeformWizardPanel() {
41     }
42     
43     public Component JavaDoc getComponent() {
44         if (component == null) {
45             component = new FreeformPanelVisual(this);
46             component.setName(NbBundle.getMessage(FreeformWizardPanel.class, "LBL_CreateProjectStep"));
47         }
48         return component;
49     }
50     
51     public HelpCtx getHelp() {
52         String JavaDoc help = (String JavaDoc) wizardDescriptor.getProperty("help");
53         if (help != null) {
54             return new HelpCtx(help);
55         } else {
56             return null;
57         }
58     }
59     
60     public boolean isValid() {
61         getComponent();
62         return component.valid(wizardDescriptor);
63     }
64     
65     private final Set JavaDoc/*<ChangeListener>*/ listeners = new HashSet JavaDoc(1);
66     public final void addChangeListener(ChangeListener JavaDoc l) {
67         synchronized (listeners) {
68             listeners.add(l);
69         }
70     }
71     public final void removeChangeListener(ChangeListener JavaDoc l) {
72         synchronized (listeners) {
73             listeners.remove(l);
74         }
75     }
76     protected final void fireChangeEvent() {
77         Iterator JavaDoc it;
78         synchronized (listeners) {
79             it = new HashSet JavaDoc(listeners).iterator();
80         }
81         ChangeEvent JavaDoc ev = new ChangeEvent JavaDoc(this);
82         while (it.hasNext()) {
83             ((ChangeListener JavaDoc) it.next()).stateChanged(ev);
84         }
85     }
86     
87     public void readSettings(Object JavaDoc settings) {
88         wizardDescriptor = (WizardDescriptor) settings;
89         component.read(wizardDescriptor);
90     }
91     
92     public void storeSettings(Object JavaDoc settings) {
93         WizardDescriptor d = (WizardDescriptor) settings;
94         component.store(d);
95     }
96     
97     public boolean isFinishPanel() {
98         return true;
99     }
100     
101     public void validate() throws WizardValidationException {
102         getComponent();
103         component.validate(wizardDescriptor);
104     }
105     
106 }
107
Popular Tags