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