1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1915 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
1286 |
* |
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 |
1915 |
initCollapsiblePane(optionsPane); |
108 |
iliev |
1286 |
|
109 |
|
|
mainPane.add(optionsPane); |
110 |
|
|
|
111 |
iliev |
1688 |
confirmPane.setContentPane(confirmRemovalPane); |
112 |
|
|
confirmPane.setAlignmentX(LEFT_ALIGNMENT); |
113 |
iliev |
1915 |
initCollapsiblePane(confirmPane); |
114 |
iliev |
1688 |
|
115 |
|
|
mainPane.add(confirmPane); |
116 |
|
|
|
117 |
iliev |
1286 |
add(mainPane); |
118 |
|
|
|
119 |
iliev |
1915 |
initCollapsiblePane(mainPane); |
120 |
iliev |
1286 |
mainPane.setCollapsed(false); |
121 |
iliev |
1688 |
} |
122 |
|
|
|
123 |
|
|
private void |
124 |
iliev |
1915 |
initCollapsiblePane(final JXCollapsiblePane pane) { |
125 |
iliev |
1688 |
pane.setAnimated(false); |
126 |
|
|
pane.setCollapsed(true); |
127 |
|
|
pane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
128 |
iliev |
1286 |
|
129 |
|
|
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
130 |
|
|
public void |
131 |
|
|
propertyChange(PropertyChangeEvent e) { |
132 |
iliev |
1688 |
pane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
133 |
iliev |
1286 |
} |
134 |
|
|
}); |
135 |
|
|
} |
136 |
|
|
|
137 |
iliev |
1767 |
public void |
138 |
|
|
showOptionsPane(boolean show) { |
139 |
iliev |
1818 |
if(show != btnOptions.isSelected()) btnOptions.doClick(0); |
140 |
iliev |
1767 |
} |
141 |
|
|
|
142 |
|
|
public boolean |
143 |
|
|
isOptionsPaneExpanded() { return btnOptions.isSelected(); } |
144 |
|
|
|
145 |
iliev |
1286 |
protected void |
146 |
|
|
setDeviceName(String s) { |
147 |
|
|
lDevName.setText(s); |
148 |
|
|
Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height); |
149 |
|
|
lDevName.setMaximumSize(d); |
150 |
|
|
} |
151 |
|
|
|
152 |
|
|
protected void |
153 |
|
|
destroyDevice() { } |
154 |
|
|
|
155 |
|
|
protected void |
156 |
|
|
restoreDevice() { |
157 |
|
|
btnDestroy.setSelected(true); |
158 |
iliev |
1688 |
confirmRemovalPane.restore(); |
159 |
iliev |
1286 |
mainPane.setCollapsed(false); |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
protected void |
163 |
|
|
setOptionsPane(javax.swing.JComponent c) { |
164 |
|
|
optionsPane.setContentPane(c); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
protected JPanel |
168 |
|
|
createVSeparator() { |
169 |
|
|
PixmapPane p = new PixmapPane(Res.gfxVLine); |
170 |
|
|
p.setOpaque(false); |
171 |
|
|
p.setPreferredSize(new Dimension(2, 24)); |
172 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
173 |
|
|
p.setMaximumSize(p.getPreferredSize()); |
174 |
|
|
return p; |
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
protected JPanel |
178 |
|
|
createHSeparator() { |
179 |
|
|
PixmapPane p = new PixmapPane(Res.gfxHLine); |
180 |
|
|
p.setOpaque(false); |
181 |
|
|
p.setPreferredSize(new Dimension(77, 2)); |
182 |
|
|
p.setMinimumSize(p.getPreferredSize()); |
183 |
|
|
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 2)); |
184 |
|
|
return p; |
185 |
iliev |
1688 |
} |
186 |
iliev |
1286 |
|
187 |
iliev |
1688 |
private boolean |
188 |
|
|
shouldConfirm() { return preferences().getBoolProperty(CONFIRM_DEVICE_REMOVAL); } |
189 |
|
|
|
190 |
|
|
private void |
191 |
|
|
confirmRemoval() { |
192 |
|
|
confirmRemovalPane.showOptions = !optionsPane.isCollapsed(); |
193 |
|
|
if(optionsPane.isCollapsed() || !optionsPane.isAnimated()) { |
194 |
|
|
if(btnOptions.isSelected()) btnOptions.doClick(0); |
195 |
|
|
btnOptions.setEnabled(false); |
196 |
|
|
confirmPane.setCollapsed(false); |
197 |
|
|
return; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
201 |
|
|
optionsPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
202 |
|
|
public void |
203 |
|
|
propertyChange(PropertyChangeEvent e) { |
204 |
|
|
if(e.getNewValue() == "collapsed") { |
205 |
|
|
confirmPane.setCollapsed(false); |
206 |
|
|
optionsPane.removePropertyChangeListener(s, this); |
207 |
|
|
} |
208 |
|
|
} |
209 |
|
|
}); |
210 |
|
|
|
211 |
|
|
btnOptions.doClick(0); |
212 |
|
|
btnOptions.setEnabled(false); |
213 |
|
|
} |
214 |
|
|
|
215 |
iliev |
1286 |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
216 |
|
|
OptionsButton() { |
217 |
|
|
super(Res.gfxOptionsOff, Res.gfxOptionsOn); |
218 |
|
|
setRolloverIcon(Res.gfxOptionsOffRO); |
219 |
|
|
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
220 |
|
|
addActionListener(this); |
221 |
iliev |
1688 |
setToolTipText(i18n.getButtonLabel("DevicePane.ttShowOptions")); |
222 |
iliev |
1286 |
} |
223 |
|
|
|
224 |
iliev |
1785 |
@Override |
225 |
iliev |
1286 |
public void |
226 |
|
|
actionPerformed(ActionEvent e) { |
227 |
|
|
showOptionsPane(isSelected()); |
228 |
iliev |
1767 |
} |
229 |
|
|
|
230 |
|
|
private void |
231 |
|
|
showOptionsPane(boolean show) { |
232 |
|
|
optionsPane.setCollapsed(!show); |
233 |
iliev |
1286 |
|
234 |
|
|
String s; |
235 |
iliev |
1688 |
if(isSelected()) s = i18n.getButtonLabel("DevicePane.ttHideOptions"); |
236 |
|
|
else s = i18n.getButtonLabel("DevicePane.ttShowOptions"); |
237 |
iliev |
1286 |
|
238 |
|
|
setToolTipText(s); |
239 |
|
|
} |
240 |
|
|
|
241 |
iliev |
1785 |
@Override |
242 |
iliev |
1286 |
public boolean |
243 |
|
|
contains(int x, int y) { return super.contains(x, y) & y < 13; } |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
private class PowerButton extends PixmapToggleButton |
247 |
|
|
implements ActionListener, PropertyChangeListener { |
248 |
|
|
|
249 |
|
|
PowerButton() { |
250 |
|
|
super(Res.gfxPowerOff18, Res.gfxPowerOn18); |
251 |
|
|
|
252 |
|
|
setSelected(true); |
253 |
|
|
addActionListener(this); |
254 |
|
|
String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
255 |
|
|
mainPane.addPropertyChangeListener(s, this); |
256 |
iliev |
1688 |
setToolTipText(i18n.getButtonLabel("DevicePane.ttRemoveDevice")); |
257 |
iliev |
1286 |
} |
258 |
|
|
|
259 |
iliev |
1785 |
@Override |
260 |
iliev |
1286 |
public void |
261 |
|
|
actionPerformed(ActionEvent e) { |
262 |
iliev |
1688 |
if(shouldConfirm()) { |
263 |
|
|
if(isSelected()) confirmRemovalPane.onCancel(); |
264 |
|
|
else confirmRemoval(); |
265 |
|
|
return; |
266 |
|
|
} |
267 |
|
|
|
268 |
iliev |
1286 |
if(!mainPane.isAnimated()) { |
269 |
|
|
destroyDevice(); |
270 |
|
|
return; |
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
mainPane.setCollapsed(true); |
274 |
|
|
} |
275 |
|
|
|
276 |
iliev |
1785 |
@Override |
277 |
iliev |
1286 |
public void |
278 |
|
|
propertyChange(PropertyChangeEvent e) { |
279 |
|
|
if(e.getNewValue() == "collapsed") { |
280 |
|
|
destroyDevice(); |
281 |
|
|
} |
282 |
|
|
} |
283 |
|
|
} |
284 |
|
|
|
285 |
iliev |
1688 |
private class ConfirmRemovalPane extends PixmapPane implements ActionListener { |
286 |
|
|
private final JButton btnRemove = new JButton(i18n.getButtonLabel("DevicePane.btnRemove")); |
287 |
|
|
private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel")); |
288 |
|
|
|
289 |
|
|
protected boolean showOptions = false; |
290 |
|
|
|
291 |
|
|
ConfirmRemovalPane() { |
292 |
|
|
super(Res.gfxChannelOptions); |
293 |
|
|
|
294 |
|
|
setAlignmentX(LEFT_ALIGNMENT); |
295 |
|
|
|
296 |
|
|
setPixmapInsets(new Insets(1, 1, 1, 1)); |
297 |
|
|
setLayout(new java.awt.BorderLayout()); |
298 |
|
|
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
299 |
|
|
setOpaque(false); |
300 |
|
|
|
301 |
|
|
PixmapPane p = new PixmapPane(Res.gfxRoundBg7); |
302 |
|
|
p.setPixmapInsets(new Insets(3, 3, 3, 3)); |
303 |
|
|
p.setOpaque(false); |
304 |
|
|
|
305 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
306 |
|
|
p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
307 |
|
|
|
308 |
|
|
p.add(Box.createGlue()); |
309 |
|
|
p.add(btnRemove); |
310 |
|
|
p.add(Box.createRigidArea(new Dimension(5, 0))); |
311 |
|
|
p.add(btnCancel); |
312 |
|
|
|
313 |
|
|
add(p); |
314 |
|
|
|
315 |
|
|
btnRemove.addActionListener(this); |
316 |
|
|
|
317 |
|
|
btnCancel.addActionListener(new ActionListener() { |
318 |
|
|
public void |
319 |
|
|
actionPerformed(ActionEvent e) { |
320 |
|
|
onCancel(); |
321 |
|
|
} |
322 |
|
|
}); |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
protected void |
326 |
|
|
onCancel() { |
327 |
|
|
btnDestroy.setSelected(true); |
328 |
|
|
btnOptions.setEnabled(true); |
329 |
|
|
btnRemove.setEnabled(true); |
330 |
|
|
|
331 |
|
|
if(!showOptions) { |
332 |
|
|
confirmPane.setCollapsed(true); |
333 |
|
|
return; |
334 |
|
|
} |
335 |
|
|
showOptions = false; |
336 |
|
|
|
337 |
|
|
if(!confirmPane.isAnimated()) { |
338 |
|
|
confirmPane.setCollapsed(true); |
339 |
|
|
btnOptions.doClick(0); |
340 |
|
|
return; |
341 |
|
|
} |
342 |
|
|
|
343 |
|
|
final String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
344 |
|
|
confirmPane.addPropertyChangeListener(s, new PropertyChangeListener() { |
345 |
|
|
public void |
346 |
|
|
propertyChange(PropertyChangeEvent e) { |
347 |
|
|
if(e.getNewValue() == "collapsed") { |
348 |
|
|
btnOptions.doClick(0); |
349 |
|
|
confirmPane.removePropertyChangeListener(s, this); |
350 |
|
|
} |
351 |
|
|
} |
352 |
|
|
}); |
353 |
|
|
|
354 |
|
|
confirmPane.setCollapsed(true); |
355 |
|
|
} |
356 |
|
|
|
357 |
|
|
protected void |
358 |
|
|
restore() { |
359 |
|
|
btnOptions.setEnabled(true); |
360 |
|
|
boolean b = confirmPane.isAnimated(); |
361 |
|
|
confirmPane.setAnimated(false); |
362 |
|
|
confirmPane.setCollapsed(true); |
363 |
|
|
confirmPane.setAnimated(b); |
364 |
|
|
btnRemove.setEnabled(true); |
365 |
|
|
showOptions = false; |
366 |
|
|
} |
367 |
|
|
|
368 |
iliev |
1785 |
@Override |
369 |
iliev |
1688 |
public void |
370 |
|
|
actionPerformed(ActionEvent e) { |
371 |
|
|
btnRemove.setEnabled(false); |
372 |
|
|
|
373 |
|
|
if(!mainPane.isAnimated()) { |
374 |
|
|
destroyDevice(); |
375 |
|
|
return; |
376 |
|
|
} |
377 |
|
|
|
378 |
|
|
mainPane.setCollapsed(true); |
379 |
|
|
} |
380 |
|
|
} |
381 |
iliev |
1286 |
} |