1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2008 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.fantasia; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dialog; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.Frame; |
29 |
import java.awt.Graphics; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.GridBagLayout; |
32 |
import java.awt.Insets; |
33 |
|
34 |
import java.awt.event.ActionEvent; |
35 |
import java.awt.event.ActionListener; |
36 |
import java.awt.event.KeyEvent; |
37 |
|
38 |
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 |
import java.util.logging.Level; |
45 |
|
46 |
import javax.swing.BorderFactory; |
47 |
import javax.swing.JCheckBoxMenuItem; |
48 |
import javax.swing.JFileChooser; |
49 |
import javax.swing.JMenu; |
50 |
import javax.swing.JMenuBar; |
51 |
import javax.swing.JMenuItem; |
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.JSplitPane; |
54 |
import javax.swing.KeyStroke; |
55 |
import javax.swing.SwingUtilities; |
56 |
import javax.swing.Timer; |
57 |
|
58 |
import org.jsampler.CC; |
59 |
import org.jsampler.HF; |
60 |
import org.jsampler.LSConsoleModel; |
61 |
import org.jsampler.Server; |
62 |
|
63 |
import org.jsampler.view.JSChannelsPane; |
64 |
import org.jsampler.view.JSMainFrame; |
65 |
import org.jsampler.view.LscpFileFilter; |
66 |
|
67 |
import org.jsampler.view.std.JSConnectDlg; |
68 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
69 |
import org.jsampler.view.std.JSQuitDlg; |
70 |
import org.jsampler.view.std.JSamplerHomeChooser; |
71 |
|
72 |
import static org.jsampler.view.fantasia.A4n.a4n; |
73 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
74 |
import static org.jsampler.view.fantasia.FantasiaPrefs.preferences; |
75 |
import static org.jsampler.view.std.StdPrefs.*; |
76 |
|
77 |
|
78 |
/** |
79 |
* |
80 |
* @author Grigor Iliev |
81 |
*/ |
82 |
public class MainFrame extends JSMainFrame { |
83 |
private final StandardBar standardBar = new StandardBar(); |
84 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
85 |
private final JPanel rootPane = new JPanel(); |
86 |
private final MainPane mainPane = new MainPane(); |
87 |
private final PianoKeyboardPane pianoKeyboardPane; |
88 |
|
89 |
private final JMenu recentScriptsMenu = |
90 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
91 |
|
92 |
private final JSplitPane hSplitPane; |
93 |
private final JSplitPane pianoRollSplitPane; |
94 |
|
95 |
private final LeftSidePane leftSidePane = new LeftSidePane(); |
96 |
private final RightSidePane rightSidePane = new RightSidePane(); |
97 |
private final JPanel rightPane; |
98 |
|
99 |
//private final StatusBar statusBar = new StatusBar(); |
100 |
|
101 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
102 |
private final Vector<String> recentScripts = new Vector<String>(); |
103 |
|
104 |
|
105 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
106 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
107 |
|
108 |
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
109 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
110 |
|
111 |
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
112 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
113 |
|
114 |
private final JCheckBoxMenuItem cbmiMidiKeyboardVisible = |
115 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard")); |
116 |
|
117 |
private final Timer guiTimer = new Timer(1000, null); |
118 |
|
119 |
/** Creates a new instance of <code>MainFrame</code> */ |
120 |
public |
121 |
MainFrame() { |
122 |
setTitle(i18n.getLabel("MainFrame.title")); |
123 |
|
124 |
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
125 |
|
126 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
127 |
//getContentPane().add(statusBar, BorderLayout.SOUTH); |
128 |
|
129 |
rightPane = createRightPane(); |
130 |
|
131 |
hSplitPane = new JSplitPane ( |
132 |
JSplitPane.HORIZONTAL_SPLIT, |
133 |
true, // continuousLayout |
134 |
leftSidePane, rightPane |
135 |
); |
136 |
hSplitPane.setResizeWeight(0.5); |
137 |
|
138 |
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 |
rootPane.setLayout(new BorderLayout()); |
152 |
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
153 |
rootPane.setOpaque(false); |
154 |
rootPane.add(hSplitPane); |
155 |
|
156 |
addMenu(); |
157 |
|
158 |
getContentPane().add(pianoRollSplitPane); |
159 |
|
160 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
161 |
hSplitPane.setDividerLocation(i); |
162 |
|
163 |
setSavedSize(); |
164 |
|
165 |
guiTimer.start(); |
166 |
} |
167 |
|
168 |
private JPanel |
169 |
createRightPane() { |
170 |
JPanel p = new JPanel(); |
171 |
GridBagLayout gridbag = new GridBagLayout(); |
172 |
GridBagConstraints c = new GridBagConstraints(); |
173 |
|
174 |
p.setLayout(gridbag); |
175 |
|
176 |
c.fill = GridBagConstraints.BOTH; |
177 |
|
178 |
c.gridx = 1; |
179 |
c.gridy = 0; |
180 |
c.weightx = 1.0; |
181 |
c.weighty = 1.0; |
182 |
c.insets = new Insets(0, 3, 0, 0); |
183 |
gridbag.setConstraints(rightSidePane, c); |
184 |
p.add(rightSidePane); |
185 |
|
186 |
c.gridx = 0; |
187 |
c.gridy = 0; |
188 |
c.weightx = 0.0; |
189 |
c.weighty = 1.0; |
190 |
c.insets = new Insets(0, 3, 0, 3); |
191 |
c.fill = GridBagConstraints.VERTICAL; |
192 |
gridbag.setConstraints(mainPane, c); |
193 |
p.add(mainPane); |
194 |
|
195 |
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 |
pack(); |
206 |
try { |
207 |
int i = s.indexOf(','); |
208 |
int x = Integer.parseInt(s.substring(0, i)); |
209 |
|
210 |
s = s.substring(i + 1); |
211 |
i = s.indexOf(','); |
212 |
int y = Integer.parseInt(s.substring(0, i)); |
213 |
|
214 |
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 |
} catch(Exception x) { |
223 |
String msg = "Parsing of window size and location string failed"; |
224 |
CC.getLogger().log(Level.INFO, msg, x); |
225 |
setDefaultSizeAndLocation(); |
226 |
} |
227 |
|
228 |
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
229 |
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
230 |
} |
231 |
} |
232 |
|
233 |
private void |
234 |
setDefaultSizeAndLocation() { |
235 |
setPreferredSize(new Dimension(900, 600)); |
236 |
pack(); |
237 |
setLocationRelativeTo(null); |
238 |
} |
239 |
|
240 |
|
241 |
/** Invoked when this window is about to close. */ |
242 |
protected void |
243 |
onWindowClose() { |
244 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
245 |
if(b && CC.getSamplerModel().isModified()) { |
246 |
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
247 |
dlg.setVisible(true); |
248 |
if(dlg.isCancelled()) return; |
249 |
} |
250 |
|
251 |
leftSidePane.savePreferences(); |
252 |
rightSidePane.savePreferences(); |
253 |
|
254 |
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 |
java.awt.Point p = getLocation(); |
268 |
Dimension d = getSize(); |
269 |
StringBuffer sb = new StringBuffer(); |
270 |
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 |
|
274 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
275 |
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
276 |
|
277 |
if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) { |
278 |
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
279 |
} |
280 |
|
281 |
super.onWindowClose(); |
282 |
} |
283 |
|
284 |
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 |
mi = new JMenuItem(a4n.refresh); |
295 |
mi.setIcon(null); |
296 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
297 |
m.add(mi); |
298 |
|
299 |
mi = new JMenuItem(a4n.samplerInfo); |
300 |
mi.setIcon(null); |
301 |
m.add(mi); |
302 |
|
303 |
mi = new JMenuItem(a4n.resetSampler); |
304 |
mi.setIcon(null); |
305 |
m.add(mi); |
306 |
|
307 |
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 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
326 |
m.add(mi); |
327 |
|
328 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
329 |
for(String s : list) recentScripts.add(s); |
330 |
|
331 |
updateRecentScriptsMenu(); |
332 |
|
333 |
m.add(recentScriptsMenu); |
334 |
|
335 |
m.addSeparator(); |
336 |
|
337 |
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 |
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 |
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 |
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 |
// View |
387 |
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
388 |
menuBar.add(m); |
389 |
|
390 |
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 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
404 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
405 |
)); |
406 |
m.add(cbmiLeftSidePaneVisible); |
407 |
|
408 |
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
409 |
public void |
410 |
actionPerformed(ActionEvent e) { |
411 |
showSidePane(cbmiLeftSidePaneVisible.getState()); |
412 |
} |
413 |
}); |
414 |
|
415 |
b = preferences().getBoolProperty("leftSidePane.visible"); |
416 |
cbmiLeftSidePaneVisible.setSelected(b); |
417 |
showSidePane(b); |
418 |
|
419 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
420 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
421 |
)); |
422 |
m.add(cbmiRightSidePaneVisible); |
423 |
|
424 |
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
425 |
public void |
426 |
actionPerformed(ActionEvent e) { |
427 |
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
428 |
} |
429 |
}); |
430 |
|
431 |
b = preferences().getBoolProperty("rightSidePane.visible"); |
432 |
cbmiRightSidePaneVisible.setSelected(b); |
433 |
showDevicesPane(b); |
434 |
|
435 |
m.addSeparator(); |
436 |
|
437 |
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 |
// 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 |
mi = new JMenuItem(a4n.browseOnlineTutorial); |
468 |
mi.setIcon(null); |
469 |
m.add(mi); |
470 |
|
471 |
m.addSeparator(); |
472 |
|
473 |
mi = new JMenuItem(a4n.helpAbout); |
474 |
mi.setIcon(null); |
475 |
m.add(mi); |
476 |
|
477 |
menuBar.add(m); |
478 |
} |
479 |
|
480 |
public RightSidePane |
481 |
getRightSidePane() { return rightSidePane; } |
482 |
|
483 |
/** |
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 |
|
490 |
} |
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 |
public void |
508 |
installJSamplerHome() { |
509 |
JSamplerHomeChooser chooser = new JSamplerHomeChooser(this); |
510 |
chooser.setVisible(true); |
511 |
if(chooser.isCancelled()) return; |
512 |
|
513 |
CC.changeJSamplerHome(chooser.getJSamplerHome()); |
514 |
} |
515 |
|
516 |
public void |
517 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
518 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
519 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
520 |
); |
521 |
dlg.setVisible(true); |
522 |
} |
523 |
|
524 |
public void |
525 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
526 |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
527 |
owner, Res.iconWarning32, i18n.getError("error"), err, details |
528 |
); |
529 |
dlg.setVisible(true); |
530 |
} |
531 |
|
532 |
/** |
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 |
public Timer |
564 |
getGuiTimer() { return guiTimer; } |
565 |
|
566 |
protected LSConsoleModel |
567 |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
568 |
|
569 |
protected LSConsolePane |
570 |
getLSConsolePane() { |
571 |
return getLSConsoleFrame().getLSConsolePane(); |
572 |
} |
573 |
|
574 |
protected LSConsoleFrame |
575 |
getLSConsoleFrame() { return lsConsoleFrame; } |
576 |
|
577 |
protected boolean |
578 |
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 |
if(result != JFileChooser.APPROVE_OPTION) return false; |
584 |
|
585 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
586 |
preferences().setStringProperty("lastScriptLocation", path); |
587 |
|
588 |
runScript(fc.getSelectedFile()); |
589 |
|
590 |
return true; |
591 |
} |
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 |
} |
604 |
|
605 |
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 |
} |
618 |
|
619 |
String s = script.getAbsolutePath(); |
620 |
recentScripts.remove(s); |
621 |
recentScripts.insertElementAt(s, 0); |
622 |
|
623 |
updateRecentScriptsMenu(); |
624 |
} |
625 |
|
626 |
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 |
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 |
preferences().setBoolProperty("leftSidePane.visible", b); |
659 |
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 |
preferences().setBoolProperty("rightSidePane.visible", b); |
691 |
|
692 |
int width = leftSidePane.getWidth(); |
693 |
int height = leftSidePane.getPreferredSize().height; |
694 |
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
695 |
|
696 |
if(b) { |
697 |
int w = preferences().getIntProperty("devicesPane.width", 200); |
698 |
|
699 |
int h = rightSidePane.getPreferredSize().height; |
700 |
rightSidePane.setPreferredSize(new Dimension(w, h)); |
701 |
} else { |
702 |
int w = rightSidePane.getWidth(); |
703 |
if(w > 0 && w < 200) w = 200; |
704 |
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
705 |
} |
706 |
|
707 |
hSplitPane.setResizeWeight(0.0); |
708 |
rightSidePane.setVisible(b); |
709 |
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 |
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 |
sidePanesVisibilityChanged() { |
744 |
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
745 |
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
746 |
|
747 |
if(leftSidePaneVisible && rightSidePaneVisible) { |
748 |
hSplitPane.setResizeWeight(0.5); |
749 |
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
750 |
hSplitPane.setResizeWeight(1.0); |
751 |
} |
752 |
|
753 |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
754 |
standardBar.showFantasiaLogo(false); |
755 |
if(isResizable()) setResizable(false); |
756 |
} else { |
757 |
standardBar.showFantasiaLogo(true); |
758 |
if(!isResizable()) setResizable(true); |
759 |
} |
760 |
} |
761 |
|
762 |
private class RecentScriptHandler implements ActionListener { |
763 |
private String script; |
764 |
|
765 |
RecentScriptHandler(String script) { this.script = script; } |
766 |
|
767 |
public void |
768 |
actionPerformed(ActionEvent e) { |
769 |
runScript(script); |
770 |
if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) { |
771 |
a4n.windowLSConsole.actionPerformed(null); |
772 |
} |
773 |
} |
774 |
} |
775 |
|
776 |
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 |
setContentAreaFilled(false); |
782 |
} |
783 |
} |
784 |
|
785 |
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 |
|
789 |
FantasiaMenuBar() { |
790 |
setOpaque(false); |
791 |
} |
792 |
|
793 |
protected void |
794 |
paintComponent(Graphics g) { |
795 |
super.paintComponent(g); |
796 |
if(standardBar.isVisible()) { |
797 |
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
798 |
} else { |
799 |
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
800 |
} |
801 |
} |
802 |
} |
803 |
} |