001: package de.webman.wminstaller.app;
002:
003: import javax.swing.*;
004: import java.awt.*;
005: import java.awt.event.*;
006: import java.util.*;
007: import java.beans.*;
008:
009: /**
010: * @author <a href="mailto:ulf@webman.de">Ulf Goldammer</a>
011: * @version $Revision: 1.3 $
012: **/
013: public abstract class InstallerScreen implements ActionListener {
014: /* $Id: InstallerScreen.java,v 1.3 2002/03/08 14:38:59 gregor Exp $ */
015:
016: public static final int BUTTONS_START = 10;
017: public static final int BUTTONS_MIDDLE = 20;
018: public static final int BUTTONS_FINISH = 30;
019: public static final int BUTTONS_END = 40;
020:
021: protected Installer wmi;
022: JPanel contentPanel = new JPanel();
023: int typeOfButtons;
024: JPanel navPanel;
025:
026: public InstallerScreen(Installer wmi, int bt) {
027: this .wmi = wmi;
028: this .typeOfButtons = bt;
029: }
030:
031: /**
032: * Subclasses must implement this method. This method has to collect
033: * the values from the screen and store it into the global
034: * ValueDictionary, a HashMap, which is available by
035: * Installer.getDictionary()
036: *
037: * @return returns <code>true</code> if the values a valid, and the
038: * navigator may continue to the next screen. Should return
039: * <code>false</code> if values are missing, has bad input, etc.
040: **/
041: public abstract boolean storeValues();
042:
043: public boolean startInstallation() {
044: return true;
045: }
046:
047: public String getDataName() {
048: String dn = "";
049: StringTokenizer st = new StringTokenizer(this .getClass()
050: .getName(), ".", false);
051: while (st.hasMoreTokens())
052: dn = st.nextToken();
053: return dn;
054: }
055:
056: public void actionPerformed(ActionEvent evt) {
057: String cmd = evt.getActionCommand();
058: if (cmd.equals("ok"))
059: wmi.leave(0);
060: else if (cmd.equals("cancel"))
061: wmi.leave(1);
062: else if (cmd.equals("back"))
063: wmi.stepBackward();
064: else if (cmd.equals("forward")) {
065: if (storeValues()) {
066: wmi.stepForward();
067:
068: // for (Iterator it = wmi.getDictionary().keySet().iterator();
069: // it.hasNext(); ) {
070: // String key = (String) it.next();
071: // System.out.println("|" + key + "='" + wmi.getDictionary().get(key) + "'|");
072: // }
073: }
074: } else if (cmd.equals("finish")) {
075: if (startInstallation())
076: wmi.stepFinish();
077: }
078: }
079:
080: private JPanel getNavigator(String backName, String backCmd,
081: String cancelName, String cancelCmd, String forwardName,
082: String forwardCmd) {
083: JPanel p = new JPanel();
084: JButton b;
085: p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
086: // p.setBackground( Color.green);
087:
088: boolean insertStrut = false;
089:
090: if (backName != null) {
091: b = new JButton(backName);
092: b.setActionCommand(backCmd.equals("") ? "back" : backCmd);
093: b.addActionListener(this );
094: if (insertStrut)
095: p.add(Box.createHorizontalStrut(20));
096: p.add(b);
097: insertStrut = true;
098: }
099: if (cancelName != null) {
100: b = new JButton(cancelName);
101: b.setActionCommand(cancelCmd.equals("") ? "cancel"
102: : cancelCmd);
103: b.addActionListener(this );
104: if (insertStrut)
105: p.add(Box.createHorizontalStrut(20));
106: p.add(b);
107: insertStrut = true;
108: }
109:
110: p.add(Box.createHorizontalStrut(20));
111: p.add(Box.createHorizontalGlue());
112:
113: if (forwardName != null) {
114: b = new JButton(forwardName);
115: b.setActionCommand(forwardCmd.equals("") ? "forward"
116: : forwardCmd);
117: b.addActionListener(this );
118: if (insertStrut)
119: p.add(Box.createHorizontalStrut(20));
120: p.add(b);
121: insertStrut = true;
122: }
123:
124: JPanel q = new JPanel(new BorderLayout());
125: q.add(p, BorderLayout.SOUTH);
126: return q;
127: }
128:
129: /**
130: * adds a new component to the installer card screen; this method
131: * connects the component in question with the corresponding navigator.
132: * @param title the title screen
133: * @param panel the component (card) itself
134: * @return returns the index of the card in the card panel
135: */
136: public final int addScreen(String title, Component panel) {
137: switch (typeOfButtons) {
138: case BUTTONS_START:
139: return wmi.addScreen(title, panel, getNavigator(null, "",
140: "Abbruch", "", "Weiter", ""));
141: case BUTTONS_MIDDLE:
142: return wmi.addScreen(title, panel, getNavigator("Zurück",
143: "", "Abbruch", "", "Weiter", ""));
144: case BUTTONS_FINISH:
145: return wmi.addScreen(title, panel, getNavigator("Zurück",
146: "", "Abbruch", "", "Start", "finish"));
147: case BUTTONS_END:
148: return wmi.addScreen(title, panel, getNavigator(null, "",
149: null, "", "Ende", "ok"));
150: }
151:
152: return -1;
153: }
154:
155: }
|