1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005-2007 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 |
iliev |
1357 |
import java.awt.GridBagConstraints; |
27 |
|
|
import java.awt.GridBagLayout; |
28 |
|
|
import java.awt.Insets; |
29 |
iliev |
1286 |
|
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 |
|
|
|
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 |
iliev |
1357 |
/** Forbids the instantiation of this class. */ |
60 |
iliev |
1286 |
private JSGeneralProps() { } |
61 |
|
|
|
62 |
|
|
private static JSPrefs |
63 |
|
|
preferences() { return CC.getViewConfig().preferences(); } |
64 |
|
|
|
65 |
|
|
|
66 |
iliev |
1357 |
public static class MaxVolumePane extends JPanel { |
67 |
|
|
private final JLabel lMaxMasterVol = |
68 |
|
|
new JLabel(i18n.getLabel("JSGeneralProps.lMaxMasterVol")); |
69 |
|
|
|
70 |
|
|
private final JLabel lMaxChannelVol = |
71 |
|
|
new JLabel(i18n.getLabel("JSGeneralProps.lMaxChannelVol")); |
72 |
|
|
|
73 |
|
|
private final JSpinner spMaxMasterVol; |
74 |
|
|
private final JSpinner spMaxChannelVol; |
75 |
|
|
|
76 |
|
|
public |
77 |
|
|
MaxVolumePane() { |
78 |
|
|
int i = preferences().getIntProperty(MAXIMUM_MASTER_VOLUME); |
79 |
|
|
spMaxMasterVol = new JSpinner(new SpinnerNumberModel(i, 10, 1000, 10)); |
80 |
|
|
i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
81 |
|
|
spMaxChannelVol = new JSpinner(new SpinnerNumberModel(i, 10, 1000, 10)); |
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(lMaxMasterVol, c); |
95 |
|
|
add(lMaxMasterVol); |
96 |
|
|
|
97 |
|
|
c.gridx = 0; |
98 |
|
|
c.gridy = 1; |
99 |
|
|
gridbag.setConstraints(lMaxChannelVol, c); |
100 |
|
|
add(lMaxChannelVol); |
101 |
|
|
|
102 |
|
|
c.gridx = 1; |
103 |
|
|
c.gridy = 0; |
104 |
|
|
c.fill = GridBagConstraints.HORIZONTAL; |
105 |
|
|
c.anchor = GridBagConstraints.WEST; |
106 |
|
|
gridbag.setConstraints(spMaxMasterVol, c); |
107 |
|
|
add(spMaxMasterVol); |
108 |
|
|
|
109 |
|
|
c.gridx = 1; |
110 |
|
|
c.gridy = 1; |
111 |
|
|
gridbag.setConstraints(spMaxChannelVol, c); |
112 |
|
|
add(spMaxChannelVol); |
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 |
|
|
|
127 |
|
|
public void |
128 |
|
|
apply() { |
129 |
|
|
int i = Integer.parseInt(spMaxMasterVol.getValue().toString()); |
130 |
|
|
preferences().setIntProperty(MAXIMUM_MASTER_VOLUME, i); |
131 |
|
|
|
132 |
|
|
i = Integer.parseInt(spMaxChannelVol.getValue().toString()); |
133 |
|
|
preferences().setIntProperty(MAXIMUM_CHANNEL_VOLUME, i); |
134 |
|
|
} |
135 |
|
|
} |
136 |
|
|
|
137 |
iliev |
1286 |
public static class JSamplerHomePane extends JPanel { |
138 |
|
|
private final JTextField tfJSamplerHome = new JTextField(); |
139 |
|
|
private final JButton btnChange = |
140 |
|
|
new JButton(i18n.getButtonLabel("JSGeneralProps.btnChange")); |
141 |
|
|
|
142 |
|
|
public |
143 |
|
|
JSamplerHomePane() { |
144 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
145 |
|
|
|
146 |
|
|
JPanel p = new JPanel(); |
147 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
148 |
|
|
|
149 |
|
|
if(CC.getJSamplerHome() != null) { |
150 |
|
|
tfJSamplerHome.setText(CC.getJSamplerHome()); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
Dimension d; |
154 |
|
|
d = new Dimension(Short.MAX_VALUE, tfJSamplerHome.getPreferredSize().height); |
155 |
|
|
tfJSamplerHome.setMaximumSize(d); |
156 |
|
|
p.add(tfJSamplerHome); |
157 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
158 |
|
|
p.add(btnChange); |
159 |
|
|
p.setBorder(BorderFactory.createEmptyBorder(2, 6, 6, 6)); |
160 |
|
|
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
161 |
|
|
add(p); |
162 |
|
|
|
163 |
|
|
String s = i18n.getLabel("JSGeneralProps.jSamplerHome"); |
164 |
|
|
setBorder(BorderFactory.createTitledBorder(s)); |
165 |
|
|
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
166 |
|
|
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
167 |
|
|
|
168 |
|
|
btnChange.addActionListener(new ActionListener() { |
169 |
|
|
public void |
170 |
|
|
actionPerformed(ActionEvent e) { onChange(); } |
171 |
|
|
}); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
private void |
175 |
|
|
onChange() { |
176 |
|
|
JFileChooser fc = new JFileChooser(); |
177 |
|
|
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
178 |
|
|
int result = fc.showOpenDialog(this); |
179 |
|
|
if(result != JFileChooser.APPROVE_OPTION) return; |
180 |
|
|
|
181 |
|
|
String s = CC.getJSamplerHome(); |
182 |
|
|
String suf = File.separator + ".jsampler"; |
183 |
|
|
if(s != null) suf = File.separator + new File(s).getName(); |
184 |
|
|
|
185 |
|
|
tfJSamplerHome.setText(fc.getSelectedFile().getPath() + suf); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
/** |
189 |
|
|
* Gets the selected JSampler's home directory. |
190 |
|
|
*/ |
191 |
|
|
public String |
192 |
|
|
getJSamplerHome() { return tfJSamplerHome.getText(); } |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
|
196 |
|
|
public static class RecentScriptsPane extends JPanel { |
197 |
|
|
private final JLabel lRecentScriptsSize = |
198 |
|
|
new JLabel(i18n.getLabel("JSGeneralProps.lRecentScriptsSize")); |
199 |
|
|
|
200 |
|
|
private final JSpinner spRecentScriptsSize; |
201 |
|
|
|
202 |
|
|
private final JButton btnClearRecentScriptList = |
203 |
|
|
new JButton(i18n.getButtonLabel("JSGeneralProps.btnClearRecentScriptList")); |
204 |
|
|
|
205 |
|
|
public |
206 |
|
|
RecentScriptsPane() { |
207 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
208 |
|
|
|
209 |
|
|
int i = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
210 |
|
|
spRecentScriptsSize = new JSpinner(new SpinnerNumberModel(i, 0, 100, 1)); |
211 |
|
|
spRecentScriptsSize.setMaximumSize(spRecentScriptsSize.getPreferredSize()); |
212 |
|
|
|
213 |
|
|
JPanel p = new JPanel(); |
214 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
215 |
|
|
p.add(lRecentScriptsSize); |
216 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
217 |
|
|
p.add(spRecentScriptsSize); |
218 |
|
|
|
219 |
|
|
p.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
220 |
|
|
add(p); |
221 |
|
|
|
222 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
223 |
|
|
|
224 |
|
|
btnClearRecentScriptList.addActionListener(new ActionListener() { |
225 |
|
|
public void |
226 |
|
|
actionPerformed(ActionEvent e) { |
227 |
|
|
preferences().setStringProperty(RECENT_LSCP_SCRIPTS, null); |
228 |
|
|
clearRecentScripts(); |
229 |
|
|
} |
230 |
|
|
}); |
231 |
|
|
|
232 |
|
|
btnClearRecentScriptList.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
233 |
|
|
add(btnClearRecentScriptList); |
234 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
235 |
|
|
|
236 |
|
|
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
237 |
|
|
setAlignmentX(JPanel.LEFT_ALIGNMENT); |
238 |
|
|
String s = i18n.getLabel("JSGeneralProps.recentScripts"); |
239 |
|
|
setBorder(BorderFactory.createTitledBorder(s)); |
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
/** |
243 |
|
|
* Override this method to clear the recent scripts. |
244 |
|
|
*/ |
245 |
|
|
protected void |
246 |
|
|
clearRecentScripts() { } |
247 |
|
|
|
248 |
|
|
public int |
249 |
|
|
getRecentScriptsSize() { |
250 |
|
|
return Integer.parseInt(spRecentScriptsSize.getValue().toString()); |
251 |
|
|
} |
252 |
|
|
} |
253 |
|
|
} |