1 /*******************************************************************************
\r
2 * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
\r
3 * All rights reserved. This program and the accompanying materials
\r
4 * are made available under the terms of the Eclipse Public License v1.0
\r
5 * which accompanies this distribution, and is available at
\r
6 * http://www.eclipse.org/legal/epl-v10.html
\r
9 * VTT Technical Research Centre of Finland - initial API and implementation
\r
10 *******************************************************************************/
\r
11 package org.simantics.proconf.g3d.animation;
\r
13 import java.util.ArrayList;
\r
14 import java.util.List;
\r
16 import org.simantics.db.Graph;
\r
17 import org.simantics.proconf.g3d.base.ScenegraphAdapter;
\r
20 public class AnimationSystem {
\r
21 private ScenegraphAdapter adapter;
\r
22 private List<AnimationController> animationControllers = new ArrayList<AnimationController>();
\r
24 private List<AnimationSystemListener> listeners = new ArrayList<AnimationSystemListener>();
\r
26 private boolean pause = false;
\r
28 public AnimationSystem(ScenegraphAdapter adapter) {
\r
29 if (adapter == null)
\r
30 throw new IllegalArgumentException("ScenegraphAdapter must not be null");
\r
31 this.adapter = adapter;
\r
34 public void add(AnimationController controller) {
\r
35 animationControllers.add(controller);
\r
36 for (AnimationSystemListener l : listeners)
\r
37 l.animationAdded(this, controller);
\r
40 public void addListener(AnimationSystemListener l) {
\r
44 public void removeListener(AnimationSystemListener l) {
\r
45 listeners.remove(l);
\r
48 public boolean isRunning() {
\r
49 return animationControllers.size() > 0;
\r
52 public void pause() {
\r
56 for (AnimationSystemListener l : listeners)
\r
57 l.animationPaused(this);
\r
60 public void play() {
\r
64 for (AnimationSystemListener l : listeners)
\r
65 l.animationPlay(this);
\r
68 public void stop() {
\r
69 for (AnimationController c : animationControllers)
\r
71 animationControllers.clear();
\r
72 for (AnimationSystemListener l : listeners)
\r
73 l.animationStopped(this);
\r
76 public boolean isPause() {
\r
80 public void run(Graph graph, double frameTime) {
\r
83 if (animationControllers.size() > 0) {
\r
84 for (AnimationController c : animationControllers)
\r
85 c.updateAnimation(graph, frameTime);
\r
86 adapter.setChanged(true);
\r
90 public List<AnimationController> getAnimationControllers() {
\r
91 return animationControllers;
\r