--- /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.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