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