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.JSamplerHomeChooser; |
import org.jsampler.view.std.JSamplerHomeChooser; |
82 |
|
|
83 |
import static org.jsampler.view.fantasia.A4n.a4n; |
import static org.jsampler.view.fantasia.A4n.a4n; |
91 |
* @author Grigor Iliev |
* @author Grigor Iliev |
92 |
*/ |
*/ |
93 |
public class MainFrame extends JSMainFrame { |
public class MainFrame extends JSMainFrame { |
|
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
|
94 |
private final StandardBar standardBar = new StandardBar(); |
private final StandardBar standardBar = new StandardBar(); |
95 |
|
private final FantasiaMenuBar menuBar = new FantasiaMenuBar(); |
96 |
|
private final JPanel rootPane = new JPanel(); |
97 |
private final MainPane mainPane = new MainPane(); |
private final MainPane mainPane = new MainPane(); |
98 |
private final DevicesPane devicesPane = new DevicesPane(); |
private final DevicesPane devicesPane = new DevicesPane(); |
99 |
|
private final JScrollPane spDevicesPane = new JScrollPane(); |
100 |
|
|
101 |
private final JMenu recentScriptsMenu = |
private final JMenu recentScriptsMenu = |
102 |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
new JMenu(i18n.getMenuLabel("actions.recentScripts")); |
104 |
private final JSplitPane hSplitPane; |
private final JSplitPane hSplitPane; |
105 |
|
|
106 |
private final SidePane sidePane = new SidePane(); |
private final SidePane sidePane = new SidePane(); |
107 |
|
private final JPanel rightPane; |
108 |
|
|
109 |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
private final LSConsoleFrame lsConsoleFrame = new LSConsoleFrame(); |
110 |
private final Vector<String> recentScripts = new Vector<String>(); |
private final Vector<String> recentScripts = new Vector<String>(); |
111 |
|
|
112 |
|
|
113 |
|
private final JCheckBoxMenuItem cbmiToolBarVisible = |
114 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.toolBar")); |
115 |
|
|
116 |
|
private final JCheckBoxMenuItem cbmiSidePaneVisible = |
117 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.sidePane")); |
118 |
|
|
119 |
|
private final JCheckBoxMenuItem cbmiDevicesPaneVisible = |
120 |
|
new JCheckBoxMenuItem(i18n.getMenuLabel("view.devicesPane")); |
121 |
|
|
122 |
/** Creates a new instance of <code>MainFrame</code> */ |
/** Creates a new instance of <code>MainFrame</code> */ |
123 |
public |
public |
124 |
MainFrame() { |
MainFrame() { |
128 |
|
|
129 |
getContentPane().add(standardBar, BorderLayout.NORTH); |
getContentPane().add(standardBar, BorderLayout.NORTH); |
130 |
|
|
131 |
addMenu(); |
rightPane = createRightPane(); |
|
|
|
|
addChannelsPane(mainPane.getChannelsPane()); |
|
|
|
|
|
JScrollPane sp = new JScrollPane(createRightPane()); |
|
|
sp.setBorder(BorderFactory.createEmptyBorder()); |
|
132 |
|
|
133 |
hSplitPane = new JSplitPane ( |
hSplitPane = new JSplitPane ( |
134 |
JSplitPane.HORIZONTAL_SPLIT, |
JSplitPane.HORIZONTAL_SPLIT, |
135 |
true, // continuousLayout |
true, // continuousLayout |
136 |
sidePane, sp |
sidePane, rightPane |
137 |
); |
); |
138 |
|
hSplitPane.setResizeWeight(0.5); |
139 |
|
|
140 |
getContentPane().add(hSplitPane); |
rootPane.setLayout(new BorderLayout()); |
141 |
|
rootPane.setBorder(BorderFactory.createEmptyBorder(6, 0, 0, 0)); |
142 |
|
rootPane.setOpaque(false); |
143 |
|
rootPane.add(hSplitPane); |
144 |
|
|
145 |
|
addMenu(); |
146 |
|
|
147 |
|
addChannelsPane(mainPane.getChannelsPane()); |
148 |
|
|
149 |
|
getContentPane().add(rootPane); |
150 |
|
|
151 |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
152 |
hSplitPane.setDividerLocation(i); |
hSplitPane.setDividerLocation(i); |
164 |
|
|
165 |
c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
166 |
|
|
167 |
|
spDevicesPane.setViewportView(devicesPane); |
168 |
|
spDevicesPane.setBorder(BorderFactory.createEmptyBorder()); |
169 |
|
int h = spDevicesPane.getMinimumSize().height; |
170 |
|
spDevicesPane.setMinimumSize(new Dimension(200, h)); |
171 |
|
|
172 |
c.gridx = 1; |
c.gridx = 1; |
173 |
c.gridy = 0; |
c.gridy = 0; |
174 |
c.weightx = 1.0; |
c.weightx = 1.0; |
175 |
c.weighty = 1.0; |
c.weighty = 1.0; |
176 |
c.insets = new Insets(0, 3, 3, 0); |
c.insets = new Insets(0, 3, 3, 0); |
177 |
gridbag.setConstraints(devicesPane, c); |
gridbag.setConstraints(spDevicesPane, c); |
178 |
p.add(devicesPane); |
p.add(spDevicesPane); |
179 |
|
|
180 |
c.gridx = 0; |
c.gridx = 0; |
181 |
c.gridy = 0; |
c.gridy = 0; |
329 |
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
m = new FantasiaMenu(i18n.getMenuLabel("edit")); |
330 |
menuBar.add(m); |
menuBar.add(m); |
331 |
|
|
332 |
|
mi = new JMenuItem(i18n.getMenuLabel("edit.addChannel")); |
333 |
|
m.add(mi); |
334 |
|
mi.addActionListener(new ActionListener() { |
335 |
|
public void |
336 |
|
actionPerformed(ActionEvent e) { |
337 |
|
CC.getSamplerModel().addBackendChannel(); |
338 |
|
} |
339 |
|
}); |
340 |
|
|
341 |
|
m.addSeparator(); |
342 |
|
|
343 |
|
mi = new JMenuItem(a4n.createMidiDevice); |
344 |
|
mi.setIcon(null); |
345 |
|
m.add(mi); |
346 |
|
|
347 |
|
mi = new JMenuItem(a4n.createAudioDevice); |
348 |
|
mi.setIcon(null); |
349 |
|
m.add(mi); |
350 |
|
|
351 |
|
m.addSeparator(); |
352 |
|
|
353 |
mi = new JMenuItem(a4n.editPreferences); |
mi = new JMenuItem(a4n.editPreferences); |
354 |
mi.setIcon(null); |
mi.setIcon(null); |
355 |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
mi.setAccelerator(KeyStroke.getKeyStroke ( |
357 |
)); |
)); |
358 |
m.add(mi); |
m.add(mi); |
359 |
|
|
360 |
|
// View |
361 |
|
m = new FantasiaMenu(i18n.getMenuLabel("view")); |
362 |
|
menuBar.add(m); |
363 |
|
|
364 |
|
m.add(cbmiToolBarVisible); |
365 |
|
|
366 |
|
cbmiToolBarVisible.addActionListener(new ActionListener() { |
367 |
|
public void |
368 |
|
actionPerformed(ActionEvent e) { |
369 |
|
showToolBar(cbmiToolBarVisible.getState()); |
370 |
|
} |
371 |
|
}); |
372 |
|
|
373 |
|
boolean b = preferences().getBoolProperty("toolBar.visible"); |
374 |
|
cbmiToolBarVisible.setSelected(b); |
375 |
|
showToolBar(b); |
376 |
|
|
377 |
|
cbmiSidePaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
378 |
|
KeyEvent.VK_L, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
379 |
|
)); |
380 |
|
m.add(cbmiSidePaneVisible); |
381 |
|
|
382 |
|
cbmiSidePaneVisible.addActionListener(new ActionListener() { |
383 |
|
public void |
384 |
|
actionPerformed(ActionEvent e) { |
385 |
|
showSidePane(cbmiSidePaneVisible.getState()); |
386 |
|
} |
387 |
|
}); |
388 |
|
|
389 |
|
b = preferences().getBoolProperty("sidePane.visible"); |
390 |
|
cbmiSidePaneVisible.setSelected(b); |
391 |
|
showSidePane(b); |
392 |
|
|
393 |
|
cbmiDevicesPaneVisible.setAccelerator(KeyStroke.getKeyStroke ( |
394 |
|
KeyEvent.VK_R, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK |
395 |
|
)); |
396 |
|
m.add(cbmiDevicesPaneVisible); |
397 |
|
|
398 |
|
cbmiDevicesPaneVisible.addActionListener(new ActionListener() { |
399 |
|
public void |
400 |
|
actionPerformed(ActionEvent e) { |
401 |
|
showDevicesPane(cbmiDevicesPaneVisible.getState()); |
402 |
|
} |
403 |
|
}); |
404 |
|
|
405 |
|
b = preferences().getBoolProperty("devicesPane.visible"); |
406 |
|
cbmiDevicesPaneVisible.setSelected(b); |
407 |
|
showDevicesPane(b); |
408 |
|
|
409 |
|
|
410 |
// Window |
// Window |
411 |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
m = new FantasiaMenu(i18n.getMenuLabel("window")); |
465 |
|
|
466 |
public void |
public void |
467 |
showDetailedErrorMessage(Frame owner, String err, String details) { |
showDetailedErrorMessage(Frame owner, String err, String details) { |
468 |
// TODO: |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
469 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
470 |
|
); |
471 |
|
dlg.setVisible(true); |
472 |
} |
} |
473 |
|
|
474 |
public void |
public void |
475 |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
showDetailedErrorMessage(Dialog owner, String err, String details) { |
476 |
// TODO: |
JSDetailedErrorDlg dlg = new JSDetailedErrorDlg ( |
477 |
|
owner, Res.iconWarning32, i18n.getError("error"), err, details |
478 |
|
); |
479 |
|
dlg.setVisible(true); |
480 |
} |
} |
481 |
|
|
482 |
protected LSConsoleModel |
protected LSConsoleModel |
561 |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
recentScriptsMenu.setEnabled(recentScripts.size() != 0); |
562 |
} |
} |
563 |
|
|
564 |
|
private void |
565 |
|
showToolBar(boolean b) { |
566 |
|
preferences().setBoolProperty("toolBar.visible", b); |
567 |
|
standardBar.setVisible(b); |
568 |
|
} |
569 |
|
|
570 |
|
private void |
571 |
|
showSidePane(boolean b) { |
572 |
|
preferences().setBoolProperty("sidePane.visible", b); |
573 |
|
rootPane.remove(rightPane); |
574 |
|
rootPane.remove(hSplitPane); |
575 |
|
|
576 |
|
if(b) { |
577 |
|
hSplitPane.setRightComponent(rightPane); |
578 |
|
rootPane.add(hSplitPane); |
579 |
|
int i = preferences().getIntProperty("MainFrame.hSplitDividerLocation", 220); |
580 |
|
|
581 |
|
hSplitPane.setDividerLocation(i); |
582 |
|
hSplitPane.validate(); |
583 |
|
} else { |
584 |
|
rootPane.add(rightPane); |
585 |
|
|
586 |
|
} |
587 |
|
|
588 |
|
int w = getPreferredSize().width; |
589 |
|
int h = getSize().height; |
590 |
|
setSize(new Dimension(w, h)); |
591 |
|
|
592 |
|
rootPane.revalidate(); |
593 |
|
rootPane.validate(); |
594 |
|
rootPane.repaint(); |
595 |
|
|
596 |
|
SwingUtilities.invokeLater(new Runnable() { |
597 |
|
public void |
598 |
|
run() { sidePanesVisibilityChanged(); } |
599 |
|
}); |
600 |
|
} |
601 |
|
|
602 |
|
private void |
603 |
|
showDevicesPane(boolean b) { |
604 |
|
preferences().setBoolProperty("devicesPane.visible", b); |
605 |
|
|
606 |
|
int width = sidePane.getWidth(); |
607 |
|
int height = sidePane.getPreferredSize().height; |
608 |
|
if(width != 0) sidePane.setPreferredSize(new Dimension(width, height)); |
609 |
|
|
610 |
|
if(b) { |
611 |
|
int w = preferences().getIntProperty("devicesPane.width", 200); |
612 |
|
|
613 |
|
int h = spDevicesPane.getPreferredSize().height; |
614 |
|
spDevicesPane.setPreferredSize(new Dimension(w, h)); |
615 |
|
} else { |
616 |
|
int w = spDevicesPane.getWidth(); |
617 |
|
if(w > 0 && w < 200) w = 200; |
618 |
|
if(w != 0) preferences().setIntProperty("devicesPane.width", w); |
619 |
|
} |
620 |
|
|
621 |
|
hSplitPane.setResizeWeight(0.0); |
622 |
|
spDevicesPane.setVisible(b); |
623 |
|
hSplitPane.resetToPreferredSizes(); |
624 |
|
|
625 |
|
int w = getPreferredSize().width; |
626 |
|
int h = getSize().height; |
627 |
|
setSize(new Dimension(w, h)); |
628 |
|
|
629 |
|
rootPane.validate(); |
630 |
|
rootPane.repaint(); |
631 |
|
//hSplitPane.validate(); |
632 |
|
|
633 |
|
SwingUtilities.invokeLater(new Runnable() { |
634 |
|
public void |
635 |
|
run() { sidePanesVisibilityChanged(); } |
636 |
|
}); |
637 |
|
} |
638 |
|
|
639 |
|
private void |
640 |
|
sidePanesVisibilityChanged() { |
641 |
|
boolean sidePaneVisible = cbmiSidePaneVisible.isSelected(); |
642 |
|
boolean devicesPaneVisible = cbmiDevicesPaneVisible.isSelected(); |
643 |
|
|
644 |
|
if(sidePaneVisible && devicesPaneVisible) { |
645 |
|
hSplitPane.setResizeWeight(0.5); |
646 |
|
} else if(sidePaneVisible && !devicesPaneVisible) { |
647 |
|
hSplitPane.setResizeWeight(1.0); |
648 |
|
} |
649 |
|
|
650 |
|
if(!sidePaneVisible && !devicesPaneVisible) { |
651 |
|
standardBar.showFantasiaLogo(false); |
652 |
|
if(isResizable()) setResizable(false); |
653 |
|
} else { |
654 |
|
standardBar.showFantasiaLogo(true); |
655 |
|
if(!isResizable()) setResizable(true); |
656 |
|
} |
657 |
|
} |
658 |
|
|
659 |
private class RecentScriptHandler implements ActionListener { |
private class RecentScriptHandler implements ActionListener { |
660 |
private String script; |
private String script; |
661 |
|
|
678 |
} |
} |
679 |
} |
} |
680 |
|
|
681 |
private static class FantasiaMenuBar extends JMenuBar { |
private class FantasiaMenuBar extends JMenuBar { |
682 |
private static Insets pixmapInsets = new Insets(6, 6, 0, 6); |
private Insets pixmapInsets = new Insets(6, 6, 0, 6); |
683 |
|
private Insets pixmapInsets2 = new Insets(6, 6, 6, 6); |
684 |
|
|
685 |
FantasiaMenuBar() { |
FantasiaMenuBar() { |
686 |
setOpaque(false); |
setOpaque(false); |
689 |
protected void |
protected void |
690 |
paintComponent(Graphics g) { |
paintComponent(Graphics g) { |
691 |
super.paintComponent(g); |
super.paintComponent(g); |
692 |
|
if(standardBar.isVisible()) { |
693 |
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
PixmapPane.paintComponent(this, g, Res.gfxMenuBarBg, pixmapInsets); |
694 |
|
} else { |
695 |
|
PixmapPane.paintComponent(this, g, Res.gfxRoundBg14, pixmapInsets2); |
696 |
|
} |
697 |
} |
} |
698 |
} |
} |
699 |
} |
} |