/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSManageMidiMapsPane.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSManageMidiMapsPane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1866 - (show annotations) (download)
Sun Mar 15 19:40:29 2009 UTC (15 years, 1 month ago) by iliev
File size: 5113 byte(s)
* show controller names in fx sends dialogs
* save send levels when exporting sampler configuration
* ask when removing nonempty map
* fixed compilation error

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

  ViewVC Help
Powered by ViewVC