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, BorderLayout.NORTH); |
89 |
tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), 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 |
connectionPane.setLSAddress(Prefs.getLSAddress()); |
122 |
connectionPane.setLSPort(String.valueOf(Prefs.getLSPort())); |
123 |
} |
124 |
|
125 |
private void |
126 |
installListeners() { |
127 |
btnApply.addActionListener(new ActionListener() { |
128 |
public void |
129 |
actionPerformed(ActionEvent e) { onApply(); } |
130 |
}); |
131 |
|
132 |
btnClose.addActionListener(new ActionListener() { |
133 |
public void |
134 |
actionPerformed(ActionEvent e) { onExit(); } |
135 |
}); |
136 |
} |
137 |
|
138 |
protected void |
139 |
onOk() { onApply(); } |
140 |
|
141 |
protected void |
142 |
onCancel() { onExit(); } |
143 |
|
144 |
private void |
145 |
onApply() { |
146 |
genPane.apply(); |
147 |
viewPane.apply(); |
148 |
consolePane.apply(); |
149 |
connectionPane.apply(); |
150 |
defaultsPane.apply(); |
151 |
|
152 |
setVisible(false); |
153 |
} |
154 |
|
155 |
private void |
156 |
onExit() { setVisible(false); } |
157 |
} |
158 |
|
159 |
class GeneralPane extends JPanel { |
160 |
private final JCheckBox checkTurnOffAnimationEffects = |
161 |
new JCheckBox(i18n.getLabel("GeneralPane.checkTurnOffAnimationEffects")); |
162 |
|
163 |
private final JCheckBox checkShowLSConsoleWhenRunScript = |
164 |
new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript")); |
165 |
|
166 |
private final JCheckBox checkShowVolumesInDecibels = |
167 |
new JCheckBox(i18n.getLabel("GeneralPane.checkShowVolumesInDecibels")); |
168 |
|
169 |
private final JSGeneralProps.MaxVolumePane maxVolPane = new JSGeneralProps.MaxVolumePane(); |
170 |
|
171 |
private final JSGeneralProps.JSamplerHomePane jSamplerHomePane = |
172 |
new JSGeneralProps.JSamplerHomePane(); |
173 |
|
174 |
private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane(); |
175 |
|
176 |
public |
177 |
GeneralPane() { |
178 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
179 |
|
180 |
checkTurnOffAnimationEffects.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
181 |
|
182 |
boolean b = !preferences().getBoolProperty(ANIMATED); |
183 |
checkTurnOffAnimationEffects.setSelected(b); |
184 |
|
185 |
add(checkTurnOffAnimationEffects); |
186 |
|
187 |
add(Box.createRigidArea(new Dimension(0, 6))); |
188 |
|
189 |
checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
190 |
|
191 |
b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT); |
192 |
checkShowLSConsoleWhenRunScript.setSelected(b); |
193 |
|
194 |
add(checkShowLSConsoleWhenRunScript); |
195 |
|
196 |
add(Box.createRigidArea(new Dimension(0, 6))); |
197 |
|
198 |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
199 |
checkShowVolumesInDecibels.setSelected(b); |
200 |
|
201 |
add(checkShowVolumesInDecibels); |
202 |
|
203 |
add(Box.createRigidArea(new Dimension(0, 6))); |
204 |
|
205 |
add(maxVolPane); |
206 |
|
207 |
add(Box.createRigidArea(new Dimension(0, 6))); |
208 |
|
209 |
add(jSamplerHomePane); |
210 |
|
211 |
add(Box.createRigidArea(new Dimension(0, 6))); |
212 |
|
213 |
add(recentScriptsPane); |
214 |
add(Box.createGlue()); |
215 |
|
216 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
217 |
|
218 |
|
219 |
} |
220 |
|
221 |
protected void |
222 |
apply() { |
223 |
maxVolPane.apply(); |
224 |
|
225 |
boolean b = !checkTurnOffAnimationEffects.isSelected(); |
226 |
preferences().setBoolProperty(ANIMATED, b); |
227 |
|
228 |
b = checkShowLSConsoleWhenRunScript.isSelected(); |
229 |
preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b); |
230 |
|
231 |
b = checkShowVolumesInDecibels.isSelected(); |
232 |
preferences().setBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL, b); |
233 |
|
234 |
int size = recentScriptsPane.getRecentScriptsSize(); |
235 |
preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size); |
236 |
((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu(); |
237 |
|
238 |
String s = jSamplerHomePane.getJSamplerHome(); |
239 |
if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) { |
240 |
CC.changeJSamplerHome(s); |
241 |
} |
242 |
} |
243 |
|
244 |
private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane { |
245 |
protected void |
246 |
clearRecentScripts() { |
247 |
((MainFrame)CC.getMainFrame()).clearRecentScripts(); |
248 |
} |
249 |
} |
250 |
} |
251 |
|
252 |
class ViewPane extends JPanel { |
253 |
private final JCheckBox checkTurnOffCustomWindowDecoration = |
254 |
new JCheckBox(i18n.getLabel("ViewPane.checkTurnOffCustomWindowDecoration")); |
255 |
|
256 |
private final JSViewProps.MidiDevicesPane midiDevsPane = new JSViewProps.MidiDevicesPane(); |
257 |
private final JSViewProps.AudioDevicesPane audioDevsPane = new JSViewProps.AudioDevicesPane(); |
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 |
} |
270 |
|
271 |
protected void |
272 |
apply() { |
273 |
String s = "TurnOffCustomWindowDecoration"; |
274 |
preferences().setBoolProperty(s, checkTurnOffCustomWindowDecoration.isSelected()); |
275 |
|
276 |
midiDevsPane.apply(); |
277 |
audioDevsPane.apply(); |
278 |
} |
279 |
} |
280 |
|
281 |
class ConsolePane extends JSLSConsolePropsPane { |
282 |
protected void |
283 |
clearConsoleHistory() { |
284 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
285 |
mainFrame.getLSConsoleModel().clearCommandHistory(); |
286 |
} |
287 |
|
288 |
protected void |
289 |
apply() { |
290 |
super.apply(); |
291 |
|
292 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
293 |
|
294 |
LSConsoleModel model = mainFrame.getLSConsoleModel(); |
295 |
model.setCommandHistorySize(preferences().getIntProperty(LS_CONSOLE_HISTSIZE)); |
296 |
|
297 |
LSConsolePane console = mainFrame.getLSConsolePane(); |
298 |
|
299 |
int c = preferences().getIntProperty(LS_CONSOLE_TEXT_COLOR); |
300 |
console.setTextColor(new Color(c)); |
301 |
|
302 |
c = preferences().getIntProperty(LS_CONSOLE_BACKGROUND_COLOR); |
303 |
console.setBackgroundColor(new Color(c)); |
304 |
|
305 |
c = preferences().getIntProperty(LS_CONSOLE_NOTIFY_COLOR); |
306 |
console.setNotifyColor(new Color(c)); |
307 |
|
308 |
c = preferences().getIntProperty(LS_CONSOLE_WARNING_COLOR); |
309 |
console.setWarningColor(new Color(c)); |
310 |
|
311 |
c = preferences().getIntProperty(LS_CONSOLE_ERROR_COLOR); |
312 |
console.setErrorColor(new Color(c)); |
313 |
} |
314 |
} |