001 package com.croftsoft.core.util.loop;
002
003 import java.awt.EventQueue;
004
005 import com.croftsoft.core.lang.lifecycle.Updatable;
006 import com.croftsoft.core.lang.lifecycle.UpdateRunner;
007
008 /***********************************************************************
009 * A Loopable that updates Updatables via the EventQueue.
010 *
011 * @version
012 * $Id: EventQueueUpdateLoop.java,v 1.3 2008/09/20 05:01:27 croft Exp $
013 * @since
014 * 2006-01-03
015 * @author
016 * <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
017 ***********************************************************************/
018
019 public final class EventQueueUpdateLoop
020 implements Loopable
021 ////////////////////////////////////////////////////////////////////////
022 ////////////////////////////////////////////////////////////////////////
023 {
024
025 private final Runnable updateRunner;
026
027 ////////////////////////////////////////////////////////////////////////
028 ////////////////////////////////////////////////////////////////////////
029
030 public EventQueueUpdateLoop ( final Updatable... updatables )
031 ////////////////////////////////////////////////////////////////////////
032 {
033 updateRunner = new UpdateRunner ( updatables );
034 }
035
036 ////////////////////////////////////////////////////////////////////////
037 ////////////////////////////////////////////////////////////////////////
038
039 public boolean loop ( )
040 ////////////////////////////////////////////////////////////////////////
041 {
042 try
043 {
044 EventQueue.invokeAndWait ( updateRunner );
045
046 return true;
047 }
048 catch ( InterruptedException ex )
049 {
050 // ignore
051 }
052 catch ( Exception ex )
053 {
054 ex.printStackTrace ( );
055 }
056
057 return false;
058 }
059
060 ////////////////////////////////////////////////////////////////////////
061 ////////////////////////////////////////////////////////////////////////
062 }