1 |
iliev |
913 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
2288 |
* Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
913 |
* |
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 |
|
|
|
23 |
|
|
package org.jsampler.view.classic; |
24 |
|
|
|
25 |
|
|
import java.awt.Dimension; |
26 |
|
|
|
27 |
|
|
import java.awt.datatransfer.DataFlavor; |
28 |
|
|
|
29 |
|
|
import java.awt.event.ActionEvent; |
30 |
|
|
import java.awt.event.ActionListener; |
31 |
|
|
import java.awt.event.MouseAdapter; |
32 |
|
|
import java.awt.event.MouseEvent; |
33 |
|
|
|
34 |
|
|
import javax.swing.Action; |
35 |
|
|
import javax.swing.BoxLayout; |
36 |
|
|
import javax.swing.JComponent; |
37 |
|
|
import javax.swing.JScrollPane; |
38 |
|
|
import javax.swing.JSplitPane; |
39 |
|
|
import javax.swing.JToolBar; |
40 |
|
|
import javax.swing.TransferHandler; |
41 |
|
|
|
42 |
|
|
import javax.swing.event.ListSelectionEvent; |
43 |
|
|
import javax.swing.event.ListSelectionListener; |
44 |
|
|
|
45 |
iliev |
2288 |
import net.sf.juife.swing.LinkButton; |
46 |
|
|
import net.sf.juife.swing.NavigationPage; |
47 |
iliev |
913 |
|
48 |
iliev |
2288 |
import org.jsampler.view.swing.InstrumentTable; |
49 |
|
|
import org.jsampler.view.swing.OrchestraTable; |
50 |
iliev |
913 |
|
51 |
iliev |
1285 |
import org.jsampler.view.std.JSManageOrchestrasPane; |
52 |
|
|
import org.jsampler.view.std.JSOrchestraPane; |
53 |
|
|
|
54 |
iliev |
913 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* |
59 |
|
|
* @author Grigor Iliev |
60 |
|
|
*/ |
61 |
|
|
public class ManageOrchestrasPage extends NavigationPage { |
62 |
|
|
private final JComponent manageOrchestrasPane; |
63 |
iliev |
1285 |
OrchestraTable orchestraTable; |
64 |
iliev |
913 |
|
65 |
|
|
private LinkButton lnkOrchestras = |
66 |
|
|
new LinkButton(i18n.getButtonLabel("ManageOrchestrasPage.lnkOrchestras")); |
67 |
|
|
|
68 |
iliev |
1285 |
private OrchestraPane orchestraPane = new OrchestraPane(); |
69 |
iliev |
913 |
|
70 |
|
|
|
71 |
|
|
/** Creates a new instance of <code>ManageOrchestrasPage</code>. */ |
72 |
|
|
public ManageOrchestrasPage() { |
73 |
|
|
setTitle(i18n.getLabel("ManageOrchestrasPage.title")); |
74 |
|
|
|
75 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
76 |
|
|
|
77 |
|
|
manageOrchestrasPane = createManageOrchestrasPane(); |
78 |
|
|
add(manageOrchestrasPane); |
79 |
|
|
|
80 |
|
|
installListeneres(); |
81 |
|
|
} |
82 |
|
|
|
83 |
iliev |
1285 |
class ManageOrchestrasPane extends JSManageOrchestrasPane { |
84 |
|
|
ManageOrchestrasPane() { |
85 |
|
|
actionAddOrchestra.putValue(Action.SMALL_ICON, Res.iconNew16); |
86 |
|
|
actionEditOrchestra.putValue(Action.SMALL_ICON, Res.iconEdit16); |
87 |
|
|
actionDeleteOrchestra.putValue(Action.SMALL_ICON, Res.iconDelete16); |
88 |
|
|
actionOrchestraUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
89 |
|
|
actionOrchestraDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
90 |
|
|
|
91 |
|
|
removeAll(); |
92 |
|
|
|
93 |
|
|
JToolBar toolBar = new JToolBar(); |
94 |
|
|
toolBar.add(new ToolbarButton(actionAddOrchestra)); |
95 |
|
|
toolBar.add(new ToolbarButton(actionEditOrchestra)); |
96 |
|
|
toolBar.add(new ToolbarButton(actionDeleteOrchestra)); |
97 |
|
|
|
98 |
|
|
toolBar.addSeparator(); |
99 |
|
|
|
100 |
|
|
toolBar.add(new ToolbarButton(actionOrchestraUp)); |
101 |
|
|
toolBar.add(new ToolbarButton(actionOrchestraDown)); |
102 |
|
|
|
103 |
|
|
toolBar.setFloatable(false); |
104 |
|
|
add(toolBar, java.awt.BorderLayout.NORTH); |
105 |
|
|
|
106 |
|
|
JScrollPane sp = new JScrollPane(orchestraTable); |
107 |
|
|
Dimension d; |
108 |
|
|
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
109 |
|
|
sp.setPreferredSize(d); |
110 |
|
|
|
111 |
|
|
add(sp); |
112 |
|
|
|
113 |
|
|
ManageOrchestrasPage.this.orchestraTable = this.orchestraTable; |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
class OrchestraPane extends JSOrchestraPane { |
118 |
|
|
OrchestraPane() { |
119 |
|
|
actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16); |
120 |
|
|
actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16); |
121 |
|
|
actionDeleteInstrument.putValue(Action.SMALL_ICON, Res.iconDelete16); |
122 |
|
|
actionInstrumentUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
123 |
|
|
actionInstrumentDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
124 |
|
|
|
125 |
|
|
removeAll(); |
126 |
|
|
|
127 |
|
|
JToolBar toolBar = new JToolBar(); |
128 |
|
|
toolBar.add(new ToolbarButton(actionAddInstrument)); |
129 |
|
|
toolBar.add(new ToolbarButton(actionEditInstrument)); |
130 |
|
|
toolBar.add(new ToolbarButton(actionDeleteInstrument)); |
131 |
|
|
|
132 |
|
|
toolBar.addSeparator(); |
133 |
|
|
|
134 |
|
|
toolBar.add(new ToolbarButton(actionInstrumentUp)); |
135 |
|
|
toolBar.add(new ToolbarButton(actionInstrumentDown)); |
136 |
|
|
|
137 |
|
|
toolBar.setFloatable(false); |
138 |
|
|
add(toolBar, java.awt.BorderLayout.NORTH); |
139 |
|
|
|
140 |
|
|
JScrollPane sp = new JScrollPane(instrumentTable); |
141 |
|
|
Dimension d; |
142 |
|
|
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
143 |
|
|
sp.setPreferredSize(d); |
144 |
|
|
|
145 |
|
|
add(sp); |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
iliev |
913 |
private JComponent |
150 |
|
|
createManageOrchestrasPane() { |
151 |
|
|
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
152 |
iliev |
1143 |
splitPane.setContinuousLayout(true); |
153 |
iliev |
1285 |
splitPane.setTopComponent(new ManageOrchestrasPane()); |
154 |
|
|
splitPane.setBottomComponent(orchestraPane); |
155 |
iliev |
913 |
splitPane.setDividerSize(3); |
156 |
|
|
splitPane.setDividerLocation(180); |
157 |
|
|
|
158 |
|
|
return splitPane; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
private void |
162 |
|
|
installListeneres() { |
163 |
|
|
lnkOrchestras.addActionListener(new ActionListener() { |
164 |
|
|
public void |
165 |
|
|
actionPerformed(ActionEvent e) { |
166 |
|
|
LeftPane.getLeftPane().showOrchestrasPage(); |
167 |
|
|
} |
168 |
|
|
}); |
169 |
|
|
|
170 |
|
|
OrchestraSelectionHandler l = new OrchestraSelectionHandler(); |
171 |
|
|
orchestraTable.getSelectionModel().addListSelectionListener(l); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
public class DnDScrollPane extends JScrollPane { |
175 |
|
|
private InstrumentTable instrumentTable; |
176 |
|
|
|
177 |
|
|
private |
178 |
|
|
DnDScrollPane(InstrumentTable table) { |
179 |
|
|
instrumentTable = table; |
180 |
|
|
setViewport(new DnDViewPort()); |
181 |
|
|
setViewportView(instrumentTable); |
182 |
|
|
|
183 |
|
|
Dimension d; |
184 |
|
|
d = new Dimension(getMinimumSize().width, getPreferredSize().height); |
185 |
|
|
setPreferredSize(d); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
public class DnDViewPort extends javax.swing.JViewport { |
189 |
|
|
private |
190 |
|
|
DnDViewPort() { |
191 |
|
|
setTransferHandler(new TransferHandler("instrument") { |
192 |
|
|
public boolean |
193 |
|
|
canImport(JComponent comp, DataFlavor[] flavors) { |
194 |
|
|
if(instrumentTable.isPerformingDnD()) return false; |
195 |
iliev |
1285 |
|
196 |
|
|
if(orchestraPane.getSelectedInstrument() == null) { |
197 |
|
|
return false; |
198 |
|
|
} |
199 |
iliev |
913 |
|
200 |
|
|
return super.canImport(comp, flavors); |
201 |
|
|
} |
202 |
|
|
}); |
203 |
|
|
|
204 |
|
|
addMouseListener(new MouseAdapter() { |
205 |
|
|
public void |
206 |
|
|
mouseClicked(MouseEvent e) { |
207 |
|
|
instrumentTable.clearSelection(); |
208 |
|
|
} |
209 |
|
|
}); |
210 |
|
|
} |
211 |
|
|
|
212 |
|
|
public String |
213 |
|
|
getInstrument() { return null; } |
214 |
|
|
|
215 |
|
|
public void |
216 |
|
|
setInstrument(String instr) { |
217 |
|
|
instrumentTable.setSelectedInstrument(null); |
218 |
|
|
instrumentTable.setInstrument(instr); |
219 |
|
|
} |
220 |
|
|
} |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
private class OrchestraSelectionHandler implements ListSelectionListener { |
224 |
|
|
public void |
225 |
|
|
valueChanged(ListSelectionEvent e) { |
226 |
|
|
if(e.getValueIsAdjusting()) return; |
227 |
|
|
|
228 |
iliev |
1285 |
orchestraPane.setOrchestra(orchestraTable.getSelectedOrchestra()); |
229 |
iliev |
913 |
} |
230 |
|
|
} |
231 |
|
|
} |