35 |
import javax.swing.JFileChooser; |
import javax.swing.JFileChooser; |
36 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
37 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
|
import javax.swing.JSpinner; |
|
38 |
import javax.swing.JTextField; |
import javax.swing.JTextField; |
|
import javax.swing.SpinnerNumberModel; |
|
39 |
|
|
40 |
import javax.swing.event.DocumentEvent; |
import javax.swing.event.DocumentEvent; |
41 |
import javax.swing.event.DocumentListener; |
import javax.swing.event.DocumentListener; |
42 |
|
|
43 |
import net.sf.juife.OkCancelDialog; |
import net.sf.juife.OkCancelDialog; |
44 |
|
|
45 |
|
import net.sf.juife.event.TaskEvent; |
46 |
|
import net.sf.juife.event.TaskListener; |
47 |
|
|
48 |
import org.jsampler.CC; |
import org.jsampler.CC; |
49 |
import org.jsampler.Instrument; |
import org.jsampler.OrchestraInstrument; |
50 |
import org.jsampler.JSPrefs; |
import org.jsampler.JSPrefs; |
51 |
|
|
52 |
|
import org.jsampler.task.Global; |
53 |
|
|
54 |
|
import org.linuxsampler.lscp.Instrument; |
55 |
|
|
56 |
import static org.jsampler.view.std.StdI18n.i18n; |
import static org.jsampler.view.std.StdI18n.i18n; |
57 |
import static org.linuxsampler.lscp.Parser.*; |
import static org.linuxsampler.lscp.Parser.*; |
58 |
|
|
73 |
private final JTextField tfName = new JTextField(); |
private final JTextField tfName = new JTextField(); |
74 |
private final JTextField tfDesc = new JTextField(); |
private final JTextField tfDesc = new JTextField(); |
75 |
private final JComboBox cbPath = new JComboBox(); |
private final JComboBox cbPath = new JComboBox(); |
76 |
private final JSpinner spinnerIndex = new JSpinner(new SpinnerNumberModel(0, 0, 500, 1)); |
private final JComboBox cbIndex = new JComboBox(); |
77 |
|
|
78 |
private Instrument instrument; |
private OrchestraInstrument instrument; |
79 |
|
|
80 |
|
|
81 |
/** |
/** |
82 |
* Creates a new instance of <code>JSAddOrEditInstrumentDlg</code>. |
* Creates a new instance of <code>JSAddOrEditInstrumentDlg</code>. |
83 |
*/ |
*/ |
84 |
public JSAddOrEditInstrumentDlg() { this(new Instrument()); } |
public JSAddOrEditInstrumentDlg() { this(new OrchestraInstrument()); } |
85 |
|
|
86 |
/** |
/** |
87 |
* Creates a new instance of <code>JSAddOrEditInstrumentDlg</code>. |
* Creates a new instance of <code>JSAddOrEditInstrumentDlg</code>. |
88 |
* |
* |
89 |
* @param instr The instrument to modify. |
* @param instr The instrument to modify. |
90 |
*/ |
*/ |
91 |
public JSAddOrEditInstrumentDlg(Instrument instr) { |
public JSAddOrEditInstrumentDlg(OrchestraInstrument instr) { |
92 |
super(CC.getMainFrame(), i18n.getLabel("JSAddOrEditInstrumentDlg.title")); |
super(CC.getMainFrame(), i18n.getLabel("JSAddOrEditInstrumentDlg.title")); |
93 |
|
|
94 |
instrument = instr; |
instrument = instr; |
158 |
gridbag.setConstraints(cbPath, c); |
gridbag.setConstraints(cbPath, c); |
159 |
p.add(cbPath); |
p.add(cbPath); |
160 |
|
|
161 |
|
for(int i = 0; i < 101; i++) cbIndex.addItem(i); |
162 |
|
|
163 |
c.gridx = 1; |
c.gridx = 1; |
164 |
c.gridy = 3; |
c.gridy = 3; |
165 |
c.gridwidth = 2; |
c.gridwidth = 2; |
166 |
gridbag.setConstraints(spinnerIndex, c); |
gridbag.setConstraints(cbIndex, c); |
167 |
p.add(spinnerIndex); |
p.add(cbIndex); |
168 |
|
|
169 |
setMainPane(p); |
setMainPane(p); |
170 |
|
|
179 |
btnBrowse.addActionListener(getHandler()); |
btnBrowse.addActionListener(getHandler()); |
180 |
cbPath.addActionListener(new ActionListener() { |
cbPath.addActionListener(new ActionListener() { |
181 |
public void |
public void |
182 |
actionPerformed(ActionEvent e) { updateState(); } |
actionPerformed(ActionEvent e) { |
183 |
|
updateState(); |
184 |
|
updateFileInstruments(); |
185 |
|
} |
186 |
}); |
}); |
187 |
|
|
188 |
updateInfo(); |
updateInfo(); |
196 |
updateInfo() { |
updateInfo() { |
197 |
tfName.setText(getInstrument().getName()); |
tfName.setText(getInstrument().getName()); |
198 |
tfDesc.setText(getInstrument().getDescription()); |
tfDesc.setText(getInstrument().getDescription()); |
199 |
cbPath.setSelectedItem(getInstrument().getPath()); |
cbPath.setSelectedItem(getInstrument().getFilePath()); |
200 |
spinnerIndex.setValue(getInstrument().getInstrumentIndex()); |
cbIndex.setSelectedIndex(getInstrument().getInstrumentIndex()); |
201 |
} |
} |
202 |
|
|
203 |
private void |
private void |
206 |
if(tfName.getText().length() == 0) b = false; |
if(tfName.getText().length() == 0) b = false; |
207 |
Object o = cbPath.getSelectedItem(); |
Object o = cbPath.getSelectedItem(); |
208 |
if(o == null || o.toString().length() == 0) b = false; |
if(o == null || o.toString().length() == 0) b = false; |
209 |
|
o = cbIndex.getSelectedItem(); |
210 |
|
if(o == null || o.toString().length() == 0) b = false; |
211 |
|
|
212 |
btnOk.setEnabled(b); |
btnOk.setEnabled(b); |
213 |
} |
} |
214 |
|
|
215 |
|
private boolean init = true; |
216 |
|
|
217 |
|
private void |
218 |
|
updateFileInstruments() { |
219 |
|
Object o = cbPath.getSelectedItem(); |
220 |
|
if(o == null) return; |
221 |
|
String s = o.toString(); |
222 |
|
final Global.GetFileInstruments t = new Global.GetFileInstruments(s); |
223 |
|
|
224 |
|
t.addTaskListener(new TaskListener() { |
225 |
|
public void |
226 |
|
taskPerformed(TaskEvent e) { |
227 |
|
Instrument[] instrs = t.getResult(); |
228 |
|
if(instrs == null) { |
229 |
|
cbIndex.removeAllItems(); |
230 |
|
for(int i = 0; i < 101; i++) cbIndex.addItem(i); |
231 |
|
return; |
232 |
|
} else { |
233 |
|
|
234 |
|
cbIndex.removeAllItems(); |
235 |
|
for(int i = 0; i < instrs.length; i++) { |
236 |
|
cbIndex.addItem(i + " - " + instrs[i].getName()); |
237 |
|
} |
238 |
|
} |
239 |
|
|
240 |
|
if(init) { |
241 |
|
int i = getInstrument().getInstrumentIndex(); |
242 |
|
cbIndex.setSelectedIndex(i); |
243 |
|
init = false; |
244 |
|
} |
245 |
|
} |
246 |
|
}); |
247 |
|
|
248 |
|
CC.getTaskQueue().add(t); |
249 |
|
} |
250 |
|
|
251 |
protected void |
protected void |
252 |
onOk() { |
onOk() { |
253 |
if(!btnOk.isEnabled()) return; |
if(!btnOk.isEnabled()) return; |
254 |
|
|
255 |
instrument.setName(tfName.getText()); |
instrument.setName(tfName.getText()); |
256 |
instrument.setDescription(tfDesc.getText()); |
instrument.setDescription(tfDesc.getText()); |
257 |
instrument.setPath(cbPath.getSelectedItem().toString()); |
instrument.setFilePath(cbPath.getSelectedItem().toString()); |
258 |
int idx = Integer.parseInt(spinnerIndex.getValue().toString()); |
int idx = cbIndex.getSelectedIndex(); |
259 |
instrument.setInstrumentIndex(idx); |
instrument.setInstrumentIndex(idx); |
260 |
|
|
261 |
StdUtils.updateRecentElements("recentInstrumentFiles", instrument.getPath()); |
StdUtils.updateRecentElements("recentInstrumentFiles", instrument.getFilePath()); |
262 |
|
|
263 |
setVisible(false); |
setVisible(false); |
264 |
setCancelled(false); |
setCancelled(false); |
273 |
* Gets the created/modified orchestra. |
* Gets the created/modified orchestra. |
274 |
* @return The created/modified orchestra. |
* @return The created/modified orchestra. |
275 |
*/ |
*/ |
276 |
public Instrument |
public OrchestraInstrument |
277 |
getInstrument() { return instrument; } |
getInstrument() { return instrument; } |
278 |
|
|
279 |
|
|