/[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 1767 - (show annotations) (download)
Mon Sep 8 00:19:27 2008 UTC (15 years, 7 months ago) by iliev
File size: 22230 byte(s)
* Added `Copy To' and `Move To' commands to the MIDI bank context menu
  and to the MIDI instrument context menu
* Added commands to the MIDI instrument context menu for moving
  a MIDI instrument to another program
  (right-click on a MIDI instrument and choose `Change Program')
* Added option to choose between zero-based and one-based
  MIDI bank/program numbering
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to choose whether to include MIDI instrument
  mappings when exporting a sampler configuration to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Added option to set the MIDI instrument loading in background
  when exporting MIDI instrument mappings to LSCP script.
  (choose Edit/Preferences, then click the `Advanced' button)
* Implemented an option to change the socket read timeout
  (choose Edit/Preferences, then click the `Backend' tab)
* Updated LscpTree
* Fantasia: Added option to hide the active stream/voice count statistic
  in the sampler channel's small view
  (choose Edit/Preferences, then click the `Channels' tab)
* Fantasia: `Turn off animation effects' checkbox moved to the `View' tab

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

  ViewVC Help
Powered by ViewVC