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.9
Committed: Mon Mar 19 03:31:40 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.8: +129 -19 lines
Log Message:
The final changes I intend to make...after this it will only be bug fixes.

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 ajm 1.7 package uk.org.iscream.conient;
3 ajm 1.1
4     //---IMPORTS---
5 ajm 1.8 import java.awt.*;
6 ajm 1.3 import java.awt.event.*;
7     import javax.swing.*;
8     import javax.swing.border.*;
9 ajm 1.1 import java.util.Properties;
10 ajm 1.5 import java.util.StringTokenizer;
11 ajm 1.1
12     /**
13     * This provides a modal dialog from which the user
14     * can reconfigure the conient client.
15     *
16 ajm 1.9 * Look at the comments for the attributes of this class to see
17     * what configuration options this class deals with.
18     *
19     * It then writes back the configuration to the loaded configuration.
20     * The user can then opt to save it.
21 ajm 1.1 *
22     *
23     * @author $Author: ajm4 $
24 ajm 1.9 * @version $Id: ConfigurationDialog.java,v 1.8 2001/03/16 19:47:53 ajm4 Exp $
25 ajm 1.1 */
26     public class ConfigurationDialog extends JDialog {
27    
28     //---FINAL ATTRIBUTES---
29    
30     /**
31     * The current CVS revision of this class
32     */
33 ajm 1.9 public static final String REVISION = "$Revision: 1.8 $";
34 ajm 1.1
35     //---STATIC METHODS---
36    
37     //---CONSTRUCTORS---
38    
39     /**
40     * Constructs and shows the dialog for the user
41     */
42 ajm 1.2 public ConfigurationDialog() {
43 ajm 1.3 super(Conient.getFrame(), "Configuration Options", true);
44 ajm 1.2
45 ajm 1.3 // setup the buttoms
46     JPanel buttonPanel = new JPanel();
47     buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
48     JButton ok = new JButton("OK");
49 ajm 1.4 ok.addActionListener(new ActionListener() {
50     public void actionPerformed(ActionEvent e) {
51     setNewSettingsAndClose();
52     }
53     });
54    
55     JButton cancel = new JButton("Cancel");
56 ajm 1.3 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 ajm 1.5 JTabbedPane center = new JTabbedPane();
68     //center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
69 ajm 1.3
70     // client options
71 ajm 1.5 center.addTab("Client Options", createClientOptions());
72 ajm 1.3
73 ajm 1.4 // server options
74 ajm 1.5 center.addTab("Server Options", createServerOptions());
75 ajm 1.4
76     // firewall options
77 ajm 1.5 center.addTab("Firewall Options", createFirewallOptions());
78 ajm 1.4
79     // data options
80 ajm 1.5 center.addTab("Data Options", createDataOptions());
81 ajm 1.4
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 ajm 1.5
98 ajm 1.9 /**
99     * creates a JPanel for the client options
100     *
101     * @return the build panel with the options
102     */
103 ajm 1.4 private JPanel createClientOptions() {
104 ajm 1.8 GridBagLayout gridbag = new GridBagLayout();
105     GridBagLayout gridbag2 = new GridBagLayout();
106     GridBagConstraints c = new GridBagConstraints();
107     c.fill = GridBagConstraints.HORIZONTAL;
108    
109 ajm 1.4 JPanel clientPanel = new JPanel();
110 ajm 1.8 clientPanel.setLayout(gridbag);
111 ajm 1.3 JLabel nameLabel = new JLabel("Client name:");
112 ajm 1.4 nameLabel.setHorizontalAlignment(JLabel.RIGHT);
113     name = new JTextField(20);
114 ajm 1.3 JPanel nameBox = new JPanel();
115 ajm 1.4 nameBox.setLayout(new GridLayout(1,2));
116     nameBox.add(nameLabel);
117     nameBox.add(name);
118 ajm 1.8
119     c.gridy = 0;
120     gridbag.setConstraints(nameBox, c);
121 ajm 1.4 clientPanel.add(nameBox);
122 ajm 1.5
123     JPanel lists = new JPanel();
124 ajm 1.8 lists.setLayout(gridbag2);
125 ajm 1.5
126     JPanel knownHostsPanel = new JPanel();
127     knownHostsPanel.setLayout(new BoxLayout(knownHostsPanel, BoxLayout.Y_AXIS));
128     hostDiscoveryMode = new JCheckBox("Discover new hosts from the server");
129     knownHostsPanel.add(hostDiscoveryMode);
130     knownHostsPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Known Hosts "));
131     knownHosts = new JList();
132     knownHosts.setVisibleRowCount(10);
133     JScrollPane knownHostsScrollPane = new JScrollPane(knownHosts);
134     knownHostsPanel.add(knownHostsScrollPane);
135     JLabel newHostLabel = new JLabel("New host:");
136     newHostLabel.setHorizontalAlignment(JLabel.RIGHT);
137     newHost = new JTextField(20);
138 ajm 1.8
139     JButton newHostButton = new JButton("Add Host");
140 ajm 1.6 newHostButton.addActionListener(new ActionListener() {
141     public void actionPerformed(ActionEvent e) {
142     knownHostsModel.addElement(newHost.getText());
143     newHost.setText("");
144     }
145     });
146 ajm 1.8 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 ajm 1.5 JPanel newHostBox = new JPanel();
156     newHostBox.setLayout(new GridLayout(1,3));
157     newHostBox.add(newHostLabel);
158     newHostBox.add(newHost);
159 ajm 1.8
160     JPanel buttonPanel = new JPanel();
161     buttonPanel.add(newHostButton);
162     buttonPanel.add(removeHostButton);
163     knownHostsPanel.add(buttonPanel);
164 ajm 1.5 knownHostsPanel.add(newHostBox);
165 ajm 1.8
166    
167     c.gridy = 0;
168     c.gridx = 0;
169     gridbag.setConstraints(knownHostsPanel, c);
170 ajm 1.5 lists.add(knownHostsPanel);
171    
172    
173     JPanel addRemoveBox = new JPanel();
174     addRemoveBox.setLayout(new BoxLayout(addRemoveBox, BoxLayout.Y_AXIS));
175     addRemoveBox.add(Box.createGlue());
176     JButton add = new JButton(">>>");
177 ajm 1.6 add.addActionListener(new ActionListener() {
178     public void actionPerformed(ActionEvent e) {
179     Object[] selected = knownHosts.getSelectedValues();
180     for(int x = 0; x < selected.length; x++) {
181     knownHostsModel.removeElement(selected[x]);
182     hostListModel.addElement(selected[x]);
183     }
184     }
185     });
186    
187 ajm 1.5 addRemoveBox.add(add);
188     addRemoveBox.add(Box.createGlue());
189     JButton remove = new JButton("<<<");
190 ajm 1.6 remove.addActionListener(new ActionListener() {
191     public void actionPerformed(ActionEvent e) {
192     Object[] selected = hostList.getSelectedValues();
193     for(int x = 0; x < selected.length; x++) {
194     hostListModel.removeElement(selected[x]);
195     knownHostsModel.addElement(selected[x]);
196     }
197     }
198     });
199 ajm 1.5 addRemoveBox.add(remove);
200     addRemoveBox.add(Box.createGlue());
201 ajm 1.8
202     c.gridy = 0;
203     c.gridx = 1;
204     gridbag.setConstraints(addRemoveBox, c);
205 ajm 1.5 lists.add(addRemoveBox);
206    
207     JPanel hostListPanel = new JPanel();
208     hostListPanel.setLayout(new BoxLayout(hostListPanel, BoxLayout.Y_AXIS));
209     useHostList = new JCheckBox("Only monitor hosts in this list");
210     hostListPanel.add(useHostList);
211     hostListPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Hosts To Monitor "));
212     hostList = new JList();
213     hostList.setVisibleRowCount(10);
214     JScrollPane hostListScrollPane = new JScrollPane(hostList);
215     hostListPanel.add(hostListScrollPane);
216 ajm 1.8
217     c.gridy = 0;
218     c.gridx = 2;
219     gridbag.setConstraints(hostListPanel, c);
220 ajm 1.5 lists.add(hostListPanel);
221    
222 ajm 1.8 c.gridy = 1;
223     c.gridx = 0;
224     gridbag.setConstraints(lists, c);
225 ajm 1.5 clientPanel.add(lists);
226 ajm 1.4 return clientPanel;
227     }
228 ajm 1.9
229     /**
230     * creates a JPanel for the server options
231     *
232     * @return the build panel with the options
233     */
234 ajm 1.4 private JPanel createServerOptions() {
235 ajm 1.8 GridBagLayout gridbag = new GridBagLayout();
236     GridBagConstraints c = new GridBagConstraints();
237     c.fill = GridBagConstraints.HORIZONTAL;
238 ajm 1.3 JPanel serverPanel = new JPanel();
239 ajm 1.8 serverPanel.setLayout(gridbag);
240 ajm 1.9 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 ajm 1.3 JLabel serverLabel = new JLabel("i-scream Server:");
249 ajm 1.4 serverLabel.setHorizontalAlignment(JLabel.RIGHT);
250     server = new JTextField(20);
251     JPanel serverBox = new JPanel();
252     serverBox.setLayout(new GridLayout(1,2));
253 ajm 1.3 serverBox.add(serverLabel);
254     serverBox.add(server);
255 ajm 1.9 c.gridy = 2;
256 ajm 1.8 gridbag.setConstraints(serverBox, c);
257 ajm 1.3 serverPanel.add(serverBox);
258     JLabel portLabel = new JLabel("Client interface port:");
259 ajm 1.4 portLabel.setHorizontalAlignment(JLabel.RIGHT);
260     port = new JTextField(4);
261     JPanel portBox = new JPanel();
262     portBox.setLayout(new GridLayout(1,2));
263 ajm 1.3 portBox.add(portLabel);
264     portBox.add(port);
265 ajm 1.9 c.gridy = 3;
266 ajm 1.8 gridbag.setConstraints(portBox, c);
267 ajm 1.3 serverPanel.add(portBox);
268 ajm 1.4 return serverPanel;
269     }
270 ajm 1.3
271 ajm 1.9 /**
272     * creates a JPanel for the firewall options
273     *
274     * @return the build panel with the options
275     */
276 ajm 1.4 private JPanel createFirewallOptions() {
277 ajm 1.8 GridBagLayout gridbag = new GridBagLayout();
278     GridBagConstraints c = new GridBagConstraints();
279     c.fill = GridBagConstraints.HORIZONTAL;
280 ajm 1.3 JPanel firewallPanel = new JPanel();
281 ajm 1.8 firewallPanel.setLayout(gridbag);
282    
283 ajm 1.4
284     useFirewall = new JCheckBox("Use firewall command to connect through to server");
285 ajm 1.8 c.gridy = 0;
286     gridbag.setConstraints(useFirewall, c);
287 ajm 1.4 firewallPanel.add(useFirewall);
288 ajm 1.8
289 ajm 1.3 JLabel commandLabel = new JLabel("Firewall command:");
290 ajm 1.4 commandLabel.setHorizontalAlignment(JLabel.RIGHT);
291     firewallCommand = new JTextField(20);
292 ajm 1.8 firewallCommand.setSize(new Dimension(1,10));
293 ajm 1.4 JPanel commandBox = new JPanel();
294     commandBox.setLayout(new GridLayout(1,2));
295 ajm 1.3 commandBox.add(commandLabel);
296 ajm 1.4 commandBox.add(firewallCommand);
297 ajm 1.5
298 ajm 1.8 c.gridy = 1;
299     gridbag.setConstraints(commandBox, c);
300 ajm 1.3 firewallPanel.add(commandBox);
301    
302     JLabel waitLabel = new JLabel("Firewall wait time:");
303 ajm 1.4 waitLabel.setHorizontalAlignment(JLabel.RIGHT);
304     firewallWait = new JTextField(2);
305     JPanel waitBox = new JPanel();
306     waitBox.setLayout(new GridLayout(1,2));
307 ajm 1.3 waitBox.add(waitLabel);
308 ajm 1.4 waitBox.add(firewallWait);
309 ajm 1.8
310     c.gridy = 2;
311     gridbag.setConstraints(waitBox, c);
312 ajm 1.3 firewallPanel.add(waitBox);
313    
314     JLabel fserverLabel = new JLabel("Firewall server:");
315 ajm 1.4 fserverLabel.setHorizontalAlignment(JLabel.RIGHT);
316     firewallServer = new JTextField(20);
317     JPanel fserverBox = new JPanel();
318     fserverBox.setLayout(new GridLayout(1,2));
319 ajm 1.3 fserverBox.add(fserverLabel);
320 ajm 1.4 fserverBox.add(firewallServer);
321 ajm 1.5
322 ajm 1.8 c.gridy = 3;
323     gridbag.setConstraints(fserverBox, c);
324 ajm 1.3 firewallPanel.add(fserverBox);
325 ajm 1.8
326 ajm 1.4 return firewallPanel;
327     }
328    
329 ajm 1.9 /**
330     * creates a JPanel for the data options
331     *
332     * @return the build panel with the options
333     */
334 ajm 1.4 private JPanel createDataOptions() {
335 ajm 1.8 GridBagLayout gridbag = new GridBagLayout();
336     GridBagConstraints c = new GridBagConstraints();
337     c.fill = GridBagConstraints.HORIZONTAL;
338 ajm 1.4 JPanel dataPanel = new JPanel();
339 ajm 1.8 dataPanel.setLayout(gridbag);
340 ajm 1.4 displayQueue = new JCheckBox("Display server queue information");
341 ajm 1.8 c.gridy = 0;
342     gridbag.setConstraints(displayQueue, c);
343 ajm 1.5 dataPanel.add(displayQueue);
344 ajm 1.4 displayExtra = new JCheckBox("Display extra data found in packets");
345 ajm 1.8 c.gridy = 1;
346     gridbag.setConstraints(displayExtra, c);
347 ajm 1.5 dataPanel.add(displayExtra);
348 ajm 1.4 packetDump = new JCheckBox("Dump raw packet data to the console");
349 ajm 1.8 c.gridy = 2;
350     gridbag.setConstraints(packetDump, c);
351 ajm 1.5 dataPanel.add(packetDump);
352 ajm 1.4 return dataPanel;
353     }
354    
355 ajm 1.9 /**
356     * Reads in the current settings from the loaded configuration
357     */
358 ajm 1.4 private void getCurrentSettings() {
359     name.setText(config.getProperty("clientname"));
360     server.setText(config.getProperty("control.server"));
361     port.setText(config.getProperty("control.port"));
362     connectControl.setSelected(config.getProperty("control.onstartconnect").equals("1"));
363     connectData.setSelected(config.getProperty("data.onstartconnect").equals("1"));
364     firewallCommand.setText(config.getProperty("firewall.command"));
365     firewallCommand.moveCaretPosition(0);
366     firewallWait.setText(config.getProperty("firewall.commandwait"));
367     firewallServer.setText(config.getProperty("firewall.server"));
368     displayQueue.setSelected(config.getProperty("displayQueueInformation").equals("1"));
369     displayExtra.setSelected(config.getProperty("displayExtraData").equals("1"));
370     packetDump.setSelected(config.getProperty("packetDump").equals("1"));
371     useFirewall.setSelected(config.getProperty("useFirewall").equals("1"));
372 ajm 1.5 hostDiscoveryMode.setSelected(config.getProperty("hostDiscoveryMode").equals("1"));
373     useHostList.setSelected(config.getProperty("useHostList").equals("1"));
374     prepareLists();
375     }
376    
377 ajm 1.9 /**
378     * Displays the host lists in the host windows
379     */
380 ajm 1.5 private void prepareLists() {
381     knownHostsModel = new DefaultListModel();
382     hostListModel = new DefaultListModel();
383     String configKnownHostsList = config.getProperty("knownHostsList");
384     String configHostList = config.getProperty("hostList");
385     StringTokenizer st;
386     st = new StringTokenizer(configKnownHostsList, ";");
387     while(st.hasMoreTokens()) {
388 ajm 1.6 // check its not in the other list...as we only want one entry in the two
389     String knownHost = st.nextToken();
390     if(configHostList.indexOf(knownHost) == -1) knownHostsModel.addElement(knownHost);
391 ajm 1.5 }
392     st = new StringTokenizer(configHostList, ";");
393     while(st.hasMoreTokens()) {
394     hostListModel.addElement(st.nextToken());
395     }
396     knownHosts.setModel(knownHostsModel);
397     hostList.setModel(hostListModel);
398 ajm 1.4 }
399    
400 ajm 1.9 /**
401     * Writes the changes back to the loaded configuration
402     * Then closes the windows
403     */
404 ajm 1.4 private void setNewSettingsAndClose() {
405 ajm 1.5
406 ajm 1.4 config.setProperty("clientname", name.getText().trim());
407     config.setProperty("control.server", server.getText().trim());
408     config.setProperty("control.port", port.getText().trim());
409     config.setProperty("firewall.command", firewallCommand.getText().trim());
410     config.setProperty("firewall.commandwait", firewallWait.getText().trim());
411     config.setProperty("firewall.server", firewallServer.getText().trim());
412     if (useFirewall.isSelected()) {
413     config.setProperty("useFirewall", "1");
414     } else {
415     config.setProperty("useFirewall", "0");
416     }
417     if (connectControl.isSelected()) {
418     config.setProperty("control.onstartconnect", "1");
419     } else {
420     config.setProperty("control.onstartconnect", "0");
421     }
422     if (connectData.isSelected()) {
423     config.setProperty("data.onstartconnect", "1");
424     } else {
425     config.setProperty("data.onstartconnect", "0");
426     }
427     if (packetDump.isSelected()) {
428     config.setProperty("packetDump", "1");
429     } else {
430     config.setProperty("packetDump", "0");
431     }
432     if (displayExtra.isSelected()) {
433     config.setProperty("displayExtraData", "1");
434     } else {
435     config.setProperty("displayExtraData", "0");
436     }
437     if (displayQueue.isSelected()) {
438     config.setProperty("displayQueueInformation", "1");
439     } else {
440     config.setProperty("displayQueueInformation", "0");
441     }
442 ajm 1.5 if (useHostList.isSelected()) {
443     config.setProperty("useHostList", "1");
444     } else {
445     config.setProperty("useHostList", "0");
446     }
447     if (hostDiscoveryMode.isSelected()) {
448     config.setProperty("hostDiscoveryMode", "1");
449     } else {
450     config.setProperty("hostDiscoveryMode", "0");
451     }
452 ajm 1.6
453     // sort out the hosts lists
454    
455     // known hosts are both the known hosts list AND the host list
456     // first the hostlist...
457     Object[] hostListSaveArray = hostListModel.toArray();
458     String hostListSave = "";
459     for(int x = 0; x < hostListSaveArray.length; x++) {
460     hostListSave += (String) hostListSaveArray[x] + ";";
461     }
462     Object[] knownHostsListSaveArray = knownHostsModel.toArray();
463     String knownHostsListSave = "";
464     for(int x = 0; x < knownHostsListSaveArray.length; x++) {
465     knownHostsListSave += (String) knownHostsListSaveArray[x] + ";";
466     }
467     knownHostsListSave += hostListSave;
468     config.setProperty("hostList", hostListSave);
469     config.setProperty("knownHostsList", knownHostsListSave);
470 ajm 1.4 dispose();
471 ajm 1.1 }
472    
473 ajm 1.4 //---ACCESSOR/MUTATOR METHODS---
474 ajm 1.1
475 ajm 1.4 //---ATTRIBUTES---
476 ajm 1.1
477 ajm 1.9 /**
478     * A reference to the configuration in use
479     */
480 ajm 1.5 Configuration config = Configuration.getInstance();
481 ajm 1.9
482     /**
483     * Used to add a new host to the known host list
484     */
485 ajm 1.5 private JTextField newHost;
486    
487 ajm 1.9 /**
488     * Lists the known hosts (less the ones we're monitoring)
489     */
490 ajm 1.5 private JList knownHosts;
491 ajm 1.9
492     /**
493     * The list of hosts we're monitoring
494     */
495 ajm 1.5 private JList hostList;
496 ajm 1.9
497     /**
498     * If we are making a note of the hosts the server
499     * sends us.
500     */
501 ajm 1.5 private JCheckBox hostDiscoveryMode;
502 ajm 1.9
503     /**
504     * If we are using the host list setting to only view data
505     * from certain hosts
506     */
507 ajm 1.5 private JCheckBox useHostList;
508 ajm 1.9
509     /**
510     * The name to identify this client to the server
511     */
512 ajm 1.4 private JTextField name;
513 ajm 1.9
514     /**
515     * The port the i-scream server is running on
516     */
517 ajm 1.4 private JTextField port;
518 ajm 1.9
519     /**
520     * The hostname of the i-scream server
521     */
522 ajm 1.4 private JTextField server;
523 ajm 1.9
524     /**
525     * If we want to start the control channel on startup
526     */
527 ajm 1.4 private JCheckBox connectControl;
528 ajm 1.9
529     /**
530     * If we want to start the data channel on startup
531     */
532 ajm 1.4 private JCheckBox connectData;
533 ajm 1.9
534     /**
535     * If we want to use the firewall command to connect
536     */
537 ajm 1.4 private JCheckBox useFirewall;
538 ajm 1.9
539     /**
540     * The command to run to open a pipe to the iscream server
541     */
542 ajm 1.4 private JTextField firewallCommand;
543 ajm 1.9
544     /**
545     * How long to wait for the firewall command to execute
546     */
547 ajm 1.4 private JTextField firewallWait;
548 ajm 1.9
549     /**
550     * The name of the machine to locally connect through to
551     * reach the i-scream server
552     */
553 ajm 1.4 private JTextField firewallServer;
554 ajm 1.9
555     /**
556     * Whether to display server queue debugging information
557     */
558 ajm 1.4 private JCheckBox displayQueue;
559 ajm 1.9
560     /**
561     * Whether to display extra data contained in packets
562     */
563 ajm 1.4 private JCheckBox displayExtra;
564 ajm 1.9
565     /**
566     * Whether to dump raw packet data to the console
567     */
568 ajm 1.4 private JCheckBox packetDump;
569 ajm 1.9
570     /**
571     * holds the known hosts
572     */
573 ajm 1.5 private DefaultListModel knownHostsModel;
574 ajm 1.9
575     /**
576     * holds the monitored hosts
577     */
578 ajm 1.5 private DefaultListModel hostListModel;
579 ajm 1.1
580     //---STATIC ATTRIBUTES---
581    
582     }