/[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 1785 - (show annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 6 months ago) by iliev
File size: 23663 byte(s)
* Fantasia: Implemented multiple channels panels
* Fantasia: Refactoring - all basic UI components moved to
  org.jsampler.view.fantasia.basic package

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

  ViewVC Help
Powered by ViewVC