/[svn]/jsampler/trunk/src/org/jsampler/view/classic/InstrumentsDbTable.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/InstrumentsDbTable.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1205 - (show annotations) (download)
Thu May 24 21:55:41 2007 UTC (16 years, 10 months ago) by iliev
File size: 40522 byte(s)
* upgrading to version 0.5a

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

  ViewVC Help
Powered by ViewVC