/******************************************************************************* * Copyright (c) 2007 VTT Technical Research Centre of Finland and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.proconf.g3d.animation.ui; import org.eclipse.jface.action.Action; import org.simantics.proconf.g3d.Activator; import org.simantics.proconf.g3d.animation.AnimationController; import org.simantics.proconf.g3d.animation.AnimationSystem; import org.simantics.proconf.g3d.animation.AnimationSystemListener; public class AnimationControlCreator { private AnimationSystem animationSystem; public AnimationControlCreator(AnimationSystem animationSystem) { if (animationSystem == null) throw new IllegalArgumentException("AnimationSystem must not be null"); this.animationSystem = animationSystem; } public Action createStopAction() { return new StopAction(); } public Action createPauseAction() { return new PauseAction(); } public Action createPlayAction() { return new PlayAction(); } private class StopAction extends Action implements AnimationSystemListener { public StopAction() { super(); this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_stop_blue.png")); this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_stop.png")); animationSystem.addListener(this); if (!animationSystem.isRunning()) this.setEnabled(false); } public void run() { animationSystem.stop(); } public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) { this.setEnabled(true); } public void animationPaused(AnimationSystem animationSystem) { this.setEnabled(true); } public void animationPlay(AnimationSystem animationSystem) { this.setEnabled(true); } public void animationStopped(AnimationSystem animationSystem) { this.setEnabled(false); } } private class PlayAction extends Action implements AnimationSystemListener { public PlayAction() { super(); this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_play_blue.png")); this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_play.png")); animationSystem.addListener(this); if (!animationSystem.isPause() || !animationSystem.isRunning()) this.setEnabled(false); } public void run() { animationSystem.play(); } public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) { this.setEnabled(animationSystem.isPause()); } public void animationPaused(AnimationSystem animationSystem) { this.setEnabled(true); } public void animationPlay(AnimationSystem animationSystem) { this.setEnabled(false); } public void animationStopped(AnimationSystem animationSystem) { this.setEnabled(false); } } private class PauseAction extends Action implements AnimationSystemListener { public PauseAction() { super(); this.setImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_pause_blue.png")); this.setDisabledImageDescriptor(Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/silk/control_pause.png")); animationSystem.addListener(this); if (animationSystem.isPause() || !animationSystem.isRunning()) this.setEnabled(false); } public void run() { animationSystem.pause(); } public void animationAdded(AnimationSystem animationSystem, AnimationController animationController) { this.setEnabled(!animationSystem.isPause()); } public void animationPaused(AnimationSystem animationSystem) { this.setEnabled(false); } public void animationPlay(AnimationSystem animationSystem) { this.setEnabled(true); } public void animationStopped(AnimationSystem animationSystem) { this.setEnabled(false); } } }