/[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 1866 - (hide annotations) (download)
Sun Mar 15 19:40:29 2009 UTC (15 years, 1 month ago) by iliev
File size: 26652 byte(s)
* show controller names in fx sends dialogs
* save send levels when exporting sampler configuration
* ask when removing nonempty map
* fixed compilation error

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

  ViewVC Help
Powered by ViewVC