/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/MainFrame.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/MainFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1865 - (show annotations) (download)
Sun Mar 15 14:33:48 2009 UTC (15 years, 1 month ago) by iliev
File size: 26578 byte(s)
* Mac OS integration, work in progress: screen menu bar fixes

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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.Color;
27 import java.awt.Composite;
28 import java.awt.Dialog;
29 import java.awt.Dimension;
30 import java.awt.Frame;
31 import java.awt.Graphics;
32 import java.awt.Graphics2D;
33 import java.awt.GridBagConstraints;
34 import java.awt.GridBagLayout;
35 import java.awt.Insets;
36 import java.awt.Paint;
37 import java.awt.Rectangle;
38
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.KeyEvent;
42
43 import java.beans.PropertyChangeEvent;
44 import java.beans.PropertyChangeListener;
45
46 import java.io.BufferedReader;
47 import java.io.File;
48 import java.io.FileNotFoundException;
49 import java.io.FileReader;
50
51 import java.util.Vector;
52
53 import javax.swing.BorderFactory;
54 import javax.swing.BoxLayout;
55 import javax.swing.JCheckBoxMenuItem;
56 import javax.swing.JFileChooser;
57 import javax.swing.JMenu;
58 import javax.swing.JMenuBar;
59 import javax.swing.JMenuItem;
60 import javax.swing.JPanel;
61 import javax.swing.JSplitPane;
62 import javax.swing.KeyStroke;
63 import javax.swing.SwingUtilities;
64 import javax.swing.Timer;
65
66 import javax.swing.event.ListSelectionEvent;
67 import javax.swing.event.ListSelectionListener;
68
69 import org.jsampler.CC;
70 import org.jsampler.HF;
71 import org.jsampler.LSConsoleModel;
72 import org.jsampler.Server;
73
74 import org.jsampler.view.JSChannelsPane;
75 import org.jsampler.view.LscpFileFilter;
76 import org.jsampler.view.SessionViewConfig;
77
78 import org.jsampler.view.fantasia.basic.FantasiaPainter;
79 import org.jsampler.view.fantasia.basic.FantasiaPanel;
80 import org.jsampler.view.fantasia.basic.FantasiaSubPanel;
81
82 import org.jsampler.view.std.JSBackendLogFrame;
83 import org.jsampler.view.std.JSConnectDlg;
84 import org.jsampler.view.std.JSDetailedErrorDlg;
85 import org.jsampler.view.std.JSQuitDlg;
86 import org.jsampler.view.std.JSamplerHomeChooser;
87 import org.jsampler.view.std.StdMainFrame;
88 import org.jsampler.view.std.StdUtils;
89
90 import static org.jsampler.view.fantasia.A4n.a4n;
91 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
92 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
93 import static org.jsampler.view.std.StdPrefs.*;
94
95
96 /**
97 *
98 * @author Grigor Iliev
99 */
100 public class MainFrame extends StdMainFrame {
101 private final StandardBar standardBar = new StandardBar();
102 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103 private final JPanel rootPane = new RootPane();
104 private final BottomPane bottomPane;
105 private final MainPane mainPane;
106 private final PianoKeyboardPane pianoKeyboardPane;
107
108 private final JMenu recentScriptsMenu =
109 new JMenu(i18n.getMenuLabel("actions.recentScripts"));
110
111 private final JSplitPane hSplitPane;
112
113 private final LeftSidePane leftSidePane;
114 private final RightSidePane rightSidePane;
115 private final JPanel rightPane;
116
117 //private final StatusBar statusBar = new StatusBar();
118
119 private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
120 private final Vector<String> recentScripts = new Vector<String>();
121
122 private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
123
124
125 private final JCheckBoxMenuItem cbmiToolBarVisible =
126 new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
127
128 private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
129 new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
130
131 private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
132 new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
133
134 private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
135 new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
136
137 private final Timer guiTimer = new Timer(1000, null);
138
139 /** Creates a new instance of <code>MainFrame</code> */
140 public
141 MainFrame() {
142 setTitle(i18n.getLabel("MainFrame.title"));
143 //setUndecorated(true);
144 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
145
146 CC.setMainFrame(this); // TODO:
147 mainPane = new MainPane();
148 leftSidePane = new LeftSidePane();
149 rightSidePane = new RightSidePane();
150
151 setSelectedChannelsPane(mainPane.getChannelsPane(0));
152
153 getContentPane().add(standardBar, BorderLayout.NORTH);
154
155 rightPane = createRightPane();
156
157 hSplitPane = new JSplitPane (
158 JSplitPane.HORIZONTAL_SPLIT,
159 true, // continuousLayout
160 leftSidePane, rightPane
161 );
162 hSplitPane.setResizeWeight(0.5);
163
164 pianoKeyboardPane = new PianoKeyboardPane();
165
166 for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
167 addChannelsPane(mainPane.getChannelsPane(i));
168 getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
169 }
170
171
172 int h = preferences().getIntProperty("midiKeyboard.height");
173 setMidiKeyboardHeight(h);
174
175 PropertyChangeListener l = new PropertyChangeListener() {
176 public void
177 propertyChange(PropertyChangeEvent e) {
178 int h = preferences().getIntProperty("midiKeyboard.height");
179 setMidiKeyboardHeight(h);
180 }
181 };
182
183 CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
184
185 bottomPane = new BottomPane();
186
187 hSplitPane.setOpaque(false);
188 rootPane.add(hSplitPane);
189 rootPane.add(bottomPane, BorderLayout.SOUTH);
190 add(rootPane);
191
192 if(CC.isMacOS()) {
193 try { new MacOSApplicationHandler(); }
194 catch(Throwable e) { }
195 }
196
197 addMenu();
198
199 if(CC.getViewConfig().isUsingScreenMenuBar()) {
200 // fix for moving the menu bar on top of the screen
201 // when running on Mac OS and third party plugin is used
202 ((ViewConfig)CC.getViewConfig()).restoreMenuProperties();
203 }
204
205 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
206 hSplitPane.setDividerLocation(i);
207
208 setSavedSize();
209
210 guiTimer.start();
211 }
212
213 private JPanel
214 createRightPane() {
215 JPanel p = new FantasiaPanel();
216 p.setOpaque(false);
217
218 GridBagLayout gridbag = new GridBagLayout();
219 GridBagConstraints c = new GridBagConstraints();
220
221 p.setLayout(gridbag);
222
223 c.fill = GridBagConstraints.BOTH;
224
225 c.gridx = 1;
226 c.gridy = 0;
227 c.weightx = 1.0;
228 c.weighty = 1.0;
229 c.insets = new Insets(0, 3, 0, 0);
230 gridbag.setConstraints(rightSidePane, c);
231 p.add(rightSidePane);
232
233 c.gridx = 0;
234 c.gridy = 0;
235 c.weightx = 0.0;
236 c.weighty = 1.0;
237 c.insets = new Insets(0, 0, 0, 3);
238 c.fill = GridBagConstraints.VERTICAL;
239 gridbag.setConstraints(mainPane, c);
240 p.add(mainPane);
241
242 return p;
243 }
244
245 private void
246 setSavedSize() {
247 Rectangle r = StdUtils.getWindowBounds("MainFrame");
248 if(r == null) {
249 setDefaultSizeAndLocation();
250 return;
251 }
252
253 setBounds(r);
254 }
255
256 private void
257 setDefaultSizeAndLocation() {
258 setPreferredSize(new Dimension(900, 600));
259 pack();
260 setLocationRelativeTo(null);
261 }
262
263
264 /** Invoked when this window is about to close. */
265 @Override
266 public void
267 onWindowClose() {
268 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
269 if(b && CC.getSamplerModel().isModified()) {
270 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
271 dlg.setVisible(true);
272 if(dlg.isCancelled()) return;
273 }
274
275 leftSidePane.savePreferences();
276 rightSidePane.savePreferences();
277
278 int i = hSplitPane.getDividerLocation();
279 preferences().setIntProperty("MainFrame.hSplitDividerLocation", i);
280
281 preferences().setBoolProperty (
282 "MainFrame.windowMaximized",
283 (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH
284 );
285
286 if(preferences().getBoolProperty("MainFrame.windowMaximized")) {
287 super.onWindowClose();
288 return;
289 }
290
291 StdUtils.saveWindowBounds("MainFrame", getBounds());
292
293 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
294 preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
295
296 if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
297 if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
298 }
299
300 if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
301 if(getLSConsolePane() != null) getLSConsolePane().disconnect();
302
303 super.onWindowClose();
304 }
305
306 @Override
307 public void
308 setVisible(boolean b) {
309 if(b == isVisible()) return;
310
311 super.setVisible(b);
312
313 if(b && preferences().getBoolProperty("MainFrame.windowMaximized")) {
314 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
315 }
316 }
317
318 private void
319 addMenu() {
320 JMenu m;
321 JMenuItem mi;
322
323 setJMenuBar(menuBar);
324
325 // Actions
326 m = new FantasiaMenu(i18n.getMenuLabel("actions"));
327
328 mi = new JMenuItem(a4n.refresh);
329 mi.setIcon(null);
330 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
331 m.add(mi);
332
333 mi = new JMenuItem(a4n.samplerInfo);
334 mi.setIcon(null);
335 m.add(mi);
336
337 mi = new JMenuItem(a4n.resetSampler);
338 mi.setIcon(null);
339 m.add(mi);
340
341 m.addSeparator();
342
343 JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
344 m.add(exportMenu);
345
346 int modKey = CC.getViewConfig().getDefaultModKey();
347
348 mi = new JMenuItem(a4n.exportSamplerConfig);
349 mi.setIcon(null);
350 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
351 exportMenu.add(mi);
352
353 mi = new JMenuItem(a4n.exportMidiInstrumentMaps);
354 mi.setIcon(null);
355 exportMenu.add(mi);
356
357 m.addSeparator();
358
359 mi = new JMenuItem(a4n.loadScript);
360 mi.setIcon(null);
361 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
362 m.add(mi);
363
364 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
365 for(String s : list) recentScripts.add(s);
366
367 updateRecentScriptsMenu();
368
369 m.add(recentScriptsMenu);
370
371 m.addSeparator();
372
373 mi = new JMenuItem(a4n.changeBackend);
374 mi.setIcon(null);
375 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
376 m.add(mi);
377
378 m.addSeparator();
379
380 mi = new JMenuItem(i18n.getMenuLabel("actions.exit"));
381 m.add(mi);
382 mi.addActionListener(new ActionListener() {
383 public void
384 actionPerformed(ActionEvent e) { onWindowClose(); }
385 });
386
387 menuBar.add(m);
388
389
390 // Edit
391 m = new FantasiaMenu(i18n.getMenuLabel("edit"));
392 menuBar.add(m);
393
394 mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel"));
395 m.add(mi);
396 mi.addActionListener(new ActionListener() {
397 public void
398 actionPerformed(ActionEvent e) {
399 CC.getSamplerModel().addBackendChannel();
400 }
401 });
402
403 m.addSeparator();
404
405 mi = new JMenuItem(a4n.createMidiDevice);
406 mi.setIcon(null);
407 m.add(mi);
408
409 mi = new JMenuItem(a4n.createAudioDevice);
410 mi.setIcon(null);
411 m.add(mi);
412
413 m.addSeparator();
414
415 mi = new JMenuItem(a4n.editPreferences);
416 mi.setIcon(null);
417 mi.setAccelerator(KeyStroke.getKeyStroke (
418 KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
419 ));
420 m.add(mi);
421
422 // View
423 m = new FantasiaMenu(i18n.getMenuLabel("view"));
424 menuBar.add(m);
425
426 m.add(cbmiToolBarVisible);
427
428 cbmiToolBarVisible.addActionListener(new ActionListener() {
429 public void
430 actionPerformed(ActionEvent e) {
431 showToolBar(cbmiToolBarVisible.getState());
432 }
433 });
434
435 boolean b = preferences().getBoolProperty("toolBar.visible");
436 cbmiToolBarVisible.setSelected(b);
437 showToolBar(b);
438
439 cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
440 KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
441 ));
442 m.add(cbmiLeftSidePaneVisible);
443
444 cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
445 public void
446 actionPerformed(ActionEvent e) {
447 showSidePane(cbmiLeftSidePaneVisible.getState());
448 }
449 });
450
451 b = preferences().getBoolProperty("leftSidePane.visible");
452 cbmiLeftSidePaneVisible.setSelected(b);
453 showSidePane(b);
454
455 cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
456 KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
457 ));
458 m.add(cbmiRightSidePaneVisible);
459
460 cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
461 public void
462 actionPerformed(ActionEvent e) {
463 showDevicesPane(cbmiRightSidePaneVisible.getState());
464 }
465 });
466
467 b = preferences().getBoolProperty("rightSidePane.visible");
468 cbmiRightSidePaneVisible.setSelected(b);
469 showDevicesPane(b);
470
471 m.addSeparator();
472
473 m.add(cbmiMidiKeyboardVisible);
474
475 cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
476 public void
477 actionPerformed(ActionEvent e) {
478 setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
479 }
480 });
481
482 b = preferences().getBoolProperty("midiKeyboard.visible");
483 cbmiMidiKeyboardVisible.setSelected(b);
484 setMidiKeyboardVisible(b);
485
486
487 // Channels
488 m = new FantasiaMenu(i18n.getMenuLabel("channels"));
489
490 mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel"));
491 mi.addActionListener(new ActionListener() {
492 public void
493 actionPerformed(ActionEvent e) {
494 CC.getSamplerModel().addBackendChannel();
495 }
496 });
497 m.add(mi);
498
499 m.addSeparator();
500
501 MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup();
502 MenuManager.getMenuManager().registerChannelViewGroup(group);
503
504 for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem);
505
506 m.addSeparator();
507
508 m.add(new JMenuItem(a4n.moveChannelsOnTop));
509 m.add(new JMenuItem(a4n.moveChannelsUp));
510 m.add(new JMenuItem(a4n.moveChannelsDown));
511 m.add(new JMenuItem(a4n.moveChannelsAtBottom));
512
513 m.add(new ToPanelMenu());
514
515 m.addSeparator();
516
517 mi = new JMenuItem(a4n.selectAllChannels);
518 mi.setIcon(null);
519 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
520 m.add(mi);
521
522 mi = new JMenuItem(a4n.deselectChannels);
523 mi.setIcon(null);
524 mi.setAccelerator(KeyStroke.getKeyStroke (
525 KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
526 ));
527 m.add(mi);
528
529 menuBar.add(m);
530
531 // Window
532 m = new FantasiaMenu(i18n.getMenuLabel("window"));
533 menuBar.add(m);
534
535 mi = new JMenuItem(a4n.windowLSConsole);
536 mi.setIcon(null);
537 m.add(mi);
538
539 mi = new JMenuItem(a4n.windowInstrumentsDb);
540 mi.setIcon(null);
541 m.add(mi);
542
543 m.addSeparator();
544
545 final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog"));
546 m.add(mi2);
547 mi2.addActionListener(new ActionListener() {
548 public void
549 actionPerformed(ActionEvent e) {
550 if(getBackendLogFrame().isVisible()) {
551 getBackendLogFrame().setVisible(false);
552 }
553
554 getBackendLogFrame().setVisible(true);
555 }
556 });
557
558 mi2.setEnabled(CC.getBackendProcess() != null);
559
560 CC.addBackendProcessListener(new ActionListener() {
561 public void
562 actionPerformed(ActionEvent e) {
563 mi2.setEnabled(CC.getBackendProcess() != null);
564 }
565 });
566
567
568 // Help
569 m = new FantasiaMenu(i18n.getMenuLabel("help"));
570
571 mi = new JMenuItem(a4n.browseOnlineTutorial);
572 mi.setIcon(null);
573 m.add(mi);
574
575 m.addSeparator();
576
577 mi = new JMenuItem(a4n.helpAbout);
578 mi.setIcon(null);
579 m.add(mi);
580
581 menuBar.add(m);
582 }
583
584 public static class ToPanelMenu extends FantasiaMenu implements ListSelectionListener {
585 public
586 ToPanelMenu() {
587 super(i18n.getMenuLabel("channels.toPanel"));
588 setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
589
590 CC.getMainFrame().addChannelsPaneSelectionListener(this);
591
592 for(int i = 0; i < CC.getMainFrame().getChannelsPaneCount(); i++) {
593 JSChannelsPane p = CC.getMainFrame().getChannelsPane(i);
594 add(new JMenuItem(new A4n.MoveChannelsToPanel(p)));
595 p.addListSelectionListener(this);
596 }
597 }
598
599 @Override
600 public void
601 valueChanged(ListSelectionEvent e) {
602 setEnabled(CC.getMainFrame().getSelectedChannelsPane().hasSelectedChannel());
603 }
604 }
605
606 public RightSidePane
607 getRightSidePane() { return rightSidePane; }
608
609 @Override
610 public A4n
611 getA4n() { return A4n.a4n; }
612
613 /**
614 * This method does nothing, because <b>Fantasia</b> has constant
615 * number of panes containing sampler channels, which can not be changed.
616 */
617 @Override
618 public void
619 insertChannelsPane(JSChannelsPane pane, int idx) {
620
621 }
622
623 @Override
624 public JSChannelsPane
625 getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
626
627 @Override
628 public void
629 setSelectedChannelsPane(JSChannelsPane pane) {
630 mainPane.setSelectedChannelsPane(pane);
631 fireChannelsPaneSelectionChanged();
632 }
633
634 @Override
635 public void
636 installJSamplerHome() {
637 JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
638 chooser.setVisible(true);
639 if(chooser.isCancelled()) return;
640
641 CC.changeJSamplerHome(chooser.getJSamplerHome());
642 }
643
644 @Override
645 public void
646 showDetailedErrorMessage(Frame owner, String err, String details) {
647 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
648 owner, Res.iconWarning32, i18n.getError("error"), err, details
649 );
650 dlg.setVisible(true);
651 }
652
653 @Override
654 public void
655 showDetailedErrorMessage(Dialog owner, String err, String details) {
656 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
657 owner, Res.iconWarning32, i18n.getError("error"), err, details
658 );
659 dlg.setVisible(true);
660 }
661
662 /**
663 * Gets the server address to which to connect. If the server should be
664 * manually selected, a dialog asking the user to choose a server is displayed.
665 */
666 @Override
667 public Server
668 getServer() {
669 boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP);
670 return getServer(b);
671 }
672
673 /**
674 * Gets the server address to which to connect. If the server should be
675 * manually selected, a dialog asking the user to choose a server is displayed.
676 * @param manualSelect Determines whether the server should be manually selected.
677 */
678 @Override
679 public Server
680 getServer(boolean manualSelect) {
681 if(manualSelect) {
682 JSConnectDlg dlg = new JSConnectDlg();
683 dlg.setVisible(true);
684
685 return dlg.getSelectedServer();
686 }
687
688 int i = preferences().getIntProperty(SERVER_INDEX);
689 int size = CC.getServerList().getServerCount();
690 if(size == 0) return null;
691 if(i >= size) return CC.getServerList().getServer(0);
692
693 return CC.getServerList().getServer(i);
694 }
695
696 public Timer
697 getGuiTimer() { return guiTimer; }
698
699 protected LSConsoleModel
700 getLSConsoleModel() { return getLSConsolePane().getModel(); }
701
702 protected LSConsolePane
703 getLSConsolePane() {
704 return getLSConsoleFrame().getLSConsolePane();
705 }
706
707 protected LSConsoleFrame
708 getLSConsoleFrame() { return lsConsoleFrame; }
709
710 public JSBackendLogFrame
711 getBackendLogFrame() { return backendLogFrame; }
712
713 protected boolean
714 runScript() {
715 String s = preferences().getStringProperty("lastScriptLocation");
716 JFileChooser fc = new JFileChooser(s);
717 fc.setFileFilter(new LscpFileFilter());
718 int result = fc.showOpenDialog(this);
719 if(result != JFileChooser.APPROVE_OPTION) return false;
720
721 String path = fc.getCurrentDirectory().getAbsolutePath();
722 preferences().setStringProperty("lastScriptLocation", path);
723
724 runScript(fc.getSelectedFile());
725
726 return true;
727 }
728
729 @Override
730 public void
731 runScript(String script) { runScript(new File(script)); }
732
733 private void
734 runScript(File script) {
735 FileReader fr;
736 try { fr = new FileReader(script); }
737 catch(FileNotFoundException e) {
738 HF.showErrorMessage(i18n.getMessage("FileNotFound!"));
739 return;
740 }
741
742 String prefix = "#jsampler.fantasia: ";
743 Vector<String> v = new Vector<String>();
744 BufferedReader br = new BufferedReader(fr);
745
746 try {
747 String s = br.readLine();
748 while(s != null) {
749 getLSConsoleModel().setCommandLineText(s);
750 getLSConsoleModel().execCommand();
751 if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
752 s = br.readLine();
753 }
754 } catch(Exception e) {
755 HF.showErrorMessage(e);
756 return;
757 }
758
759 String s = script.getAbsolutePath();
760 recentScripts.remove(s);
761 recentScripts.insertElementAt(s, 0);
762
763 updateRecentScriptsMenu();
764
765 CC.getViewConfig().setSessionViewConfig(
766 new SessionViewConfig(v.toArray(new String[v.size()]))
767 );
768 }
769
770 protected void
771 clearRecentScripts() {
772 recentScripts.removeAllElements();
773 updateRecentScriptsMenu();
774 }
775
776 protected void
777 updateRecentScriptsMenu() {
778 int size = preferences().getIntProperty(RECENT_LSCP_SCRIPTS_SIZE);
779 while(recentScripts.size() > size) {
780 recentScripts.removeElementAt(recentScripts.size() - 1);
781 }
782
783 recentScriptsMenu.removeAll();
784
785 for(String script : recentScripts) {
786 JMenuItem mi = new JMenuItem(script);
787 recentScriptsMenu.add(mi);
788 mi.addActionListener(new RecentScriptHandler(script));
789 }
790
791 recentScriptsMenu.setEnabled(recentScripts.size() != 0);
792 }
793
794 private void
795 showToolBar(boolean b) {
796 preferences().setBoolProperty("toolBar.visible", b);
797 standardBar.setVisible(b);
798 }
799
800 private void
801 showSidePane(boolean b) {
802 preferences().setBoolProperty("leftSidePane.visible", b);
803 rootPane.remove(rightPane);
804 rootPane.remove(hSplitPane);
805
806 if(b) {
807 hSplitPane.setRightComponent(rightPane);
808 rootPane.add(hSplitPane);
809 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
810
811 hSplitPane.setDividerLocation(i);
812 hSplitPane.validate();
813 } else {
814 rootPane.add(rightPane);
815
816 }
817
818 int w = getPreferredSize().width;
819 int h = getSize().height;
820 setSize(new Dimension(w, h));
821
822 rootPane.revalidate();
823 rootPane.validate();
824 rootPane.repaint();
825
826 SwingUtilities.invokeLater(new Runnable() {
827 public void
828 run() { sidePanesVisibilityChanged(); }
829 });
830 }
831
832 private void
833 showDevicesPane(boolean b) {
834 preferences().setBoolProperty("rightSidePane.visible", b);
835
836 int width = leftSidePane.getWidth();
837 int height = leftSidePane.getPreferredSize().height;
838 if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
839
840 if(b) {
841 int w = preferences().getIntProperty("devicesPane.width", 200);
842
843 int h = rightSidePane.getPreferredSize().height;
844 rightSidePane.setPreferredSize(new Dimension(w, h));
845 } else {
846 int w = rightSidePane.getWidth();
847 if(w > 0 && w < 200) w = 200;
848 if(w != 0) preferences().setIntProperty("devicesPane.width", w);
849 }
850
851 hSplitPane.setResizeWeight(0.0);
852 rightSidePane.setVisible(b);
853 hSplitPane.resetToPreferredSizes();
854
855 int w = getPreferredSize().width;
856 int h = getSize().height;
857 setSize(new Dimension(w, h));
858
859 rootPane.validate();
860 rootPane.repaint();
861 //hSplitPane.validate();
862
863 SwingUtilities.invokeLater(new Runnable() {
864 public void
865 run() { sidePanesVisibilityChanged(); }
866 });
867 }
868
869 public void
870 setMidiKeyboardVisible(boolean b) {
871 preferences().setBoolProperty("midiKeyboard.visible", b);
872 pianoKeyboardPane.setVisible(b);
873
874 if(cbmiMidiKeyboardVisible.isSelected() != b) {
875 cbmiMidiKeyboardVisible.setSelected(b);
876 }
877
878 if(standardBar.btnMidiKeyboard.isSelected() != b) {
879 standardBar.btnMidiKeyboard.setSelected(b);
880 }
881
882 if(pianoKeyboardPane.btnPower.isSelected() != b) {
883 pianoKeyboardPane.btnPower.setSelected(b);
884 }
885
886 rootPane.validate();
887 rootPane.repaint();
888 }
889
890 public void
891 setMidiKeyboardHeight(int height) {
892 Dimension d = pianoKeyboardPane.getPreferredSize();
893 d = new Dimension(d.width, height);
894 pianoKeyboardPane.setPreferredSize(d);
895 pianoKeyboardPane.setMinimumSize(d);
896 pianoKeyboardPane.revalidate();
897 pianoKeyboardPane.repaint();
898 }
899
900 private void
901 sidePanesVisibilityChanged() {
902 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
903 boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
904
905 if(leftSidePaneVisible && rightSidePaneVisible) {
906 hSplitPane.setResizeWeight(0.5);
907 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
908 hSplitPane.setResizeWeight(1.0);
909 }
910
911 if(!leftSidePaneVisible && !rightSidePaneVisible) {
912 standardBar.showFantasiaLogo(false);
913 if(isResizable()) setResizable(false);
914 } else {
915 standardBar.showFantasiaLogo(true);
916 if(!isResizable()) setResizable(true);
917 }
918 }
919
920 private class RecentScriptHandler implements ActionListener {
921 private String script;
922
923 RecentScriptHandler(String script) { this.script = script; }
924
925 @Override
926 public void
927 actionPerformed(ActionEvent e) {
928 runScript(script);
929 if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
930 a4n.windowLSConsole.actionPerformed(null);
931 }
932 }
933 }
934
935 private static class FantasiaMenu extends JMenu {
936 FantasiaMenu(String s) {
937 super(s);
938 setFont(getFont().deriveFont(java.awt.Font.BOLD));
939 setOpaque(false);
940 setContentAreaFilled(false);
941 }
942 }
943
944 private class FantasiaMenuBar extends JMenuBar {
945 FantasiaMenuBar() {
946 setOpaque(false);
947 setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
948 }
949
950 @Override
951 protected void
952 paintComponent(Graphics g) {
953 //super.paintComponent(g);
954 Graphics2D g2 = (Graphics2D)g;
955
956 Paint oldPaint = g2.getPaint();
957 Composite oldComposite = g2.getComposite();
958
959 double h = getSize().getHeight();
960 double w = getSize().getWidth();
961
962 FantasiaPainter.paintGradient(g2, 0.0, 0.0, w - 1, h - 1, FantasiaPainter.color6, FantasiaPainter.color5);
963
964 FantasiaPainter.Border b;
965
966
967 if(standardBar.isVisible()) {
968 b = new FantasiaPainter.Border(true, true, false, true);
969 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
970 } else {
971 b = new FantasiaPainter.Border(true, true, true, true);
972 FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
973 }
974
975 g2.setPaint(oldPaint);
976 g2.setComposite(oldComposite);
977 }
978 }
979
980 class RootPane extends FantasiaSubPanel {
981 private final Color color1 = new Color(0x454545);
982 private final Color color2 = new Color(0x2e2e2e);
983
984 RootPane() {
985 setLayout(new BorderLayout());
986 setBorder(BorderFactory.createEmptyBorder(9, 10, 6, 10));
987 setOpaque(false);
988
989 }
990
991 @Override
992 public void
993 paintComponent(Graphics g) {
994 Graphics2D g2 = (Graphics2D)g;
995
996 Paint oldPaint = g2.getPaint();
997 Composite oldComposite = g2.getComposite();
998
999 double h = getSize().getHeight();
1000 double w = getSize().getWidth();
1001
1002 FantasiaPainter.paintBorder(g2, 0, -3, w - 1, h - 1, 6, false);
1003 paintComponent(g2, 5, 1, w - 10, h - 6, color1, color2);
1004
1005 g2.setPaint(oldPaint);
1006 g2.setComposite(oldComposite);
1007 }
1008 }
1009
1010 class BottomPane extends FantasiaPanel {
1011 BottomPane() {
1012 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
1013 setOpaque(false);
1014 add(pianoKeyboardPane);
1015
1016 }
1017 }
1018 }

  ViewVC Help
Powered by ViewVC