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