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 |
iliev |
1347 |
import static org.linuxsampler.lscp.Parser.*; |
94 |
|
|
|
95 |
iliev |
1286 |
/** |
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 |
|
|
instrumentsDbTree.refreshDirectoryContent(n.getInfo().getDirectoryPath()); |
426 |
|
|
} |
427 |
|
|
|
428 |
|
|
public void |
429 |
|
|
valueChanged(TreeSelectionEvent e) { |
430 |
|
|
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
431 |
|
|
setEnabled(n != null); |
432 |
|
|
} |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
class CreateDirectoryAction extends AbstractAction { |
436 |
|
|
private String directoryName = null; |
437 |
|
|
|
438 |
|
|
CreateDirectoryAction() { |
439 |
|
|
super(i18n.getMenuLabel("instrumentsdb.actions.createFolder")); |
440 |
|
|
|
441 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.actions.createFolder.tt"); |
442 |
|
|
putValue(SHORT_DESCRIPTION, s); |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
public void |
446 |
|
|
actionPerformed(ActionEvent e) { |
447 |
|
|
setDirectoryName(getUniqueDirectoryName()); |
448 |
|
|
|
449 |
|
|
String path = instrumentsDbTree.getSelectedDirectoryPath(); |
450 |
|
|
if(path.length() > 1) path += "/"; |
451 |
iliev |
1347 |
path += toEscapedFileName(getDirectoryName()); |
452 |
iliev |
1286 |
|
453 |
|
|
final InstrumentsDb.CreateDirectory t = |
454 |
|
|
new InstrumentsDb.CreateDirectory(path); |
455 |
|
|
|
456 |
|
|
setCreatedDirectoryName(directoryName); |
457 |
|
|
|
458 |
|
|
t.addTaskListener(new TaskListener() { |
459 |
|
|
public void |
460 |
|
|
taskPerformed(TaskEvent e) { |
461 |
|
|
if(t.doneWithErrors()) { |
462 |
|
|
setCreatedDirectoryName(null); |
463 |
|
|
return; |
464 |
|
|
} |
465 |
|
|
} |
466 |
|
|
}); |
467 |
|
|
CC.getTaskQueue().add(t); |
468 |
|
|
} |
469 |
|
|
|
470 |
|
|
/** |
471 |
|
|
* Gets the name of the directory to be created. |
472 |
|
|
* @return The name of the directory to be created. |
473 |
|
|
*/ |
474 |
|
|
public String |
475 |
|
|
getDirectoryName() { return directoryName; } |
476 |
|
|
|
477 |
|
|
/** |
478 |
|
|
* Sets the name of the directory to be created. |
479 |
|
|
* @param name The name of the directory to be created. |
480 |
|
|
*/ |
481 |
|
|
public void |
482 |
|
|
setDirectoryName(String name) { directoryName = name; } |
483 |
|
|
} |
484 |
|
|
|
485 |
|
|
class DeleteAction extends AbstractAction { |
486 |
|
|
DeleteAction() { |
487 |
|
|
super(i18n.getMenuLabel("instrumentsdb.actions.delete")); |
488 |
|
|
|
489 |
|
|
String s; |
490 |
|
|
s = i18n.getMenuLabel("instrumentsdb.actions.delete.tt"); |
491 |
|
|
putValue(SHORT_DESCRIPTION, s); |
492 |
|
|
setEnabled(false); |
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
public void |
496 |
|
|
actionPerformed(ActionEvent e) { |
497 |
|
|
final DbDirectoryInfo[] dirs = getSelectedDirectories(); |
498 |
|
|
|
499 |
|
|
if(dirs.length > 0) { |
500 |
|
|
String s = i18n.getMessage("JSInstrumentsDbTable.confirmDeletion"); |
501 |
|
|
if(!showYesNoDialog(s)) return; |
502 |
|
|
|
503 |
|
|
final Task t = new InstrumentsDb.RemoveDirectories(dirs); |
504 |
|
|
t.addTaskListener(new TaskListener() { |
505 |
|
|
public void |
506 |
|
|
taskPerformed(TaskEvent e) { |
507 |
|
|
if(instrumentsDbTree.getSelectionCount() == 0) { |
508 |
|
|
// update search results |
509 |
|
|
// TODO: lazily implemented |
510 |
|
|
deleteDirectories(dirs); |
511 |
|
|
} |
512 |
|
|
} |
513 |
|
|
}); |
514 |
|
|
CC.getTaskQueue().add(t); |
515 |
|
|
|
516 |
|
|
|
517 |
|
|
} |
518 |
|
|
|
519 |
|
|
final DbInstrumentInfo[] instrs = getSelectedInstruments(); |
520 |
|
|
if(instrs.length > 0) { |
521 |
|
|
final Task t = new InstrumentsDb.RemoveInstruments(instrs); |
522 |
|
|
t.addTaskListener(new TaskListener() { |
523 |
|
|
public void |
524 |
|
|
taskPerformed(TaskEvent e) { |
525 |
|
|
if(instrumentsDbTree.getSelectionCount() == 0) { |
526 |
|
|
// update search results |
527 |
|
|
// TODO: lazily implemented |
528 |
|
|
deleteInstruments(instrs); |
529 |
|
|
} |
530 |
|
|
} |
531 |
|
|
}); |
532 |
|
|
CC.getTaskQueue().add(t); |
533 |
|
|
} |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
/** Deletes the specified directories from the model */ |
537 |
|
|
private void |
538 |
|
|
deleteDirectories(DbDirectoryInfo[] dirs) { |
539 |
|
|
for(DbDirectoryInfo info : dirs) { |
540 |
|
|
String path = info.getDirectoryPath(); |
541 |
|
|
getParentDirectoryNode().removeDirectoryByPathName(path); |
542 |
|
|
getModel().fireTableDataChanged(); |
543 |
|
|
} |
544 |
|
|
} |
545 |
|
|
|
546 |
|
|
/** Deletes the specified instruments from the model */ |
547 |
|
|
private void |
548 |
|
|
deleteInstruments(DbInstrumentInfo[] instrs) { |
549 |
|
|
for(DbInstrumentInfo info : instrs) { |
550 |
|
|
String path = info.getInstrumentPath(); |
551 |
|
|
getParentDirectoryNode().removeInstrumentByPathName(path); |
552 |
|
|
getModel().fireTableDataChanged(); |
553 |
|
|
} |
554 |
|
|
} |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
class AddInstrumentsFromFileAction extends AbstractAction { |
558 |
|
|
AddInstrumentsFromFileAction() { |
559 |
|
|
super(i18n.getMenuLabel("instrumentsdb.actions.addInstruments.fromFile")); |
560 |
|
|
|
561 |
|
|
String s = "instrumentsdb.actions.addInstruments.fromFile.tt"; |
562 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel(s)); |
563 |
|
|
} |
564 |
|
|
|
565 |
|
|
public void |
566 |
|
|
actionPerformed(ActionEvent e) { |
567 |
|
|
String s; |
568 |
|
|
DbDirectoryTreeNode node = getParentDirectoryNode(); |
569 |
|
|
if(node == null || node.getInfo() == null) s = null; |
570 |
|
|
else s = node.getInfo().getDirectoryPath(); |
571 |
|
|
|
572 |
|
|
JSAddDbInstrumentsFromFileDlg dlg; |
573 |
|
|
Icon ico = instrumentsDbTree.getView().getOpenIcon(); |
574 |
|
|
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
575 |
|
|
if(w instanceof Dialog) { |
576 |
|
|
dlg = new JSAddDbInstrumentsFromFileDlg((Dialog)w, s, ico); |
577 |
|
|
} else if(w instanceof Frame) { |
578 |
|
|
dlg = new JSAddDbInstrumentsFromFileDlg((Frame)w, s, ico); |
579 |
|
|
} else { |
580 |
|
|
dlg = new JSAddDbInstrumentsFromFileDlg((Frame)null, s, ico); |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
dlg.setVisible(true); |
584 |
|
|
if(w != null) w.toFront(); |
585 |
|
|
} |
586 |
|
|
} |
587 |
|
|
|
588 |
|
|
class AddInstrumentsFromDirAction extends AbstractAction { |
589 |
|
|
AddInstrumentsFromDirAction() { |
590 |
|
|
super(i18n.getMenuLabel("instrumentsdb.actions.addInstruments.fromDir")); |
591 |
|
|
|
592 |
|
|
String s = "instrumentsdb.actions.addInstruments.fromDir.tt"; |
593 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel(s)); |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
public void |
597 |
|
|
actionPerformed(ActionEvent e) { |
598 |
|
|
String s; |
599 |
|
|
DbDirectoryTreeNode node = getParentDirectoryNode(); |
600 |
|
|
if(node == null || node.getInfo() == null) s = null; |
601 |
|
|
else s = node.getInfo().getDirectoryPath(); |
602 |
|
|
|
603 |
|
|
JSAddDbInstrumentsFromDirDlg dlg; |
604 |
|
|
Icon ico = instrumentsDbTree.getView().getOpenIcon(); |
605 |
|
|
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
606 |
|
|
if(w instanceof Dialog) { |
607 |
|
|
dlg = new JSAddDbInstrumentsFromDirDlg((Dialog)w, s, ico); |
608 |
|
|
} else if(w instanceof Frame) { |
609 |
|
|
dlg = new JSAddDbInstrumentsFromDirDlg((Frame)w, s, ico); |
610 |
|
|
} else { |
611 |
|
|
dlg = new JSAddDbInstrumentsFromDirDlg((Frame)null, s, ico); |
612 |
|
|
} |
613 |
|
|
|
614 |
|
|
dlg.setVisible(true); |
615 |
|
|
if(w != null) w.toFront(); |
616 |
|
|
} |
617 |
|
|
} |
618 |
|
|
|
619 |
|
|
class LoadInstrumentAction extends AbstractAction { |
620 |
|
|
private final SamplerChannelModel channelModel; |
621 |
|
|
|
622 |
|
|
LoadInstrumentAction(SamplerChannelModel model) { |
623 |
|
|
String s = "instrumentsdb.actions.loadInstrument.onChannel"; |
624 |
|
|
putValue(Action.NAME, i18n.getMenuLabel(s, model.getChannelId())); |
625 |
|
|
channelModel = model; |
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
public void |
629 |
|
|
actionPerformed(ActionEvent e) { |
630 |
|
|
Object obj = getLeadObject(); |
631 |
|
|
if(obj == null || !(obj instanceof DbInstrumentInfo)) return; |
632 |
|
|
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
633 |
|
|
int idx = info.getInstrumentIndex(); |
634 |
|
|
channelModel.setBackendEngineType(info.getFormatFamily()); // TODO: fix this |
635 |
|
|
channelModel.loadBackendInstrument(info.getFilePath(), idx); |
636 |
|
|
} |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
class AddToMidiMapAction extends AbstractAction { |
640 |
|
|
private final MidiInstrumentMap midiMap; |
641 |
|
|
|
642 |
|
|
AddToMidiMapAction(MidiInstrumentMap map) { |
643 |
|
|
super(map.getName()); |
644 |
|
|
midiMap = map; |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
public void |
648 |
|
|
actionPerformed(ActionEvent e) { |
649 |
|
|
Object obj = getLeadObject(); |
650 |
|
|
if(obj == null || !(obj instanceof DbInstrumentInfo)) return; |
651 |
|
|
|
652 |
|
|
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
653 |
|
|
|
654 |
|
|
JSAddMidiInstrumentDlg dlg; |
655 |
|
|
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
656 |
|
|
if(w instanceof Dialog) { |
657 |
|
|
dlg = new JSAddMidiInstrumentDlg((Dialog)w); |
658 |
|
|
} else if(w instanceof Frame) { |
659 |
|
|
dlg = new JSAddMidiInstrumentDlg((Frame)w); |
660 |
|
|
} else { |
661 |
|
|
dlg = new JSAddMidiInstrumentDlg((Frame)null); |
662 |
|
|
} |
663 |
|
|
|
664 |
|
|
dlg.setInstrumentName(info.getName()); |
665 |
|
|
dlg.setVisible(true); |
666 |
|
|
if(dlg.isCancelled()) return; |
667 |
|
|
|
668 |
|
|
MidiInstrumentInfo instrInfo = new MidiInstrumentInfo(); |
669 |
|
|
instrInfo.setName(dlg.getInstrumentName()); |
670 |
|
|
instrInfo.setFilePath(info.getFilePath()); |
671 |
|
|
instrInfo.setInstrumentIndex(info.getInstrumentIndex()); |
672 |
|
|
instrInfo.setEngine(info.getFormatFamily()); // TODO: this should be fixed |
673 |
|
|
instrInfo.setVolume(dlg.getVolume()); |
674 |
|
|
instrInfo.setLoadMode(dlg.getLoadMode()); |
675 |
|
|
|
676 |
|
|
int id = midiMap.getMapId(); |
677 |
|
|
int b = dlg.getMidiBank(); |
678 |
|
|
int p = dlg.getMidiProgram(); |
679 |
|
|
CC.getSamplerModel().mapBackendMidiInstrument(id, b, p, instrInfo); |
680 |
|
|
} |
681 |
|
|
} |
682 |
|
|
|
683 |
|
|
class AddToOrchestraAction extends AbstractAction { |
684 |
|
|
private final OrchestraModel orchestraModel; |
685 |
|
|
|
686 |
|
|
AddToOrchestraAction(OrchestraModel model) { |
687 |
|
|
super(model.getName()); |
688 |
|
|
orchestraModel = model; |
689 |
|
|
} |
690 |
|
|
|
691 |
|
|
public void |
692 |
|
|
actionPerformed(ActionEvent e) { |
693 |
|
|
Object obj = getLeadObject(); |
694 |
|
|
if(obj == null || !(obj instanceof DbInstrumentInfo)) return; |
695 |
|
|
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
696 |
|
|
Instrument instr = new Instrument(); |
697 |
|
|
instr.setPath(info.getFilePath()); |
698 |
|
|
instr.setInstrumentIndex(info.getInstrumentIndex()); |
699 |
|
|
instr.setName(info.getName()); |
700 |
|
|
instr.setDescription(info.getDescription()); |
701 |
|
|
instr.setEngine(info.getFormatFamily()); // TODO: this should be fixed |
702 |
|
|
orchestraModel.addInstrument(instr); |
703 |
|
|
} |
704 |
|
|
} |
705 |
|
|
|
706 |
|
|
class PropertiesAction extends AbstractAction { |
707 |
|
|
PropertiesAction() { |
708 |
|
|
super(i18n.getMenuLabel("instrumentsdb.actions.properties")); |
709 |
|
|
|
710 |
|
|
String s; |
711 |
|
|
s = i18n.getMenuLabel("instrumentsdb.actions.properties.tt"); |
712 |
|
|
putValue(SHORT_DESCRIPTION, s); |
713 |
|
|
setEnabled(false); |
714 |
|
|
} |
715 |
|
|
|
716 |
|
|
public void |
717 |
|
|
actionPerformed(ActionEvent e) { |
718 |
|
|
Object obj = getLeadObject(); |
719 |
|
|
if(obj == null) { |
720 |
|
|
DbDirectoryTreeNode node = getParentDirectoryNode(); |
721 |
|
|
if(node == null || node.getInfo() == null) return; |
722 |
|
|
showDirectoryProperties(node.getInfo()); |
723 |
|
|
return; |
724 |
|
|
} |
725 |
|
|
|
726 |
|
|
if(obj instanceof DbDirectoryInfo) { |
727 |
|
|
showDirectoryProperties((DbDirectoryInfo)obj); |
728 |
|
|
} else if(obj instanceof DbInstrumentInfo) { |
729 |
|
|
showInstrumentProperties((DbInstrumentInfo)obj); |
730 |
|
|
} |
731 |
|
|
} |
732 |
|
|
|
733 |
|
|
private void |
734 |
|
|
showInstrumentProperties(DbInstrumentInfo instr) { |
735 |
|
|
JPanel p = new JSDbInstrumentPropsPane(instr); |
736 |
|
|
String s = i18n.getLabel("JSInstrumentsDbTable.instrProps"); |
737 |
|
|
showDialog(s, p); |
738 |
|
|
} |
739 |
|
|
|
740 |
|
|
private void |
741 |
|
|
showDirectoryProperties(DbDirectoryInfo dir) { |
742 |
|
|
JPanel p = new JSDbDirectoryPropsPane(dir); |
743 |
|
|
String s = i18n.getLabel("JSInstrumentsDbTable.dirProps"); |
744 |
|
|
showDialog(s, p); |
745 |
|
|
} |
746 |
|
|
|
747 |
|
|
private void |
748 |
|
|
showDialog(String title, JPanel mainPane) { |
749 |
|
|
InformationDialog dlg; |
750 |
|
|
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
751 |
|
|
if(w instanceof Dialog) { |
752 |
|
|
dlg = new InformationDialog((Dialog)w, title, mainPane); |
753 |
|
|
} else if(w instanceof Frame) { |
754 |
|
|
dlg = new InformationDialog((Frame)w, title, mainPane); |
755 |
|
|
} else { |
756 |
|
|
dlg = new InformationDialog((Frame)null, title, mainPane); |
757 |
|
|
} |
758 |
|
|
|
759 |
|
|
dlg.setMinimumSize(dlg.getPreferredSize()); |
760 |
|
|
dlg.setVisible(true); |
761 |
|
|
} |
762 |
|
|
} |
763 |
|
|
|
764 |
|
|
class RenameAction extends AbstractAction { |
765 |
|
|
private String directoryPath = null; |
766 |
|
|
|
767 |
|
|
RenameAction() { |
768 |
|
|
super(i18n.getMenuLabel("instrumentsdb.edit.rename")); |
769 |
|
|
|
770 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.edit.rename.tt"); |
771 |
|
|
putValue(SHORT_DESCRIPTION, s); |
772 |
|
|
setEnabled(false); |
773 |
|
|
} |
774 |
|
|
|
775 |
|
|
public void |
776 |
|
|
actionPerformed(ActionEvent e) { |
777 |
|
|
int i = getSelectionModel().getLeadSelectionIndex(); |
778 |
|
|
if(i == -1) return; |
779 |
|
|
editCellAt(i, 0); |
780 |
|
|
} |
781 |
|
|
} |
782 |
|
|
|
783 |
|
|
class ChangeDescriptionAction extends AbstractAction { |
784 |
|
|
private String directoryPath = null; |
785 |
|
|
|
786 |
|
|
ChangeDescriptionAction() { |
787 |
|
|
super(i18n.getMenuLabel("instrumentsdb.edit.description")); |
788 |
|
|
|
789 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.edit.description.tt"); |
790 |
|
|
putValue(SHORT_DESCRIPTION, s); |
791 |
|
|
setEnabled(false); |
792 |
|
|
} |
793 |
|
|
|
794 |
|
|
public void |
795 |
|
|
actionPerformed(ActionEvent e) { |
796 |
|
|
Object obj = getLeadObject(); |
797 |
|
|
if(obj == null) return; |
798 |
|
|
|
799 |
|
|
if(obj instanceof DbDirectoryInfo) { |
800 |
|
|
DbDirectoryInfo info = (DbDirectoryInfo)obj; |
801 |
|
|
String s = editDescription(info.getDescription()); |
802 |
|
|
if(s == null) return; |
803 |
|
|
String path = info.getDirectoryPath(); |
804 |
|
|
Task t = new InstrumentsDb.SetDirectoryDescription(path, s); |
805 |
|
|
CC.getTaskQueue().add(t); |
806 |
|
|
} else if(obj instanceof DbInstrumentInfo) { |
807 |
|
|
DbInstrumentInfo info = (DbInstrumentInfo)obj; |
808 |
|
|
String s = editDescription(info.getDescription()); |
809 |
|
|
if(s == null) return; |
810 |
|
|
String path = info.getInstrumentPath(); |
811 |
|
|
Task t = new InstrumentsDb.SetInstrumentDescription(path, s); |
812 |
|
|
CC.getTaskQueue().add(t); |
813 |
|
|
} |
814 |
|
|
} |
815 |
|
|
|
816 |
|
|
private String |
817 |
|
|
editDescription(String s) { |
818 |
|
|
JSDbDescriptionDlg dlg; |
819 |
|
|
Window w = JuifeUtils.getWindow(JSInstrumentsDbTable.this); |
820 |
|
|
if(w instanceof Dialog) { |
821 |
|
|
dlg = new JSDbDescriptionDlg((Dialog)w); |
822 |
|
|
} else if(w instanceof Frame) { |
823 |
|
|
dlg = new JSDbDescriptionDlg((Frame)w); |
824 |
|
|
} else { |
825 |
|
|
dlg = new JSDbDescriptionDlg((Frame)null); |
826 |
|
|
} |
827 |
|
|
|
828 |
|
|
dlg.setDescription(s); |
829 |
|
|
dlg.setVisible(true); |
830 |
|
|
if(dlg.isCancelled()) return null; |
831 |
|
|
return dlg.getDescription(); |
832 |
|
|
} |
833 |
|
|
} |
834 |
|
|
|
835 |
|
|
class CutAction extends AbstractAction { |
836 |
|
|
CutAction() { |
837 |
|
|
super(i18n.getMenuLabel("instrumentsdb.edit.cut")); |
838 |
|
|
|
839 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.edit.cut.tt"); |
840 |
|
|
putValue(SHORT_DESCRIPTION, s); |
841 |
|
|
setEnabled(false); |
842 |
|
|
} |
843 |
|
|
|
844 |
|
|
public void |
845 |
|
|
actionPerformed(ActionEvent e) { |
846 |
|
|
getDbClipboard().setDirectories(getSelectedDirectories()); |
847 |
|
|
getDbClipboard().setInstruments(getSelectedInstruments()); |
848 |
|
|
getDbClipboard().setOperation(DbClipboard.Operation.CUT); |
849 |
|
|
} |
850 |
|
|
} |
851 |
|
|
|
852 |
|
|
class CopyAction extends AbstractAction { |
853 |
|
|
CopyAction() { |
854 |
|
|
super(i18n.getMenuLabel("instrumentsdb.edit.copy")); |
855 |
|
|
|
856 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.edit.copy.tt"); |
857 |
|
|
putValue(SHORT_DESCRIPTION, s); |
858 |
|
|
setEnabled(false); |
859 |
|
|
} |
860 |
|
|
|
861 |
|
|
public void |
862 |
|
|
actionPerformed(ActionEvent e) { |
863 |
|
|
getDbClipboard().setDirectories(getSelectedDirectories()); |
864 |
|
|
getDbClipboard().setInstruments(getSelectedInstruments()); |
865 |
|
|
getDbClipboard().setOperation(DbClipboard.Operation.COPY); |
866 |
|
|
} |
867 |
|
|
} |
868 |
|
|
|
869 |
|
|
class PasteAction extends AbstractAction implements TreeSelectionListener, ChangeListener { |
870 |
|
|
PasteAction() { |
871 |
|
|
super(i18n.getMenuLabel("instrumentsdb.edit.paste")); |
872 |
|
|
|
873 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.edit.paste.tt"); |
874 |
|
|
putValue(SHORT_DESCRIPTION, s); |
875 |
|
|
setEnabled(false); |
876 |
|
|
getDbClipboard().addChangeListener(this); |
877 |
|
|
} |
878 |
|
|
|
879 |
|
|
public void |
880 |
|
|
actionPerformed(ActionEvent e) { |
881 |
|
|
DbDirectoryInfo[] dirs = getDbClipboard().getDirectories(); |
882 |
|
|
DbInstrumentInfo[] instrs = getDbClipboard().getInstruments(); |
883 |
|
|
String dest = instrumentsDbTree.getSelectedDirectoryPath(); |
884 |
|
|
|
885 |
|
|
Task t; |
886 |
|
|
if(getDbClipboard().getOperation() == DbClipboard.Operation.CUT) { |
887 |
|
|
t = new InstrumentsDb.Move(dirs, instrs, dest); |
888 |
|
|
getDbClipboard().setDirectories(new DbDirectoryInfo[0]); |
889 |
|
|
getDbClipboard().setInstruments(new DbInstrumentInfo[0]); |
890 |
|
|
} else if(getDbClipboard().getOperation() == DbClipboard.Operation.COPY) { |
891 |
|
|
t = new InstrumentsDb.Copy(dirs, instrs, dest); |
892 |
|
|
} else { |
893 |
|
|
return; |
894 |
|
|
} |
895 |
|
|
|
896 |
|
|
CC.getTaskQueue().add(t); |
897 |
|
|
} |
898 |
|
|
|
899 |
|
|
public void |
900 |
|
|
valueChanged(TreeSelectionEvent e) { updateState(); } |
901 |
|
|
|
902 |
|
|
public void |
903 |
|
|
stateChanged(ChangeEvent e) { updateState(); } |
904 |
|
|
|
905 |
|
|
private void |
906 |
|
|
updateState() { |
907 |
|
|
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
908 |
|
|
if(n == null) { |
909 |
|
|
setEnabled(false); |
910 |
|
|
return; |
911 |
|
|
} |
912 |
|
|
|
913 |
|
|
int dirs = getDbClipboard().getDirectories().length; |
914 |
|
|
setEnabled(dirs > 0 || getDbClipboard().getInstruments().length > 0); |
915 |
|
|
} |
916 |
|
|
} |
917 |
|
|
|
918 |
|
|
class InstrumentsDbCellRenderer extends JLabel implements TableCellRenderer { |
919 |
|
|
|
920 |
|
|
InstrumentsDbCellRenderer() { |
921 |
|
|
setOpaque(true); |
922 |
|
|
setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); |
923 |
|
|
} |
924 |
|
|
|
925 |
|
|
public Component |
926 |
|
|
getTableCellRendererComponent ( |
927 |
|
|
JTable table, |
928 |
|
|
Object value, |
929 |
|
|
boolean isSelected, |
930 |
|
|
boolean hasFocus, |
931 |
|
|
int row, |
932 |
|
|
int column |
933 |
|
|
) { |
934 |
|
|
if(column == 0 && value != null) { |
935 |
|
|
String s; |
936 |
|
|
if(value instanceof DbDirectoryInfo) { |
937 |
|
|
setIcon(getView().getFolderIcon()); |
938 |
|
|
s = ((DbDirectoryInfo)value).getDescription(); |
939 |
|
|
setToolTipText(s.length() == 0 ? null : s); |
940 |
|
|
} else if(value instanceof String) { |
941 |
|
|
setIcon(getView().getFolderIcon()); |
942 |
|
|
setToolTipText(null); |
943 |
|
|
} else if(value instanceof DbInstrumentInfo) { |
944 |
|
|
DbInstrumentInfo info = (DbInstrumentInfo)value; |
945 |
|
|
if("GIG".equals(info.getFormatFamily())) { // TODO: fix it! |
946 |
|
|
setIcon(getView().getGigInstrumentIcon()); |
947 |
|
|
} else { |
948 |
|
|
setIcon(getView().getInstrumentIcon()); |
949 |
|
|
} |
950 |
|
|
|
951 |
|
|
s = info.getDescription(); |
952 |
|
|
setToolTipText(s.length() == 0 ? null : s); |
953 |
|
|
} else { |
954 |
|
|
setIcon(null); |
955 |
|
|
setToolTipText(null); |
956 |
|
|
} |
957 |
|
|
} else { |
958 |
|
|
setIcon(null); |
959 |
|
|
setToolTipText(null); |
960 |
|
|
} |
961 |
|
|
|
962 |
|
|
if(value != null) setText(value.toString()); |
963 |
|
|
else setText(""); |
964 |
|
|
|
965 |
|
|
if (isSelected) { |
966 |
|
|
setBackground(table.getSelectionBackground()); |
967 |
|
|
setForeground(table.getSelectionForeground()); |
968 |
|
|
} else { |
969 |
|
|
setBackground(table.getBackground()); |
970 |
|
|
setForeground(table.getForeground()); |
971 |
|
|
} |
972 |
|
|
|
973 |
|
|
ColumnType ct = |
974 |
|
|
((InstrumentsDbTableModel)table.getModel()).getColumnType(column); |
975 |
|
|
|
976 |
|
|
if(ct == ColumnType.IS_DRUM || ct == ColumnType.FORMAT_FAMILY) { |
977 |
|
|
setHorizontalAlignment(CENTER); |
978 |
|
|
} else if ( ct == ColumnType.SIZE || |
979 |
|
|
ct == ColumnType.INSTRUMENT_NR || |
980 |
|
|
ct == ColumnType.FORMAT_VERSION |
981 |
|
|
) { |
982 |
|
|
setHorizontalAlignment(RIGHT); |
983 |
|
|
} else { |
984 |
|
|
setHorizontalAlignment(LEFT); |
985 |
|
|
} |
986 |
|
|
|
987 |
|
|
return this; |
988 |
|
|
} |
989 |
|
|
} |
990 |
|
|
|
991 |
|
|
private final EventHandler eventHandler = new EventHandler(); |
992 |
|
|
|
993 |
|
|
private EventHandler |
994 |
|
|
getHandler() { return eventHandler; } |
995 |
|
|
|
996 |
|
|
private class EventHandler implements ListSelectionListener, TreeSelectionListener, |
997 |
|
|
SamplerChannelListListener, ListListener<OrchestraModel> { |
998 |
|
|
|
999 |
|
|
public void |
1000 |
|
|
valueChanged(ListSelectionEvent e) { |
1001 |
|
|
boolean b = !getSelectionModel().isSelectionEmpty(); |
1002 |
|
|
deleteAction.setEnabled(b); |
1003 |
|
|
propertiesAction.setEnabled(b || instrumentsDbTree.getSelectionCount() > 0); |
1004 |
|
|
renameAction.setEnabled(b); |
1005 |
|
|
changeDescriptionAction.setEnabled(b); |
1006 |
|
|
cutAction.setEnabled(b); |
1007 |
|
|
copyAction.setEnabled(b); |
1008 |
|
|
updateLoadInstrumentMenuStates(); |
1009 |
|
|
updateAddToMidiMapMenuStates(); |
1010 |
|
|
updateAddToOrchestraMenuStates(); |
1011 |
|
|
} |
1012 |
|
|
|
1013 |
|
|
public void |
1014 |
|
|
valueChanged(TreeSelectionEvent e) { |
1015 |
|
|
DbDirectoryTreeNode n = instrumentsDbTree.getSelectedDirectoryNode(); |
1016 |
|
|
setParentDirectoryNode(n); |
1017 |
|
|
reloadAction.setEnabled(n != null); |
1018 |
|
|
createDirectoryAction.setEnabled(n != null); |
1019 |
|
|
propertiesAction.setEnabled(n != null || getLeadObject() != null); |
1020 |
|
|
} |
1021 |
|
|
|
1022 |
|
|
public void |
1023 |
|
|
channelAdded(SamplerChannelListEvent e) { |
1024 |
|
|
updateLoadInstrumentMenus(); |
1025 |
|
|
} |
1026 |
|
|
|
1027 |
|
|
public void |
1028 |
|
|
channelRemoved(SamplerChannelListEvent e) { |
1029 |
|
|
updateLoadInstrumentMenus(); |
1030 |
|
|
} |
1031 |
|
|
|
1032 |
|
|
public void |
1033 |
|
|
entryAdded(ListEvent<OrchestraModel> e) { updateAddToOrchestraMenus(); } |
1034 |
|
|
|
1035 |
|
|
public void |
1036 |
|
|
entryRemoved(ListEvent<OrchestraModel> e) { updateAddToOrchestraMenus(); } |
1037 |
|
|
} |
1038 |
|
|
|
1039 |
|
|
class ContextMenu extends MouseAdapter { |
1040 |
|
|
private final JPopupMenu instrumentMenu = new JPopupMenu(); |
1041 |
|
|
private final JPopupMenu directoryMenu = new JPopupMenu(); |
1042 |
|
|
private final JPopupMenu menu = new JPopupMenu(); |
1043 |
|
|
|
1044 |
|
|
private JMenu loadInstrumentMenu; |
1045 |
|
|
private JMenu addToMidiMapMenu; |
1046 |
|
|
private JMenu addToOrchestraMenu; |
1047 |
|
|
|
1048 |
|
|
class MenuItem extends JMenuItem { |
1049 |
|
|
MenuItem(Action a) { super(a); } |
1050 |
|
|
|
1051 |
|
|
public Icon |
1052 |
|
|
getIcon() { return null; } |
1053 |
|
|
} |
1054 |
|
|
|
1055 |
|
|
ContextMenu() { |
1056 |
|
|
JMenuItem mi = new JMenuItem(pasteAction); |
1057 |
|
|
mi.setIcon(null); |
1058 |
|
|
menu.add(mi); |
1059 |
|
|
|
1060 |
|
|
menu.addSeparator(); |
1061 |
|
|
|
1062 |
|
|
mi = new MenuItem(createDirectoryAction); |
1063 |
|
|
mi.setIcon(null); |
1064 |
|
|
menu.add(mi); |
1065 |
|
|
|
1066 |
|
|
String s = i18n.getMenuLabel("instrumentsdb.actions.addInstruments"); |
1067 |
|
|
JMenu addInstrumentsMenu = new JMenu(s); |
1068 |
|
|
menu.add(addInstrumentsMenu); |
1069 |
|
|
|
1070 |
|
|
mi = new JMenuItem(addInstrumentsFromFileAction); |
1071 |
|
|
mi.setIcon(null); |
1072 |
|
|
addInstrumentsMenu.add(mi); |
1073 |
|
|
|
1074 |
|
|
mi = new JMenuItem(addInstrumentsFromDirAction); |
1075 |
|
|
mi.setIcon(null); |
1076 |
|
|
addInstrumentsMenu.add(mi); |
1077 |
|
|
|
1078 |
|
|
menu.addSeparator(); |
1079 |
|
|
|
1080 |
|
|
mi = new MenuItem(reloadAction); |
1081 |
|
|
mi.setIcon(null); |
1082 |
|
|
menu.add(mi); |
1083 |
|
|
|
1084 |
|
|
menu.addSeparator(); |
1085 |
|
|
|
1086 |
|
|
mi = new JMenuItem(propertiesAction); |
1087 |
|
|
mi.setIcon(null); |
1088 |
|
|
menu.add(mi); |
1089 |
|
|
|
1090 |
|
|
// Instrument's context menu |
1091 |
|
|
mi = new JMenuItem(cutAction); |
1092 |
|
|
mi.setIcon(null); |
1093 |
|
|
instrumentMenu.add(mi); |
1094 |
|
|
|
1095 |
|
|
mi = new JMenuItem(copyAction); |
1096 |
|
|
mi.setIcon(null); |
1097 |
|
|
instrumentMenu.add(mi); |
1098 |
|
|
|
1099 |
|
|
instrumentMenu.addSeparator(); |
1100 |
|
|
|
1101 |
|
|
mi = new JMenuItem(deleteAction); |
1102 |
|
|
mi.setIcon(null); |
1103 |
|
|
instrumentMenu.add(mi); |
1104 |
|
|
|
1105 |
|
|
mi = new JMenuItem(renameAction); |
1106 |
|
|
mi.setIcon(null); |
1107 |
|
|
instrumentMenu.add(mi); |
1108 |
|
|
|
1109 |
|
|
mi = new JMenuItem(changeDescriptionAction); |
1110 |
|
|
mi.setIcon(null); |
1111 |
|
|
instrumentMenu.add(mi); |
1112 |
|
|
|
1113 |
|
|
instrumentMenu.addSeparator(); |
1114 |
|
|
|
1115 |
|
|
s = i18n.getMenuLabel("instrumentsdb.actions.loadInstrument"); |
1116 |
|
|
loadInstrumentMenu = new JMenu(s); |
1117 |
|
|
instrumentMenu.add(loadInstrumentMenu); |
1118 |
|
|
registerLoadInstrumentMenus(loadInstrumentMenu); |
1119 |
|
|
|
1120 |
|
|
addToMidiMapMenu = |
1121 |
|
|
new JMenu(i18n.getMenuLabel("instrumentsdb.actions.addToMidiMap")); |
1122 |
|
|
instrumentMenu.add(addToMidiMapMenu); |
1123 |
|
|
registerAddToMidiMapMenu(addToMidiMapMenu); |
1124 |
|
|
|
1125 |
|
|
s = i18n.getMenuLabel("instrumentsdb.actions.addToOrchestra"); |
1126 |
|
|
addToOrchestraMenu = new JMenu(s); |
1127 |
|
|
instrumentMenu.add(addToOrchestraMenu); |
1128 |
|
|
registerAddToOrchestraMenu(addToOrchestraMenu); |
1129 |
|
|
|
1130 |
|
|
instrumentMenu.addSeparator(); |
1131 |
|
|
|
1132 |
|
|
mi = new JMenuItem(propertiesAction); |
1133 |
|
|
mi.setIcon(null); |
1134 |
|
|
instrumentMenu.add(mi); |
1135 |
|
|
|
1136 |
|
|
// Directory's context menu |
1137 |
|
|
mi = new JMenuItem(cutAction); |
1138 |
|
|
mi.setIcon(null); |
1139 |
|
|
directoryMenu.add(mi); |
1140 |
|
|
|
1141 |
|
|
mi = new JMenuItem(copyAction); |
1142 |
|
|
mi.setIcon(null); |
1143 |
|
|
directoryMenu.add(mi); |
1144 |
|
|
|
1145 |
|
|
directoryMenu.addSeparator(); |
1146 |
|
|
|
1147 |
|
|
mi = new JMenuItem(deleteAction); |
1148 |
|
|
mi.setIcon(null); |
1149 |
|
|
directoryMenu.add(mi); |
1150 |
|
|
|
1151 |
|
|
mi = new JMenuItem(renameAction); |
1152 |
|
|
mi.setIcon(null); |
1153 |
|
|
directoryMenu.add(mi); |
1154 |
|
|
|
1155 |
|
|
mi = new JMenuItem(changeDescriptionAction); |
1156 |
|
|
mi.setIcon(null); |
1157 |
|
|
directoryMenu.add(mi); |
1158 |
|
|
|
1159 |
|
|
directoryMenu.addSeparator(); |
1160 |
|
|
|
1161 |
|
|
mi = new JMenuItem(propertiesAction); |
1162 |
|
|
mi.setIcon(null); |
1163 |
|
|
directoryMenu.add(mi); |
1164 |
|
|
} |
1165 |
|
|
|
1166 |
|
|
public void |
1167 |
|
|
mousePressed(MouseEvent e) { |
1168 |
|
|
if(e.isPopupTrigger()) show(e); |
1169 |
|
|
} |
1170 |
|
|
|
1171 |
|
|
public void |
1172 |
|
|
mouseReleased(MouseEvent e) { |
1173 |
|
|
if(e.isPopupTrigger()) show(e); |
1174 |
|
|
} |
1175 |
|
|
|
1176 |
|
|
void |
1177 |
|
|
show(MouseEvent e) { |
1178 |
|
|
Object obj = getLeadObject(); |
1179 |
|
|
if(obj == null) { |
1180 |
|
|
menu.show(e.getComponent(), e.getX(), e.getY()); |
1181 |
|
|
return; |
1182 |
|
|
} |
1183 |
|
|
|
1184 |
|
|
if(obj instanceof DbInstrumentInfo) { |
1185 |
|
|
instrumentMenu.show(e.getComponent(), e.getX(), e.getY()); |
1186 |
|
|
return; |
1187 |
|
|
} |
1188 |
|
|
|
1189 |
|
|
if(obj instanceof DbDirectoryInfo) { |
1190 |
|
|
directoryMenu.show(e.getComponent(), e.getX(), e.getY()); |
1191 |
|
|
return; |
1192 |
|
|
} |
1193 |
|
|
} |
1194 |
|
|
} |
1195 |
|
|
} |