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