package at.oefai.aaa.animation;

import org.w3c.dom.svg.SVGSVGElement;

/**
 * SVG anim for directly setting the position of an object on top of another one.
 * @author Stefan Rank
 */
public class SetOnto extends BaseSVGAnim {
    private volatile boolean done = false;

    public BaseAnim newInstance() { return new SetOnto(); }

    protected void doFirstTime() {
        assert (this.args.size() == 2) : "wrong arguments for SetOnto";
        String theObject = this.args.get(0).getString();
        SVGSVGElement eleAbove = getNamedElement(theObject);
        SVGSVGElement eleBelow = getNamedElement(this.args.get(1).getString());
        // for set dont check if eleBelow already has a child svg (move would need to check)
        // take out above element from where it is now:
        eleAbove.getParentNode().removeChild(eleAbove);
        setElementsPos(eleAbove, getCoordsOfOntoObject(eleAbove, eleBelow));
        // put it under below in the tree (which puts it above on screen;-)
        eleBelow.appendChild(eleAbove);
        hideElement(theObject + SHADOW_POSTFIX);
        this.done = true;
    }

    public boolean isFinished() {
        return this.done;
    }

    protected void doIt() {
        //nothin
    }
}
