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.std; |
24 |
|
25 |
import java.awt.Dialog; |
26 |
import java.awt.Dimension; |
27 |
|
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
import java.awt.event.ItemEvent; |
31 |
import java.awt.event.ItemListener; |
32 |
|
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.Icon; |
37 |
import javax.swing.JButton; |
38 |
import javax.swing.JCheckBox; |
39 |
import javax.swing.JComboBox; |
40 |
import javax.swing.JDialog; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JPanel; |
43 |
|
44 |
import org.jsampler.CC; |
45 |
import org.jsampler.JSPrefs; |
46 |
|
47 |
import org.linuxsampler.lscp.AudioOutputDriver; |
48 |
import org.linuxsampler.lscp.MidiInputDriver; |
49 |
|
50 |
import static org.jsampler.view.std.StdI18n.i18n; |
51 |
import static org.jsampler.view.std.StdPrefs.*; |
52 |
|
53 |
/** |
54 |
* |
55 |
* @author Grigor Iliev |
56 |
*/ |
57 |
public class JSDefaultsPropsPane extends JPanel { |
58 |
private final ChannelDefaultsPane channelDefaultsPane; |
59 |
private final DefaultMidiDriverPane defaultMidiDriverPane = new DefaultMidiDriverPane(); |
60 |
private final DefaultAudioDriverPane defaultAudioDriverPane = new DefaultAudioDriverPane(); |
61 |
|
62 |
|
63 |
/** Creates a new instance of <code>JSDefaultsPropsPane</code> */ |
64 |
public |
65 |
JSDefaultsPropsPane(Dialog owner, Icon iconChangeDefaults) { |
66 |
this(owner, iconChangeDefaults, false); |
67 |
} |
68 |
|
69 |
/** Creates a new instance of <code>JSDefaultsPropsPane</code> */ |
70 |
public |
71 |
JSDefaultsPropsPane(Dialog owner, Icon iconChangeDefaults, boolean showDefaultChannelView) { |
72 |
channelDefaultsPane = new ChannelDefaultsPane(owner, iconChangeDefaults, showDefaultChannelView); |
73 |
|
74 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
75 |
add(channelDefaultsPane); |
76 |
add(Box.createRigidArea(new Dimension(0, 6))); |
77 |
add(defaultMidiDriverPane); |
78 |
add(Box.createRigidArea(new Dimension(0, 6))); |
79 |
add(defaultAudioDriverPane); |
80 |
} |
81 |
|
82 |
private static JSPrefs |
83 |
preferences() { return CC.getViewConfig().preferences(); } |
84 |
|
85 |
public void |
86 |
apply() { |
87 |
channelDefaultsPane.apply(); |
88 |
defaultMidiDriverPane.apply(); |
89 |
defaultAudioDriverPane.apply(); |
90 |
} |
91 |
|
92 |
public static class ChannelDefaultsPane extends JPanel { |
93 |
private final Dialog owner; |
94 |
private final JCheckBox checkChannelDefaults = |
95 |
new JCheckBox(i18n.getLabel("JSDefaultsPropsPane.checkChannelDefaults")); |
96 |
|
97 |
private final JButton btnChannelDefaults; |
98 |
|
99 |
private final boolean showDefaultView; |
100 |
private final JComboBox cbDefaultView = new JComboBox(); |
101 |
|
102 |
|
103 |
public |
104 |
ChannelDefaultsPane(Dialog owner, Icon iconChangeDefaults) { |
105 |
this(owner, iconChangeDefaults, false); |
106 |
} |
107 |
|
108 |
public |
109 |
ChannelDefaultsPane(Dialog owner, Icon iconChangeDefaults, boolean showDefaultView) { |
110 |
this.owner = owner; |
111 |
this.showDefaultView = showDefaultView; |
112 |
btnChannelDefaults = new JButton(iconChangeDefaults); |
113 |
btnChannelDefaults.setEnabled(false); |
114 |
btnChannelDefaults.setMargin(new java.awt.Insets(0, 0, 0, 0)); |
115 |
|
116 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
117 |
|
118 |
JPanel p = new JPanel(); |
119 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
120 |
|
121 |
p.add(checkChannelDefaults); |
122 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
123 |
p.add(btnChannelDefaults); |
124 |
p.setAlignmentX(LEFT_ALIGNMENT); |
125 |
p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); |
126 |
add(p); |
127 |
|
128 |
setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
129 |
|
130 |
String s = i18n.getLabel("JSDefaultsPropsPane.titleChannels"); |
131 |
setBorder(BorderFactory.createTitledBorder(s)); |
132 |
setAlignmentX(LEFT_ALIGNMENT); |
133 |
|
134 |
checkChannelDefaults.addItemListener(new ItemListener() { |
135 |
public void |
136 |
itemStateChanged(ItemEvent e) { |
137 |
btnChannelDefaults.setEnabled(checkChannelDefaults.isSelected()); |
138 |
} |
139 |
}); |
140 |
|
141 |
if(preferences().getBoolProperty(USE_CHANNEL_DEFAULTS)) { |
142 |
checkChannelDefaults.doClick(0); |
143 |
} |
144 |
|
145 |
btnChannelDefaults.addActionListener(new ActionListener() { |
146 |
public void |
147 |
actionPerformed(ActionEvent e) { editChannelDefaults(); } |
148 |
}); |
149 |
|
150 |
if(showDefaultView) { |
151 |
p = new JPanel(); |
152 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
153 |
|
154 |
s = i18n.getLabel("JSDefaultsPropsPane.lDefaultChannelView"); |
155 |
p.add(new JLabel(s)); |
156 |
|
157 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
158 |
|
159 |
s = i18n.getLabel("JSDefaultsPropsPane.lSmallView"); |
160 |
cbDefaultView.addItem(s); |
161 |
|
162 |
s = i18n.getLabel("JSDefaultsPropsPane.lNormalView"); |
163 |
cbDefaultView.addItem(s); |
164 |
|
165 |
int i = preferences().getIntProperty(DEFAULT_CHANNEL_VIEW); |
166 |
if(i < 0 || i >= cbDefaultView.getItemCount()) i = 1; |
167 |
|
168 |
cbDefaultView.setSelectedIndex(i); |
169 |
|
170 |
p.add(cbDefaultView); |
171 |
|
172 |
p.setAlignmentX(LEFT_ALIGNMENT); |
173 |
p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); |
174 |
add(p); |
175 |
} |
176 |
|
177 |
setMaximumSize(new Dimension(Short.MAX_VALUE, getPreferredSize().height)); |
178 |
} |
179 |
|
180 |
public void |
181 |
apply() { |
182 |
boolean b = checkChannelDefaults.isSelected(); |
183 |
preferences().setBoolProperty(USE_CHANNEL_DEFAULTS, b); |
184 |
|
185 |
if(showDefaultView) { |
186 |
int i = cbDefaultView.getSelectedIndex(); |
187 |
preferences().setIntProperty(DEFAULT_CHANNEL_VIEW, i); |
188 |
} |
189 |
} |
190 |
|
191 |
protected void |
192 |
editChannelDefaults() { |
193 |
JDialog dlg = new JSChannelsDefaultSettingsPane().createDialog(owner); |
194 |
dlg.setVisible(true); |
195 |
} |
196 |
} |
197 |
|
198 |
public static class DefaultMidiDriverPane extends JPanel { |
199 |
private final JComboBox cbDriver = new JComboBox(); |
200 |
|
201 |
public |
202 |
DefaultMidiDriverPane() { |
203 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
204 |
|
205 |
JPanel p = new JPanel(); |
206 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
207 |
|
208 |
cbDriver.setAlignmentX(LEFT_ALIGNMENT); |
209 |
int h = cbDriver.getPreferredSize().height; |
210 |
cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
211 |
|
212 |
p.add(cbDriver); |
213 |
p.setAlignmentX(LEFT_ALIGNMENT); |
214 |
p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); |
215 |
|
216 |
add(p); |
217 |
|
218 |
String s = i18n.getLabel("JSDefaultsPropsPane.titleMidiDriver"); |
219 |
setBorder(BorderFactory.createTitledBorder(s)); |
220 |
setAlignmentX(LEFT_ALIGNMENT); |
221 |
|
222 |
// not connected? |
223 |
if(CC.getSamplerModel().getMidiInputDrivers() == null) return; |
224 |
|
225 |
for(Object o : CC.getSamplerModel().getMidiInputDrivers()) { |
226 |
cbDriver.addItem(o); |
227 |
} |
228 |
|
229 |
String drv = preferences().getStringProperty(DEFAULT_MIDI_DRIVER); |
230 |
for(MidiInputDriver d : CC.getSamplerModel().getMidiInputDrivers()) { |
231 |
if(d.getName().equals(drv)){ |
232 |
cbDriver.setSelectedItem(d); |
233 |
break; |
234 |
} |
235 |
} |
236 |
} |
237 |
|
238 |
public void |
239 |
apply() { |
240 |
// not connected? |
241 |
if(CC.getSamplerModel().getMidiInputDrivers() == null) return; |
242 |
|
243 |
Object o = cbDriver.getSelectedItem(); |
244 |
if(o == null) { |
245 |
preferences().setStringProperty(DEFAULT_MIDI_DRIVER, null); |
246 |
return; |
247 |
} |
248 |
|
249 |
String drv = ((MidiInputDriver) o).getName(); |
250 |
preferences().setStringProperty(DEFAULT_MIDI_DRIVER, drv); |
251 |
} |
252 |
} |
253 |
|
254 |
public static class DefaultAudioDriverPane extends JPanel { |
255 |
private final JComboBox cbDriver = new JComboBox(); |
256 |
|
257 |
public |
258 |
DefaultAudioDriverPane() { |
259 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
260 |
|
261 |
JPanel p = new JPanel(); |
262 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
263 |
|
264 |
cbDriver.setAlignmentX(LEFT_ALIGNMENT); |
265 |
int h = cbDriver.getPreferredSize().height; |
266 |
cbDriver.setMaximumSize(new Dimension(Short.MAX_VALUE, h)); |
267 |
|
268 |
p.add(cbDriver); |
269 |
p.setAlignmentX(LEFT_ALIGNMENT); |
270 |
p.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5)); |
271 |
|
272 |
add(p); |
273 |
|
274 |
String s = i18n.getLabel("JSDefaultsPropsPane.titleAudioDriver"); |
275 |
setBorder(BorderFactory.createTitledBorder(s)); |
276 |
setAlignmentX(LEFT_ALIGNMENT); |
277 |
|
278 |
// not connected? |
279 |
if(CC.getSamplerModel().getAudioOutputDrivers() == null) return; |
280 |
|
281 |
for(Object o : CC.getSamplerModel().getAudioOutputDrivers()) { |
282 |
cbDriver.addItem(o); |
283 |
} |
284 |
|
285 |
String drv = preferences().getStringProperty(DEFAULT_AUDIO_DRIVER); |
286 |
for(AudioOutputDriver d : CC.getSamplerModel().getAudioOutputDrivers()) { |
287 |
if(d.getName().equals(drv)){ |
288 |
cbDriver.setSelectedItem(d); |
289 |
break; |
290 |
} |
291 |
} |
292 |
} |
293 |
|
294 |
public void |
295 |
apply() { |
296 |
// not connected? |
297 |
if(CC.getSamplerModel().getAudioOutputDrivers() == null) return; |
298 |
|
299 |
Object o = cbDriver.getSelectedItem(); |
300 |
if(o == null) { |
301 |
preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, null); |
302 |
return; |
303 |
} |
304 |
|
305 |
String drv = ((AudioOutputDriver) o).getName(); |
306 |
preferences().setStringProperty(DEFAULT_AUDIO_DRIVER, drv); |
307 |
} |
308 |
} |
309 |
} |