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.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 |
public class StdA4n { |
49 |
protected static StdA4n a4n = new StdA4n(); |
50 |
|
51 |
protected StdA4n() { } |
52 |
|
53 |
protected JSPrefs preferences() { return CC.getViewConfig().preferences(); } |
54 |
|
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) { |
121 |
if(!CC.verifyConnection()) { |
122 |
CC.changeBackend(); |
123 |
return; |
124 |
} |
125 |
CC.reconnect(); |
126 |
} |
127 |
} |
128 |
|
129 |
public final Action resetSampler = new Reset(); |
130 |
|
131 |
private class Reset extends AbstractAction { |
132 |
Reset() { |
133 |
super(i18n.getMenuLabel("actions.resetSampler")); |
134 |
|
135 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.resetSampler.tt")); |
136 |
} |
137 |
|
138 |
public void |
139 |
actionPerformed(ActionEvent e) { |
140 |
if(!CC.verifyConnection()) return; |
141 |
|
142 |
String s = i18n.getMessage("StdA4n.resetSampler?"); |
143 |
if(!HF.showYesNoDialog(CC.getMainFrame(), s)) return; |
144 |
CC.getSamplerModel().resetBackend(); |
145 |
} |
146 |
} |
147 |
|
148 |
public final Action exportSamplerConfig = new ExportSamplerConfig(); |
149 |
|
150 |
private class ExportSamplerConfig extends AbstractAction { |
151 |
ExportSamplerConfig() { |
152 |
super(i18n.getMenuLabel("actions.export.samplerConfiguration")); |
153 |
|
154 |
String s = i18n.getMenuLabel("actions.export.samplerConfiguration.tt"); |
155 |
putValue(SHORT_DESCRIPTION, s); |
156 |
|
157 |
} |
158 |
|
159 |
public void |
160 |
actionPerformed(ActionEvent e) { |
161 |
if(!CC.verifyConnection()) return; |
162 |
exportSamplerConfig(); |
163 |
} |
164 |
} |
165 |
|
166 |
public final Action exportMidiInstrumentMaps = new ExportMidiInstrumentMaps(); |
167 |
|
168 |
private class ExportMidiInstrumentMaps extends AbstractAction { |
169 |
ExportMidiInstrumentMaps() { |
170 |
super(i18n.getMenuLabel("actions.export.MidiInstrumentMaps")); |
171 |
|
172 |
String s = i18n.getMenuLabel("actions.export.MidiInstrumentMaps.tt"); |
173 |
putValue(SHORT_DESCRIPTION, s); |
174 |
} |
175 |
|
176 |
public void |
177 |
actionPerformed(ActionEvent e) { |
178 |
if(!CC.verifyConnection()) return; |
179 |
exportMidiInstrumentMaps(); |
180 |
} |
181 |
} |
182 |
|
183 |
public final Action changeBackend = new ChangeBackend(); |
184 |
|
185 |
private class ChangeBackend extends AbstractAction { |
186 |
ChangeBackend() { |
187 |
super(i18n.getMenuLabel("actions.changeBackend")); |
188 |
|
189 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.changeBackend.tt")); |
190 |
} |
191 |
|
192 |
public void |
193 |
actionPerformed(ActionEvent e) { CC.changeBackend(); } |
194 |
} |
195 |
|
196 |
public final Action browseOnlineTutorial = new BrowseOnlineTutorial(); |
197 |
|
198 |
private class BrowseOnlineTutorial extends AbstractAction { |
199 |
BrowseOnlineTutorial() { |
200 |
super(i18n.getMenuLabel("help.onlineTutorial")); |
201 |
|
202 |
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("help.onlineTutorial.tt")); |
203 |
} |
204 |
|
205 |
public void |
206 |
actionPerformed(ActionEvent e) { |
207 |
StdUtils.browse("http://jsampler.sourceforge.net/"); |
208 |
} |
209 |
} |
210 |
} |