KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > core > util > SimpleWizardPanel


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.tasklist.core.util;
21
22 import java.awt.Component JavaDoc;
23 import javax.swing.JComponent 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
30 /**
31  * A simple panel for a wizard.
32  */

33 public class SimpleWizardPanel implements WizardDescriptor.FinishablePanel {
34     private EventListenerList JavaDoc listeners = new EventListenerList JavaDoc();
35
36     /** created component or null */
37     protected Component JavaDoc component;
38     
39     protected HelpCtx helpCtx = HelpCtx.DEFAULT_HELP;
40     
41     /** is this panel valid? */
42     private boolean valid = true;
43     
44     /** wizard */
45     protected WizardDescriptor wizard;
46     
47     private boolean finish;
48     
49     /**
50      * Creates a new instance of SimpleWizardPanel
51      *
52      * @param component panel for the wizard
53      */

54     public SimpleWizardPanel(Component JavaDoc component) {
55         this.component = component;
56     }
57     
58     /**
59      * Sets whether this is a finish panel
60      *
61      * @param finish true = this is a finishable panel
62      */

63     public void setFinishPanel(boolean finish) {
64         this.finish = finish;
65     }
66     
67     public void readSettings(Object JavaDoc settings) {
68         wizard = (WizardDescriptor) settings;
69         check();
70     }
71
72     public void storeSettings(Object JavaDoc settings) {
73     }
74
75     /**
76      * Sets another error message that will be shown in the bottom of the
77      * wizard dialog.
78      *
79      * @param err new error message or null if none
80      */

81     public void setErrorMessage(String JavaDoc err) {
82         if (wizard != null)
83             wizard.putProperty("WizardPanel_errorMessage", err); // NOI18N
84
this.valid = err == null;
85     }
86     
87     /**
88      * Sets help context for this panel
89      *
90      * @param h new help context
91      */

92     public void setHelpContext(HelpCtx h) {
93         this.helpCtx = h;
94     }
95     
96     public boolean isValid() {
97         return valid;
98     }
99     
100     /**
101      * This method should check the content of the panel and
102      */

103     protected void check() {
104     }
105     
106     public java.awt.Component JavaDoc getComponent() {
107         return component;
108     }
109
110     public HelpCtx getHelp() {
111         return helpCtx;
112     }
113
114     public void addChangeListener(ChangeListener JavaDoc l) {
115         listeners.add(ChangeListener JavaDoc.class, l);
116     }
117
118     public void removeChangeListener(ChangeListener JavaDoc l) {
119         listeners.remove(ChangeListener JavaDoc.class, l);
120     }
121
122     private void fireChange() {
123         // Guaranteed to return a non-null array
124
Object JavaDoc[] l = listeners.getListenerList();
125         ChangeEvent JavaDoc event = null;
126
127         // Process the listeners last to first, notifying
128
// those that are interested in this event
129
for (int i = l.length - 2; i >= 0; i -= 2) {
130             if (l[i] == ChangeListener JavaDoc.class) {
131                 // Lazily create the event:
132
if (event == null)
133                     event = new ChangeEvent JavaDoc(this);
134                 ((ChangeListener JavaDoc) l[i+1]).stateChanged(event);
135             }
136         }
137     }
138     
139     public boolean isFinishPanel() {
140         return finish;
141     }
142     
143     /**
144      * Sets the Index of highlighted step in the content.
145      *
146      * @param index new index
147      */

148     public void setContentHighlightedIndex(int index) {
149         if (wizard != null)
150             wizard.putProperty("WizardPanel_contentSelectedIndex", // NOI18N
151
new Integer JavaDoc(index));
152         else
153             ((JComponent JavaDoc) getComponent()).putClientProperty(
154                 "WizardPanel_contentSelectedIndex",
155                 new Integer JavaDoc(index)); // NOI18N
156
}
157 }
158
Popular Tags