/[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 1786 - (show annotations) (download)
Wed Oct 8 22:38:15 2008 UTC (15 years, 6 months ago) by iliev
File size: 23949 byte(s)
* Implemented option to launch the backend if it is not yet started
  (choose Edit/Preferences, then click the `Backend' tab)
* LSCP scripts can now be run by passing them to jsampler
  as command-line arguments
* The scripts in the `scripts' directory now pass the command-line
  arguments to the respective jsampler distribution
* ant: the default target is now build-fantasia
* bugfix: backend address was always set to 127.0.0.1 when adding
  backend to the backend list

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

  ViewVC Help
Powered by ViewVC