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: TestMulti.java,v 1.6 2006/07/29 19:44:28 pietschy Exp $
020: */package wizard;
021:
022: import org.pietschy.wizard.*;
023: import org.pietschy.wizard.models.*;
024:
025: import javax.swing.*;
026: import java.awt.event.ActionListener;
027: import java.awt.event.ActionEvent;
028: import java.awt.*;
029:
030: /**
031: * Created by IntelliJ IDEA.
032: * User: andrewp
033: * Date: 10/06/2004
034: * Time: 10:57:42
035: * To change this template use Options | File Templates.
036: */
037: public class TestMulti {
038:
039: public TestMulti() {
040: }
041:
042: public static void main(String[] args) {
043:
044: try {
045: UIManager.setLookAndFeel(UIManager
046: .getSystemLookAndFeelClassName());
047: } catch (Exception e) {
048: e.printStackTrace(); //To change body of catch statement use Options | File Templates.
049: }
050: UIManager.put("swing.boldMetal", Boolean.FALSE);
051:
052: // Set keys = new TreeSet(UIManager.getLookAndFeel().getDefaults().keySet());
053: // for (Iterator iter = keys.iterator(); iter.hasNext();)
054: // System.out.println(iter.next());
055:
056: Icon iconA = new Icon() {
057: public int getIconHeight() {
058: return 50;
059: }
060:
061: public int getIconWidth() {
062: return 50;
063: }
064:
065: public void paintIcon(Component c, Graphics g, int x, int y) {
066: g.setColor(Color.RED);
067: g.fillRect(x, y, getIconWidth(), getIconHeight());
068: }
069: };
070:
071: Icon iconB = new Icon() {
072: public int getIconHeight() {
073: return 10; //To change body of implemented methods use File | Settings | File Templates.
074: }
075:
076: public int getIconWidth() {
077: return 10; //To change body of implemented methods use File | Settings | File Templates.
078: }
079:
080: public void paintIcon(Component c, Graphics g, int x, int y) {
081: g.setColor(Color.BLUE);
082: g.fillRect(x, y, getIconWidth(), getIconHeight());
083: }
084: };
085:
086: BranchingPath firstPath = new BranchingPath();
087: firstPath
088: .addStep(new EmptyStep(
089: "My first step",
090: "<html>My first step that has some longer text associated with it that has <u>bit of <b>HTML</b> added</u> for good measure.</html>",
091: iconA) {
092:
093: Model m;
094: JTextArea ta;
095:
096: public void init(WizardModel model) {
097: setComplete(true);
098: m = (Model) model;
099: ta = new JTextArea();
100: ta.setColumns(15);
101: ta.setRows(5);
102: setLayout(new BorderLayout());
103: add(new JScrollPane(ta), BorderLayout.CENTER);
104: }
105:
106: public void applyState()
107: throws InvalidStateException {
108: String text = ta.getText();
109: m.branch = text.trim().length() > 0;
110: }
111:
112: });
113:
114: SimplePath branch = new SimplePath(new AbstractWizardStep(
115: "Third step", "My third step", iconB) {
116: /////////////////////////////////////////////////////////////////////
117: // Abstract Methods
118: //
119:
120: public void prepare() {
121: setComplete(false);
122: setBusy(true);
123: JProgressBar pgb = new JProgressBar();
124: pgb.setIndeterminate(true);
125: pgb
126: .setString("Please wait.. reading options from database..");
127: pgb.setStringPainted(true);
128: setView(pgb);
129: Timer t = new Timer(2000, new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: setView(new JLabel("Ok, now you can move on.."));
132: setComplete(true);
133: setBusy(false);
134: }
135: });
136: t.setRepeats(false);
137: t.start();
138: }
139:
140: public void applyState() throws InvalidStateException {
141: }
142:
143: public Dimension getPreferredSize() {
144: return new JLabel("Done..").getPreferredSize();
145: }
146:
147: public void init(WizardModel model) {
148: setComplete(false);
149: }
150: });
151:
152: SimplePath endPath = new SimplePath(new AbstractWizardStep(
153: "Last Step", "Click showCloseButton to do it..") {
154:
155: public void init(WizardModel model) {
156: setComplete(true);
157: }
158:
159: public void prepare() {
160: setComplete(true);
161: setView(new JLabel("I've done all the stuff! (c:"));
162: }
163:
164: public void applyState() throws InvalidStateException {
165: setView(new JLabel("I'm done, bye"));
166: }
167:
168: public Dimension getPreferredSize() {
169: return new JLabel("I've done all the stuff! (c:")
170: .getPreferredSize();
171: }
172:
173: });
174:
175: branch.setNextPath(endPath);
176:
177: firstPath.addBranch(branch, new Condition() {
178: public boolean evaluate(WizardModel model) {
179: return ((Model) model).branch;
180: }
181: });
182:
183: firstPath.addBranch(endPath, new Condition() {
184: public boolean evaluate(WizardModel model) {
185: return !((Model) model).branch;
186: }
187: });
188:
189: Model m = new Model(firstPath);
190: m.setLastVisible(false);
191:
192: Wizard wizard = new Wizard(m) {
193: protected JComponent createTitleComponent() {
194: DefaultTitleComponent titleComponent = (DefaultTitleComponent) super
195: .createTitleComponent();
196: titleComponent.setGradientBackground(true);
197: return titleComponent; //To change body of overridden methods use File | Settings | File Templates.
198: }
199: };
200: wizard.addWizardListener(new WizardAdapter() {
201: public void wizardClosed(WizardEvent e) {
202: System.exit(0);
203: }
204:
205: public void wizardCancelled(WizardEvent e) {
206: System.exit(0);
207: }
208: });
209:
210: wizard.setOverviewVisible(false);
211: wizard.showInFrame("My TestStatic Wizard");
212:
213: }
214:
215: private static class Model extends MultiPathModel {
216: public boolean branch = true;
217:
218: public Model(Path firstPath) {
219: super(firstPath);
220: }
221: }
222:
223: }
|