/[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 1785 - (show annotations) (download)
Tue Oct 7 00:07:14 2008 UTC (15 years, 6 months ago) by iliev
File size: 23067 byte(s)
* Fantasia: Implemented multiple channels panels
* Fantasia: Refactoring - all basic UI components moved to
  org.jsampler.view.fantasia.basic package

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

  ViewVC Help
Powered by ViewVC