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

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

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

revision 1742 by iliev, Thu May 8 17:26:19 2008 UTC revision 1743 by iliev, Sat May 31 23:04:01 2008 UTC
# Line 43  import javax.swing.JLabel; Line 43  import javax.swing.JLabel;
43  import javax.swing.JPanel;  import javax.swing.JPanel;
44    
45  import org.jsampler.CC;  import org.jsampler.CC;
46    import org.jsampler.event.SamplerChannelListEvent;
47    import org.jsampler.event.SamplerChannelListListener;
48    
49  import org.jvnet.substance.SubstanceImageCreator;  import org.jvnet.substance.SubstanceImageCreator;
50    
# Line 149  public class SmallChannelView extends Pi Line 151  public class SmallChannelView extends Pi
151                  });                  });
152                                    
153                  addEnhancedMouseListener(channel.getContextMenu());                  addEnhancedMouseListener(channel.getContextMenu());
154                    CC.getSamplerModel().addSamplerChannelListListener(getHandler());
155          }          }
156                    
157          public void          public void
158          uninstallView() {          uninstallView() {
159                  //removeEnhancedMouseListener(channel.getContextMenu());                  //removeEnhancedMouseListener(channel.getContextMenu());
160                    CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
161                    screen.onDestroy();
162                  btnOptions.onDestroy();                  btnOptions.onDestroy();
163                  uninstallChannelOptionsView();                  uninstallChannelOptionsView();
164          }          }
# Line 256  public class SmallChannelView extends Pi Line 261  public class SmallChannelView extends Pi
261          }          }
262                    
263                    
264            private final EventHandler eventHandler = new EventHandler();
265            
266            private EventHandler
267            getHandler() { return eventHandler; }
268            
269            private class EventHandler implements SamplerChannelListListener {
270                    public void
271                    channelAdded(SamplerChannelListEvent e) {
272                            if(CC.getSamplerModel().getChannelListIsAdjusting()) return;
273                            screen.channelInfoPane.updateChannelIndex();
274                    }
275            
276                    public void
277                    channelRemoved(SamplerChannelListEvent e) {
278                            //if(CC.getSamplerModel().getChannelListIsAdjusting()) return; //TODO:
279                            
280                            screen.channelInfoPane.updateChannelIndex();
281                    }
282            }
283            
284            
285          private class MuteButton extends PixmapButton implements ActionListener {          private class MuteButton extends PixmapButton implements ActionListener {
286                  MuteButton() {                  MuteButton() {
287                          super(Res.gfxMuteSmallOff);                          super(Res.gfxMuteSmallOff);
# Line 327  public class SmallChannelView extends Pi Line 353  public class SmallChannelView extends Pi
353          static class ChannelScreen extends PixmapPane {          static class ChannelScreen extends PixmapPane {
354                  private final Channel channel;                  private final Channel channel;
355                                    
356                  //private final ChannelInfoPane channelInfoPane;                  private final ChannelInfoPane channelInfoPane;
357                                    
358                  private final Channel.StreamVoiceCountPane streamVoiceCountPane;                  private final Channel.StreamVoiceCountPane streamVoiceCountPane;
359                                                    
# Line 342  public class SmallChannelView extends Pi Line 368  public class SmallChannelView extends Pi
368                                    
369                  private final Vector<JComponent> components = new Vector<JComponent>();                  private final Vector<JComponent> components = new Vector<JComponent>();
370                                    
371                    private final PropertyChangeListener chnNumberingListener;
372                    private final PropertyChangeListener showMidiInfoListener;
373                    
374                    private boolean bShowNumbering;
375                    private boolean bShowMidiInfo;
376                    
377                  ChannelScreen(final Channel channel) {                  ChannelScreen(final Channel channel) {
378                          super(Res.gfxTextField);                          super(Res.gfxTextField);
379                                                    
# Line 352  public class SmallChannelView extends Pi Line 384  public class SmallChannelView extends Pi
384                          streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel);                          streamVoiceCountPane = new Channel.StreamVoiceCountPane(channel);
385                          components.add(streamVoiceCountPane);                          components.add(streamVoiceCountPane);
386                                                    
387                          //channelInfoPane = new ChannelInfoPane(channel);                          channelInfoPane = new ChannelInfoPane(channel);
388                          volumePane = new Channel.VolumePane(channel);                          volumePane = new Channel.VolumePane(channel);
389                          components.add(volumePane);                          components.add(volumePane);
390                                                    
# Line 366  public class SmallChannelView extends Pi Line 398  public class SmallChannelView extends Pi
398                          p.setOpaque(false);                          p.setOpaque(false);
399                          p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));                          p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
400                                                    
401                          //p.add(channelInfoPane);                          p.add(channelInfoPane);
402                                                    
403                          btnInstr.setRolloverEnabled(false);                          btnInstr.setRolloverEnabled(false);
404                          btnInstr.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));                          btnInstr.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
# Line 399  public class SmallChannelView extends Pi Line 431  public class SmallChannelView extends Pi
431                                  public void                                  public void
432                                  actionPerformed(ActionEvent e) { channel.loadInstrument(); }                                  actionPerformed(ActionEvent e) { channel.loadInstrument(); }
433                          });                          });
434                            
435                            final String s = "channel.smallView.showChannelNumbering";
436                            
437                            chnNumberingListener = new PropertyChangeListener() {
438                                    public void
439                                    propertyChange(PropertyChangeEvent e) {
440                                            bShowNumbering = preferences().getBoolProperty(s);
441                                            channelInfoPane.setShowNumbering(bShowNumbering);
442                                    }
443                            };
444                                                    
445                            preferences().addPropertyChangeListener(s, chnNumberingListener);
446                            
447                            bShowNumbering = preferences().getBoolProperty(s);
448                            channelInfoPane.setShowNumbering(bShowNumbering);
449                            
450                            
451                            
452                            final String s2 = "channel.smallView.showMidiInfo";
453                            
454                            showMidiInfoListener = new PropertyChangeListener() {
455                                    public void
456                                    propertyChange(PropertyChangeEvent e) {
457                                            bShowMidiInfo = preferences().getBoolProperty(s2);
458                                            channelInfoPane.setShowMidiInfo(bShowMidiInfo);
459                                    }
460                            };
461                                                    
462                            preferences().addPropertyChangeListener(s2, showMidiInfoListener);
463                            
464                            bShowMidiInfo = preferences().getBoolProperty(s2);
465                            channelInfoPane.setShowMidiInfo(bShowMidiInfo);
466                  }                  }
467                                    
468                  public void                  public void
# Line 438  public class SmallChannelView extends Pi Line 502  public class SmallChannelView extends Pi
502                    
503                  protected void                  protected void
504                  updateScreenInfo(SamplerChannel sc) {                  updateScreenInfo(SamplerChannel sc) {
505                            String s = btnInstr.getToolTipText();
506                            
507                          int status = sc.getInstrumentStatus();                          int status = sc.getInstrumentStatus();
508                          if(status >= 0 && status < 100) {                          if(status >= 0 && status < 100) {
509                                  btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status));                                  btnInstr.setText(i18n.getLabel("ChannelScreen.loadingInstrument", status));
510                                    if(s != null) btnInstr.setToolTipText(null);
511                          } else if(status == -1) {                          } else if(status == -1) {
512                                  btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                                  btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
513                                    if(s != null) btnInstr.setToolTipText(null);
514                          } else if(status < -1) {                          } else if(status < -1) {
515                                   btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument"));                                   btnInstr.setText(i18n.getLabel("ChannelScreen.errorLoadingInstrument"));
516                                     if(s != null) btnInstr.setToolTipText(null);
517                          } else {                          } else {
518                                  if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());                                  if(sc.getInstrumentName() != null) btnInstr.setText(sc.getInstrumentName());
519                                  else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));                                  else btnInstr.setText(i18n.getButtonLabel("ChannelScreen.btnInstr"));
520                                    
521                                    btnInstr.setToolTipText(sc.getInstrumentName());
522                          }                          }
523                                                    
524                          //channelInfoPane.updateChannelInfo();                          channelInfoPane.updateChannelInfo();
525                    }
526                    
527                    public void
528                    onDestroy() {
529                            String s = "channel.smallView.showChannelNumbering";
530                            preferences().removePropertyChangeListener(s, chnNumberingListener);
531                            
532                            s = "channel.smallView.showMidiInfo";
533                            preferences().removePropertyChangeListener(s, showMidiInfoListener);
534                  }                  }
535          }          }
536                    
537          private static class ChannelInfoPane extends JPanel {          private static class ChannelInfoPane extends JPanel {
538                  private final Channel channel;                  private final Channel channel;
539                  private final JLabel lInfo;                  private final JLabel lInfo;
540                    
541                    private int channelIndex = -1;
542                    
543                    private boolean showNumbering;
544                    private boolean showMidiInfo;
545                                                    
546                  ChannelInfoPane(Channel channel) {                  ChannelInfoPane(Channel channel) {
547                          this.channel = channel;                          this.channel = channel;
# Line 466  public class SmallChannelView extends Pi Line 551  public class SmallChannelView extends Pi
551                                                    
552                          lInfo = createScreenLabel("");                          lInfo = createScreenLabel("");
553                          lInfo.setFont(Res.fontScreenMono);                          lInfo.setFont(Res.fontScreenMono);
554                          lInfo.setText("1234");                          lInfo.setToolTipText(i18n.getLabel("SmallChannelView.ttMidiPortChannel"));
555                            
556                            updateChannelIndex();
557                            
558                            updateLabelLength();
559                            
560                            add(lInfo);
561                    }
562                    
563                    private void
564                    updateLabelLength() {
565                            lInfo.setPreferredSize(null);
566                            
567                            int l = 0;
568                            if(getShowNumbering()) l += 4;
569                            if(getShowMidiInfo()) l += 6;
570                            
571                            StringBuffer sb = new StringBuffer();
572                            for(int i = 0; i < l; i++) sb.append("0");
573                            lInfo.setText(sb.toString());
574                            
575                          lInfo.setPreferredSize(lInfo.getPreferredSize()); // Don't remove this!                          lInfo.setPreferredSize(lInfo.getPreferredSize()); // Don't remove this!
576                          lInfo.setMinimumSize(lInfo.getPreferredSize());                          lInfo.setMinimumSize(lInfo.getPreferredSize());
577                          lInfo.setMaximumSize(lInfo.getPreferredSize());                          lInfo.setMaximumSize(lInfo.getPreferredSize());
578                    }
579                    
580                    protected void
581                    updateChannelInfo() {
582                            StringBuffer sb = new StringBuffer();
583                                                    
584                          updateChannelInfo();                          if(getShowNumbering()) {
585                                    if(channelIndex < 10) sb.append(" ");
586                                    sb.append(channelIndex + 1).append(": ");
587                            }
588                                                    
589                          add(lInfo);                          if(getShowMidiInfo()) {
590                                    SamplerChannel sc = channel.getChannelInfo();
591                                    if(sc.getMidiInputDevice() == -1) {
592                                            sb.append("-/-");
593                                    } else {
594                                            sb.append(sc.getMidiInputPort()).append("/");
595                                            
596                                            if(sc.getMidiInputChannel() == -1) sb.append("All");
597                                            else sb.append(sc.getMidiInputChannel() + 1);
598                                    }
599                            }
600                                                    
601                          setPreferredSize(getPreferredSize()); // Don't remove this!                          lInfo.setText(sb.toString());
                         setMinimumSize(getPreferredSize());  
                         setMaximumSize(getPreferredSize());  
602                  }                  }
603                                    
604                  protected void                  protected void
605                  updateChannelInfo() {                  updateChannelIndex() {
606                          String s = channel.getChannelId() < 10 ? " " : "";                          int i = CC.getSamplerModel().getChannelIndex(channel.getModel());
607                          s += String.valueOf(channel.getChannelId()) + ":";                          channelIndex = i;
608                            if(!getShowNumbering()) return;
609                            
610                            updateChannelInfo();
611                    }
612                    
613                    protected boolean
614                    getShowNumbering() { return showNumbering; }
615                    
616                    protected void
617                    setShowNumbering(boolean b) {
618                            if(b == showNumbering) return;
619                            showNumbering = b;
620                                                    
621                          /*SamplerChannel sc = channel.getChannelInfo();                          updateLabelLength();
622                          s += sc.getMidiInputPort() + "/";                          updateChannelIndex();
623                    }
624                    
625                    protected boolean
626                    getShowMidiInfo() { return showMidiInfo; }
627                    
628                    protected void
629                    setShowMidiInfo(boolean b) {
630                            if(b == showMidiInfo) return;
631                            showMidiInfo = b;
632                                                    
633                          if(sc.getMidiInputChannel() == -1) s += "All";                          updateLabelLength();
634                          else s += sc.getMidiInputChannel() + 1;*/                          updateChannelInfo();
                         lInfo.setText(s);  
635                  }                  }
636          }          }
637                    

Legend:
Removed from v.1742  
changed lines
  Added in v.1743

  ViewVC Help
Powered by ViewVC