KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > webman > wminstaller > app > InstallerScreen


1 package de.webman.wminstaller.app;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.*;
7 import java.beans.*;
8
9 /**
10  * @author <a HREF="mailto:ulf@webman.de">Ulf Goldammer</a>
11  * @version $Revision: 1.3 $
12  **/

13 public abstract class InstallerScreen
14     implements ActionListener
15 {
16     /* $Id: InstallerScreen.java,v 1.3 2002/03/08 14:38:59 gregor Exp $ */
17
18     public static final int BUTTONS_START = 10;
19     public static final int BUTTONS_MIDDLE = 20;
20     public static final int BUTTONS_FINISH = 30;
21     public static final int BUTTONS_END = 40;
22
23     protected Installer wmi;
24     JPanel contentPanel = new JPanel();
25     int typeOfButtons;
26     JPanel navPanel;
27     
28     public InstallerScreen( Installer wmi, int bt) {
29         this.wmi = wmi;
30         this.typeOfButtons = bt;
31     }
32
33     /**
34      * Subclasses must implement this method. This method has to collect
35      * the values from the screen and store it into the global
36      * ValueDictionary, a HashMap, which is available by
37      * Installer.getDictionary()
38      *
39      * @return returns <code>true</code> if the values a valid, and the
40      * navigator may continue to the next screen. Should return
41      * <code>false</code> if values are missing, has bad input, etc.
42      **/

43     public abstract boolean storeValues();
44
45     public boolean startInstallation() {
46         return true;
47     }
48     
49     public String JavaDoc getDataName() {
50         String JavaDoc dn = "";
51         StringTokenizer st = new StringTokenizer( this.getClass().getName(), ".", false);
52         while( st.hasMoreTokens() ) dn = st.nextToken();
53         return dn;
54     }
55     
56     public void actionPerformed( ActionEvent evt) {
57         String JavaDoc cmd = evt.getActionCommand();
58         if ( cmd.equals("ok"))
59             wmi.leave( 0);
60         else if ( cmd.equals("cancel"))
61             wmi.leave( 1);
62         else if ( cmd.equals("back"))
63             wmi.stepBackward();
64         else if ( cmd.equals("forward")) {
65             if (storeValues()) {
66                 wmi.stepForward();
67                 
68 // for (Iterator it = wmi.getDictionary().keySet().iterator();
69
// it.hasNext(); ) {
70
// String key = (String) it.next();
71
// System.out.println("|" + key + "='" + wmi.getDictionary().get(key) + "'|");
72
// }
73
}
74         }
75         else if ( cmd.equals("finish")) {
76             if (startInstallation())
77                 wmi.stepFinish();
78         }
79     }
80
81     private JPanel getNavigator (String JavaDoc backName, String JavaDoc backCmd,
82                                  String JavaDoc cancelName, String JavaDoc cancelCmd,
83                                  String JavaDoc forwardName, String JavaDoc forwardCmd) {
84         JPanel p = new JPanel();
85         JButton b;
86         p.setLayout( new BoxLayout( p, BoxLayout.X_AXIS));
87         // p.setBackground( Color.green);
88

89         boolean insertStrut = false;
90         
91         if ( backName != null ) {
92             b = new JButton( backName );
93             b.setActionCommand( backCmd.equals("") ? "back" : backCmd );
94             b.addActionListener( this );
95             if ( insertStrut ) p.add( Box.createHorizontalStrut( 20 ));
96             p.add( b );
97             insertStrut = true;
98         }
99         if ( cancelName != null) {
100             b = new JButton( cancelName);
101             b.setActionCommand( cancelCmd.equals("") ? "cancel" : cancelCmd );
102             b.addActionListener( this);
103             if ( insertStrut ) p.add( Box.createHorizontalStrut( 20 ));
104             p.add( b);
105             insertStrut = true;
106         }
107         
108         p.add( Box.createHorizontalStrut( 20));
109         p.add( Box.createHorizontalGlue());
110
111         if ( forwardName != null) {
112             b = new JButton( forwardName);
113             b.setActionCommand( forwardCmd.equals("") ? "forward" : forwardCmd );
114             b.addActionListener( this);
115             if ( insertStrut ) p.add( Box.createHorizontalStrut( 20 ));
116             p.add( b);
117             insertStrut = true;
118         }
119
120         JPanel q = new JPanel( new BorderLayout());
121         q.add( p, BorderLayout.SOUTH);
122         return q;
123     }
124     
125
126     /**
127      * adds a new component to the installer card screen; this method
128      * connects the component in question with the corresponding navigator.
129      * @param title the title screen
130      * @param panel the component (card) itself
131      * @return returns the index of the card in the card panel
132      */

133     public final int addScreen(String JavaDoc title, Component panel) {
134         switch ( typeOfButtons ) {
135         case BUTTONS_START:
136             return wmi.addScreen(title, panel,
137                                  getNavigator( null, "", "Abbruch", "", "Weiter", ""));
138         case BUTTONS_MIDDLE:
139             return wmi.addScreen(title, panel,
140                                  getNavigator( "Zurück", "", "Abbruch", "", "Weiter", ""));
141         case BUTTONS_FINISH:
142             return wmi.addScreen(title, panel,
143                                  getNavigator( "Zurück", "", "Abbruch", "", "Start", "finish"));
144         case BUTTONS_END:
145             return wmi.addScreen(title, panel,
146                                  getNavigator( null, "", null, "", "Ende", "ok"));
147         }
148
149         return -1;
150     }
151
152
153
154
155 }
156
157
Popular Tags