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.11
Committed: Fri Mar 23 03:27:07 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.10: +237 -211 lines
Log Message:
Now sorts the host lists throughout.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.conient;
3
4 //---IMPORTS---
5 import java.awt.*;
6 import java.awt.event.*;
7 import javax.swing.*;
8 import javax.swing.border.*;
9 import java.util.Properties;
10 import java.util.StringTokenizer;
11 import java.util.Collections;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14
15 /**
16 * This provides a modal dialog from which the user
17 * can reconfigure the conient client.
18 *
19 * Look at the comments for the attributes of this class to see
20 * what configuration options this class deals with.
21 *
22 * It then writes back the configuration to the loaded configuration.
23 * The user can then opt to save it.
24 *
25 *
26 * @author $Author: ajm4 $
27 * @version $Id: ConfigurationDialog.java,v 1.10 2001/03/22 01:19:04 ajm4 Exp $
28 */
29 public class ConfigurationDialog extends JDialog {
30
31 //---FINAL ATTRIBUTES---
32
33 /**
34 * The current CVS revision of this class
35 */
36 public static final String REVISION = "$Revision: 1.10 $";
37
38 //---STATIC METHODS---
39
40 //---CONSTRUCTORS---
41
42 /**
43 * Constructs and shows the dialog for the user
44 */
45 public ConfigurationDialog() {
46 super(Conient.getFrame(), "Configuration Options", true);
47
48 // setup the buttoms
49 JPanel buttonPanel = new JPanel();
50 buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
51 JButton ok = new JButton("OK");
52 ok.addActionListener(new ActionListener() {
53 public void actionPerformed(ActionEvent e) {
54 setNewSettingsAndClose();
55 }
56 });
57
58 JButton cancel = new JButton("Cancel");
59 cancel.addActionListener(new ActionListener() {
60 public void actionPerformed(ActionEvent e) {
61 dispose();
62 }
63 });
64 buttonPanel.add(Box.createHorizontalGlue());
65 buttonPanel.add(ok);
66 buttonPanel.add(cancel);
67
68
69 // setup the options panes
70 JTabbedPane center = new JTabbedPane();
71 //center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
72
73 // client options
74 center.addTab("Client Options", createClientOptions());
75
76 // _server options
77 center.addTab("Server Options", create_serverOptions());
78
79 // firewall options
80 center.addTab("Firewall Options", createFirewallOptions());
81
82 // data options
83 center.addTab("Data Options", createDataOptions());
84
85 // display the current settings
86 getCurrentSettings();
87
88 // set the window up
89 getContentPane().add(buttonPanel, "South");
90 getContentPane().add(center, "Center");
91 pack();
92 setLocationRelativeTo(Conient.getFrame());
93 setResizable(false);
94 setVisible(true);
95 }
96
97 //---PUBLIC METHODS---
98
99 //---PRIVATE METHODS---
100
101 /**
102 * creates a JPanel for the client options
103 *
104 * @return the build panel with the options
105 */
106 private JPanel createClientOptions() {
107 GridBagLayout gridbag = new GridBagLayout();
108 GridBagLayout gridbag2 = new GridBagLayout();
109 GridBagConstraints c = new GridBagConstraints();
110 c.fill = GridBagConstraints.HORIZONTAL;
111
112 JPanel clientPanel = new JPanel();
113 clientPanel.setLayout(gridbag);
114 JLabel _nameLabel = new JLabel("Client name:");
115 _nameLabel.setHorizontalAlignment(JLabel.RIGHT);
116 _name = new JTextField(20);
117 JPanel _nameBox = new JPanel();
118 _nameBox.setLayout(new GridLayout(1,2));
119 _nameBox.add(_nameLabel);
120 _nameBox.add(_name);
121
122 c.gridy = 0;
123 gridbag.setConstraints(_nameBox, c);
124 clientPanel.add(_nameBox);
125
126 JPanel lists = new JPanel();
127 lists.setLayout(gridbag2);
128
129 JPanel _knownHostsPanel = new JPanel();
130 _knownHostsPanel.setLayout(new BoxLayout(_knownHostsPanel, BoxLayout.Y_AXIS));
131 _hostDiscoveryMode = new JCheckBox("Discover new hosts from the server");
132 _knownHostsPanel.add(_hostDiscoveryMode);
133 _knownHostsPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Known Hosts "));
134 _knownHosts = new JList();
135 _knownHosts.setVisibleRowCount(10);
136 JScrollPane _knownHostsScrollPane = new JScrollPane(_knownHosts);
137 _knownHostsPanel.add(_knownHostsScrollPane);
138 JLabel _newHostLabel = new JLabel("New host:");
139 _newHostLabel.setHorizontalAlignment(JLabel.RIGHT);
140 _newHost = new JTextField(20);
141
142 JButton _newHostButton = new JButton("Add Host");
143 _newHostButton.addActionListener(new ActionListener() {
144 public void actionPerformed(ActionEvent e) {
145 _knownHostsData.add(_newHost.getText());
146 _newHost.setText("");
147 setListDisplay();
148 }
149 });
150 JButton removeHostButton = new JButton("Remove Host(s)");
151 removeHostButton.addActionListener(new ActionListener() {
152 public void actionPerformed(ActionEvent e) {
153 Object[] selected = _knownHosts.getSelectedValues();
154 for(int x = 0; x < selected.length; x++) {
155 _knownHostsData.remove(_knownHostsData.indexOf(selected[x]));
156 setListDisplay();
157 }
158 }
159 });
160 JPanel _newHostBox = new JPanel();
161 _newHostBox.setLayout(new GridLayout(1,3));
162 _newHostBox.add(_newHostLabel);
163 _newHostBox.add(_newHost);
164
165 JPanel buttonPanel = new JPanel();
166 buttonPanel.add(_newHostButton);
167 buttonPanel.add(removeHostButton);
168 _knownHostsPanel.add(buttonPanel);
169 _knownHostsPanel.add(_newHostBox);
170
171
172 c.gridy = 0;
173 c.gridx = 0;
174 gridbag.setConstraints(_knownHostsPanel, c);
175 lists.add(_knownHostsPanel);
176
177
178 JPanel addRemoveBox = new JPanel();
179 addRemoveBox.setLayout(new BoxLayout(addRemoveBox, BoxLayout.Y_AXIS));
180 addRemoveBox.add(Box.createGlue());
181 JButton add = new JButton(">>>");
182 add.addActionListener(new ActionListener() {
183 public void actionPerformed(ActionEvent e) {
184 Object[] selected = _knownHosts.getSelectedValues();
185 for(int x = 0; x < selected.length; x++) {
186 _knownHostsData.remove(_knownHostsData.indexOf(selected[x]));
187 _hostListData.add(selected[x]);
188 setListDisplay();
189 }
190 }
191 });
192
193 addRemoveBox.add(add);
194 addRemoveBox.add(Box.createGlue());
195 JButton remove = new JButton("<<<");
196 remove.addActionListener(new ActionListener() {
197 public void actionPerformed(ActionEvent e) {
198 Object[] selected = _hostList.getSelectedValues();
199 for(int x = 0; x < selected.length; x++) {
200 _hostListData.remove(_hostListData.indexOf(selected[x]));
201 _knownHostsData.add(selected[x]);
202 setListDisplay();
203 }
204 }
205 });
206 addRemoveBox.add(remove);
207 addRemoveBox.add(Box.createGlue());
208
209 c.gridy = 0;
210 c.gridx = 1;
211 gridbag.setConstraints(addRemoveBox, c);
212 lists.add(addRemoveBox);
213
214 JPanel _hostListPanel = new JPanel();
215 _hostListPanel.setLayout(new BoxLayout(_hostListPanel, BoxLayout.Y_AXIS));
216 _useHostList = new JCheckBox("Only monitor hosts in this list");
217 _hostListPanel.add(_useHostList);
218 _hostListPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Hosts To Monitor "));
219 _hostList = new JList();
220 _hostList.setVisibleRowCount(10);
221 JScrollPane _hostListScrollPane = new JScrollPane(_hostList);
222 _hostListPanel.add(_hostListScrollPane);
223
224 c.gridy = 0;
225 c.gridx = 2;
226 gridbag.setConstraints(_hostListPanel, c);
227 lists.add(_hostListPanel);
228
229 c.gridy = 1;
230 c.gridx = 0;
231 gridbag.setConstraints(lists, c);
232 clientPanel.add(lists);
233 return clientPanel;
234 }
235
236 /**
237 * creates a JPanel for the server options
238 *
239 * @return the build panel with the options
240 */
241 private JPanel create_serverOptions() {
242 GridBagLayout gridbag = new GridBagLayout();
243 GridBagConstraints c = new GridBagConstraints();
244 c.fill = GridBagConstraints.HORIZONTAL;
245 JPanel _serverPanel = new JPanel();
246 _serverPanel.setLayout(gridbag);
247 _connectControl = new JCheckBox("Automatically connect the control channel");
248 c.gridy = 0;
249 gridbag.setConstraints(_connectControl, c);
250 _serverPanel.add(_connectControl);
251 _connectData = new JCheckBox("Automatically connect the data channel");
252 c.gridy = 1;
253 gridbag.setConstraints(_connectData, c);
254 _serverPanel.add(_connectData);
255 JLabel _serverLabel = new JLabel("i-scream server:");
256 _serverLabel.setHorizontalAlignment(JLabel.RIGHT);
257 _server = new JTextField(20);
258 JPanel _serverBox = new JPanel();
259 _serverBox.setLayout(new GridLayout(1,2));
260 _serverBox.add(_serverLabel);
261 _serverBox.add(_server);
262 c.gridy = 2;
263 gridbag.setConstraints(_serverBox, c);
264 _serverPanel.add(_serverBox);
265 JLabel _portLabel = new JLabel("Client interface port:");
266 _portLabel.setHorizontalAlignment(JLabel.RIGHT);
267 _port = new JTextField(4);
268 JPanel _portBox = new JPanel();
269 _portBox.setLayout(new GridLayout(1,2));
270 _portBox.add(_portLabel);
271 _portBox.add(_port);
272 c.gridy = 3;
273 gridbag.setConstraints(_portBox, c);
274 _serverPanel.add(_portBox);
275 return _serverPanel;
276 }
277
278 /**
279 * creates a JPanel for the firewall options
280 *
281 * @return the build panel with the options
282 */
283 private JPanel createFirewallOptions() {
284 GridBagLayout gridbag = new GridBagLayout();
285 GridBagConstraints c = new GridBagConstraints();
286 c.fill = GridBagConstraints.HORIZONTAL;
287 JPanel firewallPanel = new JPanel();
288 firewallPanel.setLayout(gridbag);
289
290
291 _useFirewall = new JCheckBox("Use firewall command to connect through to server");
292 c.gridy = 0;
293 gridbag.setConstraints(_useFirewall, c);
294 firewallPanel.add(_useFirewall);
295
296 JLabel commandLabel = new JLabel("Firewall command:");
297 commandLabel.setHorizontalAlignment(JLabel.RIGHT);
298 _firewallCommand = new JTextField(20);
299 JPanel commandBox = new JPanel();
300 commandBox.setLayout(new GridLayout(1,2));
301 commandBox.add(commandLabel);
302 commandBox.add(_firewallCommand);
303
304 c.gridy = 1;
305 gridbag.setConstraints(commandBox, c);
306 firewallPanel.add(commandBox);
307
308 JLabel waitLabel = new JLabel("Firewall wait time:");
309 waitLabel.setHorizontalAlignment(JLabel.RIGHT);
310 _firewallWait = new JTextField(2);
311 JPanel waitBox = new JPanel();
312 waitBox.setLayout(new GridLayout(1,2));
313 waitBox.add(waitLabel);
314 waitBox.add(_firewallWait);
315
316 c.gridy = 2;
317 gridbag.setConstraints(waitBox, c);
318 firewallPanel.add(waitBox);
319
320 JLabel fServerLabel = new JLabel("Firewall server:");
321 fServerLabel.setHorizontalAlignment(JLabel.RIGHT);
322 _firewallServer = new JTextField(20);
323 JPanel fServerBox = new JPanel();
324 fServerBox.setLayout(new GridLayout(1,2));
325 fServerBox.add(fServerLabel);
326 fServerBox.add(_firewallServer);
327
328 c.gridy = 3;
329 gridbag.setConstraints(fServerBox, c);
330 firewallPanel.add(fServerBox);
331
332 return firewallPanel;
333 }
334
335 /**
336 * creates a JPanel for the data options
337 *
338 * @return the build panel with the options
339 */
340 private JPanel createDataOptions() {
341 GridBagLayout gridbag = new GridBagLayout();
342 GridBagConstraints c = new GridBagConstraints();
343 c.fill = GridBagConstraints.HORIZONTAL;
344 JPanel dataPanel = new JPanel();
345 dataPanel.setLayout(gridbag);
346 _displayQueue = new JCheckBox("Display server queue information");
347 c.gridy = 0;
348 gridbag.setConstraints(_displayQueue, c);
349 dataPanel.add(_displayQueue);
350 _displayExtra = new JCheckBox("Display extra data found in packets");
351 c.gridy = 1;
352 gridbag.setConstraints(_displayExtra, c);
353 dataPanel.add(_displayExtra);
354 _packetDump = new JCheckBox("Dump raw packet data to the console");
355 c.gridy = 2;
356 gridbag.setConstraints(_packetDump, c);
357 dataPanel.add(_packetDump);
358
359 JLabel _queueLimitLabel = new JLabel("Maximum data queue size:");
360 _queueLimitLabel.setHorizontalAlignment(JLabel.RIGHT);
361 _queueLimit = new JTextField(4);
362 JPanel queueBox = new JPanel();
363 queueBox.setLayout(new GridLayout(1,2));
364 queueBox.add(_queueLimitLabel);
365 queueBox.add(_queueLimit);
366 c.gridy = 3;
367 gridbag.setConstraints(queueBox, c);
368 dataPanel.add(queueBox);
369 return dataPanel;
370 }
371
372 /**
373 * Reads in the current settings from the loaded configuration
374 */
375 private void getCurrentSettings() {
376 _name.setText(_config.getProperty("clientname"));
377 _server.setText(_config.getProperty("control.server"));
378 _port.setText(_config.getProperty("control.port"));
379 _connectControl.setSelected(_config.getProperty("control.onstartconnect").equals("1"));
380 _connectData.setSelected(_config.getProperty("data.onstartconnect").equals("1"));
381 _firewallCommand.setText(_config.getProperty("firewall.command"));
382 _firewallCommand.moveCaretPosition(0);
383 _firewallWait.setText(_config.getProperty("firewall.commandwait"));
384 _firewallServer.setText(_config.getProperty("firewall.server"));
385 _displayQueue.setSelected(_config.getProperty("displayQueueInformation").equals("1"));
386 _displayExtra.setSelected(_config.getProperty("displayExtraData").equals("1"));
387 _packetDump.setSelected(_config.getProperty("packetDump").equals("1"));
388 _useFirewall.setSelected(_config.getProperty("useFirewall").equals("1"));
389 _hostDiscoveryMode.setSelected(_config.getProperty("hostDiscoveryMode").equals("1"));
390 _useHostList.setSelected(_config.getProperty("useHostList").equals("1"));
391 _queueLimit.setText(_config.getProperty("dataQueueSize"));
392 prepareLists();
393 }
394
395 /**
396 * Displays the host lists in the host windows
397 * in alphabetical order
398 */
399 private void prepareLists() {
400 _knownHostsData = new ArrayList();
401 _hostListData = new ArrayList();
402 String _configKnownHostsList = _config.getProperty("knownHostsList");
403 String _configHostList = _config.getProperty("hostList");
404 StringTokenizer st;
405 st = new StringTokenizer(_configKnownHostsList, ";");
406 while(st.hasMoreTokens()) {
407 // check its not in the other list...as we only want one entry in the two
408 String knownHost = st.nextToken();
409 if(_configHostList.indexOf(knownHost) == -1) _knownHostsData.add(knownHost);
410 }
411 st = new StringTokenizer(_configHostList, ";");
412 while(st.hasMoreTokens()) {
413 _hostListData.add(st.nextToken());
414 }
415 setListDisplay();
416 }
417
418 /**
419 * Because of the limitation of the existing
420 * data model for lists, ArrayLists are used.
421 * Whenever the data in these lists is changed,
422 * this method is called to re-sort the lists
423 * and reset the display.
424 */
425 private void setListDisplay() {
426 // ensure the order
427 Collections.sort(_hostListData);
428 Collections.sort(_knownHostsData);
429
430 _knownHosts.setListData(_knownHostsData.toArray());
431 _hostList.setListData(_hostListData.toArray());
432 }
433
434 /**
435 * Writes the changes back to the loaded configuration
436 * Then closes the windows
437 */
438 private void setNewSettingsAndClose() {
439
440 _config.setProperty("clientname", _name.getText().trim());
441 _config.setProperty("control.server", _server.getText().trim());
442 _config.setProperty("control.port", _port.getText().trim());
443 _config.setProperty("firewall.command", _firewallCommand.getText().trim());
444 _config.setProperty("firewall.commandwait", _firewallWait.getText().trim());
445 _config.setProperty("firewall.server", _firewallServer.getText().trim());
446 _config.setProperty("dataQueueSize", _queueLimit.getText().trim());
447 if (_useFirewall.isSelected()) {
448 _config.setProperty("useFirewall", "1");
449 } else {
450 _config.setProperty("useFirewall", "0");
451 }
452 if (_connectControl.isSelected()) {
453 _config.setProperty("control.onstartconnect", "1");
454 } else {
455 _config.setProperty("control.onstartconnect", "0");
456 }
457 if (_connectData.isSelected()) {
458 _config.setProperty("data.onstartconnect", "1");
459 } else {
460 _config.setProperty("data.onstartconnect", "0");
461 }
462 if (_packetDump.isSelected()) {
463 _config.setProperty("packetDump", "1");
464 } else {
465 _config.setProperty("packetDump", "0");
466 }
467 if (_displayExtra.isSelected()) {
468 _config.setProperty("displayExtraData", "1");
469 } else {
470 _config.setProperty("displayExtraData", "0");
471 }
472 if (_displayQueue.isSelected()) {
473 _config.setProperty("displayQueueInformation", "1");
474 } else {
475 _config.setProperty("displayQueueInformation", "0");
476 }
477 if (_useHostList.isSelected()) {
478 _config.setProperty("useHostList", "1");
479 } else {
480 _config.setProperty("useHostList", "0");
481 }
482 if (_hostDiscoveryMode.isSelected()) {
483 _config.setProperty("hostDiscoveryMode", "1");
484 } else {
485 _config.setProperty("hostDiscoveryMode", "0");
486 }
487
488 // sort out the hosts lists
489
490 // known hosts are both the known hosts list AND the host list
491 // first the hostList...
492 Iterator i;
493 i = _hostListData.iterator();
494 String _hostListSave = "";
495 while(i.hasNext()) {
496 _hostListSave += (String) i.next() + ";";
497 }
498
499 i = _knownHostsData.iterator();
500 String _knownHostsListSave = "";
501 while(i.hasNext()) {
502 _knownHostsListSave += (String) i.next() + ";";
503 }
504
505 _knownHostsListSave += _hostListSave;
506 _config.setProperty("hostList", _hostListSave);
507 _config.setProperty("knownHostsList", _knownHostsListSave);
508 dispose();
509 }
510
511 //---ACCESSOR/MUTATOR METHODS---
512
513 //---ATTRIBUTES---
514
515 /**
516 * A reference to the configuration in use
517 */
518 Configuration _config = Configuration.getInstance();
519
520 /**
521 * Used to add a new host to the known host list
522 */
523 private JTextField _newHost;
524
525 /**
526 * Lists the known hosts (less the ones we're monitoring)
527 */
528 private JList _knownHosts;
529
530 /**
531 * The list of hosts we're monitoring
532 */
533 private JList _hostList;
534
535 /**
536 * If we are making a note of the hosts the _server
537 * sends us.
538 */
539 private JCheckBox _hostDiscoveryMode;
540
541 /**
542 * If we are using the host list setting to only view data
543 * from certain hosts
544 */
545 private JCheckBox _useHostList;
546
547 /**
548 * The _name to identify this client to the _server
549 */
550 private JTextField _name;
551
552 /**
553 * The _port the i-scream _server is running on
554 */
555 private JTextField _port;
556
557 /**
558 * The host_name of the i-scream server
559 */
560 private JTextField _server;
561
562 /**
563 * If we want to start the control channel on startup
564 */
565 private JCheckBox _connectControl;
566
567 /**
568 * If we want to start the data channel on startup
569 */
570 private JCheckBox _connectData;
571
572 /**
573 * If we want to use the firewall command to connect
574 */
575 private JCheckBox _useFirewall;
576
577 /**
578 * The command to run to open a pipe to the iscream server
579 */
580 private JTextField _firewallCommand;
581
582 /**
583 * How long to wait for the firewall command to execute
584 */
585 private JTextField _firewallWait;
586
587 /**
588 * The name of the machine to locally connect through to
589 * reach the i-scream server
590 */
591 private JTextField _firewallServer;
592
593 /**
594 * Whether to display server queue debugging information
595 */
596 private JCheckBox _displayQueue;
597
598 /**
599 * Whether to display extra data contained in packets
600 */
601 private JCheckBox _displayExtra;
602
603 /**
604 * Whether to dump raw packet data to the console
605 */
606 private JCheckBox _packetDump;
607
608 /**
609 * The limit on the data queue size
610 */
611 private JTextField _queueLimit;
612
613 /**
614 * holds the known hosts
615 */
616 private ArrayList _knownHostsData;
617
618 /**
619 * holds the monitored hosts
620 */
621 private ArrayList _hostListData;
622
623 //---STATIC ATTRIBUTES---
624
625 }