KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > wizard > TBWizard


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.common.wizard;
25
26 // ToolBox
27
import org.enhydra.tool.common.event.FirstFocusEvent;
28 import org.enhydra.tool.common.event.FirstFocusListener;
29 import org.enhydra.tool.common.DialogHandler;
30 import org.enhydra.tool.common.ButtonPanel;
31 import org.enhydra.tool.common.InnerPanel;
32 import org.enhydra.tool.common.DialogPanel;
33 import org.enhydra.tool.common.SwingUtil;
34 import org.enhydra.tool.common.event.HelpEvent;
35 import org.enhydra.tool.common.event.HelpListener;
36
37 // JDK
38
import javax.swing.*;
39 import javax.swing.border.*;
40 import java.awt.*;
41 import java.awt.event.ActionEvent JavaDoc;
42 import java.awt.event.ActionListener JavaDoc;
43 import java.io.File JavaDoc;
44 import java.beans.*;
45 import java.lang.ref.WeakReference JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.Arrays JavaDoc;
48 import java.util.ResourceBundle JavaDoc;
49
50 /**
51  * The TBWizardDialog defines a default container for presenting
52  * wizards. To use this class you need to a create one or more
53  * TBWizardPage objects and add them to this dialog. This dialog
54  * supplies action buttons for the Previous, Next, Finish,
55  * Cancel and Help.
56  * <P><I>
57  * This class is used when creating a standalone wizard. Use the
58  * OpenTools BasicWizard when developing JBuilder add-ins.
59  * </I></P>
60  */

61 abstract public class TBWizard extends DialogHandler
62     implements FirstFocusListener {
63     //
64
static ResourceBundle JavaDoc res =
65         ResourceBundle.getBundle("org.enhydra.tool.common.Res"); // nores
66

67     //
68

69     private TBWizardButtonPanel buttonPanel;
70     private TBWizardInnerPanel innerPanel;
71     private TBWizardButtonListener buttonListener;
72     private WeakReference JavaDoc backRef = null;
73     private WeakReference JavaDoc nextRef = null;
74     private WeakReference JavaDoc finishRef = null;
75
76     /**
77      * Create a wizard dialog as a child of another dialog.
78      *
79      * @param owner
80      * The dialog that is the parent of this wizard.
81      */

82     public TBWizard() {
83         super();
84         innerPanel = new TBWizardInnerPanel();
85         buttonPanel = new TBWizardButtonPanel();
86         innerPanel.addFirstFocusListener(this);
87     }
88
89     // implments FirstFocusListener
90
public void onFirstFocus(FirstFocusEvent event) {
91         refreshButtons();
92     }
93
94     /**
95      * Clear all object references.
96      */

97     protected void clearAll() {
98         super.clearAll();
99         if (backRef != null) {
100             backRef.clear();
101         }
102         if (nextRef != null) {
103             nextRef.clear();
104         }
105         if (finishRef != null) {
106             finishRef.clear();
107         }
108         innerPanel = null;
109         buttonPanel = null;
110         backRef = null;
111         nextRef = null;
112         finishRef = null;
113     }
114
115     public TBWizardDeck getDeck() {
116         return innerPanel.getDeck();
117     }
118
119     public void setDeck(TBWizardDeck d) {
120         innerPanel.setDeck(d);
121     }
122
123     // implements DialogHandler
124
public ActionListener JavaDoc createButtonListener() {
125         return (new TBWizardButtonListener(this));
126     }
127
128     // implements DialogHandler
129
public ButtonPanel getButtonPanel() {
130         return buttonPanel;
131     }
132
133     public InnerPanel getInnerPanel() {
134         return innerPanel;
135     }
136
137     public void setLargeIcon(Icon icon) {
138         innerPanel.setLargeIcon(icon);
139     }
140
141     public Icon getLargeIcon() {
142         return innerPanel.getLargeIcon();
143     }
144
145     /**
146      * Add a page to the wizard.
147      *
148      * @param page
149      * A panel that contains swing controls that
150      * are specific to the current wizard.
151      */

152     public void addWizardPage(TBWizardPage page) {
153         innerPanel.addWizardPage(page);
154     }
155
156     public void back() {
157         innerPanel.getDeck().back();
158         refreshButtons();
159     }
160
161     public void next() {
162         innerPanel.getDeck().next();
163         refreshButtons();
164     }
165
166     public void finish() {
167         setOption(JOptionPane.OK_OPTION);
168         super.closeWindow();
169     }
170
171     public void cancel() {
172         setOption(JOptionPane.CANCEL_OPTION);
173         super.closeWindow();
174     }
175
176     //
177
//
178
private Component getNext() {
179         Component comp = null;
180
181         if (nextRef == null) {
182             comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(),
183                                           ButtonPanel.COMMAND_NEXT);
184             if (comp != null) {
185                 nextRef = new WeakReference JavaDoc(comp);
186             }
187         } else {
188             comp = (Component) nextRef.get();
189         }
190         return comp;
191     }
192
193     private Component getBack() {
194         Component comp = null;
195
196         if (backRef == null) {
197             comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(),
198                                           ButtonPanel.COMMAND_BACK);
199             if (comp != null) {
200                 backRef = new WeakReference JavaDoc(comp);
201             }
202         } else {
203             comp = (Component) backRef.get();
204         }
205         return comp;
206     }
207
208     private Component getFinish() {
209         Component comp = null;
210
211         if (finishRef == null) {
212             comp = ButtonPanel.findButton(getInnerPanel().getTopLevelAncestor(),
213                                           ButtonPanel.COMMAND_FINISH);
214             if (comp != null) {
215                 finishRef = new WeakReference JavaDoc(comp);
216             }
217         } else {
218             comp = (Component) finishRef.get();
219         }
220         return comp;
221     }
222
223     public void refreshButtons() {
224         Component back = null;
225         Component next = null;
226         Component finish = null;
227         boolean backEnable = true;
228         boolean nextEnable = true;
229         boolean finishEnable = true;
230
231         back = getBack();
232         next = getNext();
233         finish = getFinish();
234         if (innerPanel.getDeck().isLastPageShowing()) {
235             nextEnable = false;
236         }
237         if (innerPanel.getDeck().isFirstPageShowing()) {
238             backEnable = false;
239             finishEnable = false;
240         }
241         if (back != null) {
242             back.setEnabled(backEnable);
243         }
244         if (next != null) {
245             next.setEnabled(nextEnable);
246         }
247         if (finish != null) {
248             finish.setEnabled(finishEnable);
249         }
250     }
251
252 }
253
Popular Tags