ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/ConfigurationDialog.java
Revision: 1.4
Committed: Tue Feb 27 03:09:58 2001 UTC (23 years, 3 months ago) by ajm
Branch: MAIN
Changes since 1.3: +174 -76 lines
Log Message:
Now has fully support for configuration modification, saving and loading.

Note there are still bugs, namely the server config is NOT treated seperately
from local config, as well as concurrency issues of loading in a config as
its changing.

Also not present is support for checking all REQUIRED configuration options
are present, so that will need to be done.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.ac.ukc.iscream.conient;
3
4 //---IMPORTS---
5 import java.awt.Frame;
6 import java.awt.Color;
7 import java.awt.GridLayout;
8 import java.awt.event.*;
9 import javax.swing.*;
10 import javax.swing.border.*;
11 import java.util.Properties;
12
13 /**
14 * This provides a modal dialog from which the user
15 * can reconfigure the conient client.
16 *
17 * It then writes back the configuration to the file.
18 *
19 * Server configured options are displayed, but are
20 * for information purposes only, and cannot be changed.
21 *
22 * @author $Author: ajm4 $
23 * @version $Id: ConfigurationDialog.java,v 1.3 2001/02/26 18:40:25 ajm4 Exp $
24 */
25 public class ConfigurationDialog extends JDialog {
26
27 //---FINAL ATTRIBUTES---
28
29 /**
30 * The current CVS revision of this class
31 */
32 public static final String REVISION = "$Revision: 1.3 $";
33
34 //---STATIC METHODS---
35
36 //---CONSTRUCTORS---
37
38 /**
39 * Constructs and shows the dialog for the user
40 */
41 public ConfigurationDialog() {
42 super(Conient.getFrame(), "Configuration Options", true);
43
44 // setup the buttoms
45 JPanel buttonPanel = new JPanel();
46 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
47 JButton ok = new JButton("OK");
48 ok.addActionListener(new ActionListener() {
49 public void actionPerformed(ActionEvent e) {
50 setNewSettingsAndClose();
51 }
52 });
53
54 JButton cancel = new JButton("Cancel");
55 cancel.addActionListener(new ActionListener() {
56 public void actionPerformed(ActionEvent e) {
57 dispose();
58 }
59 });
60 buttonPanel.add(Box.createHorizontalGlue());
61 buttonPanel.add(ok);
62 buttonPanel.add(cancel);
63
64
65 // setup the options panes
66 JPanel center = new JPanel();
67 center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
68
69 // client options
70 center.add(createClientOptions());
71
72 // server options
73 center.add(createServerOptions());
74
75 // firewall options
76 center.add(createFirewallOptions());
77
78 // data options
79 center.add(createDataOptions());
80
81 // display the current settings
82 getCurrentSettings();
83
84 // set the window up
85 getContentPane().add(buttonPanel, "South");
86 getContentPane().add(center, "Center");
87 pack();
88 setLocationRelativeTo(Conient.getFrame());
89 setResizable(false);
90 setVisible(true);
91 }
92
93 //---PUBLIC METHODS---
94
95 //---PRIVATE METHODS---
96
97 private JPanel createClientOptions() {
98 JPanel clientPanel = new JPanel();
99 clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS));
100 clientPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Client Options "));
101 JLabel nameLabel = new JLabel("Client name:");
102 nameLabel.setHorizontalAlignment(JLabel.RIGHT);
103 name = new JTextField(20);
104 JPanel nameBox = new JPanel();
105 nameBox.setLayout(new GridLayout(1,2));
106 nameBox.add(nameLabel);
107 nameBox.add(name);
108 clientPanel.add(nameBox);
109 return clientPanel;
110 }
111
112 private JPanel createServerOptions() {
113 JPanel serverPanel = new JPanel();
114 serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS));
115 serverPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " i-scream Server Options "));
116 JLabel serverLabel = new JLabel("i-scream Server:");
117 serverLabel.setHorizontalAlignment(JLabel.RIGHT);
118 server = new JTextField(20);
119 JPanel serverBox = new JPanel();
120 serverBox.setLayout(new GridLayout(1,2));
121 serverBox.add(serverLabel);
122 serverBox.add(server);
123 serverPanel.add(serverBox);
124
125 JLabel portLabel = new JLabel("Client interface port:");
126 portLabel.setHorizontalAlignment(JLabel.RIGHT);
127 port = new JTextField(4);
128 JPanel portBox = new JPanel();
129 portBox.setLayout(new GridLayout(1,2));
130 portBox.add(portLabel);
131 portBox.add(port);
132 serverPanel.add(portBox);
133
134 connectControl = new JCheckBox("Automatically connect the control channel");
135 serverPanel.add(connectControl);
136 connectData = new JCheckBox("Automatically connect the data channel");
137 serverPanel.add(connectData);
138 return serverPanel;
139 }
140
141 private JPanel createFirewallOptions() {
142 JPanel firewallPanel = new JPanel();
143 firewallPanel.setLayout(new BoxLayout(firewallPanel, BoxLayout.Y_AXIS));
144 firewallPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Firewall Options "));
145
146 useFirewall = new JCheckBox("Use firewall command to connect through to server");
147 firewallPanel.add(useFirewall);
148
149 JLabel commandLabel = new JLabel("Firewall command:");
150 commandLabel.setHorizontalAlignment(JLabel.RIGHT);
151 firewallCommand = new JTextField(20);
152 JPanel commandBox = new JPanel();
153 commandBox.setLayout(new GridLayout(1,2));
154 commandBox.add(commandLabel);
155 commandBox.add(firewallCommand);
156 firewallPanel.add(commandBox);
157
158 JLabel waitLabel = new JLabel("Firewall wait time:");
159 waitLabel.setHorizontalAlignment(JLabel.RIGHT);
160 firewallWait = new JTextField(2);
161 JPanel waitBox = new JPanel();
162 waitBox.setLayout(new GridLayout(1,2));
163 waitBox.add(waitLabel);
164 waitBox.add(firewallWait);
165 firewallPanel.add(waitBox);
166
167 JLabel fserverLabel = new JLabel("Firewall server:");
168 fserverLabel.setHorizontalAlignment(JLabel.RIGHT);
169 firewallServer = new JTextField(20);
170 JPanel fserverBox = new JPanel();
171 fserverBox.setLayout(new GridLayout(1,2));
172 fserverBox.add(fserverLabel);
173 fserverBox.add(firewallServer);
174 firewallPanel.add(fserverBox);
175 return firewallPanel;
176 }
177
178 private JPanel createDataOptions() {
179 JPanel dataPanel = new JPanel();
180 dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.X_AXIS));
181 dataPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Data Options "));
182
183 JPanel dataChecks = new JPanel();
184 dataChecks.setLayout(new BoxLayout(dataChecks, BoxLayout.Y_AXIS));
185 displayQueue = new JCheckBox("Display server queue information");
186 dataChecks.add(displayQueue);
187 displayExtra = new JCheckBox("Display extra data found in packets");
188 dataChecks.add(displayExtra);
189 packetDump = new JCheckBox("Dump raw packet data to the console");
190 dataChecks.add(packetDump);
191
192 dataPanel.add(Box.createHorizontalGlue());
193 dataPanel.add(dataChecks);
194 dataPanel.add(Box.createHorizontalGlue());
195 return dataPanel;
196 }
197
198 private void getCurrentSettings() {
199 Configuration config = Configuration.getInstance();
200 name.setText(config.getProperty("clientname"));
201 server.setText(config.getProperty("control.server"));
202 port.setText(config.getProperty("control.port"));
203 connectControl.setSelected(config.getProperty("control.onstartconnect").equals("1"));
204 connectData.setSelected(config.getProperty("data.onstartconnect").equals("1"));
205 firewallCommand.setText(config.getProperty("firewall.command"));
206 firewallCommand.moveCaretPosition(0);
207 firewallWait.setText(config.getProperty("firewall.commandwait"));
208 firewallServer.setText(config.getProperty("firewall.server"));
209 displayQueue.setSelected(config.getProperty("displayQueueInformation").equals("1"));
210 displayExtra.setSelected(config.getProperty("displayExtraData").equals("1"));
211 packetDump.setSelected(config.getProperty("packetDump").equals("1"));
212 useFirewall.setSelected(config.getProperty("useFirewall").equals("1"));
213 }
214
215 private void setNewSettingsAndClose() {
216 Configuration config = Configuration.getInstance();
217 config.setProperty("clientname", name.getText().trim());
218 config.setProperty("control.server", server.getText().trim());
219 config.setProperty("control.port", port.getText().trim());
220 config.setProperty("firewall.command", firewallCommand.getText().trim());
221 config.setProperty("firewall.commandwait", firewallWait.getText().trim());
222 config.setProperty("firewall.server", firewallServer.getText().trim());
223 if (useFirewall.isSelected()) {
224 config.setProperty("useFirewall", "1");
225 } else {
226 config.setProperty("useFirewall", "0");
227 }
228 if (connectControl.isSelected()) {
229 config.setProperty("control.onstartconnect", "1");
230 } else {
231 config.setProperty("control.onstartconnect", "0");
232 }
233 if (connectData.isSelected()) {
234 config.setProperty("data.onstartconnect", "1");
235 } else {
236 config.setProperty("data.onstartconnect", "0");
237 }
238 if (packetDump.isSelected()) {
239 config.setProperty("packetDump", "1");
240 } else {
241 config.setProperty("packetDump", "0");
242 }
243 if (displayExtra.isSelected()) {
244 config.setProperty("displayExtraData", "1");
245 } else {
246 config.setProperty("displayExtraData", "0");
247 }
248 if (displayQueue.isSelected()) {
249 config.setProperty("displayQueueInformation", "1");
250 } else {
251 config.setProperty("displayQueueInformation", "0");
252 }
253
254 dispose();
255 }
256
257 //---ACCESSOR/MUTATOR METHODS---
258
259 //---ATTRIBUTES---
260
261 private JTextField name;
262 private JTextField port;
263 private JTextField server;
264 private JCheckBox connectControl;
265 private JCheckBox connectData;
266 private JCheckBox useFirewall;
267 private JTextField firewallCommand;
268 private JTextField firewallWait;
269 private JTextField firewallServer;
270 private JCheckBox displayQueue;
271 private JCheckBox displayExtra;
272 private JCheckBox packetDump;
273
274
275 //---STATIC ATTRIBUTES---
276
277 }