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