KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.openide.WizardDescriptor;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author Radek Matous
35  */

36 public abstract class BasicPanel extends JPanel JavaDoc {
37     private BasicWizardPanel wiardPanel;
38     private boolean isOK = false;
39
40     public abstract int getPanelIndex();
41     public abstract String JavaDoc getPanelDescription();
42     protected abstract void storeWizardData(WizardData data);
43     protected abstract void readWizardData(WizardData data);
44     
45     public abstract void validateContent() throws org.openide.WizardValidationException;
46     
47     public String JavaDoc getName() {
48         return getPanelDescription();
49     }
50     
51     public final boolean isOK() {
52         return isOK;
53     }
54     
55     public final void setValid(boolean valid) {
56         boolean fire = (isOK() != valid);
57         isOK = valid;
58         if (fire) {
59             wiardPanel.fireChange();
60         }
61     }
62             
63     
64     public final WizardDescriptor.Panel getWizardPanel() {
65         if (wiardPanel == null) {
66             initPanel();
67             wiardPanel = new BasicWizardPanel();
68         }
69         return wiardPanel;
70     }
71     
72     final void initPanel() {
73         putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
74
putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
75
putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
76
putClientProperty("WizardPanel_contentSelectedIndex", // NOI18N
77
new Integer JavaDoc(getPanelIndex()));
78         putClientProperty("WizardPanel_contentData", new String JavaDoc[] { // NOI18N
79
getPanelDescription()
80         });
81         setPreferredSize(new java.awt.Dimension JavaDoc(500, 380));
82     }
83
84     
85     public static class WizardData {
86         private ErrorMessages errorMessages;
87         public final void setErrorMessages(ErrorMessages errorMessages) {
88             this.errorMessages = errorMessages;
89         }
90         
91         public final ErrorMessages getErrorMessages() {
92             return errorMessages;
93         }
94     }
95     
96     public interface ErrorMessages {
97         void setError(String JavaDoc message);
98     }
99     
100     
101     private class BasicWizardPanel implements WizardDescriptor.Panel, WizardDescriptor.ValidatingPanel {
102         
103         /** Registered ChangeListeners */
104         private List JavaDoc changeListeners;
105         
106         /** Creates a new instance of BasicWizardPanel */
107         public BasicWizardPanel() {
108         }
109         
110         public void addChangeListener(ChangeListener JavaDoc l) {
111             if (changeListeners == null) {
112                 changeListeners = new ArrayList JavaDoc(2);
113             }
114             changeListeners.add(l);
115         }
116         
117         public void removeChangeListener(ChangeListener JavaDoc l) {
118             if (changeListeners != null) {
119                 if (changeListeners.remove(l) && changeListeners.isEmpty()) {
120                     changeListeners = null;
121                 }
122             }
123         }
124         
125         public void fireChange() {
126             if (changeListeners != null) {
127                 ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
128                 for (Iterator JavaDoc i = changeListeners.iterator(); i.hasNext(); ) {
129                     ((ChangeListener JavaDoc) i.next()).stateChanged(e);
130                 }
131             }
132         }
133         
134         public final void storeSettings(Object JavaDoc settings) {
135             BasicPanel.this.storeWizardData((BasicPanel.WizardData)settings);
136         }
137         
138         public final void readSettings(Object JavaDoc settings) {
139             BasicPanel.this.readWizardData((BasicPanel.WizardData)settings);
140         }
141         
142         public org.openide.util.HelpCtx getHelp() {
143             return null;
144         }
145         
146         
147         public java.awt.Component JavaDoc getComponent() {
148             return BasicPanel.this;
149         }
150         
151         public boolean isValid() {
152             return BasicPanel.this.isOK();
153         }
154         
155         public void validate() throws org.openide.WizardValidationException {
156             BasicPanel.this.validateContent();
157         }
158     }
159     
160     
161 }
162
Popular Tags