123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package algorithm;
- public class AnimationController {
- public static final int DEFAULT_DELAY = 100;
- private Action next;
- private boolean continuous;
- private long lastTime;
- private long delay;
- private int stepOption;
-
- public AnimationController()
- {
- stepOption = 0;
- next = null;
- continuous = false;
- lastTime = 0;
- delay = DEFAULT_DELAY;
- }
-
-
- public Action getNextAction() throws InterruptedException
- {
- long old = lastTime;
- Action ret = null;
- synchronized( this ) {
- while( next == null )
- wait();
- lastTime = System.currentTimeMillis();
- ret = next;
- }
- if( !continuous )
- next = null;
- else
- {
- if( lastTime - old < delay )
- {
- Thread.sleep( delay - ( lastTime - old ) );
- lastTime = System.currentTimeMillis();
- }
- }
- return ret;
- }
-
- public void setContinuous( boolean c )
- {
- if( !c && continuous )
- {
- synchronized( this ) {
- next = null;
- }
- }
- this.continuous = c;
- }
-
- public void setDelay( long delay )
- {
- this.delay = delay;
- }
-
- public void setNextAction( Action a )
- {
- synchronized( this ) {
- next = a;
- notify();
- }
- }
-
- public void setStepOption( int opt )
- {
- stepOption = opt;
- }
-
- public int getStepOption()
- {
- return stepOption;
- }
-
- public boolean isContinuous()
- {
- return continuous;
- }
- }
|