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 |
|
|
public abstract class StdA4n { |
49 |
|
|
protected StdA4n() { } |
50 |
|
|
|
51 |
|
|
protected abstract JSPrefs preferences(); |
52 |
|
|
|
53 |
|
|
protected void |
54 |
|
|
exportSamplerConfig() { |
55 |
|
|
String s = preferences().getStringProperty("lastScriptLocation"); |
56 |
|
|
JFileChooser fc = new JFileChooser(s); |
57 |
|
|
fc.setFileFilter(new LscpFileFilter()); |
58 |
|
|
int result = fc.showSaveDialog(CC.getMainFrame()); |
59 |
|
|
if(result != JFileChooser.APPROVE_OPTION) return; |
60 |
|
|
|
61 |
|
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
62 |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
63 |
|
|
|
64 |
|
|
try { |
65 |
|
|
FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); |
66 |
|
|
fos.write(CC.exportSessionToLscpScript().getBytes("US-ASCII")); |
67 |
|
|
fos.close(); |
68 |
|
|
} catch(Exception x) { |
69 |
|
|
CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x); |
70 |
|
|
HF.showErrorMessage(x); |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
protected void |
75 |
|
|
exportMidiInstrumentMaps() { |
76 |
|
|
String s = preferences().getStringProperty("lastScriptLocation"); |
77 |
|
|
JFileChooser fc = new JFileChooser(s); |
78 |
|
|
fc.setFileFilter(new LscpFileFilter()); |
79 |
|
|
int result = fc.showSaveDialog(CC.getMainFrame()); |
80 |
|
|
if(result != JFileChooser.APPROVE_OPTION) return; |
81 |
|
|
|
82 |
|
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
83 |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
84 |
|
|
|
85 |
|
|
try { |
86 |
|
|
FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); |
87 |
|
|
fos.write(CC.exportInstrMapsToLscpScript().getBytes("US-ASCII")); |
88 |
|
|
fos.close(); |
89 |
|
|
} catch(Exception x) { |
90 |
|
|
CC.getLogger().log(Level.FINE, HF.getErrorMessage(x), x); |
91 |
|
|
HF.showErrorMessage(x); |
92 |
|
|
}; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
public final Action connect = new Connect(); |
96 |
|
|
|
97 |
|
|
private class Connect extends AbstractAction { |
98 |
|
|
Connect() { |
99 |
|
|
super(i18n.getMenuLabel("actions.connect")); |
100 |
|
|
|
101 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.connect.tt")); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
public void |
105 |
|
|
actionPerformed(ActionEvent e) { CC.reconnect(); } |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
public final Action refresh = new Refresh(); |
109 |
|
|
|
110 |
|
|
private class Refresh extends AbstractAction { |
111 |
|
|
Refresh() { |
112 |
|
|
super(i18n.getMenuLabel("actions.refresh")); |
113 |
|
|
|
114 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.refresh.tt")); |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
public void |
118 |
|
|
actionPerformed(ActionEvent e) { CC.initSamplerModel(); } |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
public final Action resetSampler = new Reset(); |
122 |
|
|
|
123 |
|
|
private class Reset extends AbstractAction { |
124 |
|
|
Reset() { |
125 |
|
|
super(i18n.getMenuLabel("actions.resetSampler")); |
126 |
|
|
|
127 |
|
|
putValue(SHORT_DESCRIPTION, i18n.getMenuLabel("actions.resetSampler.tt")); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
public void |
131 |
|
|
actionPerformed(ActionEvent e) { CC.getSamplerModel().resetBackend(); } |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
public final Action exportSamplerConfig = new ExportSamplerConfig(); |
135 |
|
|
|
136 |
|
|
private class ExportSamplerConfig extends AbstractAction { |
137 |
|
|
ExportSamplerConfig() { |
138 |
|
|
super(i18n.getMenuLabel("actions.export.samplerConfiguration")); |
139 |
|
|
|
140 |
|
|
String s = i18n.getMenuLabel("actions.export.samplerConfiguration.tt"); |
141 |
|
|
putValue(SHORT_DESCRIPTION, s); |
142 |
|
|
|
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
public void |
146 |
|
|
actionPerformed(ActionEvent e) { |
147 |
|
|
exportSamplerConfig(); |
148 |
|
|
} |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
public final Action exportMidiInstrumentMaps = new ExportMidiInstrumentMaps(); |
152 |
|
|
|
153 |
|
|
private class ExportMidiInstrumentMaps extends AbstractAction { |
154 |
|
|
ExportMidiInstrumentMaps() { |
155 |
|
|
super(i18n.getMenuLabel("actions.export.MidiInstrumentMaps")); |
156 |
|
|
|
157 |
|
|
String s = i18n.getMenuLabel("actions.export.MidiInstrumentMaps.tt"); |
158 |
|
|
putValue(SHORT_DESCRIPTION, s); |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
public void |
162 |
|
|
actionPerformed(ActionEvent e) { |
163 |
|
|
exportMidiInstrumentMaps(); |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
} |