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.classic; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
|
27 |
import java.beans.PropertyChangeEvent; |
28 |
import java.beans.PropertyChangeListener; |
29 |
|
30 |
import javax.swing.AbstractAction; |
31 |
import javax.swing.Action; |
32 |
|
33 |
import org.jsampler.CC; |
34 |
import org.jsampler.HF; |
35 |
|
36 |
import org.jsampler.view.JSChannel; |
37 |
import org.jsampler.view.JSChannelsPane; |
38 |
import org.jsampler.view.JSMainFrame; |
39 |
import org.jsampler.view.std.JSAddMidiInstrumentMapDlg; |
40 |
|
41 |
import org.jsampler.view.std.JSNewMidiDeviceDlg; |
42 |
import org.jsampler.view.std.JSNewAudioDeviceDlg; |
43 |
import org.jsampler.view.std.JSNewMidiInstrumentWizard; |
44 |
import org.jsampler.view.std.StdA4n; |
45 |
|
46 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
47 |
|
48 |
|
49 |
/** |
50 |
* This class provides an <code>Action</code> instances performing all needed tasks. |
51 |
* @author Grigor Iliev |
52 |
*/ |
53 |
public class A4n extends StdA4n { |
54 |
protected static A4n a4n = new A4n(); |
55 |
|
56 |
/** Forbids the instantiation of <code>A4n</code> */ |
57 |
private A4n() { |
58 |
refresh.putValue(Action.SMALL_ICON, Res.iconReload32); |
59 |
resetSampler.putValue(Action.SMALL_ICON, Res.iconReset32); |
60 |
exportSamplerConfig.putValue(Action.SMALL_ICON, Res.iconExportSession32); |
61 |
exportMidiInstrumentMaps.putValue(Action.SMALL_ICON, Res.iconExport16); |
62 |
|
63 |
moveChannelsUp.putValue(Action.SMALL_ICON, Res.iconUp24); |
64 |
moveChannelsDown.putValue(Action.SMALL_ICON, Res.iconDown24); |
65 |
|
66 |
duplicateChannels.putValue(Action.SMALL_ICON, Res.iconCopy24); |
67 |
removeChannels.putValue(Action.SMALL_ICON, Res.iconDelete24); |
68 |
} |
69 |
|
70 |
protected ClassicPrefs |
71 |
preferences() { |
72 |
return ClassicPrefs.preferences(); |
73 |
} |
74 |
|
75 |
private static boolean |
76 |
verifyConnection() { |
77 |
if(!CC.getClient().isConnected()) { |
78 |
HF.showErrorMessage(i18n.getError("notConnected")); |
79 |
return false; |
80 |
} |
81 |
|
82 |
return true; |
83 |
} |
84 |
|
85 |
public final static Action samplerInfo = new SamplerInfo(); |
86 |
|
87 |
private static class SamplerInfo extends AbstractAction { |
88 |
SamplerInfo() { |
89 |
super(i18n.getMenuLabel("actions.samplerInfo")); |
90 |
|
91 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttSamplerInfo")); |
92 |
putValue(Action.SMALL_ICON, Res.iconInfo32); |
93 |
} |
94 |
|
95 |
public void |
96 |
actionPerformed(ActionEvent e) { |
97 |
new SamplerInfoDlg(CC.getMainFrame()).setVisible(true); |
98 |
} |
99 |
} |
100 |
|
101 |
public final static Action addMidiInstrumentMap = new AddMidiInstrumentMap(); |
102 |
|
103 |
private static class AddMidiInstrumentMap extends AbstractAction { |
104 |
AddMidiInstrumentMap() { |
105 |
super(i18n.getMenuLabel("actions.midiInstruments.addMap")); |
106 |
|
107 |
String s = i18n.getMenuLabel("actions.midiInstruments.addMap.tt"); |
108 |
putValue(SHORT_DESCRIPTION, s); |
109 |
putValue(Action.SMALL_ICON, Res.iconNew16); |
110 |
} |
111 |
|
112 |
public void |
113 |
actionPerformed(ActionEvent e) { |
114 |
JSAddMidiInstrumentMapDlg dlg = new JSAddMidiInstrumentMapDlg(); |
115 |
dlg.setVisible(true); |
116 |
if(dlg.isCancelled()) return; |
117 |
|
118 |
CC.getSamplerModel().addBackendMidiInstrumentMap(dlg.getMapName()); |
119 |
LeftPane.getLeftPane().showMidiInstrumentMapsPage(); |
120 |
} |
121 |
} |
122 |
|
123 |
public final static Action removeMidiInstrumentMap = new RemoveMidiInstrumentMap(); |
124 |
|
125 |
private static class RemoveMidiInstrumentMap extends AbstractAction { |
126 |
RemoveMidiInstrumentMap() { |
127 |
super(i18n.getMenuLabel("actions.midiInstruments.removeMap")); |
128 |
|
129 |
String s = i18n.getMenuLabel("actions.midiInstruments.removeMap.tt"); |
130 |
putValue(SHORT_DESCRIPTION, s); |
131 |
putValue(Action.SMALL_ICON, Res.iconDelete16); |
132 |
} |
133 |
|
134 |
public void |
135 |
actionPerformed(ActionEvent e) { |
136 |
RemoveMidiInstrumentMapDlg dlg = new RemoveMidiInstrumentMapDlg(); |
137 |
dlg.setVisible(true); |
138 |
if(dlg.isCancelled()) return; |
139 |
int id = dlg.getSelectedMap().getMapId(); |
140 |
CC.getSamplerModel().removeBackendMidiInstrumentMap(id); |
141 |
} |
142 |
} |
143 |
|
144 |
public final static Action addMidiInstrumentWizard = new AddMidiInstrumentWizard(); |
145 |
|
146 |
private static class AddMidiInstrumentWizard extends AbstractAction { |
147 |
AddMidiInstrumentWizard() { |
148 |
super(i18n.getMenuLabel("actions.midiInstruments.newMidiInstrumentWizard")); |
149 |
|
150 |
String s = "actions.midiInstruments.newMidiInstrumentWizard.tt"; |
151 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel(s)); |
152 |
putValue(Action.SMALL_ICON, Res.iconNew16); |
153 |
} |
154 |
|
155 |
public void |
156 |
actionPerformed(ActionEvent e) { |
157 |
ClassicPrefs prefs = ClassicPrefs.preferences(); |
158 |
JSNewMidiInstrumentWizard wizard = |
159 |
new JSNewMidiInstrumentWizard(Res.iconFolderOpen16); |
160 |
|
161 |
wizard.getWizardDialog().setResizable(false); |
162 |
|
163 |
if(prefs.getBoolProperty("NewMidiInstrumentWizard.skip1")) { |
164 |
if(wizard.getModel().getCurrentPage() == null) { |
165 |
wizard.getModel().next(); |
166 |
} |
167 |
wizard.getModel().next(); |
168 |
} |
169 |
|
170 |
wizard.showWizard(); |
171 |
|
172 |
} |
173 |
} |
174 |
|
175 |
public final static Action loadScript = new LoadLscpScript(); |
176 |
|
177 |
private static class LoadLscpScript extends AbstractAction { |
178 |
LoadLscpScript() { |
179 |
super(i18n.getMenuLabel("actions.runScript")); |
180 |
|
181 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRunScript")); |
182 |
putValue(Action.SMALL_ICON, Res.iconLoadScript32); |
183 |
} |
184 |
|
185 |
public void |
186 |
actionPerformed(ActionEvent e) { |
187 |
((MainFrame)CC.getMainFrame()).runScript(); |
188 |
} |
189 |
} |
190 |
|
191 |
public final static Action addMidiDevice = new AddMidiDevice(); |
192 |
|
193 |
private static class AddMidiDevice extends AbstractAction { |
194 |
AddMidiDevice() { |
195 |
super(""); |
196 |
|
197 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAddMidiDevice")); |
198 |
putValue(Action.SMALL_ICON, Res.iconNew16); |
199 |
} |
200 |
|
201 |
public void |
202 |
actionPerformed(ActionEvent e) { |
203 |
if(!verifyConnection()) return; |
204 |
new JSNewMidiDeviceDlg(CC.getMainFrame()).setVisible(true); |
205 |
} |
206 |
} |
207 |
|
208 |
public final static Action addAudioDevice = new AddAudioDevice(); |
209 |
|
210 |
private static class AddAudioDevice extends AbstractAction { |
211 |
AddAudioDevice() { |
212 |
super(""); |
213 |
|
214 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAddAudioDevice")); |
215 |
putValue(Action.SMALL_ICON, Res.iconNew16); |
216 |
} |
217 |
|
218 |
public void |
219 |
actionPerformed(ActionEvent e) { |
220 |
if(!verifyConnection()) return; |
221 |
new JSNewAudioDeviceDlg(CC.getMainFrame()).setVisible(true); |
222 |
} |
223 |
} |
224 |
|
225 |
// EDIT |
226 |
public final static Action preferences = new Preferences(); |
227 |
|
228 |
private static class Preferences extends AbstractAction { |
229 |
Preferences() { |
230 |
super(i18n.getMenuLabel("edit.preferences")); |
231 |
|
232 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttPrefs")); |
233 |
putValue(Action.SMALL_ICON, Res.iconPreferences32); |
234 |
} |
235 |
|
236 |
public void |
237 |
actionPerformed(ActionEvent e) { new PrefsDlg(CC.getMainFrame()).setVisible(true); } |
238 |
} |
239 |
|
240 |
// VIEW |
241 |
|
242 |
|
243 |
|
244 |
// CHANNELS |
245 |
public final static Action newChannel = new NewChannel(); |
246 |
public final static Action newChannelWizard = new NewChannelWizard(); |
247 |
|
248 |
|
249 |
private static class NewChannel extends AbstractAction { |
250 |
NewChannel() { |
251 |
super(i18n.getMenuLabel("channels.new")); |
252 |
|
253 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannel")); |
254 |
putValue(Action.SMALL_ICON, Res.iconNew24); |
255 |
} |
256 |
|
257 |
public void |
258 |
actionPerformed(ActionEvent e) { |
259 |
if(!verifyConnection()) return; |
260 |
CC.getSamplerModel().addBackendChannel(); |
261 |
} |
262 |
} |
263 |
|
264 |
private static class NewChannelWizard extends AbstractAction { |
265 |
NewChannelWizard() { |
266 |
super(i18n.getMenuLabel("channels.wizard")); |
267 |
|
268 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannelWizard")); |
269 |
} |
270 |
|
271 |
public void |
272 |
actionPerformed(ActionEvent e) { |
273 |
new org.jsampler.view.classic.NewChannelWizard().showWizard(); |
274 |
} |
275 |
} |
276 |
|
277 |
public static class |
278 |
MoveChannelsTo extends AbstractAction implements PropertyChangeListener { |
279 |
private final JSChannelsPane pane; |
280 |
|
281 |
MoveChannelsTo(JSChannelsPane pane) { |
282 |
super(pane.getTitle()); |
283 |
|
284 |
this.pane = pane; |
285 |
|
286 |
String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle()); |
287 |
putValue(SHORT_DESCRIPTION, desc); |
288 |
pane.addPropertyChangeListener(JSChannelsPane.TITLE, this); |
289 |
} |
290 |
|
291 |
public void |
292 |
actionPerformed(ActionEvent e) { |
293 |
JSChannelsPane acp = CC.getMainFrame().getSelectedChannelsPane(); |
294 |
JSChannel[] chns = acp.getSelectedChannels(); |
295 |
|
296 |
for(JSChannel c : chns) acp.removeChannel(c); |
297 |
|
298 |
pane.addChannels(chns); |
299 |
|
300 |
CC.getMainFrame().setSelectedChannelsPane(pane); |
301 |
|
302 |
} |
303 |
|
304 |
public void |
305 |
propertyChange(PropertyChangeEvent e) { |
306 |
putValue(NAME, pane.getTitle()); |
307 |
|
308 |
String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle()); |
309 |
putValue(SHORT_DESCRIPTION, desc); |
310 |
} |
311 |
|
312 |
public JSChannelsPane |
313 |
getChannelsPane() { return pane; } |
314 |
} |
315 |
|
316 |
// TABS |
317 |
public final static Action newChannelsTab = new NewChannelsTab(); |
318 |
|
319 |
public final static Action editTabTitle = new EditTabTitle(); |
320 |
|
321 |
public final static Action moveTab2Beginning = new MoveTab2Beginning(); |
322 |
public final static Action moveTab2Left = new MoveTab2Left(); |
323 |
public final static Action moveTab2Right = new MoveTab2Right(); |
324 |
public final static Action moveTab2End = new MoveTab2End(); |
325 |
|
326 |
public final static Action closeChannelsTab = new CloseChannelsTab(); |
327 |
|
328 |
|
329 |
private static class NewChannelsTab extends AbstractAction { |
330 |
NewChannelsTab() { |
331 |
super(i18n.getMenuLabel("tabs.new")); |
332 |
|
333 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewTab")); |
334 |
putValue(Action.SMALL_ICON, Res.iconTabNew22); |
335 |
} |
336 |
|
337 |
public void |
338 |
actionPerformed(ActionEvent e) { |
339 |
new NewChannelsTabDlg(CC.getMainFrame()).setVisible(true); |
340 |
} |
341 |
} |
342 |
|
343 |
private static class EditTabTitle extends AbstractAction { |
344 |
EditTabTitle() { |
345 |
super(i18n.getMenuLabel("tabs.changeTitle")); |
346 |
|
347 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttEditTabTitle")); |
348 |
setEnabled(false); |
349 |
} |
350 |
|
351 |
public void |
352 |
actionPerformed(ActionEvent e) { |
353 |
new ChangeTabTitleDlg(CC.getMainFrame()).setVisible(true); |
354 |
} |
355 |
} |
356 |
|
357 |
private static class MoveTab2Beginning extends AbstractAction { |
358 |
MoveTab2Beginning() { |
359 |
super(i18n.getMenuLabel("tabs.move2Beginning")); |
360 |
|
361 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Beginning")); |
362 |
setEnabled(false); |
363 |
} |
364 |
|
365 |
public void |
366 |
actionPerformed(ActionEvent e) { |
367 |
((MainFrame)CC.getMainFrame()).moveTab2Beginning(); |
368 |
} |
369 |
} |
370 |
|
371 |
private static class MoveTab2Left extends AbstractAction { |
372 |
MoveTab2Left() { |
373 |
super(i18n.getMenuLabel("tabs.move2Left")); |
374 |
|
375 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Left")); |
376 |
putValue(Action.SMALL_ICON, Res.iconTabMoveLeft22); |
377 |
setEnabled(false); |
378 |
} |
379 |
|
380 |
public void |
381 |
actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Left(); } |
382 |
} |
383 |
|
384 |
private static class MoveTab2Right extends AbstractAction { |
385 |
MoveTab2Right() { |
386 |
super(i18n.getMenuLabel("tabs.move2Right")); |
387 |
|
388 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Right")); |
389 |
putValue(Action.SMALL_ICON, Res.iconTabMoveRight22); |
390 |
setEnabled(false); |
391 |
} |
392 |
|
393 |
public void |
394 |
actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Right(); } |
395 |
} |
396 |
|
397 |
private static class MoveTab2End extends AbstractAction { |
398 |
MoveTab2End() { |
399 |
super(i18n.getMenuLabel("tabs.move2End")); |
400 |
|
401 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2End")); |
402 |
setEnabled(false); |
403 |
} |
404 |
|
405 |
public void |
406 |
actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2End(); } |
407 |
} |
408 |
|
409 |
private static class CloseChannelsTab extends AbstractAction { |
410 |
CloseChannelsTab() { |
411 |
super(i18n.getMenuLabel("tabs.close")); |
412 |
|
413 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttCloseTab")); |
414 |
putValue(Action.SMALL_ICON, Res.iconTabRemove22); |
415 |
setEnabled(false); |
416 |
} |
417 |
|
418 |
public void |
419 |
actionPerformed(ActionEvent e) { |
420 |
JSMainFrame frm = CC.getMainFrame(); |
421 |
JSChannelsPane chnPane = frm.getSelectedChannelsPane(); |
422 |
if(chnPane.getChannelCount() > 0) { |
423 |
CloseTabDlg dlg = new CloseTabDlg(frm); |
424 |
dlg.setVisible(true); |
425 |
if(dlg.isCancelled()) return; |
426 |
|
427 |
JSChannel[] chns = chnPane.getChannels(); |
428 |
|
429 |
if(dlg.remove()) { |
430 |
|
431 |
|
432 |
} else { |
433 |
JSChannelsPane p = dlg.getSelectedChannelsPane(); |
434 |
for(JSChannel c : chns) { |
435 |
chnPane.removeChannel(c); |
436 |
} |
437 |
p.addChannels(chns); |
438 |
frm.setSelectedChannelsPane(p); |
439 |
} |
440 |
} |
441 |
|
442 |
frm.removeChannelsPane(chnPane); |
443 |
} |
444 |
} |
445 |
|
446 |
// WINDOW |
447 |
public final static WindowInstrumentsDb windowInstrumentsDb = new WindowInstrumentsDb(); |
448 |
|
449 |
private static class WindowInstrumentsDb extends AbstractAction { |
450 |
InstrumentsDbFrame instrumentsDbFrame = null; |
451 |
|
452 |
WindowInstrumentsDb() { |
453 |
super(i18n.getMenuLabel("window.instrumentsDb")); |
454 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("window.instrumentsDb.tt")); |
455 |
putValue(Action.SMALL_ICON, Res.iconDb32); |
456 |
} |
457 |
|
458 |
public void |
459 |
actionPerformed(ActionEvent e) { |
460 |
if(!CC.verifyConnection()) return; |
461 |
|
462 |
if(CC.getInstrumentsDbTreeModel() == null) { |
463 |
String s = i18n.getMessage("A4n.noInstrumentsDbSupport!"); |
464 |
HF.showErrorMessage(s, CC.getMainFrame()); |
465 |
return; |
466 |
} |
467 |
|
468 |
if(instrumentsDbFrame != null && instrumentsDbFrame.isVisible()) { |
469 |
instrumentsDbFrame.setVisible(false); |
470 |
instrumentsDbFrame.setVisible(true); |
471 |
return; |
472 |
} |
473 |
|
474 |
instrumentsDbFrame = new InstrumentsDbFrame(); |
475 |
instrumentsDbFrame.setVisible(true); |
476 |
} |
477 |
} |
478 |
|
479 |
// HELP |
480 |
public final static HelpAbout helpAbout = new HelpAbout(); |
481 |
|
482 |
private static class HelpAbout extends AbstractAction { |
483 |
HelpAbout() { |
484 |
super(i18n.getMenuLabel("help.about", "JS Classic")); |
485 |
} |
486 |
|
487 |
public void |
488 |
actionPerformed(ActionEvent e) { |
489 |
new HelpAboutDlg(CC.getMainFrame()).setVisible(true); |
490 |
} |
491 |
} |
492 |
} |