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 |
* |
* |
34 |
import java.awt.GridBagLayout; |
import java.awt.GridBagLayout; |
35 |
import java.awt.Insets; |
import java.awt.Insets; |
36 |
import java.awt.Paint; |
import java.awt.Paint; |
37 |
|
import java.awt.Rectangle; |
38 |
|
|
39 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
40 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
49 |
import java.io.FileReader; |
import java.io.FileReader; |
50 |
|
|
51 |
import java.util.Vector; |
import java.util.Vector; |
|
import java.util.logging.Level; |
|
52 |
|
|
53 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
54 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
63 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
64 |
import javax.swing.Timer; |
import javax.swing.Timer; |
65 |
|
|
66 |
|
import javax.swing.event.ListSelectionEvent; |
67 |
|
import javax.swing.event.ListSelectionListener; |
68 |
|
|
69 |
import org.jsampler.CC; |
import org.jsampler.CC; |
70 |
import org.jsampler.HF; |
import org.jsampler.HF; |
71 |
import org.jsampler.LSConsoleModel; |
import org.jsampler.LSConsoleModel; |
72 |
import org.jsampler.Server; |
import org.jsampler.Server; |
73 |
|
|
74 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
|
import org.jsampler.view.JSMainFrame; |
|
75 |
import org.jsampler.view.LscpFileFilter; |
import org.jsampler.view.LscpFileFilter; |
76 |
|
import org.jsampler.view.SessionViewConfig; |
77 |
|
|
78 |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
import org.jsampler.view.fantasia.basic.FantasiaPainter; |
79 |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
import org.jsampler.view.fantasia.basic.FantasiaPanel; |
80 |
import org.jsampler.view.fantasia.basic.FantasiaSubPanel; |
import org.jsampler.view.fantasia.basic.FantasiaSubPanel; |
81 |
|
|
82 |
|
import org.jsampler.view.std.JSBackendLogFrame; |
83 |
import org.jsampler.view.std.JSConnectDlg; |
import org.jsampler.view.std.JSConnectDlg; |
84 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
import org.jsampler.view.std.JSDetailedErrorDlg; |
85 |
import org.jsampler.view.std.JSQuitDlg; |
import org.jsampler.view.std.JSQuitDlg; |
86 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
87 |
|
import org.jsampler.view.std.StdMainFrame; |
88 |
|
import org.jsampler.view.std.StdUtils; |
89 |
|
|
90 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
91 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
97 |
* |
* |
98 |
* @author Grigor Iliev |
* @author Grigor Iliev |
99 |
*/ |
*/ |
100 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends StdMainFrame { |
101 |
private final StandardBar standardBar = new StandardBar(); |
private final StandardBar standardBar = new StandardBar(); |
102 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
103 |
private final JPanel rootPane = new RootPane(); |
private final JPanel rootPane = new RootPane(); |
118 |
|
|
119 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
120 |
private final Vector<String> recentScripts = new Vector<String>(); |
private final Vector<String> recentScripts = new Vector<String>(); |
121 |
|
|
122 |
|
private final JSBackendLogFrame backendLogFrame = new JSBackendLogFrame(); |
123 |
|
|
124 |
|
|
125 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
233 |
|
|
234 |
private void |
private void |
235 |
setSavedSize() { |
setSavedSize() { |
236 |
String s = preferences().getStringProperty("MainFrame.sizeAndLocation"); |
Rectangle r = StdUtils.getWindowBounds("MainFrame"); |
237 |
if(s == null) { |
if(r == null) { |
238 |
setDefaultSizeAndLocation(); |
setDefaultSizeAndLocation(); |
239 |
return; |
return; |
240 |
} |
} |
|
pack(); |
|
|
try { |
|
|
int i = s.indexOf(','); |
|
|
int x = Integer.parseInt(s.substring(0, i)); |
|
|
|
|
|
s = s.substring(i + 1); |
|
|
i = s.indexOf(','); |
|
|
int y = Integer.parseInt(s.substring(0, i)); |
|
|
|
|
|
s = s.substring(i + 1); |
|
|
i = s.indexOf(','); |
|
|
int width = Integer.parseInt(s.substring(0, i)); |
|
|
|
|
|
s = s.substring(i + 1); |
|
|
int height = Integer.parseInt(s); |
|
|
|
|
|
setBounds(x, y, width, height); |
|
|
} catch(Exception x) { |
|
|
String msg = "Parsing of window size and location string failed"; |
|
|
CC.getLogger().log(Level.INFO, msg, x); |
|
|
setDefaultSizeAndLocation(); |
|
|
} |
|
241 |
|
|
242 |
if(preferences().getBoolProperty("MainFrame.windowMaximized")) { |
setBounds(r); |
|
setExtendedState(getExtendedState() | MAXIMIZED_BOTH); |
|
|
} |
|
243 |
} |
} |
244 |
|
|
245 |
private void |
private void |
252 |
|
|
253 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
254 |
@Override |
@Override |
255 |
protected void |
public void |
256 |
onWindowClose() { |
onWindowClose() { |
257 |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
258 |
if(b && CC.getSamplerModel().isModified()) { |
if(b && CC.getSamplerModel().isModified()) { |
277 |
return; |
return; |
278 |
} |
} |
279 |
|
|
280 |
java.awt.Point p = getLocation(); |
StdUtils.saveWindowBounds("MainFrame", getBounds()); |
|
Dimension d = getSize(); |
|
|
StringBuffer sb = new StringBuffer(); |
|
|
sb.append(p.x).append(',').append(p.y).append(','); |
|
|
sb.append(d.width).append(',').append(d.height); |
|
|
preferences().setStringProperty("MainFrame.sizeAndLocation", sb.toString()); |
|
281 |
|
|
282 |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
String[] list = recentScripts.toArray(new String[recentScripts.size()]); |
283 |
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
preferences().setStringListProperty(RECENT_LSCP_SCRIPTS, list); |
286 |
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
if(lsConsoleFrame != null) getLSConsolePane().saveConsoleHistory(); |
287 |
} |
} |
288 |
|
|
289 |
|
if(getBackendLogFrame() != null) getBackendLogFrame().stopTimer(); |
290 |
|
if(getLSConsolePane() != null) getLSConsolePane().disconnect(); |
291 |
|
|
292 |
super.onWindowClose(); |
super.onWindowClose(); |
293 |
} |
} |
294 |
|
|
295 |
|
@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 |
private void |
private void |
308 |
addMenu() { |
addMenu() { |
309 |
|
if(CC.isMacOS()) { |
310 |
|
try { new MacOSApplicationHandler(); } |
311 |
|
catch(Throwable e) { } |
312 |
|
} |
313 |
|
|
314 |
|
if(CC.getViewConfig().isUsingScreenMenuBar()) { |
315 |
|
((ViewConfig)CC.getViewConfig()).setNativeMenuProperties(); |
316 |
|
} |
317 |
|
|
318 |
JMenu m; |
JMenu m; |
319 |
JMenuItem mi; |
JMenuItem mi; |
320 |
|
|
340 |
|
|
341 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
342 |
m.add(exportMenu); |
m.add(exportMenu); |
343 |
|
|
344 |
|
int modKey = CC.getViewConfig().getDefaultModKey(); |
345 |
|
|
346 |
mi = new JMenuItem(a4n.exportSamplerConfig); |
mi = new JMenuItem(a4n.exportSamplerConfig); |
347 |
mi.setIcon(null); |
mi.setIcon(null); |
348 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, modKey)); |
349 |
exportMenu.add(mi); |
exportMenu.add(mi); |
350 |
|
|
351 |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
mi = new JMenuItem(a4n.exportMidiInstrumentMaps); |
356 |
|
|
357 |
mi = new JMenuItem(a4n.loadScript); |
mi = new JMenuItem(a4n.loadScript); |
358 |
mi.setIcon(null); |
mi.setIcon(null); |
359 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, modKey)); |
360 |
m.add(mi); |
m.add(mi); |
361 |
|
|
362 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
370 |
|
|
371 |
mi = new JMenuItem(a4n.changeBackend); |
mi = new JMenuItem(a4n.changeBackend); |
372 |
mi.setIcon(null); |
mi.setIcon(null); |
373 |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, modKey)); |
374 |
m.add(mi); |
m.add(mi); |
375 |
|
|
376 |
m.addSeparator(); |
m.addSeparator(); |
413 |
mi = new JMenuItem(a4n.editPreferences); |
mi = new JMenuItem(a4n.editPreferences); |
414 |
mi.setIcon(null); |
mi.setIcon(null); |
415 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
416 |
KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_P, modKey | KeyEvent.SHIFT_MASK |
417 |
)); |
)); |
418 |
m.add(mi); |
m.add(mi); |
419 |
|
|
435 |
showToolBar(b); |
showToolBar(b); |
436 |
|
|
437 |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
438 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_L, modKey | KeyEvent.SHIFT_MASK |
439 |
)); |
)); |
440 |
m.add(cbmiLeftSidePaneVisible); |
m.add(cbmiLeftSidePaneVisible); |
441 |
|
|
451 |
showSidePane(b); |
showSidePane(b); |
452 |
|
|
453 |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
454 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_R, modKey | KeyEvent.SHIFT_MASK |
455 |
)); |
)); |
456 |
m.add(cbmiRightSidePaneVisible); |
m.add(cbmiRightSidePaneVisible); |
457 |
|
|
482 |
setMidiKeyboardVisible(b); |
setMidiKeyboardVisible(b); |
483 |
|
|
484 |
|
|
485 |
|
// Channels |
486 |
|
m = new FantasiaMenu(i18n.getMenuLabel("channels")); |
487 |
|
|
488 |
|
mi = new JMenuItem(i18n.getMenuLabel("channels.newChannel")); |
489 |
|
mi.addActionListener(new ActionListener() { |
490 |
|
public void |
491 |
|
actionPerformed(ActionEvent e) { |
492 |
|
CC.getSamplerModel().addBackendChannel(); |
493 |
|
} |
494 |
|
}); |
495 |
|
m.add(mi); |
496 |
|
|
497 |
|
m.addSeparator(); |
498 |
|
|
499 |
|
MenuManager.ChannelViewGroup group = new MenuManager.ChannelViewGroup(); |
500 |
|
MenuManager.getMenuManager().registerChannelViewGroup(group); |
501 |
|
|
502 |
|
for(JMenuItem menuItem : group.getMenuItems()) m.add(menuItem); |
503 |
|
|
504 |
|
m.addSeparator(); |
505 |
|
|
506 |
|
m.add(new JMenuItem(a4n.moveChannelsOnTop)); |
507 |
|
m.add(new JMenuItem(a4n.moveChannelsUp)); |
508 |
|
m.add(new JMenuItem(a4n.moveChannelsDown)); |
509 |
|
m.add(new JMenuItem(a4n.moveChannelsAtBottom)); |
510 |
|
|
511 |
|
m.add(new ToPanelMenu()); |
512 |
|
|
513 |
|
m.addSeparator(); |
514 |
|
|
515 |
|
mi = new JMenuItem(a4n.selectAllChannels); |
516 |
|
mi.setIcon(null); |
517 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, modKey)); |
518 |
|
m.add(mi); |
519 |
|
|
520 |
|
mi = new JMenuItem(a4n.deselectChannels); |
521 |
|
mi.setIcon(null); |
522 |
|
mi.setAccelerator(KeyStroke.getKeyStroke ( |
523 |
|
KeyEvent.VK_A, modKey | KeyEvent.SHIFT_MASK |
524 |
|
)); |
525 |
|
m.add(mi); |
526 |
|
|
527 |
|
menuBar.add(m); |
528 |
|
|
529 |
// Window |
// Window |
530 |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
531 |
menuBar.add(m); |
menuBar.add(m); |
538 |
mi.setIcon(null); |
mi.setIcon(null); |
539 |
m.add(mi); |
m.add(mi); |
540 |
|
|
541 |
|
m.addSeparator(); |
542 |
|
|
543 |
|
final JMenuItem mi2 = new JMenuItem(i18n.getMenuLabel("window.backendLog")); |
544 |
|
m.add(mi2); |
545 |
|
mi2.addActionListener(new ActionListener() { |
546 |
|
public void |
547 |
|
actionPerformed(ActionEvent e) { |
548 |
|
if(getBackendLogFrame().isVisible()) { |
549 |
|
getBackendLogFrame().setVisible(false); |
550 |
|
} |
551 |
|
|
552 |
|
getBackendLogFrame().setVisible(true); |
553 |
|
} |
554 |
|
}); |
555 |
|
|
556 |
|
mi2.setEnabled(CC.getBackendProcess() != null); |
557 |
|
|
558 |
|
CC.addBackendProcessListener(new ActionListener() { |
559 |
|
public void |
560 |
|
actionPerformed(ActionEvent e) { |
561 |
|
mi2.setEnabled(CC.getBackendProcess() != null); |
562 |
|
} |
563 |
|
}); |
564 |
|
|
565 |
|
|
566 |
// Help |
// Help |
567 |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
577 |
m.add(mi); |
m.add(mi); |
578 |
|
|
579 |
menuBar.add(m); |
menuBar.add(m); |
580 |
|
|
581 |
|
if(CC.getViewConfig().isUsingScreenMenuBar()) { |
582 |
|
((ViewConfig)CC.getViewConfig()).restoreMenuProperties(); |
583 |
|
} |
584 |
|
} |
585 |
|
|
586 |
|
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 |
public RightSidePane |
public RightSidePane |
609 |
getRightSidePane() { return rightSidePane; } |
getRightSidePane() { return rightSidePane; } |
610 |
|
|
611 |
|
@Override |
612 |
|
public A4n |
613 |
|
getA4n() { return A4n.a4n; } |
614 |
|
|
615 |
/** |
/** |
616 |
* This method does nothing, because <b>Fantasia</b> has constant |
* This method does nothing, because <b>Fantasia</b> has constant |
617 |
* number of panes containing sampler channels, which can not be changed. |
* number of panes containing sampler channels, which can not be changed. |
683 |
if(manualSelect) { |
if(manualSelect) { |
684 |
JSConnectDlg dlg = new JSConnectDlg(); |
JSConnectDlg dlg = new JSConnectDlg(); |
685 |
dlg.setVisible(true); |
dlg.setVisible(true); |
686 |
|
|
687 |
return dlg.getSelectedServer(); |
return dlg.getSelectedServer(); |
688 |
} |
} |
689 |
|
|
709 |
protected LSConsoleFrame |
protected LSConsoleFrame |
710 |
getLSConsoleFrame() { return lsConsoleFrame; } |
getLSConsoleFrame() { return lsConsoleFrame; } |
711 |
|
|
712 |
|
public JSBackendLogFrame |
713 |
|
getBackendLogFrame() { return backendLogFrame; } |
714 |
|
|
715 |
protected boolean |
protected boolean |
716 |
runScript() { |
runScript() { |
717 |
String s = preferences().getStringProperty("lastScriptLocation"); |
String s = preferences().getStringProperty("lastScriptLocation"); |
728 |
return true; |
return true; |
729 |
} |
} |
730 |
|
|
731 |
private void |
@Override |
732 |
|
public void |
733 |
runScript(String script) { runScript(new File(script)); } |
runScript(String script) { runScript(new File(script)); } |
734 |
|
|
735 |
private void |
private void |
741 |
return; |
return; |
742 |
} |
} |
743 |
|
|
744 |
|
String prefix = "#jsampler.fantasia: "; |
745 |
|
Vector<String> v = new Vector<String>(); |
746 |
BufferedReader br = new BufferedReader(fr); |
BufferedReader br = new BufferedReader(fr); |
747 |
|
|
748 |
try { |
try { |
750 |
while(s != null) { |
while(s != null) { |
751 |
getLSConsoleModel().setCommandLineText(s); |
getLSConsoleModel().setCommandLineText(s); |
752 |
getLSConsoleModel().execCommand(); |
getLSConsoleModel().execCommand(); |
753 |
|
if(s.startsWith(prefix)) v.add(s.substring(prefix.length())); |
754 |
s = br.readLine(); |
s = br.readLine(); |
755 |
} |
} |
756 |
} catch(Exception e) { |
} catch(Exception e) { |
763 |
recentScripts.insertElementAt(s, 0); |
recentScripts.insertElementAt(s, 0); |
764 |
|
|
765 |
updateRecentScriptsMenu(); |
updateRecentScriptsMenu(); |
766 |
|
|
767 |
|
CC.getViewConfig().setSessionViewConfig( |
768 |
|
new SessionViewConfig(v.toArray(new String[v.size()])) |
769 |
|
); |
770 |
} |
} |
771 |
|
|
772 |
protected void |
protected void |