//
// AnimationControlJ2D.java
//

/*
VisAD system for interactive analysis and visualization of numerical
data.  Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/

package visad.java2d;

import visad.*;
import visad.browser.Convert;
import visad.util.Delay;

import java.rmi.*;
import java.util.StringTokenizer;

/**
   AnimationControlJ2D is the VisAD class for controlling Animation
   display scalars under Java2D.

WLH - manipulate a list of VisADSwitch nodes in scene graph.

*/ public class AnimationControlJ2D extends AVControlJ2D implements Runnable, AnimationControl { private int current = 0; private boolean direction; // true = forward private long step; // time in milliseconds for the current step private long[] stepValues = {500}; // times in milliseconds between animation steps private transient AnimationSetControlJ2D animationSet; private ToggleControl animate; private RealType real; private boolean no_tick = false; private boolean computeSet = true; private transient VisADCanvasJ2D canvas; /** AnimationControlJ2D is Serializable, mark as transient */ private transient Thread animationThread; public AnimationControlJ2D(DisplayImplJ2D d, RealType r) { super(d); real = r; current = 0; direction = true; step = 500; stepValues = new long[] {step}; if (d != null) { canvas = ((DisplayRendererJ2D) d.getDisplayRenderer()).getCanvas(); animationSet = new AnimationSetControlJ2D(d, this); d.addControl(animationSet); animate = new ToggleControl(d, this); d.addControl(animate); try { animate.setOn(false); } catch (VisADException v) { } catch (RemoteException v) { } new Delay(); // initialize the stepValues array try { Set set = animationSet.getSet(); if (set != null) stepValues = new long[set.getLength()]; } catch (VisADException v) {;} for (int i = 0; i 0"); } step = st; for (int i=0; i < stepValues.length; i++) { stepValues[i] = step; } // WLH 5 May 2000 // changeControl(true); changeControl(false); } /** * set the dwell time for individual steps. * * @param steps an array of dwell rates for each step in the animation * If the length of the array is less than the number of * frames in the animation, the subsequent step values will * be set to the value of the last step. * * @throws VisADException Couldn't create necessary VisAD object. The * dwell times remain unchanged. * @throws RemoteException Java RMI exception */ public void setSteps(int[] steps) throws VisADException, RemoteException { // verify that the values are valid for (int i = 0; i < stepValues.length; i++) { stepValues[i] = (i < steps.length) ? steps[i] : steps[steps.length-1]; if (stepValues[i] <= 0) throw new DisplayException("AnimationControlJ2D.setSteps: " + "step " + i + " must be > 0"); } // WLH 5 May 2000 // changeControl(true); changeControl(false); } /** * advance one step (forward or backward) * * @throws VisADException Couldn't create necessary VisAD object. No * step is taken. * @throws RemoteException Java RMI exception */ public void takeStep() throws VisADException, RemoteException { if (direction) current++; else current--; if (animationSet != null) { current = animationSet.clipCurrent(current); canvas.renderTrigger(); } changeControl(false); } public void init() throws VisADException { if (animationSet != null && animationSet.getSet() != null) { double value = animationSet.getValue(current); Set set = animationSet.getSet(); animation_string(real, set, value, current); selectSwitches(value, set); } } public Set getSet() { if (animationSet != null) { return animationSet.getSet(); } else { return null; } } /** *

Sets the set of times in this animation control. If the argument * set is equal to the current set, then nothing is done.

* * @param s The set of times. * @throws VisADException if a VisAD failure occurs. * @throws RemoteException if a Java RMI failure occurs. */ public void setSet(Set s) throws VisADException, RemoteException { if (s == null && animationSet != null && animationSet.getSet() == null) return; // check for null/null if (animationSet == null || s == null || (s != null && !s.equals(animationSet.getSet()))) { setSet(s, false); // have to do this i animationSet == null if (s == null) { stepValues = new long[] {step}; current = 0; } else if (s.getLength() != stepValues.length) { stepValues = new long[s.getLength()]; for (int i = 0; i < stepValues.length; i++) { stepValues[i] = step; } } } } /** *

Sets the set of times in this animation control. If the argument * set is equal to the current set, then nothing is done.

* * @param s The set of times. * @param noChange changeControl(!noChange) to not trigger * re-transform, used by ScalarMap.setRange * @throws VisADException if a VisAD failure occurs. * @throws RemoteException if a Java RMI failure occurs. */ public void setSet(Set s, boolean noChange) throws VisADException, RemoteException { if (animationSet != null) { if (s == null) { stepValues = new long[] {step}; current = 0; } else if (s.getLength() != stepValues.length) { stepValues = new long[s.getLength()]; for (int i = 0; i < stepValues.length; i++) { stepValues[i] = step; } } animationSet.setSet(s, noChange); } } /** return true if automatic stepping is on */ public boolean getOn() { if (animate != null) { return animate.getOn(); } else { return false; } } /** * Set automatic stepping on or off. * * @param o true = turn stepping on, false = turn stepping off * * @throws VisADException Couldn't create necessary VisAD object. No * change in automatic stepping occurs. * @throws RemoteException Java RMI exception */ public void setOn(boolean o) throws VisADException, RemoteException { if (animate != null) { animate.setOn(o); } } /** * toggle automatic stepping between off and on * * @throws VisADException Couldn't create necessary VisAD object. No * change in automatic stepping occurs. * @throws RemoteException Java RMI exception */ public void toggle() throws VisADException, RemoteException { if (animate != null) { animate.setOn(!animate.getOn()); } } public void subSetTicks() { if (animationSet != null) { animationSet.setTicks(); } if (animate != null) { animate.setTicks(); } } public boolean subCheckTicks(DataRenderer r, DataDisplayLink link) { boolean flag = false; if (animationSet != null) { flag |= animationSet.checkTicks(r, link); } if (animate != null) { flag |= animate.checkTicks(r, link); } return flag; } public boolean subPeekTicks(DataRenderer r, DataDisplayLink link) { boolean flag = false; if (animationSet != null) { flag |= animationSet.peekTicks(r, link); } if (animate != null) { flag |= animate.peekTicks(r, link); } return flag; } public void subResetTicks() { if (animationSet != null) { animationSet.resetTicks(); } if (animate != null) { animate.resetTicks(); } } /** get a String that can be used to reconstruct this AnimationControl later */ public String getSaveString() { int numSteps; long[] steps; if (stepValues == null) { numSteps = 1; steps = new long[1]; steps[0] = 500; } else { numSteps = stepValues.length; steps = stepValues; } StringBuffer sb = new StringBuffer(35 + 12 * numSteps); sb.append(animate != null && animate.getOn()); sb.append(' '); sb.append(direction); sb.append(' '); sb.append(current); sb.append(' '); sb.append(numSteps); for (int i=0; i

Ads help maintain this website.