2 |
|
package uk.org.iscream.conient; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import java.awt.Frame; |
6 |
< |
import java.awt.Color; |
7 |
< |
import java.awt.GridLayout; |
5 |
> |
import java.awt.*; |
6 |
|
import java.awt.event.*; |
7 |
|
import javax.swing.*; |
8 |
|
import javax.swing.border.*; |
13 |
|
* This provides a modal dialog from which the user |
14 |
|
* can reconfigure the conient client. |
15 |
|
* |
16 |
< |
* It then writes back the configuration to the file. |
16 |
> |
* Look at the comments for the attributes of this class to see |
17 |
> |
* what configuration options this class deals with. |
18 |
|
* |
19 |
< |
* Server configured options are displayed, but are |
20 |
< |
* for information purposes only, and cannot be changed. |
19 |
> |
* It then writes back the configuration to the loaded configuration. |
20 |
> |
* The user can then opt to save it. |
21 |
|
* |
22 |
+ |
* |
23 |
|
* @author $Author$ |
24 |
|
* @version $Id$ |
25 |
|
*/ |
95 |
|
|
96 |
|
//---PRIVATE METHODS--- |
97 |
|
|
98 |
+ |
/** |
99 |
+ |
* creates a JPanel for the client options |
100 |
+ |
* |
101 |
+ |
* @return the build panel with the options |
102 |
+ |
*/ |
103 |
|
private JPanel createClientOptions() { |
104 |
+ |
GridBagLayout gridbag = new GridBagLayout(); |
105 |
+ |
GridBagLayout gridbag2 = new GridBagLayout(); |
106 |
+ |
GridBagConstraints c = new GridBagConstraints(); |
107 |
+ |
c.fill = GridBagConstraints.HORIZONTAL; |
108 |
+ |
|
109 |
|
JPanel clientPanel = new JPanel(); |
110 |
< |
clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS)); |
110 |
> |
clientPanel.setLayout(gridbag); |
111 |
|
JLabel nameLabel = new JLabel("Client name:"); |
112 |
|
nameLabel.setHorizontalAlignment(JLabel.RIGHT); |
113 |
|
name = new JTextField(20); |
115 |
|
nameBox.setLayout(new GridLayout(1,2)); |
116 |
|
nameBox.add(nameLabel); |
117 |
|
nameBox.add(name); |
118 |
+ |
|
119 |
+ |
c.gridy = 0; |
120 |
+ |
gridbag.setConstraints(nameBox, c); |
121 |
|
clientPanel.add(nameBox); |
122 |
|
|
123 |
|
JPanel lists = new JPanel(); |
124 |
< |
lists.setLayout(new BoxLayout(lists, BoxLayout.X_AXIS)); |
124 |
> |
lists.setLayout(gridbag2); |
125 |
|
|
126 |
|
JPanel knownHostsPanel = new JPanel(); |
127 |
|
knownHostsPanel.setLayout(new BoxLayout(knownHostsPanel, BoxLayout.Y_AXIS)); |
135 |
|
JLabel newHostLabel = new JLabel("New host:"); |
136 |
|
newHostLabel.setHorizontalAlignment(JLabel.RIGHT); |
137 |
|
newHost = new JTextField(20); |
138 |
< |
JButton newHostButton = new JButton("Add to known hosts"); |
138 |
> |
|
139 |
> |
JButton newHostButton = new JButton("Add Host"); |
140 |
|
newHostButton.addActionListener(new ActionListener() { |
141 |
|
public void actionPerformed(ActionEvent e) { |
142 |
|
knownHostsModel.addElement(newHost.getText()); |
143 |
|
newHost.setText(""); |
144 |
|
} |
145 |
|
}); |
146 |
+ |
JButton removeHostButton = new JButton("Remove Host(s)"); |
147 |
+ |
removeHostButton.addActionListener(new ActionListener() { |
148 |
+ |
public void actionPerformed(ActionEvent e) { |
149 |
+ |
Object[] selected = knownHosts.getSelectedValues(); |
150 |
+ |
for(int x = 0; x < selected.length; x++) { |
151 |
+ |
knownHostsModel.removeElement(selected[x]); |
152 |
+ |
} |
153 |
+ |
} |
154 |
+ |
}); |
155 |
|
JPanel newHostBox = new JPanel(); |
156 |
|
newHostBox.setLayout(new GridLayout(1,3)); |
157 |
|
newHostBox.add(newHostLabel); |
158 |
|
newHostBox.add(newHost); |
159 |
< |
|
159 |
> |
|
160 |
> |
JPanel buttonPanel = new JPanel(); |
161 |
> |
buttonPanel.add(newHostButton); |
162 |
> |
buttonPanel.add(removeHostButton); |
163 |
> |
knownHostsPanel.add(buttonPanel); |
164 |
|
knownHostsPanel.add(newHostBox); |
165 |
< |
knownHostsPanel.add(newHostButton); |
165 |
> |
|
166 |
> |
|
167 |
> |
c.gridy = 0; |
168 |
> |
c.gridx = 0; |
169 |
> |
gridbag.setConstraints(knownHostsPanel, c); |
170 |
|
lists.add(knownHostsPanel); |
171 |
|
|
172 |
|
|
198 |
|
}); |
199 |
|
addRemoveBox.add(remove); |
200 |
|
addRemoveBox.add(Box.createGlue()); |
201 |
+ |
|
202 |
+ |
c.gridy = 0; |
203 |
+ |
c.gridx = 1; |
204 |
+ |
gridbag.setConstraints(addRemoveBox, c); |
205 |
|
lists.add(addRemoveBox); |
206 |
|
|
207 |
|
JPanel hostListPanel = new JPanel(); |
213 |
|
hostList.setVisibleRowCount(10); |
214 |
|
JScrollPane hostListScrollPane = new JScrollPane(hostList); |
215 |
|
hostListPanel.add(hostListScrollPane); |
216 |
+ |
|
217 |
+ |
c.gridy = 0; |
218 |
+ |
c.gridx = 2; |
219 |
+ |
gridbag.setConstraints(hostListPanel, c); |
220 |
|
lists.add(hostListPanel); |
221 |
|
|
222 |
+ |
c.gridy = 1; |
223 |
+ |
c.gridx = 0; |
224 |
+ |
gridbag.setConstraints(lists, c); |
225 |
|
clientPanel.add(lists); |
226 |
|
return clientPanel; |
227 |
|
} |
228 |
< |
|
228 |
> |
|
229 |
> |
/** |
230 |
> |
* creates a JPanel for the server options |
231 |
> |
* |
232 |
> |
* @return the build panel with the options |
233 |
> |
*/ |
234 |
|
private JPanel createServerOptions() { |
235 |
+ |
GridBagLayout gridbag = new GridBagLayout(); |
236 |
+ |
GridBagConstraints c = new GridBagConstraints(); |
237 |
+ |
c.fill = GridBagConstraints.HORIZONTAL; |
238 |
|
JPanel serverPanel = new JPanel(); |
239 |
< |
serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS)); |
239 |
> |
serverPanel.setLayout(gridbag); |
240 |
> |
connectControl = new JCheckBox("Automatically connect the control channel"); |
241 |
> |
c.gridy = 0; |
242 |
> |
gridbag.setConstraints(connectControl, c); |
243 |
> |
serverPanel.add(connectControl); |
244 |
> |
connectData = new JCheckBox("Automatically connect the data channel"); |
245 |
> |
c.gridy = 1; |
246 |
> |
gridbag.setConstraints(connectData, c); |
247 |
> |
serverPanel.add(connectData); |
248 |
|
JLabel serverLabel = new JLabel("i-scream Server:"); |
249 |
|
serverLabel.setHorizontalAlignment(JLabel.RIGHT); |
250 |
|
server = new JTextField(20); |
252 |
|
serverBox.setLayout(new GridLayout(1,2)); |
253 |
|
serverBox.add(serverLabel); |
254 |
|
serverBox.add(server); |
255 |
+ |
c.gridy = 2; |
256 |
+ |
gridbag.setConstraints(serverBox, c); |
257 |
|
serverPanel.add(serverBox); |
198 |
– |
|
258 |
|
JLabel portLabel = new JLabel("Client interface port:"); |
259 |
|
portLabel.setHorizontalAlignment(JLabel.RIGHT); |
260 |
|
port = new JTextField(4); |
262 |
|
portBox.setLayout(new GridLayout(1,2)); |
263 |
|
portBox.add(portLabel); |
264 |
|
portBox.add(port); |
265 |
+ |
c.gridy = 3; |
266 |
+ |
gridbag.setConstraints(portBox, c); |
267 |
|
serverPanel.add(portBox); |
207 |
– |
|
208 |
– |
connectControl = new JCheckBox("Automatically connect the control channel"); |
209 |
– |
serverPanel.add(connectControl); |
210 |
– |
connectData = new JCheckBox("Automatically connect the data channel"); |
211 |
– |
serverPanel.add(connectData); |
268 |
|
return serverPanel; |
269 |
|
} |
270 |
|
|
271 |
+ |
/** |
272 |
+ |
* creates a JPanel for the firewall options |
273 |
+ |
* |
274 |
+ |
* @return the build panel with the options |
275 |
+ |
*/ |
276 |
|
private JPanel createFirewallOptions() { |
277 |
+ |
GridBagLayout gridbag = new GridBagLayout(); |
278 |
+ |
GridBagConstraints c = new GridBagConstraints(); |
279 |
+ |
c.fill = GridBagConstraints.HORIZONTAL; |
280 |
|
JPanel firewallPanel = new JPanel(); |
281 |
< |
firewallPanel.setLayout(new BoxLayout(firewallPanel, BoxLayout.Y_AXIS)); |
281 |
> |
firewallPanel.setLayout(gridbag); |
282 |
> |
|
283 |
|
|
284 |
|
useFirewall = new JCheckBox("Use firewall command to connect through to server"); |
285 |
+ |
c.gridy = 0; |
286 |
+ |
gridbag.setConstraints(useFirewall, c); |
287 |
|
firewallPanel.add(useFirewall); |
288 |
< |
|
288 |
> |
|
289 |
|
JLabel commandLabel = new JLabel("Firewall command:"); |
290 |
|
commandLabel.setHorizontalAlignment(JLabel.RIGHT); |
291 |
|
firewallCommand = new JTextField(20); |
294 |
|
commandBox.add(commandLabel); |
295 |
|
commandBox.add(firewallCommand); |
296 |
|
|
297 |
+ |
c.gridy = 1; |
298 |
+ |
gridbag.setConstraints(commandBox, c); |
299 |
|
firewallPanel.add(commandBox); |
300 |
|
|
301 |
|
JLabel waitLabel = new JLabel("Firewall wait time:"); |
305 |
|
waitBox.setLayout(new GridLayout(1,2)); |
306 |
|
waitBox.add(waitLabel); |
307 |
|
waitBox.add(firewallWait); |
308 |
< |
|
308 |
> |
|
309 |
> |
c.gridy = 2; |
310 |
> |
gridbag.setConstraints(waitBox, c); |
311 |
|
firewallPanel.add(waitBox); |
312 |
|
|
313 |
|
JLabel fserverLabel = new JLabel("Firewall server:"); |
318 |
|
fserverBox.add(fserverLabel); |
319 |
|
fserverBox.add(firewallServer); |
320 |
|
|
321 |
+ |
c.gridy = 3; |
322 |
+ |
gridbag.setConstraints(fserverBox, c); |
323 |
|
firewallPanel.add(fserverBox); |
324 |
< |
firewallPanel.add(Box.createGlue()); |
324 |
> |
|
325 |
|
return firewallPanel; |
326 |
|
} |
327 |
|
|
328 |
+ |
/** |
329 |
+ |
* creates a JPanel for the data options |
330 |
+ |
* |
331 |
+ |
* @return the build panel with the options |
332 |
+ |
*/ |
333 |
|
private JPanel createDataOptions() { |
334 |
+ |
GridBagLayout gridbag = new GridBagLayout(); |
335 |
+ |
GridBagConstraints c = new GridBagConstraints(); |
336 |
+ |
c.fill = GridBagConstraints.HORIZONTAL; |
337 |
|
JPanel dataPanel = new JPanel(); |
338 |
< |
dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS)); |
258 |
< |
|
338 |
> |
dataPanel.setLayout(gridbag); |
339 |
|
displayQueue = new JCheckBox("Display server queue information"); |
340 |
+ |
c.gridy = 0; |
341 |
+ |
gridbag.setConstraints(displayQueue, c); |
342 |
|
dataPanel.add(displayQueue); |
343 |
|
displayExtra = new JCheckBox("Display extra data found in packets"); |
344 |
+ |
c.gridy = 1; |
345 |
+ |
gridbag.setConstraints(displayExtra, c); |
346 |
|
dataPanel.add(displayExtra); |
347 |
|
packetDump = new JCheckBox("Dump raw packet data to the console"); |
348 |
+ |
c.gridy = 2; |
349 |
+ |
gridbag.setConstraints(packetDump, c); |
350 |
|
dataPanel.add(packetDump); |
351 |
< |
|
352 |
< |
dataPanel.add(Box.createGlue()); |
351 |
> |
|
352 |
> |
JLabel queueLimitLabel = new JLabel("Maximum data queue size:"); |
353 |
> |
queueLimitLabel.setHorizontalAlignment(JLabel.RIGHT); |
354 |
> |
queueLimit = new JTextField(4); |
355 |
> |
JPanel queueBox = new JPanel(); |
356 |
> |
queueBox.setLayout(new GridLayout(1,2)); |
357 |
> |
queueBox.add(queueLimitLabel); |
358 |
> |
queueBox.add(queueLimit); |
359 |
> |
c.gridy = 3; |
360 |
> |
gridbag.setConstraints(queueBox, c); |
361 |
> |
dataPanel.add(queueBox); |
362 |
|
return dataPanel; |
363 |
|
} |
364 |
|
|
365 |
+ |
/** |
366 |
+ |
* Reads in the current settings from the loaded configuration |
367 |
+ |
*/ |
368 |
|
private void getCurrentSettings() { |
369 |
|
name.setText(config.getProperty("clientname")); |
370 |
|
server.setText(config.getProperty("control.server")); |
381 |
|
useFirewall.setSelected(config.getProperty("useFirewall").equals("1")); |
382 |
|
hostDiscoveryMode.setSelected(config.getProperty("hostDiscoveryMode").equals("1")); |
383 |
|
useHostList.setSelected(config.getProperty("useHostList").equals("1")); |
384 |
+ |
queueLimit.setText(config.getProperty("dataQueueSize")); |
385 |
|
prepareLists(); |
386 |
|
} |
387 |
|
|
388 |
< |
|
388 |
> |
/** |
389 |
> |
* Displays the host lists in the host windows |
390 |
> |
*/ |
391 |
|
private void prepareLists() { |
392 |
|
knownHostsModel = new DefaultListModel(); |
393 |
|
hostListModel = new DefaultListModel(); |
408 |
|
hostList.setModel(hostListModel); |
409 |
|
} |
410 |
|
|
411 |
+ |
/** |
412 |
+ |
* Writes the changes back to the loaded configuration |
413 |
+ |
* Then closes the windows |
414 |
+ |
*/ |
415 |
|
private void setNewSettingsAndClose() { |
416 |
|
|
417 |
|
config.setProperty("clientname", name.getText().trim()); |
420 |
|
config.setProperty("firewall.command", firewallCommand.getText().trim()); |
421 |
|
config.setProperty("firewall.commandwait", firewallWait.getText().trim()); |
422 |
|
config.setProperty("firewall.server", firewallServer.getText().trim()); |
423 |
+ |
config.setProperty("dataQueueSize", queueLimit.getText().trim()); |
424 |
|
if (useFirewall.isSelected()) { |
425 |
|
config.setProperty("useFirewall", "1"); |
426 |
|
} else { |
486 |
|
|
487 |
|
//---ATTRIBUTES--- |
488 |
|
|
489 |
+ |
/** |
490 |
+ |
* A reference to the configuration in use |
491 |
+ |
*/ |
492 |
|
Configuration config = Configuration.getInstance(); |
493 |
< |
|
493 |
> |
|
494 |
> |
/** |
495 |
> |
* Used to add a new host to the known host list |
496 |
> |
*/ |
497 |
|
private JTextField newHost; |
498 |
|
|
499 |
+ |
/** |
500 |
+ |
* Lists the known hosts (less the ones we're monitoring) |
501 |
+ |
*/ |
502 |
|
private JList knownHosts; |
503 |
+ |
|
504 |
+ |
/** |
505 |
+ |
* The list of hosts we're monitoring |
506 |
+ |
*/ |
507 |
|
private JList hostList; |
508 |
+ |
|
509 |
+ |
/** |
510 |
+ |
* If we are making a note of the hosts the server |
511 |
+ |
* sends us. |
512 |
+ |
*/ |
513 |
|
private JCheckBox hostDiscoveryMode; |
514 |
+ |
|
515 |
+ |
/** |
516 |
+ |
* If we are using the host list setting to only view data |
517 |
+ |
* from certain hosts |
518 |
+ |
*/ |
519 |
|
private JCheckBox useHostList; |
520 |
+ |
|
521 |
+ |
/** |
522 |
+ |
* The name to identify this client to the server |
523 |
+ |
*/ |
524 |
|
private JTextField name; |
525 |
+ |
|
526 |
+ |
/** |
527 |
+ |
* The port the i-scream server is running on |
528 |
+ |
*/ |
529 |
|
private JTextField port; |
530 |
+ |
|
531 |
+ |
/** |
532 |
+ |
* The hostname of the i-scream server |
533 |
+ |
*/ |
534 |
|
private JTextField server; |
535 |
+ |
|
536 |
+ |
/** |
537 |
+ |
* If we want to start the control channel on startup |
538 |
+ |
*/ |
539 |
|
private JCheckBox connectControl; |
540 |
+ |
|
541 |
+ |
/** |
542 |
+ |
* If we want to start the data channel on startup |
543 |
+ |
*/ |
544 |
|
private JCheckBox connectData; |
545 |
+ |
|
546 |
+ |
/** |
547 |
+ |
* If we want to use the firewall command to connect |
548 |
+ |
*/ |
549 |
|
private JCheckBox useFirewall; |
550 |
+ |
|
551 |
+ |
/** |
552 |
+ |
* The command to run to open a pipe to the iscream server |
553 |
+ |
*/ |
554 |
|
private JTextField firewallCommand; |
555 |
+ |
|
556 |
+ |
/** |
557 |
+ |
* How long to wait for the firewall command to execute |
558 |
+ |
*/ |
559 |
|
private JTextField firewallWait; |
560 |
+ |
|
561 |
+ |
/** |
562 |
+ |
* The name of the machine to locally connect through to |
563 |
+ |
* reach the i-scream server |
564 |
+ |
*/ |
565 |
|
private JTextField firewallServer; |
566 |
+ |
|
567 |
+ |
/** |
568 |
+ |
* Whether to display server queue debugging information |
569 |
+ |
*/ |
570 |
|
private JCheckBox displayQueue; |
571 |
+ |
|
572 |
+ |
/** |
573 |
+ |
* Whether to display extra data contained in packets |
574 |
+ |
*/ |
575 |
|
private JCheckBox displayExtra; |
576 |
+ |
|
577 |
+ |
/** |
578 |
+ |
* Whether to dump raw packet data to the console |
579 |
+ |
*/ |
580 |
|
private JCheckBox packetDump; |
581 |
< |
|
581 |
> |
|
582 |
> |
/** |
583 |
> |
* The limit on the data queue size |
584 |
> |
*/ |
585 |
> |
private JTextField queueLimit; |
586 |
> |
|
587 |
> |
/** |
588 |
> |
* holds the known hosts |
589 |
> |
*/ |
590 |
|
private DefaultListModel knownHostsModel; |
591 |
+ |
|
592 |
+ |
/** |
593 |
+ |
* holds the monitored hosts |
594 |
+ |
*/ |
595 |
|
private DefaultListModel hostListModel; |
596 |
|
|
597 |
|
//---STATIC ATTRIBUTES--- |