/[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 1776 - (show annotations) (download)
Thu Sep 11 18:48:36 2008 UTC (15 years, 7 months ago) by iliev
File size: 22681 byte(s)
* Implemented virtual MIDI keyboard

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

  ViewVC Help
Powered by ViewVC