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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show 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 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2011 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.swing.EnhancedDialog;
46 import net.sf.juife.swing.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 import org.jsampler.view.swing.SHF;
59
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 private final JTabbedPane tabbedPane = new JTabbedPane();
70
71 private final GeneralPane genPane = new GeneralPane(this);
72 private final ViewPane viewPane = new ViewPane();
73 private final ChannelsPropsPane channelsPane = new ChannelsPropsPane();
74 private final ConsolePane consolePane = new ConsolePane();
75 private final JSConnectionPropsPane connectionPane = new JSConnectionPropsPane();
76 private final JSDefaultsPropsPane defaultsPane;
77
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 PrefsDlg(Frame owner) {
85 super(owner, i18n.getLabel("PrefsDlg.title"), true);
86
87 defaultsPane = new JSDefaultsPropsPane(this, Res.iconEdit16, true);
88
89 JTabbedPane tp = tabbedPane;
90 tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
91
92 tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane);
93 tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane);
94 tp.addTab(i18n.getLabel("PrefsDlg.tabChannels"), channelsPane);
95 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 p.add(connectionPane);
101 tp.addTab(i18n.getLabel("PrefsDlg.tabBackend"), p);
102 tp.addTab(i18n.getLabel("PrefsDlg.tabDefaults"), defaultsPane);
103
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
133 int i = preferences().getIntProperty("PrefsDlg.tabIndex");
134
135 if(i >= 0 && i < tp.getTabCount()) tp.setSelectedIndex(i);
136 }
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 viewPane.apply();
161 channelsPane.apply();
162 consolePane.apply();
163 connectionPane.apply();
164 defaultsPane.apply();
165
166 preferences().setIntProperty("PrefsDlg.tabIndex", tabbedPane.getSelectedIndex());
167
168 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 private final JCheckBox checkShowVolumesInDecibels =
180 new JCheckBox(i18n.getLabel("GeneralPane.checkShowVolumesInDecibels"));
181
182 private final JSGeneralProps.PolyphonyPane polyphonyPane = new JSGeneralProps.PolyphonyPane();
183
184 private final JSGeneralProps.JSamplerHomePane jSamplerHomePane =
185 new JSGeneralProps.JSamplerHomePane();
186
187 private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane();
188
189 private final JButton btnAdvanced = new JButton(i18n.getButtonLabel("GeneralPane.btnAdvanced"));
190
191 private final Dialog owner;
192
193 public
194 GeneralPane(Dialog owner) {
195 this.owner = owner;
196
197 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
198
199 checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT);
200
201 boolean b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT);
202 checkShowLSConsoleWhenRunScript.setSelected(b);
203
204 add(checkShowLSConsoleWhenRunScript);
205
206 add(Box.createRigidArea(new Dimension(0, 6)));
207
208 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 add(polyphonyPane);
216
217 add(Box.createRigidArea(new Dimension(0, 6)));
218
219 add(jSamplerHomePane);
220
221 add(Box.createRigidArea(new Dimension(0, 6)));
222
223 add(recentScriptsPane);
224
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 add(Box.createGlue());
238
239 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
240
241 btnAdvanced.addActionListener(new ActionListener() {
242 public void
243 actionPerformed(ActionEvent e) { showAdvancedProperties(); }
244 });
245 }
246
247 private void
248 showAdvancedProperties() {
249 new JSAdvancedGeneralPropsDlg(owner).setVisible(true);
250 }
251
252 protected void
253 apply() {
254 polyphonyPane.apply();
255
256 boolean b = checkShowLSConsoleWhenRunScript.isSelected();
257 preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b);
258
259 b = checkShowVolumesInDecibels.isSelected();
260 preferences().setBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL, b);
261
262 int size = recentScriptsPane.getRecentScriptsSize();
263 preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size);
264 ((MainFrame)SHF.getMainFrame()).updateRecentScriptsMenu();
265
266 String s = jSamplerHomePane.getJSamplerHome();
267 if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) {
268 JSUtils.changeJSamplerHome(s);
269 }
270 }
271
272 private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane {
273 protected void
274 clearRecentScripts() {
275 ((MainFrame)SHF.getMainFrame()).clearRecentScripts();
276 }
277 }
278 }
279
280 class ViewPane extends JPanel {
281 private final JCheckBox checkTurnOffAnimationEffects =
282 new JCheckBox(i18n.getLabel("GeneralPane.checkTurnOffAnimationEffects"));
283
284 private final JCheckBox checkTurnOffCustomWindowDecoration =
285 new JCheckBox(i18n.getLabel("ViewPane.checkTurnOffCustomWindowDecoration"));
286
287 private final JCheckBox checkShowInstrumentsDb =
288 new JCheckBox(i18n.getLabel("ViewPane.checkShowInstrumentsDb"));
289
290 private final JCheckBox checkUseNativeFileChoosers =
291 new JCheckBox(i18n.getLabel("ViewPane.checkUseNativeFileChoosers"));
292
293 private final JSViewProps.MidiDevicesPane midiDevsPane = new JSViewProps.MidiDevicesPane();
294 private final JSViewProps.AudioDevicesPane audioDevsPane = new JSViewProps.AudioDevicesPane();
295
296 private final JSViewProps.ConfirmationMessagesPane confirmationMessagesPane =
297 new JSViewProps.ConfirmationMessagesPane();
298
299 ViewPane() {
300 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
301
302 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 checkTurnOffCustomWindowDecoration.setSelected(b);
313 checkTurnOffCustomWindowDecoration.setAlignmentX(JPanel.LEFT_ALIGNMENT);
314 add(checkTurnOffCustomWindowDecoration);
315 add(Box.createRigidArea(new Dimension(0, 6)));
316
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
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
329 add(midiDevsPane);
330 add(audioDevsPane);
331 add(confirmationMessagesPane);
332 }
333
334 protected void
335 apply() {
336 boolean b = !checkTurnOffAnimationEffects.isSelected();
337 preferences().setBoolProperty(ANIMATED, b);
338
339 String s = "TurnOffCustomWindowDecoration";
340 preferences().setBoolProperty(s, checkTurnOffCustomWindowDecoration.isSelected());
341
342 s = "rightSidePane.showInstrumentsDb";
343 preferences().setBoolProperty(s, checkShowInstrumentsDb.isSelected());
344
345 s = "nativeFileChoosers";
346 preferences().setBoolProperty(s, checkUseNativeFileChoosers.isSelected());
347
348 midiDevsPane.apply();
349 audioDevsPane.apply();
350 confirmationMessagesPane.apply();
351 }
352 }
353
354 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 private final JCheckBox checkShowStreamVoiceCount =
362 new JCheckBox(i18n.getLabel("ChannelsPropsPane.checkShowStreamVoiceCount"));
363
364 private final JLabel lChannelLaneNumber =
365 new JLabel(i18n.getLabel("ChannelsPropsPane.lChannelLaneNumber"));
366
367 private JSpinner spChannelLaneNumber;
368
369 ChannelsPropsPane() {
370 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
371
372 add(createChannelLanesPane());
373 add(createSmallViewPane());
374
375 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
388 b = checkShowStreamVoiceCount.isSelected();
389 preferences().setBoolProperty("channel.smallView.showStreamVoiceCount", b);
390
391 int i = Integer.parseInt(spChannelLaneNumber.getValue().toString());
392 preferences().setIntProperty("channelLanes.count", i);
393 }
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 b = preferences().getBoolProperty("channel.smallView.showStreamVoiceCount");
411 checkShowStreamVoiceCount.setSelected(b);
412 checkShowStreamVoiceCount.setAlignmentX(LEFT_ALIGNMENT);
413 p.add(checkShowStreamVoiceCount);
414
415 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
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 }
449
450 class ConsolePane extends JSLSConsolePropsPane {
451 protected void
452 clearConsoleHistory() {
453 MainFrame mainFrame = (MainFrame)SHF.getMainFrame();
454 mainFrame.getLSConsoleModel().clearCommandHistory();
455 }
456
457 protected void
458 apply() {
459 super.apply();
460
461 MainFrame mainFrame = (MainFrame)SHF.getMainFrame();
462
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