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

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

  ViewVC Help
Powered by ViewVC