1 |
iliev |
1313 |
/* |
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.GridBagConstraints; |
27 |
|
|
import java.awt.GridBagLayout; |
28 |
|
|
import java.awt.Insets; |
29 |
|
|
|
30 |
|
|
import java.awt.event.ActionEvent; |
31 |
|
|
import java.awt.event.ActionListener; |
32 |
|
|
|
33 |
|
|
import javax.swing.BorderFactory; |
34 |
|
|
import javax.swing.JComboBox; |
35 |
|
|
import javax.swing.JDialog; |
36 |
|
|
import javax.swing.JLabel; |
37 |
|
|
import javax.swing.JPanel; |
38 |
|
|
|
39 |
|
|
import net.sf.juife.InformationDialog; |
40 |
|
|
|
41 |
|
|
import org.linuxsampler.lscp.SamplerEngine; |
42 |
|
|
|
43 |
|
|
import org.jsampler.CC; |
44 |
|
|
import org.jsampler.JSPrefs; |
45 |
|
|
|
46 |
|
|
import static org.jsampler.view.std.StdI18n.i18n; |
47 |
|
|
import static org.jsampler.view.std.StdPrefs.*; |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* |
52 |
|
|
* @author Grigor Iliev |
53 |
|
|
*/ |
54 |
|
|
public class JSChannelsDefaultSettingsPane extends JPanel { |
55 |
|
|
private final JLabel lDefaultEngine = |
56 |
|
|
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lDefaultEngine")); |
57 |
|
|
|
58 |
|
|
private final JLabel lMidiInput = |
59 |
|
|
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lMidiInput")); |
60 |
|
|
|
61 |
|
|
private final JLabel lAudioOutput = |
62 |
|
|
new JLabel(i18n.getLabel("JSChannelsDefaultSettingsPane.lAudioOutput")); |
63 |
|
|
|
64 |
|
|
private final JComboBox cbDefaultEngine = new JComboBox(); |
65 |
|
|
private final JComboBox cbMidiInput = new JComboBox(); |
66 |
|
|
private final JComboBox cbAudioOutput = new JComboBox(); |
67 |
|
|
|
68 |
|
|
private final static String strFirstDevice = |
69 |
|
|
i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDevice"); |
70 |
|
|
|
71 |
|
|
private final static String strFirstDeviceNextChannel = |
72 |
|
|
i18n.getLabel("JSChannelsDefaultSettingsPane.strFirstDeviceNextChannel"); |
73 |
|
|
|
74 |
|
|
/** Creates a new instance of <code>JSChannelsDefaultSettingsPane</code> */ |
75 |
|
|
public |
76 |
|
|
JSChannelsDefaultSettingsPane() { |
77 |
|
|
GridBagLayout gridbag = new GridBagLayout(); |
78 |
|
|
GridBagConstraints c = new GridBagConstraints(); |
79 |
|
|
|
80 |
|
|
setLayout(gridbag); |
81 |
|
|
|
82 |
|
|
c.fill = GridBagConstraints.NONE; |
83 |
|
|
|
84 |
|
|
c.gridx = 0; |
85 |
|
|
c.gridy = 0; |
86 |
|
|
c.anchor = GridBagConstraints.EAST; |
87 |
|
|
c.insets = new Insets(3, 3, 3, 3); |
88 |
|
|
gridbag.setConstraints(lDefaultEngine, c); |
89 |
|
|
add(lDefaultEngine); |
90 |
|
|
|
91 |
|
|
c.gridx = 0; |
92 |
|
|
c.gridy = 1; |
93 |
|
|
gridbag.setConstraints(lMidiInput, c); |
94 |
|
|
add(lMidiInput); |
95 |
|
|
|
96 |
|
|
c.gridx = 0; |
97 |
|
|
c.gridy = 2; |
98 |
|
|
gridbag.setConstraints(lAudioOutput, c); |
99 |
|
|
add(lAudioOutput); |
100 |
|
|
|
101 |
|
|
c.fill = GridBagConstraints.HORIZONTAL; |
102 |
|
|
c.gridx = 1; |
103 |
|
|
c.gridy = 0; |
104 |
|
|
c.weightx = 1.0; |
105 |
|
|
c.anchor = GridBagConstraints.WEST; |
106 |
|
|
gridbag.setConstraints(cbDefaultEngine, c); |
107 |
|
|
add(cbDefaultEngine); |
108 |
|
|
|
109 |
|
|
c.gridx = 1; |
110 |
|
|
c.gridy = 1; |
111 |
|
|
gridbag.setConstraints(cbMidiInput, c); |
112 |
|
|
add(cbMidiInput); |
113 |
|
|
|
114 |
|
|
c.gridx = 1; |
115 |
|
|
c.gridy = 2; |
116 |
|
|
gridbag.setConstraints(cbAudioOutput, c); |
117 |
|
|
add(cbAudioOutput); |
118 |
|
|
|
119 |
|
|
for(SamplerEngine e : CC.getSamplerModel().getEngines()) { |
120 |
|
|
cbDefaultEngine.addItem(e); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
String defaultEngine = preferences().getStringProperty(DEFAULT_ENGINE); |
124 |
|
|
for(SamplerEngine e : CC.getSamplerModel().getEngines()) { |
125 |
|
|
if(e.getName().equals(defaultEngine)) cbDefaultEngine.setSelectedItem(e); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
cbDefaultEngine.addActionListener(new ActionListener() { |
129 |
|
|
public void |
130 |
|
|
actionPerformed(ActionEvent e) { changeDefaultEngine(); } |
131 |
|
|
}); |
132 |
|
|
|
133 |
|
|
cbMidiInput.addItem(strFirstDevice); |
134 |
|
|
cbMidiInput.addItem(strFirstDeviceNextChannel); |
135 |
|
|
|
136 |
|
|
String s = preferences().getStringProperty(DEFAULT_MIDI_INPUT); |
137 |
|
|
|
138 |
|
|
if(s.equals("firstDevice")) { |
139 |
|
|
cbMidiInput.setSelectedItem(strFirstDevice); |
140 |
|
|
} else if(s.equals("firstDeviceNextChannel")) { |
141 |
|
|
cbMidiInput.setSelectedItem(strFirstDeviceNextChannel); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
cbMidiInput.addActionListener(new ActionListener() { |
145 |
|
|
public void |
146 |
|
|
actionPerformed(ActionEvent e) { changeDefaultMidiInput(); } |
147 |
|
|
}); |
148 |
|
|
|
149 |
|
|
cbAudioOutput.addItem(strFirstDevice); |
150 |
|
|
|
151 |
|
|
cbAudioOutput.addActionListener(new ActionListener() { |
152 |
|
|
public void |
153 |
|
|
actionPerformed(ActionEvent e) { changeDefaultAudioOutput(); } |
154 |
|
|
}); |
155 |
|
|
} |
156 |
|
|
|
157 |
|
|
public JDialog |
158 |
|
|
createDialog(Dialog owner) { |
159 |
|
|
String s = i18n.getLabel("JSChannelsDefaultSettingsPane.title"); |
160 |
|
|
InformationDialog dlg = new InformationDialog(owner, s, this); |
161 |
|
|
return dlg; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
private void |
165 |
|
|
changeDefaultEngine() { |
166 |
|
|
Object o = cbDefaultEngine.getSelectedItem(); |
167 |
|
|
if(o == null) return; |
168 |
|
|
String s = ((SamplerEngine) o).getName(); |
169 |
|
|
preferences().setStringProperty(DEFAULT_ENGINE, s); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
private void |
173 |
|
|
changeDefaultMidiInput() { |
174 |
|
|
Object o = cbMidiInput.getSelectedItem(); |
175 |
|
|
if(o == null) return; |
176 |
|
|
|
177 |
|
|
if(o == strFirstDevice) { |
178 |
|
|
preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDevice"); |
179 |
|
|
} else if(o == strFirstDeviceNextChannel) { |
180 |
|
|
preferences().setStringProperty(DEFAULT_MIDI_INPUT, "firstDeviceNextChannel"); |
181 |
|
|
} |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
private void |
185 |
|
|
changeDefaultAudioOutput() { |
186 |
|
|
Object o = cbAudioOutput.getSelectedItem(); |
187 |
|
|
if(o == null) return; |
188 |
|
|
|
189 |
|
|
if(o == strFirstDevice) { |
190 |
|
|
preferences().setStringProperty(DEFAULT_AUDIO_OUTPUT, "firstDevice"); |
191 |
|
|
} |
192 |
|
|
} |
193 |
|
|
|
194 |
|
|
private static JSPrefs |
195 |
|
|
preferences() { return CC.getViewConfig().preferences(); } |
196 |
|
|
} |