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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1865 - (hide 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 iliev 912 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1864 * Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 912 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.view.fantasia;
24    
25     import java.awt.BorderLayout;
26 iliev 1778 import java.awt.Color;
27     import java.awt.Composite;
28 iliev 1204 import java.awt.Dialog;
29 iliev 912 import java.awt.Dimension;
30 iliev 1204 import java.awt.Frame;
31 iliev 1285 import java.awt.Graphics;
32 iliev 1778 import java.awt.Graphics2D;
33 iliev 1285 import java.awt.GridBagConstraints;
34     import java.awt.GridBagLayout;
35     import java.awt.Insets;
36 iliev 1778 import java.awt.Paint;
37 iliev 1786 import java.awt.Rectangle;
38 iliev 912
39     import java.awt.event.ActionEvent;
40     import java.awt.event.ActionListener;
41 iliev 1285 import java.awt.event.KeyEvent;
42 iliev 912
43 iliev 1778 import java.beans.PropertyChangeEvent;
44     import java.beans.PropertyChangeListener;
45    
46 iliev 1285 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 iliev 912
53 iliev 1285 import javax.swing.BorderFactory;
54 iliev 1778 import javax.swing.BoxLayout;
55 iliev 912 import javax.swing.JCheckBoxMenuItem;
56 iliev 1285 import javax.swing.JFileChooser;
57 iliev 912 import javax.swing.JMenu;
58 iliev 1285 import javax.swing.JMenuBar;
59 iliev 912 import javax.swing.JMenuItem;
60     import javax.swing.JPanel;
61 iliev 1285 import javax.swing.JSplitPane;
62     import javax.swing.KeyStroke;
63     import javax.swing.SwingUtilities;
64 iliev 1734 import javax.swing.Timer;
65 iliev 912
66 iliev 1818 import javax.swing.event.ListSelectionEvent;
67     import javax.swing.event.ListSelectionListener;
68    
69 iliev 912 import org.jsampler.CC;
70     import org.jsampler.HF;
71 iliev 1285 import org.jsampler.LSConsoleModel;
72 iliev 1688 import org.jsampler.Server;
73 iliev 912
74     import org.jsampler.view.JSChannelsPane;
75 iliev 1285 import org.jsampler.view.LscpFileFilter;
76 iliev 1818 import org.jsampler.view.SessionViewConfig;
77 iliev 912
78 iliev 1785 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 iliev 1786 import org.jsampler.view.std.JSBackendLogFrame;
83 iliev 1688 import org.jsampler.view.std.JSConnectDlg;
84 iliev 1355 import org.jsampler.view.std.JSDetailedErrorDlg;
85 iliev 1567 import org.jsampler.view.std.JSQuitDlg;
86 iliev 1285 import org.jsampler.view.std.JSamplerHomeChooser;
87 iliev 1818 import org.jsampler.view.std.StdMainFrame;
88 iliev 1786 import org.jsampler.view.std.StdUtils;
89 iliev 1285
90     import static org.jsampler.view.fantasia.A4n.a4n;
91 iliev 912 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
92 iliev 1285 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
93     import static org.jsampler.view.std.StdPrefs.*;
94 iliev 912
95    
96     /**
97     *
98     * @author Grigor Iliev
99     */
100 iliev 1818 public class MainFrame extends StdMainFrame {
101 iliev 1323 private final StandardBar standardBar = new StandardBar();
102 iliev 1285 private final FantasiaMenuBar menuBar = new FantasiaMenuBar();
103 iliev 1778 private final JPanel rootPane = new RootPane();
104     private final BottomPane bottomPane;
105 iliev 1785 private final MainPane mainPane;
106 iliev 1776 private final PianoKeyboardPane pianoKeyboardPane;
107 iliev 912
108 iliev 1285 private final JMenu recentScriptsMenu =
109     new JMenu(i18n.getMenuLabel("actions.recentScripts"));
110 iliev 912
111 iliev 1285 private final JSplitPane hSplitPane;
112    
113 iliev 1785 private final LeftSidePane leftSidePane;
114     private final RightSidePane rightSidePane;
115 iliev 1323 private final JPanel rightPane;
116 iliev 1285
117 iliev 1767 //private final StatusBar statusBar = new StatusBar();
118    
119 iliev 1311 private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame();
120 iliev 1285 private final Vector<String> recentScripts = new Vector<String>();
121 iliev 1786
122     private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame();
123 iliev 1285
124    
125 iliev 1323 private final JCheckBoxMenuItem cbmiToolBarVisible =
126     new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar"));
127    
128 iliev 1729 private final JCheckBoxMenuItem cbmiLeftSidePaneVisible =
129     new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane"));
130 iliev 1323
131 iliev 1729 private final JCheckBoxMenuItem cbmiRightSidePaneVisible =
132     new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane"));
133 iliev 1323
134 iliev 1776 private final JCheckBoxMenuItem cbmiMidiKeyboardVisible =
135     new JCheckBoxMenuItem(i18n.getMenuLabel("view.midiKeyboard"));
136    
137 iliev 1734 private final Timer guiTimer = new Timer(1000, null);
138    
139 iliev 912 /** Creates a new instance of <code>MainFrame</code> */
140     public
141     MainFrame() {
142     setTitle(i18n.getLabel("MainFrame.title"));
143 iliev 1778 //setUndecorated(true);
144 iliev 1285 if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage());
145 iliev 912
146 iliev 1785 CC.setMainFrame(this); // TODO:
147     mainPane = new MainPane();
148     leftSidePane = new LeftSidePane();
149     rightSidePane = new RightSidePane();
150    
151     setSelectedChannelsPane(mainPane.getChannelsPane(0));
152    
153 iliev 1285 getContentPane().add(standardBar, BorderLayout.NORTH);
154 iliev 912
155 iliev 1323 rightPane = createRightPane();
156 iliev 912
157 iliev 1285 hSplitPane = new JSplitPane (
158     JSplitPane.HORIZONTAL_SPLIT,
159     true, // continuousLayout
160 iliev 1729 leftSidePane, rightPane
161 iliev 1285 );
162 iliev 1323 hSplitPane.setResizeWeight(0.5);
163 iliev 912
164 iliev 1785 pianoKeyboardPane = new PianoKeyboardPane();
165 iliev 1776
166 iliev 1785 for(int i = 0; i < mainPane.getChannelsPaneCount(); i++) {
167     addChannelsPane(mainPane.getChannelsPane(i));
168     getChannelsPane(i).addListSelectionListener(pianoKeyboardPane);
169     }
170    
171    
172 iliev 1778 int h = preferences().getIntProperty("midiKeyboard.height");
173     setMidiKeyboardHeight(h);
174 iliev 1776
175 iliev 1778 PropertyChangeListener l = new PropertyChangeListener() {
176     public void
177     propertyChange(PropertyChangeEvent e) {
178     int h = preferences().getIntProperty("midiKeyboard.height");
179     setMidiKeyboardHeight(h);
180     }
181     };
182 iliev 1776
183 iliev 1778 CC.preferences().addPropertyChangeListener("midiKeyboard.height", l);
184 iliev 1776
185 iliev 1778 bottomPane = new BottomPane();
186    
187     hSplitPane.setOpaque(false);
188 iliev 1323 rootPane.add(hSplitPane);
189 iliev 1778 rootPane.add(bottomPane, BorderLayout.SOUTH);
190     add(rootPane);
191 iliev 1865
192     if(CC.isMacOS()) {
193     try { new MacOSApplicationHandler(); }
194     catch(Throwable e) { }
195     }
196 iliev 912
197 iliev 1323 addMenu();
198    
199 iliev 1865 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 iliev 1285 int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220);
206     hSplitPane.setDividerLocation(i);
207 iliev 912
208 iliev 1285 setSavedSize();
209 iliev 1734
210     guiTimer.start();
211 iliev 1285 }
212    
213     private JPanel
214     createRightPane() {
215 iliev 1778 JPanel p = new FantasiaPanel();
216     p.setOpaque(false);
217    
218 iliev 1285 GridBagLayout gridbag = new GridBagLayout();
219     GridBagConstraints c = new GridBagConstraints();
220 iliev 912
221 iliev 1285 p.setLayout(gridbag);
222 iliev 912
223 iliev 1285 c.fill = GridBagConstraints.BOTH;
224 iliev 912
225 iliev 1285 c.gridx = 1;
226     c.gridy = 0;
227     c.weightx = 1.0;
228     c.weighty = 1.0;
229 iliev 1729 c.insets = new Insets(0, 3, 0, 0);
230     gridbag.setConstraints(rightSidePane, c);
231     p.add(rightSidePane);
232 iliev 912
233 iliev 1285 c.gridx = 0;
234     c.gridy = 0;
235     c.weightx = 0.0;
236     c.weighty = 1.0;
237 iliev 1778 c.insets = new Insets(0, 0, 0, 3);
238 iliev 1285 c.fill = GridBagConstraints.VERTICAL;
239     gridbag.setConstraints(mainPane, c);
240     p.add(mainPane);
241 iliev 912
242 iliev 1285 return p;
243     }
244    
245     private void
246     setSavedSize() {
247 iliev 1786 Rectangle r = StdUtils.getWindowBounds("MainFrame");
248     if(r == null) {
249 iliev 1285 setDefaultSizeAndLocation();
250     return;
251     }
252    
253 iliev 1786 setBounds(r);
254 iliev 912 }
255    
256     private void
257 iliev 1285 setDefaultSizeAndLocation() {
258     setPreferredSize(new Dimension(900, 600));
259     pack();
260     setLocationRelativeTo(null);
261 iliev 912 }
262    
263    
264     /** Invoked when this window is about to close. */
265 iliev 1778 @Override
266 iliev 1864 public void
267 iliev 912 onWindowClose() {
268 iliev 1688 boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT);
269     if(b && CC.getSamplerModel().isModified()) {
270 iliev 1567 JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32);
271     dlg.setVisible(true);
272     if(dlg.isCancelled()) return;
273     }
274    
275 iliev 1729 leftSidePane.savePreferences();
276     rightSidePane.savePreferences();
277 iliev 912
278 iliev 1285 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 iliev 1786 StdUtils.saveWindowBounds("MainFrame", getBounds());
292 iliev 912
293 iliev 1308 String[] list = recentScripts.toArray(new String[recentScripts.size()]);
294     preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list);
295 iliev 1285
296     if(preferences().getBoolProperty(SAVE_LS_CONSOLE_HISTORY)) {
297     if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory();
298     }
299    
300 iliev 1786 if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer();
301     if(getLSConsolePane() != null) getLSConsolePane().disconnect();
302    
303 iliev 912 super.onWindowClose();
304     }
305    
306 iliev 1786 @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 iliev 1285 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 iliev 1688 mi = new JMenuItem(a4n.refresh);
329 iliev 1285 mi.setIcon(null);
330 iliev 1688 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
331 iliev 1285 m.add(mi);
332    
333     mi = new JMenuItem(a4n.samplerInfo);
334     mi.setIcon(null);
335     m.add(mi);
336    
337 iliev 1688 mi = new JMenuItem(a4n.resetSampler);
338     mi.setIcon(null);
339     m.add(mi);
340    
341 iliev 1285 m.addSeparator();
342    
343     JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export"));
344     m.add(exportMenu);
345 iliev 1864
346     int modKey = CC.getViewConfig().getDefaultModKey();
347 iliev 1285
348     mi = new JMenuItem(a4n.exportSamplerConfig);
349     mi.setIcon(null);
350 iliev 1864 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey));
351 iliev 1285 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 iliev 1864 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey));
362 iliev 1285 m.add(mi);
363    
364 iliev 1308 String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS);
365     for(String s : list) recentScripts.add(s);
366 iliev 1285
367     updateRecentScriptsMenu();
368    
369     m.add(recentScriptsMenu);
370    
371     m.addSeparator();
372    
373 iliev 1688 mi = new JMenuItem(a4n.changeBackend);
374     mi.setIcon(null);
375 iliev 1864 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey));
376 iliev 1688 m.add(mi);
377    
378     m.addSeparator();
379    
380 iliev 1285 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 iliev 1323 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 iliev 1285 mi = new JMenuItem(a4n.editPreferences);
416     mi.setIcon(null);
417     mi.setAccelerator(KeyStroke.getKeyStroke (
418 iliev 1864 KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK
419 iliev 1285 ));
420     m.add(mi);
421    
422 iliev 1323 // View
423     m = new FantasiaMenu(i18n.getMenuLabel("view"));
424     menuBar.add(m);
425 iliev 1285
426 iliev 1323 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 iliev 1729 cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
440 iliev 1864 KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK
441 iliev 1323 ));
442 iliev 1729 m.add(cbmiLeftSidePaneVisible);
443 iliev 1323
444 iliev 1729 cbmiLeftSidePaneVisible.addActionListener(new ActionListener() {
445 iliev 1323 public void
446     actionPerformed(ActionEvent e) {
447 iliev 1729 showSidePane(cbmiLeftSidePaneVisible.getState());
448 iliev 1323 }
449     });
450    
451 iliev 1729 b = preferences().getBoolProperty("leftSidePane.visible");
452     cbmiLeftSidePaneVisible.setSelected(b);
453 iliev 1323 showSidePane(b);
454    
455 iliev 1729 cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke (
456 iliev 1864 KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK
457 iliev 1323 ));
458 iliev 1729 m.add(cbmiRightSidePaneVisible);
459 iliev 1323
460 iliev 1729 cbmiRightSidePaneVisible.addActionListener(new ActionListener() {
461 iliev 1323 public void
462     actionPerformed(ActionEvent e) {
463 iliev 1729 showDevicesPane(cbmiRightSidePaneVisible.getState());
464 iliev 1323 }
465     });
466    
467 iliev 1729 b = preferences().getBoolProperty("rightSidePane.visible");
468     cbmiRightSidePaneVisible.setSelected(b);
469 iliev 1323 showDevicesPane(b);
470    
471 iliev 1776 m.addSeparator();
472 iliev 1323
473 iliev 1776 m.add(cbmiMidiKeyboardVisible);
474    
475     cbmiMidiKeyboardVisible.addActionListener(new ActionListener() {
476     public void
477     actionPerformed(ActionEvent e) {
478 iliev 1778 setMidiKeyboardVisible(cbmiMidiKeyboardVisible.getState());
479 iliev 1776 }
480     });
481    
482     b = preferences().getBoolProperty("midiKeyboard.visible");
483     cbmiMidiKeyboardVisible.setSelected(b);
484 iliev 1778 setMidiKeyboardVisible(b);
485 iliev 1776
486    
487 iliev 1818 // 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 iliev 1864 mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey));
520 iliev 1818 m.add(mi);
521    
522     mi = new JMenuItem(a4n.deselectChannels);
523     mi.setIcon(null);
524     mi.setAccelerator(KeyStroke.getKeyStroke (
525 iliev 1864 KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK
526 iliev 1818 ));
527     m.add(mi);
528    
529     menuBar.add(m);
530    
531 iliev 1285 // 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 iliev 1786 m.addSeparator();
544 iliev 1285
545 iliev 1786 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 iliev 1285 // Help
569     m = new FantasiaMenu(i18n.getMenuLabel("help"));
570    
571 iliev 1496 mi = new JMenuItem(a4n.browseOnlineTutorial);
572     mi.setIcon(null);
573     m.add(mi);
574    
575     m.addSeparator();
576    
577 iliev 1285 mi = new JMenuItem(a4n.helpAbout);
578     mi.setIcon(null);
579     m.add(mi);
580    
581     menuBar.add(m);
582 iliev 912 }
583    
584 iliev 1818 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 iliev 1767 public RightSidePane
607     getRightSidePane() { return rightSidePane; }
608    
609 iliev 1818 @Override
610     public A4n
611     getA4n() { return A4n.a4n; }
612    
613 iliev 912 /**
614 iliev 1785 * This method does nothing, because <b>Fantasia</b> has constant
615     * number of panes containing sampler channels, which can not be changed.
616 iliev 912 */
617 iliev 1778 @Override
618 iliev 912 public void
619     insertChannelsPane(JSChannelsPane pane, int idx) {
620 iliev 1285
621 iliev 912 }
622    
623 iliev 1778 @Override
624 iliev 912 public JSChannelsPane
625 iliev 1785 getSelectedChannelsPane() { return mainPane.getSelectedChannelsPane(); }
626 iliev 912
627 iliev 1778 @Override
628 iliev 912 public void
629 iliev 1785 setSelectedChannelsPane(JSChannelsPane pane) {
630     mainPane.setSelectedChannelsPane(pane);
631     fireChannelsPaneSelectionChanged();
632     }
633 iliev 912
634 iliev 1778 @Override
635 iliev 1285 public void
636     installJSamplerHome() {
637     JSamplerHomeChooser chooser = new JSamplerHomeChooser(this);
638     chooser.setVisible(true);
639     if(chooser.isCancelled()) return;
640 iliev 912
641 iliev 1285 CC.changeJSamplerHome(chooser.getJSamplerHome());
642 iliev 912 }
643    
644 iliev 1778 @Override
645 iliev 1143 public void
646 iliev 1204 showDetailedErrorMessage(Frame owner, String err, String details) {
647 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
648     owner, Res.iconWarning32, i18n.getError("error"), err, details
649     );
650     dlg.setVisible(true);
651 iliev 1204 }
652    
653 iliev 1778 @Override
654 iliev 1204 public void
655     showDetailedErrorMessage(Dialog owner, String err, String details) {
656 iliev 1355 JSDetailedErrorDlg dlg = new JSDetailedErrorDlg (
657     owner, Res.iconWarning32, i18n.getError("error"), err, details
658     );
659     dlg.setVisible(true);
660 iliev 1204 }
661 iliev 912
662 iliev 1688 /**
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 iliev 1778 @Override
667 iliev 1688 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 iliev 1778 @Override
679 iliev 1688 public Server
680     getServer(boolean manualSelect) {
681     if(manualSelect) {
682     JSConnectDlg dlg = new JSConnectDlg();
683     dlg.setVisible(true);
684 iliev 1786
685 iliev 1688 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 iliev 1734 public Timer
697     getGuiTimer() { return guiTimer; }
698    
699 iliev 1285 protected LSConsoleModel
700     getLSConsoleModel() { return getLSConsolePane().getModel(); }
701    
702     protected LSConsolePane
703     getLSConsolePane() {
704     return getLSConsoleFrame().getLSConsolePane();
705     }
706    
707     protected LSConsoleFrame
708 iliev 1311 getLSConsoleFrame() { return lsConsoleFrame; }
709 iliev 1285
710 iliev 1786 public JSBackendLogFrame
711     getBackendLogFrame() { return backendLogFrame; }
712    
713 iliev 1688 protected boolean
714 iliev 1285 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 iliev 1688 if(result != JFileChooser.APPROVE_OPTION) return false;
720 iliev 912
721 iliev 1285 String path = fc.getCurrentDirectory().getAbsolutePath();
722     preferences().setStringProperty("lastScriptLocation", path);
723    
724     runScript(fc.getSelectedFile());
725 iliev 1688
726     return true;
727 iliev 1285 }
728    
729 iliev 1786 @Override
730     public void
731 iliev 1285 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 iliev 912 }
741    
742 iliev 1818 String prefix = "#jsampler.fantasia: ";
743     Vector<String> v = new Vector<String>();
744 iliev 1285 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 iliev 1818 if(s.startsWith(prefix)) v.add(s.substring(prefix.length()));
752 iliev 1285 s = br.readLine();
753     }
754     } catch(Exception e) {
755     HF.showErrorMessage(e);
756     return;
757 iliev 912 }
758 iliev 1285
759     String s = script.getAbsolutePath();
760     recentScripts.remove(s);
761     recentScripts.insertElementAt(s, 0);
762    
763     updateRecentScriptsMenu();
764 iliev 1818
765     CC.getViewConfig().setSessionViewConfig(
766     new SessionViewConfig(v.toArray(new String[v.size()]))
767     );
768 iliev 1285 }
769 iliev 912
770 iliev 1285 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 iliev 1323 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 iliev 1729 preferences().setBoolProperty("leftSidePane.visible", b);
803 iliev 1323 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 iliev 1729 preferences().setBoolProperty("rightSidePane.visible", b);
835 iliev 1323
836 iliev 1729 int width = leftSidePane.getWidth();
837     int height = leftSidePane.getPreferredSize().height;
838     if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height));
839 iliev 1323
840     if(b) {
841     int w = preferences().getIntProperty("devicesPane.width", 200);
842    
843 iliev 1729 int h = rightSidePane.getPreferredSize().height;
844     rightSidePane.setPreferredSize(new Dimension(w, h));
845 iliev 1323 } else {
846 iliev 1729 int w = rightSidePane.getWidth();
847 iliev 1323 if(w > 0 && w < 200) w = 200;
848     if(w != 0) preferences().setIntProperty("devicesPane.width", w);
849     }
850    
851     hSplitPane.setResizeWeight(0.0);
852 iliev 1729 rightSidePane.setVisible(b);
853 iliev 1323 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 iliev 1778 public void
870     setMidiKeyboardVisible(boolean b) {
871 iliev 1776 preferences().setBoolProperty("midiKeyboard.visible", b);
872 iliev 1778 pianoKeyboardPane.setVisible(b);
873    
874     if(cbmiMidiKeyboardVisible.isSelected() != b) {
875     cbmiMidiKeyboardVisible.setSelected(b);
876 iliev 1776 }
877    
878 iliev 1778 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 iliev 1776 }
889    
890 iliev 1778 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 iliev 1776 private void
901 iliev 1323 sidePanesVisibilityChanged() {
902 iliev 1729 boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected();
903     boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected();
904 iliev 1323
905 iliev 1729 if(leftSidePaneVisible && rightSidePaneVisible) {
906 iliev 1323 hSplitPane.setResizeWeight(0.5);
907 iliev 1729 } else if(leftSidePaneVisible && !rightSidePaneVisible) {
908 iliev 1323 hSplitPane.setResizeWeight(1.0);
909     }
910    
911 iliev 1729 if(!leftSidePaneVisible && !rightSidePaneVisible) {
912 iliev 1323 standardBar.showFantasiaLogo(false);
913     if(isResizable()) setResizable(false);
914     } else {
915     standardBar.showFantasiaLogo(true);
916     if(!isResizable()) setResizable(true);
917     }
918     }
919    
920 iliev 1285 private class RecentScriptHandler implements ActionListener {
921     private String script;
922    
923     RecentScriptHandler(String script) { this.script = script; }
924    
925 iliev 1778 @Override
926 iliev 912 public void
927 iliev 1285 actionPerformed(ActionEvent e) {
928     runScript(script);
929     if(preferences().getBoolProperty(SHOW_LS_CONSOLE_WHEN_RUN_SCRIPT)) {
930     a4n.windowLSConsole.actionPerformed(null);
931     }
932 iliev 912 }
933 iliev 1285 }
934 iliev 912
935 iliev 1285 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 iliev 1776 setContentAreaFilled(false);
941 iliev 912 }
942     }
943 iliev 1285
944 iliev 1323 private class FantasiaMenuBar extends JMenuBar {
945 iliev 1285 FantasiaMenuBar() {
946     setOpaque(false);
947 iliev 1778 setBorder(BorderFactory.createEmptyBorder(2, 6, 0, 0));
948 iliev 1285 }
949    
950 iliev 1778 @Override
951 iliev 1285 protected void
952     paintComponent(Graphics g) {
953 iliev 1778 //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 iliev 1323 if(standardBar.isVisible()) {
968 iliev 1778 b = new FantasiaPainter.Border(true, true, false, true);
969     FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h + 1, b);
970 iliev 1323 } else {
971 iliev 1778 b = new FantasiaPainter.Border(true, true, true, true);
972     FantasiaPainter.paintBoldOuterBorder(g2, 0, 0, w - 1, h - 1, b);
973 iliev 1323 }
974 iliev 1778
975     g2.setPaint(oldPaint);
976     g2.setComposite(oldComposite);
977 iliev 1285 }
978     }
979 iliev 1778
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 iliev 912 }

  ViewVC Help
Powered by ViewVC