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.7 by ajm, Thu Mar 15 01:05:46 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.Frame;
6 > import java.awt.Color;
7 > import java.awt.GridLayout;
8 > import java.awt.event.*;
9 > import javax.swing.*;
10 > import javax.swing.border.*;
11   import java.util.Properties;
12 + import java.util.StringTokenizer;
13  
14   /**
15   * This provides a modal dialog from which the user
# Line 34 | Line 40 | public class ConfigurationDialog extends JDialog {
40       * Constructs and shows the dialog for the user
41       */
42      public ConfigurationDialog() {
43 +        super(Conient.getFrame(), "Configuration Options", true);
44          
45 +        // setup the buttoms
46 +        JPanel buttonPanel = new JPanel();
47 +        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
48 +        JButton ok = new JButton("OK");
49 +        ok.addActionListener(new ActionListener() {
50 +            public void actionPerformed(ActionEvent e) {
51 +                setNewSettingsAndClose();
52 +            }
53 +        });
54 +        
55 +        JButton cancel = new JButton("Cancel");
56 +        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 +        JTabbedPane center = new JTabbedPane();
68 +        //center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
69 +        
70 +        // client options
71 +        center.addTab("Client Options", createClientOptions());
72 +        
73 +        // server options
74 +        center.addTab("Server Options", createServerOptions());
75 +
76 +        // firewall options
77 +        center.addTab("Firewall Options", createFirewallOptions());
78 +        
79 +        // data options
80 +        center.addTab("Data Options", createDataOptions());
81 +        
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 +  
98 +    private JPanel createClientOptions() {
99 +        JPanel clientPanel = new JPanel();
100 +        clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS));
101 +        JLabel nameLabel = new JLabel("Client name:");
102 +        nameLabel.setHorizontalAlignment(JLabel.RIGHT);
103 +        name = new JTextField(20);
104 +        JPanel nameBox = new JPanel();
105 +        nameBox.setLayout(new GridLayout(1,2));
106 +        nameBox.add(nameLabel);
107 +        nameBox.add(name);
108 +        clientPanel.add(nameBox);
109 +              
110 +        JPanel lists = new JPanel();
111 +        lists.setLayout(new BoxLayout(lists, BoxLayout.X_AXIS));
112 +        
113 +        JPanel knownHostsPanel = new JPanel();
114 +        knownHostsPanel.setLayout(new BoxLayout(knownHostsPanel, BoxLayout.Y_AXIS));
115 +        hostDiscoveryMode = new JCheckBox("Discover new hosts from the server");
116 +        knownHostsPanel.add(hostDiscoveryMode);
117 +        knownHostsPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Known Hosts "));
118 +        knownHosts = new JList();
119 +        knownHosts.setVisibleRowCount(10);
120 +        JScrollPane knownHostsScrollPane = new JScrollPane(knownHosts);
121 +        knownHostsPanel.add(knownHostsScrollPane);
122 +        JLabel newHostLabel = new JLabel("New host:");
123 +        newHostLabel.setHorizontalAlignment(JLabel.RIGHT);
124 +        newHost = new JTextField(20);
125 +        JButton newHostButton = new JButton("Add to known hosts");
126 +        newHostButton.addActionListener(new ActionListener() {
127 +            public void actionPerformed(ActionEvent e) {
128 +                knownHostsModel.addElement(newHost.getText());
129 +                newHost.setText("");
130 +            }
131 +        });
132 +        JPanel newHostBox = new JPanel();
133 +        newHostBox.setLayout(new GridLayout(1,3));
134 +        newHostBox.add(newHostLabel);
135 +        newHostBox.add(newHost);
136 +          
137 +        knownHostsPanel.add(newHostBox);
138 +        knownHostsPanel.add(newHostButton);  
139 +        lists.add(knownHostsPanel);
140 +                
141 +        
142 +        JPanel addRemoveBox = new JPanel();
143 +        addRemoveBox.setLayout(new BoxLayout(addRemoveBox, BoxLayout.Y_AXIS));
144 +        addRemoveBox.add(Box.createGlue());
145 +        JButton add = new JButton(">>>");
146 +        add.addActionListener(new ActionListener() {
147 +            public void actionPerformed(ActionEvent e) {
148 +                Object[] selected = knownHosts.getSelectedValues();
149 +                for(int x = 0; x < selected.length; x++) {
150 +                    knownHostsModel.removeElement(selected[x]);
151 +                    hostListModel.addElement(selected[x]);
152 +                }
153 +            }
154 +        });
155 +        
156 +        addRemoveBox.add(add);
157 +        addRemoveBox.add(Box.createGlue());
158 +        JButton remove = new JButton("<<<");
159 +        remove.addActionListener(new ActionListener() {
160 +            public void actionPerformed(ActionEvent e) {
161 +                Object[] selected = hostList.getSelectedValues();
162 +                for(int x = 0; x < selected.length; x++) {
163 +                    hostListModel.removeElement(selected[x]);
164 +                    knownHostsModel.addElement(selected[x]);
165 +                }
166 +            }
167 +        });
168 +        addRemoveBox.add(remove);
169 +        addRemoveBox.add(Box.createGlue());
170 +        lists.add(addRemoveBox);
171  
172 +        JPanel hostListPanel = new JPanel();
173 +        hostListPanel.setLayout(new BoxLayout(hostListPanel, BoxLayout.Y_AXIS));
174 +        useHostList = new JCheckBox("Only monitor hosts in this list");
175 +        hostListPanel.add(useHostList);
176 +        hostListPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Hosts To Monitor "));
177 +        hostList = new JList();
178 +        hostList.setVisibleRowCount(10);
179 +        JScrollPane hostListScrollPane = new JScrollPane(hostList);
180 +        hostListPanel.add(hostListScrollPane);
181 +        lists.add(hostListPanel);
182 +        
183 +        clientPanel.add(lists);
184 +        return clientPanel;
185 +    }
186 +
187 +    private JPanel createServerOptions() {
188 +        JPanel serverPanel = new JPanel();
189 +        serverPanel.setLayout(new BoxLayout(serverPanel, BoxLayout.Y_AXIS));
190 +        JLabel serverLabel = new JLabel("i-scream Server:");
191 +        serverLabel.setHorizontalAlignment(JLabel.RIGHT);
192 +        server = new JTextField(20);
193 +        JPanel serverBox = new JPanel();
194 +        serverBox.setLayout(new GridLayout(1,2));
195 +        serverBox.add(serverLabel);
196 +        serverBox.add(server);
197 +        serverPanel.add(serverBox);
198 +        
199 +        JLabel portLabel = new JLabel("Client interface port:");
200 +        portLabel.setHorizontalAlignment(JLabel.RIGHT);
201 +        port = new JTextField(4);
202 +        JPanel portBox = new JPanel();
203 +        portBox.setLayout(new GridLayout(1,2));
204 +        portBox.add(portLabel);
205 +        portBox.add(port);
206 +        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);
212 +        return serverPanel;
213 +    }
214 +
215 +    private JPanel createFirewallOptions() {
216 +        JPanel firewallPanel = new JPanel();
217 +        firewallPanel.setLayout(new BoxLayout(firewallPanel, BoxLayout.Y_AXIS));
218 +        
219 +        useFirewall = new JCheckBox("Use firewall command to connect through to server");
220 +        firewallPanel.add(useFirewall);
221 +        
222 +        JLabel commandLabel = new JLabel("Firewall command:");
223 +        commandLabel.setHorizontalAlignment(JLabel.RIGHT);
224 +        firewallCommand = new JTextField(20);
225 +        JPanel commandBox = new JPanel();
226 +        commandBox.setLayout(new GridLayout(1,2));
227 +        commandBox.add(commandLabel);
228 +        commandBox.add(firewallCommand);
229 +        
230 +        firewallPanel.add(commandBox);
231 +        
232 +        JLabel waitLabel = new JLabel("Firewall wait time:");
233 +        waitLabel.setHorizontalAlignment(JLabel.RIGHT);
234 +        firewallWait = new JTextField(2);
235 +        JPanel waitBox = new JPanel();
236 +        waitBox.setLayout(new GridLayout(1,2));
237 +        waitBox.add(waitLabel);
238 +        waitBox.add(firewallWait);
239 +        
240 +        firewallPanel.add(waitBox);
241 +        
242 +        JLabel fserverLabel = new JLabel("Firewall server:");
243 +        fserverLabel.setHorizontalAlignment(JLabel.RIGHT);
244 +        firewallServer = new JTextField(20);
245 +        JPanel fserverBox = new JPanel();
246 +        fserverBox.setLayout(new GridLayout(1,2));
247 +        fserverBox.add(fserverLabel);
248 +        fserverBox.add(firewallServer);
249 +        
250 +        firewallPanel.add(fserverBox);
251 +        firewallPanel.add(Box.createGlue());
252 +        return firewallPanel;
253 +    }
254 +
255 +    private JPanel createDataOptions() {
256 +        JPanel dataPanel = new JPanel();
257 +        dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS));
258 +
259 +        displayQueue = new JCheckBox("Display server queue information");
260 +        dataPanel.add(displayQueue);
261 +        displayExtra = new JCheckBox("Display extra data found in packets");
262 +        dataPanel.add(displayExtra);
263 +        packetDump = new JCheckBox("Dump raw packet data to the console");
264 +        dataPanel.add(packetDump);
265 +
266 +        dataPanel.add(Box.createGlue());
267 +        return dataPanel;
268 +    }
269 +    
270 +    private void getCurrentSettings() {
271 +        name.setText(config.getProperty("clientname"));
272 +        server.setText(config.getProperty("control.server"));
273 +        port.setText(config.getProperty("control.port"));
274 +        connectControl.setSelected(config.getProperty("control.onstartconnect").equals("1"));
275 +        connectData.setSelected(config.getProperty("data.onstartconnect").equals("1"));
276 +        firewallCommand.setText(config.getProperty("firewall.command"));
277 +        firewallCommand.moveCaretPosition(0);
278 +        firewallWait.setText(config.getProperty("firewall.commandwait"));
279 +        firewallServer.setText(config.getProperty("firewall.server"));
280 +        displayQueue.setSelected(config.getProperty("displayQueueInformation").equals("1"));
281 +        displayExtra.setSelected(config.getProperty("displayExtraData").equals("1"));
282 +        packetDump.setSelected(config.getProperty("packetDump").equals("1"));
283 +        useFirewall.setSelected(config.getProperty("useFirewall").equals("1"));
284 +        hostDiscoveryMode.setSelected(config.getProperty("hostDiscoveryMode").equals("1"));
285 +        useHostList.setSelected(config.getProperty("useHostList").equals("1"));
286 +        prepareLists();                
287 +    }
288 +    
289 +    
290 +    private void prepareLists() {
291 +        knownHostsModel = new DefaultListModel();
292 +        hostListModel = new DefaultListModel();
293 +        String configKnownHostsList = config.getProperty("knownHostsList");
294 +        String configHostList = config.getProperty("hostList");
295 +        StringTokenizer st;
296 +        st = new StringTokenizer(configKnownHostsList, ";");
297 +        while(st.hasMoreTokens()) {
298 +            // check its not in the other list...as we only want one entry in the two
299 +            String knownHost = st.nextToken();
300 +            if(configHostList.indexOf(knownHost) == -1) knownHostsModel.addElement(knownHost);
301 +        }
302 +        st = new StringTokenizer(configHostList, ";");
303 +        while(st.hasMoreTokens()) {
304 +            hostListModel.addElement(st.nextToken());
305 +        }
306 +        knownHosts.setModel(knownHostsModel);
307 +        hostList.setModel(hostListModel);
308 +    }
309 +    
310 +    private void setNewSettingsAndClose() {
311 +        
312 +        config.setProperty("clientname", name.getText().trim());
313 +        config.setProperty("control.server", server.getText().trim());
314 +        config.setProperty("control.port", port.getText().trim());
315 +        config.setProperty("firewall.command", firewallCommand.getText().trim());
316 +        config.setProperty("firewall.commandwait", firewallWait.getText().trim());
317 +        config.setProperty("firewall.server", firewallServer.getText().trim());
318 +        if (useFirewall.isSelected()) {
319 +            config.setProperty("useFirewall", "1");
320 +        } else {
321 +            config.setProperty("useFirewall", "0");
322 +        }
323 +        if (connectControl.isSelected()) {
324 +            config.setProperty("control.onstartconnect", "1");
325 +        } else {
326 +            config.setProperty("control.onstartconnect", "0");
327 +        }
328 +        if (connectData.isSelected()) {
329 +            config.setProperty("data.onstartconnect", "1");
330 +        } else {
331 +            config.setProperty("data.onstartconnect", "0");
332 +        }
333 +        if (packetDump.isSelected()) {
334 +            config.setProperty("packetDump", "1");
335 +        } else {
336 +            config.setProperty("packetDump", "0");
337 +        }
338 +        if (displayExtra.isSelected()) {
339 +            config.setProperty("displayExtraData", "1");
340 +        } else {
341 +            config.setProperty("displayExtraData", "0");
342 +        }
343 +        if (displayQueue.isSelected()) {
344 +            config.setProperty("displayQueueInformation", "1");
345 +        } else {
346 +            config.setProperty("displayQueueInformation", "0");
347 +        }
348 +        if (useHostList.isSelected()) {
349 +            config.setProperty("useHostList", "1");
350 +        } else {
351 +            config.setProperty("useHostList", "0");
352 +        }
353 +        if (hostDiscoveryMode.isSelected()) {
354 +            config.setProperty("hostDiscoveryMode", "1");
355 +        } else {
356 +            config.setProperty("hostDiscoveryMode", "0");
357 +        }
358 +        
359 +        // sort out the hosts lists
360 +        
361 +        // known hosts are both the known hosts list AND the host list
362 +        // first the hostlist...
363 +        Object[] hostListSaveArray =  hostListModel.toArray();
364 +        String hostListSave = "";
365 +        for(int x = 0; x < hostListSaveArray.length; x++) {
366 +            hostListSave += (String) hostListSaveArray[x] + ";";
367 +        }
368 +        Object[] knownHostsListSaveArray = knownHostsModel.toArray();
369 +        String knownHostsListSave = "";
370 +        for(int x = 0; x < knownHostsListSaveArray.length; x++) {
371 +            knownHostsListSave += (String) knownHostsListSaveArray[x] + ";";
372 +        }
373 +        knownHostsListSave += hostListSave;
374 +        config.setProperty("hostList", hostListSave);
375 +        config.setProperty("knownHostsList", knownHostsListSave);
376 +        dispose();
377 +    }
378 +
379   //---ACCESSOR/MUTATOR METHODS---
380  
381   //---ATTRIBUTES---
382 +
383 +    Configuration config = Configuration.getInstance();
384 +
385 +    private JTextField newHost;
386 +    
387 +    private JList knownHosts;
388 +    private JList hostList;
389 +    private JCheckBox hostDiscoveryMode;
390 +    private JCheckBox useHostList;
391 +    private JTextField name;
392 +    private JTextField port;
393 +    private JTextField server;
394 +    private JCheckBox connectControl;
395 +    private JCheckBox connectData;
396 +    private JCheckBox useFirewall;
397 +    private JTextField firewallCommand;
398 +    private JTextField firewallWait;
399 +    private JTextField firewallServer;
400 +    private JCheckBox displayQueue;
401 +    private JCheckBox displayExtra;
402 +    private JCheckBox packetDump;
403 +
404 +    private DefaultListModel knownHostsModel;
405 +    private DefaultListModel hostListModel;
406  
407   //---STATIC ATTRIBUTES---
408  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines