/[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 1688 - (show annotations) (download)
Thu Feb 14 16:52:36 2008 UTC (16 years, 2 months ago) by iliev
File size: 18524 byte(s)
* Implemented a backend list with option to manually choose a backend
  to connect on startup(Edit/Preferences, then click the `Backend' tab)
  and option to change the backend without restarting JSampler
  (Actions/Change Backend or Ctrl + B)

* Added confirmation messages for removing sampler channels and
  audio/MIDI devices (Edit/Preferences, then click the `View' tab)

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.classic;
24
25 import java.awt.event.ActionEvent;
26
27 import java.beans.PropertyChangeEvent;
28 import java.beans.PropertyChangeListener;
29
30 import java.util.logging.Level;
31
32 import javax.swing.AbstractAction;
33 import javax.swing.Action;
34
35 import net.sf.juife.event.TaskEvent;
36 import net.sf.juife.event.TaskListener;
37
38 import org.jsampler.CC;
39 import org.jsampler.HF;
40 import org.jsampler.JSampler;
41
42 import org.jsampler.view.JSChannel;
43 import org.jsampler.view.JSChannelsPane;
44 import org.jsampler.view.JSMainFrame;
45 import org.jsampler.view.std.JSAddMidiInstrumentMapDlg;
46
47 import org.jsampler.view.std.JSNewMidiDeviceDlg;
48 import org.jsampler.view.std.JSNewAudioDeviceDlg;
49 import org.jsampler.view.std.JSNewMidiInstrumentWizard;
50 import org.jsampler.view.std.StdA4n;
51
52 import static org.jsampler.view.classic.ClassicI18n.i18n;
53
54
55 /**
56 * This class provides an <code>Action</code> instances performing all needed tasks.
57 * @author Grigor Iliev
58 */
59 public class A4n extends StdA4n {
60 protected static A4n a4n = new A4n();
61
62 /** Forbids the instantiation of <code>A4n</code> */
63 private A4n() {
64 refresh.putValue(Action.SMALL_ICON, Res.iconReload32);
65 resetSampler.putValue(Action.SMALL_ICON, Res.iconReset32);
66 exportSamplerConfig.putValue(Action.SMALL_ICON, Res.iconExportSession32);
67 exportMidiInstrumentMaps.putValue(Action.SMALL_ICON, Res.iconExport16);
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 public final static Action duplicateChannels = new DuplicateChannels();
248
249 public final static Action moveChannelsOnTop = new MoveChannelsOnTop();
250 public final static Action moveChannelsUp = new MoveChannelsUp();
251 public final static Action moveChannelsDown = new MoveChannelsDown();
252 public final static Action moveChannelsAtBottom = new MoveChannelsAtBottom();
253
254 public final static Action selectAllChannels = new SelectAllChannels();
255 public final static Action deselectChannels = new DeselectChannels();
256
257 public final static Action removeChannels = new RemoveChannels();
258
259
260 private static class NewChannel extends AbstractAction {
261 NewChannel() {
262 super(i18n.getMenuLabel("channels.new"));
263
264 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannel"));
265 putValue(Action.SMALL_ICON, Res.iconNew24);
266 }
267
268 public void
269 actionPerformed(ActionEvent e) {
270 if(!verifyConnection()) return;
271 CC.getSamplerModel().addBackendChannel();
272 }
273 }
274
275 private static class NewChannelWizard extends AbstractAction {
276 NewChannelWizard() {
277 super(i18n.getMenuLabel("channels.wizard"));
278
279 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannelWizard"));
280 }
281
282 public void
283 actionPerformed(ActionEvent e) {
284 new org.jsampler.view.classic.NewChannelWizard().showWizard();
285 }
286 }
287
288 private static class DuplicateChannels extends AbstractAction {
289 DuplicateChannels() {
290 super(i18n.getMenuLabel("channels.duplicate"));
291
292 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDuplicateChannels"));
293 putValue(Action.SMALL_ICON, Res.iconCopy24);
294
295 setEnabled(false);
296 }
297
298 public void
299 actionPerformed(ActionEvent e) {
300 JSChannel[] channels =
301 CC.getMainFrame().getSelectedChannelsPane().getSelectedChannels();
302
303 if(channels.length > 2) {
304 if(!HF.showYesNoDialog (
305 CC.getMainFrame(),
306 i18n.getMessage("A4n.duplicateChannels?")
307 )) return;
308 }
309
310 CC.getTaskQueue().add (
311 new org.jsampler.task.DuplicateChannels(channels)
312 );
313 }
314 }
315
316 private static class MoveChannelsOnTop extends AbstractAction {
317 MoveChannelsOnTop() {
318 super(i18n.getMenuLabel("channels.MoveOnTop"));
319
320 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsOnTop"));
321 setEnabled(false);
322 }
323
324 public void
325 actionPerformed(ActionEvent e) {
326 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
327 p.moveSelectedChannelsOnTop();
328 }
329 }
330
331 private static class MoveChannelsUp extends AbstractAction {
332 MoveChannelsUp() {
333 super(i18n.getMenuLabel("channels.MoveUp"));
334
335 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsUp"));
336 putValue(Action.SMALL_ICON, Res.iconUp24);
337
338 setEnabled(false);
339 }
340
341 public void
342 actionPerformed(ActionEvent e) {
343 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
344 p.moveSelectedChannelsUp();
345 }
346 }
347
348 private static class MoveChannelsDown extends AbstractAction {
349 MoveChannelsDown() {
350 super(i18n.getMenuLabel("channels.MoveDown"));
351
352 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsDown"));
353 putValue(Action.SMALL_ICON, Res.iconDown24);
354
355 setEnabled(false);
356 }
357
358 public void
359 actionPerformed(ActionEvent e) {
360 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
361 p.moveSelectedChannelsDown();
362 }
363 }
364
365 private static class MoveChannelsAtBottom extends AbstractAction {
366 MoveChannelsAtBottom() {
367 super(i18n.getMenuLabel("channels.MoveAtBottom"));
368
369 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsAtBottom"));
370 setEnabled(false);
371 }
372
373 public void
374 actionPerformed(ActionEvent e) {
375 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
376 p.moveSelectedChannelsAtBottom();
377 }
378 }
379
380 public static class
381 MoveChannelsTo extends AbstractAction implements PropertyChangeListener {
382 private final JSChannelsPane pane;
383
384 MoveChannelsTo(JSChannelsPane pane) {
385 super(pane.getTitle());
386
387 this.pane = pane;
388
389 String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle());
390 putValue(SHORT_DESCRIPTION, desc);
391 pane.addPropertyChangeListener(JSChannelsPane.TITLE, this);
392 }
393
394 public void
395 actionPerformed(ActionEvent e) {
396 JSChannelsPane acp = CC.getMainFrame().getSelectedChannelsPane();
397 JSChannel[] chns = acp.getSelectedChannels();
398
399 for(JSChannel c : chns) acp.removeChannel(c);
400
401 pane.addChannels(chns);
402
403 CC.getMainFrame().setSelectedChannelsPane(pane);
404
405 }
406
407 public void
408 propertyChange(PropertyChangeEvent e) {
409 putValue(NAME, pane.getTitle());
410
411 String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle());
412 putValue(SHORT_DESCRIPTION, desc);
413 }
414
415 public JSChannelsPane
416 getChannelsPane() { return pane; }
417 }
418
419 private static class SelectAllChannels extends AbstractAction {
420 SelectAllChannels() {
421 super(i18n.getMenuLabel("channels.selectAll"));
422
423 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttSelectAllChannels"));
424 }
425
426 public void
427 actionPerformed(ActionEvent e) {
428 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
429 p.selectAllChannels();
430 }
431 }
432
433 private static class DeselectChannels extends AbstractAction {
434 DeselectChannels() {
435 super(i18n.getMenuLabel("channels.selectNone"));
436
437 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDeselectChannels"));
438 }
439
440 public void
441 actionPerformed(ActionEvent e) {
442 ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
443 p.deselectChannels();
444 }
445 }
446
447 private static class RemoveChannels extends AbstractAction {
448 RemoveChannels() {
449 super(i18n.getMenuLabel("channels.RemoveChannel"));
450
451 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRemoveChannels"));
452 putValue(Action.SMALL_ICON, Res.iconDelete24);
453
454 setEnabled(false);
455 }
456
457 public void
458 actionPerformed(ActionEvent e) {
459 JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane();
460 if(p.getSelectedChannelCount() > 1)
461 if(!HF.showYesNoDialog (
462 CC.getMainFrame(), i18n.getMessage("A4n.removeChannels?")
463 )) return;
464
465 JSChannel[] chnS = p.getSelectedChannels();
466
467 for(JSChannel c : chnS) removeChannel(c);
468 }
469
470 private void
471 removeChannel(final JSChannel c) {
472 final JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane();
473 int id = c.getChannelInfo().getChannelId();
474
475 CC.getSamplerModel().removeBackendChannel(id);
476 }
477 }
478
479 // TABS
480 public final static Action newChannelsTab = new NewChannelsTab();
481
482 public final static Action editTabTitle = new EditTabTitle();
483
484 public final static Action moveTab2Beginning = new MoveTab2Beginning();
485 public final static Action moveTab2Left = new MoveTab2Left();
486 public final static Action moveTab2Right = new MoveTab2Right();
487 public final static Action moveTab2End = new MoveTab2End();
488
489 public final static Action closeChannelsTab = new CloseChannelsTab();
490
491
492 private static class NewChannelsTab extends AbstractAction {
493 NewChannelsTab() {
494 super(i18n.getMenuLabel("tabs.new"));
495
496 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewTab"));
497 putValue(Action.SMALL_ICON, Res.iconTabNew22);
498 }
499
500 public void
501 actionPerformed(ActionEvent e) {
502 new NewChannelsTabDlg(CC.getMainFrame()).setVisible(true);
503 }
504 }
505
506 private static class EditTabTitle extends AbstractAction {
507 EditTabTitle() {
508 super(i18n.getMenuLabel("tabs.changeTitle"));
509
510 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttEditTabTitle"));
511 setEnabled(false);
512 }
513
514 public void
515 actionPerformed(ActionEvent e) {
516 new ChangeTabTitleDlg(CC.getMainFrame()).setVisible(true);
517 }
518 }
519
520 private static class MoveTab2Beginning extends AbstractAction {
521 MoveTab2Beginning() {
522 super(i18n.getMenuLabel("tabs.move2Beginning"));
523
524 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Beginning"));
525 setEnabled(false);
526 }
527
528 public void
529 actionPerformed(ActionEvent e) {
530 ((MainFrame)CC.getMainFrame()).moveTab2Beginning();
531 }
532 }
533
534 private static class MoveTab2Left extends AbstractAction {
535 MoveTab2Left() {
536 super(i18n.getMenuLabel("tabs.move2Left"));
537
538 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Left"));
539 putValue(Action.SMALL_ICON, Res.iconTabMoveLeft22);
540 setEnabled(false);
541 }
542
543 public void
544 actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Left(); }
545 }
546
547 private static class MoveTab2Right extends AbstractAction {
548 MoveTab2Right() {
549 super(i18n.getMenuLabel("tabs.move2Right"));
550
551 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Right"));
552 putValue(Action.SMALL_ICON, Res.iconTabMoveRight22);
553 setEnabled(false);
554 }
555
556 public void
557 actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Right(); }
558 }
559
560 private static class MoveTab2End extends AbstractAction {
561 MoveTab2End() {
562 super(i18n.getMenuLabel("tabs.move2End"));
563
564 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2End"));
565 setEnabled(false);
566 }
567
568 public void
569 actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2End(); }
570 }
571
572 private static class CloseChannelsTab extends AbstractAction {
573 CloseChannelsTab() {
574 super(i18n.getMenuLabel("tabs.close"));
575
576 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttCloseTab"));
577 putValue(Action.SMALL_ICON, Res.iconTabRemove22);
578 setEnabled(false);
579 }
580
581 public void
582 actionPerformed(ActionEvent e) {
583 JSMainFrame frm = CC.getMainFrame();
584 JSChannelsPane chnPane = frm.getSelectedChannelsPane();
585 if(chnPane.getChannelCount() > 0) {
586 CloseTabDlg dlg = new CloseTabDlg(frm);
587 dlg.setVisible(true);
588 if(dlg.isCancelled()) return;
589
590 JSChannel[] chns = chnPane.getChannels();
591
592 if(dlg.remove()) {
593
594
595 } else {
596 JSChannelsPane p = dlg.getSelectedChannelsPane();
597 for(JSChannel c : chns) {
598 chnPane.removeChannel(c);
599 }
600 p.addChannels(chns);
601 frm.setSelectedChannelsPane(p);
602 }
603 }
604
605 frm.removeChannelsPane(chnPane);
606 }
607 }
608
609 // WINDOW
610 public final static WindowInstrumentsDb windowInstrumentsDb = new WindowInstrumentsDb();
611
612 private static class WindowInstrumentsDb extends AbstractAction {
613 InstrumentsDbFrame instrumentsDbFrame = null;
614
615 WindowInstrumentsDb() {
616 super(i18n.getMenuLabel("window.instrumentsDb"));
617 putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("window.instrumentsDb.tt"));
618 putValue(Action.SMALL_ICON, Res.iconDb32);
619 }
620
621 public void
622 actionPerformed(ActionEvent e) {
623 if(!CC.verifyConnection()) return;
624
625 if(CC.getInstrumentsDbTreeModel() == null) {
626 String s = i18n.getMessage("A4n.noInstrumentsDbSupport!");
627 HF.showErrorMessage(s, CC.getMainFrame());
628 return;
629 }
630
631 if(instrumentsDbFrame != null && instrumentsDbFrame.isVisible()) {
632 instrumentsDbFrame.setVisible(false);
633 instrumentsDbFrame.setVisible(true);
634 return;
635 }
636
637 instrumentsDbFrame = new InstrumentsDbFrame();
638 instrumentsDbFrame.setVisible(true);
639 }
640 }
641
642 // HELP
643 public final static HelpAbout helpAbout = new HelpAbout();
644
645 private static class HelpAbout extends AbstractAction {
646 HelpAbout() {
647 super(i18n.getMenuLabel("help.about", "JS Classic"));
648 }
649
650 public void
651 actionPerformed(ActionEvent e) {
652 new HelpAboutDlg(CC.getMainFrame()).setVisible(true);
653 }
654 }
655 }

  ViewVC Help
Powered by ViewVC