All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.gov.nasa.worldwind.animation.BasicAnimator Maven / Gradle / Ivy

Go to download

World Wind is a collection of components that interactively display 3D geographic information within Java applications or applets.

There is a newer version: 2.0.0-986
Show newest version
/*
 * Copyright (C) 2012 United States Government as represented by the Administrator of the
 * National Aeronautics and Space Administration.
 * All Rights Reserved.
 */
package gov.nasa.worldwind.animation;

/**
 * @author jym
 * @version $Id: BasicAnimator.java 1171 2013-02-11 21:45:02Z dcollins $
 */

/**
 * A base class for an interpolating Animator.
 */
public class BasicAnimator implements Animator
{
    private boolean stopOnInvalidState = false;
    private boolean lastStateValid = true;
    private boolean hasNext = true;

    /**
     * Used to drive the animators next value based on the interpolant returned by the
     * Interpolator's next interpolant
     */
    protected Interpolator interpolator;

    /**
     * Constructs a BasicAnimator.  Sets the Animator's Interpolator to
     * null. 
     */
    public BasicAnimator()
    {
        interpolator = null;
    }

    /**
     * Constructs a BasicAnimator.  The next method will use the passed
     * Interpolator to retrieve the interpolant
     *
     * @param interpolator The Interpolator to be used to get the interpolant for
     * setting the next value.
     */
    public BasicAnimator(Interpolator interpolator)
    {
        this.interpolator = interpolator;
    }

    /**
     * Calls the set method with the next interpolant as determined
     * by the interpolator member.
     */
    public void next()
    {
        set(this.interpolator.nextInterpolant());
    }

    /**
     * Calls the setImpl method with the interpolant value.  Deriving classes are expected to
     * implement the desired action of a set operation in thier setImpl method.
     *
     * @param interpolant A value between 0 and 1.
     */
    public void set(double interpolant)
    {
        this.setImpl(interpolant);
        if (isStopOnInvalidState() && !isLastStateValid())
        {
            this.stop();
        }
    }

    /**
     * Returns true if the Animator has more elements.
     *
     * @return true if the Animator has more elements
     */
    public boolean hasNext()
    {
        return this.hasNext;
    }

    /**
     * Starts the Animator, hasNext will now return true
     */
    public void start()
    {
        this.hasNext = true;
    }

    /**
     * Stops the Animator, hasNext will now return false
     */
    public void stop()
    {
        this.hasNext = false;
    }

    /**
     * No-op intended to be overrided by deriving classes.  Deriving classes are expected to
     * implement the desired action of a set operation in this method.
     *
     * @param interpolant A value between 0 and 1.
     */
    protected void setImpl(double interpolant)
    {

    }

    public void setStopOnInvalidState(boolean stop)
    {
       this.stopOnInvalidState = stop;
    }

    public boolean isStopOnInvalidState()
    {
       return this.stopOnInvalidState;
    }

    protected void flagLastStateInvalid()
    {
       this.lastStateValid = false;
    }

    protected boolean isLastStateValid()
    {
       return this.lastStateValid;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy