001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: * Paul Mahar
021: *
022: */
023: package org.enhydra.tool.common.wizard;
024:
025: // ToolBox
026: import org.enhydra.tool.common.event.FirstFocusEvent;
027: import org.enhydra.tool.common.event.FirstFocusListener;
028: import org.enhydra.tool.common.DialogHandler;
029: import org.enhydra.tool.common.ButtonPanel;
030: import org.enhydra.tool.common.InnerPanel;
031: import org.enhydra.tool.common.DialogPanel;
032: import org.enhydra.tool.common.SwingUtil;
033: import org.enhydra.tool.common.event.HelpEvent;
034: import org.enhydra.tool.common.event.HelpListener;
035:
036: // JDK
037: import javax.swing.*;
038: import javax.swing.border.*;
039: import java.awt.*;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.ActionListener;
042: import java.io.File;
043: import java.beans.*;
044: import java.lang.ref.WeakReference;
045: import java.util.ArrayList;
046: import java.util.Arrays;
047: import java.util.ResourceBundle;
048:
049: /**
050: * The TBWizardDialog defines a default container for presenting
051: * wizards. To use this class you need to a create one or more
052: * TBWizardPage objects and add them to this dialog. This dialog
053: * supplies action buttons for the Previous, Next, Finish,
054: * Cancel and Help.
055: * <P><I>
056: * This class is used when creating a standalone wizard. Use the
057: * OpenTools BasicWizard when developing JBuilder add-ins.
058: * </I></P>
059: */
060: abstract public class TBWizard extends DialogHandler implements
061: FirstFocusListener {
062: //
063: static ResourceBundle res = ResourceBundle
064: .getBundle("org.enhydra.tool.common.Res"); // nores
065:
066: //
067:
068: private TBWizardButtonPanel buttonPanel;
069: private TBWizardInnerPanel innerPanel;
070: private TBWizardButtonListener buttonListener;
071: private WeakReference backRef = null;
072: private WeakReference nextRef = null;
073: private WeakReference finishRef = null;
074:
075: /**
076: * Create a wizard dialog as a child of another dialog.
077: *
078: * @param owner
079: * The dialog that is the parent of this wizard.
080: */
081: public TBWizard() {
082: super ();
083: innerPanel = new TBWizardInnerPanel();
084: buttonPanel = new TBWizardButtonPanel();
085: innerPanel.addFirstFocusListener(this );
086: }
087:
088: // implments FirstFocusListener
089: public void onFirstFocus(FirstFocusEvent event) {
090: refreshButtons();
091: }
092:
093: /**
094: * Clear all object references.
095: */
096: protected void clearAll() {
097: super .clearAll();
098: if (backRef != null) {
099: backRef.clear();
100: }
101: if (nextRef != null) {
102: nextRef.clear();
103: }
104: if (finishRef != null) {
105: finishRef.clear();
106: }
107: innerPanel = null;
108: buttonPanel = null;
109: backRef = null;
110: nextRef = null;
111: finishRef = null;
112: }
113:
114: public TBWizardDeck getDeck() {
115: return innerPanel.getDeck();
116: }
117:
118: public void setDeck(TBWizardDeck d) {
119: innerPanel.setDeck(d);
120: }
121:
122: // implements DialogHandler
123: public ActionListener createButtonListener() {
124: return (new TBWizardButtonListener(this ));
125: }
126:
127: // implements DialogHandler
128: public ButtonPanel getButtonPanel() {
129: return buttonPanel;
130: }
131:
132: public InnerPanel getInnerPanel() {
133: return innerPanel;
134: }
135:
136: public void setLargeIcon(Icon icon) {
137: innerPanel.setLargeIcon(icon);
138: }
139:
140: public Icon getLargeIcon() {
141: return innerPanel.getLargeIcon();
142: }
143:
144: /**
145: * Add a page to the wizard.
146: *
147: * @param page
148: * A panel that contains swing controls that
149: * are specific to the current wizard.
150: */
151: public void addWizardPage(TBWizardPage page) {
152: innerPanel.addWizardPage(page);
153: }
154:
155: public void back() {
156: innerPanel.getDeck().back();
157: refreshButtons();
158: }
159:
160: public void next() {
161: innerPanel.getDeck().next();
162: refreshButtons();
163: }
164:
165: public void finish() {
166: setOption(JOptionPane.OK_OPTION);
167: super .closeWindow();
168: }
169:
170: public void cancel() {
171: setOption(JOptionPane.CANCEL_OPTION);
172: super .closeWindow();
173: }
174:
175: //
176: //
177: private Component getNext() {
178: Component comp = null;
179:
180: if (nextRef == null) {
181: comp = ButtonPanel.findButton(getInnerPanel()
182: .getTopLevelAncestor(), ButtonPanel.COMMAND_NEXT);
183: if (comp != null) {
184: nextRef = new WeakReference(comp);
185: }
186: } else {
187: comp = (Component) nextRef.get();
188: }
189: return comp;
190: }
191:
192: private Component getBack() {
193: Component comp = null;
194:
195: if (backRef == null) {
196: comp = ButtonPanel.findButton(getInnerPanel()
197: .getTopLevelAncestor(), ButtonPanel.COMMAND_BACK);
198: if (comp != null) {
199: backRef = new WeakReference(comp);
200: }
201: } else {
202: comp = (Component) backRef.get();
203: }
204: return comp;
205: }
206:
207: private Component getFinish() {
208: Component comp = null;
209:
210: if (finishRef == null) {
211: comp = ButtonPanel.findButton(getInnerPanel()
212: .getTopLevelAncestor(), ButtonPanel.COMMAND_FINISH);
213: if (comp != null) {
214: finishRef = new WeakReference(comp);
215: }
216: } else {
217: comp = (Component) finishRef.get();
218: }
219: return comp;
220: }
221:
222: public void refreshButtons() {
223: Component back = null;
224: Component next = null;
225: Component finish = null;
226: boolean backEnable = true;
227: boolean nextEnable = true;
228: boolean finishEnable = true;
229:
230: back = getBack();
231: next = getNext();
232: finish = getFinish();
233: if (innerPanel.getDeck().isLastPageShowing()) {
234: nextEnable = false;
235: }
236: if (innerPanel.getDeck().isFirstPageShowing()) {
237: backEnable = false;
238: finishEnable = false;
239: }
240: if (back != null) {
241: back.setEnabled(backEnable);
242: }
243: if (next != null) {
244: next.setEnabled(nextEnable);
245: }
246: if (finish != null) {
247: finish.setEnabled(finishEnable);
248: }
249: }
250:
251: }
|