1 |
iliev |
1286 |
/* |
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.Dimension; |
26 |
|
|
import java.awt.Insets; |
27 |
|
|
|
28 |
|
|
import java.awt.event.ActionEvent; |
29 |
|
|
import java.awt.event.ActionListener; |
30 |
|
|
|
31 |
|
|
import java.beans.PropertyChangeEvent; |
32 |
|
|
import java.beans.PropertyChangeListener; |
33 |
|
|
|
34 |
|
|
import javax.swing.BorderFactory; |
35 |
|
|
import javax.swing.Box; |
36 |
|
|
import javax.swing.BoxLayout; |
37 |
iliev |
1688 |
import javax.swing.JButton; |
38 |
iliev |
1286 |
import javax.swing.JPanel; |
39 |
|
|
|
40 |
|
|
import org.jdesktop.swingx.JXCollapsiblePane; |
41 |
|
|
|
42 |
iliev |
1785 |
import org.jsampler.view.fantasia.basic.FantasiaLabel; |
43 |
|
|
import org.jsampler.view.fantasia.basic.PixmapToggleButton; |
44 |
|
|
import org.jsampler.view.fantasia.basic.PixmapPane; |
45 |
|
|
|
46 |
iliev |
1286 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
47 |
|
|
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
48 |
|
|
|
49 |
|
|
/** |
50 |
|
|
* |
51 |
|
|
* @author Grigor Iliev |
52 |
|
|
*/ |
53 |
|
|
public class DevicePane extends JPanel { |
54 |
|
|
private final PowerButton btnDestroy; |
55 |
|
|
private final OptionsButton btnOptions = new OptionsButton(); |
56 |
|
|
private final FantasiaLabel lDevName; |
57 |
|
|
|
58 |
|
|
private final JXCollapsiblePane mainPane = new JXCollapsiblePane(); |
59 |
|
|
private final JXCollapsiblePane optionsPane = new JXCollapsiblePane(); |
60 |
iliev |
1688 |
private final JXCollapsiblePane confirmPane = new JXCollapsiblePane(); |
61 |
|
|
private final ConfirmRemovalPane confirmRemovalPane = new ConfirmRemovalPane(); |
62 |
iliev |
1286 |
|
63 |
|
|
/** Creates a new instance of <code>DevicePane</code> */ |
64 |
|
|
public |
65 |
|
|
DevicePane() { |
66 |
|
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
67 |
|
|
|
68 |
|
|
mainPane.getContentPane().setLayout ( |
69 |
|
|
new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS) |
70 |
|
|
); |
71 |
|
|
|
72 |
|
|
PixmapPane p = new PixmapPane(Res.gfxDeviceBg); |
73 |
|
|
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
74 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
75 |
|
|
p.add(Box.createRigidArea(new Dimension(3, 0))); |
76 |
|
|
btnDestroy = new PowerButton(); |
77 |
|
|
p.add(btnDestroy); |
78 |
|
|
p.add(Box.createRigidArea(new Dimension(3, 0))); |
79 |
|
|
|
80 |
|
|
p.add(createVSeparator()); |
81 |
|
|
|
82 |
|
|
p.add(Box.createRigidArea(new Dimension(6, 0))); |
83 |
|
|
|
84 |
iliev |
1496 |
lDevName = new FantasiaLabel("", true); |
85 |
iliev |
1286 |
lDevName.setOpaque(false); |
86 |
|
|
lDevName.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
87 |
|
|
Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height); |
88 |
|
|
lDevName.setMaximumSize(d); |
89 |
iliev |
1445 |
lDevName.setMinimumSize(new Dimension(70, lDevName.getPreferredSize().height)); |
90 |
iliev |
1286 |
p.add(lDevName); |
91 |
|
|
|
92 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
93 |
|
|
|
94 |
|
|
p.add(btnOptions); |
95 |
|
|
|
96 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
97 |
|
|
|
98 |
|
|
d = new Dimension(77, 24); |
99 |
|
|
p.setPreferredSize(d); |
100 |
|
|
p.setMinimumSize(d); |
101 |
|
|
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 24)); |
102 |
|
|
p.setAlignmentX(LEFT_ALIGNMENT); |
103 |
|
|
mainPane.add(p); |
104 |
|
|
|
105 |
|
|
optionsPane.setAlignmentX(LEFT_ALIGNMENT); |
106 |
|
|
|
107 |
iliev |
1688 |
initCollasiblePane(optionsPane); |
108 |
iliev |
1286 |
|
109 |
|
|
mainPane.add(optionsPane); |
110 |
|
|
|
111 |
iliev |
1688 |
JPanel p2 = new JPanel(); |
112 |
|
|
|
113 |
|
|
confirmPane.setContentPane(confirmRemovalPane); |
114 |
|
|
confirmPane.setAlignmentX(LEFT_ALIGNMENT); |
115 |
|
|
initCollasiblePane(confirmPane); |
116 |
|
|
|
117 |
|
|
mainPane.add(confirmPane); |
118 |
|
|
|
119 |
iliev |
1286 |
add(mainPane); |
120 |
|
|
|
121 |
iliev |
1688 |
initCollasiblePane(mainPane); |
122 |
iliev |
1286 |
mainPane.setCollapsed(false); |
123 |
iliev |
1688 |
} |
124 |
|
|
|
125 |
|
|
private void |
126 |
|
|
initCollasiblePane(final JXCollapsiblePane pane) { |
127 |
|
|
pane.setAnimated(false); |
128 |
|
|
pane.setCollapsed(true); |
129 |
|
|
pane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
130 |
iliev |
1286 |
|
131 |
|
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
132 |
|
|
public void |
133 |
|
|
propertyChange(PropertyChangeEvent e) { |
134 |
iliev |
1688 |
pane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
135 |
iliev |
1286 |
} |
136 |
|
|
}); |
137 |
|
|
} |
138 |
|
|
|
139 |
iliev |
1767 |
public void |
140 |
|
|
showOptionsPane(boolean show) { |
141 |
iliev |
1818 |
if(show != btnOptions.isSelected()) btnOptions.doClick(0); |
142 |
iliev |
1767 |
} |
143 |
|
|
|
144 |
|
|
public boolean |
145 |
|
|
isOptionsPaneExpanded() { return btnOptions.isSelected(); } |
146 |
|
|
|
147 |
iliev |
1286 |
protected void |
148 |
|
|
setDeviceName(String s) { |
149 |
|
|
lDevName.setText(s); |
150 |
|
|
Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height); |
151 |
|
|
lDevName.setMaximumSize(d); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
protected void |
155 |
|
|
destroyDevice() { } |
156 |
|
|
|
157 |
|
|
protected void |
158 |
|
|
restoreDevice() { |
159 |
|
|
btnDestroy.setSelected(true); |
160 |
iliev |
1688 |
confirmRemovalPane.restore(); |
161 |
iliev |
1286 |
mainPane.setCollapsed(false); |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
protected void |
165 |
|
|
setOptionsPane(javax.swing.JComponent c) { |
166 |
|
|
optionsPane.setContentPane(c); |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
protected JPanel |
170 |
|
|
createVSeparator() { |
171 |
|
|
PixmapPane p = new PixmapPane(Res.gfxVLine); |
172 |
|
|
p.setOpaque(false); |
173 |
|
|
p.setPreferredSize(new Dimension(2, 24)); |
174 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
175 |
|
|
p.setMaximumSize(p.getPreferredSize()); |
176 |
|
|
return p; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
protected JPanel |
180 |
|
|
createHSeparator() { |
181 |
|
|
PixmapPane p = new PixmapPane(Res.gfxHLine); |
182 |
|
|
p.setOpaque(false); |
183 |
|
|
p.setPreferredSize(new Dimension(77, 2)); |
184 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
185 |
|
|
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 2)); |
186 |
|
|
return p; |
187 |
iliev |
1688 |
} |
188 |
iliev |
1286 |
|
189 |
iliev |
1688 |
private boolean |
190 |
|
|
shouldConfirm() { return preferences().getBoolProperty(CONFIRM_DEVICE_REMOVAL); } |
191 |
|
|
|
192 |
|
|
private void |
193 |
|
|
confirmRemoval() { |
194 |
|
|
confirmRemovalPane.showOptions = !optionsPane.isCollapsed(); |
195 |
|
|
if(optionsPane.isCollapsed() || !optionsPane.isAnimated()) { |
196 |
|
|
if(btnOptions.isSelected()) btnOptions.doClick(0); |
197 |
|
|
btnOptions.setEnabled(false); |
198 |
|
|
confirmPane.setCollapsed(false); |
199 |
|
|
return; |
200 |
|
|
} |
201 |
|
|
|
202 |
|
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
203 |
|
|
optionsPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
204 |
|
|
public void |
205 |
|
|
propertyChange(PropertyChangeEvent e) { |
206 |
|
|
if(e.getNewValue() == "collapsed") { |
207 |
|
|
confirmPane.setCollapsed(false); |
208 |
|
|
optionsPane.removePropertyChangeListener(s, this); |
209 |
|
|
} |
210 |
|
|
} |
211 |
|
|
}); |
212 |
|
|
|
213 |
|
|
btnOptions.doClick(0); |
214 |
|
|
btnOptions.setEnabled(false); |
215 |
|
|
} |
216 |
|
|
|
217 |
iliev |
1286 |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
218 |
|
|
OptionsButton() { |
219 |
|
|
super(Res.gfxOptionsOff, Res.gfxOptionsOn); |
220 |
|
|
setRolloverIcon(Res.gfxOptionsOffRO); |
221 |
|
|
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
222 |
|
|
addActionListener(this); |
223 |
iliev |
1688 |
setToolTipText(i18n.getButtonLabel("DevicePane.ttShowOptions")); |
224 |
iliev |
1286 |
} |
225 |
|
|
|
226 |
iliev |
1785 |
@Override |
227 |
iliev |
1286 |
public void |
228 |
|
|
actionPerformed(ActionEvent e) { |
229 |
|
|
showOptionsPane(isSelected()); |
230 |
iliev |
1767 |
} |
231 |
|
|
|
232 |
|
|
private void |
233 |
|
|
showOptionsPane(boolean show) { |
234 |
|
|
optionsPane.setCollapsed(!show); |
235 |
iliev |
1286 |
|
236 |
|
|
String s; |
237 |
iliev |
1688 |
if(isSelected()) s = i18n.getButtonLabel("DevicePane.ttHideOptions"); |
238 |
|
|
else s = i18n.getButtonLabel("DevicePane.ttShowOptions"); |
239 |
iliev |
1286 |
|
240 |
|
|
setToolTipText(s); |
241 |
|
|
} |
242 |
|
|
|
243 |
iliev |
1785 |
@Override |
244 |
iliev |
1286 |
public boolean |
245 |
|
|
contains(int x, int y) { return super.contains(x, y) & y < 13; } |
246 |
|
|
} |
247 |
|
|
|
248 |
|
|
private class PowerButton extends PixmapToggleButton |
249 |
|
|
implements ActionListener, PropertyChangeListener { |
250 |
|
|
|
251 |
|
|
PowerButton() { |
252 |
|
|
super(Res.gfxPowerOff18, Res.gfxPowerOn18); |
253 |
|
|
|
254 |
|
|
setSelected(true); |
255 |
|
|
addActionListener(this); |
256 |
|
|
String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
257 |
|
|
mainPane.addPropertyChangeListener(s, this); |
258 |
iliev |
1688 |
setToolTipText(i18n.getButtonLabel("DevicePane.ttRemoveDevice")); |
259 |
iliev |
1286 |
} |
260 |
|
|
|
261 |
iliev |
1785 |
@Override |
262 |
iliev |
1286 |
public void |
263 |
|
|
actionPerformed(ActionEvent e) { |
264 |
iliev |
1688 |
if(shouldConfirm()) { |
265 |
|
|
if(isSelected()) confirmRemovalPane.onCancel(); |
266 |
|
|
else confirmRemoval(); |
267 |
|
|
return; |
268 |
|
|
} |
269 |
|
|
|
270 |
iliev |
1286 |
if(!mainPane.isAnimated()) { |
271 |
|
|
destroyDevice(); |
272 |
|
|
return; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
mainPane.setCollapsed(true); |
276 |
|
|
} |
277 |
|
|
|
278 |
iliev |
1785 |
@Override |
279 |
iliev |
1286 |
public void |
280 |
|
|
propertyChange(PropertyChangeEvent e) { |
281 |
|
|
if(e.getNewValue() == "collapsed") { |
282 |
|
|
destroyDevice(); |
283 |
|
|
} |
284 |
|
|
} |
285 |
|
|
} |
286 |
|
|
|
287 |
iliev |
1688 |
private class ConfirmRemovalPane extends PixmapPane implements ActionListener { |
288 |
|
|
private final JButton btnRemove = new JButton(i18n.getButtonLabel("DevicePane.btnRemove")); |
289 |
|
|
private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel")); |
290 |
|
|
|
291 |
|
|
protected boolean showOptions = false; |
292 |
|
|
|
293 |
|
|
ConfirmRemovalPane() { |
294 |
|
|
super(Res.gfxChannelOptions); |
295 |
|
|
|
296 |
|
|
setAlignmentX(LEFT_ALIGNMENT); |
297 |
|
|
|
298 |
|
|
setPixmapInsets(new Insets(1, 1, 1, 1)); |
299 |
|
|
setLayout(new java.awt.BorderLayout()); |
300 |
|
|
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
301 |
|
|
setOpaque(false); |
302 |
|
|
|
303 |
|
|
PixmapPane p = new PixmapPane(Res.gfxRoundBg7); |
304 |
|
|
p.setPixmapInsets(new Insets(3, 3, 3, 3)); |
305 |
|
|
p.setOpaque(false); |
306 |
|
|
|
307 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
308 |
|
|
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
309 |
|
|
|
310 |
|
|
p.add(Box.createGlue()); |
311 |
|
|
p.add(btnRemove); |
312 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
313 |
|
|
p.add(btnCancel); |
314 |
|
|
|
315 |
|
|
add(p); |
316 |
|
|
|
317 |
|
|
btnRemove.addActionListener(this); |
318 |
|
|
|
319 |
|
|
btnCancel.addActionListener(new ActionListener() { |
320 |
|
|
public void |
321 |
|
|
actionPerformed(ActionEvent e) { |
322 |
|
|
onCancel(); |
323 |
|
|
} |
324 |
|
|
}); |
325 |
|
|
} |
326 |
|
|
|
327 |
|
|
protected void |
328 |
|
|
onCancel() { |
329 |
|
|
btnDestroy.setSelected(true); |
330 |
|
|
btnOptions.setEnabled(true); |
331 |
|
|
btnRemove.setEnabled(true); |
332 |
|
|
|
333 |
|
|
if(!showOptions) { |
334 |
|
|
confirmPane.setCollapsed(true); |
335 |
|
|
return; |
336 |
|
|
} |
337 |
|
|
showOptions = false; |
338 |
|
|
|
339 |
|
|
if(!confirmPane.isAnimated()) { |
340 |
|
|
confirmPane.setCollapsed(true); |
341 |
|
|
btnOptions.doClick(0); |
342 |
|
|
return; |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
346 |
|
|
confirmPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
347 |
|
|
public void |
348 |
|
|
propertyChange(PropertyChangeEvent e) { |
349 |
|
|
if(e.getNewValue() == "collapsed") { |
350 |
|
|
btnOptions.doClick(0); |
351 |
|
|
confirmPane.removePropertyChangeListener(s, this); |
352 |
|
|
} |
353 |
|
|
} |
354 |
|
|
}); |
355 |
|
|
|
356 |
|
|
confirmPane.setCollapsed(true); |
357 |
|
|
} |
358 |
|
|
|
359 |
|
|
protected void |
360 |
|
|
restore() { |
361 |
|
|
btnOptions.setEnabled(true); |
362 |
|
|
boolean b = confirmPane.isAnimated(); |
363 |
|
|
confirmPane.setAnimated(false); |
364 |
|
|
confirmPane.setCollapsed(true); |
365 |
|
|
confirmPane.setAnimated(b); |
366 |
|
|
btnRemove.setEnabled(true); |
367 |
|
|
showOptions = false; |
368 |
|
|
} |
369 |
|
|
|
370 |
iliev |
1785 |
@Override |
371 |
iliev |
1688 |
public void |
372 |
|
|
actionPerformed(ActionEvent e) { |
373 |
|
|
btnRemove.setEnabled(false); |
374 |
|
|
|
375 |
|
|
if(!mainPane.isAnimated()) { |
376 |
|
|
destroyDevice(); |
377 |
|
|
return; |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
mainPane.setCollapsed(true); |
381 |
|
|
} |
382 |
|
|
} |
383 |
iliev |
1286 |
} |