001: /**
002: * Wizard Framework
003: * Copyright (c) 2004 Andrew Pietsch
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * $Id: TestDynamic.java,v 1.5 2005/09/18 05:27:53 pietschy Exp $
020: */package wizard;
021:
022: import org.pietschy.wizard.*;
023: import org.pietschy.wizard.models.StaticModel;
024: import org.pietschy.wizard.models.DynamicModel;
025: import org.pietschy.wizard.models.Condition;
026:
027: import javax.swing.*;
028: import java.awt.event.ActionListener;
029: import java.awt.event.ActionEvent;
030: import java.awt.*;
031: import java.util.Set;
032: import java.util.Iterator;
033: import java.util.TreeSet;
034: import java.net.URL;
035: import java.net.MalformedURLException;
036:
037: /**
038: * Created by IntelliJ IDEA.
039: * User: andrewp
040: * Date: 10/06/2004
041: * Time: 10:57:42
042: * To change this template use Options | File Templates.
043: */
044: public class TestDynamic {
045: private static Wizard wizard;
046:
047: public TestDynamic() {
048: }
049:
050: public static void main(String[] args) {
051:
052: try {
053: UIManager.setLookAndFeel(UIManager
054: .getSystemLookAndFeelClassName());
055: } catch (Exception e) {
056: e.printStackTrace(); //To change body of catch statement use Options | File Templates.
057: }
058: UIManager.put("swing.boldMetal", Boolean.FALSE);
059:
060: // Set keys = new TreeSet(UIManager.getLookAndFeel().getDefaults().keySet());
061: // for (Iterator iter = keys.iterator(); iter.hasNext();)
062: // System.out.println(iter.next());
063:
064: DynamicModel model = new TestModel() {
065: public boolean isLastVisible() {
066: return true;
067: }
068: };
069:
070: model
071: .add(new EmptyStep(
072: "My first step",
073: "<html>My first step that has some longer text associated with it that has bit of <u>HTML</u> added for good measure.</html>"));
074: model.add(new ConditionalTriggerStep("The second one",
075: "My second step"));
076: model
077: .add(new ConditionalStep("Third step",
078: "My third step that has some longer text associated with it.."));
079: model.add(new ConditionalTriggerStep("Fourth",
080: "The fourth step"));
081: model.add(new ConditionalStep("Fifth", "The fifth step"));
082: model.add(new EmptyStep("Summary", "The end..") {
083: public void applyState() throws InvalidStateException {
084: // throw new InvalidStateException("Oops...!");
085: setLayout(new BorderLayout());
086: add(new JLabel("Finished! (c:"), BorderLayout.CENTER);
087: }
088: });
089:
090: wizard = new Wizard(model) {
091: protected JComponent createTitleComponent() {
092: DefaultTitleComponent titleComponent = (DefaultTitleComponent) super
093: .createTitleComponent();
094: titleComponent.setGradientBackground(true);
095: return titleComponent; //To change body of overridden methods use File | Settings | File Templates.
096: }
097: };
098: wizard.addWizardListener(new WizardAdapter() {
099: public void wizardClosed(WizardEvent e) {
100: // System.exit(0);
101: }
102:
103: public void wizardCancelled(WizardEvent e) {
104: // System.exit(0);
105: }
106: });
107:
108: wizard.setDefaultExitMode(Wizard.EXIT_ON_FINISH);
109:
110: try {
111: URL url = new URL("http://pietschy.com/Images/pietschy.png");
112: ImageIcon icon = new ImageIcon(url);
113: // wizard.setOverviewVisible(false);
114: wizard.showInFrame("My TestStatic Wizard", icon.getImage());
115: } catch (MalformedURLException e) {
116: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
117: }
118:
119: }
120:
121: private static class TestModel extends DynamicModel {
122: boolean skipNextStep;
123:
124: public TestModel() {
125: }
126:
127: }
128:
129: private static class ConditionalStep extends EmptyStep implements
130: Condition {
131:
132: public ConditionalStep(String name, String summary) {
133: super (name, summary);
134: }
135:
136: public boolean evaluate(WizardModel model) {
137: boolean choose = !((TestModel) model).skipNextStep;
138: ((TestModel) model).skipNextStep = false;
139:
140: return choose;
141: }
142: }
143:
144: private static class ConditionalTriggerStep extends PanelWizardStep
145: implements Condition {
146: TestModel m;
147: private JCheckBox skipNext = new JCheckBox("Skip next step");
148:
149: public ConditionalTriggerStep(String name, String summary) {
150: super (name, summary);
151: setLayout(new BorderLayout());
152: add(skipNext, BorderLayout.CENTER);
153: }
154:
155: public void init(WizardModel model) {
156: m = (TestModel) model;
157: }
158:
159: public void prepare() {
160: skipNext.setSelected(m.skipNextStep);
161: setComplete(true);
162: }
163:
164: public void applyState() throws InvalidStateException {
165: m.skipNextStep = skipNext.isSelected();
166: }
167:
168: public boolean evaluate(WizardModel model) {
169: boolean choose = !((TestModel) model).skipNextStep;
170: ((TestModel) model).skipNextStep = false;
171:
172: return choose;
173: }
174: }
175: }
|