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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1734 - (hide annotations) (download)
Sun May 4 18:40:13 2008 UTC (15 years, 11 months ago) by iliev
File size: 21942 byte(s)
* bugfix: JSampler took forever to load a configuration with
  too many sampler channels
* Implemented option to show different channel view when
  the mouse pointer is over sampler channel
  (choose Edit/Preferences, then click the `Defaults' tab)

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

  ViewVC Help
Powered by ViewVC