001         package com.croftsoft.apps.slideshow;
002         
003         import java.awt.*;
004         import javax.swing.*;
005    
006         import com.croftsoft.core.gui.LifecycleWindowListener;
007         import com.croftsoft.core.lang.lifecycle.Lifecycle;
008         import com.croftsoft.core.lang.lifecycle.LifecycleLib;
009         import com.croftsoft.core.lang.lifecycle.Updatable;
010         import com.croftsoft.core.util.loop.EventQueueUpdateLoop;
011         import com.croftsoft.core.util.loop.Looper;
012         import com.croftsoft.core.util.loop.NanoTimeLoopGovernor;
013    
014         /*********************************************************************
015         * CroftSoft Savor.
016         *
017         * @version
018         *   $Id: SlideshowMain.java,v 1.1 2006/12/16 09:27:57 croft Exp $
019         * @since
020         *   2006-12-09
021         * @author
022         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
023         *********************************************************************/
024    
025         public final class  SlideshowMain
026           implements Lifecycle
027         //////////////////////////////////////////////////////////////////////
028         //////////////////////////////////////////////////////////////////////
029         {
030         
031         private final SlideshowConfig  slideshowConfig;
032         
033         private final SlideshowView    slideshowView;
034           
035         private final Looper           looper;
036         
037         //////////////////////////////////////////////////////////////////////
038         // public static methods
039         //////////////////////////////////////////////////////////////////////
040    
041         public static void  main ( final String [ ]  args )
042         //////////////////////////////////////////////////////////////////////
043         {
044           final SlideshowMain  slideshowMain = new SlideshowMain ( args );
045           
046           final JFrame  jFrame = new JFrame (
047             slideshowMain.slideshowConfig.getFrameTitle ( ) );
048           
049           slideshowMain.setContentPane ( jFrame.getContentPane ( ) );
050           
051           // The Frame is the framework.
052           
053           LifecycleWindowListener.launchFrameAsDesktopApp (
054             jFrame,
055             slideshowMain,
056             slideshowMain.slideshowConfig.getFrameSize ( ),
057             slideshowMain.slideshowConfig.getShutdownConfirmationPrompt ( ) );
058         }
059         
060         //////////////////////////////////////////////////////////////////////
061         //////////////////////////////////////////////////////////////////////
062         
063         public  SlideshowMain ( final String [ ]  args )
064         //////////////////////////////////////////////////////////////////////
065         {
066           slideshowConfig = SlideshowConfig.load ( args );
067           
068           slideshowView = new SlideshowView ( slideshowConfig );
069           
070           final Updatable [ ]  updatables = new Updatable [ ] {
071             slideshowView };
072           
073           looper = new Looper (
074             new EventQueueUpdateLoop ( updatables ), // loopable
075             new NanoTimeLoopGovernor ( slideshowConfig.getUpdateRate ( ) ),
076             null, // exceptionHandler
077             slideshowConfig.getThreadName ( ),
078             Thread.MIN_PRIORITY,
079             true ); // useDaemonThread
080         }
081         
082         //////////////////////////////////////////////////////////////////////
083         // accessor methods
084         //////////////////////////////////////////////////////////////////////
085         
086         public SlideshowConfig  getSlideshowConfig ( )
087         //////////////////////////////////////////////////////////////////////
088         {
089           return slideshowConfig;
090         }
091         
092         //////////////////////////////////////////////////////////////////////
093         // mutator methods
094         //////////////////////////////////////////////////////////////////////
095         
096         public void  setContentPane ( final Container  contentPane )
097         //////////////////////////////////////////////////////////////////////
098         {
099           slideshowView.setContentPane ( contentPane );
100         }
101         
102         //////////////////////////////////////////////////////////////////////
103         // interface Lifecycle methods
104         //////////////////////////////////////////////////////////////////////
105         
106         public void  init ( )
107         //////////////////////////////////////////////////////////////////////
108         {
109           LifecycleLib.init ( slideshowView, looper );
110         }
111         
112         public void  start ( )
113         //////////////////////////////////////////////////////////////////////
114         {
115           LifecycleLib.start ( looper );
116         }
117         
118         public void  stop ( )
119         //////////////////////////////////////////////////////////////////////
120         {
121           LifecycleLib.stop ( looper );
122         }
123         
124         public void  destroy ( )
125         //////////////////////////////////////////////////////////////////////
126         {
127           LifecycleLib.destroy ( looper );
128         }     
129         
130         //////////////////////////////////////////////////////////////////////
131         //////////////////////////////////////////////////////////////////////
132         }