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 |
* |
* |
71 |
import org.jsampler.CC; |
import org.jsampler.CC; |
72 |
import org.jsampler.HF; |
import org.jsampler.HF; |
73 |
import org.jsampler.LSConsoleModel; |
import org.jsampler.LSConsoleModel; |
74 |
|
import org.jsampler.Server; |
75 |
|
|
76 |
import org.jsampler.view.JSChannel; |
import org.jsampler.view.JSChannel; |
77 |
import org.jsampler.view.JSChannelsPane; |
import org.jsampler.view.JSChannelsPane; |
78 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
79 |
import org.jsampler.view.LscpFileFilter; |
import org.jsampler.view.LscpFileFilter; |
80 |
|
|
81 |
|
import org.jsampler.view.std.JSConnectDlg; |
82 |
import org.jsampler.view.std.JSDetailedErrorDlg; |
import org.jsampler.view.std.JSDetailedErrorDlg; |
83 |
|
import org.jsampler.view.std.JSQuitDlg; |
84 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
85 |
|
|
86 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
98 |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
99 |
private final JPanel rootPane = new JPanel(); |
private final JPanel rootPane = new JPanel(); |
100 |
private final MainPane mainPane = new MainPane(); |
private final MainPane mainPane = new MainPane(); |
|
private final DevicesPane devicesPane = new DevicesPane(); |
|
|
private final JScrollPane spDevicesPane = new JScrollPane(); |
|
101 |
|
|
102 |
private final JMenu recentScriptsMenu = |
private final JMenu recentScriptsMenu = |
103 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
104 |
|
|
105 |
private final JSplitPane hSplitPane; |
private final JSplitPane hSplitPane; |
106 |
|
|
107 |
private final SidePane sidePane = new SidePane(); |
private final LeftSidePane leftSidePane = new LeftSidePane(); |
108 |
|
private final RightSidePane rightSidePane = new RightSidePane(); |
109 |
private final JPanel rightPane; |
private final JPanel rightPane; |
110 |
|
|
111 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
115 |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
private final JCheckBoxMenuItem cbmiToolBarVisible = |
116 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
117 |
|
|
118 |
private final JCheckBoxMenuItem cbmiSidePaneVisible = |
private final JCheckBoxMenuItem cbmiLeftSidePaneVisible = |
119 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.leftSidePane")); |
120 |
|
|
121 |
private final JCheckBoxMenuItem cbmiDevicesPaneVisible = |
private final JCheckBoxMenuItem cbmiRightSidePaneVisible = |
122 |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane")); |
new JCheckBoxMenuItem(i18n.getMenuLabel("view.rightSidePane")); |
123 |
|
|
124 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
125 |
public |
public |
135 |
hSplitPane = new JSplitPane ( |
hSplitPane = new JSplitPane ( |
136 |
JSplitPane.HORIZONTAL_SPLIT, |
JSplitPane.HORIZONTAL_SPLIT, |
137 |
true, // continuousLayout |
true, // continuousLayout |
138 |
sidePane, rightPane |
leftSidePane, rightPane |
139 |
); |
); |
140 |
hSplitPane.setResizeWeight(0.5); |
hSplitPane.setResizeWeight(0.5); |
141 |
|
|
166 |
|
|
167 |
c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
168 |
|
|
|
spDevicesPane.setViewportView(devicesPane); |
|
|
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
|
|
int h = spDevicesPane.getMinimumSize().height; |
|
|
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
|
|
|
|
169 |
c.gridx = 1; |
c.gridx = 1; |
170 |
c.gridy = 0; |
c.gridy = 0; |
171 |
c.weightx = 1.0; |
c.weightx = 1.0; |
172 |
c.weighty = 1.0; |
c.weighty = 1.0; |
173 |
c.insets = new Insets(0, 3, 3, 0); |
c.insets = new Insets(0, 3, 0, 0); |
174 |
gridbag.setConstraints(spDevicesPane, c); |
gridbag.setConstraints(rightSidePane, c); |
175 |
p.add(spDevicesPane); |
p.add(rightSidePane); |
176 |
|
|
177 |
c.gridx = 0; |
c.gridx = 0; |
178 |
c.gridy = 0; |
c.gridy = 0; |
179 |
c.weightx = 0.0; |
c.weightx = 0.0; |
180 |
c.weighty = 1.0; |
c.weighty = 1.0; |
181 |
c.insets = new Insets(0, 3, 3, 3); |
c.insets = new Insets(0, 3, 0, 3); |
182 |
c.fill = GridBagConstraints.VERTICAL; |
c.fill = GridBagConstraints.VERTICAL; |
183 |
gridbag.setConstraints(mainPane, c); |
gridbag.setConstraints(mainPane, c); |
184 |
p.add(mainPane); |
p.add(mainPane); |
232 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
233 |
protected void |
protected void |
234 |
onWindowClose() { |
onWindowClose() { |
235 |
sidePane.savePreferences(); |
boolean b = preferences().getBoolProperty(CONFIRM_APP_QUIT); |
236 |
|
if(b && CC.getSamplerModel().isModified()) { |
237 |
|
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
238 |
|
dlg.setVisible(true); |
239 |
|
if(dlg.isCancelled()) return; |
240 |
|
} |
241 |
|
|
242 |
|
leftSidePane.savePreferences(); |
243 |
|
rightSidePane.savePreferences(); |
244 |
|
|
245 |
int i = hSplitPane.getDividerLocation(); |
int i = hSplitPane.getDividerLocation(); |
246 |
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
preferences().setIntProperty("MainFrame.hSplitDividerLocation", i); |
282 |
// Actions |
// Actions |
283 |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
m = new FantasiaMenu(i18n.getMenuLabel("actions")); |
284 |
|
|
285 |
mi = new JMenuItem(a4n.connect); |
mi = new JMenuItem(a4n.refresh); |
286 |
mi.setIcon(null); |
mi.setIcon(null); |
287 |
//mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK)); |
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); |
288 |
m.add(mi); |
m.add(mi); |
289 |
|
|
290 |
mi = new JMenuItem(a4n.samplerInfo); |
mi = new JMenuItem(a4n.samplerInfo); |
291 |
mi.setIcon(null); |
mi.setIcon(null); |
292 |
m.add(mi); |
m.add(mi); |
293 |
|
|
294 |
|
mi = new JMenuItem(a4n.resetSampler); |
295 |
|
mi.setIcon(null); |
296 |
|
m.add(mi); |
297 |
|
|
298 |
m.addSeparator(); |
m.addSeparator(); |
299 |
|
|
300 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("actions.export")); |
313 |
|
|
314 |
mi = new JMenuItem(a4n.loadScript); |
mi = new JMenuItem(a4n.loadScript); |
315 |
mi.setIcon(null); |
mi.setIcon(null); |
316 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); |
317 |
m.add(mi); |
m.add(mi); |
318 |
|
|
319 |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
String[] list = preferences().getStringListProperty(RECENT_LSCP_SCRIPTS); |
325 |
|
|
326 |
m.addSeparator(); |
m.addSeparator(); |
327 |
|
|
328 |
|
mi = new JMenuItem(a4n.changeBackend); |
329 |
|
mi.setIcon(null); |
330 |
|
mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); |
331 |
|
m.add(mi); |
332 |
|
|
333 |
|
m.addSeparator(); |
334 |
|
|
335 |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
mi = new JMenuItem(i18n.getMenuLabel("actions.exit")); |
336 |
m.add(mi); |
m.add(mi); |
337 |
mi.addActionListener(new ActionListener() { |
mi.addActionListener(new ActionListener() { |
391 |
cbmiToolBarVisible.setSelected(b); |
cbmiToolBarVisible.setSelected(b); |
392 |
showToolBar(b); |
showToolBar(b); |
393 |
|
|
394 |
cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiLeftSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
395 |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
396 |
)); |
)); |
397 |
m.add(cbmiSidePaneVisible); |
m.add(cbmiLeftSidePaneVisible); |
398 |
|
|
399 |
cbmiSidePaneVisible.addActionListener(new ActionListener() { |
cbmiLeftSidePaneVisible.addActionListener(new ActionListener() { |
400 |
public void |
public void |
401 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
402 |
showSidePane(cbmiSidePaneVisible.getState()); |
showSidePane(cbmiLeftSidePaneVisible.getState()); |
403 |
} |
} |
404 |
}); |
}); |
405 |
|
|
406 |
b = preferences().getBoolProperty("sidePane.visible"); |
b = preferences().getBoolProperty("leftSidePane.visible"); |
407 |
cbmiSidePaneVisible.setSelected(b); |
cbmiLeftSidePaneVisible.setSelected(b); |
408 |
showSidePane(b); |
showSidePane(b); |
409 |
|
|
410 |
cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
cbmiRightSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
411 |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
412 |
)); |
)); |
413 |
m.add(cbmiDevicesPaneVisible); |
m.add(cbmiRightSidePaneVisible); |
414 |
|
|
415 |
cbmiDevicesPaneVisible.addActionListener(new ActionListener() { |
cbmiRightSidePaneVisible.addActionListener(new ActionListener() { |
416 |
public void |
public void |
417 |
actionPerformed(ActionEvent e) { |
actionPerformed(ActionEvent e) { |
418 |
showDevicesPane(cbmiDevicesPaneVisible.getState()); |
showDevicesPane(cbmiRightSidePaneVisible.getState()); |
419 |
} |
} |
420 |
}); |
}); |
421 |
|
|
422 |
b = preferences().getBoolProperty("devicesPane.visible"); |
b = preferences().getBoolProperty("rightSidePane.visible"); |
423 |
cbmiDevicesPaneVisible.setSelected(b); |
cbmiRightSidePaneVisible.setSelected(b); |
424 |
showDevicesPane(b); |
showDevicesPane(b); |
425 |
|
|
426 |
|
|
502 |
dlg.setVisible(true); |
dlg.setVisible(true); |
503 |
} |
} |
504 |
|
|
505 |
|
/** |
506 |
|
* Gets the server address to which to connect. If the server should be |
507 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
508 |
|
*/ |
509 |
|
public Server |
510 |
|
getServer() { |
511 |
|
boolean b = preferences().getBoolProperty(MANUAL_SERVER_SELECT_ON_STARTUP); |
512 |
|
return getServer(b); |
513 |
|
} |
514 |
|
|
515 |
|
/** |
516 |
|
* Gets the server address to which to connect. If the server should be |
517 |
|
* manually selected, a dialog asking the user to choose a server is displayed. |
518 |
|
* @param manualSelect Determines whether the server should be manually selected. |
519 |
|
*/ |
520 |
|
public Server |
521 |
|
getServer(boolean manualSelect) { |
522 |
|
if(manualSelect) { |
523 |
|
JSConnectDlg dlg = new JSConnectDlg(); |
524 |
|
dlg.setVisible(true); |
525 |
|
return dlg.getSelectedServer(); |
526 |
|
} |
527 |
|
|
528 |
|
int i = preferences().getIntProperty(SERVER_INDEX); |
529 |
|
int size = CC.getServerList().getServerCount(); |
530 |
|
if(size == 0) return null; |
531 |
|
if(i >= size) return CC.getServerList().getServer(0); |
532 |
|
|
533 |
|
return CC.getServerList().getServer(i); |
534 |
|
} |
535 |
|
|
536 |
protected LSConsoleModel |
protected LSConsoleModel |
537 |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
getLSConsoleModel() { return getLSConsolePane().getModel(); } |
538 |
|
|
544 |
protected LSConsoleFrame |
protected LSConsoleFrame |
545 |
getLSConsoleFrame() { return lsConsoleFrame; } |
getLSConsoleFrame() { return lsConsoleFrame; } |
546 |
|
|
547 |
protected void |
protected boolean |
548 |
runScript() { |
runScript() { |
549 |
String s = preferences().getStringProperty("lastScriptLocation"); |
String s = preferences().getStringProperty("lastScriptLocation"); |
550 |
JFileChooser fc = new JFileChooser(s); |
JFileChooser fc = new JFileChooser(s); |
551 |
fc.setFileFilter(new LscpFileFilter()); |
fc.setFileFilter(new LscpFileFilter()); |
552 |
int result = fc.showOpenDialog(this); |
int result = fc.showOpenDialog(this); |
553 |
if(result != JFileChooser.APPROVE_OPTION) return; |
if(result != JFileChooser.APPROVE_OPTION) return false; |
554 |
|
|
555 |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
String path = fc.getCurrentDirectory().getAbsolutePath(); |
556 |
preferences().setStringProperty("lastScriptLocation", path); |
preferences().setStringProperty("lastScriptLocation", path); |
557 |
|
|
558 |
runScript(fc.getSelectedFile()); |
runScript(fc.getSelectedFile()); |
559 |
|
|
560 |
|
return true; |
561 |
} |
} |
562 |
|
|
563 |
private void |
private void |
625 |
|
|
626 |
private void |
private void |
627 |
showSidePane(boolean b) { |
showSidePane(boolean b) { |
628 |
preferences().setBoolProperty("sidePane.visible", b); |
preferences().setBoolProperty("leftSidePane.visible", b); |
629 |
rootPane.remove(rightPane); |
rootPane.remove(rightPane); |
630 |
rootPane.remove(hSplitPane); |
rootPane.remove(hSplitPane); |
631 |
|
|
657 |
|
|
658 |
private void |
private void |
659 |
showDevicesPane(boolean b) { |
showDevicesPane(boolean b) { |
660 |
preferences().setBoolProperty("devicesPane.visible", b); |
preferences().setBoolProperty("rightSidePane.visible", b); |
661 |
|
|
662 |
int width = sidePane.getWidth(); |
int width = leftSidePane.getWidth(); |
663 |
int height = sidePane.getPreferredSize().height; |
int height = leftSidePane.getPreferredSize().height; |
664 |
if(width != 0) sidePane.setPreferredSize(new Dimension(width, height)); |
if(width != 0) leftSidePane.setPreferredSize(new Dimension(width, height)); |
665 |
|
|
666 |
if(b) { |
if(b) { |
667 |
int w = preferences().getIntProperty("devicesPane.width", 200); |
int w = preferences().getIntProperty("devicesPane.width", 200); |
668 |
|
|
669 |
int h = spDevicesPane.getPreferredSize().height; |
int h = rightSidePane.getPreferredSize().height; |
670 |
spDevicesPane.setPreferredSize(new Dimension(w, h)); |
rightSidePane.setPreferredSize(new Dimension(w, h)); |
671 |
} else { |
} else { |
672 |
int w = spDevicesPane.getWidth(); |
int w = rightSidePane.getWidth(); |
673 |
if(w > 0 && w < 200) w = 200; |
if(w > 0 && w < 200) w = 200; |
674 |
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
675 |
} |
} |
676 |
|
|
677 |
hSplitPane.setResizeWeight(0.0); |
hSplitPane.setResizeWeight(0.0); |
678 |
spDevicesPane.setVisible(b); |
rightSidePane.setVisible(b); |
679 |
hSplitPane.resetToPreferredSizes(); |
hSplitPane.resetToPreferredSizes(); |
680 |
|
|
681 |
int w = getPreferredSize().width; |
int w = getPreferredSize().width; |
694 |
|
|
695 |
private void |
private void |
696 |
sidePanesVisibilityChanged() { |
sidePanesVisibilityChanged() { |
697 |
boolean sidePaneVisible = cbmiSidePaneVisible.isSelected(); |
boolean leftSidePaneVisible = cbmiLeftSidePaneVisible.isSelected(); |
698 |
boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected(); |
boolean rightSidePaneVisible = cbmiRightSidePaneVisible.isSelected(); |
699 |
|
|
700 |
if(sidePaneVisible && devicesPaneVisible) { |
if(leftSidePaneVisible && rightSidePaneVisible) { |
701 |
hSplitPane.setResizeWeight(0.5); |
hSplitPane.setResizeWeight(0.5); |
702 |
} else if(sidePaneVisible && !devicesPaneVisible) { |
} else if(leftSidePaneVisible && !rightSidePaneVisible) { |
703 |
hSplitPane.setResizeWeight(1.0); |
hSplitPane.setResizeWeight(1.0); |
704 |
} |
} |
705 |
|
|
706 |
if(!sidePaneVisible && !devicesPaneVisible) { |
if(!leftSidePaneVisible && !rightSidePaneVisible) { |
707 |
standardBar.showFantasiaLogo(false); |
standardBar.showFantasiaLogo(false); |
708 |
if(isResizable()) setResizable(false); |
if(isResizable()) setResizable(false); |
709 |
} else { |
} else { |