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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1746 - (show annotations) (download)
Mon Jun 2 03:33:11 2008 UTC (15 years, 10 months ago) by iliev
File size: 7036 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 /*
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.ActionListener;
29 import java.awt.event.KeyEvent;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
32
33 import javax.swing.AbstractAction;
34 import javax.swing.Action;
35 import javax.swing.JComponent;
36 import javax.swing.JPanel;
37 import javax.swing.JScrollPane;
38 import javax.swing.KeyStroke;
39
40 import javax.swing.event.ListSelectionEvent;
41 import javax.swing.event.ListSelectionListener;
42
43 import org.jsampler.CC;
44 import org.jsampler.HF;
45 import org.jsampler.OrchestraModel;
46
47 import org.jsampler.view.OrchestraTable;
48 import org.jsampler.view.OrchestraTableModel;
49
50 import static org.jsampler.view.std.StdI18n.i18n;
51
52 /**
53 *
54 * @author Grigor Iliev
55 */
56 public class JSManageOrchestrasPane extends JPanel {
57 protected final OrchestraTable orchestraTable;
58
59 protected final Action actionAddOrchestra = new AddOrchestraAction();
60 protected final Action actionEditOrchestra = new EditOrchestraAction();
61 protected final Action actionDeleteOrchestra = new DeleteOrchestraAction();
62 protected final Action actionOrchestraUp = new OrchestraUpAction();
63 protected final Action actionOrchestraDown = new OrchestraDownAction();
64
65 /** Creates a new instance of <code>JSManageOrchestrasPane</code> */
66 public
67 JSManageOrchestrasPane() {
68 setLayout(new BorderLayout());
69 orchestraTable = new OrchestraTable(new OrchestraTableModel(CC.getOrchestras()));
70 JScrollPane sp = new JScrollPane(orchestraTable);
71 add(sp);
72
73 installListeneres();
74 }
75
76 private void
77 installListeneres() {
78 OrchestraSelectionHandler l = new OrchestraSelectionHandler();
79 orchestraTable.getSelectionModel().addListSelectionListener(l);
80
81 orchestraTable.addMouseListener(new MouseAdapter() {
82 public void
83 mouseClicked(MouseEvent e) {
84 if(e.getClickCount() < 2) return;
85
86 if(orchestraTable.getSelectedOrchestra() == null) return;
87 editOrchestra(orchestraTable.getSelectedOrchestra());
88 }
89 });
90
91 KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
92 orchestraTable.getInputMap(JComponent.WHEN_FOCUSED).put(k, "deleteOrchestra");
93 orchestraTable.getActionMap().put("deleteOrchestra", actionDeleteOrchestra);
94 }
95
96 /**
97 * Invoked when the user initiates the creation of new orchestra.
98 * @return The model of the orchestra to add
99 * or <code>null</code> if the user cancelled the task.
100 */
101 public OrchestraModel
102 createOrchestra() {
103 JSAddOrEditOrchestraDlg dlg = new JSAddOrEditOrchestraDlg();
104 dlg.setVisible(true);
105
106 if(dlg.isCancelled()) return null;
107
108 return dlg.getOrchestra();
109 }
110
111 public void
112 editOrchestra(OrchestraModel model) {
113 JSAddOrEditOrchestraDlg dlg = new JSAddOrEditOrchestraDlg(model);
114 dlg.setVisible(true);
115 }
116
117 private class OrchestraSelectionHandler implements ListSelectionListener {
118 public void
119 valueChanged(ListSelectionEvent e) {
120 if(e.getValueIsAdjusting()) return;
121
122 if(orchestraTable.getSelectedOrchestra() == null) {
123 actionEditOrchestra.setEnabled(false);
124 actionDeleteOrchestra.setEnabled(false);
125 actionOrchestraUp.setEnabled(false);
126 actionOrchestraDown.setEnabled(false);
127 return;
128 }
129
130 actionEditOrchestra.setEnabled(true);
131 actionDeleteOrchestra.setEnabled(true);
132
133 OrchestraModel orchestraModel = orchestraTable.getSelectedOrchestra();
134 int idx = orchestraTable.getSelectedRow();
135 actionOrchestraUp.setEnabled(idx != 0);
136 actionOrchestraDown.setEnabled(idx != orchestraTable.getRowCount() - 1);
137 }
138 }
139
140 private class AddOrchestraAction extends AbstractAction {
141 AddOrchestraAction() {
142 super("");
143
144 String s = i18n.getLabel("JSManageOrchestrasPane.ttAddOrchestra");
145 putValue(SHORT_DESCRIPTION, s);
146 }
147
148 public void
149 actionPerformed(ActionEvent e) {
150 OrchestraModel newOrch = createOrchestra();
151 if(newOrch == null) return;
152
153 OrchestraModel om = orchestraTable.getSelectedOrchestra();
154 int idx = CC.getOrchestras().getOrchestraIndex(om);
155 if(idx < 0) CC.getOrchestras().addOrchestra(newOrch);
156 else CC.getOrchestras().insertOrchestra(newOrch, idx);
157
158 orchestraTable.setSelectedOrchestra(newOrch);
159 }
160 }
161
162 private class EditOrchestraAction extends AbstractAction {
163 EditOrchestraAction() {
164 super("");
165
166 String s = i18n.getLabel("JSManageOrchestrasPane.ttEditOrchestra");
167 putValue(SHORT_DESCRIPTION, s);
168
169 setEnabled(false);
170 }
171
172 public void
173 actionPerformed(ActionEvent e) {
174 editOrchestra(orchestraTable.getSelectedOrchestra());
175 }
176 }
177
178 private class DeleteOrchestraAction extends AbstractAction {
179 DeleteOrchestraAction() {
180 super("");
181
182 String s = i18n.getLabel("JSManageOrchestrasPane.ttDeleteOrchestra");
183 putValue(SHORT_DESCRIPTION, s);
184
185 setEnabled(false);
186 }
187
188 public void
189 actionPerformed(ActionEvent e) {
190 OrchestraModel om = orchestraTable.getSelectedOrchestra();
191 if(om == null) return;
192 if(om.getInstrumentCount() > 0) {
193 String s;
194 s = i18n.getMessage("JSManageOrchestrasPane.removeOrchestra?");
195 if(!HF.showYesNoDialog(CC.getMainFrame(), s)) return;
196 }
197
198 int i = orchestraTable.getSelectedRow();
199 CC.getOrchestras().removeOrchestra(om);
200 if(orchestraTable.getRowCount() > i) {
201 orchestraTable.getSelectionModel().setSelectionInterval(i, i);
202 }
203 }
204 }
205
206 private class OrchestraUpAction extends AbstractAction {
207 OrchestraUpAction() {
208 super("");
209
210 String s = i18n.getLabel("JSManageOrchestrasPane.ttOrchestraUp");
211 putValue(SHORT_DESCRIPTION, s);
212
213 setEnabled(false);
214 }
215
216 public void
217 actionPerformed(ActionEvent e) {
218 OrchestraModel om = orchestraTable.getSelectedOrchestra();
219 CC.getOrchestras().moveOrchestraUp(om);
220 orchestraTable.setSelectedOrchestra(om);
221 }
222 }
223
224 private class OrchestraDownAction extends AbstractAction {
225 OrchestraDownAction() {
226 super("");
227
228 String s = i18n.getLabel("JSManageOrchestrasPane.ttOrchestraDown");
229 putValue(SHORT_DESCRIPTION, s);
230
231 setEnabled(false);
232 }
233
234 public void
235 actionPerformed(ActionEvent e) {
236 OrchestraModel om = orchestraTable.getSelectedOrchestra();
237 CC.getOrchestras().moveOrchestraDown(om);
238 orchestraTable.setSelectedOrchestra(om);
239 }
240 }
241 }

  ViewVC Help
Powered by ViewVC