/[svn]/jsampler/trunk/src/org/jsampler/view/std/StdA4n.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/view/std/StdA4n.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1567 - (hide annotations) (download)
Thu Dec 6 19:37:41 2007 UTC (16 years, 4 months ago) by iliev
File size: 5243 byte(s)
* added confirmation dialog on exit
* some minor gui enhancements
* preparations for release 0.8a

1 iliev 1286 /*
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.std;
24    
25     import java.awt.event.ActionEvent;
26    
27     import java.io.FileOutputStream;
28    
29     import java.util.logging.Level;
30    
31     import javax.swing.AbstractAction;
32     import javax.swing.Action;
33     import javax.swing.JFileChooser;
34    
35     import org.jsampler.CC;
36     import org.jsampler.HF;
37     import org.jsampler.JSPrefs;
38    
39     import org.jsampler.view.LscpFileFilter;
40    
41     import static org.jsampler.view.std.StdI18n.i18n;
42    
43    
44     /**
45     * This class provides an <code>Action</code> instances performing some of the common tasks.
46     * @author Grigor Iliev
47     */
48 iliev 1567 public class StdA4n {
49     protected static StdA4n a4n = new StdA4n();
50    
51 iliev 1286 protected StdA4n() { }
52    
53 iliev 1567 protected JSPrefs preferences() { return CC.getViewConfig().preferences(); }
54 iliev 1286
55     protected void
56     exportSamplerConfig() {
57     String s = preferences().getStringProperty("lastScriptLocation");
58     JFileChooser fc = new JFileChooser(s);
59     fc.setFileFilter(new LscpFileFilter());
60     int result = fc.showSaveDialog(CC.getMainFrame());
61     if(result != JFileChooser.APPROVE_OPTION) return;
62    
63     String path = fc.getCurrentDirectory().getAbsolutePath();
64     preferences().setStringProperty("lastScriptLocation", path);
65    
66     try {
67     FileOutputStream fos = new FileOutputStream(fc.getSelectedFile());
68     fos.write(CC.exportSessionToLscpScript().getBytes("US-ASCII"));
69     fos.close();
70     } catch(Exception x) {
71     CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x);
72     HF.showErrorMessage(x);
73     }
74     }
75    
76     protected void
77     exportMidiInstrumentMaps() {
78     String s = preferences().getStringProperty("lastScriptLocation");
79     JFileChooser fc = new JFileChooser(s);
80     fc.setFileFilter(new LscpFileFilter());
81     int result = fc.showSaveDialog(CC.getMainFrame());
82     if(result != JFileChooser.APPROVE_OPTION) return;
83    
84     String path = fc.getCurrentDirectory().getAbsolutePath();
85     preferences().setStringProperty("lastScriptLocation", path);
86    
87     try {
88     FileOutputStream fos = new FileOutputStream(fc.getSelectedFile());
89     fos.write(CC.exportInstrMapsToLscpScript().getBytes("US-ASCII"));
90     fos.close();
91     } catch(Exception x) {
92     CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x);
93     HF.showErrorMessage(x);
94     };
95     }
96    
97     public final Action connect = new Connect();
98    
99     private class Connect extends AbstractAction {
100     Connect() {
101     super(i18n.getMenuLabel("actions.connect"));
102    
103     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.connect.tt"));
104     }
105    
106     public void
107     actionPerformed(ActionEvent e) { CC.reconnect(); }
108     }
109    
110     public final Action refresh = new Refresh();
111    
112     private class Refresh extends AbstractAction {
113     Refresh() {
114     super(i18n.getMenuLabel("actions.refresh"));
115    
116     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.refresh.tt"));
117     }
118    
119     public void
120     actionPerformed(ActionEvent e) { CC.initSamplerModel(); }
121     }
122    
123     public final Action resetSampler = new Reset();
124    
125     private class Reset extends AbstractAction {
126     Reset() {
127     super(i18n.getMenuLabel("actions.resetSampler"));
128    
129     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.resetSampler.tt"));
130     }
131    
132     public void
133     actionPerformed(ActionEvent e) { CC.getSamplerModel().resetBackend(); }
134     }
135    
136     public final Action exportSamplerConfig = new ExportSamplerConfig();
137    
138     private class ExportSamplerConfig extends AbstractAction {
139     ExportSamplerConfig() {
140     super(i18n.getMenuLabel("actions.export.samplerConfiguration"));
141    
142     String s = i18n.getMenuLabel("actions.export.samplerConfiguration.tt");
143     putValue(SHORT_DESCRIPTION, s);
144    
145     }
146    
147     public void
148     actionPerformed(ActionEvent e) {
149     exportSamplerConfig();
150     }
151     }
152    
153     public final Action exportMidiInstrumentMaps = new ExportMidiInstrumentMaps();
154    
155     private class ExportMidiInstrumentMaps extends AbstractAction {
156     ExportMidiInstrumentMaps() {
157     super(i18n.getMenuLabel("actions.export.MidiInstrumentMaps"));
158    
159     String s = i18n.getMenuLabel("actions.export.MidiInstrumentMaps.tt");
160     putValue(SHORT_DESCRIPTION, s);
161     }
162    
163     public void
164     actionPerformed(ActionEvent e) {
165     exportMidiInstrumentMaps();
166     }
167     }
168 iliev 1496
169     public final Action browseOnlineTutorial = new BrowseOnlineTutorial();
170    
171     private class BrowseOnlineTutorial extends AbstractAction {
172     BrowseOnlineTutorial() {
173     super(i18n.getMenuLabel("help.onlineTutorial"));
174    
175     putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("help.onlineTutorial.tt"));
176     }
177    
178     public void
179     actionPerformed(ActionEvent e) {
180     StdUtils.browse("http://jsampler.sourceforge.net/");
181     }
182     }
183 iliev 1286 }

  ViewVC Help
Powered by ViewVC