50 |
import javax.swing.Box; |
import javax.swing.Box; |
51 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
52 |
import javax.swing.JCheckBoxMenuItem; |
import javax.swing.JCheckBoxMenuItem; |
53 |
|
import javax.swing.JComponent; |
54 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
55 |
import javax.swing.JFileChooser; |
import javax.swing.JFileChooser; |
56 |
import javax.swing.JFrame; |
import javax.swing.JFrame; |
77 |
import org.jsampler.view.JSMainFrame; |
import org.jsampler.view.JSMainFrame; |
78 |
import org.jsampler.view.LscpFileFilter; |
import org.jsampler.view.LscpFileFilter; |
79 |
|
|
80 |
|
import org.jsampler.view.std.JSDetailedErrorDlg; |
81 |
|
import org.jsampler.view.std.JSQuitDlg; |
82 |
import org.jsampler.view.std.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
83 |
|
|
84 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
92 |
* @author Grigor Iliev |
* @author Grigor Iliev |
93 |
*/ |
*/ |
94 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends JSMainFrame { |
|
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
|
95 |
private final StandardBar standardBar = new StandardBar(); |
private final StandardBar standardBar = new StandardBar(); |
96 |
|
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
97 |
|
private final JPanel rootPane = new JPanel(); |
98 |
private final MainPane mainPane = new MainPane(); |
private final MainPane mainPane = new MainPane(); |
99 |
private final DevicesPane devicesPane = new DevicesPane(); |
private final DevicesPane devicesPane = new DevicesPane(); |
100 |
|
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")); |
105 |
private final JSplitPane hSplitPane; |
private final JSplitPane hSplitPane; |
106 |
|
|
107 |
private final SidePane sidePane = new SidePane(); |
private final SidePane sidePane = new SidePane(); |
108 |
|
private final JPanel rightPane; |
109 |
|
|
110 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
111 |
private final Vector<String> recentScripts = new Vector<String>(); |
private final Vector<String> recentScripts = new Vector<String>(); |
112 |
|
|
113 |
|
|
114 |
|
private final JCheckBoxMenuItem cbmiToolBarVisible = |
115 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
116 |
|
|
117 |
|
private final JCheckBoxMenuItem cbmiSidePaneVisible = |
118 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane")); |
119 |
|
|
120 |
|
private final JCheckBoxMenuItem cbmiDevicesPaneVisible = |
121 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane")); |
122 |
|
|
123 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
124 |
public |
public |
125 |
MainFrame() { |
MainFrame() { |
129 |
|
|
130 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
getContentPane().add(standardBar, BorderLayout.NORTH); |
131 |
|
|
132 |
addMenu(); |
rightPane = createRightPane(); |
|
|
|
|
addChannelsPane(mainPane.getChannelsPane()); |
|
|
|
|
|
JPanel rp = createRightPane(); |
|
133 |
|
|
134 |
hSplitPane = new JSplitPane ( |
hSplitPane = new JSplitPane ( |
135 |
JSplitPane.HORIZONTAL_SPLIT, |
JSplitPane.HORIZONTAL_SPLIT, |
136 |
true, // continuousLayout |
true, // continuousLayout |
137 |
sidePane, rp |
sidePane, rightPane |
138 |
); |
); |
139 |
|
hSplitPane.setResizeWeight(0.5); |
140 |
|
|
141 |
getContentPane().add(hSplitPane); |
rootPane.setLayout(new BorderLayout()); |
142 |
|
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
143 |
|
rootPane.setOpaque(false); |
144 |
|
rootPane.add(hSplitPane); |
145 |
|
|
146 |
|
addMenu(); |
147 |
|
|
148 |
|
addChannelsPane(mainPane.getChannelsPane()); |
149 |
|
|
150 |
|
getContentPane().add(rootPane); |
151 |
|
|
152 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
153 |
hSplitPane.setDividerLocation(i); |
hSplitPane.setDividerLocation(i); |
165 |
|
|
166 |
c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
167 |
|
|
168 |
JScrollPane sp = new JScrollPane(devicesPane); |
spDevicesPane.setViewportView(devicesPane); |
169 |
sp.setBorder(BorderFactory.createEmptyBorder()); |
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
170 |
|
int h = spDevicesPane.getMinimumSize().height; |
171 |
|
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
172 |
|
|
173 |
c.gridx = 1; |
c.gridx = 1; |
174 |
c.gridy = 0; |
c.gridy = 0; |
175 |
c.weightx = 1.0; |
c.weightx = 1.0; |
176 |
c.weighty = 1.0; |
c.weighty = 1.0; |
177 |
c.insets = new Insets(0, 3, 3, 0); |
c.insets = new Insets(0, 3, 3, 0); |
178 |
gridbag.setConstraints(sp, c); |
gridbag.setConstraints(spDevicesPane, c); |
179 |
p.add(sp); |
p.add(spDevicesPane); |
180 |
|
|
181 |
c.gridx = 0; |
c.gridx = 0; |
182 |
c.gridy = 0; |
c.gridy = 0; |
236 |
/** Invoked when this window is about to close. */ |
/** Invoked when this window is about to close. */ |
237 |
protected void |
protected void |
238 |
onWindowClose() { |
onWindowClose() { |
239 |
|
if(CC.getSamplerModel().isModified()) { |
240 |
|
JSQuitDlg dlg = new JSQuitDlg(Res.iconQuestion32); |
241 |
|
dlg.setVisible(true); |
242 |
|
if(dlg.isCancelled()) return; |
243 |
|
} |
244 |
|
|
245 |
sidePane.savePreferences(); |
sidePane.savePreferences(); |
246 |
|
|
247 |
int i = hSplitPane.getDividerLocation(); |
int i = hSplitPane.getDividerLocation(); |
336 |
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
337 |
menuBar.add(m); |
menuBar.add(m); |
338 |
|
|
339 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel")); |
340 |
|
m.add(mi); |
341 |
|
mi.addActionListener(new ActionListener() { |
342 |
|
public void |
343 |
|
actionPerformed(ActionEvent e) { |
344 |
|
CC.getSamplerModel().addBackendChannel(); |
345 |
|
} |
346 |
|
}); |
347 |
|
|
348 |
|
m.addSeparator(); |
349 |
|
|
350 |
|
mi = new JMenuItem(a4n.createMidiDevice); |
351 |
|
mi.setIcon(null); |
352 |
|
m.add(mi); |
353 |
|
|
354 |
|
mi = new JMenuItem(a4n.createAudioDevice); |
355 |
|
mi.setIcon(null); |
356 |
|
m.add(mi); |
357 |
|
|
358 |
|
m.addSeparator(); |
359 |
|
|
360 |
mi = new JMenuItem(a4n.editPreferences); |
mi = new JMenuItem(a4n.editPreferences); |
361 |
mi.setIcon(null); |
mi.setIcon(null); |
362 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
364 |
)); |
)); |
365 |
m.add(mi); |
m.add(mi); |
366 |
|
|
367 |
|
// View |
368 |
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
369 |
|
menuBar.add(m); |
370 |
|
|
371 |
|
m.add(cbmiToolBarVisible); |
372 |
|
|
373 |
|
cbmiToolBarVisible.addActionListener(new ActionListener() { |
374 |
|
public void |
375 |
|
actionPerformed(ActionEvent e) { |
376 |
|
showToolBar(cbmiToolBarVisible.getState()); |
377 |
|
} |
378 |
|
}); |
379 |
|
|
380 |
|
boolean b = preferences().getBoolProperty("toolBar.visible"); |
381 |
|
cbmiToolBarVisible.setSelected(b); |
382 |
|
showToolBar(b); |
383 |
|
|
384 |
|
cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
385 |
|
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
386 |
|
)); |
387 |
|
m.add(cbmiSidePaneVisible); |
388 |
|
|
389 |
|
cbmiSidePaneVisible.addActionListener(new ActionListener() { |
390 |
|
public void |
391 |
|
actionPerformed(ActionEvent e) { |
392 |
|
showSidePane(cbmiSidePaneVisible.getState()); |
393 |
|
} |
394 |
|
}); |
395 |
|
|
396 |
|
b = preferences().getBoolProperty("sidePane.visible"); |
397 |
|
cbmiSidePaneVisible.setSelected(b); |
398 |
|
showSidePane(b); |
399 |
|
|
400 |
|
cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
401 |
|
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
402 |
|
)); |
403 |
|
m.add(cbmiDevicesPaneVisible); |
404 |
|
|
405 |
|
cbmiDevicesPaneVisible.addActionListener(new ActionListener() { |
406 |
|
public void |
407 |
|
actionPerformed(ActionEvent e) { |
408 |
|
showDevicesPane(cbmiDevicesPaneVisible.getState()); |
409 |
|
} |
410 |
|
}); |
411 |
|
|
412 |
|
b = preferences().getBoolProperty("devicesPane.visible"); |
413 |
|
cbmiDevicesPaneVisible.setSelected(b); |
414 |
|
showDevicesPane(b); |
415 |
|
|
416 |
|
|
417 |
// Window |
// Window |
418 |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
430 |
// Help |
// Help |
431 |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
m = new FantasiaMenu(i18n.getMenuLabel("help")); |
432 |
|
|
433 |
|
mi = new JMenuItem(a4n.browseOnlineTutorial); |
434 |
|
mi.setIcon(null); |
435 |
|
m.add(mi); |
436 |
|
|
437 |
|
m.addSeparator(); |
438 |
|
|
439 |
mi = new JMenuItem(a4n.helpAbout); |
mi = new JMenuItem(a4n.helpAbout); |
440 |
mi.setIcon(null); |
mi.setIcon(null); |
441 |
m.add(mi); |
m.add(mi); |
478 |
|
|
479 |
public void |
public void |
480 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
showDetailedErrorMessage(Frame owner, String err, String details) { |
481 |
// TODO: |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
482 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
483 |
|
); |
484 |
|
dlg.setVisible(true); |
485 |
} |
} |
486 |
|
|
487 |
public void |
public void |
488 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
489 |
// TODO: |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
490 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
491 |
|
); |
492 |
|
dlg.setVisible(true); |
493 |
} |
} |
494 |
|
|
495 |
protected LSConsoleModel |
protected LSConsoleModel |
574 |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
575 |
} |
} |
576 |
|
|
577 |
|
private void |
578 |
|
showToolBar(boolean b) { |
579 |
|
preferences().setBoolProperty("toolBar.visible", b); |
580 |
|
standardBar.setVisible(b); |
581 |
|
} |
582 |
|
|
583 |
|
private void |
584 |
|
showSidePane(boolean b) { |
585 |
|
preferences().setBoolProperty("sidePane.visible", b); |
586 |
|
rootPane.remove(rightPane); |
587 |
|
rootPane.remove(hSplitPane); |
588 |
|
|
589 |
|
if(b) { |
590 |
|
hSplitPane.setRightComponent(rightPane); |
591 |
|
rootPane.add(hSplitPane); |
592 |
|
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
593 |
|
|
594 |
|
hSplitPane.setDividerLocation(i); |
595 |
|
hSplitPane.validate(); |
596 |
|
} else { |
597 |
|
rootPane.add(rightPane); |
598 |
|
|
599 |
|
} |
600 |
|
|
601 |
|
int w = getPreferredSize().width; |
602 |
|
int h = getSize().height; |
603 |
|
setSize(new Dimension(w, h)); |
604 |
|
|
605 |
|
rootPane.revalidate(); |
606 |
|
rootPane.validate(); |
607 |
|
rootPane.repaint(); |
608 |
|
|
609 |
|
SwingUtilities.invokeLater(new Runnable() { |
610 |
|
public void |
611 |
|
run() { sidePanesVisibilityChanged(); } |
612 |
|
}); |
613 |
|
} |
614 |
|
|
615 |
|
private void |
616 |
|
showDevicesPane(boolean b) { |
617 |
|
preferences().setBoolProperty("devicesPane.visible", b); |
618 |
|
|
619 |
|
int width = sidePane.getWidth(); |
620 |
|
int height = sidePane.getPreferredSize().height; |
621 |
|
if(width != 0) sidePane.setPreferredSize(new Dimension(width, height)); |
622 |
|
|
623 |
|
if(b) { |
624 |
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
625 |
|
|
626 |
|
int h = spDevicesPane.getPreferredSize().height; |
627 |
|
spDevicesPane.setPreferredSize(new Dimension(w, h)); |
628 |
|
} else { |
629 |
|
int w = spDevicesPane.getWidth(); |
630 |
|
if(w > 0 && w < 200) w = 200; |
631 |
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
632 |
|
} |
633 |
|
|
634 |
|
hSplitPane.setResizeWeight(0.0); |
635 |
|
spDevicesPane.setVisible(b); |
636 |
|
hSplitPane.resetToPreferredSizes(); |
637 |
|
|
638 |
|
int w = getPreferredSize().width; |
639 |
|
int h = getSize().height; |
640 |
|
setSize(new Dimension(w, h)); |
641 |
|
|
642 |
|
rootPane.validate(); |
643 |
|
rootPane.repaint(); |
644 |
|
//hSplitPane.validate(); |
645 |
|
|
646 |
|
SwingUtilities.invokeLater(new Runnable() { |
647 |
|
public void |
648 |
|
run() { sidePanesVisibilityChanged(); } |
649 |
|
}); |
650 |
|
} |
651 |
|
|
652 |
|
private void |
653 |
|
sidePanesVisibilityChanged() { |
654 |
|
boolean sidePaneVisible = cbmiSidePaneVisible.isSelected(); |
655 |
|
boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected(); |
656 |
|
|
657 |
|
if(sidePaneVisible && devicesPaneVisible) { |
658 |
|
hSplitPane.setResizeWeight(0.5); |
659 |
|
} else if(sidePaneVisible && !devicesPaneVisible) { |
660 |
|
hSplitPane.setResizeWeight(1.0); |
661 |
|
} |
662 |
|
|
663 |
|
if(!sidePaneVisible && !devicesPaneVisible) { |
664 |
|
standardBar.showFantasiaLogo(false); |
665 |
|
if(isResizable()) setResizable(false); |
666 |
|
} else { |
667 |
|
standardBar.showFantasiaLogo(true); |
668 |
|
if(!isResizable()) setResizable(true); |
669 |
|
} |
670 |
|
} |
671 |
|
|
672 |
private class RecentScriptHandler implements ActionListener { |
private class RecentScriptHandler implements ActionListener { |
673 |
private String script; |
private String script; |
674 |
|
|
691 |
} |
} |
692 |
} |
} |
693 |
|
|
694 |
private static class FantasiaMenuBar extends JMenuBar { |
private class FantasiaMenuBar extends JMenuBar { |
695 |
private static Insets pixmapInsets = new Insets(6, 6, 0, 6); |
private Insets pixmapInsets = new Insets(6, 6, 0, 6); |
696 |
|
private Insets pixmapInsets2 = new Insets(6, 6, 6, 6); |
697 |
|
|
698 |
FantasiaMenuBar() { |
FantasiaMenuBar() { |
699 |
setOpaque(false); |
setOpaque(false); |
702 |
protected void |
protected void |
703 |
paintComponent(Graphics g) { |
paintComponent(Graphics g) { |
704 |
super.paintComponent(g); |
super.paintComponent(g); |
705 |
|
if(standardBar.isVisible()) { |
706 |
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
707 |
|
} else { |
708 |
|
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
709 |
|
} |
710 |
} |
} |
711 |
} |
} |
712 |
} |
} |