1 |
iliev |
1286 |
/* |
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 |
iliev |
1313 |
import org.jsampler.view.std.JSDefaultsPropsPane; |
50 |
iliev |
1286 |
import org.jsampler.view.std.JSGeneralProps; |
51 |
|
|
import org.jsampler.view.std.JSLSConsolePropsPane; |
52 |
|
|
|
53 |
|
|
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
54 |
|
|
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* |
59 |
|
|
* @author Grigor Iliev |
60 |
|
|
*/ |
61 |
|
|
public class PrefsDlg extends EnhancedDialog { |
62 |
|
|
private final GeneralPane genPane = new GeneralPane(); |
63 |
|
|
private final ConsolePane consolePane = new ConsolePane(); |
64 |
|
|
private final JSConnectionPropsPane connectionPane = new JSConnectionPropsPane(); |
65 |
iliev |
1313 |
private final JSDefaultsPropsPane defaultsPane; |
66 |
iliev |
1286 |
|
67 |
|
|
private final JButton btnApply = new JButton(i18n.getButtonLabel("apply")); |
68 |
|
|
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
/** Creates a new instance of <code>PrefsDlg</code> */ |
72 |
|
|
public |
73 |
|
|
PrefsDlg(Frame owner) { |
74 |
|
|
super(owner, i18n.getLabel("PrefsDlg.title"), true); |
75 |
|
|
|
76 |
iliev |
1313 |
defaultsPane = new JSDefaultsPropsPane(this, Res.iconEdit16); |
77 |
|
|
|
78 |
iliev |
1286 |
JTabbedPane tp = new JTabbedPane(); |
79 |
|
|
tp.addTab(i18n.getLabel("PrefsDlg.tabGeneral"), genPane); |
80 |
|
|
tp.addTab(i18n.getLabel("PrefsDlg.tabConsole"), consolePane); |
81 |
|
|
|
82 |
|
|
JPanel p = new JPanel(); |
83 |
|
|
p.setLayout(new BorderLayout()); |
84 |
|
|
p.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
85 |
|
|
p.add(connectionPane, BorderLayout.NORTH); |
86 |
|
|
tp.addTab(i18n.getLabel("PrefsDlg.tabConnection"), p); |
87 |
iliev |
1313 |
tp.addTab(i18n.getLabel("PrefsDlg.tabDefaults"), defaultsPane); |
88 |
iliev |
1286 |
|
89 |
|
|
tp.setAlignmentX(RIGHT_ALIGNMENT); |
90 |
|
|
|
91 |
|
|
// Set preferred size for Apply & Exit buttons |
92 |
|
|
Dimension d = JuifeUtils.getUnionSize(btnApply, btnClose); |
93 |
|
|
btnApply.setPreferredSize(d); |
94 |
|
|
btnClose.setPreferredSize(d); |
95 |
|
|
|
96 |
|
|
JPanel btnPane = new JPanel(); |
97 |
|
|
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.X_AXIS)); |
98 |
|
|
btnPane.add(btnApply); |
99 |
|
|
btnPane.add(Box.createRigidArea(new Dimension(5, 0))); |
100 |
|
|
btnPane.add(btnClose); |
101 |
|
|
btnPane.setAlignmentX(RIGHT_ALIGNMENT); |
102 |
|
|
|
103 |
|
|
JPanel mainPane = new JPanel(); |
104 |
|
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
105 |
|
|
mainPane.add(tp); |
106 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 12))); |
107 |
|
|
mainPane.add(btnPane); |
108 |
|
|
mainPane.setBorder(BorderFactory.createEmptyBorder(11, 12, 12, 12)); |
109 |
|
|
|
110 |
|
|
getContentPane().add(mainPane); |
111 |
|
|
|
112 |
|
|
pack(); |
113 |
|
|
setResizable(false); |
114 |
|
|
setLocation(JuifeUtils.centerLocation(this, owner)); |
115 |
|
|
|
116 |
|
|
installListeners(); |
117 |
|
|
|
118 |
|
|
connectionPane.setLSAddress(Prefs.getLSAddress()); |
119 |
|
|
connectionPane.setLSPort(String.valueOf(Prefs.getLSPort())); |
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 |
|
|
consolePane.apply(); |
145 |
|
|
connectionPane.apply(); |
146 |
iliev |
1313 |
defaultsPane.apply(); |
147 |
iliev |
1286 |
|
148 |
|
|
setVisible(false); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
private void |
152 |
|
|
onExit() { setVisible(false); } |
153 |
|
|
} |
154 |
|
|
|
155 |
|
|
class GeneralPane extends JPanel { |
156 |
|
|
private final JCheckBox checkTurnOffAnimationEffects = |
157 |
|
|
new JCheckBox(i18n.getLabel("GeneralPane.checkTurnOffAnimationEffects")); |
158 |
|
|
|
159 |
|
|
private final JCheckBox checkShowLSConsoleWhenRunScript = |
160 |
|
|
new JCheckBox(i18n.getLabel("GeneralPane.checkShowLSConsoleWhenRunScript")); |
161 |
|
|
|
162 |
|
|
private final JSGeneralProps.JSamplerHomePane jSamplerHomePane = |
163 |
|
|
new JSGeneralProps.JSamplerHomePane(); |
164 |
|
|
|
165 |
|
|
private final RecentScriptsPane recentScriptsPane = new RecentScriptsPane(); |
166 |
|
|
|
167 |
|
|
public |
168 |
|
|
GeneralPane() { |
169 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
170 |
|
|
|
171 |
|
|
checkTurnOffAnimationEffects.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
172 |
|
|
|
173 |
|
|
boolean b = !preferences().getBoolProperty(ANIMATED); |
174 |
|
|
checkTurnOffAnimationEffects.setSelected(b); |
175 |
|
|
|
176 |
|
|
add(checkTurnOffAnimationEffects); |
177 |
|
|
|
178 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
179 |
|
|
|
180 |
|
|
checkShowLSConsoleWhenRunScript.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
181 |
|
|
|
182 |
|
|
b = preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT); |
183 |
|
|
checkShowLSConsoleWhenRunScript.setSelected(b); |
184 |
|
|
|
185 |
|
|
add(checkShowLSConsoleWhenRunScript); |
186 |
|
|
|
187 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
188 |
|
|
|
189 |
|
|
add(jSamplerHomePane); |
190 |
|
|
|
191 |
|
|
add(Box.createRigidArea(new Dimension(0, 6))); |
192 |
|
|
|
193 |
|
|
add(recentScriptsPane); |
194 |
|
|
add(Box.createGlue()); |
195 |
|
|
|
196 |
|
|
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
197 |
|
|
|
198 |
|
|
|
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
protected void |
202 |
|
|
apply() { |
203 |
|
|
boolean b = !checkTurnOffAnimationEffects.isSelected(); |
204 |
|
|
preferences().setBoolProperty(ANIMATED, b); |
205 |
|
|
|
206 |
|
|
b = checkShowLSConsoleWhenRunScript.isSelected(); |
207 |
|
|
preferences().setBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT, b); |
208 |
|
|
|
209 |
|
|
int size = recentScriptsPane.getRecentScriptsSize(); |
210 |
|
|
preferences().setIntProperty(RECENT_LSCP_SCRIPTS_SIZE, size); |
211 |
|
|
((MainFrame)CC.getMainFrame()).updateRecentScriptsMenu(); |
212 |
|
|
|
213 |
|
|
String s = jSamplerHomePane.getJSamplerHome(); |
214 |
|
|
if(s.length() > 0 && !s.equals(CC.getJSamplerHome())) { |
215 |
|
|
CC.changeJSamplerHome(s); |
216 |
|
|
} |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
private class RecentScriptsPane extends JSGeneralProps.RecentScriptsPane { |
220 |
|
|
protected void |
221 |
|
|
clearRecentScripts() { |
222 |
|
|
((MainFrame)CC.getMainFrame()).clearRecentScripts(); |
223 |
|
|
} |
224 |
|
|
} |
225 |
|
|
} |
226 |
|
|
|
227 |
|
|
class ConsolePane extends JSLSConsolePropsPane { |
228 |
|
|
protected void |
229 |
|
|
clearConsoleHistory() { |
230 |
|
|
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
231 |
|
|
mainFrame.getLSConsoleModel().clearCommandHistory(); |
232 |
|
|
} |
233 |
|
|
|
234 |
|
|
protected void |
235 |
|
|
apply() { |
236 |
|
|
super.apply(); |
237 |
|
|
|
238 |
|
|
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
239 |
|
|
|
240 |
|
|
LSConsoleModel model = mainFrame.getLSConsoleModel(); |
241 |
|
|
model.setCommandHistorySize(preferences().getIntProperty(LS_CONSOLE_HISTSIZE)); |
242 |
|
|
|
243 |
|
|
LSConsolePane console = mainFrame.getLSConsolePane(); |
244 |
|
|
|
245 |
|
|
int c = preferences().getIntProperty(LS_CONSOLE_TEXT_COLOR); |
246 |
|
|
console.setTextColor(new Color(c)); |
247 |
|
|
|
248 |
|
|
c = preferences().getIntProperty(LS_CONSOLE_BACKGROUND_COLOR); |
249 |
|
|
console.setBackgroundColor(new Color(c)); |
250 |
|
|
|
251 |
|
|
c = preferences().getIntProperty(LS_CONSOLE_NOTIFY_COLOR); |
252 |
|
|
console.setNotifyColor(new Color(c)); |
253 |
|
|
|
254 |
|
|
c = preferences().getIntProperty(LS_CONSOLE_WARNING_COLOR); |
255 |
|
|
console.setWarningColor(new Color(c)); |
256 |
|
|
|
257 |
|
|
c = preferences().getIntProperty(LS_CONSOLE_ERROR_COLOR); |
258 |
|
|
console.setErrorColor(new Color(c)); |
259 |
|
|
} |
260 |
|
|
} |