/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSConnectionPropsPane.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSConnectionPropsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1786 - (show annotations) (download)
Wed Oct 8 22:38:15 2008 UTC (15 years, 6 months ago) by iliev
File size: 11711 byte(s)
* Implemented option to launch the backend if it is not yet started
  (choose Edit/Preferences, then click the `Backend' tab)
* LSCP scripts can now be run by passing them to jsampler
  as command-line arguments
* The scripts in the `scripts' directory now pass the command-line
  arguments to the respective jsampler distribution
* ant: the default target is now build-fantasia
* bugfix: backend address was always set to 127.0.0.1 when adding
  backend to the backend list

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.view.std;
24
25 import java.awt.Dialog;
26 import java.awt.Dimension;
27 import java.awt.Frame;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.Window;
32
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35
36 import javax.swing.BorderFactory;
37 import javax.swing.Box;
38 import javax.swing.BoxLayout;
39 import javax.swing.JButton;
40 import javax.swing.JCheckBox;
41 import javax.swing.JLabel;
42 import javax.swing.JPanel;
43 import javax.swing.JScrollPane;
44 import javax.swing.JSpinner;
45 import javax.swing.JTextField;
46 import javax.swing.SpinnerNumberModel;
47
48 import javax.swing.event.ListSelectionEvent;
49 import javax.swing.event.ListSelectionListener;
50
51 import net.sf.juife.JuifeUtils;
52
53 import org.jsampler.CC;
54 import org.jsampler.HF;
55 import org.jsampler.JSPrefs;
56
57 import org.jsampler.view.ServerTable;
58 import org.jsampler.view.ServerTableModel;
59
60 import static org.jsampler.view.std.StdI18n.i18n;
61 import static org.jsampler.view.std.StdPrefs.*;
62
63
64 /**
65 *
66 * @author Grigor Iliev
67 */
68 public class JSConnectionPropsPane extends JPanel {
69 private final JCheckBox checkManualSelect =
70 new JCheckBox(i18n.getLabel("JSConnectionPropsPane.checkManualSelect"));
71
72 private final JLabel lReadTimeout =
73 new JLabel(i18n.getLabel("JSConnectionPropsPane.lReadTimeout"));
74
75 private final JSpinner spinnerTimeout = new JSpinner(new SpinnerNumberModel(0, 0, 2000, 1));
76
77 private final ServerListPane serverListPane;
78 private final LocalSettingsPane localSettingsPane = new LocalSettingsPane();
79
80
81 /** Creates a new instance of <code>JSConnectionPropsPane</code> */
82 public
83 JSConnectionPropsPane() {
84 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
85
86 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
87 checkManualSelect.setSelected(b);
88
89 checkManualSelect.setAlignmentX(LEFT_ALIGNMENT);
90 add(checkManualSelect);
91 add(Box.createRigidArea(new Dimension(0, 6)));
92
93 JPanel p = new JPanel();
94 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
95
96 p.add(lReadTimeout);
97 p.add(Box.createRigidArea(new Dimension(6, 0)));
98
99 int i = preferences().getIntProperty(SOCKET_READ_TIMEOUT);
100 spinnerTimeout.setValue(i);
101 p.add(spinnerTimeout);
102
103 p.setAlignmentX(LEFT_ALIGNMENT);
104 p.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height));
105 add(p);
106 add(Box.createRigidArea(new Dimension(0, 6)));
107
108 serverListPane = createServerListPane();
109 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));
115 }
116
117 private ServerListPane
118 createServerListPane() {
119 ServerListPane p = new ServerListPane();
120 p.setPreferredSize(new Dimension(200, 160));
121 p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
122
123 String s = i18n.getLabel("JSConnectionPropsPane.title");
124 p.setBorder(BorderFactory.createTitledBorder(s));
125 p.setAlignmentX(LEFT_ALIGNMENT);
126
127 return p;
128 }
129
130 private static JSPrefs
131 preferences() { return CC.getViewConfig().preferences(); }
132
133 /**
134 * Gets the read timeout in seconds.
135 */
136 public int
137 getReadTimeout() { return Integer.parseInt(spinnerTimeout.getValue().toString()); }
138
139 public void
140 apply() {
141 boolean b = checkManualSelect.isSelected();
142 preferences().setBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP, b);
143
144 preferences().setIntProperty(SOCKET_READ_TIMEOUT, getReadTimeout());
145
146 CC.setClientReadTimeout(getReadTimeout());
147
148 int i = serverListPane.serverTable.getSelectedRow();
149 if(i != -1) preferences().setIntProperty(SERVER_INDEX, i);
150
151 localSettingsPane.apply();
152 }
153
154 public static class ServerListPane extends JPanel {
155 protected final ServerTable serverTable;
156
157 private final JButton btnAdd = new JButton(i18n.getButtonLabel("add"));
158 private final JButton btnRemove = new JButton(i18n.getButtonLabel("remove"));
159
160 private final JButton btnMoveUp =
161 new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveUp"));
162
163 private final JButton btnMoveDown =
164 new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveDown"));
165
166 public
167 ServerListPane() {
168 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
169
170 ServerTableModel model = new ServerTableModel(CC.getServerList());
171 serverTable = new ServerTable(model);
172
173 add(new JScrollPane(serverTable));
174
175 int h = btnAdd.getPreferredSize().height;
176 btnAdd.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
177
178 h = btnRemove.getPreferredSize().height;
179 btnRemove.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
180
181 h = btnMoveUp.getPreferredSize().height;
182 btnMoveUp.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
183
184 h = btnMoveDown.getPreferredSize().height;
185 btnMoveDown.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
186
187 JPanel p = new JPanel();
188 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
189 p.add(btnAdd);
190 p.add(Box.createRigidArea(new Dimension(0, 5)));
191 p.add(btnRemove);
192 p.add(Box.createRigidArea(new Dimension(0, 17)));
193 p.add(btnMoveUp);
194 p.add(Box.createRigidArea(new Dimension(0, 5)));
195 p.add(btnMoveDown);
196 p.add(Box.createGlue());
197
198 p.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
199
200 add(p);
201
202 installListeners();
203
204 int i = preferences().getIntProperty(JSPrefs.SERVER_INDEX);
205 int size = CC.getServerList().getServerCount();
206 if(size > 0) {
207 if(i < 0 || i >= size) {
208 serverTable.getSelectionModel().setSelectionInterval(0, 0);
209 } else {
210 serverTable.getSelectionModel().setSelectionInterval(i, i);
211 }
212 }
213 }
214
215 private void
216 installListeners() {
217 btnAdd.addActionListener(new ActionListener() {
218 public void
219 actionPerformed(ActionEvent e) { addServer(); }
220 });
221
222 btnRemove.addActionListener(new ActionListener() {
223 public void
224 actionPerformed(ActionEvent e) {
225 removeServer();
226 }
227 });
228
229 btnMoveUp.addActionListener(new ActionListener() {
230 public void
231 actionPerformed(ActionEvent e) {
232 serverTable.moveSelectedServerUp();
233 }
234 });
235
236 btnMoveDown.addActionListener(new ActionListener() {
237 public void
238 actionPerformed(ActionEvent e) {
239 serverTable.moveSelectedServerDown();
240 }
241 });
242
243 ServerSelectionHandler l = new ServerSelectionHandler();
244 serverTable.getSelectionModel().addListSelectionListener(l);
245 }
246
247 private void
248 addServer() {
249 int i = serverTable.getSelectedRow();
250
251 JSAddServerDlg dlg;
252 Window w = JuifeUtils.getWindow(this);
253 if(w instanceof Dialog) dlg = new JSAddServerDlg((Dialog)w);
254 else if(w instanceof Frame) dlg = new JSAddServerDlg((Frame)w);
255 else dlg = new JSAddServerDlg(CC.getMainFrame());
256
257 dlg.setVisible(true);
258 if(dlg.isCancelled()) return;
259
260 serverTable.getSelectionModel().setSelectionInterval(i, i);
261 }
262
263 private void
264 removeServer() {
265 if(CC.getServerList().getServerCount() < 2) {
266 Window w = JuifeUtils.getWindow(this);
267 String s = i18n.getError("JSConnectionPropsPane.cantRemove");
268 if(w instanceof Dialog) HF.showErrorMessage(s, (Dialog)w);
269 else if(w instanceof Frame) HF.showErrorMessage(s, (Frame)w);
270 return;
271 }
272
273 serverTable.removeSelectedServer();
274 }
275
276 private class ServerSelectionHandler implements ListSelectionListener {
277 @Override
278 public void
279 valueChanged(ListSelectionEvent e) {
280 if(e.getValueIsAdjusting()) return;
281
282 if(serverTable.getSelectedServer() == null) {
283 btnMoveUp.setEnabled(false);
284 btnMoveDown.setEnabled(false);
285 return;
286 }
287
288 int idx = serverTable.getSelectedRow();
289 btnMoveUp.setEnabled(idx != 0);
290 btnMoveDown.setEnabled(idx != serverTable.getRowCount() - 1);
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 }

  ViewVC Help
Powered by ViewVC