Search in sources :

Example 11 with DefaultModelGeneratorState

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

the class ScriptViewerUI method addSelectionChangeListeners.

/**
     * Add the selection Change event listeners.
     */
protected void addSelectionChangeListeners() {
    SWTselectionChangeHandler = new SelectionListener() {

        public void widgetSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            for (TableItem selectedItem : selectedItems) {
                // TODO: Currently supports only single selection.
                Object data = selectedItem.getData();
                if (data instanceof Frame) {
                    selection.setSelectedState(null);
                } else {
                    selection.setSelectedState(selectedItem);
                }
            }
            setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
        // Let selection change handle changing the frame
        }

        public void widgetDefaultSelected(SelectionEvent evt) {
            SWTList swtList = view.getScriptEditorList();
            TableItem[] selectedItems = swtList.getSelectionObject();
            // TODO: Currently supports only single selection.
            for (TableItem selectedItem : selectedItems) {
                Object data = selectedItem.getData();
                if (data instanceof DefaultModelGeneratorState) {
                    Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
                    DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
                    // In case we need this; not a context selection
                    // in truth, but we can re-use the structure.
                    contextSelection.setSelectedState(stepState);
                    performAction(ProjectLID.EditScript, s);
                }
            }
        }
    };
    view.addSWTListSelectionHandler(SWTselectionChangeHandler);
    AlertHandler selectionChangeHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
            if (event != null) {
                if (event.selected) {
                    DefaultModelGeneratorState stepState = event.changedState;
                    Frame resultFrame = null;
                    Script script = getSelectedScript(stepState);
                    AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
                    if (stepState != null) {
                        resultFrame = stepState.getScriptStep().getCurrentFrame();
                    } else if (script != null) {
                        resultFrame = script.getDemonstration().getResultFrame();
                    }
                    DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
                    if (overrideState == null) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> siblingTasks = group.getUndertakings();
                        int currentTaskIndex = siblingTasks.indexOf(t);
                        CognitiveModelGenerator modelGen = script.getModelGenerator();
                        while ((overrideState == null) && (0 <= --currentTaskIndex)) {
                            AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
                            TaskApplication ta = project.getTaskApplication(prevSibling, design);
                            if (ta != null) {
                                script = ta.getScript(modelGen);
                                if (script != null) {
                                    overrideState = script.getLastState();
                                }
                            }
                        }
                    }
                    uiModel.setCurrentOverride(script, overrideState);
                    try {
                        setCurrentFrame(resultFrame);
                    } catch (GraphicsUtil.ImageException ex) {
                        throw new RcvrImageException("Changing current demonstration frame", ex);
                    }
                }
            }
        }
    };
    selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) SWTListGroupScript(edu.cmu.cs.hcii.cogtool.view.SWTListGroupScript) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) TableItem(org.eclipse.swt.widgets.TableItem) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) EventObject(java.util.EventObject) SWTList(edu.cmu.cs.hcii.cogtool.view.SWTList) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EventObject(java.util.EventObject) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with DefaultModelGeneratorState

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

the class ScriptViewerUI method showSelectionContextMenu.

/**
     * Mouse event occurred on the table, use the selected item to
     * display an appropriate menu.
     *
     */
public void showSelectionContextMenu(int x, int y) {
    contextSelection.deselectAll();
    Table historyTable = view.getHistoryTable();
    org.eclipse.swt.graphics.Point atPoint = historyTable.toControl(x, y);
    TableItem ti = historyTable.getItem(atPoint);
    if ((ti != null) && (ti.getData() instanceof DefaultModelGeneratorState)) {
        contextSelection.setSelectedState((DefaultModelGeneratorState) ti.getData());
    } else {
        // this is the result Step, so no selection
        historyTable.select(historyTable.getItemCount() - 1);
    }
    showContextMenu(contextSelection, true);
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 13 with DefaultModelGeneratorState

use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState 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 14 with DefaultModelGeneratorState

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

the class SEDemoController method performChangeThink.

// performInsertThink
protected boolean performChangeThink(SEDemoSelectionState selection) {
    DefaultModelGeneratorState selectedState = selection.getSelectedState();
    if ((selectedState == null) || !(selectedState.getScriptStep() instanceof ThinkScriptStep)) {
        interaction.protestNotThinkStep();
        return false;
    }
    final ThinkScriptStep thinkStep = (ThinkScriptStep) selectedState.getScriptStep();
    final double oldDuration = thinkStep.getThinkDuration();
    final String oldLabel = thinkStep.getLabel();
    final SEDemoInteraction.TimedActionData data = getTimedActionData(oldDuration, oldLabel, IS_THINK);
    if (data == null) {
        return false;
    }
    thinkStep.setThinkDuration(data.duration);
    thinkStep.setLabel(data.labelString);
    final Collection<ComputationUndoRedo> computeUndoRedos = resetComputations();
    IUndoableEdit edit = new AUndoableEdit(SEDemoLID.ChangeThinkProperties) {

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

        @Override
        public void redo() {
            super.redo();
            thinkStep.setThinkDuration(data.duration);
            thinkStep.setLabel(data.labelString);
            DemoScriptCmd.redoAllChanges(computeUndoRedos);
        }

        @Override
        public void undo() {
            super.undo();
            thinkStep.setThinkDuration(oldDuration);
            thinkStep.setLabel(oldLabel);
            DemoScriptCmd.undoAllChanges(computeUndoRedos);
        }
    };
    undoMgr.addEdit(edit);
    return true;
}
Also used : 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) SEDemoInteraction(edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)

Example 15 with DefaultModelGeneratorState

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

the class HCIPACmd method initHCIPATaskDesign.

// For each design
protected static void initHCIPATaskDesign(Project project, String taskName, AUndertaking[] subtasks, Design design, CognitiveModelGenerator modelGen) {
    Frame f = getStartFrame(design);
    DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
    TaskApplication ta = DemoStateManager.ensureTaskApplication(project, subtasks[0], design, modelGen, demoMgr);
    Script script = ta.getScript(modelGen);
    Demonstration demo = script.getDemonstration();
    demo.setStartFrame(f);
    demo.setStartFrameChosen(true);
    IPredictionAlgo computeAlg = ta.determineActiveAlgorithm(project);
    ThinkScriptStep thinkStep = new ThinkScriptStep(f, RECOGNIZE_NEED + taskName);
    demo.appendStep(thinkStep);
    List<String> warnings = new ArrayList<String>();
    List<DefaultModelGeneratorState> states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
    script.replaceStepStates(0, states);
    APredictionResult result = ComputePredictionCmd.computePrediction(computeAlg, script);
    ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
    ta = DemoStateManager.ensureTaskApplication(project, subtasks[1], design, modelGen, demoMgr);
    script = ta.getScript(modelGen);
    demo = ta.getDemonstration();
    demo.setStartFrame(f);
    demo.setStartFrameChosen(true);
    thinkStep = new ThinkScriptStep(f, "Select Function Step");
    demo.appendStep(thinkStep);
    states = modelGen.generateScriptSteps(thinkStep, demo.getInitialState(), warnings);
    script.replaceStepStates(0, states);
    result = ComputePredictionCmd.computePrediction(computeAlg, script);
    ta.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(result));
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ArrayList(java.util.ArrayList) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Aggregations

DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)21 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 EventObject (java.util.EventObject)4 Table (org.eclipse.swt.widgets.Table)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2