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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 787 - (hide annotations) (download)
Mon Oct 10 16:03:12 2005 UTC (18 years, 7 months ago) by iliev
File size: 18545 byte(s)
* The first alpha-release of JSampler

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005 Grigor Kirilov Iliev
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.MediaTracker;
26    
27     import java.awt.event.ActionEvent;
28    
29     import java.beans.PropertyChangeEvent;
30     import java.beans.PropertyChangeListener;
31    
32     import java.net.URL;
33    
34     import java.util.logging.Level;
35    
36     import javax.swing.AbstractAction;
37     import javax.swing.Action;
38     import javax.swing.ImageIcon;
39     import javax.swing.JOptionPane;
40    
41     import org.jsampler.CC;
42     import org.jsampler.HF;
43     import org.jsampler.JSampler;
44    
45     import org.jsampler.view.JSChannel;
46     import org.jsampler.view.JSChannelsPane;
47     import org.jsampler.view.JSMainFrame;
48    
49     import net.sf.juife.event.TaskEvent;
50     import net.sf.juife.event.TaskListener;
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 {
60     public final static Action connect = new Connect();
61    
62     private static class Connect extends AbstractAction {
63     Connect() {
64     super(i18n.getMenuLabel("actions.connect"));
65    
66     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttConnect"));
67     }
68    
69     public void
70     actionPerformed(ActionEvent e) {
71     CC.initSamplerModel();
72     }
73     }
74    
75     public final static Action samplerInfo = new SamplerInfo();
76    
77     private static class SamplerInfo extends AbstractAction {
78     SamplerInfo() {
79     super(i18n.getMenuLabel("actions.samplerInfo"));
80    
81     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttSamplerInfo"));
82    
83     try {
84     URL url = ClassLoader.getSystemClassLoader().getResource (
85     "org/jsampler/view/classic/res/icons/toolbar/About24.gif"
86     );
87    
88     ImageIcon icon = new ImageIcon(url);
89     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
90     putValue(Action.SMALL_ICON, icon);
91     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
92     }
93    
94     public void
95     actionPerformed(ActionEvent e) {
96     new SamplerInfoDlg(CC.getMainFrame()).setVisible(true);
97     }
98     }
99    
100     public final static Action refresh = new Refresh();
101    
102     private static class Refresh extends AbstractAction {
103     Refresh() {
104     super(i18n.getMenuLabel("actions.refresh"));
105    
106     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRefresh"));
107    
108     try {
109     URL url = ClassLoader.getSystemClassLoader().getResource (
110     "org/jsampler/view/classic/res/icons/toolbar/Refresh24.gif"
111     );
112    
113     ImageIcon icon = new ImageIcon(url);
114     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
115     putValue(Action.SMALL_ICON, icon);
116     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
117     }
118    
119     public void
120     actionPerformed(ActionEvent e) { CC.initSamplerModel(); }
121     }
122    
123     public final static Action resetSampler = new Reset();
124    
125     private static class Reset extends AbstractAction {
126     Reset() {
127     super(i18n.getMenuLabel("actions.resetSampler"));
128    
129     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttResetSampler"));
130     }
131    
132     public void
133     actionPerformed(ActionEvent e) {
134     CC.getTaskQueue().add(new org.jsampler.task.ResetSampler());
135     }
136     }
137    
138     public final static Action addMidiDevice = new AddMidiDevice();
139    
140     private static class AddMidiDevice extends AbstractAction {
141     AddMidiDevice() {
142     super("");
143    
144     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAddMidiDevice"));
145    
146     try {
147     URL url = ClassLoader.getSystemClassLoader().getResource (
148     "org/jsampler/view/classic/res/icons/New16.gif"
149     );
150    
151     ImageIcon icon = new ImageIcon(url);
152     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
153     putValue(Action.SMALL_ICON, icon);
154     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
155     }
156    
157     public void
158     actionPerformed(ActionEvent e) {
159     new NewMidiDeviceDlg(CC.getMainFrame()).setVisible(true);
160     }
161     }
162    
163     public final static Action addAudioDevice = new AddAudioDevice();
164    
165     private static class AddAudioDevice extends AbstractAction {
166     AddAudioDevice() {
167     super("");
168    
169     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttAddAudioDevice"));
170    
171     try {
172     URL url = ClassLoader.getSystemClassLoader().getResource (
173     "org/jsampler/view/classic/res/icons/New16.gif"
174     );
175    
176     ImageIcon icon = new ImageIcon(url);
177     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
178     putValue(Action.SMALL_ICON, icon);
179     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
180     }
181    
182     public void
183     actionPerformed(ActionEvent e) {
184     new NewAudioDeviceDlg(CC.getMainFrame()).setVisible(true);
185     }
186     }
187    
188     // EDIT
189     public final static Action preferences = new Preferences();
190    
191     private static class Preferences extends AbstractAction {
192     Preferences() {
193     super(i18n.getMenuLabel("edit.preferences"));
194    
195     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttPrefs"));
196    
197     try {
198     URL url = ClassLoader.getSystemClassLoader().getResource (
199     "org/jsampler/view/classic/res/icons/toolbar/Preferences24.gif"
200     );
201    
202     ImageIcon icon = new ImageIcon(url);
203     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
204     putValue(Action.SMALL_ICON, icon);
205     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
206     }
207    
208     public void
209     actionPerformed(ActionEvent e) { new PrefsDlg(CC.getMainFrame()).setVisible(true); }
210     }
211    
212     // CHANNELS
213     public final static Action newChannel = new NewChannel();
214     public final static Action newChannelWizard = new NewChannelWizard();
215     public final static Action duplicateChannels = new DuplicateChannels();
216    
217     public final static Action moveChannelsOnTop = new MoveChannelsOnTop();
218     public final static Action moveChannelsUp = new MoveChannelsUp();
219     public final static Action moveChannelsDown = new MoveChannelsDown();
220     public final static Action moveChannelsAtBottom = new MoveChannelsAtBottom();
221    
222     public final static Action selectAllChannels = new SelectAllChannels();
223     public final static Action deselectChannels = new DeselectChannels();
224    
225     public final static Action removeChannels = new RemoveChannels();
226    
227    
228     private static class NewChannel extends AbstractAction {
229     NewChannel() {
230     super(i18n.getMenuLabel("channels.new"));
231    
232     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannel"));
233    
234     try {
235     URL url = ClassLoader.getSystemClassLoader().getResource (
236     "org/jsampler/view/classic/res/icons/toolbar/New24.gif"
237     );
238    
239     ImageIcon icon = new ImageIcon(url);
240     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
241     putValue(Action.SMALL_ICON, icon);
242     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
243     }
244    
245     public void
246     actionPerformed(ActionEvent e) { CC.getSamplerModel().createChannel(); }
247     }
248    
249     private static class NewChannelWizard extends AbstractAction {
250     NewChannelWizard() {
251     super(i18n.getMenuLabel("channels.wizard"));
252    
253     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewChannelWizard"));
254     }
255    
256     public void
257     actionPerformed(ActionEvent e) {
258     JOptionPane.showMessageDialog (
259     CC.getMainFrame(), "Not implemented yet",
260     "",
261     JOptionPane.INFORMATION_MESSAGE
262     );
263     //new org.jsampler.view.classic.NewChannelWizard().showWizard();
264     }
265     }
266    
267     private static class DuplicateChannels extends AbstractAction {
268     DuplicateChannels() {
269     super(i18n.getMenuLabel("channels.duplicate"));
270    
271     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDuplicateChannels"));
272    
273     try {
274     URL url = ClassLoader.getSystemClassLoader().getResource (
275     "org/jsampler/view/classic/res/icons/toolbar/Copy24.gif"
276     );
277    
278     ImageIcon icon = new ImageIcon(url);
279     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
280     putValue(Action.SMALL_ICON, icon);
281     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
282    
283     setEnabled(false);
284     }
285    
286     public void
287     actionPerformed(ActionEvent e) {
288     JSChannel[] channels =
289     CC.getMainFrame().getSelectedChannelsPane().getSelectedChannels();
290    
291     if(channels.length > 2) {
292     if(!HF.showYesNoDialog (
293     CC.getMainFrame(),
294     i18n.getMessage("A4n.duplicateChannels?")
295     )) return;
296     }
297    
298     CC.getTaskQueue().add (
299     new org.jsampler.task.DuplicateChannels(channels)
300     );
301     }
302     }
303    
304     private static class MoveChannelsOnTop extends AbstractAction {
305     MoveChannelsOnTop() {
306     super(i18n.getMenuLabel("channels.MoveOnTop"));
307    
308     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsOnTop"));
309     setEnabled(false);
310     }
311    
312     public void
313     actionPerformed(ActionEvent e) {
314     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
315     p.moveSelectedChannelsOnTop();
316     }
317     }
318    
319     private static class MoveChannelsUp extends AbstractAction {
320     MoveChannelsUp() {
321     super(i18n.getMenuLabel("channels.MoveUp"));
322    
323     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsUp"));
324    
325     try {
326     URL url = ClassLoader.getSystemClassLoader().getResource (
327     "org/jsampler/view/classic/res/icons/toolbar/Up24.gif"
328     );
329    
330     ImageIcon icon = new ImageIcon(url);
331     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
332     putValue(Action.SMALL_ICON, icon);
333     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
334    
335     setEnabled(false);
336     }
337    
338     public void
339     actionPerformed(ActionEvent e) {
340     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
341     p.moveSelectedChannelsUp();
342     }
343     }
344    
345     private static class MoveChannelsDown extends AbstractAction {
346     MoveChannelsDown() {
347     super(i18n.getMenuLabel("channels.MoveDown"));
348    
349     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsDown"));
350    
351     try {
352     URL url = ClassLoader.getSystemClassLoader().getResource (
353     "org/jsampler/view/classic/res/icons/toolbar/Down24.gif"
354     );
355    
356     ImageIcon icon = new ImageIcon(url);
357     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
358     putValue(Action.SMALL_ICON, icon);
359     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
360    
361     setEnabled(false);
362     }
363    
364     public void
365     actionPerformed(ActionEvent e) {
366     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
367     p.moveSelectedChannelsDown();
368     }
369     }
370    
371     private static class MoveChannelsAtBottom extends AbstractAction {
372     MoveChannelsAtBottom() {
373     super(i18n.getMenuLabel("channels.MoveAtBottom"));
374    
375     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveChannelsAtBottom"));
376     setEnabled(false);
377     }
378    
379     public void
380     actionPerformed(ActionEvent e) {
381     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
382     p.moveSelectedChannelsAtBottom();
383     }
384     }
385    
386     public static class
387     MoveChannelsTo extends AbstractAction implements PropertyChangeListener {
388     private final JSChannelsPane pane;
389    
390     MoveChannelsTo(JSChannelsPane pane) {
391     super(pane.getTitle());
392    
393     this.pane = pane;
394    
395     String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle());
396     putValue(SHORT_DESCRIPTION, desc);
397     pane.addPropertyChangeListener(JSChannelsPane.TITLE, this);
398     }
399    
400     public void
401     actionPerformed(ActionEvent e) {
402     JSChannelsPane acp = CC.getMainFrame().getSelectedChannelsPane();
403     JSChannel[] chns = acp.getSelectedChannels();
404    
405     for(JSChannel c : chns) acp.removeChannel(c);
406    
407     pane.addChannels(chns);
408    
409     CC.getMainFrame().setSelectedChannelsPane(pane);
410    
411     }
412    
413     public void
414     propertyChange(PropertyChangeEvent e) {
415     putValue(NAME, pane.getTitle());
416    
417     String desc = i18n.getMenuLabel("ttMoveChannelsTo", pane.getTitle());
418     putValue(SHORT_DESCRIPTION, desc);
419     }
420    
421     public JSChannelsPane
422     getChannelsPane() { return pane; }
423     }
424    
425     private static class SelectAllChannels extends AbstractAction {
426     SelectAllChannels() {
427     super(i18n.getMenuLabel("channels.selectAll"));
428    
429     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttSelectAllChannels"));
430     }
431    
432     public void
433     actionPerformed(ActionEvent e) {
434     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
435     p.selectAllChannels();
436     }
437     }
438    
439     private static class DeselectChannels extends AbstractAction {
440     DeselectChannels() {
441     super(i18n.getMenuLabel("channels.selectNone"));
442    
443     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttDeselectChannels"));
444     }
445    
446     public void
447     actionPerformed(ActionEvent e) {
448     ChannelsPane p = (ChannelsPane)CC.getMainFrame().getSelectedChannelsPane();
449     p.deselectChannels();
450     }
451     }
452    
453     private static class RemoveChannels extends AbstractAction {
454     RemoveChannels() {
455     super(i18n.getMenuLabel("channels.RemoveChannel"));
456    
457     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttRemoveChannels"));
458    
459     try {
460     URL url = ClassLoader.getSystemClassLoader().getResource (
461     "org/jsampler/view/classic/res/icons/toolbar/Delete24.gif"
462     );
463    
464     ImageIcon icon = new ImageIcon(url);
465     if(icon.getImageLoadStatus() == MediaTracker.COMPLETE)
466     putValue(Action.SMALL_ICON, icon);
467     } catch(Exception x) { CC.getLogger().log(Level.INFO, x.getMessage(), x); }
468    
469     setEnabled(false);
470     }
471    
472     public void
473     actionPerformed(ActionEvent e) {
474     JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane();
475     if(p.getSelectedChannelCount() > 1)
476     if(!HF.showYesNoDialog (
477     CC.getMainFrame(), i18n.getMessage("A4n.removeChannels?")
478     )) return;
479    
480     JSChannel[] chnS = p.getSelectedChannels();
481    
482     for(JSChannel c : chnS) removeChannel(c);
483     }
484    
485     private void
486     removeChannel(final JSChannel c) {
487     final JSChannelsPane p = CC.getMainFrame().getSelectedChannelsPane();
488     int id = c.getChannelInfo().getChannelID();
489     final org.jsampler.task.RemoveChannel rc =
490     new org.jsampler.task.RemoveChannel(id);
491    
492     rc.addTaskListener(new TaskListener() {
493     public void
494     taskPerformed(TaskEvent e) {
495     if(rc.doneWithErrors()) return;
496    
497     p.removeChannel(c);
498     }
499     });
500    
501     CC.getTaskQueue().add(rc);
502     }
503     }
504    
505     // TABS
506     public final static Action newChannelsTab = new NewChannelsTab();
507    
508     public final static Action editTabTitle = new EditTabTitle();
509    
510     public final static Action moveTab2Beginning = new MoveTab2Beginning();
511     public final static Action moveTab2Left = new MoveTab2Left();
512     public final static Action moveTab2Right = new MoveTab2Right();
513     public final static Action moveTab2End = new MoveTab2End();
514    
515     public final static Action closeChannelsTab = new CloseChannelsTab();
516    
517    
518     private static class NewChannelsTab extends AbstractAction {
519     NewChannelsTab() {
520     super(i18n.getMenuLabel("tabs.new"));
521    
522     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttNewTab"));
523    
524     /*try {
525     URL u = new URL(PATH + "general/Preferences24.gif");
526     ImageIcon ii = new ImageIcon(u);
527     if(ii.getImageLoadStatus() == MediaTracker.COMPLETE)
528     putValue(Action.SMALL_ICON, ii);
529     } catch(Exception x) {
530     CC.getLogger().log(Level.INFO, x.getMessage(), x);
531     }*/
532     }
533    
534     public void
535     actionPerformed(ActionEvent e) {
536     new NewChannelsTabDlg(CC.getMainFrame()).setVisible(true);
537     }
538     }
539    
540     private static class EditTabTitle extends AbstractAction {
541     EditTabTitle() {
542     super(i18n.getMenuLabel("tabs.changeTitle"));
543    
544     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttEditTabTitle"));
545     setEnabled(false);
546     }
547    
548     public void
549     actionPerformed(ActionEvent e) {
550     new ChangeTabTitleDlg(CC.getMainFrame()).setVisible(true);
551     }
552     }
553    
554     private static class MoveTab2Beginning extends AbstractAction {
555     MoveTab2Beginning() {
556     super(i18n.getMenuLabel("tabs.move2Beginning"));
557    
558     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Beginning"));
559     setEnabled(false);
560     }
561    
562     public void
563     actionPerformed(ActionEvent e) {
564     ((MainFrame)CC.getMainFrame()).moveTab2Beginning();
565     }
566     }
567    
568     private static class MoveTab2Left extends AbstractAction {
569     MoveTab2Left() {
570     super(i18n.getMenuLabel("tabs.move2Left"));
571    
572     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Left"));
573     setEnabled(false);
574     }
575    
576     public void
577     actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Left(); }
578     }
579    
580     private static class MoveTab2Right extends AbstractAction {
581     MoveTab2Right() {
582     super(i18n.getMenuLabel("tabs.move2Right"));
583    
584     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2Right"));
585     setEnabled(false);
586     }
587    
588     public void
589     actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2Right(); }
590     }
591    
592     private static class MoveTab2End extends AbstractAction {
593     MoveTab2End() {
594     super(i18n.getMenuLabel("tabs.move2End"));
595    
596     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttMoveTab2End"));
597     setEnabled(false);
598     }
599    
600     public void
601     actionPerformed(ActionEvent e) { ((MainFrame)CC.getMainFrame()).moveTab2End(); }
602     }
603    
604     private static class CloseChannelsTab extends AbstractAction {
605     CloseChannelsTab() {
606     super(i18n.getMenuLabel("tabs.close"));
607    
608     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("ttCloseTab"));
609    
610     setEnabled(false);
611     }
612    
613     public void
614     actionPerformed(ActionEvent e) {
615     JSMainFrame frm = CC.getMainFrame();
616     JSChannelsPane chnPane = frm.getSelectedChannelsPane();
617     if(chnPane.getChannelCount() > 0) {
618     CloseTabDlg dlg = new CloseTabDlg(frm);
619     dlg.setVisible(true);
620     if(dlg.isCancelled()) return;
621    
622     JSChannel[] chns = chnPane.getChannels();
623    
624     if(dlg.remove()) {
625    
626    
627     } else {
628     JSChannelsPane p = dlg.getSelectedChannelsPane();
629     for(JSChannel c : chns) {
630     chnPane.removeChannel(c);
631     }
632     p.addChannels(chns);
633     frm.setSelectedChannelsPane(p);
634     }
635     }
636    
637     frm.removeChannelsPane(chnPane);
638     }
639     }
640    
641     // HELP
642     public final static HelpAbout helpAbout = new HelpAbout();
643    
644     private static class HelpAbout extends AbstractAction {
645     HelpAbout() {
646     super(i18n.getMenuLabel("help.about", "JS Classic"));
647     }
648    
649     public void
650     actionPerformed(ActionEvent e) {
651     new HelpAboutDlg(CC.getMainFrame()).setVisible(true);
652     }
653     }
654     }

  ViewVC Help
Powered by ViewVC