39 |
import javax.swing.JButton; |
import javax.swing.JButton; |
40 |
import javax.swing.JCheckBox; |
import javax.swing.JCheckBox; |
41 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
|
import javax.swing.JOptionPane; |
|
42 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
43 |
import javax.swing.JScrollPane; |
import javax.swing.JScrollPane; |
44 |
import javax.swing.JSpinner; |
import javax.swing.JSpinner; |
53 |
import org.jsampler.CC; |
import org.jsampler.CC; |
54 |
import org.jsampler.HF; |
import org.jsampler.HF; |
55 |
import org.jsampler.JSPrefs; |
import org.jsampler.JSPrefs; |
|
import org.jsampler.Prefs; |
|
|
|
|
|
import org.jsampler.task.SetServerAddress; |
|
56 |
|
|
57 |
import org.jsampler.view.ServerTable; |
import org.jsampler.view.ServerTable; |
58 |
import org.jsampler.view.ServerTableModel; |
import org.jsampler.view.ServerTableModel; |
75 |
private final JSpinner spinnerTimeout = new JSpinner(new SpinnerNumberModel(0, 0, 2000, 1)); |
private final JSpinner spinnerTimeout = new JSpinner(new SpinnerNumberModel(0, 0, 2000, 1)); |
76 |
|
|
77 |
private final ServerListPane serverListPane; |
private final ServerListPane serverListPane; |
78 |
|
private final LocalSettingsPane localSettingsPane = new LocalSettingsPane(); |
79 |
|
|
80 |
|
|
81 |
/** Creates a new instance of <code>JSConnectionPropsPane</code> */ |
/** Creates a new instance of <code>JSConnectionPropsPane</code> */ |
107 |
|
|
108 |
serverListPane = createServerListPane(); |
serverListPane = createServerListPane(); |
109 |
add(serverListPane); |
add(serverListPane); |
110 |
|
add(Box.createRigidArea(new Dimension(0, 6))); |
111 |
|
|
112 |
|
add(localSettingsPane); |
113 |
|
|
114 |
setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
115 |
} |
} |
116 |
|
|
117 |
private ServerListPane |
private ServerListPane |
118 |
createServerListPane() { |
createServerListPane() { |
119 |
ServerListPane p = new ServerListPane(); |
ServerListPane p = new ServerListPane(); |
120 |
p.setPreferredSize(new Dimension(200, 200)); |
p.setPreferredSize(new Dimension(200, 160)); |
121 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); |
122 |
|
|
123 |
String s = i18n.getLabel("JSConnectionPropsPane.title"); |
String s = i18n.getLabel("JSConnectionPropsPane.title"); |
147 |
|
|
148 |
int i = serverListPane.serverTable.getSelectedRow(); |
int i = serverListPane.serverTable.getSelectedRow(); |
149 |
if(i != -1) preferences().setIntProperty(SERVER_INDEX, i); |
if(i != -1) preferences().setIntProperty(SERVER_INDEX, i); |
150 |
|
|
151 |
|
localSettingsPane.apply(); |
152 |
} |
} |
153 |
|
|
154 |
public static class ServerListPane extends JPanel { |
public static class ServerListPane extends JPanel { |
274 |
} |
} |
275 |
|
|
276 |
private class ServerSelectionHandler implements ListSelectionListener { |
private class ServerSelectionHandler implements ListSelectionListener { |
277 |
|
@Override |
278 |
public void |
public void |
279 |
valueChanged(ListSelectionEvent e) { |
valueChanged(ListSelectionEvent e) { |
280 |
if(e.getValueIsAdjusting()) return; |
if(e.getValueIsAdjusting()) return; |
291 |
} |
} |
292 |
} |
} |
293 |
} |
} |
294 |
|
|
295 |
|
public static class LocalSettingsPane extends JPanel { |
296 |
|
private final JCheckBox checkLaunchBackend = |
297 |
|
new JCheckBox(i18n.getLabel("JSConnectionPropsPane.checkLaunchBackend")); |
298 |
|
|
299 |
|
private final JLabel lCommand = |
300 |
|
new JLabel(i18n.getLabel("JSConnectionPropsPane.lCommand")); |
301 |
|
|
302 |
|
private final JLabel lDelay = |
303 |
|
new JLabel(i18n.getLabel("JSConnectionPropsPane.lDelay")); |
304 |
|
|
305 |
|
private final JLabel lSeconds = |
306 |
|
new JLabel(i18n.getLabel("JSConnectionPropsPane.lSeconds")); |
307 |
|
|
308 |
|
private final JTextField tfCommand = new JTextField(); |
309 |
|
private final JSpinner spinnerDelay; |
310 |
|
|
311 |
|
public |
312 |
|
LocalSettingsPane() { |
313 |
|
GridBagLayout gridbag = new GridBagLayout(); |
314 |
|
GridBagConstraints c = new GridBagConstraints(); |
315 |
|
|
316 |
|
setLayout(gridbag); |
317 |
|
|
318 |
|
c.fill = GridBagConstraints.NONE; |
319 |
|
|
320 |
|
c.gridx = 0; |
321 |
|
c.gridy = 0; |
322 |
|
c.anchor = GridBagConstraints.WEST; |
323 |
|
c.insets = new Insets(0, 3, 3, 3); |
324 |
|
c.gridwidth = 3; |
325 |
|
gridbag.setConstraints(checkLaunchBackend, c); |
326 |
|
add(checkLaunchBackend); |
327 |
|
|
328 |
|
c.gridx = 0; |
329 |
|
c.gridy = 1; |
330 |
|
c.gridwidth = 1; |
331 |
|
c.insets = new Insets(3, 9, 3, 3); |
332 |
|
c.anchor = GridBagConstraints.EAST; |
333 |
|
gridbag.setConstraints(lCommand, c); |
334 |
|
add(lCommand); |
335 |
|
|
336 |
|
c.gridx = 0; |
337 |
|
c.gridy = 2; |
338 |
|
c.insets = new Insets(3, 3, 3, 3); |
339 |
|
gridbag.setConstraints(lDelay, c); |
340 |
|
add(lDelay); |
341 |
|
|
342 |
|
spinnerDelay = new JSpinner(new SpinnerNumberModel(3, 0, 100, 1)); |
343 |
|
|
344 |
|
c.gridx = 1; |
345 |
|
c.gridy = 2; |
346 |
|
c.insets = new Insets(3, 3, 3, 3); |
347 |
|
c.anchor = GridBagConstraints.WEST; |
348 |
|
gridbag.setConstraints(spinnerDelay, c); |
349 |
|
add(spinnerDelay); |
350 |
|
|
351 |
|
c.gridx = 2; |
352 |
|
c.gridy = 2; |
353 |
|
gridbag.setConstraints(lSeconds, c); |
354 |
|
add(lSeconds); |
355 |
|
|
356 |
|
c.fill = GridBagConstraints.HORIZONTAL; |
357 |
|
c.gridx = 1; |
358 |
|
c.gridy = 1; |
359 |
|
c.weightx = 1.0; |
360 |
|
c.gridwidth = 2; |
361 |
|
c.anchor = GridBagConstraints.WEST; |
362 |
|
gridbag.setConstraints(tfCommand, c); |
363 |
|
add(tfCommand); |
364 |
|
|
365 |
|
String s = i18n.getLabel("JSConnectionPropsPane.localSettings"); |
366 |
|
setBorder(BorderFactory.createTitledBorder(s)); |
367 |
|
|
368 |
|
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
369 |
|
|
370 |
|
setAlignmentX(LEFT_ALIGNMENT); |
371 |
|
|
372 |
|
checkLaunchBackend.addActionListener(new ActionListener() { |
373 |
|
public void |
374 |
|
actionPerformed(ActionEvent e) { |
375 |
|
updateLocalSettingsState(); |
376 |
|
} |
377 |
|
}); |
378 |
|
|
379 |
|
boolean b = preferences().getBoolProperty(LAUNCH_BACKEND_LOCALLY); |
380 |
|
checkLaunchBackend.setSelected(b); |
381 |
|
|
382 |
|
s = preferences().getStringProperty(BACKEND_LAUNCH_COMMAND); |
383 |
|
tfCommand.setText(s); |
384 |
|
|
385 |
|
int i = preferences().getIntProperty(BACKEND_LAUNCH_DELAY); |
386 |
|
spinnerDelay.setValue(i); |
387 |
|
|
388 |
|
updateLocalSettingsState(); |
389 |
|
} |
390 |
|
|
391 |
|
private void |
392 |
|
updateLocalSettingsState() { |
393 |
|
boolean b = checkLaunchBackend.isSelected(); |
394 |
|
tfCommand.setEnabled(b); |
395 |
|
spinnerDelay.setEnabled(b); |
396 |
|
} |
397 |
|
|
398 |
|
public void |
399 |
|
apply() { |
400 |
|
boolean b = checkLaunchBackend.isSelected(); |
401 |
|
preferences().setBoolProperty(LAUNCH_BACKEND_LOCALLY, b); |
402 |
|
|
403 |
|
preferences().setStringProperty(BACKEND_LAUNCH_COMMAND, tfCommand.getText()); |
404 |
|
|
405 |
|
int i = Integer.parseInt(spinnerDelay.getValue().toString()); |
406 |
|
preferences().setIntProperty(BACKEND_LAUNCH_DELAY, i); |
407 |
|
} |
408 |
|
} |
409 |
} |
} |