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