use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class HCIPACmd method updateLabels.
public static IUndoableEdit updateLabels(final TaskGroup group, final String newName, final String undoRenameLabel) {
final String oldName = group.getName();
final AUndertaking t = group.getUndertakings().get(0);
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
return new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
group.setName(newName);
t.setName(IDENTIFY_LABEL + newName);
}
@Override
public void undo() {
super.undo();
group.setName(oldName);
t.setName(IDENTIFY_LABEL + oldName);
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class ProjectCmd method addNewDesign.
public static void addNewDesign(final Project project, final Design design, final int beforeIndex, final String presentationName, IUndoableEditSequence editSeq) {
project.addDesign(beforeIndex, design);
// Create undo/redo step
editSeq.addEdit(new AUndoableEdit(ProjectLID.NewDesign) {
// Map from Project.ITaskDesign to TaskApplication
protected Map<ITaskDesign, TaskApplication> associatedTAs = null;
protected boolean recoverMgr = false;
@Override
public String getPresentationName() {
return presentationName;
}
@Override
public void redo() {
super.redo();
recoverMgr = false;
project.addDesign(beforeIndex, design);
if (associatedTAs != null) {
project.restoreRemovedTaskApplications(associatedTAs);
}
}
@Override
public void undo() {
super.undo();
recoverMgr = true;
associatedTAs = project.taskApplicationsForRemovedDesign(design);
project.removeDesign(design);
}
@Override
public void die() {
super.die();
if (recoverMgr) {
UndoManagerRecovery.recoverManagers(project, design, associatedTAs);
FrameTemplateSupport.clearFrameTemplate(design);
}
}
});
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit 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.AUndoableEdit in project cogtool by cogtool.
the class ProjectController method createDuplicateTaskAppAction.
protected IListenerAction createDuplicateTaskAppAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return ProjectUI.MoveCopyTaskApplicationParms.class;
}
public boolean performAction(Object p) {
if (p != null) {
ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
// Must have selected tasks and design
if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
interaction.protestNoSelection();
return false;
}
final AUndertaking fromTask = parms.fromTask;
final AUndertaking toTask = parms.toTask;
TaskApplication taskApp = project.getTaskApplication(fromTask, parms.design);
if (taskApp == null) {
interaction.protestNoTaskApplication();
return false;
}
final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
final TaskApplication newTaskApp = taskApp.duplicate(toTask, parms.design);
DemoStateManager demoMgr = DemoStateManager.getStateManager(project, parms.design);
project.setTaskApplication(newTaskApp);
demoMgr.trackEdits(newTaskApp.getDemonstration());
IUndoableEdit edit = new AUndoableEdit(ProjectLID.DuplicateTaskApplication) {
protected boolean recoverMgrs = false;
@Override
public String getPresentationName() {
return DUPLICATE_TASKAPP;
}
@Override
public void redo() {
super.redo();
if (oldTaskApp != null) {
project.removeTaskApplication(oldTaskApp);
}
project.setTaskApplication(newTaskApp);
recoverMgrs = false;
}
@Override
public void undo() {
super.undo();
project.removeTaskApplication(newTaskApp);
if (oldTaskApp != null) {
project.setTaskApplication(oldTaskApp);
}
recoverMgrs = true;
}
@Override
public void die() {
if (recoverMgrs) {
recoverManagers(newTaskApp);
}
}
};
undoMgr.addEdit(edit);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method setBackgroundImage.
/**
* Sets the background image for the frame
*
* @param imageData the new image, or null if none
*/
private void setBackgroundImage(final byte[] imageData, final String imagePath) {
try {
// compute the size of the new image.
final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
// Get existing image
final byte[] previousImageData = model.getBackgroundImage();
final DoubleRectangle previmageSize = model.getBackgroundBounds();
final String oldPath = (String) model.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
// Perform operation
model.setBackgroundImage(imageData, imageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveBackgroundImage : FrameEditorLID.SetBackgroundImage;
// Add the undo edit
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return (imageData == null) ? REMOVE_BKG_IMG : SET_BKG_IMG;
}
@Override
public void redo() {
super.redo();
try {
model.setBackgroundImage(imageData, imageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Redo set background image failed", ex);
}
}
@Override
public void undo() {
super.undo();
try {
model.setBackgroundImage(previousImageData, previmageSize);
model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, oldPath);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Undo set background image failed", ex);
}
}
};
undoMgr.addEdit(edit);
} catch (GraphicsUtil.ImageException e) {
interaction.protestInvalidImageFile();
}
}
Aggregations