/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/PrefsDlg.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/fantasia/PrefsDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (hide annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 15128 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC