Search in sources :

Example 21 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.

the class SEDemoController method assignActions.

@Override
public void assignActions() {
    super.assignActions();
    ui.setAction(SEDemoLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(SEDemoLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(SEDemoLID.SetMouseHand, createSetMouseHandAction());
    ui.setAction(SEDemoLID.SetHandLocation, createSetHandLocationAction());
    ui.setAction(SEDemoLID.PerformTransition, createPerformTransitionAction());
    ui.setAction(SEDemoLID.InsertThink, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertThink(selection);
        }
    });
    ui.setAction(SEDemoLID.ChangeThinkProperties, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performChangeThink(selection);
        }
    });
    ui.setAction(SEDemoLID.InsertDelay, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertDelay(selection);
        }
    });
    ui.setAction(SEDemoLID.ChangeWaitProperties, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performChangeDelay(selection);
        }
    });
    ui.setAction(SEDemoLID.Edit, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            DefaultModelGeneratorState selectedState = selection.getSelectedState();
            if (selectedState == null) {
                interaction.protestNoStep();
                return false;
            }
            AScriptStep step = selectedState.getScriptStep();
            if (step instanceof ThinkScriptStep) {
                return performChangeThink(selection);
            }
            if (step instanceof DelayScriptStep) {
                return performChangeDelay(selection);
            }
            if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
                return performEditSelfTransition((ActionScriptStep) step);
            }
            step = step.getOwner();
            if ((step instanceof ActionScriptStep) && step.isDemonstrated() && step.isInsertedByUser()) {
                return performEditSelfTransition((ActionScriptStep) step);
            }
            interaction.protestNotEditable();
            return false;
        }
    });
    ui.setAction(SEDemoLID.InsertDrive, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return performInsertDrive(selection);
        }
    });
    ui.setAction(SEDemoLID.InsertLookAt, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoUI.LookAtTransition.class;
        }

        public boolean performAction(Object prms) {
            SEDemoUI.LookAtTransition lookAt = (SEDemoUI.LookAtTransition) prms;
            return performInsertLookAt(lookAt.selection, lookAt.target);
        }
    });
    ui.setAction(SEDemoLID.InsertSelfTransition, createInsertSelfTransitionAction());
    ui.setAction(SEDemoLID.Delete, new IListenerAction() {

        public Class<?> getParameterClass() {
            return SEDemoSelectionState.class;
        }

        public boolean performAction(Object prms) {
            // If not the "most recent" step state, warn
            // the user that this will remove all
            // items after as well, unless it's a think,
            // look-at or other non-transitioning item.
            SEDemoSelectionState selection = (SEDemoSelectionState) prms;
            return deleteScriptStep(selection);
        }
    });
    ui.setAction(SEDemoLID.RegenerateScript, createRegenerateScriptAction());
    ui.setAction(SEDemoLID.RecomputeScript, createSaveScriptChangesAction());
    ui.setAction(SEDemoLID.ExportScriptToCSV, createExportScriptToCSVAction());
    ui.setAction(DesignEditorLID.EditFrame, createEditFrameAction());
    ui.setAction(SEDemoLID.ShowModelVisualization, createShowModelVisualizationAction());
}
Also used : DelayScriptStep(edu.cmu.cs.hcii.cogtool.model.DelayScriptStep) ActionScriptStep(edu.cmu.cs.hcii.cogtool.model.ActionScriptStep) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) SEDemoUI(edu.cmu.cs.hcii.cogtool.ui.SEDemoUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) SEDemoSelectionState(edu.cmu.cs.hcii.cogtool.ui.SEDemoSelectionState) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 22 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.

the class SEFrameChooserController method createSetStartFrameAction.

protected IListenerAction createSetStartFrameAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return Frame.class;
        }

        public boolean performAction(Object prms) {
            final Frame startFrame = (Frame) prms;
            if (startFrame != null) {
                final Demonstration demo = taskApp.getDemonstration();
                final Frame oldStartFrame = demo.getStartFrame();
                if (startFrame == oldStartFrame) {
                    return true;
                }
                demo.setStartFrame(startFrame);
                undoMgr.addEdit(new AUndoableEdit(SEFrameChooserLID.SetStartFrame) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        demo.setStartFrame(startFrame);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        demo.setStartFrame(oldStartFrame);
                    }
                });
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration)

Example 23 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.

the class SEFrameChooserController method createSetHandLocationAction.

