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.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 |
import javax.swing.JPanel; |
39 |
|
40 |
import org.jdesktop.swingx.JXCollapsiblePane; |
41 |
|
42 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
43 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
44 |
|
45 |
/** |
46 |
* |
47 |
* @author Grigor Iliev |
48 |
*/ |
49 |
public class DevicePane extends JPanel { |
50 |
private final PowerButton btnDestroy; |
51 |
private final OptionsButton btnOptions = new OptionsButton(); |
52 |
private final FantasiaLabel lDevName; |
53 |
|
54 |
private final JXCollapsiblePane mainPane = new JXCollapsiblePane(); |
55 |
private final JXCollapsiblePane optionsPane = new JXCollapsiblePane(); |
56 |
|
57 |
/** Creates a new instance of <code>DevicePane</code> */ |
58 |
public |
59 |
DevicePane() { |
60 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
61 |
|
62 |
mainPane.getContentPane().setLayout ( |
63 |
new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS) |
64 |
); |
65 |
|
66 |
PixmapPane p = new PixmapPane(Res.gfxDeviceBg); |
67 |
p.setPixmapInsets(new Insets(1, 1, 1, 1)); |
68 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
69 |
p.add(Box.createRigidArea(new Dimension(3, 0))); |
70 |
btnDestroy = new PowerButton(); |
71 |
p.add(btnDestroy); |
72 |
p.add(Box.createRigidArea(new Dimension(3, 0))); |
73 |
|
74 |
p.add(createVSeparator()); |
75 |
|
76 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
77 |
|
78 |
lDevName = new FantasiaLabel("", true); |
79 |
lDevName.setOpaque(false); |
80 |
lDevName.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
81 |
Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height); |
82 |
lDevName.setMaximumSize(d); |
83 |
lDevName.setMinimumSize(new Dimension(70, lDevName.getPreferredSize().height)); |
84 |
p.add(lDevName); |
85 |
|
86 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
87 |
|
88 |
p.add(btnOptions); |
89 |
|
90 |
p.add(Box.createRigidArea(new Dimension(5, 0))); |
91 |
|
92 |
d = new Dimension(77, 24); |
93 |
p.setPreferredSize(d); |
94 |
p.setMinimumSize(d); |
95 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 24)); |
96 |
p.setAlignmentX(LEFT_ALIGNMENT); |
97 |
mainPane.add(p); |
98 |
|
99 |
optionsPane.setAlignmentX(LEFT_ALIGNMENT); |
100 |
optionsPane.setAnimated(false); |
101 |
optionsPane.setCollapsed(true); |
102 |
optionsPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
103 |
|
104 |
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
105 |
public void |
106 |
propertyChange(PropertyChangeEvent e) { |
107 |
optionsPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
108 |
} |
109 |
}); |
110 |
|
111 |
mainPane.add(optionsPane); |
112 |
|
113 |
add(mainPane); |
114 |
|
115 |
mainPane.setAnimated(false); |
116 |
mainPane.setCollapsed(true); |
117 |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
118 |
mainPane.setCollapsed(false); |
119 |
|
120 |
preferences().addPropertyChangeListener(ANIMATED, new PropertyChangeListener() { |
121 |
public void |
122 |
propertyChange(PropertyChangeEvent e) { |
123 |
mainPane.setAnimated(preferences().getBoolProperty(ANIMATED)); |
124 |
} |
125 |
}); |
126 |
} |
127 |
|
128 |
protected void |
129 |
setDeviceName(String s) { |
130 |
lDevName.setText(s); |
131 |
Dimension d = new Dimension(Short.MAX_VALUE, lDevName.getPreferredSize().height); |
132 |
lDevName.setMaximumSize(d); |
133 |
} |
134 |
|
135 |
protected void |
136 |
destroyDevice() { } |
137 |
|
138 |
protected void |
139 |
restoreDevice() { |
140 |
btnDestroy.setSelected(true); |
141 |
mainPane.setCollapsed(false); |
142 |
|
143 |
} |
144 |
|
145 |
protected void |
146 |
setOptionsPane(javax.swing.JComponent c) { |
147 |
optionsPane.setContentPane(c); |
148 |
} |
149 |
|
150 |
protected JPanel |
151 |
createVSeparator() { |
152 |
PixmapPane p = new PixmapPane(Res.gfxVLine); |
153 |
p.setOpaque(false); |
154 |
p.setPreferredSize(new Dimension(2, 24)); |
155 |
p.setMinimumSize(p.getPreferredSize()); |
156 |
p.setMaximumSize(p.getPreferredSize()); |
157 |
return p; |
158 |
} |
159 |
|
160 |
protected JPanel |
161 |
createHSeparator() { |
162 |
PixmapPane p = new PixmapPane(Res.gfxHLine); |
163 |
p.setOpaque(false); |
164 |
p.setPreferredSize(new Dimension(77, 2)); |
165 |
p.setMinimumSize(p.getPreferredSize()); |
166 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, 2)); |
167 |
return p; |
168 |
} |
169 |
|
170 |
private class OptionsButton extends PixmapToggleButton implements ActionListener { |
171 |
OptionsButton() { |
172 |
super(Res.gfxOptionsOff, Res.gfxOptionsOn); |
173 |
setRolloverIcon(Res.gfxOptionsOffRO); |
174 |
this.setRolloverSelectedIcon(Res.gfxOptionsOnRO); |
175 |
addActionListener(this); |
176 |
} |
177 |
|
178 |
public void |
179 |
actionPerformed(ActionEvent e) { |
180 |
showOptionsPane(isSelected()); |
181 |
|
182 |
String s; |
183 |
if(isSelected()) s = i18n.getButtonLabel("OptionsButton.ttHideOptions"); |
184 |
else s = i18n.getButtonLabel("OptionsButton.ttShowOptions"); |
185 |
|
186 |
setToolTipText(s); |
187 |
} |
188 |
|
189 |
private void |
190 |
showOptionsPane(boolean show) { |
191 |
optionsPane.setCollapsed(!show); |
192 |
} |
193 |
|
194 |
public boolean |
195 |
contains(int x, int y) { return super.contains(x, y) & y < 13; } |
196 |
} |
197 |
|
198 |
private class PowerButton extends PixmapToggleButton |
199 |
implements ActionListener, PropertyChangeListener { |
200 |
|
201 |
PowerButton() { |
202 |
super(Res.gfxPowerOff18, Res.gfxPowerOn18); |
203 |
|
204 |
setSelected(true); |
205 |
addActionListener(this); |
206 |
String s = JXCollapsiblePane.ANIMATION_STATE_KEY; |
207 |
mainPane.addPropertyChangeListener(s, this); |
208 |
} |
209 |
|
210 |
public void |
211 |
actionPerformed(ActionEvent e) { |
212 |
if(!mainPane.isAnimated()) { |
213 |
destroyDevice(); |
214 |
return; |
215 |
} |
216 |
|
217 |
mainPane.setCollapsed(true); |
218 |
} |
219 |
|
220 |
public void |
221 |
propertyChange(PropertyChangeEvent e) { |
222 |
if(e.getNewValue() == "collapsed") { |
223 |
destroyDevice(); |
224 |
} |
225 |
} |
226 |
} |
227 |
|
228 |
} |