/[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 1733 by iliev, Sat May 3 01:40:06 2008 UTC revision 1734 by iliev, Sun May 4 18:40:13 2008 UTC
# Line 67  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.JSChannel;
71    
72  import org.jsampler.view.std.JSChannelOutputRoutingDlg;  import org.jsampler.view.std.JSChannelOutputRoutingDlg;
73  import org.jsampler.view.std.JSFxSendsPane;  import org.jsampler.view.std.JSFxSendsPane;
74  import org.jsampler.view.std.JSInstrumentChooser;  import org.jsampler.view.std.JSInstrumentChooser;
# Line 84  import static org.jsampler.view.std.JSVo Line 86  import static org.jsampler.view.std.JSVo
86   *   *
87   * @author Grigor Iliev   * @author Grigor Iliev
88   */   */
89  public class Channel extends org.jsampler.view.JSChannel {  public class Channel extends JSChannel {
90          private final JXCollapsiblePane mainPane;          private final JXCollapsiblePane mainPane;
         private ChannelView channelView;  
91          private ChannelOptionsView channelOptionsView;          private ChannelOptionsView channelOptionsView;
92          private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();          private final ChannelOptionsPane optionsPane = new ChannelOptionsPane();
93                    
94            private final ViewTracker viewTracker;
95            
96          private InformationDialog fxSendsDlg = null;          private InformationDialog fxSendsDlg = null;
97                    
98          private final ContextMenu contextMenu = new ContextMenu();          private final ContextMenu contextMenu = new ContextMenu();
# Line 132  public class Channel extends org.jsample Line 135  public class Channel extends org.jsample
135                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);                  optionsPane.setAlignmentX(JPanel.CENTER_ALIGNMENT);
136                                    
137                  mainPane = new JXCollapsiblePane();                  mainPane = new JXCollapsiblePane();
138                    viewTracker = new ViewTracker();
139                    
140                  mainPane.getContentPane().setLayout (                  mainPane.getContentPane().setLayout (
141                          new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)                          new BoxLayout(mainPane.getContentPane(), BoxLayout.Y_AXIS)
142                  );                  );
# Line 231  public class Channel extends org.jsample Line 236  public class Channel extends org.jsample
236          expandChannel(boolean animated) {          expandChannel(boolean animated) {
237                  boolean b = optionsPane.isAnimated();                  boolean b = optionsPane.isAnimated();
238                  optionsPane.setAnimated(animated);                  optionsPane.setAnimated(animated);
239                  channelView.expandChannel();                  viewTracker.getCurrentView().expandChannel();
240                  optionsPane.setAnimated(b);                  optionsPane.setAnimated(b);
241          }          }
242                    
# Line 241  public class Channel extends org.jsample Line 246  public class Channel extends org.jsample
246           */           */
247          private void          private void
248          updateChannelInfo() {          updateChannelInfo() {
249                  channelView.updateChannelInfo();                  viewTracker.getCurrentView().updateChannelInfo();
250                  channelOptionsView.updateChannelInfo();                  viewTracker.getCurrentView().getChannelOptionsView().updateChannelInfo();
251          }          }
252                    
253          public void          public void
# Line 256  public class Channel extends org.jsample Line 261  public class Channel extends org.jsample
261                  }                  }
262          }          }
263                    
264            public void
265            fallbackToOriginalView() {
266                    viewTracker.fallbackToOriginalView();
267            }
268            
269            public boolean
270            isUsingOriginalView() {
271                    return viewTracker.isUsingOriginalView();
272            }
273            
274          protected void          protected void
275          onDestroy() {          onDestroy() {
276                  CC.getSamplerModel().removeSamplerChannelListListener(getHandler());                  CC.getSamplerModel().removeSamplerChannelListListener(getHandler());
277                  preferences().removePropertyChangeListener(ANIMATED, animatedPorpetyListener);                  preferences().removePropertyChangeListener(ANIMATED, animatedPorpetyListener);
278                                    
279                  channelView.uninstallView();                  viewTracker.onDestroy();
                 channelOptionsView.uninstallView();  
280          }          }
281                                    
282          public void          public void
# Line 317  public class Channel extends org.jsample Line 331  public class Channel extends org.jsample
331                   */                   */
332                  public void                  public void
333                  streamCountChanged(SamplerChannelEvent e) {                  streamCountChanged(SamplerChannelEvent e) {
334                          channelView.updateStreamCount(getModel().getStreamCount());                          viewTracker.getCurrentView().updateStreamCount(getModel().getStreamCount());
335                  }                  }
336                    
337                  /**                  /**
# Line 327  public class Channel extends org.jsample Line 341  public class Channel extends org.jsample
341                   */                   */
342                  public void                  public void
343                  voiceCountChanged(SamplerChannelEvent e) {                  voiceCountChanged(SamplerChannelEvent e) {
344                          channelView.updateVoiceCount(getModel().getVoiceCount());                          viewTracker.getCurrentView().updateVoiceCount(getModel().getVoiceCount());
345                  }                  }
346                                    
347                  /**                  /**
# Line 359  public class Channel extends org.jsample Line 373  public class Channel extends org.jsample
373                  }                  }
374          }          }
375                    
376            private static boolean viewTrackerMousePressed = false;
377            
378            class ViewTracker extends MouseAdapter implements PropertyChangeListener {
379                    private ChannelView originalView;
380                    private ChannelView mouseOverView;
381                    private ChannelView currentView;
382                    
383                    
384                    private boolean mouseOver = false;
385                    
386                    private final ActionListener guiListener;
387                    
388                    ViewTracker() {
389                            guiListener = new ActionListener() {
390                                    public void
391                                    actionPerformed(ActionEvent e) {
392                                            if(viewTrackerMousePressed) return;
393                                            
394                                            if(mainPane.getMousePosition(true) != null) {
395                                                    mouseEntered(null);
396                                            } else {
397                                                    mouseExited(null);
398                                            }
399                                    }
400                            };
401                            
402                            updateMouseOverViewType();
403                            
404                            String s = DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER;
405                            preferences().addPropertyChangeListener(s, this);
406                            
407                            s = CHANNEL_VIEW_ON_MOUSE_OVER;
408                            preferences().addPropertyChangeListener(s, this);
409                    }
410                    
411                    public boolean
412                    isUsingOriginalView() {
413                            return currentView == originalView;
414                    }
415                    
416                    private void
417                    installListeners() {
418                            ((MainFrame)CC.getMainFrame()).getGuiTimer().addActionListener(guiListener);
419                    }
420                    
421                    private void
422                    uninstallListeners() {
423                            ((MainFrame)CC.getMainFrame()).getGuiTimer().removeActionListener(guiListener);
424                    }
425                    
426                    private void
427                    updateMouseOverViewType() {
428                            if(mouseOverView != null) {
429                                    mouseOverView.removeEnhancedMouseListener(this);
430                            }
431                            
432                            boolean b;
433                            b = preferences().getBoolProperty(DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER);
434                            if(!b) {
435                                    mouseOverView = null;
436                                    uninstallListeners();
437                                    return;
438                            }
439                            
440                            Channel channel = Channel.this;
441                            int i = preferences().getIntProperty(CHANNEL_VIEW_ON_MOUSE_OVER);
442                            
443                            switch(i) {
444                                    case 0: mouseOverView = new SmallChannelView(channel); break;
445                                    case 1: mouseOverView = new NormalChannelView(channel); break;
446                                    default:mouseOverView = null;
447                            }
448                            
449                            if(mouseOverView != null) {
450                                    installListeners();
451                                    mouseOverView.addEnhancedMouseListener(this);
452                            }
453                    }
454                    
455                    public ChannelView
456                    getCurrentView() { return currentView; }
457                    
458                    public void
459                    setView(ChannelView view) {
460                            setView(view, true);
461                    }
462                    
463                    public void
464                    setView(ChannelView view, boolean manual) {
465                            boolean selected = false;
466                            if(currentView != null) selected = currentView.isOptionsButtonSelected();
467                            
468                            if(manual) {
469                                    if(originalView != null) {
470                                            originalView.removeEnhancedMouseListener(this);
471                                    }
472                                    
473                                    if(originalView != currentView) destroyOriginalView();
474                                    if(currentView != null && currentView.getType() == view.getType()) {
475                                            originalView = currentView;
476                                            originalView.addEnhancedMouseListener(this);
477                                            destroyView(view);
478                                            return;
479                                    }
480                                    
481                                    removeCurrentView();
482                                    
483                                    originalView = view;
484                                    originalView.addEnhancedMouseListener(this);
485                                    currentView = view;
486                            } else {
487                                    if(view.getType() == getCurrentView().getType()) {
488                                            destroyView(view);
489                                            return;
490                                    }
491                                    
492                                    removeCurrentView();
493                                    currentView = view;
494                            }
495                            
496                            currentView.setOptionsButtonSelected(selected);
497                            
498                            updateView();
499                    }
500                    
501                    private void
502                    updateView() {
503                            JComponent c = getCurrentView().getChannelOptionsView().getComponent();
504                            optionsPane.setContentPane(c);
505                            
506                            updateChannelInfo();
507                    
508                            mainPane.add(getCurrentView().getComponent());
509                            mainPane.add(optionsPane);
510                            mainPane.validate();
511                            mainPane.revalidate();
512                            mainPane.repaint();
513                    }
514                    
515                    public void
516                    fallbackToOriginalView() {
517                            if(currentView == originalView) return;
518                            
519                            boolean selected = false;
520                            if(currentView != null) selected = currentView.isOptionsButtonSelected();
521                            
522                            removeCurrentView();
523                            currentView = originalView;
524                            currentView.setOptionsButtonSelected(selected);
525                            
526                            updateView();
527                    }
528                    
529                    private void
530                    removeCurrentView() { removeView(currentView); }
531                    
532                    private void
533                    destroyCurrentView() { destroyView(currentView); }
534                    
535                    private void
536                    removeOriginalView() { removeView(originalView); }
537                    
538                    private void
539                    destroyOriginalView() { destroyView(originalView); }
540                    
541                    private void
542                    removeView(ChannelView view) {
543                            if(view == null) return;
544                            
545                            mainPane.remove(view.getComponent());
546                            mainPane.remove(optionsPane);
547                                    
548                            destroyView(view);
549                    }
550                    
551                    private void
552                    destroyView(ChannelView view) {
553                            if(view == null) return;
554                            
555                            view.uninstallView();
556                            view.getChannelOptionsView().uninstallView();
557                            
558                            view = null;
559                    }
560                    
561                    private void
562                    mouseEntered() {
563                            if(mouseOverView == null) return;
564                            if(getCurrentView().getType() == mouseOverView.getType()) return;
565                            
566                            JSChannel[] channels = CC.getMainFrame().getChannelsPane(0).getChannels();
567                            for(JSChannel c : channels) {
568                                    if(c == Channel.this) continue;
569                                    
570                                    Channel chn = (Channel)c;
571                                    if(!(chn).isUsingOriginalView()) chn.fallbackToOriginalView();
572                            }
573                            
574                            setView(mouseOverView, false);
575                    }
576                    
577                    private void
578                    mouseExited() {
579                            if(mouseOverView == null) return;
580                            if(getCurrentView().getType() == originalView.getType()) return;
581                            
582                            fallbackToOriginalView();
583                    }
584                    
585                    public void
586                    mouseEntered(MouseEvent e) {
587                            if(viewTrackerMousePressed) return;
588                            
589                            if(mouseOver) return;
590                            mouseOver = true;
591                            mouseEntered();
592                    }
593                    
594                    public void
595                    mouseExited(MouseEvent e) {
596                            if(viewTrackerMousePressed) return;
597                            
598                            if(mainPane.getMousePosition(true) != null) return;
599                            if(!mouseOver) return;
600                            mouseOver = false;
601                            mouseExited();
602                    }
603                    
604                    public void
605                    mousePressed(MouseEvent e) {
606                            viewTrackerMousePressed = true;
607                    }
608                    
609                    public void
610                    mouseReleased(MouseEvent e) {
611                            viewTrackerMousePressed = false;
612                    }
613                    
614                    public void
615                    onDestroy() {
616                            destroyCurrentView();
617                            destroyOriginalView();
618                            
619                            uninstallListeners();
620                            
621                            if(currentView != null) {
622                                    currentView.removeEnhancedMouseListener(this);
623                            }
624                            
625                            if(mouseOverView != null) {
626                                    mouseOverView.removeEnhancedMouseListener(this);
627                            }
628                            
629                            String s = DIFFERENT_CHANNEL_VIEW_ON_MOUSE_OVER;
630                            preferences().removePropertyChangeListener(s, this);
631                            
632                            s = CHANNEL_VIEW_ON_MOUSE_OVER;
633                            preferences().removePropertyChangeListener(s, this);
634                    }
635                    
636                    public void
637                    propertyChange(PropertyChangeEvent e) {
638                            updateMouseOverViewType();
639                    }
640            }
641            
642          class EditInstrumentAction extends AbstractAction implements SamplerChannelListener {          class EditInstrumentAction extends AbstractAction implements SamplerChannelListener {
643                  EditInstrumentAction() {                  EditInstrumentAction() {
644                          super(i18n.getMenuLabel("channels.editInstrument"));                          super(i18n.getMenuLabel("channels.editInstrument"));
# Line 428  public class Channel extends org.jsample Line 708  public class Channel extends org.jsample
708                                    
709                  public void                  public void
710                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
711                          if(channelView instanceof SmallChannelView) return;                          viewTracker.setView(new SmallChannelView(Channel.this));
                           
                         if(channelView != null) {  
                                 mainPane.remove(channelView.getComponent());  
                                 mainPane.remove(optionsPane);  
                                   
                                 channelView.uninstallView();  
                                 channelOptionsView.uninstallView();  
                         }  
                           
                         channelView = new SmallChannelView(Channel.this);  
                         channelOptionsView = channelView.getChannelOptionsView();  
                           
                         optionsPane.setContentPane(channelOptionsView.getComponent());  
                           
                         updateChannelInfo();  
                   
                         mainPane.add(channelView.getComponent());  
                         mainPane.add(optionsPane);  
                         mainPane.validate();  
712                  }                  }
713          }          }
714                    
# Line 458  public class Channel extends org.jsample Line 719  public class Channel extends org.jsample
719                                    
720                  public void                  public void
721                  actionPerformed(ActionEvent e) {                  actionPerformed(ActionEvent e) {
722                          if(channelView instanceof NormalChannelView) return;                          viewTracker.setView(new NormalChannelView(Channel.this));
                           
                         if(channelView != null) {  
                                 mainPane.remove(channelView.getComponent());  
                                 mainPane.remove(optionsPane);  
                                   
                                 channelView.uninstallView();  
                                 channelOptionsView.uninstallView();  
                         }  
                           
                         channelView = new NormalChannelView(Channel.this);  
                         channelOptionsView = channelView.getChannelOptionsView();  
                           
                         optionsPane.setContentPane(channelOptionsView.getComponent());  
                           
                         updateChannelInfo();  
                   
                         mainPane.add(channelView.getComponent());  
                         mainPane.add(optionsPane);  
                         mainPane.validate();  
723                  }                  }
724          }          }
725                    

Legend:
Removed from v.1733  
changed lines
  Added in v.1734

  ViewVC Help
Powered by ViewVC