protected IListenerAction createSetHandLocationAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return HandLocation.class;
        }

        public boolean performAction(Object prms) {
            HandLocation handLoc = (HandLocation) prms;
            if (handLoc != null) {
                setHandLocationAction(handLoc);
                return true;
            }
            interaction.protestNoHandLocation();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HandLocation(edu.cmu.cs.hcii.cogtool.model.HandLocation)

Example 24 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.

the class ProjectController method createReorderDesignsAction.

protected IListenerAction createReorderDesignsAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return Design[].class;
        }

        public boolean performAction(Object prms) {
            final Design[] newDesignOrder = (Design[]) prms;
            final Design[] oldDesignOrder = new Design[newDesignOrder.length];
            project.reorderDesigns(newDesignOrder, oldDesignOrder);
            undoMgr.addEdit(new AUndoableEdit(ProjectLID.ReorderDesigns) {

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

                @Override
                public void redo() {
                    super.redo();
                    project.reorderDesigns(newDesignOrder, null);
                }

                @Override
                public void undo() {
                    super.undo();
                    project.reorderDesigns(oldDesignOrder, null);
                }
            });
            return true;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 25 with IListenerAction

use of edu.cmu.cs.hcii.cogtool.util.IListenerAction in project cogtool by cogtool.

the class ProjectController method createImportHumanCSVFileAction.

// Action for ImportHumanCSVFile
protected IListenerAction createImportHumanCSVFileAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectSelectionState.class;
        }

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            // Must have selected tasks and design
            Design design = seln.getSelectedDesign();
            AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            List<String> outputLines = new LinkedList<String>();
            List<String> errorLines = new LinkedList<String>();
            // Get csv file
            File dataFile = interaction.selectCSVFile();
            if (dataFile == null) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                return false;
            }
            // Read lines out of file
            FileReader reader = null;
            try {
                reader = new FileReader(dataFile);
                FileUtil.readLines(reader, outputLines);
            } catch (FileNotFoundException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOFILE_MSG);
                throw new RcvrIOTempException("Error in parsing csv", e);
            } catch (IOException e) {
                interaction.setStatusMessage(IMPORT_FAIL_NOREAD_MSG);
                throw new RcvrParsingException("Error in parsing csv", e);
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                    // ignore
                    }
                    reader = null;
                }
            }
            // parse ResultSteps out of trace lines
            TraceParser<ResultStep> parser = new HumanCSVParser();
            List<ResultStep> steps;
            try {
                steps = parser.parseTrace(outputLines);
            } catch (TraceParser.ParseException e) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_IMPL_MSG);
                throw new RcvrParsingException("Error in parsing implementation", e);
            }
            System.out.println(steps);
            if (steps.size() < 1) {
                interaction.setStatusMessage(IMPORT_FAIL_PARSE_MSG);
                return false;
            }
            double taskTime = -1.0;
            Iterator<ResultStep> stepIt = steps.iterator();
            while (stepIt.hasNext()) {
                ResultStep step = stepIt.next();
                taskTime = Math.max(taskTime, step.startTime + step.duration);
            }
            // Scale time to seconds.
            taskTime /= 1000.0;
            // -------------- Done parsing
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final APredictionResult[] oldResults = new APredictionResult[tasks.length];
            final APredictionResult[] results = new APredictionResult[tasks.length];
            final IPredictionAlgo[] oldActiveAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                taskApps[i] = ensureTaskApplication(tasks[i], design, MODELGEN_ALG, demoMgr);
                // If for some reason there are no result steps,
                // create a TimePredictionResult that
                // reflects COMPUTATION_FAILED.
                // Otherwise, create a normal one.
                Script script = taskApps[i].getScript(MODELGEN_ALG);
                if (taskTime < 0.0) {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps);
                } else {
                    results[i] = new TimePredictionResult(dataFile.getName(), script, HumanDataAlgo.ONLY, outputLines, errorLines, steps, taskTime);
                }
                oldResults[i] = taskApps[i].getResult(MODELGEN_ALG, HumanDataAlgo.ONLY);
                taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                oldActiveAlgos[i] = taskApps[i].getActiveAlgorithm();
                taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
            }
            IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

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

                @Override
                public void redo() {
                    super.redo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, results[i]);
                        taskApps[i].setActiveAlgorithm(HumanDataAlgo.ONLY);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setResult(MODELGEN_ALG, HumanDataAlgo.ONLY, oldResults[i]);
                        taskApps[i].setActiveAlgorithm(oldActiveAlgos[i]);
                    }
                }
            };
            undoMgr.addEdit(edit);
            interaction.setStatusMessage(IMPORT_SUCCESS_MSG);
            return true;
        }
    };
}
Also used : TraceParser(edu.cmu.cs.hcii.cogtool.model.TraceParser) FileNotFoundException(java.io.FileNotFoundException) RcvrParsingException(edu.cmu.cs.hcii.cogtool.util.RcvrParsingException) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ResultStep(edu.cmu.cs.hcii.cogtool.model.ResultStep) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HumanCSVParser(edu.cmu.cs.hcii.cogtool.model.HumanCSVParser) TimePredictionResult(edu.cmu.cs.hcii.cogtool.model.TimePredictionResult) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FileReader(java.io.FileReader) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) LinkedList(java.util.LinkedList) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) RcvrIOTempException(edu.cmu.cs.hcii.cogtool.util.RcvrIOTempException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) File(java.io.File)

Aggregations

IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)94 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)29 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)29 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)23 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)21 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)17 IOException (java.io.IOException)14 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)13 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)10 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)10 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)9 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)8 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 File (java.io.File)8