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 |
import java.awt.event.MouseAdapter; |
29 |
import java.awt.event.MouseEvent; |
30 |
|
31 |
import javax.swing.AbstractAction; |
32 |
import javax.swing.Action; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.JScrollPane; |
35 |
|
36 |
import javax.swing.event.ListSelectionEvent; |
37 |
import javax.swing.event.ListSelectionListener; |
38 |
|
39 |
import org.jsampler.CC; |
40 |
import org.jsampler.MidiInstrumentMap; |
41 |
|
42 |
import org.jsampler.view.MidiMapTable; |
43 |
|
44 |
import static org.jsampler.view.std.StdI18n.i18n; |
45 |
|
46 |
/** |
47 |
* |
48 |
* @author Grigor Iliev |
49 |
*/ |
50 |
public class JSManageMidiMapsPane extends JPanel implements ListSelectionListener { |
51 |
protected final MidiMapTable midiMapTable = new MidiMapTable(); |
52 |
|
53 |
protected final Action actionAddMap = new AddMapAction(); |
54 |
protected final Action actionEditMap = new EditMapAction(); |
55 |
protected final Action actionRemoveMap = new RemoveMapAction(); |
56 |
|
57 |
/** Creates a new instance of <code>JSManageMidiMapsPane</code> */ |
58 |
public |
59 |
JSManageMidiMapsPane() { |
60 |
setLayout(new BorderLayout()); |
61 |
JScrollPane sp = new JScrollPane(midiMapTable); |
62 |
add(sp); |
63 |
|
64 |
installListeneres(); |
65 |
} |
66 |
|
67 |
private void |
68 |
installListeneres() { |
69 |
midiMapTable.getSelectionModel().addListSelectionListener(this); |
70 |
|
71 |
midiMapTable.addMouseListener(new MouseAdapter() { |
72 |
public void |
73 |
mouseClicked(MouseEvent e) { |
74 |
if(e.getClickCount() < 2) return; |
75 |
|
76 |
if(midiMapTable.getSelectedMidiInstrumentMap() == null) return; |
77 |
editMidiInstrumentMap(midiMapTable.getSelectedMidiInstrumentMap()); |
78 |
} |
79 |
}); |
80 |
} |
81 |
|
82 |
public void |
83 |
valueChanged(ListSelectionEvent e) { |
84 |
if(e.getValueIsAdjusting()) return; |
85 |
|
86 |
boolean b = midiMapTable.getSelectedMidiInstrumentMap() != null; |
87 |
actionEditMap.setEnabled(b); |
88 |
actionRemoveMap.setEnabled(b); |
89 |
} |
90 |
|
91 |
public void |
92 |
addMidiInstrumentMap() { |
93 |
JSAddMidiInstrumentMapDlg dlg = new JSAddMidiInstrumentMapDlg(); |
94 |
dlg.setVisible(true); |
95 |
if(dlg.isCancelled()) return; |
96 |
|
97 |
CC.getSamplerModel().addBackendMidiInstrumentMap(dlg.getMapName()); |
98 |
} |
99 |
|
100 |
public void |
101 |
editMidiInstrumentMap(MidiInstrumentMap map) { |
102 |
int id = map.getMapId(); |
103 |
JSAddMidiInstrumentMapDlg dlg = new JSAddMidiInstrumentMapDlg(); |
104 |
dlg.setTitle(i18n.getLabel("JSManageMidiMapsPane.editMap")); |
105 |
dlg.setMapName(map.getName()); |
106 |
dlg.setVisible(true); |
107 |
if(dlg.isCancelled()) return; |
108 |
|
109 |
map.setName(dlg.getMapName()); |
110 |
CC.getSamplerModel().setBackendMidiInstrumentMapName(id, dlg.getMapName()); |
111 |
} |
112 |
|
113 |
private class AddMapAction extends AbstractAction { |
114 |
AddMapAction() { |
115 |
super(i18n.getLabel("JSManageMidiMapsPane.addMap")); |
116 |
|
117 |
String s = i18n.getLabel("JSManageMidiMapsPane.addMap.tt"); |
118 |
putValue(SHORT_DESCRIPTION, s); |
119 |
} |
120 |
|
121 |
public void |
122 |
actionPerformed(ActionEvent e) { |
123 |
addMidiInstrumentMap(); |
124 |
} |
125 |
} |
126 |
|
127 |
private class EditMapAction extends AbstractAction { |
128 |
EditMapAction() { |
129 |
super(i18n.getLabel("JSManageMidiMapsPane.editMap")); |
130 |
|
131 |
String s = i18n.getLabel("JSManageMidiMapsPane.editMap.tt"); |
132 |
putValue(SHORT_DESCRIPTION, s); |
133 |
|
134 |
setEnabled(false); |
135 |
} |
136 |
|
137 |
public void |
138 |
actionPerformed(ActionEvent e) { |
139 |
editMidiInstrumentMap(midiMapTable.getSelectedMidiInstrumentMap()); |
140 |
} |
141 |
} |
142 |
|
143 |
private class RemoveMapAction extends AbstractAction { |
144 |
RemoveMapAction() { |
145 |
super(i18n.getLabel("JSManageMidiMapsPane.removeMap")); |
146 |
|
147 |
String s = i18n.getLabel("JSManageMidiMapsPane.removeMap.tt"); |
148 |
putValue(SHORT_DESCRIPTION, s); |
149 |
|
150 |
setEnabled(false); |
151 |
} |
152 |
|
153 |
public void |
154 |
actionPerformed(ActionEvent e) { |
155 |
MidiInstrumentMap map = midiMapTable.getSelectedMidiInstrumentMap(); |
156 |
CC.getSamplerModel().removeBackendMidiInstrumentMap(map.getMapId()); |
157 |
} |
158 |
} |
159 |
} |