/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/fantasia/Channel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1730 by iliev, Wed Apr 30 23:31:08 2008 UTC revision 1732 by iliev, Sat May 3 01:40:06 2008 UTC
# Line 23  Line 23 
23  package org.jsampler.view.fantasia;  package org.jsampler.view.fantasia;
24    
25  import java.awt.Container;  import java.awt.Container;
26    import java.awt.Dimension;
27  import java.awt.Rectangle;  import java.awt.Rectangle;
28    
29  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
31    import java.awt.event.MouseAdapter;
32    import java.awt.event.MouseEvent;
33    
34  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
35  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
36    
37    import java.text.NumberFormat;
38    
39    import javax.swing.AbstractAction;
40    import javax.swing.Action;
41  import javax.swing.BoxLayout;  import javax.swing.BoxLayout;
42    import javax.swing.ButtonGroup;
43  import javax.swing.DefaultListCellRenderer;  import javax.swing.DefaultListCellRenderer;
44    import javax.swing.ImageIcon;
45  import javax.swing.JButton;  import javax.swing.JButton;
46  import javax.swing.JComponent;  import javax.swing.JComponent;
47    import javax.swing.JLabel;
48    import javax.swing.JMenuItem;
49  import javax.swing.JPanel;  import javax.swing.JPanel;
50    import javax.swing.JPopupMenu;
51    import javax.swing.JRadioButtonMenuItem;
52  import javax.swing.JScrollPane;  import javax.swing.JScrollPane;
53  import javax.swing.JToggleButton;  import javax.swing.JToggleButton;
54    import javax.swing.JToolBar;
55    
56    import net.sf.juife.InformationDialog;
57  import net.sf.juife.TitleBar;  import net.sf.juife.TitleBar;
58    
59  import org.jdesktop.swingx.JXCollapsiblePane;  import org.jdesktop.swingx.JXCollapsiblePane;
# Line 52  import org.jsampler.event.SamplerChannel Line 67  import org.jsampler.event.SamplerChannel
67  import org.jsampler.event.SamplerChannelListListener;  import org.jsampler.event.SamplerChannelListListener;
68  import org.jsampler.event.SamplerChannelListener;  import org.jsampler.event.SamplerChannelListener;
69    
70    import org.jsampler.view.std.JSChannelOutputRoutingDlg;
71    import org.jsampler.view.std.JSFxSendsPane;
72    import org.jsampler.view.std.JSInstrumentChooser;
73    import org.jsampler.view.std.JSVolumeEditorPopup;
74    
75    import org.linuxsampler.lscp.SamplerChannel;
76    
77    import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
78  import static org.jsampler.view.fantasia.FantasiaPrefs.*;  import static org.jsampler.view.fantasia.FantasiaPrefs.*;
79    import static org.jsampler.view.fantasia.FantasiaUtils.*;
80    import static org.jsampler.view.std.JSVolumeEditorPopup.VolumeType;
81    
82    
83  /**  /**
# Line 65  public class Channel extends org.jsample Line 90  public class Channel extends org.jsample
90          private ChannelOptionsView channelOptionsView;          private ChannelOptionsView channelOptionsView;
91          private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();          private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();
92                    
93            private InformationDialog fxSendsDlg = null;
94            
95            private final ContextMenu contextMenu = new ContextMenu();
96            
97          private boolean selected = false;          private boolean selected = false;
98                    
99          private AnimatedPorpetyListener animatedPorpetyListener = new AnimatedPorpetyListener();          private AnimatedPorpetyListener animatedPorpetyListener = new AnimatedPorpetyListener();
# Line 107  public class Channel extends org.jsample Line 136  public class Channel extends org.jsample
136                          new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)                          new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
137                  );                  );
138                                    
139                  channelView = new NormalChannelView(this);                  int viewIdx = preferences().getIntProperty(DEFAULT_CHANNEL_VIEW);
140                  channelOptionsView = channelView.getChannelOptionsView();                  if(viewIdx == 0) {
141                                            contextMenu.rbmiSmallView.doClick(0);
142                  optionsPane.setContentPane(channelOptionsView.getComponent());                  } else if(viewIdx == 1) {
143                                            contextMenu.rbmiNormalView.doClick(0);
144                  mainPane.add(channelView.getComponent());                  } else {
145                  mainPane.add(optionsPane);                          contextMenu.rbmiNormalView.doClick(0);
146                    }
147                                    
148                  setOpaque(false);                  setOpaque(false);
149                                    
# Line 215  public class Channel extends org.jsample Line 245  public class Channel extends org.jsample
245                  channelOptionsView.updateChannelInfo();                  channelOptionsView.updateChannelInfo();
246          }          }
247                    
248            public void
249            loadInstrument() {
250                    JSInstrumentChooser dlg = FantasiaUtils.createInstrumentChooser(CC.getMainFrame());
251                    dlg.setVisible(true);
252                    
253                    if(!dlg.isCancelled()) {
254                            SamplerChannelModel m = getModel();
255                            m.loadBackendInstrument(dlg.getInstrumentFile(), dlg.getInstrumentIndex());
256                    }
257            }
258            
259          protected void          protected void
260          onDestroy() {          onDestroy() {
261                  CC.getSamplerModel().removeSamplerChannelListListener(getHandler());                  CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
# Line 239  public class Channel extends org.jsample Line 280  public class Channel extends org.jsample
280          public void          public void
281          showOptionsPane(boolean show) { optionsPane.showOptionsPane(show); }          showOptionsPane(boolean show) { optionsPane.showOptionsPane(show); }
282                    
283            public void
284            showFxSendsDialog() {
285                    if(fxSendsDlg != null && fxSendsDlg.isVisible()) {
286                            fxSendsDlg.toFront();
287                            return;
288                    }
289                    FxSendsPane p = new FxSendsPane(getModel());
290                    int id = getModel().getChannelId();
291                    fxSendsDlg = new InformationDialog(CC.getMainFrame(), p);
292                    fxSendsDlg.setTitle(i18n.getLabel("FxSendsDlg.title", id));
293                    fxSendsDlg.setModal(false);
294                    fxSendsDlg.showCloseButton(false);
295                    fxSendsDlg.setVisible(true);
296            }
297            
298          private final EventHandler eventHandler = new EventHandler();          private final EventHandler eventHandler = new EventHandler();
299                    
300          private EventHandler          private EventHandler
# Line 302  public class Channel extends org.jsample Line 358  public class Channel extends org.jsample
358                          }                          }
359                  }                  }
360          }          }
361            
362            class EditInstrumentAction extends AbstractAction implements SamplerChannelListener {
363                    EditInstrumentAction() {
364                            super(i18n.getMenuLabel("channels.editInstrument"));
365                            channelChanged(null);
366                            getModel().addSamplerChannelListener(this);
367                    }
368                    
369                    public void
370                    actionPerformed(ActionEvent e) {
371                            CC.getSamplerModel().editBackendInstrument(getChannelId());
372                    }
373                    
374                    public void
375                    channelChanged(SamplerChannelEvent e) {
376                            boolean b = getChannelInfo().getInstrumentStatus() == 100;
377                            setEnabled(b);
378                    }
379                    
380                    public void
381                    streamCountChanged(SamplerChannelEvent e) { }
382                    
383                    public void
384                    voiceCountChanged(SamplerChannelEvent e) { }
385            }
386            
387            class FxSendsAction extends AbstractAction {
388                    FxSendsAction() {
389                            super(i18n.getMenuLabel("channels.fxSends"));
390                    }
391                    
392                    public void
393                    actionPerformed(ActionEvent e) {
394                            showFxSendsDialog();
395                    }
396            }
397            
398            class ChannelRoutingAction extends AbstractAction implements SamplerChannelListener {
399                    ChannelRoutingAction() {
400                            super(i18n.getMenuLabel("channels.channelRouting"));
401                            channelChanged(null);
402                            getModel().addSamplerChannelListener(this);
403                    }
404                    
405                    public void
406                    actionPerformed(ActionEvent e) {
407                            SamplerChannel c = getChannelInfo();
408                            new JSChannelOutputRoutingDlg(CC.getMainFrame(), c).setVisible(true);
409                    }
410                    
411                    public void
412                    channelChanged(SamplerChannelEvent e) {
413                            boolean b = getChannelInfo().getAudioOutputDevice() != -1;
414                            setEnabled(b);
415                    }
416                    
417                    public void
418                    streamCountChanged(SamplerChannelEvent e) { }
419                    
420                    public void
421                    voiceCountChanged(SamplerChannelEvent e) { }
422            }
423            
424            class SetSmallViewAction extends AbstractAction {
425                    SetSmallViewAction() {
426                            super(i18n.getMenuLabel("channels.smallView"));
427                    }
428                    
429                    public void
430                    actionPerformed(ActionEvent e) {
431                            if(channelView instanceof SmallChannelView) return;
432                            
433                            if(channelView != null) {
434                                    mainPane.remove(channelView.getComponent());
435                                    mainPane.remove(optionsPane);
436                                    
437                                    channelView.uninstallView();
438                                    channelOptionsView.uninstallView();
439                            }
440                            
441                            channelView = new SmallChannelView(Channel.this);
442                            channelOptionsView = channelView.getChannelOptionsView();
443                            
444                            optionsPane.setContentPane(channelOptionsView.getComponent());
445                            
446                            updateChannelInfo();
447                    
448                            mainPane.add(channelView.getComponent());
449                            mainPane.add(optionsPane);
450                            mainPane.validate();
451                    }
452            }
453            
454            class SetNormalViewAction extends AbstractAction {
455                    SetNormalViewAction() {
456                            super(i18n.getMenuLabel("channels.normalView"));
457                    }
458                    
459                    public void
460                    actionPerformed(ActionEvent e) {
461                            if(channelView instanceof NormalChannelView) return;
462                            
463                            if(channelView != null) {
464                                    mainPane.remove(channelView.getComponent());
465                                    mainPane.remove(optionsPane);
466                                    
467                                    channelView.uninstallView();
468                                    channelOptionsView.uninstallView();
469                            }
470                            
471                            channelView = new NormalChannelView(Channel.this);
472                            channelOptionsView = channelView.getChannelOptionsView();
473                            
474                            optionsPane.setContentPane(channelOptionsView.getComponent());
475                            
476                            updateChannelInfo();
477                    
478                            mainPane.add(channelView.getComponent());
479                            mainPane.add(optionsPane);
480                            mainPane.validate();
481                    }
482            }
483            
484            public ContextMenu
485            getContextMenu() { return contextMenu; }
486            
487            class ContextMenu extends MouseAdapter {
488                    private final JPopupMenu menu = new JPopupMenu();
489                    
490                    protected final JRadioButtonMenuItem rbmiSmallView;
491                    protected final JRadioButtonMenuItem rbmiNormalView;
492                    
493                    ContextMenu() {
494                            menu.add(new JMenuItem(new EditInstrumentAction()));
495                            menu.addSeparator();
496                            
497                            rbmiSmallView = new JRadioButtonMenuItem(new SetSmallViewAction());
498                            rbmiNormalView = new JRadioButtonMenuItem(new SetNormalViewAction());
499                            
500                            ButtonGroup group = new ButtonGroup();
501                            group.add(rbmiSmallView);
502                            group.add(rbmiNormalView);
503                            
504                            menu.add(rbmiSmallView);
505                            menu.add(rbmiNormalView);
506                            
507                            menu.addSeparator();
508                            menu.add(new JMenuItem(new FxSendsAction()));
509                            menu.add(new JMenuItem(new ChannelRoutingAction()));
510                    }
511                    
512                    public void
513                    mousePressed(MouseEvent e) {
514                            if(e.isPopupTrigger()) show(e);
515                    }
516            
517                    public void
518                    mouseReleased(MouseEvent e) {
519                            if(e.isPopupTrigger()) show(e);
520                    }
521            
522                    void
523                    show(MouseEvent e) {
524                            menu.show(e.getComponent(), e.getX(), e.getY());
525                    }
526            }
527            
528            class FxSendsPane extends JSFxSendsPane {
529                    FxSendsPane(SamplerChannelModel model) {
530                            super(model);
531                            
532                            actionAddFxSend.putValue(Action.SMALL_ICON, Res.iconNew16);
533                            actionRemoveFxSend.putValue(Action.SMALL_ICON, Res.iconDelete16);
534                    }
535                    
536                    protected JToolBar
537                    createToolBar() {
538                            JToolBar tb = new JToolBar();
539                            Dimension d = new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height);
540                            tb.setMaximumSize(d);
541                            tb.setFloatable(false);
542                            tb.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
543                            
544                            tb.add(new ToolbarButton(actionAddFxSend));
545                            tb.add(new ToolbarButton(actionRemoveFxSend));
546                    
547                            return tb;
548                    }
549            }
550            
551            public static class StreamVoiceCountPane extends JPanel {
552                    private final Channel channel;
553                    
554                    private final JLabel lStreams = createScreenLabel(" --");
555                    private final JLabel lSlash = createScreenLabel("/");
556                    private final JLabel lVoices = createScreenLabel("-- ");
557                    
558                    public
559                    StreamVoiceCountPane(Channel channel) {
560                            this.channel = channel;
561                            
562                            setOpaque(false);
563                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
564                            lStreams.setFont(Res.fontScreenMono);
565                            lStreams.setHorizontalAlignment(JLabel.RIGHT);
566                            lStreams.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
567                            
568                            Dimension d = lStreams.getPreferredSize();
569                            lStreams.setMinimumSize(d);
570                            lStreams.setPreferredSize(d);
571                            lStreams.setMaximumSize(d);
572                            add(lStreams);
573                            
574                            lSlash.setFont(Res.fontScreenMono);
575                            lSlash.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
576                            add(lSlash);
577                            
578                            lVoices.setFont(Res.fontScreenMono);
579                            lVoices.setToolTipText(i18n.getLabel("Channel.streamVoiceCount"));
580                            
581                            d = lStreams.getPreferredSize();
582                            lVoices.setMinimumSize(d);
583                            lVoices.setPreferredSize(d);
584                            lVoices.setMaximumSize(d);
585                            add(lVoices);
586                            
587                            lStreams.addMouseListener(channel.getContextMenu());
588                            lSlash.addMouseListener(channel.getContextMenu());
589                            lVoices.addMouseListener(channel.getContextMenu());
590                    }
591                    
592                    public void
593                    updateStreamCount(int count) {
594                            lStreams.setText(count == 0 ? " --" : String.valueOf(count));
595                    }
596                    
597                    public void
598                    updateVoiceCount(int count) {
599                            lVoices.setText(count == 0 ? "-- " : String.valueOf(count));
600                    }
601            }
602            
603            public static class VolumePane extends JPanel {
604                    private final Channel channel;
605                    private final JButton btnVolume = createScreenButton("");
606                    private JSVolumeEditorPopup popupVolume;
607                    
608                    private static NumberFormat numberFormat = NumberFormat.getInstance();
609                    static { numberFormat.setMaximumFractionDigits(1); }
610                    
611                    public
612                    VolumePane(final Channel channel) {
613                            this.channel = channel;
614                            setOpaque(false);
615                            setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
616                            
617                            btnVolume.setIcon(Res.iconVolume14);
618                            btnVolume.setIconTextGap(2);
619                            btnVolume.setAlignmentX(RIGHT_ALIGNMENT);
620                            btnVolume.setHorizontalAlignment(btnVolume.LEFT);
621                            updateVolumeInfo(100);
622                            Dimension d = btnVolume.getPreferredSize();
623                            d.width = 57;
624                            btnVolume.setPreferredSize(d);
625                            btnVolume.setMinimumSize(d);
626                            
627                            add(btnVolume);
628                            
629                            btnVolume.addActionListener(new ActionListener() {
630                                    public void
631                                    actionPerformed(ActionEvent e) {
632                                            if(popupVolume.isVisible()) {
633                                                    popupVolume.commit();
634                                                    popupVolume.hide();
635                                            } else {
636                                                    float vol = channel.getModel().getChannelInfo().getVolume();
637                                                    popupVolume.setCurrentVolume(vol);
638                                                    popupVolume.show();
639                                            }
640                                    }
641                            });
642                            
643                            popupVolume = new JSVolumeEditorPopup(btnVolume, VolumeType.CHANNEL);
644                            
645                            popupVolume.addActionListener(new ActionListener() {
646                                    public void
647                                    actionPerformed(ActionEvent e) {
648                                            channel.getModel().setBackendVolume(popupVolume.getVolumeFactor());
649                                    }
650                            });
651                            
652                            btnVolume.addMouseListener(channel.getContextMenu());
653                    }
654                    
655                    public void
656                    updateVolumeInfo(int volume) {
657                            if(CC.getViewConfig().isMeasurementUnitDecibel()) {
658                                    String s = numberFormat.format(HF.percentsToDecibels(volume));
659                                    btnVolume.setText(s + "dB");
660                            } else {
661                                    btnVolume.setText(String.valueOf(volume) + "%");
662                            }
663                    }
664            }
665            
666            public static class PowerButton extends PixmapToggleButton implements ActionListener {
667                    private final Channel channel;
668                    
669                    PowerButton(Channel channel) {
670                            this(channel, Res.gfxPowerOff, Res.gfxPowerOn);
671                    }
672                    
673                    PowerButton(Channel channel, ImageIcon defaultIcon, ImageIcon selectedIcon) {
674                            super(defaultIcon, selectedIcon);
675                            
676                            this.channel = channel;
677                    
678                            setSelected(true);
679                            addActionListener(this);
680                            setToolTipText(i18n.getButtonLabel("Channel.ttRemoveChannel"));
681                    }
682                    
683                    public void
684                    actionPerformed(ActionEvent e) {
685                            boolean b = preferences().getBoolProperty(CONFIRM_CHANNEL_REMOVAL);
686                            if(b) {
687                                    String s = i18n.getMessage("Channel.remove?", channel.getChannelId());
688                                    if(!HF.showYesNoDialog(channel, s)) {
689                                            setSelected(true);
690                                            return;
691                                    }
692                            }
693                            channel.remove();
694                    }
695                    
696                    public boolean
697                    contains(int x, int y) { return (x - 11)*(x - 11) + (y - 11)*(y - 11) < 71; }
698            }
699            
700            public static class OptionsButton extends PixmapToggleButton implements ActionListener {
701                    private final Channel channel;
702                    
703                    OptionsButton(Channel channel) {
704                            super(Res.gfxOptionsOff, Res.gfxOptionsOn);
705                            
706                            this.channel = channel;
707                            
708                            setRolloverIcon(Res.gfxOptionsOffRO);
709                            this.setRolloverSelectedIcon(Res.gfxOptionsOnRO);
710                            addActionListener(this);
711                            setToolTipText(i18n.getButtonLabel("Channel.ttShowOptions"));
712                    }
713                    
714                    public void
715                    actionPerformed(ActionEvent e) {
716                            channel.showOptionsPane(isSelected());
717                            
718                            String s;
719                            if(isSelected()) s = i18n.getButtonLabel("Channel.ttHideOptions");
720                            else s = i18n.getButtonLabel("Channel.ttShowOptions");
721                            
722                            setToolTipText(s);
723                    }
724                    
725                    public boolean
726                    contains(int x, int y) { return super.contains(x, y) & y < 13; }
727            }
728  }  }
729    
730  class ChannelOptionsPane extends JXCollapsiblePane {  class ChannelOptionsPane extends JXCollapsiblePane {

Legend:
Removed from v.1730  
changed lines
  Added in v.1732

  ViewVC Help
Powered by ViewVC