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 |
/** Creates a new instance of <code>OrchestrasPane</code> */ |
79 |
public |
80 |
OrchestrasPane() { |
81 |
setLayout(new BorderLayout()); |
82 |
setOpaque(false); |
83 |
|
84 |
orchestrasTaskPane.setTitle(i18n.getLabel("OrchestrasPane.orchestrasTaskPane")); |
85 |
orchestrasTaskPane.add(manageOrchestrasPane); |
86 |
boolean b; |
87 |
orchestrasTaskPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
88 |
b = preferences().getBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded"); |
89 |
orchestrasTaskPane.setExpanded(b); |
90 |
|
91 |
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
92 |
public void |
93 |
propertyChange(PropertyChangeEvent e) { |
94 |
boolean b = preferences().getBoolProperty(ANIMATED); |
95 |
orchestrasTaskPane.setAnimated(b); |
96 |
} |
97 |
}); |
98 |
|
99 |
taskPaneContainer.setOpaque(false); |
100 |
taskPaneContainer.setLayout(new BorderLayout()); |
101 |
taskPaneContainer.add(orchestrasTaskPane); |
102 |
taskPaneContainer.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
103 |
|
104 |
add(taskPaneContainer, BorderLayout.NORTH); |
105 |
add(new InstrumentsPane()); |
106 |
|
107 |
cbOrchestras.addActionListener(new ActionListener() { |
108 |
public void |
109 |
actionPerformed(ActionEvent e) { orchestraChanged(); } |
110 |
}); |
111 |
|
112 |
for(int i = 0; i < CC.getOrchestras().getOrchestraCount(); i++) { |
113 |
cbOrchestras.addItem(CC.getOrchestras().getOrchestra(i)); |
114 |
} |
115 |
|
116 |
CC.getOrchestras().addOrchestraListListener(getHandler()); |
117 |
cbOrchestras.setEnabled(cbOrchestras.getItemCount() != 0); |
118 |
} |
119 |
|
120 |
public void |
121 |
savePreferences() { |
122 |
boolean b = orchestrasTaskPane.isExpanded(); |
123 |
preferences().setBoolProperty("OrchestrasPane.orchestrasTaskPane.expanded", b); |
124 |
} |
125 |
|
126 |
private void |
127 |
orchestraChanged() { |
128 |
OrchestraModel om = (OrchestraModel)cbOrchestras.getSelectedItem(); |
129 |
orchestraPane.setOrchestra(om); |
130 |
|
131 |
if(om != null) { |
132 |
String s = om.getDescription(); |
133 |
if(s != null && s.length() == 0) s = null; |
134 |
cbOrchestras.setToolTipText(s); |
135 |
} |
136 |
} |
137 |
|
138 |
class InstrumentsPane extends JPanel { |
139 |
InstrumentsPane() { |
140 |
setOpaque(false); |
141 |
setLayout(new BorderLayout()); |
142 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
143 |
|
144 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
145 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
146 |
p.setLayout(new BorderLayout()); |
147 |
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
148 |
|
149 |
PixmapPane p2 = new PixmapPane(Res.gfxRoundBg7); |
150 |
p2.setPixmapInsets(new Insets(3, 3, 3, 3)); |
151 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
152 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
153 |
p2.add(cbOrchestras); |
154 |
p2.add(Box.createRigidArea(new Dimension(0, 5))); |
155 |
p2.add(orchestraPane); |
156 |
|
157 |
add(p2); |
158 |
} |
159 |
} |
160 |
|
161 |
static class ToolBar extends JToolBar { |
162 |
private static Insets pixmapInsets = new Insets(1, 1, 1, 1); |
163 |
|
164 |
ToolBar() { |
165 |
setFloatable(false); |
166 |
setOpaque(false); |
167 |
setPreferredSize(new Dimension(77, 29)); |
168 |
setMinimumSize(getPreferredSize()); |
169 |
} |
170 |
|
171 |
protected void |
172 |
paintComponent(Graphics g) { |
173 |
super.paintComponent(g); |
174 |
|
175 |
PixmapPane.paintComponent(this, g, Res.gfxCreateChannel, pixmapInsets); |
176 |
} |
177 |
} |
178 |
|
179 |
class ManageOrchestrasPane extends JSManageOrchestrasPane { |
180 |
ManageOrchestrasPane() { |
181 |
actionAddOrchestra.putValue(Action.SMALL_ICON, Res.iconNew16); |
182 |
actionEditOrchestra.putValue(Action.SMALL_ICON, Res.iconEdit16); |
183 |
actionDeleteOrchestra.putValue(Action.SMALL_ICON, Res.iconDelete16); |
184 |
|
185 |
removeAll(); |
186 |
|
187 |
ToolBar toolBar = new ToolBar(); |
188 |
toolBar.add(new ToolbarButton(actionAddOrchestra)); |
189 |
toolBar.add(new ToolbarButton(actionEditOrchestra)); |
190 |
toolBar.add(new ToolbarButton(actionDeleteOrchestra)); |
191 |
add(toolBar, BorderLayout.NORTH); |
192 |
|
193 |
JScrollPane sp = new JScrollPane(orchestraTable); |
194 |
sp.setPreferredSize(new Dimension(120, 130)); |
195 |
|
196 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
197 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
198 |
p.setLayout(new BorderLayout()); |
199 |
p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
200 |
|
201 |
PixmapPane p2 = new PixmapPane(Res.gfxBorder); |
202 |
p2.setPixmapInsets(new Insets(1, 1, 1, 1)); |
203 |
p2.setLayout(new BorderLayout()); |
204 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
205 |
p2.add(sp); |
206 |
p.add(p2); |
207 |
|
208 |
add(p); |
209 |
} |
210 |
} |
211 |
|
212 |
class OrchestraPane extends JSOrchestraPane { |
213 |
OrchestraPane() { |
214 |
actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16); |
215 |
actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16); |
216 |
actionDeleteInstrument.putValue(Action.SMALL_ICON, Res.iconDelete16); |
217 |
//actionInstrumentUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
218 |
//actionInstrumentDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
219 |
|
220 |
removeAll(); |
221 |
|
222 |
ToolBar toolBar = new ToolBar(); |
223 |
toolBar.add(new ToolbarButton(actionAddInstrument)); |
224 |
toolBar.add(new ToolbarButton(actionEditInstrument)); |
225 |
toolBar.add(new ToolbarButton(actionDeleteInstrument)); |
226 |
|
227 |
//toolBar.addSeparator(); |
228 |
|
229 |
//toolBar.add(new ToolbarButton(actionInstrumentUp)); |
230 |
//toolBar.add(new ToolbarButton(actionInstrumentDown)); |
231 |
|
232 |
toolBar.setFloatable(false); |
233 |
add(toolBar, java.awt.BorderLayout.NORTH); |
234 |
|
235 |
JScrollPane sp = new JScrollPane(instrumentTable); |
236 |
Dimension d; |
237 |
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
238 |
sp.setPreferredSize(d); |
239 |
|
240 |
PixmapPane p = new PixmapPane(Res.gfxChannelOptions); |
241 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
242 |
p.setLayout(new BorderLayout()); |
243 |
p.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
244 |
|
245 |
PixmapPane p2 = new PixmapPane(Res.gfxBorder); |
246 |
p2.setPixmapInsets(new Insets(1, 1, 1, 1)); |
247 |
p2.setLayout(new BorderLayout()); |
248 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
249 |
p2.add(sp); |
250 |
p.add(p2); |
251 |
|
252 |
add(p); |
253 |
} |
254 |
} |
255 |
|
256 |
private final Handler eventHandler = new Handler(); |
257 |
|
258 |
private Handler |
259 |
getHandler() { return eventHandler; } |
260 |
|
261 |
private class Handler extends OrchestraAdapter implements ListListener<OrchestraModel> { |
262 |
/** Invoked when an orchestra is added to the orchestra list. */ |
263 |
public void |
264 |
entryAdded(ListEvent<OrchestraModel> e) { |
265 |
if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(true); |
266 |
cbOrchestras.addItem(e.getEntry()); |
267 |
} |
268 |
|
269 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
270 |
public void |
271 |
entryRemoved(ListEvent<OrchestraModel> e) { |
272 |
cbOrchestras.removeItem(e.getEntry()); |
273 |
if(cbOrchestras.getItemCount() == 0) cbOrchestras.setEnabled(false); |
274 |
} |
275 |
|
276 |
/** Invoked when the name of orchestra is changed. */ |
277 |
public void |
278 |
nameChanged(OrchestraEvent e) { |
279 |
|
280 |
} |
281 |
|
282 |
/** Invoked when the description of orchestra is changed. */ |
283 |
public void |
284 |
descriptionChanged(OrchestraEvent e) { } |
285 |
|
286 |
|
287 |
} |
288 |
} |