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