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.fantasia; |
24 |
|
25 |
import java.awt.BorderLayout; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.Graphics; |
28 |
import java.awt.Insets; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
|
33 |
import java.beans.PropertyChangeEvent; |
34 |
import java.beans.PropertyChangeListener; |
35 |
|
36 |
import javax.swing.Action; |
37 |
import javax.swing.BorderFactory; |
38 |
import javax.swing.Box; |
39 |
import javax.swing.BoxLayout; |
40 |
import javax.swing.JButton; |
41 |
import javax.swing.JComboBox; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JScrollPane; |
44 |
import javax.swing.JToolBar; |
45 |
|
46 |
import org.jsampler.CC; |
47 |
import org.jsampler.DefaultOrchestraModel; |
48 |
import org.jsampler.OrchestraModel; |
49 |
|
50 |
import org.jsampler.event.OrchestraAdapter; |
51 |
import org.jsampler.event.OrchestraEvent; |
52 |
import org.jsampler.event.ListEvent; |
53 |
import org.jsampler.event.ListListener; |
54 |
|
55 |
import org.jsampler.view.InstrumentTable; |
56 |
import org.jsampler.view.InstrumentTableModel; |
57 |
|
58 |
import org.jsampler.view.std.JSManageOrchestrasPane; |
59 |
import org.jsampler.view.std.JSOrchestraPane; |
60 |
|
61 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
62 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
63 |
|
64 |
|
65 |
/** |
66 |
* |
67 |
* @author Grigor Iliev |
68 |
*/ |
69 |
public class OrchestrasPane extends JPanel { |
70 |
private final JPanel taskPaneContainer = new JPanel(); |
71 |
private final TaskPane orchestrasTaskPane = new TaskPane(); |
72 |
|
73 |
private ManageOrchestrasPane manageOrchestrasPane = new ManageOrchestrasPane(); |
74 |
|
75 |
private final JComboBox cbOrchestras = new JComboBox(); |
76 |
private final OrchestraPane orchestraPane = new OrchestraPane(); |
77 |
|
78 |
/** |
79 |
* Because the orchestras are added after the view is created, |
80 |
* we need to remember the orchestra used in the previous session. |
81 |
*/ |
82 |
private int orchIdx; |
83 |
|
84 |
/** Creates a new instance of <code>OrchestrasPane</code> */ |
85 |
public |
86 |
OrchestrasPane() { |
87 |
setLayout(new BorderLayout()); |
88 |
setOpaque(false); |
89 |
|
90 |
orchestrasTaskPane.setTitle(i18n.getLabel("OrchestrasPane.orchestrasTaskPane")); |
91 |
orchestrasTaskPane.add(manageOrchestrasPane); |
92 |
boolean b; |
93 |
orchestrasTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
94 |
b = preferences().getBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded"); |
95 |
orchestrasTaskPane.setExpanded(b); |
96 |
|
97 |
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
98 |
public void |
99 |
propertyChange(PropertyChangeEvent e) { |
100 |
boolean b = preferences().getBoolProperty(ANIMATED); |
101 |
orchestrasTaskPane.setAnimated(b); |
102 |
} |
103 |
}); |
104 |
|
105 |
taskPaneContainer.setOpaque(false); |
106 |
taskPaneContainer.setLayout(new BorderLayout()); |
107 |
taskPaneContainer.add(orchestrasTaskPane); |
108 |
taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
109 |
|
110 |
add(taskPaneContainer, BorderLayout.NORTH); |
111 |
add(new InstrumentsPane()); |
112 |
|
113 |
orchIdx = preferences().getIntProperty("OrchestrasPane.OrchestraIndex", 0); |
114 |
|
115 |
cbOrchestras.addActionListener(new ActionListener() { |
116 |
public void |
117 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
118 |
}); |
119 |
|
120 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
121 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
122 |
} |
123 |
|
124 |
CC.getOrchestras().addOrchestraListListener(getHandler()); |
125 |
cbOrchestras.setEnabled(cbOrchestras.getItemCount() != 0); |
126 |
|
127 |
|
128 |
if(CC.getOrchestras().getOrchestraCount() > orchIdx) { |
129 |
cbOrchestras.setSelectedIndex(orchIdx); |
130 |
orchIdx = -1; |
131 |
} |
132 |
} |
133 |
|
134 |
public void |
135 |
savePreferences() { |
136 |
boolean b = orchestrasTaskPane.isExpanded(); |
137 |
preferences().setBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded", b); |
138 |
} |
139 |
|
140 |
private void |
141 |
orchestraChanged() { |
142 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
143 |
orchestraPane.setOrchestra(om); |
144 |
|
145 |
if(om != null) { |
146 |
String s = om.getDescription(); |
147 |
if(s != null && s.length() == 0) s = null; |
148 |
cbOrchestras.setToolTipText(s); |
149 |
} |
150 |
|
151 |
int i = cbOrchestras.getSelectedIndex(); |
152 |
if(i >= 0) preferences().setIntProperty("OrchestrasPane.OrchestraIndex", i); |
153 |
} |
154 |
|
155 |
class InstrumentsPane extends JPanel { |
156 |
InstrumentsPane() { |
157 |
setOpaque(false); |
158 |
setLayout(new BorderLayout()); |
159 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
160 |
|
161 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
162 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
163 |
p.setLayout(new BorderLayout()); |
164 |
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
165 |
|
166 |
PixmapPane p2 = new PixmapPane(Res.gfxRoundBg7); |
167 |
p2.setPixmapInsets(new Insets(3, 3, 3, 3)); |
168 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
169 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
170 |
p2.add(cbOrchestras); |
171 |
p2.add(Box.createRigidArea(new Dimension(0, 5))); |
172 |
p2.add(orchestraPane); |
173 |
|
174 |
add(p2); |
175 |
} |
176 |
} |
177 |
|
178 |
static class ToolBar extends JToolBar { |
179 |
private static Insets pixmapInsets = new Insets(1, 1, 1, 1); |
180 |
|
181 |
ToolBar() { |
182 |
setFloatable(false); |
183 |
setOpaque(false); |
184 |
setPreferredSize(new Dimension(77, 29)); |
185 |
setMinimumSize(getPreferredSize()); |
186 |
} |
187 |
|
188 |
protected void |
189 |
paintComponent(Graphics g) { |
190 |
super.paintComponent(g); |
191 |
|
192 |
PixmapPane.paintComponent(this, g, Res.gfxCreateChannel, pixmapInsets); |
193 |
} |
194 |
} |
195 |
|
196 |
class ManageOrchestrasPane extends JSManageOrchestrasPane { |
197 |
ManageOrchestrasPane() { |
198 |
actionAddOrchestra.putValue(Action.SMALL_ICON, Res.iconNew16); |
199 |
actionEditOrchestra.putValue(Action.SMALL_ICON, Res.iconEdit16); |
200 |
actionDeleteOrchestra.putValue(Action.SMALL_ICON, Res.iconDelete16); |
201 |
|
202 |
removeAll(); |
203 |
|
204 |
ToolBar toolBar = new ToolBar(); |
205 |
toolBar.add(new ToolbarButton(actionAddOrchestra)); |
206 |
toolBar.add(new ToolbarButton(actionEditOrchestra)); |
207 |
toolBar.add(new ToolbarButton(actionDeleteOrchestra)); |
208 |
add(toolBar, BorderLayout.NORTH); |
209 |
|
210 |
JScrollPane sp = new JScrollPane(orchestraTable); |
211 |
sp.setPreferredSize(new Dimension(120, 130)); |
212 |
|
213 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
214 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
215 |
p.setLayout(new BorderLayout()); |
216 |
p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
217 |
|
218 |
PixmapPane p2 = new PixmapPane(Res.gfxBorder); |
219 |
p2.setPixmapInsets(new Insets(1, 1, 1, 1)); |
220 |
p2.setLayout(new BorderLayout()); |
221 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
222 |
p2.add(sp); |
223 |
p.add(p2); |
224 |
|
225 |
add(p); |
226 |
} |
227 |
} |
228 |
|
229 |
class OrchestraPane extends JSOrchestraPane { |
230 |
OrchestraPane() { |
231 |
actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16); |
232 |
actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16); |
233 |
actionDeleteInstrument.putValue(Action.SMALL_ICON, Res.iconDelete16); |
234 |
//actionInstrumentUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
235 |
//actionInstrumentDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
236 |
|
237 |
removeAll(); |
238 |
|
239 |
ToolBar toolBar = new ToolBar(); |
240 |
toolBar.add(new ToolbarButton(actionAddInstrument)); |
241 |
toolBar.add(new ToolbarButton(actionEditInstrument)); |
242 |
toolBar.add(new ToolbarButton(actionDeleteInstrument)); |
243 |
|
244 |
//toolBar.addSeparator(); |
245 |
|
246 |
//toolBar.add(new ToolbarButton(actionInstrumentUp)); |
247 |
//toolBar.add(new ToolbarButton(actionInstrumentDown)); |
248 |
|
249 |
toolBar.setFloatable(false); |
250 |
add(toolBar, java.awt.BorderLayout.NORTH); |
251 |
|
252 |
JScrollPane sp = new JScrollPane(instrumentTable); |
253 |
Dimension d; |
254 |
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
255 |
sp.setPreferredSize(d); |
256 |
|
257 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
258 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
259 |
p.setLayout(new BorderLayout()); |
260 |
p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
261 |
|
262 |
PixmapPane p2 = new PixmapPane(Res.gfxBorder); |
263 |
p2.setPixmapInsets(new Insets(1, 1, 1, 1)); |
264 |
p2.setLayout(new BorderLayout()); |
265 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
266 |
p2.add(sp); |
267 |
p.add(p2); |
268 |
|
269 |
add(p); |
270 |
} |
271 |
} |
272 |
|
273 |
private final Handler eventHandler = new Handler(); |
274 |
|
275 |
private Handler |
276 |
getHandler() { return eventHandler; } |
277 |
|
278 |
private class Handler extends OrchestraAdapter implements ListListener<OrchestraModel> { |
279 |
/** Invoked when an orchestra is added to the orchestra list. */ |
280 |
public void |
281 |
entryAdded(ListEvent<OrchestraModel> e) { |
282 |
if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(true); |
283 |
cbOrchestras.addItem(e.getEntry()); |
284 |
|
285 |
// we do this because the orchestras are added after creation of the view. |
286 |
if(orchIdx != -1 && cbOrchestras.getItemCount() > orchIdx) { |
287 |
cbOrchestras.setSelectedIndex(orchIdx); |
288 |
orchIdx = -1; |
289 |
} |
290 |
} |
291 |
|
292 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
293 |
public void |
294 |
entryRemoved(ListEvent<OrchestraModel> e) { |
295 |
cbOrchestras.removeItem(e.getEntry()); |
296 |
if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(false); |
297 |
|
298 |
if(orchIdx != -1) orchIdx = -1; |
299 |
} |
300 |
|
301 |
/** Invoked when the name of orchestra is changed. */ |
302 |
public void |
303 |
nameChanged(OrchestraEvent e) { |
304 |
|
305 |
} |
306 |
|
307 |
/** Invoked when the description of orchestra is changed. */ |
308 |
public void |
309 |
descriptionChanged(OrchestraEvent e) { } |
310 |
|
311 |
|
312 |
} |
313 |
} |