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 |
import java.util.StringTokenizer; |
13 |
|
14 |
/** |
15 |
* This provides a modal dialog from which the user |
16 |
* can reconfigure the conient client. |
17 |
* |
18 |
* It then writes back the configuration to the file. |
19 |
* |
20 |
* Server configured options are displayed, but are |
21 |
* for information purposes only, and cannot be changed. |
22 |
* |
23 |
* @author $Author: ajm4 $ |
24 |
* @version $Id: ConfigurationDialog.java,v 1.4 2001/02/27 03:09:58 ajm4 Exp $ |
25 |
*/ |
26 |
public class ConfigurationDialog extends JDialog { |
27 |
|
28 |
//---FINAL ATTRIBUTES--- |
29 |
|
30 |
/** |
31 |
* The current CVS revision of this class |
32 |
*/ |
33 |
public static final String REVISION = "$Revision: 1.4 $"; |
34 |
|
35 |
//---STATIC METHODS--- |
36 |
|
37 |
//---CONSTRUCTORS--- |
38 |
|
39 |
/** |
40 |
* Constructs and shows the dialog for the user |
41 |
*/ |
42 |
public ConfigurationDialog() { |
43 |
super(Conient.getFrame(), "Configuration Options", true); |
44 |
|
45 |
// setup the buttoms |
46 |
JPanel buttonPanel = new JPanel(); |
47 |
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); |
48 |
JButton ok = new JButton("OK"); |
49 |
ok.addActionListener(new ActionListener() { |
50 |
public void actionPerformed(ActionEvent e) { |
51 |
setNewSettingsAndClose(); |
52 |
} |
53 |
}); |
54 |
|
55 |
JButton cancel = new JButton("Cancel"); |
56 |
cancel.addActionListener(new ActionListener() { |
57 |
public void actionPerformed(ActionEvent e) { |
58 |
dispose(); |
59 |
} |
60 |
}); |
61 |
buttonPanel.add(Box.createHorizontalGlue()); |
62 |
buttonPanel.add(ok); |
63 |
buttonPanel.add(cancel); |
64 |
|
65 |
|
66 |
// setup the options panes |
67 |
JTabbedPane center = new JTabbedPane(); |
68 |
//center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS)); |
69 |
|
70 |
// client options |
71 |
center.addTab("Client Options", createClientOptions()); |
72 |
|
73 |
// server options |
74 |
center.addTab("Server Options", createServerOptions()); |
75 |
|
76 |
// firewall options |
77 |
center.addTab("Firewall Options", createFirewallOptions()); |
78 |
|
79 |
// data options |
80 |
center.addTab("Data Options", createDataOptions()); |
81 |
|
82 |
// display the current settings |
83 |
getCurrentSettings(); |
84 |
|
85 |
// set the window up |
86 |
getContentPane().add(buttonPanel, "South"); |
87 |
getContentPane().add(center, "Center"); |
88 |
pack(); |
89 |
setLocationRelativeTo(Conient.getFrame()); |
90 |
setResizable(false); |
91 |
setVisible(true); |
92 |
} |
93 |
|
94 |
//---PUBLIC METHODS--- |
95 |
|
96 |
//---PRIVATE METHODS--- |
97 |
|
98 |
private JPanel createClientOptions() { |
99 |
JPanel clientPanel = new JPanel(); |
100 |
clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS)); |
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 |
|
110 |
JPanel lists = new JPanel(); |
111 |
lists.setLayout(new BoxLayout(lists, BoxLayout.X_AXIS)); |
112 |
|
113 |
JPanel knownHostsPanel = new JPanel(); |
114 |
knownHostsPanel.setLayout(new BoxLayout(knownHostsPanel, BoxLayout.Y_AXIS)); |
115 |
hostDiscoveryMode = new JCheckBox("Discover new hosts from the server"); |
116 |
knownHostsPanel.add(hostDiscoveryMode); |
117 |
knownHostsPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Known Hosts ")); |
118 |
knownHosts = new JList(); |
119 |
knownHosts.setVisibleRowCount(10); |
120 |
JScrollPane knownHostsScrollPane = new JScrollPane(knownHosts); |
121 |
knownHostsPanel.add(knownHostsScrollPane); |
122 |
JLabel newHostLabel = new JLabel("New host:"); |
123 |
newHostLabel.setHorizontalAlignment(JLabel.RIGHT); |
124 |
newHost = new JTextField(20); |
125 |
JButton newHostButton = new JButton("Add to known hosts"); |
126 |
JPanel newHostBox = new JPanel(); |
127 |
newHostBox.setLayout(new GridLayout(1,3)); |
128 |
newHostBox.add(newHostLabel); |
129 |
newHostBox.add(newHost); |
130 |
|
131 |
knownHostsPanel.add(newHostBox); |
132 |
knownHostsPanel.add(newHostButton); |
133 |
lists.add(knownHostsPanel); |
134 |
|
135 |
|
136 |
JPanel addRemoveBox = new JPanel(); |
137 |
addRemoveBox.setLayout(new BoxLayout(addRemoveBox, BoxLayout.Y_AXIS)); |
138 |
addRemoveBox.add(Box.createGlue()); |
139 |
JButton add = new JButton(">>>"); |
140 |
addRemoveBox.add(add); |
141 |
addRemoveBox.add(Box.createGlue()); |
142 |
JButton remove = new JButton("<<<"); |
143 |
addRemoveBox.add(remove); |
144 |
addRemoveBox.add(Box.createGlue()); |
145 |
lists.add(addRemoveBox); |
146 |
|
147 |
JPanel hostListPanel = new JPanel(); |
148 |
hostListPanel.setLayout(new BoxLayout(hostListPanel, BoxLayout.Y_AXIS)); |
149 |
useHostList = new JCheckBox("Only monitor hosts in this list"); |
150 |
hostListPanel.add(useHostList); |
151 |
hostListPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Hosts To Monitor ")); |
152 |
hostList = new JList(); |
153 |
hostList.setVisibleRowCount(10); |
154 |
JScrollPane hostListScrollPane = new JScrollPane(hostList); |
155 |
hostListPanel.add(hostListScrollPane); |
156 |
lists.add(hostListPanel); |
157 |
|
158 |
clientPanel.add(lists); |
159 |
return clientPanel; |
160 |
} |
161 |
|
162 |
private JPanel createServerOptions() { |
163 |
JPanel serverPanel = new JPanel(); |
164 |
serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS)); |
165 |
JLabel serverLabel = new JLabel("i-scream Server:"); |
166 |
serverLabel.setHorizontalAlignment(JLabel.RIGHT); |
167 |
server = new JTextField(20); |
168 |
JPanel serverBox = new JPanel(); |
169 |
serverBox.setLayout(new GridLayout(1,2)); |
170 |
serverBox.add(serverLabel); |
171 |
serverBox.add(server); |
172 |
serverPanel.add(serverBox); |
173 |
|
174 |
JLabel portLabel = new JLabel("Client interface port:"); |
175 |
portLabel.setHorizontalAlignment(JLabel.RIGHT); |
176 |
port = new JTextField(4); |
177 |
JPanel portBox = new JPanel(); |
178 |
portBox.setLayout(new GridLayout(1,2)); |
179 |
portBox.add(portLabel); |
180 |
portBox.add(port); |
181 |
serverPanel.add(portBox); |
182 |
|
183 |
connectControl = new JCheckBox("Automatically connect the control channel"); |
184 |
serverPanel.add(connectControl); |
185 |
connectData = new JCheckBox("Automatically connect the data channel"); |
186 |
serverPanel.add(connectData); |
187 |
return serverPanel; |
188 |
} |
189 |
|
190 |
private JPanel createFirewallOptions() { |
191 |
JPanel firewallPanel = new JPanel(); |
192 |
firewallPanel.setLayout(new BoxLayout(firewallPanel, BoxLayout.Y_AXIS)); |
193 |
|
194 |
useFirewall = new JCheckBox("Use firewall command to connect through to server"); |
195 |
firewallPanel.add(useFirewall); |
196 |
|
197 |
JLabel commandLabel = new JLabel("Firewall command:"); |
198 |
commandLabel.setHorizontalAlignment(JLabel.RIGHT); |
199 |
firewallCommand = new JTextField(20); |
200 |
JPanel commandBox = new JPanel(); |
201 |
commandBox.setLayout(new GridLayout(1,2)); |
202 |
commandBox.add(commandLabel); |
203 |
commandBox.add(firewallCommand); |
204 |
|
205 |
firewallPanel.add(commandBox); |
206 |
|
207 |
JLabel waitLabel = new JLabel("Firewall wait time:"); |
208 |
waitLabel.setHorizontalAlignment(JLabel.RIGHT); |
209 |
firewallWait = new JTextField(2); |
210 |
JPanel waitBox = new JPanel(); |
211 |
waitBox.setLayout(new GridLayout(1,2)); |
212 |
waitBox.add(waitLabel); |
213 |
waitBox.add(firewallWait); |
214 |
|
215 |
firewallPanel.add(waitBox); |
216 |
|
217 |
JLabel fserverLabel = new JLabel("Firewall server:"); |
218 |
fserverLabel.setHorizontalAlignment(JLabel.RIGHT); |
219 |
firewallServer = new JTextField(20); |
220 |
JPanel fserverBox = new JPanel(); |
221 |
fserverBox.setLayout(new GridLayout(1,2)); |
222 |
fserverBox.add(fserverLabel); |
223 |
fserverBox.add(firewallServer); |
224 |
|
225 |
firewallPanel.add(fserverBox); |
226 |
firewallPanel.add(Box.createGlue()); |
227 |
return firewallPanel; |
228 |
} |
229 |
|
230 |
private JPanel createDataOptions() { |
231 |
JPanel dataPanel = new JPanel(); |
232 |
dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS)); |
233 |
|
234 |
displayQueue = new JCheckBox("Display server queue information"); |
235 |
dataPanel.add(displayQueue); |
236 |
displayExtra = new JCheckBox("Display extra data found in packets"); |
237 |
dataPanel.add(displayExtra); |
238 |
packetDump = new JCheckBox("Dump raw packet data to the console"); |
239 |
dataPanel.add(packetDump); |
240 |
|
241 |
dataPanel.add(Box.createGlue()); |
242 |
return dataPanel; |
243 |
} |
244 |
|
245 |
private void getCurrentSettings() { |
246 |
name.setText(config.getProperty("clientname")); |
247 |
server.setText(config.getProperty("control.server")); |
248 |
port.setText(config.getProperty("control.port")); |
249 |
connectControl.setSelected(config.getProperty("control.onstartconnect").equals("1")); |
250 |
connectData.setSelected(config.getProperty("data.onstartconnect").equals("1")); |
251 |
firewallCommand.setText(config.getProperty("firewall.command")); |
252 |
firewallCommand.moveCaretPosition(0); |
253 |
firewallWait.setText(config.getProperty("firewall.commandwait")); |
254 |
firewallServer.setText(config.getProperty("firewall.server")); |
255 |
displayQueue.setSelected(config.getProperty("displayQueueInformation").equals("1")); |
256 |
displayExtra.setSelected(config.getProperty("displayExtraData").equals("1")); |
257 |
packetDump.setSelected(config.getProperty("packetDump").equals("1")); |
258 |
useFirewall.setSelected(config.getProperty("useFirewall").equals("1")); |
259 |
hostDiscoveryMode.setSelected(config.getProperty("hostDiscoveryMode").equals("1")); |
260 |
useHostList.setSelected(config.getProperty("useHostList").equals("1")); |
261 |
prepareLists(); |
262 |
} |
263 |
|
264 |
|
265 |
private void prepareLists() { |
266 |
knownHostsModel = new DefaultListModel(); |
267 |
hostListModel = new DefaultListModel(); |
268 |
String configKnownHostsList = config.getProperty("knownHostsList"); |
269 |
String configHostList = config.getProperty("hostList"); |
270 |
StringTokenizer st; |
271 |
st = new StringTokenizer(configKnownHostsList, ";"); |
272 |
while(st.hasMoreTokens()) { |
273 |
knownHostsModel.addElement(st.nextToken()); |
274 |
} |
275 |
st = new StringTokenizer(configHostList, ";"); |
276 |
while(st.hasMoreTokens()) { |
277 |
hostListModel.addElement(st.nextToken()); |
278 |
} |
279 |
knownHosts.setModel(knownHostsModel); |
280 |
hostList.setModel(hostListModel); |
281 |
} |
282 |
|
283 |
private void setNewSettingsAndClose() { |
284 |
|
285 |
config.setProperty("clientname", name.getText().trim()); |
286 |
config.setProperty("control.server", server.getText().trim()); |
287 |
config.setProperty("control.port", port.getText().trim()); |
288 |
config.setProperty("firewall.command", firewallCommand.getText().trim()); |
289 |
config.setProperty("firewall.commandwait", firewallWait.getText().trim()); |
290 |
config.setProperty("firewall.server", firewallServer.getText().trim()); |
291 |
if (useFirewall.isSelected()) { |
292 |
config.setProperty("useFirewall", "1"); |
293 |
} else { |
294 |
config.setProperty("useFirewall", "0"); |
295 |
} |
296 |
if (connectControl.isSelected()) { |
297 |
config.setProperty("control.onstartconnect", "1"); |
298 |
} else { |
299 |
config.setProperty("control.onstartconnect", "0"); |
300 |
} |
301 |
if (connectData.isSelected()) { |
302 |
config.setProperty("data.onstartconnect", "1"); |
303 |
} else { |
304 |
config.setProperty("data.onstartconnect", "0"); |
305 |
} |
306 |
if (packetDump.isSelected()) { |
307 |
config.setProperty("packetDump", "1"); |
308 |
} else { |
309 |
config.setProperty("packetDump", "0"); |
310 |
} |
311 |
if (displayExtra.isSelected()) { |
312 |
config.setProperty("displayExtraData", "1"); |
313 |
} else { |
314 |
config.setProperty("displayExtraData", "0"); |
315 |
} |
316 |
if (displayQueue.isSelected()) { |
317 |
config.setProperty("displayQueueInformation", "1"); |
318 |
} else { |
319 |
config.setProperty("displayQueueInformation", "0"); |
320 |
} |
321 |
if (useHostList.isSelected()) { |
322 |
config.setProperty("useHostList", "1"); |
323 |
} else { |
324 |
config.setProperty("useHostList", "0"); |
325 |
} |
326 |
if (hostDiscoveryMode.isSelected()) { |
327 |
config.setProperty("hostDiscoveryMode", "1"); |
328 |
} else { |
329 |
config.setProperty("hostDiscoveryMode", "0"); |
330 |
} |
331 |
dispose(); |
332 |
} |
333 |
|
334 |
//---ACCESSOR/MUTATOR METHODS--- |
335 |
|
336 |
//---ATTRIBUTES--- |
337 |
|
338 |
Configuration config = Configuration.getInstance(); |
339 |
|
340 |
private JTextField newHost; |
341 |
|
342 |
private JList knownHosts; |
343 |
private JList hostList; |
344 |
private JCheckBox hostDiscoveryMode; |
345 |
private JCheckBox useHostList; |
346 |
private JTextField name; |
347 |
private JTextField port; |
348 |
private JTextField server; |
349 |
private JCheckBox connectControl; |
350 |
private JCheckBox connectData; |
351 |
private JCheckBox useFirewall; |
352 |
private JTextField firewallCommand; |
353 |
private JTextField firewallWait; |
354 |
private JTextField firewallServer; |
355 |
private JCheckBox displayQueue; |
356 |
private JCheckBox displayExtra; |
357 |
private JCheckBox packetDump; |
358 |
|
359 |
private DefaultListModel knownHostsModel; |
360 |
private DefaultListModel hostListModel; |
361 |
|
362 |
|
363 |
//---STATIC ATTRIBUTES--- |
364 |
|
365 |
} |