1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
package org.jsampler.view.fantasia; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
|
26 |
import javax.swing.JMenuBar; |
27 |
import javax.swing.JPanel; |
28 |
import javax.swing.JScrollPane; |
29 |
import javax.swing.JSplitPane; |
30 |
import javax.swing.event.TreeSelectionEvent; |
31 |
import javax.swing.event.TreeSelectionListener; |
32 |
import javax.swing.tree.TreePath; |
33 |
|
34 |
import org.jsampler.CC; |
35 |
import org.jsampler.view.SamplerTreeModel; |
36 |
import org.jsampler.view.SamplerTreeModel.TreeNodeBase; |
37 |
import org.jsampler.view.std.JSFrame; |
38 |
import org.jsampler.view.std.JSSamplerTable; |
39 |
|
40 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
41 |
|
42 |
/** |
43 |
* |
44 |
* @author Grigor Iliev |
45 |
*/ |
46 |
public class SamplerBrowserFrame extends JSFrame { |
47 |
private final JMenuBar menuBar = new JMenuBar(); |
48 |
|
49 |
private final SidePane sidePane; |
50 |
private final JSplitPane splitPane; |
51 |
private final MainPane mainPane; |
52 |
|
53 |
private final FantasiaSamplerTree samplerTree = new FantasiaSamplerTree(new SamplerTreeModel()); |
54 |
private final JSSamplerTable samplerTable = new JSSamplerTable(samplerTree); |
55 |
|
56 |
/** |
57 |
* Creates a new instance of <code>InstrumentsDbFrame</code> |
58 |
*/ |
59 |
public |
60 |
SamplerBrowserFrame() { |
61 |
super(i18n.getLabel("SamplerBrowserFrame.title"), "SamplerBrowserFrame"); |
62 |
if(Res.iconAppIcon != null) setIconImage(Res.iconAppIcon.getImage()); |
63 |
|
64 |
((ViewConfig)CC.getViewConfig()).restoreMenuProperties(); |
65 |
|
66 |
sidePane = new SidePane(); |
67 |
mainPane = new MainPane(); |
68 |
|
69 |
splitPane = new JSplitPane ( |
70 |
JSplitPane.HORIZONTAL_SPLIT, |
71 |
true, // continuousLayout |
72 |
sidePane, |
73 |
mainPane |
74 |
); |
75 |
|
76 |
splitPane.setDividerSize(3); |
77 |
splitPane.setDividerLocation(200); |
78 |
|
79 |
// fix for moving the menu bar on top of the screen |
80 |
// when running on Mac OS and third party plugin is used |
81 |
((ViewConfig)CC.getViewConfig()).setNativeMenuProperties(); |
82 |
|
83 |
addMenu(); |
84 |
|
85 |
pack(); |
86 |
|
87 |
getContentPane().add(splitPane); |
88 |
} |
89 |
|
90 |
|
91 |
|
92 |
private void |
93 |
addMenu() { } |
94 |
|
95 |
class MainPane extends JPanel implements TreeSelectionListener { |
96 |
MainPane() { |
97 |
setLayout(new BorderLayout()); |
98 |
add(new JScrollPane(samplerTable)); |
99 |
|
100 |
samplerTree.getSelectionModel().addTreeSelectionListener(this); |
101 |
TreePath path = samplerTree.getSelectionPath(); |
102 |
if(path != null) samplerTable.setNode((TreeNodeBase)path.getLastPathComponent()); |
103 |
} |
104 |
|
105 |
public void |
106 |
valueChanged(TreeSelectionEvent e) { |
107 |
if(e.getNewLeadSelectionPath() == null) { |
108 |
samplerTable.setNode(null); |
109 |
return; |
110 |
} |
111 |
|
112 |
samplerTable.setNode((TreeNodeBase)e.getNewLeadSelectionPath().getLastPathComponent()); |
113 |
} |
114 |
} |
115 |
|
116 |
|
117 |
class SidePane extends JPanel { |
118 |
SidePane() { |
119 |
setLayout(new BorderLayout()); |
120 |
add(new JScrollPane(samplerTree)); |
121 |
} |
122 |
} |
123 |
} |