1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2008 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
64 |
import javax.swing.JToggleButton; |
import javax.swing.JToggleButton; |
65 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
66 |
import javax.swing.SwingUtilities; |
import javax.swing.SwingUtilities; |
67 |
|
import javax.swing.Timer; |
68 |
import javax.swing.UIManager; |
import javax.swing.UIManager; |
69 |
|
|
70 |
import net.sf.juife.TitleBar; |
import net.sf.juife.TitleBar; |
72 |
import org.jsampler.CC; |
import org.jsampler.CC; |
73 |
import org.jsampler.HF; |
import org.jsampler.HF; |
74 |
import org.jsampler.LSConsoleModel; |
import org.jsampler.LSConsoleModel; |
75 |
|
import org.jsampler.Server; |
76 |
|
|
77 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
78 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
79 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
80 |
import org.jsampler.view.LscpFileFilter; |
import org.jsampler.view.LscpFileFilter; |
81 |
|
|
82 |
|
import org.jsampler.view.std.JSConnectDlg; |
83 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
import org.jsampler.view.std.JSDetailedErrorDlg; |
84 |
|
import org.jsampler.view.std.JSQuitDlg; |
85 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
86 |
|
|
87 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
99 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
100 |
private final JPanel rootPane = new JPanel(); |
private final JPanel rootPane = new JPanel(); |
101 |
private final MainPane mainPane = new MainPane(); |
private final MainPane mainPane = new MainPane(); |
|
private final DevicesPane devicesPane = new DevicesPane(); |
|
|
private final JScrollPane spDevicesPane = new JScrollPane(); |
|
102 |
|
|
103 |
private final JMenu recentScriptsMenu = |
private final JMenu recentScriptsMenu = |
104 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
105 |
|
|
106 |
private final JSplitPane hSplitPane; |
private final JSplitPane hSplitPane; |
107 |
|
|
108 |
private final SidePane sidePane = new SidePane(); |
private final LeftSidePane leftSidePane = new LeftSidePane(); |
109 |
|
private final RightSidePane rightSidePane = new RightSidePane(); |
110 |
private final JPanel rightPane; |
private final JPanel rightPane; |
111 |
|
|
112 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
116 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
117 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
118 |
|
|
119 |
private final JCheckBoxMenuItem cbmiSidePaneVisible = |
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
120 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
121 |
|
|
122 |
private final JCheckBoxMenuItem cbmiDevicesPaneVisible = |
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
123 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
124 |
|
|
125 |
|
private final Timer guiTimer = new Timer(1000, null); |
126 |
|
|
127 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
128 |
public |
public |
138 |
hSplitPane = new JSplitPane ( |
hSplitPane = new JSplitPane ( |
139 |
JSplitPane.HORIZONTAL_SPLIT, |
JSplitPane.HORIZONTAL_SPLIT, |
140 |
true, // continuousLayout |
true, // continuousLayout |
141 |
sidePane, rightPane |
leftSidePane, rightPane |
142 |
); |
); |
143 |
hSplitPane.setResizeWeight(0.5); |
hSplitPane.setResizeWeight(0.5); |
144 |
|
|
157 |
hSplitPane.setDividerLocation(i); |
hSplitPane.setDividerLocation(i); |
158 |
|
|
159 |
setSavedSize(); |
setSavedSize(); |
160 |
|
|
161 |
|
guiTimer.start(); |
162 |
} |
} |
163 |
|
|
164 |
private JPanel |
private JPanel |
171 |
|
|
172 |
c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
173 |
|
|
|
spDevicesPane.setViewportView(devicesPane); |
|
|
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
|
|
int h = spDevicesPane.getMinimumSize().height; |
|
|
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
|
|
|
|
174 |
c.gridx = 1; |
c.gridx = 1; |
175 |
c.gridy = 0; |
c.gridy = 0; |
176 |
c.weightx = 1.0; |
c.weightx = 1.0; |
177 |
c.weighty = 1.0; |
c.weighty = 1.0; |
178 |
c.insets = new Insets(0, 3, 3, 0); |
c.insets = new Insets(0, 3, 0, 0); |
179 |
gridbag.setConstraints(spDevicesPane, c); |
gridbag.setConstraints(rightSidePane, c); |
180 |
p.add(spDevicesPane); |
p.add(rightSidePane); |
181 |
|
|
182 |
c.gridx = 0; |
c.gridx = 0; |
183 |
c.gridy = 0; |
c.gridy = 0; |
184 |
c.weightx = 0.0; |
c.weightx = 0.0; |
185 |
c.weighty = 1.0; |
c.weighty = 1.0; |
186 |
c.insets = new Insets(0, 3, 3, 3); |
c.insets = new Insets(0, 3, 0, 3); |
187 |
c.fill = GridBagConstraints.VERTICAL; |
c.fill = GridBagConstraints.VERTICAL; |
188 |
gridbag.setConstraints(mainPane, c); |
gridbag.setConstraints(mainPane, c); |
189 |
p.add(mainPane); |
p.add(mainPane); |
237 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
238 |
protected void |
protected void |
239 |
onWindowClose() { |
onWindowClose() { |
240 |
sidePane.savePreferences(); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
241 |
|
if(b && CC.getSamplerModel().isModified()) { |
242 |
|
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
243 |
|
dlg.setVisible(true); |
244 |
|
if(dlg.isCancelled()) return; |
245 |
|
} |
246 |
|
|
247 |
|
leftSidePane.savePreferences(); |
248 |
|
rightSidePane.savePreferences(); |
249 |
|
|
250 |
int i = hSplitPane.getDividerLocation(); |
int i = hSplitPane.getDividerLocation(); |
251 |
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
287 |
// Actions |
// Actions |
288 |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
289 |
|
|
290 |
mi = new JMenuItem(a4n.connect); |
mi = new JMenuItem(a4n.refresh); |
291 |
mi.setIcon(null); |
mi.setIcon(null); |
292 |
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
293 |
m.add(mi); |
m.add(mi); |
294 |
|
|
295 |
mi = new JMenuItem(a4n.samplerInfo); |
mi = new JMenuItem(a4n.samplerInfo); |
296 |
mi.setIcon(null); |
mi.setIcon(null); |
297 |
m.add(mi); |
m.add(mi); |
298 |
|
|
299 |
|
mi = new JMenuItem(a4n.resetSampler); |
300 |
|
mi.setIcon(null); |
301 |
|
m.add(mi); |
302 |
|
|
303 |
m.addSeparator(); |
m.addSeparator(); |
304 |
|
|
305 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
318 |
|
|
319 |
mi = new JMenuItem(a4n.loadScript); |
mi = new JMenuItem(a4n.loadScript); |
320 |
mi.setIcon(null); |
mi.setIcon(null); |
321 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
322 |
m.add(mi); |
m.add(mi); |
323 |
|
|
324 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
330 |
|
|
331 |
m.addSeparator(); |
m.addSeparator(); |
332 |
|
|
333 |
|
mi = new JMenuItem(a4n.changeBackend); |
334 |
|
mi.setIcon(null); |
335 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
336 |
|
m.add(mi); |
337 |
|
|
338 |
|
m.addSeparator(); |
339 |
|
|
340 |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
341 |
m.add(mi); |
m.add(mi); |
342 |
mi.addActionListener(new ActionListener() { |
mi.addActionListener(new ActionListener() { |
396 |
cbmiToolBarVisible.setSelected(b); |
cbmiToolBarVisible.setSelected(b); |
397 |
showToolBar(b); |
showToolBar(b); |
398 |
|
|
399 |
cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
400 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
401 |
)); |
)); |
402 |
m.add(cbmiSidePaneVisible); |
m.add(cbmiLeftSidePaneVisible); |
403 |
|
|
404 |
cbmiSidePaneVisible.addActionListener(new ActionListener() { |
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
405 |
public void |
public void |
406 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
407 |
showSidePane(cbmiSidePaneVisible.getState()); |
showSidePane(cbmiLeftSidePaneVisible.getState()); |
408 |
} |
} |
409 |
}); |
}); |
410 |
|
|
411 |
b = preferences().getBoolProperty("sidePane.visible"); |
b = preferences().getBoolProperty("leftSidePane.visible"); |
412 |
cbmiSidePaneVisible.setSelected(b); |
cbmiLeftSidePaneVisible.setSelected(b); |
413 |
showSidePane(b); |
showSidePane(b); |
414 |
|
|
415 |
cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
416 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
417 |
)); |
)); |
418 |
m.add(cbmiDevicesPaneVisible); |
m.add(cbmiRightSidePaneVisible); |
419 |
|
|
420 |
cbmiDevicesPaneVisible.addActionListener(new ActionListener() { |
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
421 |
public void |
public void |
422 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
423 |
showDevicesPane(cbmiDevicesPaneVisible.getState()); |
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
424 |
} |
} |
425 |
}); |
}); |
426 |
|
|
427 |
b = preferences().getBoolProperty("devicesPane.visible"); |
b = preferences().getBoolProperty("rightSidePane.visible"); |
428 |
cbmiDevicesPaneVisible.setSelected(b); |
cbmiRightSidePaneVisible.setSelected(b); |
429 |
showDevicesPane(b); |
showDevicesPane(b); |
430 |
|
|
431 |
|
|
445 |
// Help |
// Help |
446 |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
447 |
|
|
448 |
|
mi = new JMenuItem(a4n.browseOnlineTutorial); |
449 |
|
mi.setIcon(null); |
450 |
|
m.add(mi); |
451 |
|
|
452 |
|
m.addSeparator(); |
453 |
|
|
454 |
mi = new JMenuItem(a4n.helpAbout); |
mi = new JMenuItem(a4n.helpAbout); |
455 |
mi.setIcon(null); |
mi.setIcon(null); |
456 |
m.add(mi); |
m.add(mi); |
507 |
dlg.setVisible(true); |
dlg.setVisible(true); |
508 |
} |
} |
509 |
|
|
510 |
|
/** |
511 |
|
* Gets the server address to which to connect. If the server should be |
512 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
513 |
|
*/ |
514 |
|
public Server |
515 |
|
getServer() { |
516 |
|
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
517 |
|
return getServer(b); |
518 |
|
} |
519 |
|
|
520 |
|
/** |
521 |
|
* Gets the server address to which to connect. If the server should be |
522 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
523 |
|
* @param manualSelect Determines whether the server should be manually selected. |
524 |
|
*/ |
525 |
|
public Server |
526 |
|
getServer(boolean manualSelect) { |
527 |
|
if(manualSelect) { |
528 |
|
JSConnectDlg dlg = new JSConnectDlg(); |
529 |
|
dlg.setVisible(true); |
530 |
|
return dlg.getSelectedServer(); |
531 |
|
} |
532 |
|
|
533 |
|
int i = preferences().getIntProperty(SERVER_INDEX); |
534 |
|
int size = CC.getServerList().getServerCount(); |
535 |
|
if(size == 0) return null; |
536 |
|
if(i >= size) return CC.getServerList().getServer(0); |
537 |
|
|
538 |
|
return CC.getServerList().getServer(i); |
539 |
|
} |
540 |
|
|
541 |
|
public Timer |
542 |
|
getGuiTimer() { return guiTimer; } |
543 |
|
|
544 |
protected LSConsoleModel |
protected LSConsoleModel |
545 |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
546 |
|
|
552 |
protected LSConsoleFrame |
protected LSConsoleFrame |
553 |
getLSConsoleFrame() { return lsConsoleFrame; } |
getLSConsoleFrame() { return lsConsoleFrame; } |
554 |
|
|
555 |
protected void |
protected boolean |
556 |
runScript() { |
runScript() { |
557 |
String s = preferences().getStringProperty("lastScriptLocation"); |
String s = preferences().getStringProperty("lastScriptLocation"); |
558 |
JFileChooser fc = new JFileChooser(s); |
JFileChooser fc = new JFileChooser(s); |
559 |
fc.setFileFilter(new LscpFileFilter()); |
fc.setFileFilter(new LscpFileFilter()); |
560 |
int result = fc.showOpenDialog(this); |
int result = fc.showOpenDialog(this); |
561 |
if(result != JFileChooser.APPROVE_OPTION) return; |
if(result != JFileChooser.APPROVE_OPTION) return false; |
562 |
|
|
563 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
564 |
preferences().setStringProperty("lastScriptLocation", path); |
preferences().setStringProperty("lastScriptLocation", path); |
565 |
|
|
566 |
runScript(fc.getSelectedFile()); |
runScript(fc.getSelectedFile()); |
567 |
|
|
568 |
|
return true; |
569 |
} |
} |
570 |
|
|
571 |
private void |
private void |
633 |
|
|
634 |
private void |
private void |
635 |
showSidePane(boolean b) { |
showSidePane(boolean b) { |
636 |
preferences().setBoolProperty("sidePane.visible", b); |
preferences().setBoolProperty("leftSidePane.visible", b); |
637 |
rootPane.remove(rightPane); |
rootPane.remove(rightPane); |
638 |
rootPane.remove(hSplitPane); |
rootPane.remove(hSplitPane); |
639 |
|
|
665 |
|
|
666 |
private void |
private void |
667 |
showDevicesPane(boolean b) { |
showDevicesPane(boolean b) { |
668 |
preferences().setBoolProperty("devicesPane.visible", b); |
preferences().setBoolProperty("rightSidePane.visible", b); |
669 |
|
|
670 |
int width = sidePane.getWidth(); |
int width = leftSidePane.getWidth(); |
671 |
int height = sidePane.getPreferredSize().height; |
int height = leftSidePane.getPreferredSize().height; |
672 |
if(width != 0) sidePane.setPreferredSize(new Dimension(width, height)); |
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
673 |
|
|
674 |
if(b) { |
if(b) { |
675 |
int w = preferences().getIntProperty("devicesPane.width", 200); |
int w = preferences().getIntProperty("devicesPane.width", 200); |
676 |
|
|
677 |
int h = spDevicesPane.getPreferredSize().height; |
int h = rightSidePane.getPreferredSize().height; |
678 |
spDevicesPane.setPreferredSize(new Dimension(w, h)); |
rightSidePane.setPreferredSize(new Dimension(w, h)); |
679 |
} else { |
} else { |
680 |
int w = spDevicesPane.getWidth(); |
int w = rightSidePane.getWidth(); |
681 |
if(w > 0 && w < 200) w = 200; |
if(w > 0 && w < 200) w = 200; |
682 |
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
683 |
} |
} |
684 |
|
|
685 |
hSplitPane.setResizeWeight(0.0); |
hSplitPane.setResizeWeight(0.0); |
686 |
spDevicesPane.setVisible(b); |
rightSidePane.setVisible(b); |
687 |
hSplitPane.resetToPreferredSizes(); |
hSplitPane.resetToPreferredSizes(); |
688 |
|
|
689 |
int w = getPreferredSize().width; |
int w = getPreferredSize().width; |
702 |
|
|
703 |
private void |
private void |
704 |
sidePanesVisibilityChanged() { |
sidePanesVisibilityChanged() { |
705 |
boolean sidePaneVisible = cbmiSidePaneVisible.isSelected(); |
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
706 |
boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected(); |
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
707 |
|
|
708 |
if(sidePaneVisible && devicesPaneVisible) { |
if(leftSidePaneVisible && rightSidePaneVisible) { |
709 |
hSplitPane.setResizeWeight(0.5); |
hSplitPane.setResizeWeight(0.5); |
710 |
} else if(sidePaneVisible && !devicesPaneVisible) { |
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
711 |
hSplitPane.setResizeWeight(1.0); |
hSplitPane.setResizeWeight(1.0); |
712 |
} |
} |
713 |
|
|
714 |
if(!sidePaneVisible && !devicesPaneVisible) { |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
715 |
standardBar.showFantasiaLogo(false); |
standardBar.showFantasiaLogo(false); |
716 |
if(isResizable()) setResizable(false); |
if(isResizable()) setResizable(false); |
717 |
} else { |
} else { |