Search in sources :

Example 21 with Demonstration

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

the class SEDemoController method setMouseHandAction.

// resetComputations
protected void setMouseHandAction(final boolean mouseHand) {
    final Demonstration demo = script.getDemonstration();
    final boolean oldMouseHand = demo.getMouseHand();
    final DefaultModelGeneratorState initialState = demo.getInitialState();
    final HandLocation mouseHandLoc = initialState.getHandLocation(oldMouseHand);
    final DemoStateManager.IConformanceUndoRedo conformanceUndoRedo = demoStateMgr.restoreConformance(demo);
    demo.setMouseHand(mouseHand);
    initialState.setHandLocation(mouseHand, mouseHandLoc);
    initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
    IUndoableEdit edit = new AUndoableEdit(SEDemoLID.SetMouseHand) {

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

        @Override
        public void redo() {
            super.redo();
            conformanceUndoRedo.redo();
            initialState.setHandLocation(mouseHand, mouseHandLoc);
            initialState.setHandLocation(!mouseHand, HandLocation.OnKeyboard);
            // Do this last as it will alert
            demo.setMouseHand(mouseHand);
            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            conformanceUndoRedo.undo();
            initialState.setHandLocation(oldMouseHand, mouseHandLoc);
            initialState.setHandLocation(!oldMouseHand, HandLocation.OnKeyboard);
            // Do this last as it will alert
            demo.setMouseHand(oldMouseHand);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    undoMgr.addEdit(edit);
}
Also used : HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 22 with Demonstration

use of edu.cmu.cs.hcii.cogtool.model.Demonstration 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)

Example 23 with Demonstration

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

the class SEDemoController method insertStep.

protected boolean insertStep(final AScriptStep newDemoStep, AScriptStep beforeStep, CogToolLID lid, final String presentationName) {
    Set<AScriptStep> newDemoSteps = Collections.singleton(newDemoStep);
    Set<AScriptStep> emptyDemoSteps = // None are being replaced!
    new HashSet<AScriptStep>();
    Demonstration demo = script.getDemonstration();
    final int atIndex = demo.insertStep(newDemoStep, beforeStep);
    final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, atIndex, beforeStep, interaction);
    if (CogToolPref.HCIPA.getBoolean()) {
        TaskApplication ta = script.getDemonstration().getTaskApplication();
        AUndertaking t = ta.getTask();
        Design d = ta.getDesign();
        // Starting with the script after t, update all of the scripts in
        // the task group to reflect the new state
        TaskGroup grp = t.getTaskGroup();
        if (grp != null) {
            List<AUndertaking> tasks = grp.getUndertakings();
            int startIndex = tasks.indexOf(t);
            Script prevScript = script;
            for (int i = startIndex + 1; i < tasks.size(); i++) {
                t = tasks.get(i);
                ta = project.getTaskApplication(t, d);
                if (ta == null) {
                    continue;
                }
                Script s = ta.getScript(script.getModelGenerator());
                Demonstration curDemo = s.getDemonstration();
                HCIPACmd.copyState(prevScript, curDemo);
                scriptsUndoRedos.addAll(DemoScriptCmd.regenerateScripts(curDemo, 0, curDemo.getStepAt(0), interaction));
                prevScript = s;
            }
        }
    }
    IUndoableEdit edit = new DemoStateManager.ADemoUndoableEdit(lid, demo, newDemoSteps, emptyDemoSteps, demoStateMgr) {

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

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

        @Override
        public void undo() {
            super.undo();
            demo.removeStep(atIndex);
            DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
        }
    };
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(presentationName, 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 : Script(edu.cmu.cs.hcii.cogtool.model.Script) 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) Design(edu.cmu.cs.hcii.cogtool.model.Design) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with Demonstration

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

the class SEFrameChooserController method createOpenDemonstrationWindowAction.

/**
     * Create the window for demonstrating the entire script.
     */
protected IListenerAction createOpenDemonstrationWindowAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // Ensure there is a selected start frame.
            final Demonstration demo = taskApp.getDemonstration();
            final Script script = taskApp.getScript(modelGen);
            if (demo.getStartFrame() != null) {
                demo.setStartFrameChosen(true);
                final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
                // Close the current window.
                closeWindow(false);
                // Open the new demo view window
                try {
                    SEDemoController.openController(taskApp, modelGen, project);
                } catch (GraphicsUtil.ImageException ex) {
                    interaction.protestInvalidImageFile();
                }
                IUndoableEdit edit = new AUndoableEdit(SEFrameChooserLID.OpenScriptEditor) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        if (demo.getStartFrame() != null) {
                            demo.setStartFrameChosen(true);
                            DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
                            // Close the frame chooser window.
                            DefaultController frameController = ControllerRegistry.ONLY.findOpenController(taskApp);
                            if (frameController != null) {
                                frameController.closeWindow(false);
                            }
                            // Open the new demo view window
                            try {
                                SEDemoController.openController(taskApp, modelGen, project);
                            } catch (GraphicsUtil.ImageException ex) {
                                interaction.protestInvalidImageFile();
                            }
                        }
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        DefaultController seDemoController = ControllerRegistry.ONLY.findOpenController(script);
                        if (seDemoController != null) {
                            seDemoController.closeWindow(false);
                        }
                        demo.setStartFrameChosen(false);
                        DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
                        SEFrameChooserController.openController(taskApp, modelGen, project);
                    }
                };
                UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
                scriptUndoMgr.addEdit(edit);
                undoMgr.addEdit(edit);
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) ComputationUndoRedo(edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Aggregations

Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)24 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)11 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)9 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)9 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)9 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)8 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)7 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)6 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)4 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)3 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)3 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)3 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)3 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)3 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)3