/[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 1871 - (show annotations) (download)
Sun Mar 22 18:11:39 2009 UTC (15 years, 1 month ago) by iliev
File size: 13739 byte(s)
* Mac OS integration, work in progress:
* Added option to use native file choosers
  (choose Edit/Preferences, then click the `View' tab)

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

  ViewVC Help
Powered by ViewVC