/*
 * Created on 27 janv. 2005
 */
package com.ht.svg.animat;

import java.awt.geom.AffineTransform;
import java.util.HashSet;
import java.util.Set;

import org.w3c.dom.Element;

import com.ht.data.listener.IDataListener;

/**
 * the listener to the changes of a specified data
 * 
 * @author ITRIS, Jordi SUC
 */
public abstract class AbstractAnimationDataListener implements IDataListener {

	protected AnimatHandler animationsHandler;
	/**
	 * 动画对象，可以为SVG标准动画，或RTDA非标准动画
	 */
	protected Element animationElement;
	/**
	 * 动画目标对象，一般为一个SVG图形元素
	 */
	protected Element parentElement;
	protected Set<String> dataNames = new HashSet<String>();
	/**
	 * whether this animation is a transform animation
	 */
	protected boolean isTransformAnimation = false;
	/**
	 * the transform that will be applied to the parent element
	 */
	protected AffineTransform affineTransform;
	/**
	 * the initial transform of the parent element
	 */
	protected AffineTransform initialAffineTransform;

	protected boolean isBlinkingAnimation = false;

	/**
	 * the constructor of the class
	 * 
	 * @param animationHandler
	 * @param animationElement
	 *            an animation node
	 */
	public AbstractAnimationDataListener(AnimatHandler animationHandler,
			Element animationElement) {

		this.animationsHandler = animationHandler;
		this.animationElement = animationElement;

		String vars = animationElement.getAttribute("tag-var");
		if (vars != null && !vars.isEmpty()) {
			for (String var : vars.split(",")) {
				dataNames.add(var.trim());
			}
		}

		// storing the initial value of the style attribute of the
		// parent node of the animation node
		if (animationElement != null
				&& animationElement.getParentNode() != null
				&& animationElement.getParentNode() instanceof Element) {

			parentElement = (Element) animationElement.getParentNode();
		}

		// setInvalidTag(true);
	}

	public Element getAnimationElement() {
		return animationElement;
	}

	/**
	 * @return Returns the parentElement.
	 */
	public Element getParentElement() {
		return parentElement;
	}

	/**
	 * @see fr.itris.glips.rtda.animaction.ListenerAction#invalidMarkersAllowed()
	 */
	public boolean invalidMarkersAllowed() {

		return true;
	}

	public void setAnimationsHandler(AnimatHandler animationsHandler) {
		this.animationsHandler = animationsHandler;
	}
	
	public AnimatHandler getAnimationsHandler() {
		return animationsHandler;
	}

	/**
	 * @return Returns the affineTransform.
	 */
	public AffineTransform getAffineTransform() {
		return affineTransform;
	}

	/**
	 * @return Returns the initialAffineTransform.
	 */
	public AffineTransform getInitialAffineTransform() {
		return initialAffineTransform;
	}

	/**
	 * @return Returns the isTransformAnimation.
	 */
	public boolean isTransformAnimation() {
		return isTransformAnimation;
	}

	public boolean isBlinkingAnimation() {
		return isBlinkingAnimation;
	}

	/**
	 * @see fr.itris.glips.rtda.animaction.ListenerAction#getTooltipText()
	 */
	public String getTooltipText() {
		return null;
	}

	@Override
	public Set<String> getDataVarNames() {
		return dataNames;
	}
	
	public void dispose() {
		
	}
}
