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;
}
};
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
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;
}
};
}
Aggregations