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.std; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
|
27 |
import java.awt.event.ActionEvent; |
28 |
|
29 |
import javax.swing.AbstractAction; |
30 |
import javax.swing.Action; |
31 |
import javax.swing.JPanel; |
32 |
import javax.swing.JScrollPane; |
33 |
|
34 |
import javax.swing.event.TreeSelectionEvent; |
35 |
import javax.swing.event.TreeSelectionListener; |
36 |
|
37 |
import net.sf.juife.Wizard; |
38 |
|
39 |
import org.jsampler.CC; |
40 |
import org.jsampler.MidiInstrument; |
41 |
import org.jsampler.MidiInstrumentMap; |
42 |
|
43 |
import org.linuxsampler.lscp.MidiInstrumentInfo; |
44 |
|
45 |
import static org.jsampler.view.std.StdI18n.i18n; |
46 |
|
47 |
/** |
48 |
* |
49 |
* @author Grigor Iliev |
50 |
*/ |
51 |
public class JSMidiInstrumentsPane extends JPanel implements TreeSelectionListener { |
52 |
protected final JSMidiInstrumentTree midiInstrumentTree = new JSMidiInstrumentTree(); |
53 |
|
54 |
protected final Action actionAddInstrument = new AddInstrumentAction(); |
55 |
protected final Action actionEditInstrument = new EditInstrumentAction(); |
56 |
protected final Action actionRemove = new RemoveAction(); |
57 |
|
58 |
/** Creates a new instance of <code>JSMidiInstrumentsPane</code> */ |
59 |
public |
60 |
JSMidiInstrumentsPane() { |
61 |
this(null); |
62 |
} |
63 |
|
64 |
/** Creates a new instance of <code>JSMidiInstrumentsPane</code> */ |
65 |
public |
66 |
JSMidiInstrumentsPane(MidiInstrumentMap map) { |
67 |
setMidiInstrumentMap(map); |
68 |
|
69 |
setLayout(new BorderLayout()); |
70 |
JScrollPane sp = new JScrollPane(midiInstrumentTree); |
71 |
add(sp); |
72 |
|
73 |
midiInstrumentTree.addTreeSelectionListener(this); |
74 |
} |
75 |
|
76 |
public void |
77 |
setMidiInstrumentMap(MidiInstrumentMap map) { |
78 |
midiInstrumentTree.setMidiInstrumentMap(map); |
79 |
actionAddInstrument.setEnabled(map != null); |
80 |
} |
81 |
|
82 |
public void |
83 |
valueChanged(TreeSelectionEvent e) { |
84 |
actionRemove.setEnabled(midiInstrumentTree.getSelectionCount() > 0); |
85 |
boolean b = midiInstrumentTree.getSelectedInstrument() != null; |
86 |
actionEditInstrument.setEnabled(b); |
87 |
} |
88 |
|
89 |
public void |
90 |
addInstrument() { } |
91 |
|
92 |
public void |
93 |
editInstrument(MidiInstrument instr) { |
94 |
JSEditMidiInstrumentDlg dlg = new JSEditMidiInstrumentDlg(instr.getInfo()); |
95 |
dlg.setVisible(true); |
96 |
|
97 |
if(dlg.isCancelled()) return; |
98 |
|
99 |
MidiInstrumentInfo info = dlg.getInstrument(); |
100 |
CC.getSamplerModel().mapBackendMidiInstrument ( |
101 |
info.getMapId(), info.getMidiBank(), info.getMidiProgram(), info |
102 |
); |
103 |
} |
104 |
|
105 |
private class AddInstrumentAction extends AbstractAction { |
106 |
AddInstrumentAction() { |
107 |
super(i18n.getLabel("JSMidiInstrumentsPane.addInstrument")); |
108 |
|
109 |
String s = "JSMidiInstrumentsPane.addInstrument.tt"; |
110 |
putValue(SHORT_DESCRIPTION, i18n.getLabel(s)); |
111 |
} |
112 |
|
113 |
public void |
114 |
actionPerformed(ActionEvent e) { |
115 |
addInstrument(); |
116 |
} |
117 |
} |
118 |
|
119 |
private class EditInstrumentAction extends AbstractAction { |
120 |
EditInstrumentAction() { |
121 |
super(i18n.getLabel("JSMidiInstrumentsPane.editInstrument")); |
122 |
|
123 |
String s = i18n.getLabel("JSMidiInstrumentsPane.editInstrument.tt"); |
124 |
putValue(SHORT_DESCRIPTION, s); |
125 |
|
126 |
setEnabled(false); |
127 |
} |
128 |
|
129 |
public void |
130 |
actionPerformed(ActionEvent e) { |
131 |
editInstrument(midiInstrumentTree.getSelectedInstrument()); |
132 |
|
133 |
} |
134 |
} |
135 |
|
136 |
private class RemoveAction extends AbstractAction { |
137 |
RemoveAction() { |
138 |
String s = i18n.getLabel("JSMidiInstrumentsPane.remove.tt"); |
139 |
putValue(SHORT_DESCRIPTION, s); |
140 |
|
141 |
setEnabled(false); |
142 |
} |
143 |
|
144 |
public void |
145 |
actionPerformed(ActionEvent e) { |
146 |
midiInstrumentTree.removeSelectedInstrumentOrBank(); |
147 |
} |
148 |
} |
149 |
} |