001         package com.croftsoft.apps.infant;
002         
003         import java.util.*;
004         
005         import com.croftsoft.core.gui.*;
006         import com.croftsoft.core.lang.lifecycle.*;
007         
008    import com.croftsoft.core.util.loop.*;
009    import com.croftsoft.core.util.slot.Slot;
010         
011         /*********************************************************************
012         * Infant stimulation and response with pacifier input.
013         *  
014         * @version
015         *   $Id: InfantMain.java,v 1.17 2008/09/20 05:01:49 croft Exp $
016         * @since
017         *   2006-01-03
018         * @author
019         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
020         *********************************************************************/
021    
022         public final class  InfantMain
023         //////////////////////////////////////////////////////////////////////
024         //////////////////////////////////////////////////////////////////////
025         {
026           
027         public static void  main ( final String [ ]  args )
028         //////////////////////////////////////////////////////////////////////
029         {
030           final InfantConfig  infantConfig = InfantConfig.load ( );
031           
032           System.out.println ( "\n" + infantConfig.getInfo ( ) );
033           
034           final Queue<InfantMessage>  requestQueue
035             = new LinkedList<InfantMessage> ( );
036           
037           final Slot<InfantMessage>  requestSlot = new Slot<InfantMessage> ( )
038             {
039               public boolean  offer ( final InfantMessage  infantMessage )
040               {
041                 return requestQueue.offer ( infantMessage );
042               }
043             };
044           
045           final Queue<InfantMessage>  eventQueue
046             = new LinkedList<InfantMessage> ( );
047           
048           final InfantModel  infantModel
049             = new InfantModel ( infantConfig, requestQueue, eventQueue );
050           
051           final InfantView  infantView = new InfantView (
052             infantConfig, infantModel, eventQueue, requestSlot );
053           
054           final InfantController  infantController
055             = new InfantController ( infantConfig, requestQueue );
056           
057           infantView.addUserInputListener ( infantController );
058           
059           final Updatable [ ]  updatables = new Updatable [ ] {
060             infantController,
061             infantModel,
062             infantView };
063           
064           final Looper  looper = new Looper (
065             new EventQueueUpdateLoop ( updatables ), // loopable
066             new NanoTimeLoopGovernor ( infantConfig.getUpdateRate ( ) ),
067             null, // exceptionHandler
068             infantConfig.getThreadName ( ),
069             Thread.MIN_PRIORITY,
070             true ); // useDaemonThread
071           
072           LifecycleWindowListener.launchFrameAsDesktopApp (
073             infantView.getJFrame ( ),
074             new CompositeLifecycle (
075               new Initializable [ ] { looper },
076               new Startable     [ ] { looper },
077               new Stoppable     [ ] { },
078               new Destroyable   [ ] { infantView, looper, infantModel } ),
079             infantConfig.getFrameSize ( ),
080             infantConfig.getShutdownConfirmationPrompt ( ) );
081         }
082           
083         //////////////////////////////////////////////////////////////////////
084         //////////////////////////////////////////////////////////////////////
085         }