use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class SEDemoController method performChangeDelay.
// performInsertDelay
protected boolean performChangeDelay(SEDemoSelectionState selection) {
DefaultModelGeneratorState selectedState = selection.getSelectedState();
if ((selectedState == null) || !(selectedState.getScriptStep() instanceof DelayScriptStep)) {
interaction.protestNotDelayStep();
return false;
}
final DelayScriptStep delayStep = (DelayScriptStep) selectedState.getScriptStep();
final double oldDuration = delayStep.getDelayDuration();
final String oldLabel = delayStep.getLabel();
final SEDemoInteraction.TimedActionData newData = getTimedActionData(oldDuration, oldLabel, IS_WAIT);
if (newData == null) {
return false;
}
delayStep.setDelayDuration(newData.duration);
delayStep.setLabel(newData.labelString);
final Collection<ComputationUndoRedo> computeUndoRedos = resetComputations();
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.ChangeWaitProperties) {
@Override
public String getPresentationName() {
return CHG_WAIT_PROPERTIES;
}
@Override
public void redo() {
super.redo();
delayStep.setDelayDuration(newData.duration);
delayStep.setLabel(newData.labelString);
DemoScriptCmd.redoAllChanges(computeUndoRedos);
}
@Override
public void undo() {
super.undo();
delayStep.setDelayDuration(oldDuration);
delayStep.setLabel(oldLabel);
DemoScriptCmd.undoAllChanges(computeUndoRedos);
}
};
undoMgr.addEdit(edit);
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class SEDemoController method setHandLocationAction.
protected void setHandLocationAction(final HandLocation handLoc) {
final Demonstration demo = script.getDemonstration();
final boolean mouseHand = demo.getMouseHand();
final DefaultModelGeneratorState initialState = demo.getInitialState();
final HandLocation oldLoc = initialState.getHandLocation(mouseHand);
final DemoStateManager.IConformanceUndoRedo conformanceUndoRedo = demoStateMgr.restoreConformance(demo);
initialState.setHandLocation(mouseHand, handLoc);
demo.alertInitialStateChange();
final Collection<ComputationUndoRedo> scriptsUndoRedos = DemoScriptCmd.regenerateScripts(demo, 0, demo.getStepAt(0), interaction);
IUndoableEdit edit = new AUndoableEdit(SEDemoLID.SetHandLocation) {
@Override
public String getPresentationName() {
return SET_HAND_LOCATION;
}
@Override
public void redo() {
super.redo();
conformanceUndoRedo.redo();
initialState.setHandLocation(mouseHand, handLoc);
demo.alertInitialStateChange();
DemoScriptCmd.redoAllChanges(scriptsUndoRedos);
}
@Override
public void undo() {
super.undo();
conformanceUndoRedo.undo();
initialState.setHandLocation(mouseHand, oldLoc);
demo.alertInitialStateChange();
DemoScriptCmd.undoAllChanges(scriptsUndoRedos);
}
};
undoMgr.addEdit(edit);
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit 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;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class DesignEditorController method createNewTransitionAction.
// renameFrame
protected IListenerAction createNewTransitionAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return DesignEditorUI.NewTransitionParameters.class;
}
public boolean performAction(Object prms) {
DesignEditorUI.NewTransitionParameters newPrms = (DesignEditorUI.NewTransitionParameters) prms;
if (newPrms != null) {
CompoundUndoableEdit editSequence = null;
if (newPrms.target == null) {
editSequence = new CompoundUndoableEdit(DesignEditorCmd.NEW_TRANSITION, DesignEditorLID.NewTransition);
newPrms.target = createNewFrame(newPrms.x, newPrms.y, editSequence);
}
IUndoableEdit edit = createNewTransition(newPrms.source, newPrms.target);
// null is returned if the operation is canceled.
if (edit != null) {
if (editSequence != null) {
editSequence.addEdit(edit);
editSequence.end();
edit = editSequence;
}
undoMgr.addEdit(edit);
if (editSequence != null) {
ui.initiateFrameRename(newPrms.target);
}
return true;
} else if (editSequence != null) {
editSequence.end();
editSequence.undo();
}
return false;
} else {
throw new RcvrUIException("Cannot create transition without parameters.");
}
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class DesignEditorController method createPasteAction.
protected IListenerAction createPasteAction() {
return new AListenerAction() {
public boolean performAction(Object prms) {
try {
Collection<Object> objects = CogToolClipboard.fetchCogToolObjects();
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(L10N.get("UNDO.Paste", "Paste"), DesignEditorLID.Paste);
Set<DeviceType> devTypes = design.getDeviceTypes();
int numPasted = 0;
Iterator<Object> objIt = objects.iterator();
while (objIt.hasNext()) {
Object o = objIt.next();
if (o instanceof Frame) {
Frame frame = (Frame) o;
makeFrameNameUnique(frame);
// Find an unoccupied starting position
// by cascading.
DoublePoint origin = frame.getFrameOrigin();
DesignUtil.findDistinctOrigin(design, origin, 16.0, 16.0);
// Union devices
Iterator<InputDevice> frameDevices = frame.getInputDevices().iterator();
while (frameDevices.hasNext()) {
InputDevice inputDevice = frameDevices.next();
DeviceType devType = inputDevice.getDeviceType();
if (!devTypes.contains(devType)) {
DesignCmd.addDevice(design, devType);
}
}
Iterator<DeviceType> designDevTypes = devTypes.iterator();
while (designDevTypes.hasNext()) {
DeviceType devType = designDevTypes.next();
if (frame.getInputDevice(devType) == null) {
frame.addInputDevice(devType);
}
}
addFrame(frame, editSequence);
numPasted++;
} else if (o instanceof Transition) {
Transition t = (Transition) o;
DeviceType device = t.getAction().getDefaultDeviceType();
if (!devTypes.contains(device)) {
DesignCmd.addDevice(design, device);
}
IUndoableEdit edit = DesignEditorCmd.addTransition(demoStateMgr, t);
editSequence.addEdit(edit);
numPasted++;
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
interaction.setStatusMessage(numPasted + " " + pasteComplete);
} else {
interaction.setStatusMessage(nothingPasted);
}
} catch (IOException e) {
throw new RcvrClipboardException(e);
} catch (ParserConfigurationException e) {
throw new RcvrClipboardException(e);
} catch (SAXException e) {
throw new RcvrClipboardException(e);
} catch (ClipboardUtil.ClipboardException e) {
throw new RcvrClipboardException(e);
}
return true;
}
};
}
Aggregations