1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
53 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
54 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
55 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
|
import javax.swing.JFileChooser; |
|
56 |
import javax.swing.JMenu; |
import javax.swing.JMenu; |
57 |
import javax.swing.JMenuBar; |
import javax.swing.JMenuBar; |
58 |
import javax.swing.JMenuItem; |
import javax.swing.JMenuItem; |
62 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
63 |
import javax.swing.Timer; |
import javax.swing.Timer; |
64 |
|
|
65 |
|
import javax.swing.event.ListSelectionEvent; |
66 |
|
import javax.swing.event.ListSelectionListener; |
67 |
|
|
68 |
import org.jsampler.CC; |
import org.jsampler.CC; |
69 |
import org.jsampler.HF; |
import org.jsampler.HF; |
70 |
import org.jsampler.LSConsoleModel; |
import org.jsampler.LSConsoleModel; |
71 |
import org.jsampler.Server; |
import org.jsampler.Server; |
72 |
|
|
73 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
74 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.SessionViewConfig; |
|
import org.jsampler.view.LscpFileFilter; |
|
75 |
|
|
76 |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
77 |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
82 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
import org.jsampler.view.std.JSDetailedErrorDlg; |
83 |
import org.jsampler.view.std.JSQuitDlg; |
import org.jsampler.view.std.JSQuitDlg; |
84 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
85 |
|
import org.jsampler.view.std.StdMainFrame; |
86 |
import org.jsampler.view.std.StdUtils; |
import org.jsampler.view.std.StdUtils; |
87 |
|
|
88 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
95 |
* |
* |
96 |
* @author Grigor Iliev |
* @author Grigor Iliev |
97 |
*/ |
*/ |
98 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends StdMainFrame { |
99 |
private final StandardBar standardBar = new StandardBar(); |
private final StandardBar standardBar = new StandardBar(); |
100 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
101 |
private final JPanel rootPane = new RootPane(); |
private final JPanel rootPane = new RootPane(); |
186 |
rootPane.add(hSplitPane); |
rootPane.add(hSplitPane); |
187 |
rootPane.add(bottomPane, BorderLayout.SOUTH); |
rootPane.add(bottomPane, BorderLayout.SOUTH); |
188 |
add(rootPane); |
add(rootPane); |
189 |
|
|
190 |
|
if(CC.isMacOS()) { |
191 |
|
try { |
192 |
|
String s = "org.jsampler.view.fantasia.MacOSApplicationHandler"; |
193 |
|
Class.forName(s).newInstance(); } |
194 |
|
catch(Throwable e) { } |
195 |
|
} |
196 |
|
|
197 |
addMenu(); |
addMenu(); |
198 |
|
|
199 |
|
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 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
206 |
hSplitPane.setDividerLocation(i); |
hSplitPane.setDividerLocation(i); |
207 |
|
|
263 |
|
|
264 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
265 |
@Override |
@Override |
266 |
protected void |
public void |
267 |
onWindowClose() { |
onWindowClose() { |
268 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
269 |
if(b && CC.getSamplerModel().isModified()) { |
if(b && CC.getSamplerModel().isModified()) { |
342 |
|
|
343 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
344 |
m.add(exportMenu); |
m.add(exportMenu); |
345 |
|
|
346 |
|
int modKey = CC.getViewConfig().getDefaultModKey(); |
347 |
|
|
348 |
mi = new JMenuItem(a4n.exportSamplerConfig); |
mi = new JMenuItem(a4n.exportSamplerConfig); |
349 |
mi.setIcon(null); |
mi.setIcon(null); |
350 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey)); |
351 |
exportMenu.add(mi); |
exportMenu.add(mi); |
352 |
|
|
353 |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
358 |
|
|
359 |
mi = new JMenuItem(a4n.loadScript); |
mi = new JMenuItem(a4n.loadScript); |
360 |
mi.setIcon(null); |
mi.setIcon(null); |
361 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey)); |
362 |
m.add(mi); |
m.add(mi); |
363 |
|
|
364 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
372 |
|
|
373 |
mi = new JMenuItem(a4n.changeBackend); |
mi = new JMenuItem(a4n.changeBackend); |
374 |
mi.setIcon(null); |
mi.setIcon(null); |
375 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey)); |
376 |
m.add(mi); |
m.add(mi); |
377 |
|
|
378 |
m.addSeparator(); |
m.addSeparator(); |
415 |
mi = new JMenuItem(a4n.editPreferences); |
mi = new JMenuItem(a4n.editPreferences); |
416 |
mi.setIcon(null); |
mi.setIcon(null); |
417 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
418 |
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK |
419 |
)); |
)); |
420 |
m.add(mi); |
m.add(mi); |
421 |
|
|
437 |
showToolBar(b); |
showToolBar(b); |
438 |
|
|
439 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
440 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK |
441 |
)); |
)); |
442 |
m.add(cbmiLeftSidePaneVisible); |
m.add(cbmiLeftSidePaneVisible); |
443 |
|
|
453 |
showSidePane(b); |
showSidePane(b); |
454 |
|
|
455 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
456 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK |
457 |
)); |
)); |
458 |
m.add(cbmiRightSidePaneVisible); |
m.add(cbmiRightSidePaneVisible); |
459 |
|
|
484 |
setMidiKeyboardVisible(b); |
setMidiKeyboardVisible(b); |
485 |
|
|
486 |
|
|
487 |
|
// 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 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey)); |
520 |
|
m.add(mi); |
521 |
|
|
522 |
|
mi = new JMenuItem(a4n.deselectChannels); |
523 |
|
mi.setIcon(null); |
524 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
525 |
|
KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK |
526 |
|
)); |
527 |
|
m.add(mi); |
528 |
|
|
529 |
|
menuBar.add(m); |
530 |
|
|
531 |
// Window |
// Window |
532 |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
533 |
menuBar.add(m); |
menuBar.add(m); |
581 |
menuBar.add(m); |
menuBar.add(m); |
582 |
} |
} |
583 |
|
|
584 |
|
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 |
public RightSidePane |
public RightSidePane |
607 |
getRightSidePane() { return rightSidePane; } |
getRightSidePane() { return rightSidePane; } |
608 |
|
|
609 |
|
@Override |
610 |
|
public A4n |
611 |
|
getA4n() { return A4n.a4n; } |
612 |
|
|
613 |
/** |
/** |
614 |
* This method does nothing, because <b>Fantasia</b> has constant |
* This method does nothing, because <b>Fantasia</b> has constant |
615 |
* number of panes containing sampler channels, which can not be changed. |
* number of panes containing sampler channels, which can not be changed. |
712 |
|
|
713 |
protected boolean |
protected boolean |
714 |
runScript() { |
runScript() { |
715 |
String s = preferences().getStringProperty("lastScriptLocation"); |
File f = StdUtils.showOpenLscpFileChooser(); |
716 |
JFileChooser fc = new JFileChooser(s); |
if(f == null) return false; |
717 |
fc.setFileFilter(new LscpFileFilter()); |
runScript(f); |
|
int result = fc.showOpenDialog(this); |
|
|
if(result != JFileChooser.APPROVE_OPTION) return false; |
|
|
|
|
|
String path = fc.getCurrentDirectory().getAbsolutePath(); |
|
|
preferences().setStringProperty("lastScriptLocation", path); |
|
|
|
|
|
runScript(fc.getSelectedFile()); |
|
718 |
|
|
719 |
return true; |
return true; |
720 |
} |
} |
728 |
FileReader fr; |
FileReader fr; |
729 |
try { fr = new FileReader(script); } |
try { fr = new FileReader(script); } |
730 |
catch(FileNotFoundException e) { |
catch(FileNotFoundException e) { |
731 |
HF.showErrorMessage(i18n.getMessage("FileNotFound!")); |
HF.showErrorMessage(i18n.getError("fileNotFound!")); |
732 |
return; |
return; |
733 |
} |
} |
734 |
|
|
735 |
|
String prefix = "#jsampler.fantasia: "; |
736 |
|
Vector<String> v = new Vector<String>(); |
737 |
BufferedReader br = new BufferedReader(fr); |
BufferedReader br = new BufferedReader(fr); |
738 |
|
|
739 |
try { |
try { |
741 |
while(s != null) { |
while(s != null) { |
742 |
getLSConsoleModel().setCommandLineText(s); |
getLSConsoleModel().setCommandLineText(s); |
743 |
getLSConsoleModel().execCommand(); |
getLSConsoleModel().execCommand(); |
744 |
|
if(s.startsWith(prefix)) v.add(s.substring(prefix.length())); |
745 |
s = br.readLine(); |
s = br.readLine(); |
746 |
} |
} |
747 |
} catch(Exception e) { |
} catch(Exception e) { |
754 |
recentScripts.insertElementAt(s, 0); |
recentScripts.insertElementAt(s, 0); |
755 |
|
|
756 |
updateRecentScriptsMenu(); |
updateRecentScriptsMenu(); |
757 |
|
|
758 |
|
CC.getViewConfig().setSessionViewConfig( |
759 |
|
new SessionViewConfig(v.toArray(new String[v.size()])) |
760 |
|
); |
761 |
} |
} |
762 |
|
|
763 |
protected void |
protected void |