1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2010 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.Color; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.Graphics; |
28 |
import java.awt.Graphics2D; |
29 |
import java.awt.Insets; |
30 |
|
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
import java.awt.event.HierarchyEvent; |
34 |
import java.awt.event.HierarchyListener; |
35 |
import java.awt.event.MouseAdapter; |
36 |
import java.awt.event.MouseEvent; |
37 |
import java.awt.event.MouseListener; |
38 |
|
39 |
import java.beans.PropertyChangeEvent; |
40 |
import java.beans.PropertyChangeListener; |
41 |
|
42 |
import java.util.Vector; |
43 |
|
44 |
import javax.swing.BorderFactory; |
45 |
import javax.swing.Box; |
46 |
import javax.swing.BoxLayout; |
47 |
import javax.swing.JButton; |
48 |
import javax.swing.JComponent; |
49 |
import javax.swing.JLabel; |
50 |
import javax.swing.JMenuItem; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.JPopupMenu; |
53 |
|
54 |
import javax.swing.event.ChangeEvent; |
55 |
import javax.swing.event.ChangeListener; |
56 |
|
57 |
import net.sf.juife.Dial; |
58 |
|
59 |
import org.jsampler.CC; |
60 |
import org.jsampler.view.fantasia.basic.*; |
61 |
|
62 |
import org.pushingpixels.substance.internal.utils.SubstanceImageCreator; |
63 |
|
64 |
import org.linuxsampler.lscp.SamplerChannel; |
65 |
import org.linuxsampler.lscp.SamplerEngine; |
66 |
|
67 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
68 |
import static org.jsampler.view.fantasia.FantasiaPrefs.*; |
69 |
import static org.jsampler.view.fantasia.FantasiaUtils.*; |
70 |
|
71 |
/** |
72 |
* |
73 |
* @author Grigor Iliev |
74 |
*/ |
75 |
public class NormalChannelView extends JPanel implements ChannelView { |
76 |
private final Channel channel; |
77 |
private ChannelOptionsView channelOptionsView = null; |
78 |
|
79 |
private final EnhancedDial dialVolume = new EnhancedDial(); |
80 |
private final ChannelScreen screen; |
81 |
|
82 |
private final Channel.PowerButton btnPower; |
83 |
private final MuteButton btnMute = new MuteButton(); |
84 |
private final SoloButton btnSolo = new SoloButton(); |
85 |
private final Channel.OptionsButton btnOptions; |
86 |
|
87 |
private final Vector<JComponent> components = new Vector<JComponent>(); |
88 |
|
89 |
|
90 |
/** Creates a new instance of <code>NormalChannelView</code> */ |
91 |
public |
92 |
NormalChannelView(Channel channel) { |
93 |
components.add(this); |
94 |
|
95 |
this.channel = channel; |
96 |
|
97 |
btnPower = new Channel.PowerButton(channel); |
98 |
components.add(btnPower); |
99 |
btnOptions = new Channel.OptionsButton(channel); |
100 |
components.add(btnOptions); |
101 |
|
102 |
screen = new ChannelScreen(channel); |
103 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
104 |
|
105 |
btnPower.setAlignmentY(JPanel.TOP_ALIGNMENT); |
106 |
|
107 |
JPanel tb = new JPanel(); |
108 |
components.add(tb); |
109 |
tb.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 4)); |
110 |
tb.setLayout(new BoxLayout(tb, BoxLayout.X_AXIS)); |
111 |
tb.setOpaque(false); |
112 |
tb.setAlignmentY(JPanel.TOP_ALIGNMENT); |
113 |
tb.add(btnPower); |
114 |
tb.setPreferredSize(new Dimension(tb.getPreferredSize().width, 58)); |
115 |
tb.setMinimumSize(tb.getPreferredSize()); |
116 |
tb.setMaximumSize(tb.getPreferredSize()); |
117 |
add(tb); |
118 |
|
119 |
//p.add(Box.createRigidArea(new Dimension(4, 0))); |
120 |
|
121 |
add(createVSeparator()); |
122 |
|
123 |
//p.add(Box.createRigidArea(new Dimension(3, 0))); |
124 |
|
125 |
JPanel p2 = new JPanel(); |
126 |
components.add(p2); |
127 |
p2.setOpaque(false); |
128 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
129 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
130 |
p2.setBorder(BorderFactory.createEmptyBorder(5, 3, 0, 2)); |
131 |
p2.add(screen); |
132 |
add(p2); |
133 |
|
134 |
add(createVSeparator()); |
135 |
|
136 |
p2 = new JPanel(); |
137 |
components.add(p2); |
138 |
p2.setOpaque(false); |
139 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
140 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
141 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
142 |
|
143 |
JLabel l = new JLabel(Res.gfxMuteTitle); |
144 |
components.add(l); |
145 |
p2.add(l); |
146 |
components.add(btnMute); |
147 |
p2.add(btnMute); |
148 |
|
149 |
l = new JLabel(Res.gfxSoloTitle); |
150 |
components.add(l); |
151 |
p2.add(l); |
152 |
|
153 |
components.add(btnSolo); |
154 |
p2.add(btnSolo); |
155 |
|
156 |
add(p2); |
157 |
|
158 |
add(createVSeparator()); |
159 |
|
160 |
p2 = new JPanel(); |
161 |
components.add(p2); |
162 |
p2.setOpaque(false); |
163 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
164 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
165 |
p2.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0)); |
166 |
l = new JLabel(Res.gfxVolumeTitle); |
167 |
components.add(l); |
168 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
169 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
170 |
p2.add(l); |
171 |
|
172 |
components.add(dialVolume); |
173 |
dialVolume.setDialPixmap(Res.gfxVolumeDial, 30, 330); |
174 |
dialVolume.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
175 |
p2.add(dialVolume); |
176 |
add(p2); |
177 |
|
178 |
add(createVSeparator()); |
179 |
|
180 |
p2 = new JPanel(); |
181 |
components.add(p2); |
182 |
p2.setOpaque(false); |
183 |
p2.setLayout(new BoxLayout(p2, BoxLayout.Y_AXIS)); |
184 |
p2.setAlignmentY(JPanel.TOP_ALIGNMENT); |
185 |
p2.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 0)); |
186 |
l = new JLabel(Res.gfxOptionsTitle); |
187 |
components.add(l); |
188 |
l.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
189 |
l.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); |
190 |
p2.add(l); |
191 |
|
192 |
p2.add(Box.createRigidArea(new Dimension(0, 3))); |
193 |
|
194 |
btnOptions.setAlignmentX(JPanel.CENTER_ALIGNMENT); |
195 |
p2.add(btnOptions); |
196 |
add(p2); |
197 |
|
198 |
|
199 |
setPreferredSize(new Dimension(420, 60)); |
200 |
setMinimumSize(getPreferredSize()); |
201 |
setMaximumSize(getPreferredSize()); |
202 |
//p.setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); |
203 |
|
204 |
setAlignmentX(JPanel.CENTER_ALIGNMENT); |
205 |
|
206 |
installView(); |
207 |
} |
208 |
|
209 |
////////////////////////////////////////////// |
210 |
// Implementation of the ChannelView interface |
211 |
////////////////////////////////////////////// |
212 |
|
213 |
@Override |
214 |
public Type |
215 |
getType() { return Type.NORMAL; } |
216 |
|
217 |
@Override |
218 |
public JComponent |
219 |
getComponent() { return this; } |
220 |
|
221 |
@Override |
222 |
public void |
223 |
installView() { |
224 |
String vmud = VOL_MEASUREMENT_UNIT_DECIBEL; |
225 |
preferences().addPropertyChangeListener(vmud, new PropertyChangeListener() { |
226 |
public void |
227 |
propertyChange(PropertyChangeEvent e) { |
228 |
boolean b; |
229 |
b = preferences().getBoolProperty(VOL_MEASUREMENT_UNIT_DECIBEL); |
230 |
screen.updateVolumeInfo(dialVolume.getValue()); |
231 |
} |
232 |
}); |
233 |
|
234 |
screen.installListeners(); |
235 |
|
236 |
addEnhancedMouseListener(channel.getContextMenu()); |
237 |
addEnhancedMouseListener(getHandler()); |
238 |
} |
239 |
|
240 |
@Override |
241 |
public void |
242 |
uninstallView() { |
243 |
screen.onDestroy(); |
244 |
btnOptions.onDestroy(); |
245 |
uninstallChannelOptionsView(); |
246 |
//removeEnhancedMouseListener(channel.getContextMenu()); |
247 |
removeEnhancedMouseListener(getHandler()); |
248 |
} |
249 |
|
250 |
@Override |
251 |
public void |
252 |
installChannelOptionsView() { |
253 |
if(channelOptionsView != null) return; |
254 |
|
255 |
channelOptionsView = new NormalChannelOptionsView(channel); |
256 |
channelOptionsView.installView(); |
257 |
|
258 |
} |
259 |
|
260 |
@Override |
261 |
public void |
262 |
uninstallChannelOptionsView() { |
263 |
if(channelOptionsView == null) return; |
264 |
channelOptionsView.uninstallView(); |
265 |
channelOptionsView = null; |
266 |
} |
267 |
|
268 |
@Override |
269 |
public ChannelOptionsView |
270 |
getChannelOptionsView() { return channelOptionsView; } |
271 |
|
272 |
@Override |
273 |
public void |
274 |
updateChannelInfo() { |
275 |
SamplerChannel sc = channel.getChannelInfo(); |
276 |
|
277 |
screen.updateScreenInfo(sc); |
278 |
float f = sc.getVolume() * 100.0f; |
279 |
screen.updateVolumeInfo((int)f); |
280 |
updateMuteIcon(sc); |
281 |
|
282 |
if(sc.isSoloChannel()) btnSolo.setIcon(Res.gfxSoloOn); |
283 |
else btnSolo.setIcon(Res.gfxSoloOff); |
284 |
dialVolume.setValue((int)(sc.getVolume() * 100)); |
285 |
|
286 |
boolean b = sc.getEngine() != null; |
287 |
dialVolume.setEnabled(b); |
288 |
btnSolo.setEnabled(b); |
289 |
btnMute.setEnabled(b); |
290 |
|
291 |
if(getChannelOptionsView() != null) getChannelOptionsView().updateChannelInfo(); |
292 |
} |
293 |
|
294 |
@Override |
295 |
public void |
296 |
updateStreamCount(int count) { screen.updateStreamCount(count); } |
297 |
|
298 |
@Override |
299 |
public void |
300 |
updateVoiceCount(int count) { screen.updateVoiceCount(count); } |
301 |
|
302 |
@Override |
303 |
public void |
304 |
expandChannel() { |
305 |
if(btnOptions.isSelected()) return; |
306 |
btnOptions.doClick(); |
307 |
} |
308 |
|
309 |
@Override |
310 |
public boolean |
311 |
isOptionsButtonSelected() { return btnOptions.isSelected(); } |
312 |
|
313 |
@Override |
314 |
public void |
315 |
setOptionsButtonSelected(boolean b) { |
316 |
btnOptions.setSelected(b); |
317 |
} |
318 |
|
319 |
@Override |
320 |
public void |
321 |
addEnhancedMouseListener(MouseListener l) { |
322 |
removeEnhancedMouseListener(l); |
323 |
|
324 |
for(JComponent c : components) c.addMouseListener(l); |
325 |
screen.addEnhancedMouseListener(l); |
326 |
} |
327 |
|
328 |
@Override |
329 |
public void |
330 |
removeEnhancedMouseListener(MouseListener l) { |
331 |
for(JComponent c : components) c.removeMouseListener(l); |
332 |
screen.removeEnhancedMouseListener(l); |
333 |
} |
334 |
|
335 |
////////////////////////////////////////////// |
336 |
|
337 |
@Override |
338 |
protected void |
339 |
paintComponent(Graphics g) { |
340 |
if(isOpaque()) super.paintComponent(g); |
341 |
|
342 |
double h = getSize().getHeight(); |
343 |
double w = getSize().getWidth(); |
344 |
|
345 |
Color c1 = channel.isSelected() ? new Color(0x555555) : FantasiaPainter.color6; |
346 |
Color c2 = channel.isSelected() ? new Color(0x606060) : FantasiaPainter.color4; |
347 |
|
348 |
Graphics2D g2 = (Graphics2D)g; |
349 |
FantasiaPainter.paintGradient(g2, 0, 0, w - 1, h - 1, c1, c2); |
350 |
FantasiaPainter.paintOuterBorder(g2, 0, 0, w - 1, h - 1, false, 0.27f, 0.11f, 0.64f, 0.20f); |
351 |
} |
352 |
|
353 |
|
354 |
/** |
355 |
* Updates the mute button with the proper icon regarding to information obtained |
356 |
* from <code>channel</code>. |
357 |
* @param channel A <code>SamplerChannel</code> instance containing the new settings |
358 |
* for this channel. |
359 |
*/ |
360 |
private void |
361 |
updateMuteIcon(SamplerChannel channel) { |
362 |
if(channel.isMutedBySolo()) btnMute.setIcon(Res.gfxMutedBySolo); |
363 |
else if(channel.isMuted()) btnMute.setIcon(Res.gfxMuteOn); |
364 |
else btnMute.setIcon(Res.gfxMuteOff); |
365 |
} |
366 |
|
367 |
/** Invoked when the user changes the volume */ |
368 |
private void |
369 |
setVolume() { |
370 |
screen.updateVolumeInfo(dialVolume.getValue()); |
371 |
|
372 |
if(dialVolume.getValueIsAdjusting()) return; |
373 |
|
374 |
int vol = (int)(channel.getChannelInfo().getVolume() * 100); |
375 |
|
376 |
if(vol == dialVolume.getValue()) return; |
377 |
|
378 |
/* |
379 |
* If the model's volume is not equal to the dial knob |
380 |
* value we assume that the change is due to user input. |
381 |
* So we must update the volume at the backend too. |
382 |
*/ |
383 |
float volume = dialVolume.getValue(); |
384 |
volume /= 100; |
385 |
channel.getModel().setBackendVolume(volume); |
386 |
} |
387 |
|
388 |
private JPanel |
389 |
createVSeparator() { |
390 |
PixmapPane p = new PixmapPane(Res.gfxVLine); |
391 |
p.setAlignmentY(JPanel.TOP_ALIGNMENT); |
392 |
p.setPreferredSize(new Dimension(2, 60)); |
393 |
p.setMinimumSize(p.getPreferredSize()); |
394 |
p.setMaximumSize(p.getPreferredSize()); |
395 |
return p; |
396 |
} |
397 |
|
398 |
private class EnhancedDial extends Dial { |
399 |
EnhancedDial() { |
400 |
super(0, 100, 0); |
401 |
|
402 |
setMouseHandlerMode(MouseHandlerMode.LEFT_TO_RIGHT_AND_DOWN_TO_UP); |
403 |
|
404 |
int i = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
405 |
setMaximum(i); |
406 |
String mcv = MAXIMUM_CHANNEL_VOLUME; |
407 |
preferences().addPropertyChangeListener(mcv, new PropertyChangeListener() { |
408 |
public void |
409 |
propertyChange(PropertyChangeEvent e) { |
410 |
int j = preferences().getIntProperty(MAXIMUM_CHANNEL_VOLUME); |
411 |
setMaximum(j); |
412 |
} |
413 |
}); |
414 |
|
415 |
addMouseListener(new MouseAdapter() { |
416 |
public void |
417 |
mouseClicked(MouseEvent e) { |
418 |
if(e.getButton() == e.BUTTON3) { |
419 |
setValue(getMaximum() / 2); |
420 |
return; |
421 |
} |
422 |
|
423 |
if(e.getButton() != e.BUTTON1) return; |
424 |
|
425 |
if(e.getClickCount() < 2) return; |
426 |
setValue(getValueByPoint(e.getPoint())); |
427 |
} |
428 |
}); |
429 |
|
430 |
addChangeListener(new ChangeListener() { |
431 |
public void |
432 |
stateChanged(ChangeEvent e) { setVolume(); } |
433 |
}); |
434 |
} |
435 |
} |
436 |
|
437 |
|
438 |
private class MuteButton extends PixmapButton implements ActionListener { |
439 |
MuteButton() { |
440 |
super(Res.gfxMuteOff); |
441 |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
442 |
setDisabledIcon ( |
443 |
SubstanceImageCreator.makeTransparent(this, Res.gfxMuteOff, 0.4) |
444 |
); |
445 |
addActionListener(this); |
446 |
} |
447 |
|
448 |
@Override |
449 |
public void |
450 |
actionPerformed(ActionEvent e) { |
451 |
SamplerChannel sc = channel.getChannelInfo(); |
452 |
boolean b = true; |
453 |
|
454 |
/* |
455 |
* Changing the mute button icon now instead of |
456 |
* leaving the work to the notification mechanism of the LinuxSampler. |
457 |
*/ |
458 |
if(sc.isMuted() && !sc.isMutedBySolo()) { |
459 |
b = false; |
460 |
boolean hasSolo = CC.getSamplerModel().hasSoloChannel(); |
461 |
|
462 |
if(sc.isSoloChannel() || !hasSolo) setIcon(Res.gfxMuteOff); |
463 |
else setIcon(Res.gfxMutedBySolo); |
464 |
} else setIcon(Res.gfxMuteOn); |
465 |
|
466 |
channel.getModel().setBackendMute(b); |
467 |
} |
468 |
|
469 |
@Override |
470 |
public boolean |
471 |
contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
472 |
} |
473 |
|
474 |
private class SoloButton extends PixmapButton implements ActionListener { |
475 |
SoloButton() { |
476 |
super(Res.gfxSoloOff); |
477 |
//setDisabledIcon(Res.gfxMuteSoloDisabled); |
478 |
setDisabledIcon ( |
479 |
SubstanceImageCreator.makeTransparent(this, Res.gfxSoloOff, 0.4) |
480 |
); |
481 |
addActionListener(this); |
482 |
} |
483 |
|
484 |
@Override |
485 |
public void |
486 |
actionPerformed(ActionEvent e) { |
487 |
SamplerChannel sc = channel.getChannelInfo(); |
488 |
boolean b = !sc.isSoloChannel(); |
489 |
|
490 |
/* |
491 |
* Changing the solo button icon (and related) now instead of |
492 |
* leaving the work to the notification mechanism of the LinuxSampler. |
493 |
*/ |
494 |
if(b) { |
495 |
setIcon(Res.gfxSoloOn); |
496 |
if(sc.isMutedBySolo()) btnMute.setIcon(Res.gfxMuteOff); |
497 |
} else { |
498 |
setIcon(Res.gfxSoloOff); |
499 |
if(!sc.isMuted() && CC.getSamplerModel().getSoloChannelCount() > 1) |
500 |
btnMute.setIcon(Res.gfxMutedBySolo); |
501 |
} |
502 |
|
503 |
channel.getModel().setBackendSolo(b); |
504 |
} |
505 |
|
506 |
@Override |
507 |
public boolean |
508 |
contains(int x, int y) { return (x > 5 && x < 23) && (y > 5 && y < 16); } |
509 |
} |
510 |
|
511 |
private final EventHandler eventHandler = new EventHandler(); |
512 |
|
513 |
private EventHandler |
514 |
getHandler() { return eventHandler; } |
515 |
|
516 |
private class EventHandler extends MouseAdapter { |
517 |
@Override |
518 |
public void |
519 |
mousePressed(MouseEvent e) { |
520 |
// TAG: channel selection system |
521 |
if(e.getButton() == MouseEvent.BUTTON3 && channel.isSelected()) return; |
522 |
|
523 |
CC.getMainFrame().getSelectedChannelsPane().processChannelSelection ( |
524 |
channel, e.isControlDown(), e.isShiftDown() |
525 |
); |
526 |
/////// |
527 |
} |
528 |
} |
529 |
} |
530 |
|
531 |
|
532 |
class ChannelScreen extends PixmapPane { |
533 |
private final Channel channel; |
534 |
|
535 |
private final InstrumentPane instrumentPane; |
536 |
|
537 |
private final Channel.StreamVoiceCountPane streamVoiceCountPane; |
538 |
|
539 |
private final Channel.VolumePane volumePane; |
540 |
|
541 |
private JButton btnInstr = |
542 |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
543 |
|
544 |
private final JButton btnEditInstr = |
545 |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEditInstr")); |
546 |
private final ScreenButtonBg sbbEditInstr = new ScreenButtonBg(btnEditInstr); |
547 |
|
548 |
private final JButton btnFxSends = |
549 |
createScreenButton(i18n.getButtonLabel("ChannelScreen.btnFxSends")); |
550 |
|
551 |
private final JButton btnEngine |
552 |
= createScreenButton(i18n.getButtonLabel("ChannelScreen.btnEngine")); |
553 |
|
554 |
private final JPopupMenu menuEngines = new JPopupMenu(); |
555 |
|
556 |
private final ActionListener guiListener; |
557 |
|
558 |
private final Vector<JComponent> components = new Vector<JComponent>(); |
559 |
|
560 |
ChannelScreen(final Channel channel) { |
561 |
super(Res.gfxChannelScreen); |
562 |
setPixmapInsets(new Insets(6, 6, 6, 6)); |
563 |
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
564 |
|
565 |
components.add(this); |
566 |
|
567 |
this.channel = channel; |
568 |
|
569 |
streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel); |
570 |
components.add(streamVoiceCountPane); |
571 |
|
572 |
volumePane = new Channel.VolumePane(channel); |
573 |
components.add(volumePane); |
574 |
|
575 |
setOpaque(false); |
576 |
|
577 |
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); |
578 |
|
579 |
btnInstr.setAlignmentX(CENTER_ALIGNMENT); |
580 |
btnInstr.setRolloverEnabled(false); |
581 |
btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); |
582 |
components.add(btnInstr); |
583 |
|
584 |
instrumentPane = new InstrumentPane(); |
585 |
components.add(instrumentPane); |
586 |
add(instrumentPane); |
587 |
|
588 |
add(Box.createRigidArea(new Dimension(0, 3))); |
589 |
|
590 |
JPanel p = new JPanel(); |
591 |
components.add(p); |
592 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
593 |
p.setAlignmentX(CENTER_ALIGNMENT); |
594 |
p.setBorder(BorderFactory.createEmptyBorder(5, 2, 0, 0)); |
595 |
|
596 |
components.add(btnFxSends); |
597 |
btnFxSends.setToolTipText(i18n.getButtonLabel("ChannelScreen.btnFxSends.tt")); |
598 |
btnFxSends.addActionListener(new ActionListener() { |
599 |
public void |
600 |
actionPerformed(ActionEvent e) { |
601 |
channel.showFxSendsDialog(); |
602 |
} |
603 |
}); |
604 |
|
605 |
p.add(btnFxSends); |
606 |
|
607 |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
608 |
p.add(Box.createGlue()); |
609 |
|
610 |
components.add(btnEngine); |
611 |
btnEngine.setIcon(Res.iconEngine12); |
612 |
btnEngine.setIconTextGap(1); |
613 |
p.add(btnEngine); |
614 |
//p.add(new Label("|")); |
615 |
|
616 |
//p.add(Box.createRigidArea(new Dimension(6, 0))); |
617 |
|
618 |
//p.add(btnReset); |
619 |
|
620 |
p.add(Box.createGlue()); |
621 |
|
622 |
p.add(streamVoiceCountPane); |
623 |
p.add(volumePane); |
624 |
|
625 |
p.setPreferredSize(new Dimension(260, p.getPreferredSize().height)); |
626 |
p.setMinimumSize(p.getPreferredSize()); |
627 |
p.setMaximumSize(p.getPreferredSize()); |
628 |
|
629 |
//btnInstr.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); |
630 |
p.setOpaque(false); |
631 |
add(p); |
632 |
|
633 |
|
634 |
setPreferredSize(new Dimension(270, 48)); |
635 |
setMinimumSize(getPreferredSize()); |
636 |
setMaximumSize(getPreferredSize()); |
637 |
|
638 |
createEngineMenu(); |
639 |
|
640 |
guiListener = new ActionListener() { |
641 |
public void |
642 |
actionPerformed(ActionEvent e) { |
643 |
if(getMousePosition(true) != null) { |
644 |
getHandler().mouseEntered(null); |
645 |
} else { |
646 |
getHandler().mouseExited(null); |
647 |
} |
648 |
} |
649 |
}; |
650 |
} |
651 |
|
652 |
public void |
653 |
addEnhancedMouseListener(MouseListener l) { |
654 |
removeEnhancedMouseListener(l); |
655 |
for(JComponent c : components) c.addMouseListener(l); |
656 |
} |
657 |
|
658 |
public void |
659 |
removeEnhancedMouseListener(MouseListener l) { |
660 |
for(JComponent c : components) c.removeMouseListener(l); |
661 |
} |
662 |
|
663 |
protected void |
664 |
onDestroy() { uninstallListeners(); } |
665 |
|
666 |
private void |
667 |
createEngineMenu() { |
668 |
for(final SamplerEngine engine : CC.getSamplerModel().getEngines()) { |
669 |
JMenuItem mi = new JMenuItem(engine.getName() + " engine"); |
670 |
mi.setToolTipText(engine.getDescription()); |
671 |
|
672 |
mi.addActionListener(new ActionListener() { |
673 |
public void |
674 |
actionPerformed(ActionEvent e) { |
675 |
channel.getModel().setBackendEngineType(engine.getName()); |
676 |
} |
677 |
}); |
678 |
|
679 |
menuEngines.add(mi); |
680 |
} |
681 |
} |
682 |
|
683 |
protected void |
684 |
installListeners() { |
685 |
btnInstr.addActionListener(new ActionListener() { |
686 |
public void |
687 |
actionPerformed(ActionEvent e) { channel.loadInstrument(); } |
688 |
}); |
689 |
|
690 |
btnEditInstr.addActionListener(new ActionListener() { |
691 |
public void |
692 |
actionPerformed(ActionEvent e) { |
693 |
CC.getSamplerModel().editBackendInstrument(channel.getChannelId()); |
694 |
} |
695 |
}); |
696 |
|
697 |
btnEngine.addActionListener(new ActionListener() { |
698 |
public void |
699 |
actionPerformed(ActionEvent e) { |
700 |
int y = btnEngine.getHeight() + 1; |
701 |
menuEngines.show(btnEngine, 0, y); |
702 |
} |
703 |
}); |
704 |
|
705 |
addMouseListener(getHandler()); |
706 |
addHierarchyListener(getHandler()); |
707 |
|
708 |
((MainFrame)CC.getMainFrame()).getGuiTimer().addActionListener(guiListener); |
709 |
} |
710 |
|
711 |
private void |
712 |
uninstallListeners() { |
713 |
((MainFrame)CC.getMainFrame()).getGuiTimer().removeActionListener(guiListener); |
714 |
} |
715 |
|
716 |
protected void |
717 |
updateScreenInfo(SamplerChannel sc) { |
718 |
String s = btnInstr.getToolTipText(); |
719 |
|
720 |
int status = sc.getInstrumentStatus(); |
721 |
if(status >= 0 && status < 100) { |
722 |
btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status)); |
723 |
if(s != null) btnInstr.setToolTipText(null); |
724 |
} else if(status == -1) { |
725 |
btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
726 |
if(s != null) btnInstr.setToolTipText(null); |
727 |
} else if(status < -1) { |
728 |
btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument")); |
729 |
if(s != null) btnInstr.setToolTipText(null); |
730 |
} else { |
731 |
if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName()); |
732 |
else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr")); |
733 |
|
734 |
btnInstr.setToolTipText(sc.getInstrumentName()); |
735 |
} |
736 |
|
737 |
instrumentPane.update(); |
738 |
|
739 |
if(sc.getEngine() != null) { |
740 |
s = sc.getEngine().getName(); |
741 |
s += " engine"; |
742 |
if(!s.equals(btnEngine.getText())) { |
743 |
btnEngine.setText(s); |
744 |
btnEngine.setToolTipText(sc.getEngine().getDescription()); |
745 |
} |
746 |
} |
747 |
|
748 |
} |
749 |
|
750 |
protected void |
751 |
updateVolumeInfo(int volume) { |
752 |
volumePane.updateVolumeInfo(volume); |
753 |
} |
754 |
|
755 |
/** |
756 |
* Updates the number of active disk streams. |
757 |
* @param count The new number of active disk streams. |
758 |
*/ |
759 |
protected void |
760 |
updateStreamCount(int count) { |
761 |
streamVoiceCountPane.updateStreamCount(count); |
762 |
} |
763 |
|
764 |
/** |
765 |
* Updates the number of active voices. |
766 |
* @param count The new number of active voices. |
767 |
*/ |
768 |
protected void |
769 |
updateVoiceCount(int count) { |
770 |
streamVoiceCountPane.updateVoiceCount(count); |
771 |
} |
772 |
|
773 |
class InstrumentPane extends JPanel { |
774 |
private final JPanel leftPane = new JPanel(); |
775 |
private final JPanel rightPane = new JPanel(); |
776 |
|
777 |
InstrumentPane() { |
778 |
setOpaque(false); |
779 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
780 |
add(leftPane); |
781 |
add(btnInstr); |
782 |
add(rightPane); |
783 |
add(sbbEditInstr); |
784 |
btnEditInstr.setToolTipText(i18n.getLabel("ChannelScreen.btnEditInstr.tt")); |
785 |
sbbEditInstr.setVisible(false); |
786 |
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 6)); |
787 |
|
788 |
update(); |
789 |
} |
790 |
|
791 |
public void |
792 |
update() { |
793 |
int a = btnInstr.getMinimumSize().width; |
794 |
int b = 0; |
795 |
if(sbbEditInstr.isVisible()) b = sbbEditInstr.getPreferredSize().width; |
796 |
|
797 |
int max = 254 - b; |
798 |
if(a > max) a = max; |
799 |
|
800 |
int h = btnInstr.getPreferredSize().height; |
801 |
btnInstr.setPreferredSize(new Dimension(a, h)); |
802 |
h = btnInstr.getMaximumSize().height; |
803 |
btnInstr.setMaximumSize(new Dimension(a, h)); |
804 |
|
805 |
|
806 |
int i = (254 - btnInstr.getPreferredSize().width) / 2; |
807 |
|
808 |
int j = i; |
809 |
if(sbbEditInstr.isVisible()) j -= sbbEditInstr.getPreferredSize().width; |
810 |
if(i < 0 || j < 0) i = j = 0; |
811 |
|
812 |
Dimension d = new Dimension(i, 1); |
813 |
leftPane.setMinimumSize(d); |
814 |
leftPane.setPreferredSize(d); |
815 |
leftPane.setMaximumSize(d); |
816 |
|
817 |
d = new Dimension(j, 1); |
818 |
rightPane.setMinimumSize(d); |
819 |
rightPane.setPreferredSize(d); |
820 |
rightPane.setMaximumSize(d); |
821 |
|
822 |
validate(); |
823 |
} |
824 |
} |
825 |
|
826 |
static class ScreenButtonBg extends PixmapPane { |
827 |
ScreenButtonBg(JButton btn) { |
828 |
super(Res.gfxScreenBtnBg); |
829 |
setPixmapInsets(new Insets(4, 4, 4, 4)); |
830 |
setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); |
831 |
setBorder(BorderFactory.createEmptyBorder(0, 7, 0, 7)); |
832 |
add(btn); |
833 |
setPreferredSize(new Dimension(getPreferredSize().width, 13)); |
834 |
} |
835 |
|
836 |
@Override |
837 |
public Dimension |
838 |
getPreferredSize() { |
839 |
return new Dimension(super.getPreferredSize().width, 13); |
840 |
} |
841 |
} |
842 |
|
843 |
|
844 |
private final EventHandler eventHandler = new EventHandler(); |
845 |
|
846 |
private EventHandler |
847 |
getHandler() { return eventHandler; } |
848 |
|
849 |
private class EventHandler extends MouseAdapter implements HierarchyListener { |
850 |
@Override |
851 |
public void |
852 |
mouseEntered(MouseEvent e) { |
853 |
if(channel.getChannelInfo().getInstrumentStatus() != 100) return; |
854 |
|
855 |
if(!sbbEditInstr.isVisible()) { |
856 |
sbbEditInstr.setVisible(true); |
857 |
instrumentPane.update(); |
858 |
} |
859 |
} |
860 |
|
861 |
@Override |
862 |
public void |
863 |
mouseExited(MouseEvent e) { |
864 |
if(getMousePosition(true) != null) return; |
865 |
if(sbbEditInstr.isVisible()) { |
866 |
sbbEditInstr.setVisible(false); |
867 |
instrumentPane.update(); |
868 |
} |
869 |
} |
870 |
|
871 |
/** Called when the hierarchy has been changed. */ |
872 |
@Override |
873 |
public void |
874 |
hierarchyChanged(HierarchyEvent e) { |
875 |
if((e.getChangeFlags() & e.SHOWING_CHANGED) == e.SHOWING_CHANGED) { |
876 |
if(getMousePosition() == null) mouseExited(null); |
877 |
else mouseEntered(null); |
878 |
} |
879 |
} |
880 |
} |
881 |
} |