Search in sources :

Example 1 with ProjectSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.

the class ProjectController method createOpenDictionaryAction.

protected IListenerAction createOpenDictionaryAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectSelectionState seln = (ProjectSelectionState) prms;
            Design design = seln.getSelectedDesign();
            if (design != null) {
                openDictionaryEditor(design);
            }
            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) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)

Example 2 with ProjectSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.

the class ProjectController method createSetAlgorithmHumanAction.

protected IListenerAction createSetAlgorithmHumanAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState parms = (ProjectSelectionState) actionParms;
            final TaskApplication ta = project.getTaskApplication(parms.getSelectedTask(), parms.getSelectedDesign());
            final IPredictionAlgo oldAlgo = ta.determineActiveAlgorithm(project);
            ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
            undoMgr.addEdit(new AUndoableEdit(ProjectLID.SetAlgorithmHuman) {

                @Override
                public String getPresentationName() {
                    return L10N.get("UNDO.PM.SetHumanAlgorithm", "Set Algorithm to Human Data");
                }

                @Override
                public void redo() {
                    super.redo();
                    ta.setActiveAlgorithm(HumanDataAlgo.ONLY);
                }

                @Override
                public void undo() {
                    super.undo();
                    ta.setActiveAlgorithm(oldAlgo);
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 3 with ProjectSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.

the class ProjectController method createImportDictionaryAction.

protected IListenerAction createImportDictionaryAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState seln = (ProjectSelectionState) actionParms;
            Design design = seln.getSelectedDesign();
            if (design == null) {
                interaction.reportProblem("Import Dictionary", "No design is selected");
                return false;
            }
            ISimilarityDictionary prevDict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
            // Leonghwee says he wants the imported dictionary to replace
            // the old one
            ISimilarityDictionary dict = new SimilarityDictionary();
            design.setAttribute(WidgetAttributes.DICTIONARY_ATTR, dict);
            boolean success = DictionaryEditorCmd.importDictionary(design, dict, prevDict, interaction, undoMgr, null);
            if (success) {
                DictionaryEditorController.openController(dict, design, project);
            }
            return success;
        }
    };
}
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) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary) SimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.SimilarityDictionary) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)

Example 4 with ProjectSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.

the class ProjectController method createExportForSanlab.

