/[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 1732 - (hide annotations) (download)
Sat May 3 01:40:06 2008 UTC (16 years, 1 month ago) by iliev
File size: 20312 byte(s)
* Fantasia: Implemented Small View for sampler channels
  (right-click on the sampler channel then choose Small View)
* Fantasia: Implemented option to choose default sampler channel view
  (choose Edit/Preferences, then click the `Defaults' tab)
* Fantasia: Added context menu to sampler channels

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

  ViewVC Help
Powered by ViewVC