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