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