1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
2288 |
* Copyright (C) 2005-2011 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.event.ActionEvent; |
26 |
|
|
|
27 |
iliev |
1871 |
import java.io.File; |
28 |
iliev |
1286 |
import java.io.FileOutputStream; |
29 |
|
|
|
30 |
|
|
import java.util.logging.Level; |
31 |
|
|
|
32 |
|
|
import javax.swing.AbstractAction; |
33 |
|
|
import javax.swing.Action; |
34 |
|
|
|
35 |
iliev |
1785 |
import javax.swing.JMenu; |
36 |
|
|
import javax.swing.JMenuItem; |
37 |
|
|
import javax.swing.SwingUtilities; |
38 |
iliev |
1818 |
|
39 |
iliev |
1286 |
import org.jsampler.CC; |
40 |
|
|
import org.jsampler.HF; |
41 |
|
|
import org.jsampler.JSPrefs; |
42 |
iliev |
1915 |
import org.jsampler.JSUtils; |
43 |
iliev |
1785 |
import org.jsampler.SamplerChannelModel; |
44 |
iliev |
1818 |
|
45 |
|
|
import org.jsampler.view.JSChannel; |
46 |
iliev |
1785 |
import org.jsampler.view.JSChannelsPane; |
47 |
iliev |
2288 |
import org.jsampler.view.swing.SHF; |
48 |
iliev |
1286 |
|
49 |
|
|
import static org.jsampler.view.std.StdI18n.i18n; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* This class provides an <code>Action</code> instances performing some of the common tasks. |
54 |
|
|
* @author Grigor Iliev |
55 |
|
|
*/ |
56 |
iliev |
1567 |
public class StdA4n { |
57 |
|
|
protected static StdA4n a4n = new StdA4n(); |
58 |
|
|
|
59 |
iliev |
1286 |
protected StdA4n() { } |
60 |
|
|
|
61 |
iliev |
1567 |
protected JSPrefs preferences() { return CC.getViewConfig().preferences(); } |
62 |
iliev |
1286 |
|
63 |
|
|
protected void |
64 |
|
|
exportSamplerConfig() { |
65 |
iliev |
1871 |
File f = StdUtils.showSaveLscpFileChooser(); |
66 |
|
|
if(f == null) return; |
67 |
iliev |
1883 |
|
68 |
|
|
boolean b = preferences().getBoolProperty("nativeFileChoosers"); |
69 |
|
|
// On Mac OS the native file chooser asks whether to replace a file |
70 |
|
|
if(f.exists() && !(CC.isMacOS() && b)) { |
71 |
iliev |
1871 |
String msg = i18n.getMessage("StdA4n.overwriteFile?"); |
72 |
iliev |
2288 |
if(!SHF.showYesNoDialog(SHF.getMainFrame(), msg)) return; |
73 |
iliev |
1871 |
} |
74 |
iliev |
1883 |
|
75 |
iliev |
1286 |
try { |
76 |
iliev |
1871 |
FileOutputStream fos = new FileOutputStream(f); |
77 |
iliev |
1915 |
fos.write(JSUtils.exportSessionToLscpScript().getBytes("US-ASCII")); |
78 |
iliev |
1286 |
fos.close(); |
79 |
|
|
} catch(Exception x) { |
80 |
|
|
CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x); |
81 |
iliev |
2288 |
SHF.showErrorMessage(x); |
82 |
iliev |
1286 |
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
protected void |
86 |
|
|
exportMidiInstrumentMaps() { |
87 |
iliev |
1915 |
File f = StdUtils.showSaveMidiMapsChooser(); |
88 |
iliev |
1871 |
if(f == null) return; |
89 |
|
|
|
90 |
iliev |
1883 |
boolean b = preferences().getBoolProperty("nativeFileChoosers"); |
91 |
|
|
// On Mac OS the native file chooser asks whether to replace a file |
92 |
|
|
if(f.exists() && !(CC.isMacOS() && b)) { |
93 |
iliev |
1871 |
String msg = i18n.getMessage("StdA4n.overwriteFile?"); |
94 |
iliev |
2288 |
if(!SHF.showYesNoDialog(SHF.getMainFrame(), msg)) return; |
95 |
iliev |
1871 |
} |
96 |
iliev |
1915 |
|
97 |
|
|
String ext = ""; |
98 |
|
|
int i = f.getName().lastIndexOf('.'); |
99 |
|
|
if(i != -1) { |
100 |
|
|
ext = f.getName().substring(i).toLowerCase(); |
101 |
|
|
} |
102 |
iliev |
1286 |
|
103 |
|
|
try { |
104 |
iliev |
1915 |
FileOutputStream fos; |
105 |
|
|
if(ext.equals(".lscp")) { |
106 |
|
|
fos = new FileOutputStream(f); |
107 |
|
|
fos.write(JSUtils.exportInstrMapsToLscpScript().getBytes("US-ASCII")); |
108 |
|
|
} else if(ext.equals(".txt")) { |
109 |
|
|
fos = new FileOutputStream(f); |
110 |
|
|
fos.write(JSUtils.exportInstrMapsToText().getBytes("US-ASCII")); |
111 |
|
|
} else if(ext.equals(".htm") || ext.equals(".html")) { |
112 |
|
|
fos = new FileOutputStream(f); |
113 |
|
|
fos.write(JSUtils.exportInstrMapsToHtml().getBytes("US-ASCII")); |
114 |
iliev |
1916 |
} else if(ext.equals(".rgd")) { |
115 |
|
|
byte[] data = JSUtils.exportInstrMapsToRGD(); |
116 |
|
|
if(data == null) { |
117 |
|
|
String s = i18n.getError("StdA4n.rgdExportFailed"); |
118 |
iliev |
2288 |
SHF.showErrorMessage(s); |
119 |
iliev |
1916 |
return; |
120 |
|
|
} |
121 |
|
|
fos = new FileOutputStream(f); |
122 |
|
|
fos.write(data); |
123 |
iliev |
1915 |
} else { |
124 |
|
|
f = new File(f.getAbsolutePath() + ".lscp"); |
125 |
|
|
if(f.exists()) { |
126 |
|
|
String s = i18n.getError("StdA4n.fileExists", f.getAbsolutePath()); |
127 |
iliev |
2288 |
SHF.showErrorMessage(s); |
128 |
iliev |
1915 |
return; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
fos = new FileOutputStream(f); |
132 |
|
|
fos.write(JSUtils.exportInstrMapsToLscpScript().getBytes("US-ASCII")); |
133 |
|
|
} |
134 |
|
|
|
135 |
iliev |
1286 |
fos.close(); |
136 |
|
|
} catch(Exception x) { |
137 |
|
|
CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x); |
138 |
iliev |
2288 |
SHF.showErrorMessage(x); |
139 |
iliev |
1785 |
} |
140 |
iliev |
1286 |
} |
141 |
|
|
|
142 |
|
|
public final Action connect = new Connect(); |
143 |
|
|
|
144 |
|
|
private class Connect extends AbstractAction { |
145 |
|
|
Connect() { |
146 |
|
|
super(i18n.getMenuLabel("actions.connect")); |
147 |
|
|
|
148 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.connect.tt")); |
149 |
|
|
} |
150 |
|
|
|
151 |
iliev |
1785 |
@Override |
152 |
iliev |
1286 |
public void |
153 |
|
|
actionPerformed(ActionEvent e) { CC.reconnect(); } |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
public final Action refresh = new Refresh(); |
157 |
|
|
|
158 |
|
|
private class Refresh extends AbstractAction { |
159 |
|
|
Refresh() { |
160 |
|
|
super(i18n.getMenuLabel("actions.refresh")); |
161 |
|
|
|
162 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.refresh.tt")); |
163 |
|
|
} |
164 |
|
|
|
165 |
iliev |
1818 |
@Override |
166 |
iliev |
1286 |
public void |
167 |
iliev |
1688 |
actionPerformed(ActionEvent e) { |
168 |
|
|
if(!CC.verifyConnection()) { |
169 |
|
|
CC.changeBackend(); |
170 |
|
|
return; |
171 |
|
|
} |
172 |
|
|
CC.reconnect(); |
173 |
|
|
} |
174 |
iliev |
1286 |
} |
175 |
|
|
|
176 |
|
|
public final Action resetSampler = new Reset(); |
177 |
|
|
|
178 |
|
|
private class Reset extends AbstractAction { |
179 |
|
|
Reset() { |
180 |
|
|
super(i18n.getMenuLabel("actions.resetSampler")); |
181 |
|
|
|
182 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.resetSampler.tt")); |
183 |
|
|
} |
184 |
|
|
|
185 |
iliev |
1818 |
@Override |
186 |
iliev |
1286 |
public void |
187 |
iliev |
1688 |
actionPerformed(ActionEvent e) { |
188 |
|
|
if(!CC.verifyConnection()) return; |
189 |
|
|
|
190 |
|
|
String s = i18n.getMessage("StdA4n.resetSampler?"); |
191 |
iliev |
2288 |
if(!SHF.showYesNoDialog(SHF.getMainFrame(), s)) return; |
192 |
iliev |
1688 |
CC.getSamplerModel().resetBackend(); |
193 |
|
|
} |
194 |
iliev |
1286 |
} |
195 |
|
|
|
196 |
|
|
public final Action exportSamplerConfig = new ExportSamplerConfig(); |
197 |
|
|
|
198 |
|
|
private class ExportSamplerConfig extends AbstractAction { |
199 |
|
|
ExportSamplerConfig() { |
200 |
|
|
super(i18n.getMenuLabel("actions.export.samplerConfiguration")); |
201 |
|
|
|
202 |
|
|
String s = i18n.getMenuLabel("actions.export.samplerConfiguration.tt"); |
203 |
|
|
putValue(SHORT_DESCRIPTION, s); |
204 |
|
|
|
205 |
|
|
} |
206 |
|
|
|
207 |
iliev |
1818 |
@Override |
208 |
iliev |
1286 |
public void |
209 |
|
|
actionPerformed(ActionEvent e) { |
210 |
iliev |
1688 |
if(!CC.verifyConnection()) return; |
211 |
iliev |
1286 |
exportSamplerConfig(); |
212 |
|
|
} |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
public final Action exportMidiInstrumentMaps = new ExportMidiInstrumentMaps(); |
216 |
|
|
|
217 |
|
|
private class ExportMidiInstrumentMaps extends AbstractAction { |
218 |
|
|
ExportMidiInstrumentMaps() { |
219 |
|
|
super(i18n.getMenuLabel("actions.export.MidiInstrumentMaps")); |
220 |
|
|
|
221 |
|
|
String s = i18n.getMenuLabel("actions.export.MidiInstrumentMaps.tt"); |
222 |
|
|
putValue(SHORT_DESCRIPTION, s); |
223 |
|
|
} |
224 |
|
|
|
225 |
iliev |
1818 |
@Override |
226 |
iliev |
1286 |
public void |
227 |
|
|
actionPerformed(ActionEvent e) { |
228 |
iliev |
1688 |
if(!CC.verifyConnection()) return; |
229 |
iliev |
1286 |
exportMidiInstrumentMaps(); |
230 |
|
|
} |
231 |
|
|
} |
232 |
iliev |
1496 |
|
233 |
iliev |
1688 |
public final Action changeBackend = new ChangeBackend(); |
234 |
|
|
|
235 |
|
|
private class ChangeBackend extends AbstractAction { |
236 |
|
|
ChangeBackend() { |
237 |
|
|
super(i18n.getMenuLabel("actions.changeBackend")); |
238 |
|
|
|
239 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.changeBackend.tt")); |
240 |
|
|
} |
241 |
|
|
|
242 |
iliev |
1818 |
@Override |
243 |
iliev |
1688 |
public void |
244 |
|
|
actionPerformed(ActionEvent e) { CC.changeBackend(); } |
245 |
|
|
} |
246 |
|
|
|
247 |
iliev |
1818 |
|
248 |
|
|
public final Action moveChannelsOnTop = new MoveChannelsOnTop(); |
249 |
|
|
|
250 |
|
|
private class MoveChannelsOnTop extends AbstractAction { |
251 |
|
|
MoveChannelsOnTop() { |
252 |
|
|
super(i18n.getMenuLabel("channels.moveOnTop")); |
253 |
|
|
|
254 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.moveOnTop.tt")); |
255 |
|
|
setEnabled(false); |
256 |
|
|
} |
257 |
|
|
|
258 |
|
|
@Override |
259 |
|
|
public void |
260 |
|
|
actionPerformed(ActionEvent e) { |
261 |
|
|
JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
262 |
|
|
p.moveSelectedChannelsOnTop(); |
263 |
|
|
} |
264 |
|
|
} |
265 |
|
|
|
266 |
|
|
public final Action moveChannelsUp = new MoveChannelsUp(); |
267 |
|
|
|
268 |
|
|
private class MoveChannelsUp extends AbstractAction { |
269 |
|
|
MoveChannelsUp() { |
270 |
|
|
super(i18n.getMenuLabel("channels.moveUp")); |
271 |
|
|
|
272 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.moveUp.tt")); |
273 |
|
|
setEnabled(false); |
274 |
|
|
} |
275 |
|
|
|
276 |
|
|
@Override |
277 |
|
|
public void |
278 |
|
|
actionPerformed(ActionEvent e) { |
279 |
|
|
JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
280 |
|
|
p.moveSelectedChannelsUp(); |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
|
284 |
|
|
public final Action moveChannelsDown = new MoveChannelsDown(); |
285 |
|
|
|
286 |
|
|
private class MoveChannelsDown extends AbstractAction { |
287 |
|
|
MoveChannelsDown() { |
288 |
|
|
super(i18n.getMenuLabel("channels.moveDown")); |
289 |
|
|
|
290 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.moveDown.tt")); |
291 |
|
|
setEnabled(false); |
292 |
|
|
} |
293 |
|
|
|
294 |
|
|
@Override |
295 |
|
|
public void |
296 |
|
|
actionPerformed(ActionEvent e) { |
297 |
|
|
JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
298 |
|
|
p.moveSelectedChannelsDown(); |
299 |
|
|
} |
300 |
|
|
} |
301 |
|
|
|
302 |
|
|
public final Action moveChannelsAtBottom = new MoveChannelsAtBottom(); |
303 |
|
|
|
304 |
|
|
private class MoveChannelsAtBottom extends AbstractAction { |
305 |
|
|
MoveChannelsAtBottom() { |
306 |
|
|
super(i18n.getMenuLabel("channels.moveAtBottom")); |
307 |
|
|
|
308 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.moveAtBottom.tt")); |
309 |
|
|
setEnabled(false); |
310 |
|
|
} |
311 |
|
|
|
312 |
|
|
@Override |
313 |
|
|
public void |
314 |
|
|
actionPerformed(ActionEvent e) { |
315 |
|
|
JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
316 |
|
|
p.moveSelectedChannelsAtBottom(); |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
public final Action duplicateChannels = new DuplicateChannels(); |
321 |
|
|
|
322 |
|
|
private static class DuplicateChannels extends AbstractAction { |
323 |
|
|
DuplicateChannels() { |
324 |
|
|
super(i18n.getMenuLabel("channels.duplicate")); |
325 |
|
|
|
326 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.duplicateChannels.tt")); |
327 |
|
|
|
328 |
|
|
setEnabled(false); |
329 |
|
|
} |
330 |
|
|
|
331 |
iliev |
1871 |
@Override |
332 |
iliev |
1818 |
public void |
333 |
|
|
actionPerformed(ActionEvent e) { |
334 |
|
|
JSChannel[] channels = |
335 |
|
|
CC.getMainFrame().getSelectedChannelsPane().getSelectedChannels(); |
336 |
|
|
|
337 |
|
|
if(channels.length > 2) { |
338 |
iliev |
2288 |
if(!SHF.showYesNoDialog ( |
339 |
|
|
SHF.getMainFrame(), |
340 |
iliev |
1818 |
i18n.getMessage("StdA4n.duplicateChannels?") |
341 |
|
|
)) return; |
342 |
|
|
} |
343 |
|
|
|
344 |
|
|
CC.getTaskQueue().add ( |
345 |
|
|
new org.jsampler.task.DuplicateChannels(channels) |
346 |
|
|
); |
347 |
|
|
} |
348 |
|
|
} |
349 |
|
|
|
350 |
|
|
public final Action removeChannels = new RemoveChannels(); |
351 |
|
|
|
352 |
|
|
private static class RemoveChannels extends AbstractAction { |
353 |
|
|
RemoveChannels() { |
354 |
|
|
super(i18n.getMenuLabel("channels.removeChannel")); |
355 |
|
|
|
356 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.removeChannels.tt")); |
357 |
|
|
|
358 |
|
|
setEnabled(false); |
359 |
|
|
} |
360 |
|
|
|
361 |
iliev |
1871 |
@Override |
362 |
iliev |
1818 |
public void |
363 |
|
|
actionPerformed(ActionEvent e) { |
364 |
|
|
JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
365 |
|
|
if(p.getSelectedChannelCount() > 1) |
366 |
iliev |
2288 |
if(!SHF.showYesNoDialog ( |
367 |
|
|
SHF.getMainFrame(), i18n.getMessage("StdA4n.removeChannels?") |
368 |
iliev |
1818 |
)) return; |
369 |
|
|
|
370 |
|
|
JSChannel[] chnS = p.getSelectedChannels(); |
371 |
|
|
|
372 |
|
|
for(JSChannel c : chnS) removeChannel(c); |
373 |
|
|
} |
374 |
|
|
|
375 |
|
|
private void |
376 |
|
|
removeChannel(final JSChannel c) { |
377 |
|
|
final JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane(); |
378 |
|
|
int id = c.getChannelInfo().getChannelId(); |
379 |
|
|
|
380 |
|
|
CC.getSamplerModel().removeBackendChannel(id); |
381 |
|
|
} |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
public static class |
385 |
iliev |
2288 |
MoveChannelsToPanel extends AbstractAction implements org.jsampler.event.ListSelectionListener { |
386 |
iliev |
1818 |
private final JSChannelsPane pane; |
387 |
|
|
|
388 |
|
|
public |
389 |
|
|
MoveChannelsToPanel(JSChannelsPane pane) { |
390 |
|
|
super(pane.getTitle()); |
391 |
|
|
this.pane = pane; |
392 |
|
|
CC.getMainFrame().addChannelsPaneSelectionListener(this); |
393 |
|
|
valueChanged(null); |
394 |
|
|
} |
395 |
|
|
|
396 |
|
|
@Override |
397 |
|
|
public void |
398 |
|
|
actionPerformed(ActionEvent e) { |
399 |
|
|
JSChannelsPane acp = CC.getMainFrame().getSelectedChannelsPane(); |
400 |
|
|
JSChannel[] chns = acp.getSelectedChannels(); |
401 |
|
|
|
402 |
|
|
for(JSChannel c : chns) acp.removeChannel(c); |
403 |
|
|
|
404 |
|
|
pane.addChannels(chns); |
405 |
|
|
|
406 |
|
|
//CC.getMainFrame().setSelectedChannelsPane(pane); |
407 |
|
|
|
408 |
|
|
} |
409 |
|
|
|
410 |
|
|
@Override |
411 |
|
|
public void |
412 |
iliev |
2288 |
valueChanged(org.jsampler.event.ListSelectionEvent e) { |
413 |
iliev |
1818 |
setEnabled(CC.getMainFrame().getSelectedChannelsPane() != pane); |
414 |
|
|
} |
415 |
|
|
|
416 |
|
|
public JSChannelsPane |
417 |
|
|
getChannelsPane() { return pane; } |
418 |
|
|
} |
419 |
|
|
|
420 |
|
|
public final Action selectAllChannels = new SelectAllChannels(); |
421 |
|
|
|
422 |
|
|
private static class SelectAllChannels extends AbstractAction { |
423 |
|
|
SelectAllChannels() { |
424 |
|
|
super(i18n.getMenuLabel("channels.selectAll")); |
425 |
|
|
|
426 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.selectAll.tt")); |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
@Override |
430 |
|
|
public void |
431 |
|
|
actionPerformed(ActionEvent e) { |
432 |
|
|
CC.getMainFrame().getSelectedChannelsPane().selectAll(); |
433 |
|
|
} |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
public final Action deselectChannels = new DeselectChannels(); |
437 |
|
|
|
438 |
|
|
private static class DeselectChannels extends AbstractAction { |
439 |
|
|
DeselectChannels() { |
440 |
|
|
super(i18n.getMenuLabel("channels.selectNone")); |
441 |
|
|
|
442 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("channels.selectNone.tt")); |
443 |
|
|
} |
444 |
|
|
|
445 |
|
|
@Override |
446 |
|
|
public void |
447 |
|
|
actionPerformed(ActionEvent e) { |
448 |
|
|
CC.getMainFrame().getSelectedChannelsPane().clearSelection(); |
449 |
|
|
} |
450 |
|
|
} |
451 |
|
|
|
452 |
iliev |
1496 |
public final Action browseOnlineTutorial = new BrowseOnlineTutorial(); |
453 |
|
|
|
454 |
|
|
private class BrowseOnlineTutorial extends AbstractAction { |
455 |
|
|
BrowseOnlineTutorial() { |
456 |
|
|
super(i18n.getMenuLabel("help.onlineTutorial")); |
457 |
|
|
|
458 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("help.onlineTutorial.tt")); |
459 |
|
|
} |
460 |
|
|
|
461 |
iliev |
1818 |
@Override |
462 |
iliev |
1496 |
public void |
463 |
|
|
actionPerformed(ActionEvent e) { |
464 |
|
|
StdUtils.browse("http://jsampler.sourceforge.net/"); |
465 |
|
|
} |
466 |
|
|
} |
467 |
iliev |
1785 |
|
468 |
|
|
public static abstract class LoadInstrumentAction extends AbstractAction { |
469 |
|
|
protected final SamplerChannelModel channelModel; |
470 |
|
|
|
471 |
|
|
LoadInstrumentAction(SamplerChannelModel model) { this(model, false); } |
472 |
|
|
|
473 |
|
|
LoadInstrumentAction(SamplerChannelModel model, boolean onPanel) { |
474 |
|
|
String s = onPanel ? "instrumentsdb.actions.loadInstrument.onPanel.channel" |
475 |
|
|
: "instrumentsdb.actions.loadInstrument.onChannel"; |
476 |
|
|
int i = CC.getMainFrame().getChannelNumber(model) + 1; |
477 |
|
|
putValue(Action.NAME, i18n.getMenuLabel(s, i)); |
478 |
|
|
channelModel = model; |
479 |
|
|
} |
480 |
|
|
} |
481 |
|
|
|
482 |
|
|
public static interface LoadInstrumentActionFactory { |
483 |
|
|
public LoadInstrumentAction |
484 |
|
|
createLoadInstrumentAction(SamplerChannelModel model, boolean onPanel); |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
|
488 |
|
|
|
489 |
|
|
public static void |
490 |
|
|
updateLoadInstrumentMenu(final JMenu menu, final LoadInstrumentActionFactory factory) { |
491 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
492 |
|
|
public void |
493 |
|
|
run() { updateLoadInstrumentMenu0(menu, factory); } |
494 |
|
|
}); |
495 |
|
|
} |
496 |
|
|
|
497 |
|
|
private static void |
498 |
|
|
updateLoadInstrumentMenu0(JMenu menu, LoadInstrumentActionFactory factory) { |
499 |
|
|
if(CC.getMainFrame() == null) return; |
500 |
|
|
menu.removeAll(); |
501 |
|
|
int count = 0; |
502 |
|
|
JSChannelsPane chnPane = null; |
503 |
|
|
for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) { |
504 |
|
|
if(CC.getMainFrame().getChannelsPane(i).getChannelCount() == 0) continue; |
505 |
|
|
|
506 |
|
|
chnPane = CC.getMainFrame().getChannelsPane(i); |
507 |
|
|
count++; |
508 |
|
|
String s = "instrumentsdb.actions.loadInstrument.onPanel"; |
509 |
iliev |
2288 |
JMenu m = SHF.getViewConfig().createMultiColumnMenu(i18n.getMenuLabel(s, i + 1)); |
510 |
iliev |
1785 |
for(int j = 0; j < chnPane.getChannelCount(); j++) { |
511 |
|
|
SamplerChannelModel chn = chnPane.getChannel(j).getModel(); |
512 |
|
|
m.add(new JMenuItem(factory.createLoadInstrumentAction(chn, true))); |
513 |
|
|
} |
514 |
|
|
menu.add(m); |
515 |
|
|
} |
516 |
|
|
|
517 |
|
|
if(count == 1 && CC.getMainFrame().getSelectedChannelsPane() == chnPane) { |
518 |
|
|
menu.removeAll(); |
519 |
|
|
|
520 |
|
|
for(int j = 0; j < chnPane.getChannelCount(); j++) { |
521 |
|
|
SamplerChannelModel chn = chnPane.getChannel(j).getModel(); |
522 |
|
|
menu.add(new JMenuItem(factory.createLoadInstrumentAction(chn, false))); |
523 |
|
|
} |
524 |
|
|
} |
525 |
|
|
} |
526 |
iliev |
1286 |
} |