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 |
import java.awt.Frame; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
31 |
|
32 |
import javax.swing.JComboBox; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JSlider; |
36 |
import javax.swing.JSpinner; |
37 |
import javax.swing.JTextField; |
38 |
import javax.swing.SpinnerNumberModel; |
39 |
|
40 |
import javax.swing.event.DocumentEvent; |
41 |
import javax.swing.event.DocumentListener; |
42 |
|
43 |
import net.sf.juife.OkCancelDialog; |
44 |
|
45 |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
46 |
|
47 |
import static org.jsampler.view.std.StdI18n.i18n; |
48 |
|
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class JSAddMidiInstrumentDlg extends OkCancelDialog { |
55 |
private final JLabel lName = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lName")); |
56 |
private final JLabel lBank = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lBank")); |
57 |
private final JLabel lProgram = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lProgram")); |
58 |
private final JLabel lVolume = new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lVolume")); |
59 |
private final JLabel lLoadMode = |
60 |
new JLabel(i18n.getLabel("JSAddMidiInstrumentDlg.lLoadMode")); |
61 |
|
62 |
private final JTextField tfName = new JTextField(); |
63 |
private final JSpinner spinnerBank = new JSpinner(new SpinnerNumberModel(0, 0, 16383, 1)); |
64 |
private final JComboBox cbProgram = new JComboBox(); |
65 |
private final JSlider slVolume = new JSlider(0, 100, 100); |
66 |
private final JComboBox cbLoadMode = new JComboBox(); |
67 |
|
68 |
/** |
69 |
* Creates a new instance of <code>JSAddMidiInstrumentDlg</code> |
70 |
*/ |
71 |
public |
72 |
JSAddMidiInstrumentDlg(Frame owner) { |
73 |
super(owner, i18n.getLabel("JSAddMidiInstrumentDlg.title")); |
74 |
initAddMidiInstrumentDlg(); |
75 |
} |
76 |
|
77 |
/** |
78 |
* Creates a new instance of <code>JSAddMidiInstrumentDlg</code> |
79 |
*/ |
80 |
public |
81 |
JSAddMidiInstrumentDlg(Dialog owner) { |
82 |
super(owner, i18n.getLabel("JSAddMidiInstrumentDlg.title")); |
83 |
initAddMidiInstrumentDlg(); |
84 |
} |
85 |
|
86 |
private void |
87 |
initAddMidiInstrumentDlg() { |
88 |
JPanel mainPane = new JPanel(); |
89 |
GridBagLayout gridbag = new GridBagLayout(); |
90 |
GridBagConstraints c = new GridBagConstraints(); |
91 |
|
92 |
mainPane.setLayout(gridbag); |
93 |
|
94 |
c.fill = GridBagConstraints.NONE; |
95 |
|
96 |
c.gridx = 0; |
97 |
c.gridy = 0; |
98 |
c.anchor = GridBagConstraints.EAST; |
99 |
c.insets = new Insets(3, 3, 3, 3); |
100 |
gridbag.setConstraints(lName, c); |
101 |
mainPane.add(lName); |
102 |
|
103 |
c.gridx = 0; |
104 |
c.gridy = 2; |
105 |
gridbag.setConstraints(lBank, c); |
106 |
mainPane.add(lBank); |
107 |
|
108 |
c.gridx = 0; |
109 |
c.gridy = 3; |
110 |
gridbag.setConstraints(lProgram, c); |
111 |
mainPane.add(lProgram); |
112 |
|
113 |
c.gridx = 0; |
114 |
c.gridy = 4; |
115 |
gridbag.setConstraints(lLoadMode, c); |
116 |
mainPane.add(lLoadMode); |
117 |
|
118 |
c.gridx = 0; |
119 |
c.gridy = 1; |
120 |
c.insets = new Insets(3, 3, 24, 3); |
121 |
gridbag.setConstraints(lVolume, c); |
122 |
mainPane.add(lVolume); |
123 |
|
124 |
c.fill = GridBagConstraints.HORIZONTAL; |
125 |
c.gridx = 1; |
126 |
c.gridy = 0; |
127 |
c.weightx = 1.0; |
128 |
c.insets = new Insets(3, 3, 3, 3); |
129 |
c.anchor = GridBagConstraints.WEST; |
130 |
gridbag.setConstraints(tfName, c); |
131 |
mainPane.add(tfName); |
132 |
|
133 |
c.gridx = 1; |
134 |
c.gridy = 2; |
135 |
gridbag.setConstraints(spinnerBank, c); |
136 |
mainPane.add(spinnerBank); |
137 |
|
138 |
c.gridx = 1; |
139 |
c.gridy = 3; |
140 |
gridbag.setConstraints(cbProgram, c); |
141 |
mainPane.add(cbProgram); |
142 |
|
143 |
c.gridx = 1; |
144 |
c.gridy = 4; |
145 |
gridbag.setConstraints(cbLoadMode, c); |
146 |
mainPane.add(cbLoadMode); |
147 |
|
148 |
c.gridx = 1; |
149 |
c.gridy = 1; |
150 |
c.insets = new Insets(3, 3, 24, 3); |
151 |
gridbag.setConstraints(slVolume, c); |
152 |
mainPane.add(slVolume); |
153 |
|
154 |
setMainPane(mainPane); |
155 |
|
156 |
setResizable(true); |
157 |
setMinimumSize(getPreferredSize()); |
158 |
|
159 |
for(int i = 0; i < 128; i++) cbProgram.addItem(new Integer(i)); |
160 |
|
161 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.DEFAULT); |
162 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND); |
163 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.ON_DEMAND_HOLD); |
164 |
cbLoadMode.addItem(MidiInstrumentInfo.LoadMode.PERSISTENT); |
165 |
|
166 |
tfName.getDocument().addDocumentListener(getHandler()); |
167 |
}/** |
168 |
* Gets the selected MIDI bank. |
169 |
*/ |
170 |
public int |
171 |
getMidiBank() { return Integer.parseInt(spinnerBank.getValue().toString()); } |
172 |
|
173 |
/** |
174 |
* Gets the selected MIDI program. |
175 |
*/ |
176 |
public int |
177 |
getMidiProgram() { return cbProgram.getSelectedIndex(); } |
178 |
|
179 |
/** |
180 |
* Gets the chosen name for the new MIDI instrument. |
181 |
* @return The chosen name for the new MIDI instrument. |
182 |
*/ |
183 |
public String |
184 |
getInstrumentName() { return tfName.getText(); } |
185 |
|
186 |
/** |
187 |
* Sets the name for the new MIDI instrument. |
188 |
* @param name The name for the new MIDI instrument. |
189 |
*/ |
190 |
public void |
191 |
setInstrumentName(String name) { tfName.setText(name); } |
192 |
|
193 |
/** |
194 |
* Returns the volume level of the new MIDI instrument. |
195 |
* @return The volume level of the new MIDI instrument. |
196 |
*/ |
197 |
public float |
198 |
getVolume() { |
199 |
float f = slVolume.getValue(); |
200 |
f /= 100; |
201 |
return f; |
202 |
} |
203 |
|
204 |
/** Gets the selected load mode. */ |
205 |
public MidiInstrumentInfo.LoadMode |
206 |
getLoadMode() { return (MidiInstrumentInfo.LoadMode) cbLoadMode.getSelectedItem(); } |
207 |
|
208 |
protected void |
209 |
onOk() { |
210 |
if(!btnOk.isEnabled()) return; |
211 |
setCancelled(false); |
212 |
setVisible(false); |
213 |
} |
214 |
|
215 |
protected void |
216 |
onCancel() { setVisible(false); } |
217 |
|
218 |
private void |
219 |
updateState() { |
220 |
boolean b = tfName.getText().length() > 0; |
221 |
b = b && cbProgram.getSelectedItem() != null; |
222 |
btnOk.setEnabled(b); |
223 |
} |
224 |
|
225 |
private final Handler eventHandler = new Handler(); |
226 |
|
227 |
private Handler |
228 |
getHandler() { return eventHandler; } |
229 |
|
230 |
private class Handler implements DocumentListener { |
231 |
// DocumentListener |
232 |
public void |
233 |
insertUpdate(DocumentEvent e) { updateState(); } |
234 |
|
235 |
public void |
236 |
removeUpdate(DocumentEvent e) { updateState(); } |
237 |
|
238 |
public void |
239 |
changedUpdate(DocumentEvent e) { updateState(); } |
240 |
} |
241 |
} |