001        package com.croftsoft.apps.neuro;
002         
003        import java.awt.*;
004        import javax.swing.*;
005         
006        import com.croftsoft.core.animation.ComponentAnimator;
007        import com.croftsoft.core.animation.animator.NullComponentAnimator;
008        import com.croftsoft.core.gui.event.UserInputListener;
009        import com.croftsoft.core.lang.NullArgumentException;
010        import com.croftsoft.core.lang.lifecycle.Lifecycle;
011        import com.croftsoft.core.lang.lifecycle.Updatable;
012        import com.croftsoft.core.util.mail.Mail;
013         
014        /***********************************************************************
015        * Neuro view.
016        *  
017        * @version
018        *   $Id: NeuroView.java,v 1.5 2008/08/30 01:37:30 croft Exp $
019        * @since
020        *   2008-08-17
021        * @author
022        *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
023        ***********************************************************************/
024    
025        public final class  NeuroView
026          implements Lifecycle, Updatable
027        ////////////////////////////////////////////////////////////////////////
028        ////////////////////////////////////////////////////////////////////////
029        {
030             
031        private final NeuroConfig         neuroConfig;
032        
033        private final Mail<NeuroMessage>  mail;
034        
035        private final NeuroModel          neuroModel;
036         
037        private final JComponent          jComponent;
038        
039        //
040         
041        private ComponentAnimator  componentAnimator;
042         
043        ////////////////////////////////////////////////////////////////////////
044        ////////////////////////////////////////////////////////////////////////
045         
046        public  NeuroView (
047          final NeuroConfig         neuroConfig,
048          final Mail<NeuroMessage>  mail,
049          final NeuroModel          neuroModel )
050        ////////////////////////////////////////////////////////////////////////
051        {
052          NullArgumentException.checkArgs (
053            this.neuroConfig = neuroConfig,
054            this.mail        = mail,
055            this.neuroModel  = neuroModel );
056           
057          componentAnimator = NullComponentAnimator.INSTANCE;
058           
059          jComponent = new JComponent ( )
060            {
061              private static final long  serialVersionUID = 0L;
062               
063              @Override
064              public void  paintComponent ( final Graphics  graphics )
065              {
066                componentAnimator.paint ( this, ( Graphics2D ) graphics );
067              }
068            };
069        }
070         
071        ////////////////////////////////////////////////////////////////////////
072        // mutator methods
073        ////////////////////////////////////////////////////////////////////////
074         
075        public void  addUserInputListener (
076          final UserInputListener  userInputListener )
077        ////////////////////////////////////////////////////////////////////////
078        {
079          jComponent.addKeyListener   ( userInputListener );
080          
081          jComponent.addMouseListener ( userInputListener );
082        }
083         
084        public void  setContentPane ( final Container  contentPane )
085        ////////////////////////////////////////////////////////////////////////
086        {
087          contentPane.setLayout ( new BorderLayout ( ) );
088           
089          contentPane.add ( jComponent, BorderLayout.CENTER );
090        }
091         
092        ////////////////////////////////////////////////////////////////////////
093        // lifecycle methods
094        ////////////////////////////////////////////////////////////////////////
095         
096        public void  init ( )
097        ////////////////////////////////////////////////////////////////////////
098        {
099          System.out.println ( "NeuroView.init()" );
100           
101          componentAnimator = new NeuroAnimator (
102            neuroConfig,
103            mail,
104            neuroModel,
105            jComponent );
106        }
107         
108        public void  start ( )
109        ////////////////////////////////////////////////////////////////////////
110        {
111          System.out.println ( "NeuroView.start()" );       
112        }
113         
114        public void  stop ( )
115        ////////////////////////////////////////////////////////////////////////
116        {
117          System.out.println ( "NeuroView.stop()" );       
118        }
119         
120        public void  destroy ( )
121        ////////////////////////////////////////////////////////////////////////
122        {
123          System.out.println ( "NeuroView.destroy()" );
124        }
125         
126        public void  update ( )
127        ////////////////////////////////////////////////////////////////////////
128        {
129          final int  size = mail.size ( );
130          
131          for ( int  i = 0; i < size; i++ )
132          {
133            final NeuroMessage  neuroMessage = mail.get ( i );
134            
135            final NeuroMessage.Type  type = neuroMessage.getType ( );
136             
137            switch ( type )
138            {
139              case TOGGLE_CHANNEL_REQUEST:
140              case TOGGLE_PAUSE_REQUEST:
141                 
142                Toolkit.getDefaultToolkit ( ).beep ( );
143                 
144                break;
145                 
146              default:
147                
148                // ignore
149            }
150          }
151          
152          componentAnimator.update ( jComponent );
153        }       
154         
155        ////////////////////////////////////////////////////////////////////////
156        ////////////////////////////////////////////////////////////////////////
157        }