/******************************************************************************* * Copyright (c) 2007- VTT Technical Research Centre of Finland. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.proconf.g3d.animation; import java.util.ArrayList; import java.util.List; import org.simantics.db.Graph; import org.simantics.proconf.g3d.base.ScenegraphAdapter; public class AnimationSystem { private ScenegraphAdapter adapter; private List animationControllers = new ArrayList(); private List listeners = new ArrayList(); private boolean pause = false; public AnimationSystem(ScenegraphAdapter adapter) { if (adapter == null) throw new IllegalArgumentException("ScenegraphAdapter must not be null"); this.adapter = adapter; } public void add(AnimationController controller) { animationControllers.add(controller); for (AnimationSystemListener l : listeners) l.animationAdded(this, controller); } public void addListener(AnimationSystemListener l) { listeners.add(l); } public void removeListener(AnimationSystemListener l) { listeners.remove(l); } public boolean isRunning() { return animationControllers.size() > 0; } public void pause() { if (pause) return; pause = true; for (AnimationSystemListener l : listeners) l.animationPaused(this); } public void play() { if(!pause) return; pause = false; for (AnimationSystemListener l : listeners) l.animationPlay(this); } public void stop() { for (AnimationController c : animationControllers) c.dispose(); animationControllers.clear(); for (AnimationSystemListener l : listeners) l.animationStopped(this); } public boolean isPause() { return pause; } public void run(Graph graph, double frameTime) { if (pause) return; if (animationControllers.size() > 0) { for (AnimationController c : animationControllers) c.updateAnimation(graph, frameTime); adapter.setChanged(true); } } public List getAnimationControllers() { return animationControllers; } }