001: /*
002: * The contents of this file are subject to the Mozilla Public License
003: * Version 1.1 (the "License"); you may not use this file except in
004: * compliance with the License. You may obtain a copy of the License at
005: * http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
009: * License for the specific language governing rights and limitations
010: * under the License.
011: *
012: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
013: *
014: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
015: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
016: *
017: * Contributor(s):
018: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
019: *
020: * If you didn't download this code from the following link, you should check
021: * if you aren't using an obsolete version: http://www.isqlviewer.com
022: */
023: package org.isqlviewer.ui.wizards;
024:
025: import java.util.ArrayList;
026: import java.util.Collection;
027: import java.util.Iterator;
028: import java.util.List;
029:
030: import javax.swing.Icon;
031: import javax.swing.JComponent;
032: import javax.swing.JPanel;
033:
034: import org.isqlviewer.util.LoggableObject;
035:
036: /**
037: * Basic implementation of the Step interface for facilitating wizard development.
038: * <p>
039: *
040: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
041: * @version 1.0
042: */
043: public abstract class AbstractWizardStep extends LoggableObject
044: implements Step {
045:
046: public static List<Step> initializeSteps(
047: Collection<Class<? extends AbstractWizardStep>> steps,
048: WizardContext context) {
049:
050: ArrayList<Step> newSteps = new ArrayList<Step>();
051: Iterator<Class<? extends AbstractWizardStep>> listIter = steps
052: .iterator();
053: AbstractWizardStep previous = null;
054: while (listIter.hasNext()) {
055: Class<? extends AbstractWizardStep> clazz = listIter.next();
056: AbstractWizardStep step;
057: try {
058: step = clazz.newInstance();
059: step.init(context);
060: newSteps.add(step);
061: if (previous != null) {
062: step.setPrevious(previous);
063: previous.setNextStep(step);
064: }
065: previous = step;
066: } catch (InstantiationException e) {
067: throw new RuntimeException(e);
068: } catch (IllegalAccessException e) {
069: throw new RuntimeException(e);
070: }
071: }
072: return newSteps;
073: }
074:
075: private String title = null;
076: private String comment = null;
077: private Icon image = null;
078: private JComponent view = null;
079: private Step next = null;
080: private Step previous = null;
081: private WizardContext activeContext = null;
082:
083: public void init(WizardContext context) {
084:
085: this .activeContext = context;
086: }
087:
088: public void activate(WizardContext context) {
089:
090: }
091:
092: public Step getPrevious() {
093:
094: return previous;
095: }
096:
097: public void setPrevious(Step previous) {
098:
099: this .previous = previous;
100: }
101:
102: public Step getNext() {
103:
104: return next;
105: }
106:
107: public String getComment() {
108:
109: return comment;
110: }
111:
112: public void setComment(String comment) {
113:
114: this .comment = comment;
115: }
116:
117: public Icon getImage() {
118:
119: return image;
120: }
121:
122: public void setImage(Icon image) {
123:
124: this .image = image;
125: }
126:
127: public String getTitle() {
128:
129: return title;
130: }
131:
132: public void setTitle(String title) {
133:
134: this .title = title;
135: }
136:
137: public JComponent getView() {
138:
139: return view == null ? new JPanel() : view;
140: }
141:
142: public void setView(JComponent view) {
143:
144: this .view = view;
145: }
146:
147: public void setNextStep(Step nextStep) {
148:
149: this .next = nextStep;
150: }
151:
152: protected WizardContext getContext() {
153:
154: return activeContext;
155: }
156:
157: }
|