]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.proconf.g3d/src/org/simantics/proconf/g3d/animation/AnimationSystem.java
Moved 3D plug-ins to /3d/branches/dev.
[simantics/3d.git] / org.simantics.proconf.g3d / src / org / simantics / proconf / g3d / animation / AnimationSystem.java
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
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.proconf.g3d.animation;\r
12 \r
13 import java.util.ArrayList;\r
14 import java.util.List;\r
15 \r
16 import org.simantics.db.Graph;\r
17 import org.simantics.proconf.g3d.base.ScenegraphAdapter;\r
18 \r
19 \r
20 public class AnimationSystem {\r
21         private ScenegraphAdapter adapter;\r
22         private List<AnimationController> animationControllers = new ArrayList<AnimationController>();\r
23     \r
24         private List<AnimationSystemListener> listeners = new ArrayList<AnimationSystemListener>();\r
25         \r
26         private boolean pause = false;\r
27         \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
32         }\r
33         \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
38         }\r
39         \r
40         public void addListener(AnimationSystemListener l) {\r
41                 listeners.add(l);\r
42         }\r
43         \r
44         public void removeListener(AnimationSystemListener l) {\r
45                 listeners.remove(l);\r
46         }\r
47         \r
48         public boolean isRunning() {\r
49                 return animationControllers.size() > 0;\r
50         }\r
51         \r
52         public void pause() {\r
53                 if (pause)\r
54                         return;\r
55                 pause = true;\r
56                 for (AnimationSystemListener l : listeners)\r
57                 l.animationPaused(this);\r
58         }\r
59         \r
60         public void play() {\r
61                 if(!pause)\r
62                         return;\r
63                 pause = false;\r
64                 for (AnimationSystemListener l : listeners)\r
65                 l.animationPlay(this);\r
66         }\r
67         \r
68         public void stop() {\r
69                 for (AnimationController c : animationControllers)\r
70                 c.dispose();\r
71         animationControllers.clear();\r
72         for (AnimationSystemListener l : listeners)\r
73                 l.animationStopped(this);\r
74         }\r
75         \r
76         public boolean isPause() {\r
77                 return pause;\r
78         }\r
79         \r
80         public void run(Graph graph, double frameTime) {\r
81                 if (pause)\r
82                         return;\r
83                  if (animationControllers.size() > 0) {\r
84                 for (AnimationController c : animationControllers)\r
85                                 c.updateAnimation(graph, frameTime);\r
86                         adapter.setChanged(true);\r
87              }\r
88         }\r
89         \r
90         public List<AnimationController> getAnimationControllers() {\r
91                 return animationControllers;\r
92         }\r
93         \r
94 }\r