/[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 1688 - (show annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 9495 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 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.Dimension;
28 import java.awt.Frame;
29
30 import java.awt.event.ActionEvent;
31 import java.awt.event.ActionListener;
32
33 import javax.swing.BorderFactory;
34 import javax.swing.Box;
35 import javax.swing.BoxLayout;
36 import javax.swing.JButton;
37 import javax.swing.JCheckBox;
38 import javax.swing.JPanel;
39 import javax.swing.JTabbedPane;
40
41 import net.sf.juife.EnhancedDialog;
42 import net.sf.juife.JuifeUtils;
43
44 import org.jsampler.CC;
45 import org.jsampler.LSConsoleModel;
46 import org.jsampler.Prefs;
47
48 import org.jsampler.view.std.JSConnectionPropsPane;
49 import org.jsampler.view.std.JSDefaultsPropsPane;
50 import org.jsampler.view.std.JSGeneralProps;
51 import org.jsampler.view.std.JSLSConsolePropsPane;
52 import org.jsampler.view.std.JSViewProps;
53
54 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
55 import static org.jsampler.view.fantasia.FantasiaPrefs.*;
56
57
58 /**
59 *
60 * @author Grigor Iliev
61 */
62 public class PrefsDlg extends EnhancedDialog {
63 private final GeneralPane genPane = new GeneralPane();
64 private final ViewPane viewPane = new ViewPane();
65 private final ConsolePane consolePane = new ConsolePane();
66 private final JSConnectionPropsPane connectionPane = new JSConnectionPropsPane();
67 private final JSDefaultsPropsPane defaultsPane;
68
69 private final JButton btnApply = new JButton(i18n.getButtonLabel("apply"));
70 private final JButton btnClose = new JButton(i18n.getButtonLabel("close"));
71
72
73 /** Creates a new instance of <code>PrefsDlg</code> */
74 public
75 PrefsDlg(Frame owner) {
76 super(owner, i18n.getLabel("PrefsDlg.title"), true);
77
78 defaultsPane = new JSDefaultsPropsPane(this, Res.iconEdit16);
79
80 JTabbedPane tp = new JTabbedPane();
81 tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane);
82 tp.addTab(i18n.getLabel("PrefsDlg.tabView"), viewPane);
83 tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane);
84
85 JPanel p = new JPanel();
86 p.setLayout(new BorderLayout());
87 p.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
88 p.add(connectionPane);
89 tp.addTab(i18n.getLabel("PrefsDlg.tabBackend"), p);
90 tp.addTab(i18n.getLabel("PrefsDlg.tabDefaults"), defaultsPane);
91
92 tp.setAlignmentX(RIGHT_ALIGNMENT);
93
94 // Set preferred size for Apply & Exit buttons
95 Dimension d = JuifeUtils.getUnionSize(btnApply, btnClose);
96 btnApply.setPreferredSize(d);
97 btnClose.setPreferredSize(d);
98
99 JPanel btnPane = new JPanel();
100 btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS));
101 btnPane.add(btnApply);
102 btnPane.add(Box.createRigidArea(new Dimension(5, 0)));
103 btnPane.add(btnClose);
104 btnPane.setAlignmentX(RIGHT_ALIGNMENT);
105
106 JPanel mainPane = new JPanel();
107 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
108 mainPane.add(tp);
109 mainPane.add(Box.createRigidArea(new Dimension(0, 12)));
110 mainPane.add(btnPane);
111 mainPane.setBorder(BorderFactory.createEmptyBorder(11, 12, 12, 12));
112
113 getContentPane().add(mainPane);
114
115 pack();
116 setResizable(false);
117 setLocation(JuifeUtils.centerLocation(this, owner));
118
119 installListeners();
120 }
121
122 private void
123 installListeners() {
124 btnApply.addActionListener(new ActionListener() {
125 public void
126 actionPerformed(ActionEvent e) { onApply(); }
127 });
128
129 btnClose.addActionListener(new ActionListener() {
130 public void
131 actionPerformed(ActionEvent e) { onExit(); }
132 });
133 }
134
135 protected void
136 onOk() { onApply(); }
137
138 protected void
139 onCancel() { onExit(); }
140
141 private void
142 onApply() {
143 genPane.apply();
144 viewPane.apply();
145 consolePane.apply();
146 connectionPane.apply();
147 defaultsPane.apply();
148
149 setVisible(false);
150 }
151
152 private void
153 onExit() { setVisible(false); }
154 }
155
156 class GeneralPane extends JPanel {
157 private final JCheckBox checkTurnOffAnimationEffects =
158 new JCheckBox(i18n.getLabel("GeneralPane.checkTurnOffAnimationEffects"));
159
160 private final JCheckBox checkShowLSConsoleWhenRunScript =
161 new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript"));
162
163 private final JCheckBox checkShowVolumesInDecibels =
164 new JCheckBox(i18n.getLabel("GeneralPane.checkShowVolumesInDecibels"));
165
166 private final JSGeneralProps.MaxVolumePane maxVolPane = new JSGeneralProps.MaxVolumePane();
167
168 private final JSGeneralProps.JSamplerHomePane jSamplerHomePane =
169 new JSGeneralProps.JSamplerHomePane();
170
171 private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane();
172
173 public
174 GeneralPane() {
175 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
176
177 checkTurnOffAnimationEffects.setAlignmentX(JPanel.LEFT_ALIGNMENT);
178
179 boolean b = !preferences().getBoolProperty(ANIMATED);
180 checkTurnOffAnimationEffects.setSelected(b);
181
182 add(checkTurnOffAnimationEffects);
183
184 add(Box.createRigidArea(new Dimension(0, 6)));
185
186 checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT);
187
188 b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT);
189 checkShowLSConsoleWhenRunScript.setSelected(b);
190
191 add(checkShowLSConsoleWhenRunScript);
192
193 add(Box.createRigidArea(new Dimension(0, 6)));
194
195 b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL);
196 checkShowVolumesInDecibels.setSelected(b);
197
198 add(checkShowVolumesInDecibels);
199
200 add(Box.createRigidArea(new Dimension(0, 6)));
201
202 add(maxVolPane);
203
204 add(Box.createRigidArea(new Dimension(0, 6)));
205
206 add(jSamplerHomePane);
207
208 add(Box.createRigidArea(new Dimension(0, 6)));
209
210 add(recentScriptsPane);
211 add(Box.createGlue());
212
213 setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
214
215
216 }
217
218 protected void
219 apply() {
220 maxVolPane.apply();
221
222 boolean b = !checkTurnOffAnimationEffects.isSelected();
223 preferences().setBoolProperty(ANIMATED, b);
224
225 b = checkShowLSConsoleWhenRunScript.isSelected();
226 preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b);
227
228 b = checkShowVolumesInDecibels.isSelected();
229 preferences().setBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL, b);
230
231 int size = recentScriptsPane.getRecentScriptsSize();
232 preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size);
233 ((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu();
234
235 String s = jSamplerHomePane.getJSamplerHome();
236 if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) {
237 CC.changeJSamplerHome(s);
238 }
239 }
240
241 private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane {
242 protected void
243 clearRecentScripts() {
244 ((MainFrame)CC.getMainFrame()).clearRecentScripts();
245 }
246 }
247 }
248
249 class ViewPane extends JPanel {
250 private final JCheckBox checkTurnOffCustomWindowDecoration =
251 new JCheckBox(i18n.getLabel("ViewPane.checkTurnOffCustomWindowDecoration"));
252
253 private final JSViewProps.MidiDevicesPane midiDevsPane = new JSViewProps.MidiDevicesPane();
254 private final JSViewProps.AudioDevicesPane audioDevsPane = new JSViewProps.AudioDevicesPane();
255
256 private final JSViewProps.ConfirmationMessagesPane confirmationMessagesPane =
257 new JSViewProps.ConfirmationMessagesPane();
258
259 ViewPane() {
260 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
261
262 boolean b = preferences().getBoolProperty("TurnOffCustomWindowDecoration");
263 checkTurnOffCustomWindowDecoration.setSelected(b);
264 checkTurnOffCustomWindowDecoration.setAlignmentX(JPanel.LEFT_ALIGNMENT);
265 add(checkTurnOffCustomWindowDecoration);
266 add(Box.createRigidArea(new Dimension(0, 6)));
267 add(midiDevsPane);
268 add(audioDevsPane);
269 add(confirmationMessagesPane);
270 }
271
272 protected void
273 apply() {
274 String s = "TurnOffCustomWindowDecoration";
275 preferences().setBoolProperty(s, checkTurnOffCustomWindowDecoration.isSelected());
276
277 midiDevsPane.apply();
278 audioDevsPane.apply();
279 confirmationMessagesPane.apply();
280 }
281 }
282
283 class ConsolePane extends JSLSConsolePropsPane {
284 protected void
285 clearConsoleHistory() {
286 MainFrame mainFrame = (MainFrame)CC.getMainFrame();
287 mainFrame.getLSConsoleModel().clearCommandHistory();
288 }
289
290 protected void
291 apply() {
292 super.apply();
293
294 MainFrame mainFrame = (MainFrame)CC.getMainFrame();
295
296 LSConsoleModel model = mainFrame.getLSConsoleModel();
297 model.setCommandHistorySize(preferences().getIntProperty(LS_CONSOLE_HISTSIZE));
298
299 LSConsolePane console = mainFrame.getLSConsolePane();
300
301 int c = preferences().getIntProperty(LS_CONSOLE_TEXT_COLOR);
302 console.setTextColor(new Color(c));
303
304 c = preferences().getIntProperty(LS_CONSOLE_BACKGROUND_COLOR);
305 console.setBackgroundColor(new Color(c));
306
307 c = preferences().getIntProperty(LS_CONSOLE_NOTIFY_COLOR);
308 console.setNotifyColor(new Color(c));
309
310 c = preferences().getIntProperty(LS_CONSOLE_WARNING_COLOR);
311 console.setWarningColor(new Color(c));
312
313 c = preferences().getIntProperty(LS_CONSOLE_ERROR_COLOR);
314 console.setErrorColor(new Color(c));
315 }
316 }

  ViewVC Help
Powered by ViewVC