/[svn]/jsampler/trunk/src/org/jsampler/view/classic/A4n.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/classic/A4n.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 5 months ago) by iliev
File size: 14153 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC