/[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 1735 - (hide annotations) (download)
Sun May 4 18:58:16 2008 UTC (16 years ago) by iliev
File size: 21792 byte(s)
- fixed channel context menu

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

  ViewVC Help
Powered by ViewVC