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
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/ConfigurationDialog.java (file contents):
Revision 1.2 by ajm, Wed Feb 21 23:37:38 2001 UTC vs.
Revision 1.8 by ajm, Fri Mar 16 19:47:53 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.ac.ukc.iscream.conient;
2 > package uk.org.iscream.conient;
3  
4   //---IMPORTS---
5 < import javax.swing.JDialog;
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  
12   /**
13   * This provides a modal dialog from which the user
# Line 34 | Line 38 | public class ConfigurationDialog extends JDialog {
38       * Constructs and shows the dialog for the user
39       */
40      public ConfigurationDialog() {
41 +        super(Conient.getFrame(), "Configuration Options", true);
42          
43 +        // setup the buttoms
44 +        JPanel buttonPanel = new JPanel();
45 +        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
46 +        JButton ok = new JButton("OK");
47 +        ok.addActionListener(new ActionListener() {
48 +            public void actionPerformed(ActionEvent e) {
49 +                setNewSettingsAndClose();
50 +            }
51 +        });
52 +        
53 +        JButton cancel = new JButton("Cancel");
54 +        cancel.addActionListener(new ActionListener() {
55 +            public void actionPerformed(ActionEvent e) {
56 +                dispose();
57 +            }
58 +        });
59 +        buttonPanel.add(Box.createHorizontalGlue());
60 +        buttonPanel.add(ok);
61 +        buttonPanel.add(cancel);
62 +        
63 +
64 +        // setup the options panes
65 +        JTabbedPane center = new JTabbedPane();
66 +        //center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
67 +        
68 +        // client options
69 +        center.addTab("Client Options", createClientOptions());
70 +        
71 +        // server options
72 +        center.addTab("Server Options", createServerOptions());
73 +
74 +        // firewall options
75 +        center.addTab("Firewall Options", createFirewallOptions());
76 +        
77 +        // data options
78 +        center.addTab("Data Options", createDataOptions());
79 +        
80 +        // display the current settings
81 +        getCurrentSettings();
82 +        
83 +        // set the window up
84 +        getContentPane().add(buttonPanel, "South");
85 +        getContentPane().add(center, "Center");
86 +        pack();
87 +        setLocationRelativeTo(Conient.getFrame());
88 +        setResizable(false);
89 +        setVisible(true);
90      }
91  
92   //---PUBLIC METHODS---
93  
94   //---PRIVATE METHODS---
95 +  
96 +    private JPanel createClientOptions() {
97 +        GridBagLayout gridbag = new GridBagLayout();
98 +        GridBagLayout gridbag2 = new GridBagLayout();
99 +        GridBagConstraints c = new GridBagConstraints();
100 +        c.fill = GridBagConstraints.HORIZONTAL;
101 +        
102 +        JPanel clientPanel = new JPanel();
103 +        clientPanel.setLayout(gridbag);
104 +        JLabel nameLabel = new JLabel("Client name:");
105 +        nameLabel.setHorizontalAlignment(JLabel.RIGHT);
106 +        name = new JTextField(20);
107 +        JPanel nameBox = new JPanel();
108 +        nameBox.setLayout(new GridLayout(1,2));
109 +        nameBox.add(nameLabel);
110 +        nameBox.add(name);
111 +        
112 +        c.gridy = 0;
113 +        gridbag.setConstraints(nameBox, c);
114 +        clientPanel.add(nameBox);
115 +              
116 +        JPanel lists = new JPanel();
117 +        lists.setLayout(gridbag2);
118 +        
119 +        JPanel knownHostsPanel = new JPanel();
120 +        knownHostsPanel.setLayout(new BoxLayout(knownHostsPanel, BoxLayout.Y_AXIS));
121 +        hostDiscoveryMode = new JCheckBox("Discover new hosts from the server");
122 +        knownHostsPanel.add(hostDiscoveryMode);
123 +        knownHostsPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Known Hosts "));
124 +        knownHosts = new JList();
125 +        knownHosts.setVisibleRowCount(10);
126 +        JScrollPane knownHostsScrollPane = new JScrollPane(knownHosts);
127 +        knownHostsPanel.add(knownHostsScrollPane);
128 +        JLabel newHostLabel = new JLabel("New host:");
129 +        newHostLabel.setHorizontalAlignment(JLabel.RIGHT);
130 +        newHost = new JTextField(20);
131  
132 +        JButton newHostButton = new JButton("Add Host");
133 +        newHostButton.addActionListener(new ActionListener() {
134 +            public void actionPerformed(ActionEvent e) {
135 +                knownHostsModel.addElement(newHost.getText());
136 +                newHost.setText("");
137 +            }
138 +        });
139 +        JButton removeHostButton = new JButton("Remove Host(s)");
140 +        removeHostButton.addActionListener(new ActionListener() {
141 +            public void actionPerformed(ActionEvent e) {
142 +                Object[] selected = knownHosts.getSelectedValues();
143 +                for(int x = 0; x < selected.length; x++) {
144 +                    knownHostsModel.removeElement(selected[x]);
145 +                }
146 +            }
147 +        });
148 +        JPanel newHostBox = new JPanel();
149 +        newHostBox.setLayout(new GridLayout(1,3));
150 +        newHostBox.add(newHostLabel);
151 +        newHostBox.add(newHost);
152 +
153 +        JPanel buttonPanel = new JPanel();
154 +        buttonPanel.add(newHostButton);
155 +        buttonPanel.add(removeHostButton);
156 +        knownHostsPanel.add(buttonPanel);        
157 +        knownHostsPanel.add(newHostBox);
158 +        
159 +
160 +        c.gridy = 0;
161 +        c.gridx = 0;
162 +        gridbag.setConstraints(knownHostsPanel, c);
163 +        lists.add(knownHostsPanel);
164 +                
165 +        
166 +        JPanel addRemoveBox = new JPanel();
167 +        addRemoveBox.setLayout(new BoxLayout(addRemoveBox, BoxLayout.Y_AXIS));
168 +        addRemoveBox.add(Box.createGlue());
169 +        JButton add = new JButton(">>>");
170 +        add.addActionListener(new ActionListener() {
171 +            public void actionPerformed(ActionEvent e) {
172 +                Object[] selected = knownHosts.getSelectedValues();
173 +                for(int x = 0; x < selected.length; x++) {
174 +                    knownHostsModel.removeElement(selected[x]);
175 +                    hostListModel.addElement(selected[x]);
176 +                }
177 +            }
178 +        });
179 +        
180 +        addRemoveBox.add(add);
181 +        addRemoveBox.add(Box.createGlue());
182 +        JButton remove = new JButton("<<<");
183 +        remove.addActionListener(new ActionListener() {
184 +            public void actionPerformed(ActionEvent e) {
185 +                Object[] selected = hostList.getSelectedValues();
186 +                for(int x = 0; x < selected.length; x++) {
187 +                    hostListModel.removeElement(selected[x]);
188 +                    knownHostsModel.addElement(selected[x]);
189 +                }
190 +            }
191 +        });
192 +        addRemoveBox.add(remove);
193 +        addRemoveBox.add(Box.createGlue());
194 +        
195 +        c.gridy = 0;
196 +        c.gridx = 1;
197 +        gridbag.setConstraints(addRemoveBox, c);
198 +        lists.add(addRemoveBox);
199 +
200 +        JPanel hostListPanel = new JPanel();
201 +        hostListPanel.setLayout(new BoxLayout(hostListPanel, BoxLayout.Y_AXIS));
202 +        useHostList = new JCheckBox("Only monitor hosts in this list");
203 +        hostListPanel.add(useHostList);
204 +        hostListPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Hosts To Monitor "));
205 +        hostList = new JList();
206 +        hostList.setVisibleRowCount(10);
207 +        JScrollPane hostListScrollPane = new JScrollPane(hostList);
208 +        hostListPanel.add(hostListScrollPane);
209 +        
210 +        c.gridy = 0;
211 +        c.gridx = 2;
212 +        gridbag.setConstraints(hostListPanel, c);
213 +        lists.add(hostListPanel);
214 +        
215 +        c.gridy = 1;
216 +        c.gridx = 0;
217 +        gridbag.setConstraints(lists, c);
218 +        clientPanel.add(lists);
219 +        return clientPanel;
220 +    }
221 +
222 +    private JPanel createServerOptions() {
223 +        GridBagLayout gridbag = new GridBagLayout();
224 +        GridBagConstraints c = new GridBagConstraints();
225 +        c.fill = GridBagConstraints.HORIZONTAL;
226 +        JPanel serverPanel = new JPanel();
227 +        serverPanel.setLayout(gridbag);
228 +        JLabel serverLabel = new JLabel("i-scream Server:");
229 +        serverLabel.setHorizontalAlignment(JLabel.RIGHT);
230 +        server = new JTextField(20);
231 +        JPanel serverBox = new JPanel();
232 +        serverBox.setLayout(new GridLayout(1,2));
233 +        serverBox.add(serverLabel);
234 +        serverBox.add(server);
235 +        c.gridy = 0;
236 +        gridbag.setConstraints(serverBox, c);
237 +        serverPanel.add(serverBox);
238 +        JLabel portLabel = new JLabel("Client interface port:");
239 +        portLabel.setHorizontalAlignment(JLabel.RIGHT);
240 +        port = new JTextField(4);
241 +        JPanel portBox = new JPanel();
242 +        portBox.setLayout(new GridLayout(1,2));
243 +        portBox.add(portLabel);
244 +        portBox.add(port);
245 +        c.gridy = 1;
246 +        gridbag.setConstraints(portBox, c);
247 +        serverPanel.add(portBox);
248 +        connectControl = new JCheckBox("Automatically connect the control channel");
249 +        c.gridy = 2;
250 +        gridbag.setConstraints(connectControl, c);
251 +        serverPanel.add(connectControl);
252 +        connectData = new JCheckBox("Automatically connect the data channel");
253 +        c.gridy = 3;
254 +        gridbag.setConstraints(connectData, c);
255 +        serverPanel.add(connectData);
256 +        return serverPanel;
257 +    }
258 +
259 +    private JPanel createFirewallOptions() {
260 +        GridBagLayout gridbag = new GridBagLayout();
261 +        GridBagConstraints c = new GridBagConstraints();
262 +        c.fill = GridBagConstraints.HORIZONTAL;
263 +        JPanel firewallPanel = new JPanel();
264 +        firewallPanel.setLayout(gridbag);
265 +                
266 +        
267 +        useFirewall = new JCheckBox("Use firewall command to connect through to server");
268 +        c.gridy = 0;
269 +        gridbag.setConstraints(useFirewall, c);
270 +        firewallPanel.add(useFirewall);
271 +
272 +        JLabel commandLabel = new JLabel("Firewall command:");
273 +        commandLabel.setHorizontalAlignment(JLabel.RIGHT);
274 +        firewallCommand = new JTextField(20);
275 +        firewallCommand.setSize(new Dimension(1,10));
276 +        JPanel commandBox = new JPanel();
277 +        commandBox.setLayout(new GridLayout(1,2));
278 +        commandBox.add(commandLabel);
279 +        commandBox.add(firewallCommand);
280 +        
281 +        c.gridy = 1;
282 +        gridbag.setConstraints(commandBox, c);
283 +        firewallPanel.add(commandBox);
284 +        
285 +        JLabel waitLabel = new JLabel("Firewall wait time:");
286 +        waitLabel.setHorizontalAlignment(JLabel.RIGHT);
287 +        firewallWait = new JTextField(2);
288 +        JPanel waitBox = new JPanel();
289 +        waitBox.setLayout(new GridLayout(1,2));
290 +        waitBox.add(waitLabel);
291 +        waitBox.add(firewallWait);
292 +
293 +        c.gridy = 2;        
294 +        gridbag.setConstraints(waitBox, c);
295 +        firewallPanel.add(waitBox);
296 +        
297 +        JLabel fserverLabel = new JLabel("Firewall server:");
298 +        fserverLabel.setHorizontalAlignment(JLabel.RIGHT);
299 +        firewallServer = new JTextField(20);
300 +        JPanel fserverBox = new JPanel();
301 +        fserverBox.setLayout(new GridLayout(1,2));
302 +        fserverBox.add(fserverLabel);
303 +        fserverBox.add(firewallServer);
304 +        
305 +        c.gridy = 3;
306 +        gridbag.setConstraints(fserverBox, c);
307 +        firewallPanel.add(fserverBox);
308 +        
309 +        return firewallPanel;
310 +    }
311 +
312 +    private JPanel createDataOptions() {
313 +        GridBagLayout gridbag = new GridBagLayout();
314 +        GridBagConstraints c = new GridBagConstraints();
315 +        c.fill = GridBagConstraints.HORIZONTAL;
316 +        JPanel dataPanel = new JPanel();
317 +        dataPanel.setLayout(gridbag);
318 +        displayQueue = new JCheckBox("Display server queue information");
319 +        c.gridy = 0;
320 +        gridbag.setConstraints(displayQueue, c);
321 +        dataPanel.add(displayQueue);
322 +        displayExtra = new JCheckBox("Display extra data found in packets");
323 +        c.gridy = 1;
324 +        gridbag.setConstraints(displayExtra, c);
325 +        dataPanel.add(displayExtra);
326 +        packetDump = new JCheckBox("Dump raw packet data to the console");
327 +        c.gridy = 2;
328 +        gridbag.setConstraints(packetDump, c);
329 +        dataPanel.add(packetDump);
330 +        return dataPanel;
331 +    }
332 +    
333 +    private void getCurrentSettings() {
334 +        name.setText(config.getProperty("clientname"));
335 +        server.setText(config.getProperty("control.server"));
336 +        port.setText(config.getProperty("control.port"));
337 +        connectControl.setSelected(config.getProperty("control.onstartconnect").equals("1"));
338 +        connectData.setSelected(config.getProperty("data.onstartconnect").equals("1"));
339 +        firewallCommand.setText(config.getProperty("firewall.command"));
340 +        firewallCommand.moveCaretPosition(0);
341 +        firewallWait.setText(config.getProperty("firewall.commandwait"));
342 +        firewallServer.setText(config.getProperty("firewall.server"));
343 +        displayQueue.setSelected(config.getProperty("displayQueueInformation").equals("1"));
344 +        displayExtra.setSelected(config.getProperty("displayExtraData").equals("1"));
345 +        packetDump.setSelected(config.getProperty("packetDump").equals("1"));
346 +        useFirewall.setSelected(config.getProperty("useFirewall").equals("1"));
347 +        hostDiscoveryMode.setSelected(config.getProperty("hostDiscoveryMode").equals("1"));
348 +        useHostList.setSelected(config.getProperty("useHostList").equals("1"));
349 +        prepareLists();                
350 +    }
351 +    
352 +    
353 +    private void prepareLists() {
354 +        knownHostsModel = new DefaultListModel();
355 +        hostListModel = new DefaultListModel();
356 +        String configKnownHostsList = config.getProperty("knownHostsList");
357 +        String configHostList = config.getProperty("hostList");
358 +        StringTokenizer st;
359 +        st = new StringTokenizer(configKnownHostsList, ";");
360 +        while(st.hasMoreTokens()) {
361 +            // check its not in the other list...as we only want one entry in the two
362 +            String knownHost = st.nextToken();
363 +            if(configHostList.indexOf(knownHost) == -1) knownHostsModel.addElement(knownHost);
364 +        }
365 +        st = new StringTokenizer(configHostList, ";");
366 +        while(st.hasMoreTokens()) {
367 +            hostListModel.addElement(st.nextToken());
368 +        }
369 +        knownHosts.setModel(knownHostsModel);
370 +        hostList.setModel(hostListModel);
371 +    }
372 +    
373 +    private void setNewSettingsAndClose() {
374 +        
375 +        config.setProperty("clientname", name.getText().trim());
376 +        config.setProperty("control.server", server.getText().trim());
377 +        config.setProperty("control.port", port.getText().trim());
378 +        config.setProperty("firewall.command", firewallCommand.getText().trim());
379 +        config.setProperty("firewall.commandwait", firewallWait.getText().trim());
380 +        config.setProperty("firewall.server", firewallServer.getText().trim());
381 +        if (useFirewall.isSelected()) {
382 +            config.setProperty("useFirewall", "1");
383 +        } else {
384 +            config.setProperty("useFirewall", "0");
385 +        }
386 +        if (connectControl.isSelected()) {
387 +            config.setProperty("control.onstartconnect", "1");
388 +        } else {
389 +            config.setProperty("control.onstartconnect", "0");
390 +        }
391 +        if (connectData.isSelected()) {
392 +            config.setProperty("data.onstartconnect", "1");
393 +        } else {
394 +            config.setProperty("data.onstartconnect", "0");
395 +        }
396 +        if (packetDump.isSelected()) {
397 +            config.setProperty("packetDump", "1");
398 +        } else {
399 +            config.setProperty("packetDump", "0");
400 +        }
401 +        if (displayExtra.isSelected()) {
402 +            config.setProperty("displayExtraData", "1");
403 +        } else {
404 +            config.setProperty("displayExtraData", "0");
405 +        }
406 +        if (displayQueue.isSelected()) {
407 +            config.setProperty("displayQueueInformation", "1");
408 +        } else {
409 +            config.setProperty("displayQueueInformation", "0");
410 +        }
411 +        if (useHostList.isSelected()) {
412 +            config.setProperty("useHostList", "1");
413 +        } else {
414 +            config.setProperty("useHostList", "0");
415 +        }
416 +        if (hostDiscoveryMode.isSelected()) {
417 +            config.setProperty("hostDiscoveryMode", "1");
418 +        } else {
419 +            config.setProperty("hostDiscoveryMode", "0");
420 +        }
421 +        
422 +        // sort out the hosts lists
423 +        
424 +        // known hosts are both the known hosts list AND the host list
425 +        // first the hostlist...
426 +        Object[] hostListSaveArray =  hostListModel.toArray();
427 +        String hostListSave = "";
428 +        for(int x = 0; x < hostListSaveArray.length; x++) {
429 +            hostListSave += (String) hostListSaveArray[x] + ";";
430 +        }
431 +        Object[] knownHostsListSaveArray = knownHostsModel.toArray();
432 +        String knownHostsListSave = "";
433 +        for(int x = 0; x < knownHostsListSaveArray.length; x++) {
434 +            knownHostsListSave += (String) knownHostsListSaveArray[x] + ";";
435 +        }
436 +        knownHostsListSave += hostListSave;
437 +        config.setProperty("hostList", hostListSave);
438 +        config.setProperty("knownHostsList", knownHostsListSave);
439 +        dispose();
440 +    }
441 +
442   //---ACCESSOR/MUTATOR METHODS---
443  
444   //---ATTRIBUTES---
445 +
446 +    Configuration config = Configuration.getInstance();
447 +
448 +    private JTextField newHost;
449 +    
450 +    private JList knownHosts;
451 +    private JList hostList;
452 +    private JCheckBox hostDiscoveryMode;
453 +    private JCheckBox useHostList;
454 +    private JTextField name;
455 +    private JTextField port;
456 +    private JTextField server;
457 +    private JCheckBox connectControl;
458 +    private JCheckBox connectData;
459 +    private JCheckBox useFirewall;
460 +    private JTextField firewallCommand;
461 +    private JTextField firewallWait;
462 +    private JTextField firewallServer;
463 +    private JCheckBox displayQueue;
464 +    private JCheckBox displayExtra;
465 +    private JCheckBox packetDump;
466 +
467 +    private DefaultListModel knownHostsModel;
468 +    private DefaultListModel hostListModel;
469  
470   //---STATIC ATTRIBUTES---
471  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines