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.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.awt.Insets; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
|
33 |
import java.io.File; |
34 |
|
35 |
import javax.swing.BorderFactory; |
36 |
import javax.swing.Box; |
37 |
import javax.swing.BoxLayout; |
38 |
import javax.swing.JButton; |
39 |
import javax.swing.JFileChooser; |
40 |
import javax.swing.JLabel; |
41 |
import javax.swing.JPanel; |
42 |
import javax.swing.JSpinner; |
43 |
import javax.swing.JTextField; |
44 |
import javax.swing.SpinnerNumberModel; |
45 |
|
46 |
import org.jsampler.CC; |
47 |
import org.jsampler.JSPrefs; |
48 |
import org.jsampler.task.Global; |
49 |
|
50 |
import static org.jsampler.view.std.StdI18n.i18n; |
51 |
import static org.jsampler.view.std.StdPrefs.*; |
52 |
|
53 |
|
54 |
/** |
55 |
* |
56 |
* @author Grigor Iliev |
57 |
*/ |
58 |
public class JSGeneralProps { |
59 |
|
60 |
/** Forbids the instantiation of this class. */ |
61 |
private JSGeneralProps() { } |
62 |
|
63 |
private static JSPrefs |
64 |
preferences() { return CC.getViewConfig().preferences(); } |
65 |
|
66 |
|
67 |
public static class PolyphonyPane extends JPanel { |
68 |
private final JLabel lVoiceLimit = |
69 |
new JLabel(i18n.getLabel("JSGeneralProps.lVoiceLimit")); |
70 |
|
71 |
private final JLabel lStreamLimit = |
72 |
new JLabel(i18n.getLabel("JSGeneralProps.lStreamLimit")); |
73 |
|
74 |
private final JSpinner spVoiceLimit; |
75 |
private final JSpinner spStreamLimit; |
76 |
|
77 |
public |
78 |
PolyphonyPane() { |
79 |
int i = preferences().getIntProperty(GLOBAL_VOICE_LIMIT); |
80 |
spVoiceLimit = new JSpinner(new SpinnerNumberModel(i, 1, 32000, 1)); |
81 |
i = preferences().getIntProperty(GLOBAL_STREAM_LIMIT); |
82 |
spStreamLimit = new JSpinner(new SpinnerNumberModel(i, 10, 32000, 1)); |
83 |
|
84 |
GridBagLayout gridbag = new GridBagLayout(); |
85 |
GridBagConstraints c = new GridBagConstraints(); |
86 |
|
87 |
setLayout(gridbag); |
88 |
|
89 |
c.fill = GridBagConstraints.NONE; |
90 |
|
91 |
c.gridx = 0; |
92 |
c.gridy = 0; |
93 |
c.anchor = GridBagConstraints.EAST; |
94 |
c.insets = new Insets(3, 3, 3, 3); |
95 |
gridbag.setConstraints(lVoiceLimit, c); |
96 |
add(lVoiceLimit); |
97 |
|
98 |
c.gridx = 0; |
99 |
c.gridy = 1; |
100 |
gridbag.setConstraints(lStreamLimit, c); |
101 |
add(lStreamLimit); |
102 |
|
103 |
c.gridx = 1; |
104 |
c.gridy = 0; |
105 |
c.fill = GridBagConstraints.HORIZONTAL; |
106 |
c.anchor = GridBagConstraints.WEST; |
107 |
gridbag.setConstraints(spVoiceLimit, c); |
108 |
add(spVoiceLimit); |
109 |
|
110 |
c.gridx = 1; |
111 |
c.gridy = 1; |
112 |
gridbag.setConstraints(spStreamLimit, c); |
113 |
add(spStreamLimit); |
114 |
|
115 |
c.gridx = 2; |
116 |
c.gridy = 0; |
117 |
c.gridheight = 2; |
118 |
c.weightx = 1.0; |
119 |
JPanel p = new JPanel(); |
120 |
p.setOpaque(false); |
121 |
gridbag.setConstraints(p, c); |
122 |
add(p); |
123 |
|
124 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
125 |
setOpaque(false); |
126 |
|
127 |
String s = i18n.getLabel("JSGeneralProps.PolyphonyPane"); |
128 |
setBorder(BorderFactory.createTitledBorder(s)); |
129 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
130 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
131 |
} |
132 |
|
133 |
public void |
134 |
apply() { |
135 |
int v = Integer.parseInt(spVoiceLimit.getValue().toString()); |
136 |
preferences().setIntProperty(GLOBAL_VOICE_LIMIT, v); |
137 |
|
138 |
int s = Integer.parseInt(spStreamLimit.getValue().toString()); |
139 |
preferences().setIntProperty(GLOBAL_STREAM_LIMIT, s); |
140 |
|
141 |
CC.getTaskQueue().add(new Global.SetPolyphony(v, s)); |
142 |
} |
143 |
} |
144 |
|
145 |
|
146 |
public static class MaxVolumePane extends JPanel { |
147 |
private final JLabel lMaxMasterVol = |
148 |
new JLabel(i18n.getLabel("JSGeneralProps.lMaxMasterVol")); |
149 |
|
150 |
private final JLabel lMaxChannelVol = |
151 |
new JLabel(i18n.getLabel("JSGeneralProps.lMaxChannelVol")); |
152 |
|
153 |
private final JSpinner spMaxMasterVol; |
154 |
private final JSpinner spMaxChannelVol; |
155 |
|
156 |
public |
157 |
MaxVolumePane() { |
158 |
int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME); |
159 |
spMaxMasterVol = new JSpinner(new SpinnerNumberModel(i, 10, 1000, 10)); |
160 |
i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
161 |
spMaxChannelVol = new JSpinner(new SpinnerNumberModel(i, 10, 1000, 10)); |
162 |
|
163 |
GridBagLayout gridbag = new GridBagLayout(); |
164 |
GridBagConstraints c = new GridBagConstraints(); |
165 |
|
166 |
setLayout(gridbag); |
167 |
|
168 |
c.fill = GridBagConstraints.NONE; |
169 |
|
170 |
c.gridx = 0; |
171 |
c.gridy = 0; |
172 |
c.anchor = GridBagConstraints.EAST; |
173 |
c.insets = new Insets(3, 3, 3, 3); |
174 |
gridbag.setConstraints(lMaxMasterVol, c); |
175 |
add(lMaxMasterVol); |
176 |
|
177 |
c.gridx = 0; |
178 |
c.gridy = 1; |
179 |
gridbag.setConstraints(lMaxChannelVol, c); |
180 |
add(lMaxChannelVol); |
181 |
|
182 |
c.gridx = 1; |
183 |
c.gridy = 0; |
184 |
c.fill = GridBagConstraints.HORIZONTAL; |
185 |
c.anchor = GridBagConstraints.WEST; |
186 |
gridbag.setConstraints(spMaxMasterVol, c); |
187 |
add(spMaxMasterVol); |
188 |
|
189 |
c.gridx = 1; |
190 |
c.gridy = 1; |
191 |
gridbag.setConstraints(spMaxChannelVol, c); |
192 |
add(spMaxChannelVol); |
193 |
|
194 |
c.gridx = 2; |
195 |
c.gridy = 0; |
196 |
c.gridheight = 2; |
197 |
c.weightx = 1.0; |
198 |
JPanel p = new JPanel(); |
199 |
p.setOpaque(false); |
200 |
gridbag.setConstraints(p, c); |
201 |
add(p); |
202 |
|
203 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
204 |
setOpaque(false); |
205 |
} |
206 |
|
207 |
public void |
208 |
apply() { |
209 |
int i = Integer.parseInt(spMaxMasterVol.getValue().toString()); |
210 |
preferences().setIntProperty(MAXIMUM_MASTER_VOLUME, i); |
211 |
|
212 |
i = Integer.parseInt(spMaxChannelVol.getValue().toString()); |
213 |
preferences().setIntProperty(MAXIMUM_CHANNEL_VOLUME, i); |
214 |
} |
215 |
} |
216 |
|
217 |
public static class JSamplerHomePane extends JPanel { |
218 |
private final JTextField tfJSamplerHome = new JTextField(); |
219 |
private final JButton btnChange = |
220 |
new JButton(i18n.getButtonLabel("JSGeneralProps.btnChange")); |
221 |
|
222 |
public |
223 |
JSamplerHomePane() { |
224 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
225 |
|
226 |
JPanel p = new JPanel(); |
227 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
228 |
|
229 |
if(CC.getJSamplerHome() != null) { |
230 |
tfJSamplerHome.setText(CC.getJSamplerHome()); |
231 |
} |
232 |
|
233 |
Dimension d; |
234 |
d = new Dimension(Short.MAX_VALUE, tfJSamplerHome.getPreferredSize().height); |
235 |
tfJSamplerHome.setMaximumSize(d); |
236 |
p.add(tfJSamplerHome); |
237 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
238 |
p.add(btnChange); |
239 |
p.setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6)); |
240 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
241 |
add(p); |
242 |
|
243 |
String s = i18n.getLabel("JSGeneralProps.jSamplerHome"); |
244 |
setBorder(BorderFactory.createTitledBorder(s)); |
245 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
246 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
247 |
|
248 |
btnChange.addActionListener(new ActionListener() { |
249 |
public void |
250 |
actionPerformed(ActionEvent e) { onChange(); } |
251 |
}); |
252 |
} |
253 |
|
254 |
private void |
255 |
onChange() { |
256 |
JFileChooser fc = new JFileChooser(); |
257 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
258 |
int result = fc.showOpenDialog(this); |
259 |
if(result != JFileChooser.APPROVE_OPTION) return; |
260 |
|
261 |
String s = CC.getJSamplerHome(); |
262 |
String suf = File.separator + ".jsampler"; |
263 |
if(s != null) suf = File.separator + new File(s).getName(); |
264 |
|
265 |
tfJSamplerHome.setText(fc.getSelectedFile().getPath() + suf); |
266 |
} |
267 |
|
268 |
/** |
269 |
* Gets the selected JSampler's home directory. |
270 |
*/ |
271 |
public String |
272 |
getJSamplerHome() { return tfJSamplerHome.getText(); } |
273 |
} |
274 |
|
275 |
|
276 |
public static class RecentScriptsPane extends JPanel { |
277 |
private final JLabel lRecentScriptsSize = |
278 |
new JLabel(i18n.getLabel("JSGeneralProps.lRecentScriptsSize")); |
279 |
|
280 |
private final JSpinner spRecentScriptsSize; |
281 |
|
282 |
private final JButton btnClearRecentScriptList = |
283 |
new JButton(i18n.getButtonLabel("JSGeneralProps.btnClearRecentScriptList")); |
284 |
|
285 |
public |
286 |
RecentScriptsPane() { |
287 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
288 |
|
289 |
int i = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
290 |
spRecentScriptsSize = new JSpinner(new SpinnerNumberModel(i, 0, 100, 1)); |
291 |
spRecentScriptsSize.setMaximumSize(spRecentScriptsSize.getPreferredSize()); |
292 |
|
293 |
JPanel p = new JPanel(); |
294 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
295 |
p.add(lRecentScriptsSize); |
296 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
297 |
p.add(spRecentScriptsSize); |
298 |
|
299 |
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
300 |
add(p); |
301 |
|
302 |
add(Box.createRigidArea(new Dimension(0, 6))); |
303 |
|
304 |
btnClearRecentScriptList.addActionListener(new ActionListener() { |
305 |
public void |
306 |
actionPerformed(ActionEvent e) { |
307 |
preferences().setStringProperty(RECENT_LSCP_SCRIPTS, null); |
308 |
clearRecentScripts(); |
309 |
} |
310 |
}); |
311 |
|
312 |
btnClearRecentScriptList.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
313 |
add(btnClearRecentScriptList); |
314 |
add(Box.createRigidArea(new Dimension(0, 6))); |
315 |
|
316 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
317 |
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
318 |
String s = i18n.getLabel("JSGeneralProps.recentScripts"); |
319 |
setBorder(BorderFactory.createTitledBorder(s)); |
320 |
} |
321 |
|
322 |
/** |
323 |
* Override this method to clear the recent scripts. |
324 |
*/ |
325 |
protected void |
326 |
clearRecentScripts() { } |
327 |
|
328 |
public int |
329 |
getRecentScriptsSize() { |
330 |
return Integer.parseInt(spRecentScriptsSize.getValue().toString()); |
331 |
} |
332 |
} |
333 |
} |