List of usage examples for org.apache.commons.scxml.model SCXML getTargets
public final Map<String, TransitionTarget> getTargets()
From source file:org.dishevelled.piccolo.sprite.statemachine.AbstractStateMachineSprite.java
/** * Initialize the specified state machine. Animations are loaded for all * the state ids and the current animation is set to the initial target, if any. * * <p>// www . ja v a 2 s . c o m * <b>Note:</b> this method should be called from the constructor * of a subclass after its state machine has been instantiated. * </p> * * @param stateMachine state machine to initialize, must not be null */ protected final void initializeStateMachine(final SCXML stateMachine) { if (stateMachine == null) { throw new IllegalArgumentException("stateMachine must not be null"); } // load animations for state ids for (Iterator<?> entries = stateMachine.getTargets().entrySet().iterator(); entries.hasNext();) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) entries.next(); String id = (String) entry.getKey(); Object target = entry.getValue(); if (target instanceof State) { Animation animation = createAnimation(id); if (animation != null) { animations.put(id, animation); } } } // set the current animation to the initial target, if any String initialTargetId = (stateMachine.getInitialTarget() == null) ? null : stateMachine.getInitialTarget().getId(); if (animations.containsKey(initialTargetId)) { currentAnimation = animations.get(initialTargetId); } // create a state machine support class that delegates to this stateMachineSupport = new StateMachineSupport(this, stateMachine); // update current animation on entry to a new state stateMachineSupport.getExecutor().addListener(stateMachine, new AbstractSCXMLListener() { @Override public void onEntry(final TransitionTarget state) { Animation animation = animations.get(state.getId()); if (animation != null) { currentAnimation = animation; } } }); }