use of edu.cmu.cs.hcii.cogtool.util.UndoManager in project cogtool by cogtool.
the class FrameEditorController method createSetSkinAction.
private AListenerAction createSetSkinAction(final SkinType newSkin, final CogToolLID lid) {
return new AListenerAction() {
public boolean performAction(Object prms) {
final SkinType oldSkin = design.getSkin();
design.setSkin(newSkin);
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return CHANGE_SKIN;
}
@Override
public void redo() {
super.redo();
design.setSkin(newSkin);
}
@Override
public void undo() {
super.undo();
design.setSkin(oldSkin);
}
};
UndoManager designUndoMgr = UndoManager.getUndoManager(design, project);
designUndoMgr.addEdit(edit);
undoMgr.addEdit(edit);
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.UndoManager in project cogtool by cogtool.
the class ProjectController method openProjectOnCompute.
/**
* editSeq will be null if no regeneration occurred; otherwise,
* the edit sequence will contain the undoable edit for the regeneration.
*/
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
boolean notModified;
try {
notModified = UndoManager.isAtSavePoint(project);
} catch (IllegalStateException ex) {
System.err.println("Ignoring that isAtSavePoint failed.");
notModified = false;
}
ProjectController c = ProjectController.openController(project, false, notModified);
final CognitiveModelGenerator modelGen = script.getModelGenerator();
final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {
protected APredictionResult redoResult = newResult;
protected APredictionResult undoResult = oldResult;
@Override
public String getPresentationName() {
return COMPUTE_SCRIPT;
}
@Override
public void redo() {
super.redo();
redoResult = PredictionResultProxy.getLatestResult(redoResult);
taskApp.setResult(modelGen, computeAlg, redoResult);
}
@Override
public void undo() {
super.undo();
undoResult = PredictionResultProxy.getLatestResult(undoResult);
taskApp.setResult(modelGen, computeAlg, undoResult);
}
};
if (editSeq != null) {
editSeq.addEdit(edit);
editSeq.end();
edit = editSeq;
}
// Add to script's undo mgr first to set owner properly
scriptUndoMgr.addEdit(edit);
c.undoMgr.addEdit(edit);
c.takeFocus();
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.UndoManager in project cogtool by cogtool.
the class DesignEditorController method setWidgetColorForFrames.
/**
* Sets the widget color on all widgets contained within the given frames
*
* @param frames an array of IFrames
* @param color integer containing new widget color
*/
protected void setWidgetColorForFrames(final Frame[] frames, final int color) {
// save previous data for undo/redo
final Map<Frame, Integer> previousWidgetColorData = getWidgetColorData(frames);
// do operation on all frames
for (Frame frame : frames) {
frame.setWidgetColor(color);
}
// Add the undo edit
IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.SetWidgetColor) {
@Override
public String getPresentationName() {
return setWidgetColor;
}
@Override
public void redo() {
super.redo();
// selected frames
for (Frame frame : frames) {
frame.setWidgetColor(color);
}
}
@Override
public void undo() {
super.undo();
// Iterate through frames, resetting widget colors
// to old values
Iterator<Entry<Frame, Integer>> colorEntryIterator = previousWidgetColorData.entrySet().iterator();
while (colorEntryIterator.hasNext()) {
Entry<Frame, Integer> colorEntry = colorEntryIterator.next();
Frame f = colorEntry.getKey();
int oldColor = colorEntry.getValue().intValue();
f.setWidgetColor(oldColor);
}
}
};
undoMgr.addEdit(edit);
for (Frame frame : frames) {
UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
frameMgr.addEdit(edit);
}
}
Aggregations