1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.conient; |
2 |
> |
package uk.org.iscream.conient; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import java.awt.Frame; |
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 |
64 |
|
|
65 |
|
|
66 |
|
// setup the options panes |
67 |
< |
JPanel center = new JPanel(); |
68 |
< |
center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS)); |
67 |
> |
JTabbedPane center = new JTabbedPane(); |
68 |
> |
//center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS)); |
69 |
|
|
70 |
|
// client options |
71 |
< |
center.add(createClientOptions()); |
71 |
> |
center.addTab("Client Options", createClientOptions()); |
72 |
|
|
73 |
|
// server options |
74 |
< |
center.add(createServerOptions()); |
74 |
> |
center.addTab("Server Options", createServerOptions()); |
75 |
|
|
76 |
|
// firewall options |
77 |
< |
center.add(createFirewallOptions()); |
77 |
> |
center.addTab("Firewall Options", createFirewallOptions()); |
78 |
|
|
79 |
|
// data options |
80 |
< |
center.add(createDataOptions()); |
80 |
> |
center.addTab("Data Options", createDataOptions()); |
81 |
|
|
82 |
|
// display the current settings |
83 |
|
getCurrentSettings(); |
94 |
|
//---PUBLIC METHODS--- |
95 |
|
|
96 |
|
//---PRIVATE METHODS--- |
97 |
< |
|
97 |
> |
|
98 |
|
private JPanel createClientOptions() { |
99 |
|
JPanel clientPanel = new JPanel(); |
100 |
|
clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS)); |
100 |
– |
clientPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Client Options ")); |
101 |
|
JLabel nameLabel = new JLabel("Client name:"); |
102 |
|
nameLabel.setHorizontalAlignment(JLabel.RIGHT); |
103 |
|
name = new JTextField(20); |
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)); |
115 |
– |
serverPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " i-scream Server Options ")); |
190 |
|
JLabel serverLabel = new JLabel("i-scream Server:"); |
191 |
|
serverLabel.setHorizontalAlignment(JLabel.RIGHT); |
192 |
|
server = new JTextField(20); |
215 |
|
private JPanel createFirewallOptions() { |
216 |
|
JPanel firewallPanel = new JPanel(); |
217 |
|
firewallPanel.setLayout(new BoxLayout(firewallPanel, BoxLayout.Y_AXIS)); |
144 |
– |
firewallPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Firewall Options ")); |
218 |
|
|
219 |
|
useFirewall = new JCheckBox("Use firewall command to connect through to server"); |
220 |
|
firewallPanel.add(useFirewall); |
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:"); |
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:"); |
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.X_AXIS)); |
258 |
< |
dataPanel.setBorder(new TitledBorder(new LineBorder(new Color(0, 0, 102)), " Data Options ")); |
182 |
< |
|
183 |
< |
JPanel dataChecks = new JPanel(); |
184 |
< |
dataChecks.setLayout(new BoxLayout(dataChecks, BoxLayout.Y_AXIS)); |
257 |
> |
dataPanel.setLayout(new BoxLayout(dataPanel, BoxLayout.Y_AXIS)); |
258 |
> |
|
259 |
|
displayQueue = new JCheckBox("Display server queue information"); |
260 |
< |
dataChecks.add(displayQueue); |
260 |
> |
dataPanel.add(displayQueue); |
261 |
|
displayExtra = new JCheckBox("Display extra data found in packets"); |
262 |
< |
dataChecks.add(displayExtra); |
262 |
> |
dataPanel.add(displayExtra); |
263 |
|
packetDump = new JCheckBox("Dump raw packet data to the console"); |
264 |
< |
dataChecks.add(packetDump); |
264 |
> |
dataPanel.add(packetDump); |
265 |
|
|
266 |
< |
dataPanel.add(Box.createHorizontalGlue()); |
193 |
< |
dataPanel.add(dataChecks); |
194 |
< |
dataPanel.add(Box.createHorizontalGlue()); |
266 |
> |
dataPanel.add(Box.createGlue()); |
267 |
|
return dataPanel; |
268 |
|
} |
269 |
|
|
270 |
|
private void getCurrentSettings() { |
199 |
– |
Configuration config = Configuration.getInstance(); |
271 |
|
name.setText(config.getProperty("clientname")); |
272 |
|
server.setText(config.getProperty("control.server")); |
273 |
|
port.setText(config.getProperty("control.port")); |
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 |
< |
Configuration config = Configuration.getInstance(); |
311 |
> |
|
312 |
|
config.setProperty("clientname", name.getText().trim()); |
313 |
|
config.setProperty("control.server", server.getText().trim()); |
314 |
|
config.setProperty("control.port", port.getText().trim()); |
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 |
|
|
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; |
401 |
|
private JCheckBox displayExtra; |
402 |
|
private JCheckBox packetDump; |
403 |
|
|
404 |
+ |
private DefaultListModel knownHostsModel; |
405 |
+ |
private DefaultListModel hostListModel; |
406 |
|
|
407 |
|
//---STATIC ATTRIBUTES--- |
408 |
|
|