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: TestStatic.java,v 1.4 2005/09/18 05:27:54 pietschy Exp $
020: */package wizard;
021:
022: import org.pietschy.wizard.*;
023: import org.pietschy.wizard.models.StaticModel;
024:
025: import javax.swing.*;
026: import java.awt.*;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
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 TestStatic {
038: private static Wizard wizard;
039:
040: public TestStatic() {
041: }
042:
043: public static void main(String[] args) {
044:
045: try {
046: UIManager.setLookAndFeel(UIManager
047: .getSystemLookAndFeelClassName());
048: } catch (Exception e) {
049: e.printStackTrace(); //To change body of catch statement use Options | File Templates.
050: }
051: UIManager.put("swing.boldMetal", Boolean.FALSE);
052:
053: // Set keys = new TreeSet(UIManager.getLookAndFeel().getDefaults().keySet());
054: // for (Iterator iter = keys.iterator(); iter.hasNext();)
055: // System.out.println(iter.next());
056:
057: StaticModel sm = new TestModel();
058:
059: sm
060: .add(new EmptyStep(
061: "My first step",
062: "My first step that has some longer text associated with it that has bit of HTML added for good measure."));
063: sm.add(new EmptyStep("The second one", "My second step") {
064: JTextArea ta = new JTextArea();
065:
066: public void init(WizardModel model) {
067: ta.setColumns(15);
068: ta.setRows(5);
069: setLayout(new BorderLayout());
070: add(new JScrollPane(ta), BorderLayout.CENTER);
071: }
072:
073: public void applyState() throws InvalidStateException {
074: if (ta.getText().trim().length() > 0) {
075: wizard.setHelpBroker(null);
076: } else {
077: wizard.setHelpBroker(new HelpBroker() {
078: public void activateHelp(JComponent parent,
079: WizardModel model) {
080: JOptionPane.showMessageDialog(parent,
081: "Help pressed for: "
082: + model.getActiveStep()
083: .getName());
084: }
085: });
086: }
087: }
088:
089: });
090: sm
091: .add(new AbstractWizardStep("Third step",
092: "My third step that has some longer text associated with it..") {
093: /////////////////////////////////////////////////////////////////////
094: // Abstract Methods
095: //
096: public void prepare() {
097: setBusy(true);
098: setComplete(false);
099: JProgressBar pgb = new JProgressBar();
100: pgb.setIndeterminate(true);
101: pgb.setString("Please wait..");
102: pgb.setStringPainted(true);
103: setView(pgb);
104: Timer t = new Timer(2000, new ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: setBusy(false);
107: setView(new JLabel("Done.."));
108: setComplete(true);
109: }
110: });
111: t.setRepeats(false);
112: t.start();
113: }
114:
115: public void applyState()
116: throws InvalidStateException {
117: //To change body of implemented methods use File | Settings | File Templates.
118: }
119:
120: public Dimension getPreferredSize() {
121: return new JLabel("Done..").getPreferredSize();
122: }
123:
124: public void init(WizardModel model) {
125: }
126: });
127: sm.add(new EmptyStep("Summary", "The end..") {
128:
129: public void applyState() throws InvalidStateException {
130: // throw new InvalidStateException("Oops...!");
131: setLayout(new BorderLayout());
132: add(new JLabel("Finished! (c:"), BorderLayout.CENTER);
133: }
134: });
135:
136: sm.setLastVisible(true);
137:
138: wizard = new Wizard(sm) {
139: protected JComponent createTitleComponent() {
140: DefaultTitleComponent titleComponent = (DefaultTitleComponent) super
141: .createTitleComponent();
142: titleComponent.setGradientBackground(true);
143: return titleComponent;
144: }
145: };
146: wizard.addWizardListener(new WizardAdapter() {
147: public void wizardClosed(WizardEvent e) {
148: System.exit(0);
149: }
150:
151: public void wizardCancelled(WizardEvent e) {
152: System.exit(0);
153: }
154: });
155:
156: // wizard.setOverviewVisible(false);
157: // wizard.showInFrame("My TestStatic Wizard");
158:
159: JFrame parent = new JFrame("blah");
160: parent.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
161: parent.setSize(100, 100);
162: parent.setLocationRelativeTo(null);
163: parent.setVisible(true);
164: wizard.showInDialog("blah", parent, true);
165: System.out.println("canceled: " + wizard.wasCanceled());
166:
167: }
168:
169: private static class TestModel extends StaticModel implements
170: HelpBroker {
171: public TestModel() {
172: }
173:
174: public void activateHelp(JComponent parent, WizardModel model) {
175: JOptionPane.showMessageDialog(parent, "Help pressed for: "
176: + model.getActiveStep().getName());
177: }
178: }
179:
180: }
|