/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/DevicePane.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/DevicePane.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1767 - (show annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 7 months ago) by iliev
File size: 9973 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

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

  ViewVC Help
Powered by ViewVC