KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > j2seimport > ui > BasicWizardPanel


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.projectimport.j2seimport.ui;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import javax.swing.event.ChangeEvent JavaDoc;
25 import javax.swing.event.ChangeListener JavaDoc;
26 import javax.swing.event.EventListenerList JavaDoc;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.NbBundle;
30
31 /**
32  * @author Martin Krauskopf, Radek Matous
33  */

34 public abstract class BasicWizardPanel implements WizardDescriptor.Panel, PropertyChangeListener JavaDoc {
35     
36     private boolean valid = true;
37     private WizardDescriptor settings;
38     
39     private EventListenerList JavaDoc listeners = new EventListenerList JavaDoc();
40     
41     protected BasicWizardPanel(WizardDescriptor settings) {
42         this.settings = settings;
43     }
44     
45     public void setSettings(WizardDescriptor settings) {
46         this.settings = settings;
47     }
48     
49     protected WizardDescriptor getSettings() {
50         return settings;
51     }
52     
53     public void addChangeListener(ChangeListener JavaDoc l) {
54         listeners.add(ChangeListener JavaDoc.class, l);
55     }
56     
57     public void removeChangeListener(ChangeListener JavaDoc l) {
58         listeners.remove(ChangeListener JavaDoc.class, l);
59     }
60     
61     protected void fireChange() {
62         ChangeListener JavaDoc[] chListeners = (ChangeListener JavaDoc[]) listeners.
63                 getListeners(ChangeListener JavaDoc.class);
64         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
65         for (int i = 0; i < chListeners.length; i++) {
66             chListeners[i].stateChanged(e);
67         }
68     }
69         
70     public HelpCtx getHelp() {
71         return null;
72     }
73     
74     public void storeSettings(Object JavaDoc settings) {}
75     
76     public void readSettings(Object JavaDoc settings) {}
77     
78     public boolean isValid() {
79         return valid;
80     }
81     
82     /**
83      * Mainly for receiving events from wrapped component about its validity.
84      * Firing events further to Wizard descriptor so it will reread this panel's
85      * state and reenable/redisable its next/prev/finish/... buttons.
86      */

87     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
88         if ("valid".equals(evt.getPropertyName())) { // NOI18N
89
boolean nueValid = ((Boolean JavaDoc) evt.getNewValue()).booleanValue();
90             if (nueValid != valid) {
91                 valid = nueValid;
92                 fireChange();
93             }
94         }
95     }
96 }
Popular Tags