Search in sources :

Example 1 with TransitionScriptStep

use of edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep in project cogtool by cogtool.

the class SEDemoController method performTransition.

/**
     * Take the transition, and perform the action
     *
     * @param transition
     */
protected boolean performTransition(SEDemoSelectionState selection, Transition transition, CogToolLID lid) {
    AScriptStep stepToReplace = getDemoStep(selection);
    if (stepToReplace != null) {
        Frame currentFrame = stepToReplace.getCurrentFrame();
        if (transition.getDestination() == currentFrame) {
            return insertStep(new TransitionScriptStep(transition), stepToReplace, lid, PERFORM_TRANSITION);
        }
        if (!interaction.confirmDestructiveInsert()) {
            return false;
        }
    }
    AScriptStep newDemoStep = new TransitionScriptStep(transition);
    TransitionSource source = transition.getSource();
    if (source.getFrame() == transition.getDestination() && (source instanceof IWidget)) {
        toggleIfGermane((IWidget) source, newDemoStep, transition.getAction());
    }
    Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
    Set<AScriptStep> oldDemoSteps = new LinkedHashSet<AScriptStep>();
    Demonstration demo = script.getDemonstration();
    final int atIndex = demo.replaceSteps(stepToReplace, newDemoSteps, oldDemoSteps);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, stepToReplace, interaction);
    IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, oldDemoSteps, demoStateMgr) {

        @Override
        public String getPresentationName() {
            return PERFORM_TRANSITION;
        }

        @Override
        public void redo() {
            super.redo();
            demo.replaceSteps(atIndex, redoDemoSteps);
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            demo.replaceSteps(atIndex, undoDemoSteps);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(PERFORM_TRANSITION, lid);
    editSequence.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateScripts(project, demo, demoStateMgr, interaction, editSequence);
    }
    editSequence.end();
    undoMgr.addEdit(editSequence);
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TransitionScriptStep(edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)1 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 TransitionScriptStep (edu.cmu.cs.hcii.cogtool.model.TransitionScriptStep)1 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)1 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)1 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)1 LinkedHashSet (java.util.LinkedHashSet)1