1 |
iliev |
912 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1729 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
912 |
* |
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.fantasia; |
24 |
|
|
|
25 |
|
|
import java.awt.BorderLayout; |
26 |
iliev |
1204 |
import java.awt.Dialog; |
27 |
iliev |
912 |
import java.awt.Dimension; |
28 |
iliev |
1204 |
import java.awt.Frame; |
29 |
iliev |
1285 |
import java.awt.Graphics; |
30 |
|
|
import java.awt.GridBagConstraints; |
31 |
|
|
import java.awt.GridBagLayout; |
32 |
|
|
import java.awt.Insets; |
33 |
iliev |
912 |
|
34 |
|
|
import java.awt.event.ActionEvent; |
35 |
|
|
import java.awt.event.ActionListener; |
36 |
iliev |
1285 |
import java.awt.event.KeyEvent; |
37 |
iliev |
912 |
|
38 |
iliev |
1285 |
import java.io.BufferedReader; |
39 |
|
|
import java.io.File; |
40 |
|
|
import java.io.FileNotFoundException; |
41 |
|
|
import java.io.FileReader; |
42 |
|
|
|
43 |
|
|
import java.util.Vector; |
44 |
iliev |
912 |
import java.util.logging.Level; |
45 |
|
|
|
46 |
iliev |
1285 |
import javax.swing.BorderFactory; |
47 |
iliev |
912 |
import javax.swing.JCheckBoxMenuItem; |
48 |
iliev |
1285 |
import javax.swing.JFileChooser; |
49 |
iliev |
912 |
import javax.swing.JMenu; |
50 |
iliev |
1285 |
import javax.swing.JMenuBar; |
51 |
iliev |
912 |
import javax.swing.JMenuItem; |
52 |
|
|
import javax.swing.JPanel; |
53 |
iliev |
1285 |
import javax.swing.JSplitPane; |
54 |
|
|
import javax.swing.KeyStroke; |
55 |
|
|
import javax.swing.SwingUtilities; |
56 |
iliev |
1734 |
import javax.swing.Timer; |
57 |
iliev |
912 |
|
58 |
|
|
import org.jsampler.CC; |
59 |
|
|
import org.jsampler.HF; |
60 |
iliev |
1285 |
import org.jsampler.LSConsoleModel; |
61 |
iliev |
1688 |
import org.jsampler.Server; |
62 |
iliev |
912 |
|
63 |
|
|
import org.jsampler.view.JSChannelsPane; |
64 |
|
|
import org.jsampler.view.JSMainFrame; |
65 |
iliev |
1285 |
import org.jsampler.view.LscpFileFilter; |
66 |
iliev |
912 |
|
67 |
iliev |
1688 |
import org.jsampler.view.std.JSConnectDlg; |
68 |
iliev |
1355 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
69 |
iliev |
1567 |
import org.jsampler.view.std.JSQuitDlg; |
70 |
iliev |
1285 |
import org.jsampler.view.std.JSamplerHomeChooser; |
71 |
|
|
|
72 |
|
|
import static org.jsampler.view.fantasia.A4n.a4n; |
73 |
iliev |
912 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
74 |
iliev |
1285 |
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
75 |
|
|
import static org.jsampler.view.std.StdPrefs.*; |
76 |
iliev |
912 |
|
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* |
80 |
|
|
* @author Grigor Iliev |
81 |
|
|
*/ |
82 |
|
|
public class MainFrame extends JSMainFrame { |
83 |
iliev |
1323 |
private final StandardBar standardBar = new StandardBar(); |
84 |
iliev |
1285 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
85 |
iliev |
1323 |
private final JPanel rootPane = new JPanel(); |
86 |
iliev |
1285 |
private final MainPane mainPane = new MainPane(); |
87 |
iliev |
1776 |
private final PianoKeyboardPane pianoKeyboardPane; |
88 |
iliev |
912 |
|
89 |
iliev |
1285 |
private final JMenu recentScriptsMenu = |
90 |
|
|
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
91 |
iliev |
912 |
|
92 |
iliev |
1285 |
private final JSplitPane hSplitPane; |
93 |
iliev |
1776 |
private final JSplitPane pianoRollSplitPane; |
94 |
iliev |
1285 |
|
95 |
iliev |
1729 |
private final LeftSidePane leftSidePane = new LeftSidePane(); |
96 |
|
|
private final RightSidePane rightSidePane = new RightSidePane(); |
97 |
iliev |
1323 |
private final JPanel rightPane; |
98 |
iliev |
1285 |
|
99 |
iliev |
1767 |
//private final StatusBar statusBar = new StatusBar(); |
100 |
|
|
|
101 |
iliev |
1311 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
102 |
iliev |
1285 |
private final Vector<String> recentScripts = new Vector<String>(); |
103 |
|
|
|
104 |
|
|
|
105 |
iliev |
1323 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
106 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
107 |
|
|
|
108 |
iliev |
1729 |
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
109 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
110 |
iliev |
1323 |
|
111 |
iliev |
1729 |
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
112 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
113 |
iliev |
1323 |
|
114 |
iliev |
1776 |
private final JCheckBoxMenuItem cbmiMidiKeyboardVisible = |
115 |
|
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard")); |
116 |
|
|
|
117 |
iliev |
1734 |
private final Timer guiTimer = new Timer(1000, null); |
118 |
|
|
|
119 |
iliev |
912 |
/** Creates a new instance of <code>MainFrame</code> */ |
120 |
|
|
public |
121 |
|
|
MainFrame() { |
122 |
|
|
setTitle(i18n.getLabel("MainFrame.title")); |
123 |
|
|
|
124 |
iliev |
1285 |
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
125 |
iliev |
912 |
|
126 |
iliev |
1285 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
127 |
iliev |
1767 |
//getContentPane().add(statusBar, BorderLayout.SOUTH); |
128 |
iliev |
912 |
|
129 |
iliev |
1323 |
rightPane = createRightPane(); |
130 |
iliev |
912 |
|
131 |
iliev |
1285 |
hSplitPane = new JSplitPane ( |
132 |
|
|
JSplitPane.HORIZONTAL_SPLIT, |
133 |
|
|
true, // continuousLayout |
134 |
iliev |
1729 |
leftSidePane, rightPane |
135 |
iliev |
1285 |
); |
136 |
iliev |
1323 |
hSplitPane.setResizeWeight(0.5); |
137 |
iliev |
912 |
|
138 |
iliev |
1776 |
addChannelsPane(mainPane.getChannelsPane()); |
139 |
|
|
|
140 |
|
|
pianoKeyboardPane = new PianoKeyboardPane(); |
141 |
|
|
getChannelsPane(0).addListSelectionListener(pianoKeyboardPane); |
142 |
|
|
|
143 |
|
|
pianoRollSplitPane = new JSplitPane ( |
144 |
|
|
JSplitPane.VERTICAL_SPLIT, |
145 |
|
|
true, // continuousLayout |
146 |
|
|
rootPane, pianoKeyboardPane |
147 |
|
|
); |
148 |
|
|
|
149 |
|
|
pianoRollSplitPane.setResizeWeight(0.5); |
150 |
|
|
|
151 |
iliev |
1323 |
rootPane.setLayout(new BorderLayout()); |
152 |
|
|
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
153 |
|
|
rootPane.setOpaque(false); |
154 |
|
|
rootPane.add(hSplitPane); |
155 |
iliev |
912 |
|
156 |
iliev |
1323 |
addMenu(); |
157 |
|
|
|
158 |
iliev |
1776 |
getContentPane().add(pianoRollSplitPane); |
159 |
iliev |
1323 |
|
160 |
iliev |
1285 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
161 |
|
|
hSplitPane.setDividerLocation(i); |
162 |
iliev |
912 |
|
163 |
iliev |
1285 |
setSavedSize(); |
164 |
iliev |
1734 |
|
165 |
|
|
guiTimer.start(); |
166 |
iliev |
1285 |
} |
167 |
|
|
|
168 |
|
|
private JPanel |
169 |
|
|
createRightPane() { |
170 |
|
|
JPanel p = new JPanel(); |
171 |
|
|
GridBagLayout gridbag = new GridBagLayout(); |
172 |
|
|
GridBagConstraints c = new GridBagConstraints(); |
173 |
iliev |
912 |
|
174 |
iliev |
1285 |
p.setLayout(gridbag); |
175 |
iliev |
912 |
|
176 |
iliev |
1285 |
c.fill = GridBagConstraints.BOTH; |
177 |
iliev |
912 |
|
178 |
iliev |
1285 |
c.gridx = 1; |
179 |
|
|
c.gridy = 0; |
180 |
|
|
c.weightx = 1.0; |
181 |
|
|
c.weighty = 1.0; |
182 |
iliev |
1729 |
c.insets = new Insets(0, 3, 0, 0); |
183 |
|
|
gridbag.setConstraints(rightSidePane, c); |
184 |
|
|
p.add(rightSidePane); |
185 |
iliev |
912 |
|
186 |
iliev |
1285 |
c.gridx = 0; |
187 |
|
|
c.gridy = 0; |
188 |
|
|
c.weightx = 0.0; |
189 |
|
|
c.weighty = 1.0; |
190 |
iliev |
1729 |
c.insets = new Insets(0, 3, 0, 3); |
191 |
iliev |
1285 |
c.fill = GridBagConstraints.VERTICAL; |
192 |
|
|
gridbag.setConstraints(mainPane, c); |
193 |
|
|
p.add(mainPane); |
194 |
iliev |
912 |
|
195 |
iliev |
1285 |
return p; |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
private void |
199 |
|
|
setSavedSize() { |
200 |
|
|
String s = preferences().getStringProperty("MainFrame.sizeAndLocation"); |
201 |
|
|
if(s == null) { |
202 |
|
|
setDefaultSizeAndLocation(); |
203 |
|
|
return; |
204 |
|
|
} |
205 |
iliev |
912 |
pack(); |
206 |
|
|
try { |
207 |
iliev |
1285 |
int i = s.indexOf(','); |
208 |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
209 |
iliev |
912 |
|
210 |
iliev |
1285 |
s = s.substring(i + 1); |
211 |
|
|
i = s.indexOf(','); |
212 |
|
|
int y = Integer.parseInt(s.substring(0, i)); |
213 |
iliev |
912 |
|
214 |
iliev |
1285 |
s = s.substring(i + 1); |
215 |
|
|
i = s.indexOf(','); |
216 |
|
|
int width = Integer.parseInt(s.substring(0, i)); |
217 |
|
|
|
218 |
|
|
s = s.substring(i + 1); |
219 |
|
|
int height = Integer.parseInt(s); |
220 |
|
|
|
221 |
|
|
setBounds(x, y, width, height); |
222 |
iliev |
912 |
} catch(Exception x) { |
223 |
|
|
String msg = "Parsing of window size and location string failed"; |
224 |
|
|
CC.getLogger().log(Level.INFO, msg, x); |
225 |
iliev |
1285 |
setDefaultSizeAndLocation(); |
226 |
iliev |
912 |
} |
227 |
iliev |
1285 |
|
228 |
|
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
229 |
|
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
230 |
|
|
} |
231 |
iliev |
912 |
} |
232 |
|
|
|
233 |
|
|
private void |
234 |
iliev |
1285 |
setDefaultSizeAndLocation() { |
235 |
|
|
setPreferredSize(new Dimension(900, 600)); |
236 |
|
|
pack(); |
237 |
|
|
setLocationRelativeTo(null); |
238 |
iliev |
912 |
} |
239 |
|
|
|
240 |
|
|
|
241 |
|
|
/** Invoked when this window is about to close. */ |
242 |
|
|
protected void |
243 |
|
|
onWindowClose() { |
244 |
iliev |
1688 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
245 |
|
|
if(b && CC.getSamplerModel().isModified()) { |
246 |
iliev |
1567 |
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
247 |
|
|
dlg.setVisible(true); |
248 |
|
|
if(dlg.isCancelled()) return; |
249 |
|
|
} |
250 |
|
|
|
251 |
iliev |
1729 |
leftSidePane.savePreferences(); |
252 |
|
|
rightSidePane.savePreferences(); |
253 |
iliev |
912 |
|
254 |
iliev |
1285 |
int i = hSplitPane.getDividerLocation(); |
255 |
|
|
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
256 |
|
|
|
257 |
|
|
preferences().setBoolProperty ( |
258 |
|
|
"MainFrame.windowMaximized", |
259 |
|
|
(getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH |
260 |
|
|
); |
261 |
|
|
|
262 |
|
|
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
263 |
|
|
super.onWindowClose(); |
264 |
|
|
return; |
265 |
|
|
} |
266 |
|
|
|
267 |
iliev |
912 |
java.awt.Point p = getLocation(); |
268 |
|
|
Dimension d = getSize(); |
269 |
|
|
StringBuffer sb = new StringBuffer(); |
270 |
iliev |
1285 |
sb.append(p.x).append(',').append(p.y).append(','); |
271 |
|
|
sb.append(d.width).append(',').append(d.height); |
272 |
|
|
preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString()); |
273 |
iliev |
912 |
|
274 |
iliev |
1308 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
275 |
|
|
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
276 |
iliev |
1285 |
|
277 |
|
|
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
278 |
|
|
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
279 |
|
|
} |
280 |
|
|
|
281 |
iliev |
912 |
super.onWindowClose(); |
282 |
|
|
} |
283 |
|
|
|
284 |
iliev |
1285 |
private void |
285 |
|
|
addMenu() { |
286 |
|
|
JMenu m; |
287 |
|
|
JMenuItem mi; |
288 |
|
|
|
289 |
|
|
setJMenuBar(menuBar); |
290 |
|
|
|
291 |
|
|
// Actions |
292 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
293 |
|
|
|
294 |
iliev |
1688 |
mi = new JMenuItem(a4n.refresh); |
295 |
iliev |
1285 |
mi.setIcon(null); |
296 |
iliev |
1688 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
297 |
iliev |
1285 |
m.add(mi); |
298 |
|
|
|
299 |
|
|
mi = new JMenuItem(a4n.samplerInfo); |
300 |
|
|
mi.setIcon(null); |
301 |
|
|
m.add(mi); |
302 |
|
|
|
303 |
iliev |
1688 |
mi = new JMenuItem(a4n.resetSampler); |
304 |
|
|
mi.setIcon(null); |
305 |
|
|
m.add(mi); |
306 |
|
|
|
307 |
iliev |
1285 |
m.addSeparator(); |
308 |
|
|
|
309 |
|
|
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
310 |
|
|
m.add(exportMenu); |
311 |
|
|
|
312 |
|
|
mi = new JMenuItem(a4n.exportSamplerConfig); |
313 |
|
|
mi.setIcon(null); |
314 |
|
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
315 |
|
|
exportMenu.add(mi); |
316 |
|
|
|
317 |
|
|
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
318 |
|
|
mi.setIcon(null); |
319 |
|
|
exportMenu.add(mi); |
320 |
|
|
|
321 |
|
|
m.addSeparator(); |
322 |
|
|
|
323 |
|
|
mi = new JMenuItem(a4n.loadScript); |
324 |
|
|
mi.setIcon(null); |
325 |
iliev |
1688 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
326 |
iliev |
1285 |
m.add(mi); |
327 |
|
|
|
328 |
iliev |
1308 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
329 |
|
|
for(String s : list) recentScripts.add(s); |
330 |
iliev |
1285 |
|
331 |
|
|
updateRecentScriptsMenu(); |
332 |
|
|
|
333 |
|
|
m.add(recentScriptsMenu); |
334 |
|
|
|
335 |
|
|
m.addSeparator(); |
336 |
|
|
|
337 |
iliev |
1688 |
mi = new JMenuItem(a4n.changeBackend); |
338 |
|
|
mi.setIcon(null); |
339 |
|
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
340 |
|
|
m.add(mi); |
341 |
|
|
|
342 |
|
|
m.addSeparator(); |
343 |
|
|
|
344 |
iliev |
1285 |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
345 |
|
|
m.add(mi); |
346 |
|
|
mi.addActionListener(new ActionListener() { |
347 |
|
|
public void |
348 |
|
|
actionPerformed(ActionEvent e) { onWindowClose(); } |
349 |
|
|
}); |
350 |
|
|
|
351 |
|
|
menuBar.add(m); |
352 |
|
|
|
353 |
|
|
|
354 |
|
|
// Edit |
355 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
356 |
|
|
menuBar.add(m); |
357 |
|
|
|
358 |
iliev |
1323 |
mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel")); |
359 |
|
|
m.add(mi); |
360 |
|
|
mi.addActionListener(new ActionListener() { |
361 |
|
|
public void |
362 |
|
|
actionPerformed(ActionEvent e) { |
363 |
|
|
CC.getSamplerModel().addBackendChannel(); |
364 |
|
|
} |
365 |
|
|
}); |
366 |
|
|
|
367 |
|
|
m.addSeparator(); |
368 |
|
|
|
369 |
|
|
mi = new JMenuItem(a4n.createMidiDevice); |
370 |
|
|
mi.setIcon(null); |
371 |
|
|
m.add(mi); |
372 |
|
|
|
373 |
|
|
mi = new JMenuItem(a4n.createAudioDevice); |
374 |
|
|
mi.setIcon(null); |
375 |
|
|
m.add(mi); |
376 |
|
|
|
377 |
|
|
m.addSeparator(); |
378 |
|
|
|
379 |
iliev |
1285 |
mi = new JMenuItem(a4n.editPreferences); |
380 |
|
|
mi.setIcon(null); |
381 |
|
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
382 |
|
|
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
383 |
|
|
)); |
384 |
|
|
m.add(mi); |
385 |
|
|
|
386 |
iliev |
1323 |
// View |
387 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
388 |
|
|
menuBar.add(m); |
389 |
iliev |
1285 |
|
390 |
iliev |
1323 |
m.add(cbmiToolBarVisible); |
391 |
|
|
|
392 |
|
|
cbmiToolBarVisible.addActionListener(new ActionListener() { |
393 |
|
|
public void |
394 |
|
|
actionPerformed(ActionEvent e) { |
395 |
|
|
showToolBar(cbmiToolBarVisible.getState()); |
396 |
|
|
} |
397 |
|
|
}); |
398 |
|
|
|
399 |
|
|
boolean b = preferences().getBoolProperty("toolBar.visible"); |
400 |
|
|
cbmiToolBarVisible.setSelected(b); |
401 |
|
|
showToolBar(b); |
402 |
|
|
|
403 |
iliev |
1729 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
404 |
iliev |
1323 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
405 |
|
|
)); |
406 |
iliev |
1729 |
m.add(cbmiLeftSidePaneVisible); |
407 |
iliev |
1323 |
|
408 |
iliev |
1729 |
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
409 |
iliev |
1323 |
public void |
410 |
|
|
actionPerformed(ActionEvent e) { |
411 |
iliev |
1729 |
showSidePane(cbmiLeftSidePaneVisible.getState()); |
412 |
iliev |
1323 |
} |
413 |
|
|
}); |
414 |
|
|
|
415 |
iliev |
1729 |
b = preferences().getBoolProperty("leftSidePane.visible"); |
416 |
|
|
cbmiLeftSidePaneVisible.setSelected(b); |
417 |
iliev |
1323 |
showSidePane(b); |
418 |
|
|
|
419 |
iliev |
1729 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
420 |
iliev |
1323 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
421 |
|
|
)); |
422 |
iliev |
1729 |
m.add(cbmiRightSidePaneVisible); |
423 |
iliev |
1323 |
|
424 |
iliev |
1729 |
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
425 |
iliev |
1323 |
public void |
426 |
|
|
actionPerformed(ActionEvent e) { |
427 |
iliev |
1729 |
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
428 |
iliev |
1323 |
} |
429 |
|
|
}); |
430 |
|
|
|
431 |
iliev |
1729 |
b = preferences().getBoolProperty("rightSidePane.visible"); |
432 |
|
|
cbmiRightSidePaneVisible.setSelected(b); |
433 |
iliev |
1323 |
showDevicesPane(b); |
434 |
|
|
|
435 |
iliev |
1776 |
m.addSeparator(); |
436 |
iliev |
1323 |
|
437 |
iliev |
1776 |
m.add(cbmiMidiKeyboardVisible); |
438 |
|
|
|
439 |
|
|
cbmiMidiKeyboardVisible.addActionListener(new ActionListener() { |
440 |
|
|
public void |
441 |
|
|
actionPerformed(ActionEvent e) { |
442 |
|
|
showMidiKeyboard(cbmiMidiKeyboardVisible.getState()); |
443 |
|
|
} |
444 |
|
|
}); |
445 |
|
|
|
446 |
|
|
b = preferences().getBoolProperty("midiKeyboard.visible"); |
447 |
|
|
cbmiMidiKeyboardVisible.setSelected(b); |
448 |
|
|
showMidiKeyboard(b); |
449 |
|
|
|
450 |
|
|
|
451 |
iliev |
1285 |
// Window |
452 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
453 |
|
|
menuBar.add(m); |
454 |
|
|
|
455 |
|
|
mi = new JMenuItem(a4n.windowLSConsole); |
456 |
|
|
mi.setIcon(null); |
457 |
|
|
m.add(mi); |
458 |
|
|
|
459 |
|
|
mi = new JMenuItem(a4n.windowInstrumentsDb); |
460 |
|
|
mi.setIcon(null); |
461 |
|
|
m.add(mi); |
462 |
|
|
|
463 |
|
|
|
464 |
|
|
// Help |
465 |
|
|
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
466 |
|
|
|
467 |
iliev |
1496 |
mi = new JMenuItem(a4n.browseOnlineTutorial); |
468 |
|
|
mi.setIcon(null); |
469 |
|
|
m.add(mi); |
470 |
|
|
|
471 |
|
|
m.addSeparator(); |
472 |
|
|
|
473 |
iliev |
1285 |
mi = new JMenuItem(a4n.helpAbout); |
474 |
|
|
mi.setIcon(null); |
475 |
|
|
m.add(mi); |
476 |
|
|
|
477 |
|
|
menuBar.add(m); |
478 |
iliev |
912 |
} |
479 |
|
|
|
480 |
iliev |
1767 |
public RightSidePane |
481 |
|
|
getRightSidePane() { return rightSidePane; } |
482 |
|
|
|
483 |
iliev |
912 |
/** |
484 |
|
|
* This method does nothing, because <b>Fantasia</b> has exactly |
485 |
|
|
* one pane containing sampler channels, which can not be changed. |
486 |
|
|
*/ |
487 |
|
|
public void |
488 |
|
|
insertChannelsPane(JSChannelsPane pane, int idx) { |
489 |
iliev |
1285 |
|
490 |
iliev |
912 |
} |
491 |
|
|
|
492 |
|
|
/** |
493 |
|
|
* This method always returns the <code>JSChannelsPane</code> at index 0, |
494 |
|
|
* because the <b>Fantasia</b> view has exactly one pane containing sampler channels. |
495 |
|
|
* @return The <code>JSChannelsPane</code> at index 0. |
496 |
|
|
*/ |
497 |
|
|
public JSChannelsPane |
498 |
|
|
getSelectedChannelsPane() { return getChannelsPane(0); } |
499 |
|
|
|
500 |
|
|
/** |
501 |
|
|
* This method does nothing because the <b>Fantasia</b> view has |
502 |
|
|
* exactly one pane containing sampler channels which is always shown. |
503 |
|
|
*/ |
504 |
|
|
public void |
505 |
|
|
setSelectedChannelsPane(JSChannelsPane pane) { } |
506 |
|
|
|
507 |
iliev |
1285 |
public void |
508 |
|
|
installJSamplerHome() { |
509 |
|
|
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
510 |
|
|
chooser.setVisible(true); |
511 |
|
|
if(chooser.isCancelled()) return; |
512 |
iliev |
912 |
|
513 |
iliev |
1285 |
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
514 |
iliev |
912 |
} |
515 |
|
|
|
516 |
iliev |
1143 |
public void |
517 |
iliev |
1204 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
518 |
iliev |
1355 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
519 |
|
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
520 |
|
|
); |
521 |
|
|
dlg.setVisible(true); |
522 |
iliev |
1204 |
} |
523 |
|
|
|
524 |
|
|
public void |
525 |
|
|
showDetailedErrorMessage(Dialog owner, String err, String details) { |
526 |
iliev |
1355 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
527 |
|
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
528 |
|
|
); |
529 |
|
|
dlg.setVisible(true); |
530 |
iliev |
1204 |
} |
531 |
iliev |
912 |
|
532 |
iliev |
1688 |
/** |
533 |
|
|
* Gets the server address to which to connect. If the server should be |
534 |
|
|
* manually selected, a dialog asking the user to choose a server is displayed. |
535 |
|
|
*/ |
536 |
|
|
public Server |
537 |
|
|
getServer() { |
538 |
|
|
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
539 |
|
|
return getServer(b); |
540 |
|
|
} |
541 |
|
|
|
542 |
|
|
/** |
543 |
|
|
* Gets the server address to which to connect. If the server should be |
544 |
|
|
* manually selected, a dialog asking the user to choose a server is displayed. |
545 |
|
|
* @param manualSelect Determines whether the server should be manually selected. |
546 |
|
|
*/ |
547 |
|
|
public Server |
548 |
|
|
getServer(boolean manualSelect) { |
549 |
|
|
if(manualSelect) { |
550 |
|
|
JSConnectDlg dlg = new JSConnectDlg(); |
551 |
|
|
dlg.setVisible(true); |
552 |
|
|
return dlg.getSelectedServer(); |
553 |
|
|
} |
554 |
|
|
|
555 |
|
|
int i = preferences().getIntProperty(SERVER_INDEX); |
556 |
|
|
int size = CC.getServerList().getServerCount(); |
557 |
|
|
if(size == 0) return null; |
558 |
|
|
if(i >= size) return CC.getServerList().getServer(0); |
559 |
|
|
|
560 |
|
|
return CC.getServerList().getServer(i); |
561 |
|
|
} |
562 |
|
|
|
563 |
iliev |
1734 |
public Timer |
564 |
|
|
getGuiTimer() { return guiTimer; } |
565 |
|
|
|
566 |
iliev |
1285 |
protected LSConsoleModel |
567 |
|
|
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
568 |
|
|
|
569 |
|
|
protected LSConsolePane |
570 |
|
|
getLSConsolePane() { |
571 |
|
|
return getLSConsoleFrame().getLSConsolePane(); |
572 |
|
|
} |
573 |
|
|
|
574 |
|
|
protected LSConsoleFrame |
575 |
iliev |
1311 |
getLSConsoleFrame() { return lsConsoleFrame; } |
576 |
iliev |
1285 |
|
577 |
iliev |
1688 |
protected boolean |
578 |
iliev |
1285 |
runScript() { |
579 |
|
|
String s = preferences().getStringProperty("lastScriptLocation"); |
580 |
|
|
JFileChooser fc = new JFileChooser(s); |
581 |
|
|
fc.setFileFilter(new LscpFileFilter()); |
582 |
|
|
int result = fc.showOpenDialog(this); |
583 |
iliev |
1688 |
if(result != JFileChooser.APPROVE_OPTION) return false; |
584 |
iliev |
912 |
|
585 |
iliev |
1285 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
586 |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
587 |
|
|
|
588 |
|
|
runScript(fc.getSelectedFile()); |
589 |
iliev |
1688 |
|
590 |
|
|
return true; |
591 |
iliev |
1285 |
} |
592 |
|
|
|
593 |
|
|
private void |
594 |
|
|
runScript(String script) { runScript(new File(script)); } |
595 |
|
|
|
596 |
|
|
private void |
597 |
|
|
runScript(File script) { |
598 |
|
|
FileReader fr; |
599 |
|
|
try { fr = new FileReader(script); } |
600 |
|
|
catch(FileNotFoundException e) { |
601 |
|
|
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
602 |
|
|
return; |
603 |
iliev |
912 |
} |
604 |
|
|
|
605 |
iliev |
1285 |
BufferedReader br = new BufferedReader(fr); |
606 |
|
|
|
607 |
|
|
try { |
608 |
|
|
String s = br.readLine(); |
609 |
|
|
while(s != null) { |
610 |
|
|
getLSConsoleModel().setCommandLineText(s); |
611 |
|
|
getLSConsoleModel().execCommand(); |
612 |
|
|
s = br.readLine(); |
613 |
|
|
} |
614 |
|
|
} catch(Exception e) { |
615 |
|
|
HF.showErrorMessage(e); |
616 |
|
|
return; |
617 |
iliev |
912 |
} |
618 |
iliev |
1285 |
|
619 |
|
|
String s = script.getAbsolutePath(); |
620 |
|
|
recentScripts.remove(s); |
621 |
|
|
recentScripts.insertElementAt(s, 0); |
622 |
|
|
|
623 |
|
|
updateRecentScriptsMenu(); |
624 |
|
|
} |
625 |
iliev |
912 |
|
626 |
iliev |
1285 |
protected void |
627 |
|
|
clearRecentScripts() { |
628 |
|
|
recentScripts.removeAllElements(); |
629 |
|
|
updateRecentScriptsMenu(); |
630 |
|
|
} |
631 |
|
|
|
632 |
|
|
protected void |
633 |
|
|
updateRecentScriptsMenu() { |
634 |
|
|
int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE); |
635 |
|
|
while(recentScripts.size() > size) { |
636 |
|
|
recentScripts.removeElementAt(recentScripts.size() - 1); |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
recentScriptsMenu.removeAll(); |
640 |
|
|
|
641 |
|
|
for(String script : recentScripts) { |
642 |
|
|
JMenuItem mi = new JMenuItem(script); |
643 |
|
|
recentScriptsMenu.add(mi); |
644 |
|
|
mi.addActionListener(new RecentScriptHandler(script)); |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
648 |
|
|
} |
649 |
|
|
|
650 |
iliev |
1323 |
private void |
651 |
|
|
showToolBar(boolean b) { |
652 |
|
|
preferences().setBoolProperty("toolBar.visible", b); |
653 |
|
|
standardBar.setVisible(b); |
654 |
|
|
} |
655 |
|
|
|
656 |
|
|
private void |
657 |
|
|
showSidePane(boolean b) { |
658 |
iliev |
1729 |
preferences().setBoolProperty("leftSidePane.visible", b); |
659 |
iliev |
1323 |
rootPane.remove(rightPane); |
660 |
|
|
rootPane.remove(hSplitPane); |
661 |
|
|
|
662 |
|
|
if(b) { |
663 |
|
|
hSplitPane.setRightComponent(rightPane); |
664 |
|
|
rootPane.add(hSplitPane); |
665 |
|
|
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
666 |
|
|
|
667 |
|
|
hSplitPane.setDividerLocation(i); |
668 |
|
|
hSplitPane.validate(); |
669 |
|
|
} else { |
670 |
|
|
rootPane.add(rightPane); |
671 |
|
|
|
672 |
|
|
} |
673 |
|
|
|
674 |
|
|
int w = getPreferredSize().width; |
675 |
|
|
int h = getSize().height; |
676 |
|
|
setSize(new Dimension(w, h)); |
677 |
|
|
|
678 |
|
|
rootPane.revalidate(); |
679 |
|
|
rootPane.validate(); |
680 |
|
|
rootPane.repaint(); |
681 |
|
|
|
682 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
683 |
|
|
public void |
684 |
|
|
run() { sidePanesVisibilityChanged(); } |
685 |
|
|
}); |
686 |
|
|
} |
687 |
|
|
|
688 |
|
|
private void |
689 |
|
|
showDevicesPane(boolean b) { |
690 |
iliev |
1729 |
preferences().setBoolProperty("rightSidePane.visible", b); |
691 |
iliev |
1323 |
|
692 |
iliev |
1729 |
int width = leftSidePane.getWidth(); |
693 |
|
|
int height = leftSidePane.getPreferredSize().height; |
694 |
|
|
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
695 |
iliev |
1323 |
|
696 |
|
|
if(b) { |
697 |
|
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
698 |
|
|
|
699 |
iliev |
1729 |
int h = rightSidePane.getPreferredSize().height; |
700 |
|
|
rightSidePane.setPreferredSize(new Dimension(w, h)); |
701 |
iliev |
1323 |
} else { |
702 |
iliev |
1729 |
int w = rightSidePane.getWidth(); |
703 |
iliev |
1323 |
if(w > 0 && w < 200) w = 200; |
704 |
|
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
705 |
|
|
} |
706 |
|
|
|
707 |
|
|
hSplitPane.setResizeWeight(0.0); |
708 |
iliev |
1729 |
rightSidePane.setVisible(b); |
709 |
iliev |
1323 |
hSplitPane.resetToPreferredSizes(); |
710 |
|
|
|
711 |
|
|
int w = getPreferredSize().width; |
712 |
|
|
int h = getSize().height; |
713 |
|
|
setSize(new Dimension(w, h)); |
714 |
|
|
|
715 |
|
|
rootPane.validate(); |
716 |
|
|
rootPane.repaint(); |
717 |
|
|
//hSplitPane.validate(); |
718 |
|
|
|
719 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
720 |
|
|
public void |
721 |
|
|
run() { sidePanesVisibilityChanged(); } |
722 |
|
|
}); |
723 |
|
|
} |
724 |
|
|
|
725 |
|
|
private void |
726 |
iliev |
1776 |
showMidiKeyboard(boolean b) { |
727 |
|
|
preferences().setBoolProperty("midiKeyboard.visible", b); |
728 |
|
|
if(b) { |
729 |
|
|
getContentPane().remove(rootPane); |
730 |
|
|
pianoRollSplitPane.setTopComponent(rootPane); |
731 |
|
|
getContentPane().add(pianoRollSplitPane); |
732 |
|
|
} else { |
733 |
|
|
getContentPane().remove(pianoRollSplitPane); |
734 |
|
|
pianoRollSplitPane.remove(rootPane); |
735 |
|
|
getContentPane().add(rootPane); |
736 |
|
|
} |
737 |
|
|
|
738 |
|
|
getContentPane().validate(); |
739 |
|
|
getContentPane().repaint(); |
740 |
|
|
} |
741 |
|
|
|
742 |
|
|
private void |
743 |
iliev |
1323 |
sidePanesVisibilityChanged() { |
744 |
iliev |
1729 |
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
745 |
|
|
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
746 |
iliev |
1323 |
|
747 |
iliev |
1729 |
if(leftSidePaneVisible && rightSidePaneVisible) { |
748 |
iliev |
1323 |
hSplitPane.setResizeWeight(0.5); |
749 |
iliev |
1729 |
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
750 |
iliev |
1323 |
hSplitPane.setResizeWeight(1.0); |
751 |
|
|
} |
752 |
|
|
|
753 |
iliev |
1729 |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
754 |
iliev |
1323 |
standardBar.showFantasiaLogo(false); |
755 |
|
|
if(isResizable()) setResizable(false); |
756 |
|
|
} else { |
757 |
|
|
standardBar.showFantasiaLogo(true); |
758 |
|
|
if(!isResizable()) setResizable(true); |
759 |
|
|
} |
760 |
|
|
} |
761 |
|
|
|
762 |
iliev |
1285 |
private class RecentScriptHandler implements ActionListener { |
763 |
|
|
private String script; |
764 |
|
|
|
765 |
|
|
RecentScriptHandler(String script) { this.script = script; } |
766 |
|
|
|
767 |
iliev |
912 |
public void |
768 |
iliev |
1285 |
actionPerformed(ActionEvent e) { |
769 |
|
|
runScript(script); |
770 |
|
|
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
771 |
|
|
a4n.windowLSConsole.actionPerformed(null); |
772 |
|
|
} |
773 |
iliev |
912 |
} |
774 |
iliev |
1285 |
} |
775 |
iliev |
912 |
|
776 |
iliev |
1285 |
private static class FantasiaMenu extends JMenu { |
777 |
|
|
FantasiaMenu(String s) { |
778 |
|
|
super(s); |
779 |
|
|
setFont(getFont().deriveFont(java.awt.Font.BOLD)); |
780 |
|
|
setOpaque(false); |
781 |
iliev |
1776 |
setContentAreaFilled(false); |
782 |
iliev |
912 |
} |
783 |
|
|
} |
784 |
iliev |
1285 |
|
785 |
iliev |
1323 |
private class FantasiaMenuBar extends JMenuBar { |
786 |
|
|
private Insets pixmapInsets = new Insets(6, 6, 0, 6); |
787 |
|
|
private Insets pixmapInsets2 = new Insets(6, 6, 6, 6); |
788 |
iliev |
1285 |
|
789 |
|
|
FantasiaMenuBar() { |
790 |
|
|
setOpaque(false); |
791 |
|
|
} |
792 |
|
|
|
793 |
|
|
protected void |
794 |
|
|
paintComponent(Graphics g) { |
795 |
|
|
super.paintComponent(g); |
796 |
iliev |
1323 |
if(standardBar.isVisible()) { |
797 |
|
|
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
798 |
|
|
} else { |
799 |
|
|
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
800 |
|
|
} |
801 |
iliev |
1285 |
} |
802 |
|
|
} |
803 |
iliev |
912 |
} |