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