]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/proconf/g3d/animation/ui/AnimationControlCreator.java
git-svn-id: https://www.simantics.org/svn/simantics/3d/trunk@22280 ac1ea38d-2e2b...
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / proconf / g3d / animation / ui / AnimationControlCreator.java
diff --git a/org.simantics.g3d/src/org/simantics/proconf/g3d/animation/ui/AnimationControlCreator.java b/org.simantics.g3d/src/org/simantics/proconf/g3d/animation/ui/AnimationControlCreator.java
new file mode 100644 (file)
index 0000000..3571c2a
--- /dev/null
@@ -0,0 +1,139 @@
+/*******************************************************************************\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.ui;\r
+\r
+import org.eclipse.jface.action.Action;\r
+import org.simantics.proconf.g3d.Activator;\r
+import org.simantics.proconf.g3d.animation.AnimationController;\r
+import org.simantics.proconf.g3d.animation.AnimationSystem;\r
+import org.simantics.proconf.g3d.animation.AnimationSystemListener;\r
+\r
+\r
+\r
+public class AnimationControlCreator {\r
+       \r
+       private AnimationSystem animationSystem;\r
+       \r
+       public AnimationControlCreator(AnimationSystem animationSystem) {\r
+               if (animationSystem == null)\r
+                       throw new IllegalArgumentException("AnimationSystem must not be null");\r
+               this.animationSystem = animationSystem;\r
+       }\r
+       \r
+       public Action createStopAction() {\r
+               return new StopAction();\r
+       }\r
+       \r
+       public Action createPauseAction() {\r
+               return new PauseAction();\r
+       }\r
+       \r
+       public Action createPlayAction() {\r
+               return new PlayAction();\r
+       }\r
+       \r
+       private class StopAction extends Action implements AnimationSystemListener {\r
+               \r
+               public StopAction() {\r
+                       super();\r
+                       this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_stop_blue.png"));\r
+                       this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_stop.png"));\r
+                       animationSystem.addListener(this);\r
+                       if (!animationSystem.isRunning())\r
+                               this.setEnabled(false);\r
+               }\r
+               \r
+               public void run() {\r
+                       animationSystem.stop();\r
+               }\r
+               \r
+               public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) {\r
+                       this.setEnabled(true);\r
+               }\r
+               \r
+               public void animationPaused(AnimationSystem animationSystem) {\r
+                       this.setEnabled(true);\r
+               }\r
+               \r
+               public void animationPlay(AnimationSystem animationSystem) {\r
+                       this.setEnabled(true);\r
+               }\r
+               \r
+               public void animationStopped(AnimationSystem animationSystem) {\r
+                       this.setEnabled(false);\r
+               }\r
+       }\r
+       \r
+       private class PlayAction extends Action implements AnimationSystemListener {\r
+               \r
+               public PlayAction() {\r
+                       super();\r
+                       this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_play_blue.png"));\r
+                       this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_play.png"));\r
+                       animationSystem.addListener(this);\r
+                       if (!animationSystem.isPause() || !animationSystem.isRunning())\r
+                               this.setEnabled(false);\r
+               }\r
+               \r
+               public void run() {\r
+                       animationSystem.play();\r
+               }\r
+               \r
+               public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) {\r
+                       this.setEnabled(animationSystem.isPause());\r
+               }\r
+               \r
+               public void animationPaused(AnimationSystem animationSystem) {\r
+                       this.setEnabled(true);\r
+               }\r
+               \r
+               public void animationPlay(AnimationSystem animationSystem) {\r
+                       this.setEnabled(false);\r
+               }\r
+               \r
+               public void animationStopped(AnimationSystem animationSystem) {\r
+                       this.setEnabled(false);\r
+               }\r
+       }\r
+       \r
+       private class PauseAction extends Action implements AnimationSystemListener {\r
+               \r
+               public PauseAction() {\r
+                       super();\r
+                       this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_pause_blue.png"));\r
+                       this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_pause.png"));\r
+                       animationSystem.addListener(this);\r
+                       if (animationSystem.isPause() || !animationSystem.isRunning())\r
+                               this.setEnabled(false);\r
+               }\r
+               \r
+               public void run() {\r
+                       animationSystem.pause();\r
+               }\r
+               \r
+               public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) {\r
+                       this.setEnabled(!animationSystem.isPause());\r
+               }\r
+               \r
+               public void animationPaused(AnimationSystem animationSystem) {\r
+                       this.setEnabled(false);\r
+               }\r
+               \r
+               public void animationPlay(AnimationSystem animationSystem) {\r
+                       this.setEnabled(true);\r
+               }\r
+               \r
+               public void animationStopped(AnimationSystem animationSystem) {\r
+                       this.setEnabled(false);\r
+               }\r
+       }\r
+\r
+}\r