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.Component; |
26 |
import java.awt.Dialog; |
27 |
import java.awt.Frame; |
28 |
import java.awt.Window; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.KeyEvent; |
32 |
import java.awt.event.MouseAdapter; |
33 |
import java.awt.event.MouseEvent; |
34 |
|
35 |
import java.util.Vector; |
36 |
|
37 |
import javax.swing.AbstractAction; |
38 |
import javax.swing.Action; |
39 |
import javax.swing.BorderFactory; |
40 |
import javax.swing.Icon; |
41 |
import javax.swing.JComponent; |
42 |
import javax.swing.JLabel; |
43 |
import javax.swing.JMenu; |
44 |
import javax.swing.JMenuItem; |
45 |
import javax.swing.JPanel; |
46 |
import javax.swing.JPopupMenu; |
47 |
import javax.swing.JTable; |
48 |
import javax.swing.KeyStroke; |
49 |
import javax.swing.SwingUtilities; |
50 |
|
51 |
import javax.swing.event.ChangeEvent; |
52 |
import javax.swing.event.ChangeListener; |
53 |
import javax.swing.event.ListSelectionEvent; |
54 |
import javax.swing.event.ListSelectionListener; |
55 |
import javax.swing.event.TreeSelectionEvent; |
56 |
import javax.swing.event.TreeSelectionListener; |
57 |
|
58 |
import javax.swing.table.TableCellRenderer; |
59 |
|
60 |
import net.sf.juife.InformationDialog; |
61 |
import net.sf.juife.JuifeUtils; |
62 |
import net.sf.juife.Task; |
63 |
|
64 |
import net.sf.juife.event.TaskEvent; |
65 |
import net.sf.juife.event.TaskListener; |
66 |
|
67 |
import org.jsampler.CC; |
68 |
import org.jsampler.HF; |
69 |
import org.jsampler.OrchestraInstrument; |
70 |
import org.jsampler.MidiInstrumentMap; |
71 |
import org.jsampler.OrchestraModel; |
72 |
import org.jsampler.SamplerChannelModel; |
73 |
|
74 |
import org.jsampler.event.ListEvent; |
75 |
import org.jsampler.event.ListListener; |
76 |
import org.jsampler.event.SamplerChannelListEvent; |
77 |
import org.jsampler.event.SamplerChannelListListener; |
78 |
|
79 |
import org.jsampler.task.InstrumentsDb; |
80 |
|
81 |
import org.jsampler.view.DbClipboard; |
82 |
import org.jsampler.view.DbDirectoryTreeNode; |
83 |
import org.jsampler.view.InstrumentsDbTableModel; |
84 |
|
85 |
import org.jsampler.view.JSChannelsPane; |
86 |
|
87 |
import org.linuxsampler.lscp.DbDirectoryInfo; |
88 |
import org.linuxsampler.lscp.DbInstrumentInfo; |
89 |
|
90 |
import static org.jsampler.view.InstrumentsDbTableModel.ColumnType; |
91 |
import static org.jsampler.view.std.StdI18n.i18n; |
92 |
|
93 |
import static org.linuxsampler.lscp.Parser.*; |
94 |
|
95 |
/** |
96 |
* |
97 |
* @author Grigor Iliev |
98 |
*/ |
99 |
public class JSInstrumentsDbTable extends org.jsampler.view.AbstractInstrumentsDbTable { |
100 |
private JSInstrumentsDbTree instrumentsDbTree; |
101 |
private InstrumentsDbCellRenderer cellRenderer = new InstrumentsDbCellRenderer(); |
102 |
|
103 |
public final Action reloadAction = new ReloadAction(); |
104 |
public final Action createDirectoryAction = new CreateDirectoryAction(); |
105 |
public final Action deleteAction = new DeleteAction(); |
106 |
public final AddInstrumentsFromFileAction addInstrumentsFromFileAction = |
107 |
new AddInstrumentsFromFileAction(); |
108 |
public final AddInstrumentsFromDirAction addInstrumentsFromDirAction = |
109 |
new AddInstrumentsFromDirAction(); |
110 |
public final Action propertiesAction = new PropertiesAction(); |
111 |
public final Action renameAction = new RenameAction(); |
112 |
public final Action changeDescriptionAction = new ChangeDescriptionAction(); |
113 |
public final Action cutAction = new CutAction(); |
114 |
public final Action copyAction = new CopyAction(); |
115 |
public final Action pasteAction; |
116 |
|
117 |
private static final DbClipboard dbClipboard = new DbClipboard(); |
118 |
|
119 |
/** |
120 |
* Creates a new instance of <code>JSInstrumentsDbTable</code> |
121 |
*/ |
122 |
public |
123 |
JSInstrumentsDbTable(JSInstrumentsDbTree tree) { |
124 |
this(tree, ""); |
125 |
} |
126 |
|
127 |
/** |
128 |
* Creates a new instance of <code>JSInstrumentsDbTable</code> |
129 |
* @param columnPrefix Used to create unique property names for storing |
130 |
* the column preferences for different tables e.g. for DbInstrumentChooser, |
131 |
* InstrumentsDbFrame. |
132 |
*/ |
133 |
public |
134 |
JSInstrumentsDbTable(JSInstrumentsDbTree tree, String columnPrefix) { |
135 |
super(columnPrefix); |
136 |
|
137 |
instrumentsDbTree = tree; |
138 |
|
139 |
/*for(int i = 0; i < getColumnModel().getColumnCount(); i++) { |
140 |
getColumnModel().getColumn(i).setMinWidth(50); |
141 |
}*/ |
142 |
|
143 |
setShowGrid(false); |
144 |
getColumnModel().setColumnMargin(0); |
145 |
getTableHeader().setReorderingAllowed(false); |
146 |
|
147 |
setFillsViewportHeight(true); |
148 |
|
149 |
addMouseListener(new MouseAdapter() { |
150 |
public void |
151 |
mouseClicked(MouseEvent e) { |
152 |
if(e.getButton() != e.BUTTON1) return; |
153 |
int r = rowAtPoint(e.getPoint()); |
154 |
if(r == -1) { |
155 |
clearSelection(); |
156 |
return; |
157 |
} |
158 |
|
159 |
if(e.getClickCount() < 2) return; |
160 |
|
161 |
DbDirectoryTreeNode node = getSelectedDirectoryNode(); |
162 |
if(node == null) return; |
163 |
if(!node.isDetached()) { |
164 |
instrumentsDbTree.setSelectedDirectoryNode(node); |
165 |
} else { |
166 |
String s = node.getInfo().getDirectoryPath(); |
167 |
instrumentsDbTree.setSelectedDirectory(s); |
168 |
} |
169 |
} |
170 |
}); |
171 |
|
172 |
addMouseListener(new MouseAdapter() { |
173 |
public void |
174 |
mousePressed(MouseEvent e) { |
175 |
int r = rowAtPoint(e.getPoint()); |
176 |
|
177 |
if(e.getButton() != e.BUTTON1 && e.getButton() != e.BUTTON3) return; |
178 |
if(r == -1) { |
179 |
clearSelection(); |
180 |
return; |
181 |
} |
182 |
|
183 |
if(e.getButton() != e.BUTTON3) return; |
184 |
if(getSelectionModel().isSelectedIndex(r)) { |
185 |
getSelectionModel().addSelectionInterval(r, r); |
186 |
} else { |
187 |
getSelectionModel().setSelectionInterval(r, r); |
188 |
} |
189 |
} |
190 |
}); |
191 |
|
192 |
getSelectionModel().addListSelectionListener(getHandler()); |
193 |
|
194 |
instrumentsDbTree.addTreeSelectionListener(getHandler()); |
195 |
|
196 |
PasteAction pasteAction = new PasteAction(); |
197 |
instrumentsDbTree.addTreeSelectionListener(pasteAction); |
198 |
this.pasteAction = pasteAction; |
199 |
|
200 |
ContextMenu contextMenu = new ContextMenu(); |
201 |
addMouseListener(contextMenu); |
202 |
|
203 |
CC.getOrchestras().addOrchestraListListener(getHandler()); |
204 |
CC.getSamplerModel().addSamplerChannelListListener(getHandler()); |
205 |
|
206 |
CC.getMainFrame().addChannelsPaneSelectionListener(new ListSelectionListener() { |
207 |
public void |
208 |
valueChanged(ListSelectionEvent e) { |
209 |
updateLoadInstrumentMenus(); |
210 |
} |
211 |
}); |
212 |
|
213 |
ListListener<MidiInstrumentMap> l = new ListListener<MidiInstrumentMap>() { |
214 |
public void |
215 |
entryAdded(ListEvent<MidiInstrumentMap> e) { updateAddToMidiMapMenus(); } |
216 |
|
217 |
public void |
218 |
entryRemoved(ListEvent<MidiInstrumentMap> e) { updateAddToMidiMapMenus(); } |
219 |
}; |
220 |
|
221 |
CC.getSamplerModel().addMidiInstrumentMapListListener(l); |
222 |
|
223 |
installKeyboardListeners(); |
224 |
} |
225 |
|
226 |
public static DbClipboard |
227 |
getDbClipboard() { return dbClipboard; } |
228 |
|
229 |
@Override |
230 |
public TableCellRenderer |
231 |
getCellRenderer(int row, int column) { |
232 |
return cellRenderer; |
233 |
} |
234 |
|
235 |
private void |
236 |
installKeyboardListeners() { |
237 |
AbstractAction a = new AbstractAction() { |
238 |
public void |
239 |
actionPerformed(ActionEvent e) { } |
240 |
}; |
241 |
a.setEnabled(false); |
242 |
getActionMap().put("none", a); |
243 |
|
244 |
int modKey = CC.getViewConfig().getDefaultModKey(); |
245 |
|
246 |
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put ( |
247 |
KeyStroke.getKeyStroke(KeyEvent.VK_X, modKey), |
248 |
"none" |
249 |
); |
250 |
|
251 |
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put ( |
252 |
KeyStroke.getKeyStroke(KeyEvent.VK_C, modKey), |
253 |
"none" |
254 |
); |
255 |
|
256 |
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put ( |
257 |
KeyStroke.getKeyStroke(KeyEvent.VK_V, modKey), |
258 |
"none" |
259 |
); |
260 |
|
261 |
getInputMap(JComponent.WHEN_FOCUSED).put ( |
262 |
KeyStroke.getKeyStroke(KeyEvent.VK_X, modKey), |
263 |
"none" |
264 |
); |
265 |
|
266 |
getInputMap(JComponent.WHEN_FOCUSED).put ( |
267 |
KeyStroke.getKeyStroke(KeyEvent.VK_C, modKey), |
268 |
"none" |
269 |
); |
270 |
|
271 |
getInputMap(JComponent.WHEN_FOCUSED).put ( |
272 |
KeyStroke.getKeyStroke(KeyEvent.VK_V, modKey), |
273 |
"none" |
274 |
); |
275 |
|
276 |
getInputMap().put ( |
277 |
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), |
278 |
"OpenDirectory" |
279 |
); |
280 |
|
281 |
getActionMap().put ("OpenDirectory", new AbstractAction() { |
282 |
public void |
283 |
actionPerformed(ActionEvent e) { |
284 |
DbDirectoryTreeNode node = getSelectedDirectoryNode(); |
285 |
if(node == null) return; |
286 |
instrumentsDbTree.setSelectedDirectoryNode(node); |
287 |
} |
288 |
}); |
289 |
} |
290 |
|
291 |
public String |
292 |
getUniqueDirectoryName() { |
293 |
DbDirectoryTreeNode node = getParentDirectoryNode(); |
294 |
if(node == null || node.isDetached()) return null; |
295 |
if(node != instrumentsDbTree.getSelectedDirectoryNode()) return null; |
296 |
|
297 |
boolean b = false; |
298 |
int c = 2; |
299 |
String dir = "New Folder"; |
300 |
|
301 |
while(true) { |
302 |
for(int i = 0; i < node.getChildCount(); i++) { |
303 |
|
304 |
if(dir.equals(node.getChildAt(i).getInfo().getName())) { |
305 |
b = true; |
306 |
break; |
307 |
} |
308 |
} |
309 |
|
310 |
if(!b) break; |
311 |
|
312 |
b = false; |
313 |
dir = "New Folder[" + c++ + "]"; |
314 |
} |
315 |
|
316 |
return dir; |
317 |
} |
318 |
|
319 |
private final Vector<JMenu> loadInstrumentMenus = new Vector<JMenu>(); |
320 |
private final Vector<JMenu> addToMidiMapMenus = new Vector<JMenu>(); |
321 |
private final Vector<JMenu> addToOrchestraMenus = new Vector<JMenu>(); |
322 |
|
323 |
public void |
324 |
registerLoadInstrumentMenus(JMenu menu) { |
325 |
loadInstrumentMenus.add(menu); |
326 |
StdA4n.updateLoadInstrumentMenu(menu, loadInstrActionFactory); |
327 |
updateLoadInstrumentMenuState(menu); |
328 |
} |
329 |
|
330 |
public void |
331 |
registerAddToMidiMapMenu(JMenu menu) { |
332 |
addToMidiMapMenus.add(menu); |
333 |
updateAddToMidiMapMenu(menu); |
334 |
} |
335 |
|
336 |
public void |
337 |
registerAddToOrchestraMenu(JMenu menu) { |
338 |
addToOrchestraMenus.add(menu); |
339 |
updateAddToOrchestraMenu(menu); |
340 |
} |
341 |
|
342 |
private void |
343 |
updateLoadInstrumentMenus() { |
344 |
for(JMenu menu : loadInstrumentMenus) { |
345 |
StdA4n.updateLoadInstrumentMenu(menu, loadInstrActionFactory); |
346 |
updateLoadInstrumentMenuState(menu); |
347 |
} |
348 |
} |
349 |
|
350 |
private void |
351 |
updateLoadInstrumentMenuStates() { |
352 |
for(JMenu menu : loadInstrumentMenus) updateLoadInstrumentMenuState(menu); |
353 |
} |
354 |
|
355 |
private void |
356 |
updateLoadInstrumentMenuState(JMenu menu) { |
357 |
Object obj = getLeadObject(); |
358 |
boolean b = obj == null || !(obj instanceof DbInstrumentInfo); |
359 |
b = b || CC.getSamplerModel().getChannelCount() == 0; |
360 |
menu.setEnabled(!b); |
361 |
} |
362 |
|
363 |
private void |
364 |
updateAddToMidiMapMenus() { |
365 |
for(JMenu menu : addToMidiMapMenus) updateAddToMidiMapMenu(menu); |
366 |
} |
367 |
|
368 |
private void |
369 |
updateAddToMidiMapMenu(JMenu menu) { |
370 |
menu.removeAll(); |
371 |
for(int i = 0; i < CC.getSamplerModel().getMidiInstrumentMapCount(); i++) { |
372 |
MidiInstrumentMap m = CC.getSamplerModel().getMidiInstrumentMap(i); |
373 |
menu.add(new JMenuItem(new AddToMidiMapAction(m))); |
374 |
} |
375 |
|
376 |
updateAddToMidiMapMenuState(menu); |
377 |
} |
378 |
|
379 |
private void |
380 |
updateAddToMidiMapMenuStates() { |
381 |
for(JMenu menu : addToMidiMapMenus) updateAddToMidiMapMenuState(menu); |
382 |
} |
383 |
|
384 |
private void |
385 |
updateAddToMidiMapMenuState(JMenu menu) { |
386 |
Object obj = getLeadObject(); |
387 |
boolean b = obj == null || !(obj instanceof DbInstrumentInfo); |
388 |
b = b || CC.getSamplerModel().getMidiInstrumentMapCount() == 0; |
389 |
menu.setEnabled(!b); |
390 |
} |
391 |
|
392 |
private void |
393 |
updateAddToOrchestraMenus() { |
394 |
for(JMenu menu : addToOrchestraMenus) updateAddToOrchestraMenu(menu); |
395 |
} |
396 |
|
397 |
private void |
398 |
updateAddToOrchestraMenu(JMenu menu) { |
399 |
menu.removeAll(); |
400 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
401 |
OrchestraModel m = CC.getOrchestras().getOrchestra(i); |
402 |
Action a = new AddToOrchestraAction(m); |
403 |
menu.add(new JMenuItem(a)); |
404 |
} |
405 |
|
406 |
updateAddToOrchestraMenuState(menu); |
407 |
} |
408 |
|
409 |
private void |
410 |
updateAddToOrchestraMenuStates() { |
411 |
for(JMenu menu : addToOrchestraMenus) updateAddToOrchestraMenuState(menu); |
412 |
} |
413 |
|
414 |
private void |
415 |
updateAddToOrchestraMenuState(JMenu menu) { |
416 |
Object obj = getLeadObject(); |
417 |
boolean b = obj == null || !(obj instanceof DbInstrumentInfo); |
418 |
b = b || CC.getOrchestras().getOrchestraCount() == 0; |
419 |
menu.setEnabled(!b); |
420 |
} |
421 |
|
422 |
private boolean |
423 |
showYesNoDialog(String s) { |
424 |
Window w = JuifeUtils.getWindow(this); |
425 |
if(w instanceof Dialog) return HF.showYesNoDialog((Dialog)w, s); |
426 |
if(w instanceof Frame) return HF.showYesNoDialog((Frame)w, s); |
427 |
return HF.showYesNoDialog((Frame)null, s); |
428 |
} |
429 |
|
430 |
private class ReloadAction extends AbstractAction implements TreeSelectionListener { |
431 |
ReloadAction() { |
432 |
super(i18n.getMenuLabel("instrumentsdb.actions.reload")); |
433 |
|
434 |
String s = i18n.getMenuLabel("instrumentsdb.actions.reload.tt"); |
435 |
putValue(SHORT_DESCRIPTION, s); |
436 |
setEnabled(false); |
437 |
} |
438 |
|
439 |
@Override |
440 |
public void |
441 |
actionPerformed(ActionEvent e) { |
442 |
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
443 |
if(n == null) return; |
444 |
final String path = n.getInfo().getDirectoryPath(); |
445 |
instrumentsDbTree.refreshDirectoryContent(path); |
446 |
CC.scheduleInTaskQueue(new Runnable() { |
447 |
public void |
448 |
run() { instrumentsDbTree.setSelectedDirectory(path); } |
449 |
}); |
450 |
} |
451 |
|
452 |
@Override |
453 |
public void |
454 |
valueChanged(TreeSelectionEvent e) { |
455 |
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
456 |
setEnabled(n != null); |
457 |
} |
458 |
} |
459 |
|
460 |
class CreateDirectoryAction extends AbstractAction { |
461 |
private String directoryName = null; |
462 |
|
463 |
CreateDirectoryAction() { |
464 |
super(i18n.getMenuLabel("instrumentsdb.actions.createFolder")); |
465 |
|
466 |
String s = i18n.getMenuLabel("instrumentsdb.actions.createFolder.tt"); |
467 |
putValue(SHORT_DESCRIPTION, s); |
468 |
} |
469 |
|
470 |
@Override |
471 |
public void |
472 |
actionPerformed(ActionEvent e) { |
473 |
setDirectoryName(getUniqueDirectoryName()); |
474 |
|
475 |
String path = instrumentsDbTree.getSelectedDirectoryPath(); |
476 |
if(path.length() > 1) path += "/"; |
477 |
path += toEscapedFileName(getDirectoryName()); |
478 |
|
479 |
final InstrumentsDb.CreateDirectory t = |
480 |
new InstrumentsDb.CreateDirectory(path); |
481 |
|
482 |
setCreatedDirectoryName(directoryName); |
483 |
|
484 |
t.addTaskListener(new TaskListener() { |
485 |
public void |
486 |
taskPerformed(TaskEvent e) { |
487 |
if(t.doneWithErrors()) { |
488 |
setCreatedDirectoryName(null); |
489 |
return; |
490 |
} |
491 |
} |
492 |
}); |
493 |
CC.getTaskQueue().add(t); |
494 |
} |
495 |
|
496 |
/** |
497 |
* Gets the name of the directory to be created. |
498 |
* @return The name of the directory to be created. |
499 |
*/ |
500 |
public String |
501 |
getDirectoryName() { return directoryName; } |
502 |
|
503 |
/** |
504 |
* Sets the name of the directory to be created. |
505 |
* @param name The name of the directory to be created. |
506 |
*/ |
507 |
public void |
508 |
setDirectoryName(String name) { directoryName = name; } |
509 |
} |
510 |
|
511 |
class DeleteAction extends AbstractAction { |
512 |
DeleteAction() { |
513 |
super(i18n.getMenuLabel("instrumentsdb.actions.delete")); |
514 |
|
515 |
String s; |
516 |
s = i18n.getMenuLabel("instrumentsdb.actions.delete.tt"); |
517 |
putValue(SHORT_DESCRIPTION, s); |
518 |
setEnabled(false); |
519 |
} |
520 |
|
521 |
@Override |
522 |
public void |
523 |
actionPerformed(ActionEvent e) { |
524 |
final DbDirectoryInfo[] dirs = getSelectedDirectories(); |
525 |
|
526 |
if(dirs.length > 0) { |
527 |
String s = i18n.getMessage("JSInstrumentsDbTable.confirmDeletion"); |
528 |
if(!showYesNoDialog(s)) return; |
529 |
|
530 |
final Task t = new InstrumentsDb.RemoveDirectories(dirs); |
531 |
t.addTaskListener(new TaskListener() { |
532 |
public void |
533 |
taskPerformed(TaskEvent e) { |
534 |
if(instrumentsDbTree.getSelectionCount() == 0) { |
535 |
// update search results |
536 |
// TODO: lazily implemented |
537 |
deleteDirectories(dirs); |
538 |
} |
539 |
} |
540 |
}); |
541 |
CC.getTaskQueue().add(t); |
542 |
|
543 |
|
544 |
} |
545 |
|
546 |
final DbInstrumentInfo[] instrs = getSelectedInstruments(); |
547 |
if(instrs.length > 0) { |
548 |
final Task t = new InstrumentsDb.RemoveInstruments(instrs); |
549 |
t.addTaskListener(new TaskListener() { |
550 |
public void |
551 |
taskPerformed(TaskEvent e) { |
552 |
if(instrumentsDbTree.getSelectionCount() == 0) { |
553 |
// update search results |
554 |
// TODO: lazily implemented |
555 |
deleteInstruments(instrs); |
556 |
} |
557 |
} |
558 |
}); |
559 |
CC.getTaskQueue().add(t); |
560 |
} |
561 |
} |
562 |
|
563 |
/** Deletes the specified directories from the model */ |
564 |
private void |
565 |
deleteDirectories(DbDirectoryInfo[] dirs) { |
566 |
for(DbDirectoryInfo info : dirs) { |
567 |
String path = info.getDirectoryPath(); |
568 |
getParentDirectoryNode().removeDirectoryByPathName(path); |
569 |
getModel().fireTableDataChanged(); |
570 |
} |
571 |
} |
572 |
|
573 |
/** Deletes the specified instruments from the model */ |
574 |
private void |
575 |
deleteInstruments(DbInstrumentInfo[] instrs) { |
576 |
for(DbInstrumentInfo info : instrs) { |
577 |
String path = info.getInstrumentPath(); |
578 |
getParentDirectoryNode().removeInstrumentByPathName(path); |
579 |
getModel().fireTableDataChanged(); |
580 |
} |
581 |
} |
582 |
} |
583 |
|
584 |
class AddInstrumentsFromFileAction extends AbstractAction { |
585 |
AddInstrumentsFromFileAction() { |
586 |
super(i18n.getMenuLabel("instrumentsdb.actions.addInstruments.fromFile")); |
587 |
|
588 |
String s = "instrumentsdb.actions.addInstruments.fromFile.tt"; |
589 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel(s)); |
590 |
} |
591 |
|
592 |
@Override |
593 |
public void |
594 |
actionPerformed(ActionEvent e) { |
595 |
String s; |
596 |
DbDirectoryTreeNode node = getParentDirectoryNode(); |
597 |
if(node == null || node.getInfo() == null) s = null; |
598 |
else s = node.getInfo().getDirectoryPath(); |
599 |
|
600 |
JSAddDbInstrumentsFromFileDlg dlg; |
601 |
Icon ico = instrumentsDbTree.getView().getOpenIcon(); |
602 |
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
603 |
if(w instanceof Dialog) { |
604 |
dlg = new JSAddDbInstrumentsFromFileDlg((Dialog)w, s, ico); |
605 |
} else if(w instanceof Frame) { |
606 |
dlg = new JSAddDbInstrumentsFromFileDlg((Frame)w, s, ico); |
607 |
} else { |
608 |
dlg = new JSAddDbInstrumentsFromFileDlg((Frame)null, s, ico); |
609 |
} |
610 |
|
611 |
dlg.setVisible(true); |
612 |
if(w != null) w.toFront(); |
613 |
} |
614 |
} |
615 |
|
616 |
class AddInstrumentsFromDirAction extends AbstractAction { |
617 |
AddInstrumentsFromDirAction() { |
618 |
super(i18n.getMenuLabel("instrumentsdb.actions.addInstruments.fromDir")); |
619 |
|
620 |
String s = "instrumentsdb.actions.addInstruments.fromDir.tt"; |
621 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel(s)); |
622 |
} |
623 |
|
624 |
@Override |
625 |
public void |
626 |
actionPerformed(ActionEvent e) { |
627 |
String s; |
628 |
DbDirectoryTreeNode node = getParentDirectoryNode(); |
629 |
if(node == null || node.getInfo() == null) s = null; |
630 |
else s = node.getInfo().getDirectoryPath(); |
631 |
|
632 |
JSAddDbInstrumentsFromDirDlg dlg; |
633 |
Icon ico = instrumentsDbTree.getView().getOpenIcon(); |
634 |
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
635 |
if(w instanceof Dialog) { |
636 |
dlg = new JSAddDbInstrumentsFromDirDlg((Dialog)w, s, ico); |
637 |
} else if(w instanceof Frame) { |
638 |
dlg = new JSAddDbInstrumentsFromDirDlg((Frame)w, s, ico); |
639 |
} else { |
640 |
dlg = new JSAddDbInstrumentsFromDirDlg((Frame)null, s, ico); |
641 |
} |
642 |
|
643 |
dlg.setVisible(true); |
644 |
if(w != null) w.toFront(); |
645 |
} |
646 |
} |
647 |
|
648 |
class LoadInstrumentAction extends StdA4n.LoadInstrumentAction { |
649 |
LoadInstrumentAction(SamplerChannelModel model, boolean onPanel) { |
650 |
super(model, onPanel); |
651 |
} |
652 |
|
653 |
@Override |
654 |
public void |
655 |
actionPerformed(ActionEvent e) { |
656 |
Object obj = getLeadObject(); |
657 |
if(obj == null || !(obj instanceof DbInstrumentInfo)) return; |
658 |
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
659 |
int idx = info.getInstrumentIndex(); |
660 |
channelModel.setBackendEngineType(info.getFormatFamily()); // TODO: fix this |
661 |
channelModel.loadBackendInstrument(info.getFilePath(), idx); |
662 |
} |
663 |
} |
664 |
|
665 |
private LoadInstrumentActionFactory loadInstrActionFactory = new LoadInstrumentActionFactory(); |
666 |
|
667 |
class LoadInstrumentActionFactory implements StdA4n.LoadInstrumentActionFactory { |
668 |
public StdA4n.LoadInstrumentAction |
669 |
createLoadInstrumentAction(SamplerChannelModel model, boolean onPanel) { |
670 |
return new LoadInstrumentAction(model, onPanel); |
671 |
} |
672 |
} |
673 |
|
674 |
class AddToMidiMapAction extends AbstractAction { |
675 |
private final MidiInstrumentMap midiMap; |
676 |
|
677 |
AddToMidiMapAction(MidiInstrumentMap map) { |
678 |
super(map.getName()); |
679 |
midiMap = map; |
680 |
} |
681 |
|
682 |
@Override |
683 |
public void |
684 |
actionPerformed(ActionEvent e) { |
685 |
DbInstrumentInfo[] instruments = getSelectedInstruments(); |
686 |
int l = instruments.length; |
687 |
if(l == 0) return; |
688 |
|
689 |
if(l > 4) { |
690 |
String s = "JSInstrumentsDbTable.confirmAddToMidiMap"; |
691 |
s = i18n.getMessage(s, l, midiMap.getName()); |
692 |
if(!HF.showYesNoDialog(JSInstrumentsDbTable.this, s)) return; |
693 |
} |
694 |
|
695 |
JSAddMidiInstrumentDlg dlg; |
696 |
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
697 |
|
698 |
for(DbInstrumentInfo i : instruments) { |
699 |
if(w instanceof Dialog) { |
700 |
dlg = new JSAddMidiInstrumentDlg((Dialog)w, midiMap, i); |
701 |
} else if(w instanceof Frame) { |
702 |
dlg = new JSAddMidiInstrumentDlg((Frame)w, midiMap, i); |
703 |
} else { |
704 |
dlg = new JSAddMidiInstrumentDlg((Frame)null, midiMap, i); |
705 |
} |
706 |
|
707 |
dlg.setVisible(true); |
708 |
} |
709 |
} |
710 |
} |
711 |
|
712 |
class AddToOrchestraAction extends AbstractAction { |
713 |
private final OrchestraModel orchestraModel; |
714 |
|
715 |
AddToOrchestraAction(OrchestraModel model) { |
716 |
super(model.getName()); |
717 |
orchestraModel = model; |
718 |
} |
719 |
|
720 |
@Override |
721 |
public void |
722 |
actionPerformed(ActionEvent e) { |
723 |
DbInstrumentInfo[] instruments = getSelectedInstruments(); |
724 |
int l = instruments.length; |
725 |
if(l == 0) return; |
726 |
|
727 |
if(l > 1) { |
728 |
String s = "JSInstrumentsDbTable.confirmAddToOrchestra"; |
729 |
s = i18n.getMessage(s, l, orchestraModel.getName()); |
730 |
if(!HF.showYesNoDialog(JSInstrumentsDbTable.this, s)) return; |
731 |
} |
732 |
|
733 |
for(DbInstrumentInfo i : instruments) { |
734 |
OrchestraInstrument instr = new OrchestraInstrument(); |
735 |
instr.setFilePath(i.getFilePath()); |
736 |
instr.setInstrumentIndex(i.getInstrumentIndex()); |
737 |
instr.setName(i.getName()); |
738 |
instr.setDescription(i.getDescription()); |
739 |
instr.setEngine(i.getFormatFamily()); // TODO: this should be fixed |
740 |
orchestraModel.addInstrument(instr); |
741 |
} |
742 |
} |
743 |
} |
744 |
|
745 |
class PropertiesAction extends AbstractAction { |
746 |
PropertiesAction() { |
747 |
super(i18n.getMenuLabel("instrumentsdb.actions.properties")); |
748 |
|
749 |
String s; |
750 |
s = i18n.getMenuLabel("instrumentsdb.actions.properties.tt"); |
751 |
putValue(SHORT_DESCRIPTION, s); |
752 |
setEnabled(false); |
753 |
} |
754 |
|
755 |
@Override |
756 |
public void |
757 |
actionPerformed(ActionEvent e) { |
758 |
Object obj = getLeadObject(); |
759 |
if(obj == null) { |
760 |
DbDirectoryTreeNode node = getParentDirectoryNode(); |
761 |
if(node == null || node.getInfo() == null) return; |
762 |
showDirectoryProperties(node.getInfo()); |
763 |
return; |
764 |
} |
765 |
|
766 |
if(obj instanceof DbDirectoryInfo) { |
767 |
showDirectoryProperties((DbDirectoryInfo)obj); |
768 |
} else if(obj instanceof DbInstrumentInfo) { |
769 |
showInstrumentProperties((DbInstrumentInfo)obj); |
770 |
} |
771 |
} |
772 |
|
773 |
private void |
774 |
showInstrumentProperties(DbInstrumentInfo instr) { |
775 |
JPanel p = new JSDbInstrumentPropsPane(instr); |
776 |
String s = i18n.getLabel("JSInstrumentsDbTable.instrProps"); |
777 |
showDialog(s, p); |
778 |
} |
779 |
|
780 |
private void |
781 |
showDirectoryProperties(DbDirectoryInfo dir) { |
782 |
JPanel p = new JSDbDirectoryPropsPane(dir); |
783 |
String s = i18n.getLabel("JSInstrumentsDbTable.dirProps"); |
784 |
showDialog(s, p); |
785 |
} |
786 |
|
787 |
private void |
788 |
showDialog(String title, JPanel mainPane) { |
789 |
InformationDialog dlg; |
790 |
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
791 |
if(w instanceof Dialog) { |
792 |
dlg = new InformationDialog((Dialog)w, title, mainPane); |
793 |
} else if(w instanceof Frame) { |
794 |
dlg = new InformationDialog((Frame)w, title, mainPane); |
795 |
} else { |
796 |
dlg = new InformationDialog((Frame)null, title, mainPane); |
797 |
} |
798 |
|
799 |
dlg.setMinimumSize(dlg.getPreferredSize()); |
800 |
dlg.setVisible(true); |
801 |
} |
802 |
} |
803 |
|
804 |
class RenameAction extends AbstractAction { |
805 |
private String directoryPath = null; |
806 |
|
807 |
RenameAction() { |
808 |
super(i18n.getMenuLabel("instrumentsdb.edit.rename")); |
809 |
|
810 |
String s = i18n.getMenuLabel("instrumentsdb.edit.rename.tt"); |
811 |
putValue(SHORT_DESCRIPTION, s); |
812 |
setEnabled(false); |
813 |
} |
814 |
|
815 |
@Override |
816 |
public void |
817 |
actionPerformed(ActionEvent e) { |
818 |
int i = getSelectionModel().getLeadSelectionIndex(); |
819 |
if(i == -1) return; |
820 |
editCellAt(i, 0); |
821 |
} |
822 |
} |
823 |
|
824 |
class ChangeDescriptionAction extends AbstractAction { |
825 |
private String directoryPath = null; |
826 |
|
827 |
ChangeDescriptionAction() { |
828 |
super(i18n.getMenuLabel("instrumentsdb.edit.description")); |
829 |
|
830 |
String s = i18n.getMenuLabel("instrumentsdb.edit.description.tt"); |
831 |
putValue(SHORT_DESCRIPTION, s); |
832 |
setEnabled(false); |
833 |
} |
834 |
|
835 |
@Override |
836 |
public void |
837 |
actionPerformed(ActionEvent e) { |
838 |
Object obj = getLeadObject(); |
839 |
if(obj == null) return; |
840 |
|
841 |
if(obj instanceof DbDirectoryInfo) { |
842 |
DbDirectoryInfo info = (DbDirectoryInfo)obj; |
843 |
String s = editDescription(info.getDescription()); |
844 |
if(s == null) return; |
845 |
String path = info.getDirectoryPath(); |
846 |
Task t = new InstrumentsDb.SetDirectoryDescription(path, s); |
847 |
CC.getTaskQueue().add(t); |
848 |
} else if(obj instanceof DbInstrumentInfo) { |
849 |
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
850 |
String s = editDescription(info.getDescription()); |
851 |
if(s == null) return; |
852 |
String path = info.getInstrumentPath(); |
853 |
Task t = new InstrumentsDb.SetInstrumentDescription(path, s); |
854 |
CC.getTaskQueue().add(t); |
855 |
} |
856 |
} |
857 |
|
858 |
private String |
859 |
editDescription(String s) { |
860 |
JSDbDescriptionDlg dlg; |
861 |
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
862 |
if(w instanceof Dialog) { |
863 |
dlg = new JSDbDescriptionDlg((Dialog)w); |
864 |
} else if(w instanceof Frame) { |
865 |
dlg = new JSDbDescriptionDlg((Frame)w); |
866 |
} else { |
867 |
dlg = new JSDbDescriptionDlg((Frame)null); |
868 |
} |
869 |
|
870 |
dlg.setDescription(s); |
871 |
dlg.setVisible(true); |
872 |
if(dlg.isCancelled()) return null; |
873 |
return dlg.getDescription(); |
874 |
} |
875 |
} |
876 |
|
877 |
class CutAction extends AbstractAction { |
878 |
CutAction() { |
879 |
super(i18n.getMenuLabel("instrumentsdb.edit.cut")); |
880 |
|
881 |
String s = i18n.getMenuLabel("instrumentsdb.edit.cut.tt"); |
882 |
putValue(SHORT_DESCRIPTION, s); |
883 |
setEnabled(false); |
884 |
} |
885 |
|
886 |
@Override |
887 |
public void |
888 |
actionPerformed(ActionEvent e) { |
889 |
getDbClipboard().setDirectories(getSelectedDirectories()); |
890 |
getDbClipboard().setInstruments(getSelectedInstruments()); |
891 |
getDbClipboard().setOperation(DbClipboard.Operation.CUT); |
892 |
} |
893 |
} |
894 |
|
895 |
class CopyAction extends AbstractAction { |
896 |
CopyAction() { |
897 |
super(i18n.getMenuLabel("instrumentsdb.edit.copy")); |
898 |
|
899 |
String s = i18n.getMenuLabel("instrumentsdb.edit.copy.tt"); |
900 |
putValue(SHORT_DESCRIPTION, s); |
901 |
setEnabled(false); |
902 |
} |
903 |
|
904 |
@Override |
905 |
public void |
906 |
actionPerformed(ActionEvent e) { |
907 |
getDbClipboard().setDirectories(getSelectedDirectories()); |
908 |
getDbClipboard().setInstruments(getSelectedInstruments()); |
909 |
getDbClipboard().setOperation(DbClipboard.Operation.COPY); |
910 |
} |
911 |
} |
912 |
|
913 |
class PasteAction extends AbstractAction implements TreeSelectionListener, ChangeListener { |
914 |
PasteAction() { |
915 |
super(i18n.getMenuLabel("instrumentsdb.edit.paste")); |
916 |
|
917 |
String s = i18n.getMenuLabel("instrumentsdb.edit.paste.tt"); |
918 |
putValue(SHORT_DESCRIPTION, s); |
919 |
setEnabled(false); |
920 |
getDbClipboard().addChangeListener(this); |
921 |
} |
922 |
|
923 |
@Override |
924 |
public void |
925 |
actionPerformed(ActionEvent e) { |
926 |
DbDirectoryInfo[] dirs = getDbClipboard().getDirectories(); |
927 |
DbInstrumentInfo[] instrs = getDbClipboard().getInstruments(); |
928 |
String dest = instrumentsDbTree.getSelectedDirectoryPath(); |
929 |
|
930 |
Task t; |
931 |
if(getDbClipboard().getOperation() == DbClipboard.Operation.CUT) { |
932 |
t = new InstrumentsDb.Move(dirs, instrs, dest); |
933 |
getDbClipboard().setDirectories(new DbDirectoryInfo[0]); |
934 |
getDbClipboard().setInstruments(new DbInstrumentInfo[0]); |
935 |
} else if(getDbClipboard().getOperation() == DbClipboard.Operation.COPY) { |
936 |
t = new InstrumentsDb.Copy(dirs, instrs, dest); |
937 |
} else { |
938 |
return; |
939 |
} |
940 |
|
941 |
CC.getTaskQueue().add(t); |
942 |
} |
943 |
|
944 |
@Override |
945 |
public void |
946 |
valueChanged(TreeSelectionEvent e) { updateState(); } |
947 |
|
948 |
@Override |
949 |
public void |
950 |
stateChanged(ChangeEvent e) { updateState(); } |
951 |
|
952 |
private void |
953 |
updateState() { |
954 |
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
955 |
if(n == null) { |
956 |
setEnabled(false); |
957 |
return; |
958 |
} |
959 |
|
960 |
int dirs = getDbClipboard().getDirectories().length; |
961 |
setEnabled(dirs > 0 || getDbClipboard().getInstruments().length > 0); |
962 |
} |
963 |
} |
964 |
|
965 |
class InstrumentsDbCellRenderer extends JLabel implements TableCellRenderer { |
966 |
|
967 |
InstrumentsDbCellRenderer() { |
968 |
setOpaque(true); |
969 |
setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); |
970 |
} |
971 |
|
972 |
@Override |
973 |
public Component |
974 |
getTableCellRendererComponent ( |
975 |
JTable table, |
976 |
Object value, |
977 |
boolean isSelected, |
978 |
boolean hasFocus, |
979 |
int row, |
980 |
int column |
981 |
) { |
982 |
if(column == 0 && value != null) { |
983 |
String s; |
984 |
if(value instanceof DbDirectoryInfo) { |
985 |
setIcon(getView().getFolderIcon()); |
986 |
s = ((DbDirectoryInfo)value).getDescription(); |
987 |
setToolTipText(s.length() == 0 ? null : s); |
988 |
} else if(value instanceof String) { |
989 |
setIcon(getView().getFolderIcon()); |
990 |
setToolTipText(null); |
991 |
} else if(value instanceof DbInstrumentInfo) { |
992 |
DbInstrumentInfo info = (DbInstrumentInfo)value; |
993 |
if("GIG".equals(info.getFormatFamily())) { // TODO: fix it! |
994 |
setIcon(getView().getGigInstrumentIcon()); |
995 |
} else { |
996 |
setIcon(getView().getInstrumentIcon()); |
997 |
} |
998 |
|
999 |
s = info.getDescription(); |
1000 |
setToolTipText(s.length() == 0 ? null : s); |
1001 |
} else { |
1002 |
setIcon(null); |
1003 |
setToolTipText(null); |
1004 |
} |
1005 |
} else { |
1006 |
setIcon(null); |
1007 |
setToolTipText(null); |
1008 |
} |
1009 |
|
1010 |
if(value != null) setText(value.toString()); |
1011 |
else setText(""); |
1012 |
|
1013 |
if (isSelected) { |
1014 |
setBackground(table.getSelectionBackground()); |
1015 |
setForeground(table.getSelectionForeground()); |
1016 |
} else { |
1017 |
setBackground(table.getBackground()); |
1018 |
setForeground(table.getForeground()); |
1019 |
} |
1020 |
|
1021 |
ColumnType ct = |
1022 |
((InstrumentsDbTableModel)table.getModel()).getColumnType(column); |
1023 |
|
1024 |
if(ct == ColumnType.IS_DRUM || ct == ColumnType.FORMAT_FAMILY) { |
1025 |
setHorizontalAlignment(CENTER); |
1026 |
} else if ( ct == ColumnType.SIZE || |
1027 |
ct == ColumnType.INSTRUMENT_NR || |
1028 |
ct == ColumnType.FORMAT_VERSION |
1029 |
) { |
1030 |
setHorizontalAlignment(RIGHT); |
1031 |
} else { |
1032 |
setHorizontalAlignment(LEFT); |
1033 |
} |
1034 |
|
1035 |
return this; |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
private final EventHandler eventHandler = new EventHandler(); |
1040 |
|
1041 |
private EventHandler |
1042 |
getHandler() { return eventHandler; } |
1043 |
|
1044 |
private class EventHandler implements ListSelectionListener, TreeSelectionListener, |
1045 |
SamplerChannelListListener, ListListener<OrchestraModel> { |
1046 |
|
1047 |
@Override |
1048 |
public void |
1049 |
valueChanged(ListSelectionEvent e) { |
1050 |
boolean b = !getSelectionModel().isSelectionEmpty(); |
1051 |
deleteAction.setEnabled(b); |
1052 |
propertiesAction.setEnabled(b || instrumentsDbTree.getSelectionCount() > 0); |
1053 |
renameAction.setEnabled(b); |
1054 |
changeDescriptionAction.setEnabled(b); |
1055 |
cutAction.setEnabled(b); |
1056 |
copyAction.setEnabled(b); |
1057 |
updateLoadInstrumentMenuStates(); |
1058 |
updateAddToMidiMapMenuStates(); |
1059 |
updateAddToOrchestraMenuStates(); |
1060 |
} |
1061 |
|
1062 |
@Override |
1063 |
public void |
1064 |
valueChanged(TreeSelectionEvent e) { |
1065 |
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
1066 |
setParentDirectoryNode(n); |
1067 |
reloadAction.setEnabled(n != null); |
1068 |
createDirectoryAction.setEnabled(n != null); |
1069 |
propertiesAction.setEnabled(n != null || getLeadObject() != null); |
1070 |
} |
1071 |
|
1072 |
@Override |
1073 |
public void |
1074 |
channelAdded(SamplerChannelListEvent e) { |
1075 |
if(CC.getSamplerModel().getChannelListIsAdjusting()) return; |
1076 |
updateLoadInstrumentMenus(); |
1077 |
} |
1078 |
|
1079 |
@Override |
1080 |
public void |
1081 |
channelRemoved(SamplerChannelListEvent e) { |
1082 |
updateLoadInstrumentMenus(); |
1083 |
} |
1084 |
|
1085 |
@Override |
1086 |
public void |
1087 |
entryAdded(ListEvent<OrchestraModel> e) { updateAddToOrchestraMenus(); } |
1088 |
|
1089 |
@Override |
1090 |
public void |
1091 |
entryRemoved(ListEvent<OrchestraModel> e) { updateAddToOrchestraMenus(); } |
1092 |
} |
1093 |
|
1094 |
class ContextMenu extends MouseAdapter { |
1095 |
private final JPopupMenu instrumentMenu = new JPopupMenu(); |
1096 |
private final JPopupMenu directoryMenu = new JPopupMenu(); |
1097 |
private final JPopupMenu menu = new JPopupMenu(); |
1098 |
|
1099 |
private JMenu loadInstrumentMenu; |
1100 |
private JMenu addToMidiMapMenu; |
1101 |
private JMenu addToOrchestraMenu; |
1102 |
|
1103 |
class MenuItem extends JMenuItem { |
1104 |
MenuItem(Action a) { super(a); } |
1105 |
|
1106 |
public Icon |
1107 |
getIcon() { return null; } |
1108 |
} |
1109 |
|
1110 |
ContextMenu() { |
1111 |
JMenuItem mi = new JMenuItem(pasteAction); |
1112 |
mi.setIcon(null); |
1113 |
menu.add(mi); |
1114 |
|
1115 |
menu.addSeparator(); |
1116 |
|
1117 |
mi = new MenuItem(createDirectoryAction); |
1118 |
mi.setIcon(null); |
1119 |
menu.add(mi); |
1120 |
|
1121 |
String s = i18n.getMenuLabel("instrumentsdb.actions.addInstruments"); |
1122 |
JMenu addInstrumentsMenu = new JMenu(s); |
1123 |
menu.add(addInstrumentsMenu); |
1124 |
|
1125 |
mi = new JMenuItem(addInstrumentsFromFileAction); |
1126 |
mi.setIcon(null); |
1127 |
addInstrumentsMenu.add(mi); |
1128 |
|
1129 |
mi = new JMenuItem(addInstrumentsFromDirAction); |
1130 |
mi.setIcon(null); |
1131 |
addInstrumentsMenu.add(mi); |
1132 |
|
1133 |
menu.addSeparator(); |
1134 |
|
1135 |
mi = new MenuItem(reloadAction); |
1136 |
mi.setIcon(null); |
1137 |
menu.add(mi); |
1138 |
|
1139 |
menu.addSeparator(); |
1140 |
|
1141 |
mi = new JMenuItem(propertiesAction); |
1142 |
mi.setIcon(null); |
1143 |
menu.add(mi); |
1144 |
|
1145 |
// Instrument's context menu |
1146 |
mi = new JMenuItem(cutAction); |
1147 |
mi.setIcon(null); |
1148 |
instrumentMenu.add(mi); |
1149 |
|
1150 |
mi = new JMenuItem(copyAction); |
1151 |
mi.setIcon(null); |
1152 |
instrumentMenu.add(mi); |
1153 |
|
1154 |
instrumentMenu.addSeparator(); |
1155 |
|
1156 |
mi = new JMenuItem(deleteAction); |
1157 |
mi.setIcon(null); |
1158 |
instrumentMenu.add(mi); |
1159 |
|
1160 |
mi = new JMenuItem(renameAction); |
1161 |
mi.setIcon(null); |
1162 |
instrumentMenu.add(mi); |
1163 |
|
1164 |
mi = new JMenuItem(changeDescriptionAction); |
1165 |
mi.setIcon(null); |
1166 |
instrumentMenu.add(mi); |
1167 |
|
1168 |
instrumentMenu.addSeparator(); |
1169 |
|
1170 |
s = i18n.getMenuLabel("instrumentsdb.actions.loadInstrument"); |
1171 |
loadInstrumentMenu = new JMenu(s); |
1172 |
instrumentMenu.add(loadInstrumentMenu); |
1173 |
registerLoadInstrumentMenus(loadInstrumentMenu); |
1174 |
|
1175 |
addToMidiMapMenu = |
1176 |
new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToMidiMap")); |
1177 |
instrumentMenu.add(addToMidiMapMenu); |
1178 |
registerAddToMidiMapMenu(addToMidiMapMenu); |
1179 |
|
1180 |
s = i18n.getMenuLabel("instrumentsdb.actions.addToOrchestra"); |
1181 |
addToOrchestraMenu = new JMenu(s); |
1182 |
instrumentMenu.add(addToOrchestraMenu); |
1183 |
registerAddToOrchestraMenu(addToOrchestraMenu); |
1184 |
|
1185 |
instrumentMenu.addSeparator(); |
1186 |
|
1187 |
mi = new JMenuItem(propertiesAction); |
1188 |
mi.setIcon(null); |
1189 |
instrumentMenu.add(mi); |
1190 |
|
1191 |
// Directory's context menu |
1192 |
mi = new JMenuItem(cutAction); |
1193 |
mi.setIcon(null); |
1194 |
directoryMenu.add(mi); |
1195 |
|
1196 |
mi = new JMenuItem(copyAction); |
1197 |
mi.setIcon(null); |
1198 |
directoryMenu.add(mi); |
1199 |
|
1200 |
directoryMenu.addSeparator(); |
1201 |
|
1202 |
mi = new JMenuItem(deleteAction); |
1203 |
mi.setIcon(null); |
1204 |
directoryMenu.add(mi); |
1205 |
|
1206 |
mi = new JMenuItem(renameAction); |
1207 |
mi.setIcon(null); |
1208 |
directoryMenu.add(mi); |
1209 |
|
1210 |
mi = new JMenuItem(changeDescriptionAction); |
1211 |
mi.setIcon(null); |
1212 |
directoryMenu.add(mi); |
1213 |
|
1214 |
directoryMenu.addSeparator(); |
1215 |
|
1216 |
mi = new JMenuItem(propertiesAction); |
1217 |
mi.setIcon(null); |
1218 |
directoryMenu.add(mi); |
1219 |
} |
1220 |
|
1221 |
@Override |
1222 |
public void |
1223 |
mousePressed(MouseEvent e) { |
1224 |
if(e.isPopupTrigger()) show(e); |
1225 |
} |
1226 |
|
1227 |
@Override |
1228 |
public void |
1229 |
mouseReleased(MouseEvent e) { |
1230 |
if(e.isPopupTrigger()) show(e); |
1231 |
} |
1232 |
|
1233 |
void |
1234 |
show(MouseEvent e) { |
1235 |
Object obj = getLeadObject(); |
1236 |
if(obj == null) { |
1237 |
menu.show(e.getComponent(), e.getX(), e.getY()); |
1238 |
return; |
1239 |
} |
1240 |
|
1241 |
if(obj instanceof DbInstrumentInfo) { |
1242 |
instrumentMenu.show(e.getComponent(), e.getX(), e.getY()); |
1243 |
return; |
1244 |
} |
1245 |
|
1246 |
if(obj instanceof DbDirectoryInfo) { |
1247 |
directoryMenu.show(e.getComponent(), e.getX(), e.getY()); |
1248 |
return; |
1249 |
} |
1250 |
} |
1251 |
} |
1252 |
} |