/[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 1818 - (hide annotations) (download)
Wed Dec 24 17:29:47 2008 UTC (15 years, 4 months ago) by iliev
File size: 26295 byte(s)
* Added support for controlling the global sampler-wide limit of
  maximum voices and disk streams
  (choose Edit/Preferences, then click the `General' tab)
* Fantasia: store the view configuration of audio/MIDI devices and sampler
  channels in the LSCP script when exporting sampler configuration
* Fantasia: Implemented multiple sampler channels' selection
* Fantasia: Added option to move sampler channels up and down
  in the channels list
* Fantasia: Added option to move sampler channels
  to another channels panels

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

  ViewVC Help
Powered by ViewVC