/[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 1688 - (show annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 7468 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

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.JOptionPane;
43 import javax.swing.JPanel;
44 import javax.swing.JScrollPane;
45 import javax.swing.JTextField;
46
47 import javax.swing.event.ListSelectionEvent;
48 import javax.swing.event.ListSelectionListener;
49
50 import net.sf.juife.JuifeUtils;
51
52 import org.jsampler.CC;
53 import org.jsampler.HF;
54 import org.jsampler.JSPrefs;
55 import org.jsampler.Prefs;
56
57 import org.jsampler.task.SetServerAddress;
58
59 import org.jsampler.view.ServerTable;
60 import org.jsampler.view.ServerTableModel;
61
62 import static org.jsampler.view.std.StdI18n.i18n;
63 import static org.jsampler.view.std.StdPrefs.*;
64
65
66 /**
67 *
68 * @author Grigor Iliev
69 */
70 public class JSConnectionPropsPane extends JPanel {
71 private final JCheckBox checkManualSelect =
72 new JCheckBox(i18n.getLabel("JSConnectionPropsPane.checkManualSelect"));
73
74 private final ServerListPane serverListPane;
75
76
77 /** Creates a new instance of <code>JSConnectionPropsPane</code> */
78 public
79 JSConnectionPropsPane() {
80 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
81
82 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
83 checkManualSelect.setSelected(b);
84
85 checkManualSelect.setAlignmentX(LEFT_ALIGNMENT);
86 add(checkManualSelect);
87 add(Box.createRigidArea(new Dimension(0, 6)));
88 serverListPane = createServerListPane();
89 add(serverListPane);
90 setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
91 }
92
93 private ServerListPane
94 createServerListPane() {
95 ServerListPane p = new ServerListPane();
96 p.setPreferredSize(new Dimension(200, 200));
97 p.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
98
99 String s = i18n.getLabel("JSConnectionPropsPane.title");
100 p.setBorder(BorderFactory.createTitledBorder(s));
101 p.setAlignmentX(LEFT_ALIGNMENT);
102
103 return p;
104 }
105
106 private static JSPrefs
107 preferences() { return CC.getViewConfig().preferences(); }
108
109 public void
110 apply() {
111 boolean b = checkManualSelect.isSelected();
112 preferences().setBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP, b);
113
114 int i = serverListPane.serverTable.getSelectedRow();
115 if(i != -1) preferences().setIntProperty(SERVER_INDEX, i);
116 }
117
118 public static class ServerListPane extends JPanel {
119 protected final ServerTable serverTable;
120
121 private final JButton btnAdd = new JButton(i18n.getButtonLabel("add"));
122 private final JButton btnRemove = new JButton(i18n.getButtonLabel("remove"));
123
124 private final JButton btnMoveUp =
125 new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveUp"));
126
127 private final JButton btnMoveDown =
128 new JButton(i18n.getButtonLabel("JSConnectionPropsPane.btnMoveDown"));
129
130 public
131 ServerListPane() {
132 setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
133
134 ServerTableModel model = new ServerTableModel(CC.getServerList());
135 serverTable = new ServerTable(model);
136
137 add(new JScrollPane(serverTable));
138
139 int h = btnAdd.getPreferredSize().height;
140 btnAdd.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
141
142 h = btnRemove.getPreferredSize().height;
143 btnRemove.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
144
145 h = btnMoveUp.getPreferredSize().height;
146 btnMoveUp.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
147
148 h = btnMoveDown.getPreferredSize().height;
149 btnMoveDown.setMaximumSize(new Dimension(Short.MAX_VALUE, h));
150
151 JPanel p = new JPanel();
152 p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
153 p.add(btnAdd);
154 p.add(Box.createRigidArea(new Dimension(0, 5)));
155 p.add(btnRemove);
156 p.add(Box.createRigidArea(new Dimension(0, 17)));
157 p.add(btnMoveUp);
158 p.add(Box.createRigidArea(new Dimension(0, 5)));
159 p.add(btnMoveDown);
160 p.add(Box.createGlue());
161
162 p.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
163
164 add(p);
165
166 installListeners();
167
168 int i = preferences().getIntProperty(JSPrefs.SERVER_INDEX);
169 int size = CC.getServerList().getServerCount();
170 if(size > 0) {
171 if(i < 0 || i >= size) {
172 serverTable.getSelectionModel().setSelectionInterval(0, 0);
173 } else {
174 serverTable.getSelectionModel().setSelectionInterval(i, i);
175 }
176 }
177 }
178
179 private void
180 installListeners() {
181 btnAdd.addActionListener(new ActionListener() {
182 public void
183 actionPerformed(ActionEvent e) { addServer(); }
184 });
185
186 btnRemove.addActionListener(new ActionListener() {
187 public void
188 actionPerformed(ActionEvent e) {
189 removeServer();
190 }
191 });
192
193 btnMoveUp.addActionListener(new ActionListener() {
194 public void
195 actionPerformed(ActionEvent e) {
196 serverTable.moveSelectedServerUp();
197 }
198 });
199
200 btnMoveDown.addActionListener(new ActionListener() {
201 public void
202 actionPerformed(ActionEvent e) {
203 serverTable.moveSelectedServerDown();
204 }
205 });
206
207 ServerSelectionHandler l = new ServerSelectionHandler();
208 serverTable.getSelectionModel().addListSelectionListener(l);
209 }
210
211 private void
212 addServer() {
213 int i = serverTable.getSelectedRow();
214
215 JSAddServerDlg dlg;
216 Window w = JuifeUtils.getWindow(this);
217 if(w instanceof Dialog) dlg = new JSAddServerDlg((Dialog)w);
218 else if(w instanceof Frame) dlg = new JSAddServerDlg((Frame)w);
219 else dlg = new JSAddServerDlg(CC.getMainFrame());
220
221 dlg.setVisible(true);
222 if(dlg.isCancelled()) return;
223
224 serverTable.getSelectionModel().setSelectionInterval(i, i);
225 }
226
227 private void
228 removeServer() {
229 if(CC.getServerList().getServerCount() < 2) {
230 Window w = JuifeUtils.getWindow(this);
231 String s = i18n.getError("JSConnectionPropsPane.cantRemove");
232 if(w instanceof Dialog) HF.showErrorMessage(s, (Dialog)w);
233 else if(w instanceof Frame) HF.showErrorMessage(s, (Frame)w);
234 return;
235 }
236
237 serverTable.removeSelectedServer();
238 }
239
240 private class ServerSelectionHandler implements ListSelectionListener {
241 public void
242 valueChanged(ListSelectionEvent e) {
243 if(e.getValueIsAdjusting()) return;
244
245 if(serverTable.getSelectedServer() == null) {
246 btnMoveUp.setEnabled(false);
247 btnMoveDown.setEnabled(false);
248 return;
249 }
250
251 int idx = serverTable.getSelectedRow();
252 btnMoveUp.setEnabled(idx != 0);
253 btnMoveDown.setEnabled(idx != serverTable.getRowCount() - 1);
254 }
255 }
256 }
257 }

  ViewVC Help
Powered by ViewVC