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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1746 - (hide annotations) (download)
Mon Jun 2 03:33:11 2008 UTC (15 years, 11 months ago) by iliev
File size: 4770 byte(s)
* Orchestras, orchestra instruments, MIDI maps and MIDI instruments
  can now be removed using the `Delete' key from the keyboard
* Fantasia: Aligned the numbering of sampler channel 10

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

  ViewVC Help
Powered by ViewVC