protected IListenerAction createExportForSanlab() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState sel = (ProjectSelectionState) actionParms;
            // Must have selected tasks and design
            Design design = sel.getSelectedDesign();
            AUndertaking[] tasks = sel.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
            if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                return false;
            }
            // Fetch traces for the default algorithm (TODO:)
            List<String> traces = getTraces(sel, MODELGEN_ALG, project.getDefaultAlgo());
            // Ask user for location of saved file.
            File exportFile = interaction.selectExportLocation("cogtool-sanlab", CogToolFileTypes.TEXT_FILE_EXT);
            // User canceled
            if (exportFile == null) {
                return false;
            }
            boolean okToProceed = false;
            for (AUndertaking task : tasks) {
                // If no script set exists for this cell, create
                TaskApplication ta = project.getTaskApplication(task, design);
                if (ta != null) {
                    if (ta.getDesign() != design) {
                        throw new RcvrIllegalStateException("Unexpected Design mis-match for SANLab (" + ta.getDesign() + ", " + design + ")");
                    }
                    // If no script exists for this cell, create one
                    Script script = DemoStateManager.ensureScript(ta, MODELGEN_ALG);
                    try {
                        IPredictionAlgo taAlg = ta.determineActiveAlgorithm(project);
                        if (!(taAlg instanceof ACTRPredictionAlgo)) {
                            throw new RcvrIllegalStateException("Can't export model for SANLab from a non ACT-R task.");
                        }
                        if (script.getAssociatedPath() != null) {
                            File f = new File(script.getAssociatedPath());
                            // The following will throw an IOException if
                            // the input file doesn't exist; this is exactly
                            // the same behaviour as if we're trying to do
                            // a recompute, and is better than silently
                            // substituting a generated model file
                            FileUtil.copyTextFileToFile(f, exportFile);
                            return true;
                        }
                        ACTRPredictionAlgo algo = (ACTRPredictionAlgo) taAlg;
                        algo.outputModel(design, task, ta.getDemonstration().getStartFrame(), script, exportFile, null);
                    } catch (UnsupportedOperationException ex) {
                        throw new RcvrUnimplementedFnException(ex);
                    } catch (IOException ex) {
                        throw new RcvrIOException(("IOException exporting SANLab model file for task " + task.getName() + " in design " + design.getName()), ex);
                    }
                }
            }
            // TODO: should we move this file write somewhere else?
            PrintWriter writer = null;
            try {
                // Attempt to open the output file
                FileOutputStream out = new FileOutputStream(exportFile, true);
                writer = new PrintWriter(out);
                writer.println("\n\n;;; TRACE STARTS HERE");
                Matcher mt = TRACE_PAT.matcher("");
                // Put each trace line on its own output line
                Iterator<String> iter = traces.iterator();
                while (iter.hasNext()) {
                    String s = iter.next();
                    if (mt.reset(s).matches()) {
                        writer.println(s);
                    }
                }
                writer.flush();
                okToProceed = true;
            } catch (IOException e) {
                throw new RcvrIOSaveException("Writing the trace logs for " + "SANLab failed. \n\n" + "Please try again.", e);
            } finally {
                if (writer != null) {
                    writer.close();
                }
            }
            return okToProceed;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) Matcher(java.util.regex.Matcher) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) 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) RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) FileOutputStream(java.io.FileOutputStream) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File) ACTRPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo) PrintWriter(java.io.PrintWriter)

Example 5 with ProjectSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState in project cogtool by cogtool.

the class ProjectController method createExportTraces.

// TODO there's way too much cloning of code in the next three methods; refactor them
// Action for ExportTraces
protected IListenerAction createExportTraces() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState sel = (ProjectSelectionState) actionParms;
            // Fetch traces for the default algorithm (TODO:)
            List<String> traces = getTraces(sel, MODELGEN_ALG, project.getDefaultAlgo());
            // Ask user for location of saved file.
            File exportFile = interaction.selectExportLocation("Exported ACT-R trace", CogToolFileTypes.TEXT_FILE_EXT);
            // User canceled
            if (exportFile == null) {
                return false;
            }
            boolean okToProceed = false;
            // TODO: should we move this file write somewhere else?
            PrintWriter writer = null;
            try {
                // Attempt to open the output file
                FileOutputStream out = new FileOutputStream(exportFile);
                writer = new PrintWriter(out);
                // Put each trace line on its own output line
                Iterator<String> iter = traces.iterator();
                while (iter.hasNext()) {
                    String s = iter.next();
                    writer.println(s);
                }
                writer.flush();
                okToProceed = true;
            } catch (IOException e) {
                throw new RcvrIOSaveException("Writing the trace logs" + "failed. \n\n" + "Please try again.", e);
            } finally {
                if (writer != null) {
                    writer.close();
                }
            }
            return okToProceed;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) File(java.io.File) RcvrIOSaveException(edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException) PrintWriter(java.io.PrintWriter)

Aggregations

ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)21 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)20 Design (edu.cmu.cs.hcii.cogtool.model.Design)19 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)19 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)15 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)12 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)7 IOException (java.io.IOException)7 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)6 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)6 Script (edu.cmu.cs.hcii.cogtool.model.Script)6 File (java.io.File)6 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)4 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)4 RcvrUnimplementedFnException (edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException)4 ACTRPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.ACTRPredictionAlgo)3 ISimilarityDictionary (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)3 RcvrIllegalStateException (edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException)3 RcvrIOSaveException (edu.cmu.cs.hcii.cogtool.util.RcvrIOSaveException)2 FileOutputStream (java.io.FileOutputStream)2