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.17
Committed: Sun Aug 1 10:40:05 2004 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.16: +3 -3 lines
Error occurred while calculating annotation data.
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

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