PageRenderTime 25ms CodeModel.GetById 2ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/mt4j/util/animation/ani/AniAdapter.java

http://mt4j.googlecode.com/
Java | 125 lines | 74 code | 37 blank | 14 comment | 2 complexity | 9b2caa888d40a754f1680fa5ff2667f3 MD5 | raw file
  1package org.mt4j.util.animation.ani;
  2
  3import org.mt4j.util.animation.AnimationEvent;
  4import org.mt4j.util.animation.AnimationManager;
  5
  6import de.looksgood.ani.Ani;
  7
  8public class AniAdapter extends Ani {
  9	private AniAnimation correspondingAnimation;
 10	private Object animationTarget;
 11	private float currentStepDelta;
 12	
 13	
 14	static{
 15		Ani.noAutostart();
 16	}
 17	
 18//	public AdaptedAni(Adapter theTarget, float from, float to, float theDuration, float theDelay,
 19//			String theFieldName, String theEasing,
 20//			String theCallback) {
 21//		super(theTarget, theDuration, theDelay, "x", to, theEasing,
 22//				theCallback);
 23//		
 24//		this.setBegin(from);
 25//		this.correspondingAnimation = theTarget;
 26//	}
 27
 28	
 29
 30	public AniAdapter(AniAnimation theTarget, float from, float to, float theDuration, float theDelay, String theFieldName, String theEasing, Object animationTarget) {
 31		super(theTarget, theDuration, theDelay, theFieldName, to, theEasing);
 32		this.setBegin(from);
 33		this.currentStepDelta = 0;
 34		
 35		this.correspondingAnimation = theTarget;
 36		this.animationTarget = animationTarget;
 37	}
 38
 39	
 40	@Override
 41	public void seek(float theValue) {
 42		if (theValue == 0.0f){
 43			this.currentStepDelta = 0.0f;
 44			this.position = getBegin(); //FIXME TEST to fix bug with currentStepDelta
 45		}
 46		super.seek(theValue);
 47	}
 48	
 49	
 50	@Override
 51	protected void dispatchOnStart() {
 52		super.dispatchOnStart();
 53		correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_STARTED, correspondingAnimation, animationTarget));
 54	}
 55	
 56	
 57	@Override
 58	protected void updatePosition() {
 59		float lastPosition = this.getPosition();
 60		super.updatePosition();
 61		this.currentStepDelta = this.getPosition() - lastPosition;
 62//		if (this.currentStepDelta == -1.0f){
 63//			System.out.println();
 64//		}
 65		correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_UPDATED, correspondingAnimation, animationTarget));
 66	}
 67	
 68	
 69	
 70	@Override
 71	protected void dispatchOnEnd() {
 72		this.currentStepDelta = 0.0f; //Else we get the same delta as from the last step twice!
 73		super.dispatchOnEnd();
 74		correspondingAnimation.fireAnimationEvent(new AnimationEvent(this, AnimationEvent.ANIMATION_ENDED, correspondingAnimation, animationTarget));
 75	}
 76	
 77	
 78	@Override
 79	public void start() {
 80//		this.currentStepDelta = 0;
 81		AnimationManager.getInstance().registerAnimation(correspondingAnimation);
 82		super.start();
 83	}
 84	
 85	@Override
 86	public void end() {
 87		AnimationManager.getInstance().unregisterAnimation(correspondingAnimation);
 88		super.end();
 89//		this.currentStepDelta = 0;
 90	}
 91	
 92	
 93	public float getCurrentStepDelta(){
 94		return this.currentStepDelta;
 95	}
 96	
 97
 98	@Override
 99	public void repeat(int theRepeatCount) {
100		super.repeat(theRepeatCount);
101	}
102
103
104	@Override
105	public void setCallback(String theCallback) {
106		super.setCallback(theCallback);
107	}
108
109	@Override
110	public void setDelay(float theDurationDelay) {
111		super.setDelay(theDurationDelay);
112	}
113
114	@Override
115	public void setDuration(float theDurationEasing) {
116		super.setDuration(theDurationEasing);
117	}
118
119
120	
121	
122	
123	
124
125}