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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2288 - (show annotations) (download)
Wed Nov 23 21:19:44 2011 UTC (12 years, 6 months ago) by iliev
File size: 23696 byte(s)
* Added option to select a sampler engine in Add/Edit Instrument dialog
* Moved all Swing dependent code outside the JSampler core

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

  ViewVC Help
Powered by ViewVC