use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class DesignEditorController method setBackgroundImageOnFrames.
/**
* Sets the background image for the array of frames
*
* @param frames an array of IFrames
* @param imageData the new image, or null if none
* @param imageURL the file path of the new image, or
* <code>WidgetAttributes.NO_IMAGE</code>
*/
protected void setBackgroundImageOnFrames(final Frame[] frames, final byte[] imageData, final String imageURL, CogToolLID editLID) {
try {
// compute the size of the new image.
final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
// save previous data for undo/redo
final Map<Frame, ImageData> previousImageData = getBackgroundImageData(frames);
// do operation on all frames
for (Frame frame : frames) {
frame.setBackgroundImage(imageData, imageSize);
frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
}
// Add the undo edit
IUndoableEdit edit = new AUndoableEdit(editLID) {
@Override
public String getPresentationName() {
return (imageData == null) ? removeBackgroundImage : setBackgroundImage;
}
@Override
public void redo() {
super.redo();
// selected frames
try {
for (Frame frame : frames) {
frame.setBackgroundImage(imageData, imageSize);
frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
}
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Redo set background image failed", ex);
}
}
@Override
public void undo() {
super.undo();
try {
// iterate through frames
Iterator<Entry<Frame, ImageData>> imageEntryIterator = previousImageData.entrySet().iterator();
while (imageEntryIterator.hasNext()) {
Entry<Frame, ImageData> imageEntry = imageEntryIterator.next();
Frame f = imageEntry.getKey();
ImageData id = imageEntry.getValue();
f.setBackgroundImage(id.data, id.bounds);
f.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, id.imageURL);
}
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Undo set background image failed", ex);
}
}
};
undoMgr.addEdit(edit);
for (Frame frame : frames) {
UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
frameMgr.addEdit(edit);
}
} catch (GraphicsUtil.ImageException e) {
// setBackgroundImage and GraphicsUtil.getImageBounds may
// throw ImageException, translating any other exception.
interaction.protestInvalidImageFile();
}
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method renderWidget.
// createSetRenderSkinAction
public static void renderWidget(final IWidget w, final boolean rendered, final boolean oldRendered, CompoundUndoableEdit edit) {
w.setRendered(rendered);
edit.addEdit(new AUndoableEdit(FrameEditorLID.SetRenderSkin) {
@Override
public String getPresentationName() {
return CHG_WIDGET_RENDERED;
}
@Override
public void redo() {
super.redo();
w.setRendered(rendered);
}
@Override
public void undo() {
super.undo();
w.setRendered(oldRendered);
}
});
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method setWidgetImage.
private void setWidgetImage(final IWidget w, final byte[] imageData, final String imageURL, CogToolLID lid, final String undoRedoLabel, IUndoableEditSequence editSequence) {
// Get existing image
final byte[] previousImageData = w.getImage();
final String previousImagePath = (String) w.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
// Perform operation
w.setImage(imageData);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
// Add the undo edit
editSequence.addEdit(new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return undoRedoLabel;
}
@Override
public void redo() {
super.redo();
w.setImage(imageData);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
}
@Override
public void undo() {
super.undo();
w.setImage(previousImageData);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, previousImagePath);
}
});
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class DictEntryGenerator method insertEntries.
public void insertEntries(final DictionaryEditorController dec, final boolean computeAll, final ITermSimilarity oldAlg, final ITermSimilarity alg, Project project, IUndoableEditSequence editSequence) {
final ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
if ((newDictEntries.size() > 0) || (updatedDictEntries.size() > 0)) {
dict.insertEntries(newDictEntries, computeAll);
dict.insertEntries(updatedDictEntries, computeAll);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.GenerateDictionary) {
@Override
public String getPresentationName() {
return GENERATE_DICTIONARY;
}
@Override
public void redo() {
super.redo();
dict.insertEntries(newDictEntries, computeAll);
dict.insertEntries(updatedDictEntries, computeAll);
dec.setCurrentAlgorithm(alg);
}
@Override
public void undo() {
super.undo();
dict.removeEntries(newDictEntries);
dict.insertEntries(oldDictEntries, computeAll);
dec.setCurrentAlgorithm(oldAlg);
}
};
editSequence.addEdit(edit);
UndoManager.getUndoManager(dict, project).addEdit(edit);
} else {
dec.interaction.setStatusMessage("No entries to compute.");
}
}
use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.
the class DictionaryEditorController method setSimilarity.
protected void setSimilarity(final int rowIndex, final double similarity, final ITermSimilarity algorithm, IUndoableEditSequence editSeq) {
DictEntry entry = dictionary.getEntry(rowIndex);
final String goal = entry.goalWord;
final String search = entry.searchWord;
DictValue oldV = dictionary.getValue(entry);
final DictValue oldValue = new DictValue(oldV.similarity, oldV.editedDate);
final DictValue newValue = new DictValue(similarity);
if (PrecisionUtilities.withinEpsilon(oldValue.similarity, similarity, 0.001)) {
interaction.setStatusMessage(SIMIL_UNCHANGED);
return;
}
final ITermSimilarity oldAlg = entry.algorithm;
dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
editSeq.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {
@Override
public String getPresentationName() {
return SET_SIMILARITY;
}
@Override
public void redo() {
super.redo();
dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
}
@Override
public void undo() {
super.undo();
dictionary.setSimilarity(goal, search, oldAlg, oldValue, rowIndex);
}
});
}
Aggregations