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.fantasia; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Color; |
27 |
import java.awt.Dialog; |
28 |
import java.awt.Dimension; |
29 |
import java.awt.Frame; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.Box; |
36 |
import javax.swing.BoxLayout; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JPanel; |
41 |
import javax.swing.JSpinner; |
42 |
import javax.swing.JTabbedPane; |
43 |
import javax.swing.SpinnerNumberModel; |
44 |
|
45 |
import net.sf.juife.EnhancedDialog; |
46 |
import net.sf.juife.JuifeUtils; |
47 |
|
48 |
import org.jsampler.CC; |
49 |
import org.jsampler.JSUtils; |
50 |
import org.jsampler.LSConsoleModel; |
51 |
|
52 |
import org.jsampler.view.std.JSAdvancedGeneralPropsDlg; |
53 |
import org.jsampler.view.std.JSConnectionPropsPane; |
54 |
import org.jsampler.view.std.JSDefaultsPropsPane; |
55 |
import org.jsampler.view.std.JSGeneralProps; |
56 |
import org.jsampler.view.std.JSLSConsolePropsPane; |
57 |
import org.jsampler.view.std.JSViewProps; |
58 |
|
59 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
60 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
61 |
|
62 |
|
63 |
/** |
64 |
* |
65 |
* @author Grigor Iliev |
66 |
*/ |
67 |
public class PrefsDlg extends EnhancedDialog { |
68 |
private final JTabbedPane tabbedPane = new JTabbedPane(); |
69 |
|
70 |
private final GeneralPane genPane = new GeneralPane(this); |
71 |
private final ViewPane viewPane = new ViewPane(); |
72 |
private final ChannelsPropsPane channelsPane = new ChannelsPropsPane(); |
73 |
private final ConsolePane consolePane = new ConsolePane(); |
74 |
private final JSConnectionPropsPane connectionPane = new JSConnectionPropsPane(); |
75 |
private final JSDefaultsPropsPane defaultsPane; |
76 |
|
77 |
private final JButton btnApply = new JButton(i18n.getButtonLabel("apply")); |
78 |
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
79 |
|
80 |
|
81 |
/** Creates a new instance of <code>PrefsDlg</code> */ |
82 |
public |
83 |
PrefsDlg(Frame owner) { |
84 |
super(owner, i18n.getLabel("PrefsDlg.title"), true); |
85 |
|
86 |
defaultsPane = new JSDefaultsPropsPane(this, Res.iconEdit16, true); |
87 |
|
88 |
JTabbedPane tp = tabbedPane; |
89 |
tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); |
90 |
|
91 |
tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane); |
92 |
tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane); |
93 |
tp.addTab(i18n.getLabel("PrefsDlg.tabChannels"), channelsPane); |
94 |
tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane); |
95 |
|
96 |
JPanel p = new JPanel(); |
97 |
p.setLayout(new BorderLayout()); |
98 |
p.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
99 |
p.add(connectionPane); |
100 |
tp.addTab(i18n.getLabel("PrefsDlg.tabBackend"), p); |
101 |
tp.addTab(i18n.getLabel("PrefsDlg.tabDefaults"), defaultsPane); |
102 |
|
103 |
tp.setAlignmentX(RIGHT_ALIGNMENT); |
104 |
|
105 |
// Set preferred size for Apply & Exit buttons |
106 |
Dimension d = JuifeUtils.getUnionSize(btnApply, btnClose); |
107 |
btnApply.setPreferredSize(d); |
108 |
btnClose.setPreferredSize(d); |
109 |
|
110 |
JPanel btnPane = new JPanel(); |
111 |
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
112 |
btnPane.add(btnApply); |
113 |
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
114 |
btnPane.add(btnClose); |
115 |
btnPane.setAlignmentX(RIGHT_ALIGNMENT); |
116 |
|
117 |
JPanel mainPane = new JPanel(); |
118 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
119 |
mainPane.add(tp); |
120 |
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
121 |
mainPane.add(btnPane); |
122 |
mainPane.setBorder(BorderFactory.createEmptyBorder(11, 12, 12, 12)); |
123 |
|
124 |
getContentPane().add(mainPane); |
125 |
|
126 |
pack(); |
127 |
setResizable(false); |
128 |
setLocation(JuifeUtils.centerLocation(this, owner)); |
129 |
|
130 |
installListeners(); |
131 |
|
132 |
int i = preferences().getIntProperty("PrefsDlg.tabIndex"); |
133 |
|
134 |
if(i >= 0 && i < tp.getTabCount()) tp.setSelectedIndex(i); |
135 |
} |
136 |
|
137 |
private void |
138 |
installListeners() { |
139 |
btnApply.addActionListener(new ActionListener() { |
140 |
public void |
141 |
actionPerformed(ActionEvent e) { onApply(); } |
142 |
}); |
143 |
|
144 |
btnClose.addActionListener(new ActionListener() { |
145 |
public void |
146 |
actionPerformed(ActionEvent e) { onExit(); } |
147 |
}); |
148 |
} |
149 |
|
150 |
protected void |
151 |
onOk() { onApply(); } |
152 |
|
153 |
protected void |
154 |
onCancel() { onExit(); } |
155 |
|
156 |
private void |
157 |
onApply() { |
158 |
genPane.apply(); |
159 |
viewPane.apply(); |
160 |
channelsPane.apply(); |
161 |
consolePane.apply(); |
162 |
connectionPane.apply(); |
163 |
defaultsPane.apply(); |
164 |
|
165 |
preferences().setIntProperty("PrefsDlg.tabIndex", tabbedPane.getSelectedIndex()); |
166 |
|
167 |
setVisible(false); |
168 |
} |
169 |
|
170 |
private void |
171 |
onExit() { setVisible(false); } |
172 |
} |
173 |
|
174 |
class GeneralPane extends JPanel { |
175 |
private final JCheckBox checkShowLSConsoleWhenRunScript = |
176 |
new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript")); |
177 |
|
178 |
private final JCheckBox checkShowVolumesInDecibels = |
179 |
new JCheckBox(i18n.getLabel("GeneralPane.checkShowVolumesInDecibels")); |
180 |
|
181 |
private final JSGeneralProps.PolyphonyPane polyphonyPane = new JSGeneralProps.PolyphonyPane(); |
182 |
|
183 |
private final JSGeneralProps.JSamplerHomePane jSamplerHomePane = |
184 |
new JSGeneralProps.JSamplerHomePane(); |
185 |
|
186 |
private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane(); |
187 |
|
188 |
private final JButton btnAdvanced = new JButton(i18n.getButtonLabel("GeneralPane.btnAdvanced")); |
189 |
|
190 |
private final Dialog owner; |
191 |
|
192 |
public |
193 |
GeneralPane(Dialog owner) { |
194 |
this.owner = owner; |
195 |
|
196 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
197 |
|
198 |
checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
199 |
|
200 |
boolean b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT); |
201 |
checkShowLSConsoleWhenRunScript.setSelected(b); |
202 |
|
203 |
add(checkShowLSConsoleWhenRunScript); |
204 |
|
205 |
add(Box.createRigidArea(new Dimension(0, 6))); |
206 |
|
207 |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
208 |
checkShowVolumesInDecibels.setSelected(b); |
209 |
|
210 |
add(checkShowVolumesInDecibels); |
211 |
|
212 |
add(Box.createRigidArea(new Dimension(0, 6))); |
213 |
|
214 |
add(polyphonyPane); |
215 |
|
216 |
add(Box.createRigidArea(new Dimension(0, 6))); |
217 |
|
218 |
add(jSamplerHomePane); |
219 |
|
220 |
add(Box.createRigidArea(new Dimension(0, 6))); |
221 |
|
222 |
add(recentScriptsPane); |
223 |
|
224 |
add(Box.createRigidArea(new Dimension(0, 6))); |
225 |
|
226 |
JPanel p = new JPanel(); |
227 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
228 |
|
229 |
JPanel p2 = new JPanel(); |
230 |
p2.setLayout(new BorderLayout()); |
231 |
p.add(p2); |
232 |
p.add(btnAdvanced); |
233 |
p.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
234 |
add(p); |
235 |
|
236 |
add(Box.createGlue()); |
237 |
|
238 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
239 |
|
240 |
btnAdvanced.addActionListener(new ActionListener() { |
241 |
public void |
242 |
actionPerformed(ActionEvent e) { showAdvancedProperties(); } |
243 |
}); |
244 |
} |
245 |
|
246 |
private void |
247 |
showAdvancedProperties() { |
248 |
new JSAdvancedGeneralPropsDlg(owner).setVisible(true); |
249 |
} |
250 |
|
251 |
protected void |
252 |
apply() { |
253 |
polyphonyPane.apply(); |
254 |
|
255 |
boolean b = checkShowLSConsoleWhenRunScript.isSelected(); |
256 |
preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b); |
257 |
|
258 |
b = checkShowVolumesInDecibels.isSelected(); |
259 |
preferences().setBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL, b); |
260 |
|
261 |
int size = recentScriptsPane.getRecentScriptsSize(); |
262 |
preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size); |
263 |
((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu(); |
264 |
|
265 |
String s = jSamplerHomePane.getJSamplerHome(); |
266 |
if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) { |
267 |
JSUtils.changeJSamplerHome(s); |
268 |
} |
269 |
} |
270 |
|
271 |
private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane { |
272 |
protected void |
273 |
clearRecentScripts() { |
274 |
((MainFrame)CC.getMainFrame()).clearRecentScripts(); |
275 |
} |
276 |
} |
277 |
} |
278 |
|
279 |
class ViewPane extends JPanel { |
280 |
private final JCheckBox checkTurnOffAnimationEffects = |
281 |
new JCheckBox(i18n.getLabel("GeneralPane.checkTurnOffAnimationEffects")); |
282 |
|
283 |
private final JCheckBox checkTurnOffCustomWindowDecoration = |
284 |
new JCheckBox(i18n.getLabel("ViewPane.checkTurnOffCustomWindowDecoration")); |
285 |
|
286 |
private final JCheckBox checkShowInstrumentsDb = |
287 |
new JCheckBox(i18n.getLabel("ViewPane.checkShowInstrumentsDb")); |
288 |
|
289 |
private final JCheckBox checkUseNativeFileChoosers = |
290 |
new JCheckBox(i18n.getLabel("ViewPane.checkUseNativeFileChoosers")); |
291 |
|
292 |
private final JSViewProps.MidiDevicesPane midiDevsPane = new JSViewProps.MidiDevicesPane(); |
293 |
private final JSViewProps.AudioDevicesPane audioDevsPane = new JSViewProps.AudioDevicesPane(); |
294 |
|
295 |
private final JSViewProps.ConfirmationMessagesPane confirmationMessagesPane = |
296 |
new JSViewProps.ConfirmationMessagesPane(); |
297 |
|
298 |
ViewPane() { |
299 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
300 |
|
301 |
checkTurnOffAnimationEffects.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
302 |
|
303 |
boolean b = !preferences().getBoolProperty(ANIMATED); |
304 |
checkTurnOffAnimationEffects.setSelected(b); |
305 |
|
306 |
add(checkTurnOffAnimationEffects); |
307 |
|
308 |
add(Box.createRigidArea(new Dimension(0, 6))); |
309 |
|
310 |
b = preferences().getBoolProperty("TurnOffCustomWindowDecoration"); |
311 |
checkTurnOffCustomWindowDecoration.setSelected(b); |
312 |
checkTurnOffCustomWindowDecoration.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
313 |
add(checkTurnOffCustomWindowDecoration); |
314 |
add(Box.createRigidArea(new Dimension(0, 6))); |
315 |
|
316 |
b = preferences().getBoolProperty("rightSidePane.showInstrumentsDb"); |
317 |
checkShowInstrumentsDb.setSelected(b); |
318 |
checkShowInstrumentsDb.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
319 |
add(checkShowInstrumentsDb); |
320 |
add(Box.createRigidArea(new Dimension(0, 6))); |
321 |
|
322 |
b = preferences().getBoolProperty("nativeFileChoosers"); |
323 |
checkUseNativeFileChoosers.setSelected(b); |
324 |
checkUseNativeFileChoosers.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
325 |
add(checkUseNativeFileChoosers); |
326 |
add(Box.createRigidArea(new Dimension(0, 6))); |
327 |
|
328 |
add(midiDevsPane); |
329 |
add(audioDevsPane); |
330 |
add(confirmationMessagesPane); |
331 |
} |
332 |
|
333 |
protected void |
334 |
apply() { |
335 |
boolean b = !checkTurnOffAnimationEffects.isSelected(); |
336 |
preferences().setBoolProperty(ANIMATED, b); |
337 |
|
338 |
String s = "TurnOffCustomWindowDecoration"; |
339 |
preferences().setBoolProperty(s, checkTurnOffCustomWindowDecoration.isSelected()); |
340 |
|
341 |
s = "rightSidePane.showInstrumentsDb"; |
342 |
preferences().setBoolProperty(s, checkShowInstrumentsDb.isSelected()); |
343 |
|
344 |
s = "nativeFileChoosers"; |
345 |
preferences().setBoolProperty(s, checkUseNativeFileChoosers.isSelected()); |
346 |
|
347 |
midiDevsPane.apply(); |
348 |
audioDevsPane.apply(); |
349 |
confirmationMessagesPane.apply(); |
350 |
} |
351 |
} |
352 |
|
353 |
class ChannelsPropsPane extends JPanel { |
354 |
private final JCheckBox checkShowChannelNumbering = |
355 |
new JCheckBox(i18n.getLabel("ChannelsPropsPane.checkShowChannelNumbering")); |
356 |
|
357 |
private final JCheckBox checkShowMidiInfo = |
358 |
new JCheckBox(i18n.getLabel("ChannelsPropsPane.checkShowMidiInfo")); |
359 |
|
360 |
private final JCheckBox checkShowStreamVoiceCount = |
361 |
new JCheckBox(i18n.getLabel("ChannelsPropsPane.checkShowStreamVoiceCount")); |
362 |
|
363 |
private final JLabel lChannelLaneNumber = |
364 |
new JLabel(i18n.getLabel("ChannelsPropsPane.lChannelLaneNumber")); |
365 |
|
366 |
private JSpinner spChannelLaneNumber; |
367 |
|
368 |
ChannelsPropsPane() { |
369 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
370 |
|
371 |
add(createChannelLanesPane()); |
372 |
add(createSmallViewPane()); |
373 |
|
374 |
JPanel p = new JPanel(); |
375 |
p.setLayout(new BorderLayout()); |
376 |
add(p); |
377 |
} |
378 |
|
379 |
protected void |
380 |
apply() { |
381 |
boolean b = checkShowChannelNumbering.isSelected(); |
382 |
preferences().setBoolProperty("channel.smallView.showChannelNumbering", b); |
383 |
|
384 |
b = checkShowMidiInfo.isSelected(); |
385 |
preferences().setBoolProperty("channel.smallView.showMidiInfo", b); |
386 |
|
387 |
b = checkShowStreamVoiceCount.isSelected(); |
388 |
preferences().setBoolProperty("channel.smallView.showStreamVoiceCount", b); |
389 |
|
390 |
int i = Integer.parseInt(spChannelLaneNumber.getValue().toString()); |
391 |
preferences().setIntProperty("channelLanes.count", i); |
392 |
} |
393 |
|
394 |
private JPanel |
395 |
createSmallViewPane() { |
396 |
JPanel p = new JPanel(); |
397 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
398 |
|
399 |
boolean b = preferences().getBoolProperty("channel.smallView.showChannelNumbering"); |
400 |
checkShowChannelNumbering.setSelected(b); |
401 |
checkShowChannelNumbering.setAlignmentX(LEFT_ALIGNMENT); |
402 |
p.add(checkShowChannelNumbering); |
403 |
|
404 |
b = preferences().getBoolProperty("channel.smallView.showMidiInfo"); |
405 |
checkShowMidiInfo.setSelected(b); |
406 |
checkShowMidiInfo.setAlignmentX(LEFT_ALIGNMENT); |
407 |
p.add(checkShowMidiInfo); |
408 |
|
409 |
b = preferences().getBoolProperty("channel.smallView.showStreamVoiceCount"); |
410 |
checkShowStreamVoiceCount.setSelected(b); |
411 |
checkShowStreamVoiceCount.setAlignmentX(LEFT_ALIGNMENT); |
412 |
p.add(checkShowStreamVoiceCount); |
413 |
|
414 |
String s = i18n.getLabel("ChannelsPropsPane.smallView"); |
415 |
p.setBorder(BorderFactory.createTitledBorder(s)); |
416 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height)); |
417 |
|
418 |
return p; |
419 |
} |
420 |
|
421 |
private JPanel |
422 |
createChannelLanesPane() { |
423 |
int max = MainFrame.MAX_CHANNEL_LANE_NUMBER; |
424 |
|
425 |
int i = preferences().getIntProperty("channelLanes.count"); |
426 |
if(i < 1 || i > max) i = max; |
427 |
spChannelLaneNumber = new JSpinner(new SpinnerNumberModel(i, 1, max, 1)); |
428 |
|
429 |
JPanel p = new JPanel(); |
430 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
431 |
p.add(lChannelLaneNumber); |
432 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
433 |
p.add(spChannelLaneNumber); |
434 |
p.setAlignmentX(LEFT_ALIGNMENT); |
435 |
p.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0)); |
436 |
|
437 |
JPanel p2 = new JPanel(); |
438 |
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS)); |
439 |
String s = i18n.getLabel("ChannelsPropsPane.channelLanes"); |
440 |
p2.setBorder(BorderFactory.createTitledBorder(s)); |
441 |
p2.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height)); |
442 |
p2.add(p); |
443 |
p2.setAlignmentX(LEFT_ALIGNMENT); |
444 |
|
445 |
return p2; |
446 |
} |
447 |
} |
448 |
|
449 |
class ConsolePane extends JSLSConsolePropsPane { |
450 |
protected void |
451 |
clearConsoleHistory() { |
452 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
453 |
mainFrame.getLSConsoleModel().clearCommandHistory(); |
454 |
} |
455 |
|
456 |
protected void |
457 |
apply() { |
458 |
super.apply(); |
459 |
|
460 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
461 |
|
462 |
LSConsoleModel model = mainFrame.getLSConsoleModel(); |
463 |
model.setCommandHistorySize(preferences().getIntProperty(LS_CONSOLE_HISTSIZE)); |
464 |
|
465 |
LSConsolePane console = mainFrame.getLSConsolePane(); |
466 |
|
467 |
int c = preferences().getIntProperty(LS_CONSOLE_TEXT_COLOR); |
468 |
console.setTextColor(new Color(c)); |
469 |
|
470 |
c = preferences().getIntProperty(LS_CONSOLE_BACKGROUND_COLOR); |
471 |
console.setBackgroundColor(new Color(c)); |
472 |
|
473 |
c = preferences().getIntProperty(LS_CONSOLE_NOTIFY_COLOR); |
474 |
console.setNotifyColor(new Color(c)); |
475 |
|
476 |
c = preferences().getIntProperty(LS_CONSOLE_WARNING_COLOR); |
477 |
console.setWarningColor(new Color(c)); |
478 |
|
479 |
c = preferences().getIntProperty(LS_CONSOLE_ERROR_COLOR); |
480 |
console.setErrorColor(new Color(c)); |
481 |
} |
482 |
} |