001 package com.croftsoft.apps.jogl; 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 import com.croftsoft.core.util.mail.FlipMail; 014 015 import com.croftsoft.apps.jogl.imp.JoglConfigImp; 016 import com.croftsoft.apps.jogl.imp.JoglModelImp; 017 018 /*********************************************************************** 019 * Main. 020 * 021 * Launches the application within a framework. 022 * 023 * @version 024 * $Id: JoglMain.java,v 1.9 2008/04/19 21:57:09 croft Exp $ 025 * @since 026 * 2008-02-10 027 * @author 028 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 029 ***********************************************************************/ 030 031 public final class JoglMain 032 implements Lifecycle 033 //////////////////////////////////////////////////////////////////////// 034 //////////////////////////////////////////////////////////////////////// 035 { 036 037 private final JoglConfig joglConfig; 038 039 private final JoglModelImp joglModelImp; 040 041 private final JoglController joglController; 042 043 private final JoglView joglView; 044 045 private final Looper looper; 046 047 //////////////////////////////////////////////////////////////////////// 048 // public static methods 049 //////////////////////////////////////////////////////////////////////// 050 051 public static void main ( final String [ ] args ) 052 //////////////////////////////////////////////////////////////////////// 053 { 054 final JoglMain joglMain = new JoglMain ( args ); 055 056 final JFrame jFrame = new JFrame ( 057 joglMain.joglConfig.getFrameTitle ( ) ); 058 059 joglMain.setContentPane ( jFrame.getContentPane ( ) ); 060 061 // The Frame is the framework. 062 063 LifecycleWindowListener.launchFrameAsDesktopApp ( 064 jFrame, 065 joglMain, 066 joglMain.joglConfig.getFrameSize ( ), 067 joglMain.joglConfig.getShutdownConfirmationPrompt ( ) ); 068 } 069 070 //////////////////////////////////////////////////////////////////////// 071 // constructor methods 072 //////////////////////////////////////////////////////////////////////// 073 074 public JoglMain ( final String [ ] args ) 075 //////////////////////////////////////////////////////////////////////// 076 { 077 joglConfig = JoglConfigImp.load ( args ); 078 079 System.out.println ( "\n" + joglConfig.getInfo ( ) ); 080 081 final FlipMail<JoglMessage> flipMail 082 = new FlipMail<JoglMessage> ( ); 083 084 joglModelImp = new JoglModelImp ( 085 joglConfig, 086 flipMail ); 087 088 joglController = new JoglController ( flipMail ); 089 090 joglView = new JoglView ( 091 flipMail, 092 joglModelImp ); 093 094 joglView.addKeyListener ( joglController ); 095 096 joglView.addMouseListener ( joglController ); 097 098 final Updatable [ ] updatables = new Updatable [ ] { 099 flipMail, 100 joglModelImp, 101 joglView, 102 joglController }; 103 104 looper = new Looper ( 105 new EventQueueUpdateLoop ( updatables ), // loopable 106 new NanoTimeLoopGovernor ( joglConfig.getUpdateRate ( ) ), 107 null, // exceptionHandler 108 joglConfig.getThreadName ( ), 109 Thread.MIN_PRIORITY, 110 true ); // useDaemonThread 111 } 112 113 //////////////////////////////////////////////////////////////////////// 114 // accessor methods 115 //////////////////////////////////////////////////////////////////////// 116 117 public JoglConfig getJoglConfig ( ) 118 //////////////////////////////////////////////////////////////////////// 119 { 120 return joglConfig; 121 } 122 123 //////////////////////////////////////////////////////////////////////// 124 // mutator methods 125 //////////////////////////////////////////////////////////////////////// 126 127 public void setContentPane ( final Container contentPane ) 128 //////////////////////////////////////////////////////////////////////// 129 { 130 joglView.setContentPane ( contentPane ); 131 } 132 133 //////////////////////////////////////////////////////////////////////// 134 // interface Lifecycle methods 135 //////////////////////////////////////////////////////////////////////// 136 137 public void init ( ) 138 //////////////////////////////////////////////////////////////////////// 139 { 140 LifecycleLib.init ( joglView, looper ); 141 } 142 143 public void start ( ) 144 //////////////////////////////////////////////////////////////////////// 145 { 146 LifecycleLib.start ( joglView, joglController, looper ); 147 } 148 149 public void stop ( ) 150 //////////////////////////////////////////////////////////////////////// 151 { 152 LifecycleLib.stop ( joglView, looper ); 153 } 154 155 public void destroy ( ) 156 //////////////////////////////////////////////////////////////////////// 157 { 158 LifecycleLib.destroy ( joglView, looper ); 159 } 160 161 //////////////////////////////////////////////////////////////////////// 162 //////////////////////////////////////////////////////////////////////// 163 }