1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2009 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.Dimension; |
26 |
import java.awt.Frame; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import java.awt.event.FocusAdapter; |
35 |
import java.awt.event.FocusEvent; |
36 |
|
37 |
import java.io.File; |
38 |
|
39 |
import javax.swing.BorderFactory; |
40 |
import javax.swing.Box; |
41 |
import javax.swing.BoxLayout; |
42 |
import javax.swing.ButtonGroup; |
43 |
import javax.swing.Icon; |
44 |
import javax.swing.JButton; |
45 |
import javax.swing.JComboBox; |
46 |
import javax.swing.JLabel; |
47 |
import javax.swing.JPanel; |
48 |
import javax.swing.JRadioButton; |
49 |
|
50 |
import javax.swing.event.DocumentEvent; |
51 |
import javax.swing.event.DocumentListener; |
52 |
|
53 |
import net.sf.juife.OkCancelDialog; |
54 |
|
55 |
import net.sf.juife.event.TaskEvent; |
56 |
import net.sf.juife.event.TaskListener; |
57 |
|
58 |
import org.jsampler.CC; |
59 |
import org.jsampler.OrchestraInstrument; |
60 |
import org.jsampler.JSPrefs; |
61 |
import org.jsampler.OrchestraModel; |
62 |
|
63 |
import org.jsampler.task.Global; |
64 |
import org.jsampler.task.InstrumentsDb; |
65 |
|
66 |
import org.linuxsampler.lscp.Instrument; |
67 |
|
68 |
import static org.jsampler.view.std.StdI18n.i18n; |
69 |
import static org.linuxsampler.lscp.Parser.*; |
70 |
|
71 |
/** |
72 |
* |
73 |
* @author Grigor Iliev |
74 |
*/ |
75 |
public class JSInstrumentChooser extends OkCancelDialog { |
76 |
private final JRadioButton rbSelectFromOrchestra = |
77 |
new JRadioButton(i18n.getLabel("JSInstrumentChooser.rbSelectFromOrchestra")); |
78 |
private final JRadioButton rbSelectFromDb = |
79 |
new JRadioButton(i18n.getLabel("JSInstrumentChooser.rbSelectFromDb")); |
80 |
private final JRadioButton rbSelectFromFile = |
81 |
new JRadioButton(i18n.getLabel("JSInstrumentChooser.rbSelectFromFile")); |
82 |
|
83 |
|
84 |
private final JLabel lOrchestra = |
85 |
new JLabel(i18n.getLabel("JSInstrumentChooser.lOrchestra")); |
86 |
|
87 |
private final JLabel lInstrument = |
88 |
new JLabel(i18n.getLabel("JSInstrumentChooser.lInstrument")); |
89 |
|
90 |
private final JComboBox cbOrchestras = new JComboBox(); |
91 |
private final JComboBox cbInstruments = new JComboBox(); |
92 |
|
93 |
|
94 |
private final JComboBox cbDbInstrument = StdUtils.createPathComboBox(); |
95 |
private final JButton btnBrowseDb; |
96 |
|
97 |
private final JLabel lFilename = new JLabel(i18n.getLabel("JSInstrumentChooser.lFilename")); |
98 |
private final JLabel lIndex = new JLabel(i18n.getLabel("JSInstrumentChooser.lIndex")); |
99 |
|
100 |
private final JComboBox cbFilename = StdUtils.createPathComboBox(); |
101 |
private final JComboBox cbIndex = StdUtils.createEnhancedComboBox(); |
102 |
|
103 |
private final JButton btnBrowse; |
104 |
|
105 |
private String instrumentFile = null; |
106 |
private int instrumentIndex = 0; |
107 |
private String engine = null; |
108 |
|
109 |
/** |
110 |
* Creates a new instance of JSInstrumentChooser |
111 |
*/ |
112 |
public JSInstrumentChooser(Frame owner) { |
113 |
super(owner, i18n.getLabel("JSInstrumentChooser.title")); |
114 |
|
115 |
btnOk.setEnabled(false); |
116 |
Icon iconBrowse = CC.getViewConfig().getInstrumentsDbTreeView().getOpenIcon(); |
117 |
btnBrowseDb = new JButton(iconBrowse); |
118 |
btnBrowse = new JButton(iconBrowse); |
119 |
|
120 |
ButtonGroup group = new ButtonGroup(); |
121 |
group.add(rbSelectFromOrchestra); |
122 |
group.add(rbSelectFromDb); |
123 |
group.add(rbSelectFromFile); |
124 |
|
125 |
rbSelectFromOrchestra.addActionListener(getHandler()); |
126 |
rbSelectFromDb.addActionListener(getHandler()); |
127 |
rbSelectFromFile.addActionListener(getHandler()); |
128 |
rbSelectFromOrchestra.doClick(0); |
129 |
|
130 |
cbOrchestras.addFocusListener(getHandler()); |
131 |
cbInstruments.addFocusListener(getHandler()); |
132 |
|
133 |
cbDbInstrument.addFocusListener(getHandler()); |
134 |
cbDbInstrument.addActionListener(getHandler()); |
135 |
cbDbInstrument.addActionListener(new ActionListener() { |
136 |
public void |
137 |
actionPerformed(ActionEvent e) { |
138 |
if(!rbSelectFromDb.isSelected()) rbSelectFromDb.doClick(0); |
139 |
} |
140 |
}); |
141 |
|
142 |
String[] instrs = preferences().getStringListProperty("recentDbInstruments"); |
143 |
for(String s : instrs) cbDbInstrument.addItem(s); |
144 |
cbDbInstrument.setSelectedItem(null); |
145 |
|
146 |
cbFilename.addFocusListener(getHandler()); |
147 |
cbFilename.addActionListener(getHandler()); |
148 |
String[] files = preferences().getStringListProperty("recentInstrumentFiles"); |
149 |
for(String s : files) cbFilename.addItem(s); |
150 |
cbFilename.setSelectedItem(null); |
151 |
|
152 |
cbFilename.addActionListener(new ActionListener() { |
153 |
public void |
154 |
actionPerformed(ActionEvent e) { |
155 |
if(!rbSelectFromFile.isSelected()) rbSelectFromFile.doClick(0); |
156 |
updateFileInstruments(); |
157 |
} |
158 |
}); |
159 |
|
160 |
cbIndex.addFocusListener(getHandler()); |
161 |
cbIndex.addActionListener(getHandler()); |
162 |
cbFilename.addActionListener(new ActionListener() { |
163 |
public void |
164 |
actionPerformed(ActionEvent e) { |
165 |
if(!rbSelectFromFile.isSelected()) rbSelectFromFile.doClick(0); |
166 |
} |
167 |
}); |
168 |
|
169 |
for(int i = 0; i < 101; i++) cbIndex.addItem(i); |
170 |
|
171 |
JPanel mainPane = new JPanel(); |
172 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
173 |
|
174 |
rbSelectFromOrchestra.setAlignmentX(LEFT_ALIGNMENT); |
175 |
mainPane.add(rbSelectFromOrchestra); |
176 |
|
177 |
JPanel orchestraPane = createOrchestraPane(); |
178 |
orchestraPane.setBorder(BorderFactory.createEmptyBorder(0, 32, 17, 0)); |
179 |
mainPane.add(orchestraPane); |
180 |
|
181 |
rbSelectFromDb.setAlignmentX(LEFT_ALIGNMENT); |
182 |
mainPane.add(rbSelectFromDb); |
183 |
|
184 |
JPanel dbPane = createDbPane(); |
185 |
dbPane.setBorder(BorderFactory.createEmptyBorder(0, 32, 17, 0)); |
186 |
mainPane.add(dbPane); |
187 |
|
188 |
rbSelectFromFile.setAlignmentX(LEFT_ALIGNMENT); |
189 |
mainPane.add(rbSelectFromFile); |
190 |
|
191 |
JPanel filePane = createFilePane(); |
192 |
filePane.setBorder(BorderFactory.createEmptyBorder(0, 32, 0, 0)); |
193 |
mainPane.add(filePane); |
194 |
|
195 |
setMainPane(mainPane); |
196 |
|
197 |
if(!CC.getSamplerModel().getServerInfo().hasInstrumentsDbSupport()) { |
198 |
rbSelectFromDb.setEnabled(false); |
199 |
cbDbInstrument.setEnabled(false); |
200 |
btnBrowseDb.setEnabled(false); |
201 |
} else { |
202 |
btnBrowseDb.requestFocusInWindow(); |
203 |
} |
204 |
|
205 |
int i = preferences().getIntProperty("lastUsedOrchestraIndex", 0); |
206 |
if(CC.getOrchestras().getOrchestraCount() > i) { |
207 |
cbOrchestras.setSelectedIndex(i); |
208 |
i = preferences().getIntProperty("lastUsedOrchestraInstrumentIndex", 0); |
209 |
if(cbInstruments.getItemCount() > i) cbInstruments.setSelectedIndex(i); |
210 |
} |
211 |
|
212 |
String s = preferences().getStringProperty("lastUsedInstrumentSelectionMethod"); |
213 |
if("fromOrchestra".equals(s)) { |
214 |
if(!rbSelectFromOrchestra.isSelected()) rbSelectFromOrchestra.doClick(0); |
215 |
cbInstruments.requestFocusInWindow(); |
216 |
} else if("fromDb".equals(s)) { |
217 |
if(!rbSelectFromDb.isSelected()) rbSelectFromDb.doClick(0); |
218 |
} else if("fromFile".equals(s)) { |
219 |
if(!rbSelectFromFile.isSelected()) rbSelectFromFile.doClick(0); |
220 |
btnBrowse.requestFocusInWindow(); |
221 |
} else { |
222 |
if(!rbSelectFromOrchestra.isSelected()) rbSelectFromOrchestra.doClick(0); |
223 |
} |
224 |
|
225 |
updateState(); |
226 |
|
227 |
setMinimumSize(getPreferredSize()); |
228 |
setResizable(true); |
229 |
} |
230 |
|
231 |
private JPanel |
232 |
createOrchestraPane() { |
233 |
GridBagLayout gridbag = new GridBagLayout(); |
234 |
GridBagConstraints c = new GridBagConstraints(); |
235 |
|
236 |
JPanel p = new JPanel(); |
237 |
|
238 |
p.setLayout(gridbag); |
239 |
|
240 |
c.fill = GridBagConstraints.NONE; |
241 |
|
242 |
c.gridx = 0; |
243 |
c.gridy = 0; |
244 |
c.anchor = GridBagConstraints.EAST; |
245 |
c.insets = new Insets(0, 0, 6, 6); |
246 |
gridbag.setConstraints(lOrchestra, c); |
247 |
p.add(lOrchestra); |
248 |
|
249 |
c.gridx = 0; |
250 |
c.gridy = 1; |
251 |
c.insets = new Insets(0, 0, 0, 6); |
252 |
gridbag.setConstraints(lInstrument, c); |
253 |
p.add(lInstrument); |
254 |
|
255 |
c.gridx = 1; |
256 |
c.gridy = 0; |
257 |
c.weightx = 1.0; |
258 |
c.insets = new Insets(0, 0, 6, 0); |
259 |
c.fill = GridBagConstraints.HORIZONTAL; |
260 |
c.anchor = GridBagConstraints.NORTH; |
261 |
gridbag.setConstraints(cbOrchestras, c); |
262 |
p.add(cbOrchestras); |
263 |
|
264 |
c.gridx = 1; |
265 |
c.gridy = 1; |
266 |
c.insets = new Insets(0, 0, 0, 0); |
267 |
gridbag.setConstraints(cbInstruments, c); |
268 |
p.add(cbInstruments); |
269 |
|
270 |
cbOrchestras.addActionListener(new ActionListener() { |
271 |
public void |
272 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
273 |
}); |
274 |
|
275 |
cbInstruments.addActionListener(new ActionListener() { |
276 |
public void |
277 |
actionPerformed(ActionEvent e) { instrumentChanged(); } |
278 |
}); |
279 |
|
280 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
281 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
282 |
} |
283 |
|
284 |
p.setAlignmentX(LEFT_ALIGNMENT); |
285 |
return p; |
286 |
} |
287 |
|
288 |
protected JSPrefs |
289 |
preferences() { return CC.getViewConfig().preferences(); } |
290 |
|
291 |
private void |
292 |
orchestraChanged() { |
293 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
294 |
String s = om == null ? null : om.getDescription(); |
295 |
if(s != null && s.length() == 0) s = null; |
296 |
cbOrchestras.setToolTipText(s); |
297 |
|
298 |
cbInstruments.removeAllItems(); |
299 |
if(om == null || om.getInstrumentCount() == 0) { |
300 |
cbInstruments.setEnabled(false); |
301 |
return; |
302 |
} |
303 |
|
304 |
cbInstruments.setEnabled(true); |
305 |
|
306 |
for(int i = 0; i < om.getInstrumentCount(); i++) { |
307 |
cbInstruments.addItem(om.getInstrument(i)); |
308 |
} |
309 |
} |
310 |
|
311 |
private void |
312 |
instrumentChanged() { |
313 |
OrchestraInstrument instr = (OrchestraInstrument)cbInstruments.getSelectedItem(); |
314 |
String s = instr == null ? null : instr.getDescription(); |
315 |
if(s != null && s.length() == 0) s = null; |
316 |
cbInstruments.setToolTipText(s); |
317 |
|
318 |
btnOk.setEnabled(instr != null); |
319 |
} |
320 |
|
321 |
|
322 |
|
323 |
private JPanel |
324 |
createDbPane() { |
325 |
JPanel p = new JPanel(); |
326 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
327 |
p.add(cbDbInstrument); |
328 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
329 |
btnBrowseDb.setMargin(new Insets(0, 0, 0, 0)); |
330 |
p.add(btnBrowseDb); |
331 |
|
332 |
|
333 |
|
334 |
cbDbInstrument.setPreferredSize ( |
335 |
new Dimension(200, cbDbInstrument.getPreferredSize().height) |
336 |
); |
337 |
|
338 |
btnBrowseDb.addActionListener(new ActionListener() { |
339 |
public void |
340 |
actionPerformed(ActionEvent e) { onBrowseDb(); } |
341 |
}); |
342 |
|
343 |
p.setAlignmentX(LEFT_ALIGNMENT); |
344 |
|
345 |
return p; |
346 |
} |
347 |
|
348 |
private JPanel |
349 |
createFilePane() { |
350 |
GridBagLayout gridbag = new GridBagLayout(); |
351 |
GridBagConstraints c = new GridBagConstraints(); |
352 |
|
353 |
JPanel filePane = new JPanel(); |
354 |
|
355 |
filePane.setLayout(gridbag); |
356 |
|
357 |
c.fill = GridBagConstraints.NONE; |
358 |
|
359 |
c.gridx = 0; |
360 |
c.gridy = 0; |
361 |
c.anchor = GridBagConstraints.EAST; |
362 |
c.insets = new Insets(3, 3, 3, 3); |
363 |
gridbag.setConstraints(lFilename, c); |
364 |
filePane.add(lFilename); |
365 |
|
366 |
c.gridx = 0; |
367 |
c.gridy = 1; |
368 |
gridbag.setConstraints(lIndex, c); |
369 |
filePane.add(lIndex); |
370 |
|
371 |
btnBrowse.setMargin(new Insets(0, 0, 0, 0)); |
372 |
btnBrowse.setToolTipText(i18n.getLabel("JSInstrumentChooser.btnBrowse")); |
373 |
c.gridx = 2; |
374 |
c.gridy = 0; |
375 |
gridbag.setConstraints(btnBrowse, c); |
376 |
filePane.add(btnBrowse); |
377 |
|
378 |
c.fill = GridBagConstraints.HORIZONTAL; |
379 |
c.gridx = 1; |
380 |
c.gridy = 0; |
381 |
c.weightx = 1.0; |
382 |
c.anchor = GridBagConstraints.WEST; |
383 |
gridbag.setConstraints(cbFilename, c); |
384 |
filePane.add(cbFilename); |
385 |
|
386 |
c.gridx = 1; |
387 |
c.gridy = 1; |
388 |
gridbag.setConstraints(cbIndex, c); |
389 |
filePane.add(cbIndex); |
390 |
|
391 |
cbFilename.setPreferredSize ( |
392 |
new Dimension(200, cbFilename.getPreferredSize().height) |
393 |
); |
394 |
|
395 |
btnBrowse.addActionListener(new ActionListener() { |
396 |
public void |
397 |
actionPerformed(ActionEvent e) { onBrowse(); } |
398 |
}); |
399 |
|
400 |
filePane.setAlignmentX(LEFT_ALIGNMENT); |
401 |
return filePane; |
402 |
} |
403 |
|
404 |
protected JSDbInstrumentChooser |
405 |
createDbInstrumentChooser(java.awt.Dialog owner) { |
406 |
return new JSDbInstrumentChooser(owner); |
407 |
} |
408 |
|
409 |
@Override |
410 |
protected void |
411 |
onOk() { |
412 |
if(!btnOk.isEnabled()) return; |
413 |
|
414 |
String s = "lastUsedInstrumentSelectionMethod"; |
415 |
|
416 |
if(rbSelectFromOrchestra.isSelected()) { |
417 |
OrchestraInstrument instr = (OrchestraInstrument)cbInstruments.getSelectedItem(); |
418 |
instrumentFile = instr.getFilePath(); |
419 |
instrumentIndex = instr.getInstrumentIndex(); |
420 |
engine = instr.getEngine(); |
421 |
setVisible(false); |
422 |
|
423 |
int i = cbOrchestras.getSelectedIndex(); |
424 |
if(i >= 0) preferences().setIntProperty("lastUsedOrchestraIndex", i); |
425 |
|
426 |
i = cbInstruments.getSelectedIndex(); |
427 |
if(i >= 0) { |
428 |
preferences().setIntProperty("lastUsedOrchestraInstrumentIndex", i); |
429 |
} |
430 |
|
431 |
preferences().setStringProperty(s, "fromOrchestra"); |
432 |
|
433 |
return; |
434 |
} |
435 |
|
436 |
if(rbSelectFromFile.isSelected()) { |
437 |
instrumentFile = cbFilename.getSelectedItem().toString(); |
438 |
instrumentIndex = cbIndex.getSelectedIndex(); |
439 |
|
440 |
StdUtils.updateRecentElements("recentInstrumentFiles", instrumentFile); |
441 |
preferences().setStringProperty(s, "fromFile"); |
442 |
setVisible(false); |
443 |
return; |
444 |
} |
445 |
|
446 |
if(!rbSelectFromDb.isSelected()) return; |
447 |
|
448 |
preferences().setStringProperty(s, "fromDb"); |
449 |
|
450 |
String instr = cbDbInstrument.getSelectedItem().toString(); |
451 |
preferences().setStringProperty("lastUsedDbInstrument", instr); |
452 |
final InstrumentsDb.GetInstrument t = new InstrumentsDb.GetInstrument(instr); |
453 |
|
454 |
StdUtils.updateRecentElements("recentDbInstruments", instr); |
455 |
|
456 |
t.addTaskListener(new TaskListener() { |
457 |
public void |
458 |
taskPerformed(TaskEvent e) { |
459 |
updateState(); |
460 |
if(t.doneWithErrors()) return; |
461 |
|
462 |
instrumentFile = t.getResult().getFilePath(); |
463 |
instrumentIndex = t.getResult().getInstrumentIndex(); |
464 |
engine = t.getResult().getFormatFamily(); // TODO: fix this |
465 |
setVisible(false); |
466 |
} |
467 |
}); |
468 |
|
469 |
btnOk.setEnabled(false); |
470 |
CC.getTaskQueue().add(t); |
471 |
} |
472 |
|
473 |
protected void |
474 |
onCancel() { setVisible(false); } |
475 |
|
476 |
private void |
477 |
onBrowse() { |
478 |
if(!rbSelectFromFile.isSelected()) rbSelectFromFile.doClick(0); |
479 |
File f = StdUtils.showOpenInstrumentFileChooser(this); |
480 |
if(f == null) return; |
481 |
|
482 |
String path = f.getAbsolutePath(); |
483 |
if(java.io.File.separatorChar == '\\') { |
484 |
path = path.replace('\\', '/'); |
485 |
} |
486 |
cbFilename.setSelectedItem(toEscapedString(path)); |
487 |
btnOk.requestFocusInWindow(); |
488 |
} |
489 |
|
490 |
private void |
491 |
onBrowseDb() { |
492 |
if(!rbSelectFromDb.isSelected()) rbSelectFromDb.doClick(0); |
493 |
JSDbInstrumentChooser dlg; |
494 |
dlg = createDbInstrumentChooser(JSInstrumentChooser.this); |
495 |
Object o = cbDbInstrument.getSelectedItem(); |
496 |
if(o != null && o.toString().length() > 0) dlg.setSelectedInstrument(o.toString()); |
497 |
else { |
498 |
String s = preferences().getStringProperty("lastUsedDbInstrument", ""); |
499 |
if(s.length() > 0) dlg.setSelectedInstrument(s); |
500 |
else dlg.setSelectedDirectory("/"); |
501 |
} |
502 |
dlg.setVisible(true); |
503 |
if(dlg.isCancelled()) return; |
504 |
cbDbInstrument.setSelectedItem(dlg.getSelectedInstrument()); |
505 |
cbDbInstrument.requestFocus(); |
506 |
} |
507 |
|
508 |
/** |
509 |
* Gets the name of the selected instrument file. |
510 |
* @return The name of the selected instrument file. |
511 |
*/ |
512 |
public String |
513 |
getInstrumentFile() { return instrumentFile; } |
514 |
|
515 |
/** |
516 |
* Gets the index of the instrument in the instrument file. |
517 |
* @return The index of the instrument in the instrument file. |
518 |
*/ |
519 |
public int |
520 |
getInstrumentIndex() { return instrumentIndex; } |
521 |
|
522 |
public String |
523 |
getEngine() { return engine; } |
524 |
|
525 |
private void |
526 |
updateState() { |
527 |
boolean b = false; |
528 |
if(rbSelectFromOrchestra.isSelected()) { |
529 |
b = cbInstruments.getSelectedItem() != null; |
530 |
} else if(rbSelectFromDb.isSelected()) { |
531 |
Object o = cbDbInstrument.getSelectedItem(); |
532 |
b = o != null && o.toString().length() > 0; |
533 |
} else if(rbSelectFromFile.isSelected()) { |
534 |
Object o = cbFilename.getSelectedItem(); |
535 |
if(o == null) b = false; |
536 |
else b = o.toString().length() > 0; |
537 |
o = cbIndex.getSelectedItem(); |
538 |
if(o == null || o.toString().length() == 0) b = false; |
539 |
} |
540 |
|
541 |
btnOk.setEnabled(b); |
542 |
} |
543 |
|
544 |
private void |
545 |
updateFileInstruments() { |
546 |
Object o = cbFilename.getSelectedItem(); |
547 |
if(o == null) return; |
548 |
String s = o.toString(); |
549 |
final Global.GetFileInstruments t = new Global.GetFileInstruments(s); |
550 |
|
551 |
t.addTaskListener(new TaskListener() { |
552 |
public void |
553 |
taskPerformed(TaskEvent e) { |
554 |
Instrument[] instrs = t.getResult(); |
555 |
if(instrs == null) { |
556 |
cbIndex.removeAllItems(); |
557 |
for(int i = 0; i < 101; i++) cbIndex.addItem(i); |
558 |
return; |
559 |
} |
560 |
|
561 |
cbIndex.removeAllItems(); |
562 |
for(int i = 0; i < instrs.length; i++) { |
563 |
cbIndex.addItem(i + " - " + instrs[i].getName()); |
564 |
} |
565 |
} |
566 |
}); |
567 |
|
568 |
CC.getTaskQueue().add(t); |
569 |
} |
570 |
|
571 |
private final EventHandler eventHandler = new EventHandler(); |
572 |
|
573 |
private EventHandler |
574 |
getHandler() { return eventHandler; } |
575 |
|
576 |
private class EventHandler extends FocusAdapter |
577 |
implements ActionListener, DocumentListener { |
578 |
|
579 |
@Override |
580 |
public void |
581 |
actionPerformed(ActionEvent e) { |
582 |
updateState(); |
583 |
} |
584 |
|
585 |
// DocumentListener |
586 |
@Override |
587 |
public void |
588 |
insertUpdate(DocumentEvent e) { updateState(); } |
589 |
|
590 |
@Override |
591 |
public void |
592 |
removeUpdate(DocumentEvent e) { updateState(); } |
593 |
|
594 |
@Override |
595 |
public void |
596 |
changedUpdate(DocumentEvent e) { updateState(); } |
597 |
|
598 |
// FocusListener |
599 |
@Override |
600 |
public void |
601 |
focusGained(FocusEvent e) { |
602 |
Object src = e.getSource(); |
603 |
if(src == cbInstruments || src == cbOrchestras) { |
604 |
if(!rbSelectFromOrchestra.isSelected()) { |
605 |
rbSelectFromOrchestra.doClick(0); |
606 |
} |
607 |
} else if(src == cbDbInstrument) { |
608 |
if(!rbSelectFromDb.isSelected()) rbSelectFromDb.doClick(0); |
609 |
} else if(src == cbFilename || src == cbIndex) { |
610 |
if(!rbSelectFromFile.isSelected()) rbSelectFromFile.doClick(0); |
611 |
} |
612 |
} |
613 |
} |
614 |
} |