KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > wizards > ActionPanel


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.web.struts.wizards;
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
29 import org.openide.WizardDescriptor;
30 import org.openide.util.HelpCtx;
31
32 import org.netbeans.api.project.Project;
33
34 /**
35  *
36  * @author radko
37  */

38 public class ActionPanel implements WizardDescriptor.Panel, WizardDescriptor.FinishablePanel, ChangeListener JavaDoc {
39
40     private WizardDescriptor wizardDescriptor;
41     private ActionPanelVisual component;
42     private Project project;
43
44     /** Creates a new instance of ActionPanel */
45     public ActionPanel(Project project, WizardDescriptor wizardDescriptor) {
46         this.project=project;
47         this.wizardDescriptor = wizardDescriptor;
48     }
49     
50     Project getProject() {
51         return project;
52     }
53     
54     public Component JavaDoc getComponent() {
55         if (component == null){
56             component = new ActionPanelVisual(this);
57             component.addChangeListener(this);
58         }
59         return component;
60     }
61     
62     public boolean isValid() {
63         getComponent();
64         return component.valid(wizardDescriptor);
65     }
66
67     public void readSettings(Object JavaDoc settings) {
68         wizardDescriptor = (WizardDescriptor) settings;
69         component.read(wizardDescriptor);
70     }
71     
72     public void storeSettings(Object JavaDoc settings) {
73         WizardDescriptor desc = (WizardDescriptor) settings;
74         component.store(desc);
75     }
76
77     public HelpCtx getHelp() {
78         return new HelpCtx(ActionPanel.class);
79     }
80
81     private final Set JavaDoc/*<ChangeListener>*/ listeners = new HashSet JavaDoc(1);
82     
83     public final void addChangeListener(ChangeListener JavaDoc l) {
84         synchronized (listeners) {
85             listeners.add(l);
86         }
87     }
88     public final void removeChangeListener(ChangeListener JavaDoc l) {
89         synchronized (listeners) {
90             listeners.remove(l);
91         }
92     }
93     public boolean isFinishPanel() {
94         return isValid();
95     }
96     
97     public void stateChanged(ChangeEvent JavaDoc e) {
98         fireChange();
99     }
100     
101      private void fireChange() {
102         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
103         Iterator JavaDoc it = listeners.iterator();
104         while (it.hasNext()) {
105             ((ChangeListener JavaDoc)it.next()).stateChanged(e);
106         }
107     }
108 }
109
Popular Tags