use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method captureImageAction.
// createChangeAuxTextPropertyAction
/**
* Create a ListenerAction which will handle capturing a background image.
* @return
*/
private IListenerAction captureImageAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CAPTURE_BKG_IMG, FrameEditorLID.CaptureImageProperty);
// Get the selection.
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
Iterator<IWidget> selected = selection.getSelectedWidgetsIterator();
// Iterate over every selected widget
while (selected.hasNext()) {
final IWidget w = selected.next();
DoubleRectangle bounds = w.getEltBounds();
// Get the image from the background, and crop to shape
final byte[] bg = GraphicsUtil.cropImage(model.getBackgroundImage(), bounds.x, bounds.y, bounds.width, bounds.height);
// Get the old image, could be null.
final byte[] old = w.getImage();
final String previousImagePath = (String) w.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
w.setImage(bg);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, WidgetAttributes.NO_IMAGE);
editSequence.addEdit(new AUndoableEdit(FrameEditorLID.CaptureImageProperty) {
@Override
public String getPresentationName() {
return CAPTURE_BKG_IMG;
}
@Override
public void redo() {
super.redo();
w.setImage(bg);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, WidgetAttributes.NO_IMAGE);
}
@Override
public void undo() {
super.undo();
w.setImage(old);
w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, previousImagePath);
}
});
}
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method resizeElements.
/**
* Resize the selected set of elements based on where the mouse was released
* and the fixed point in the resize.
*
* While it supports multiple selection, its behavior is correct if called
* with more then one selected widget.
*/
private boolean resizeElements(double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, double ratioX, double ratioY, FrameEditorSelectionState selection) {
Iterator<FrameElement> selected = selection.getSelectedElementsIterator();
CompoundUndoableEdit editSequence = new CompoundUndoableEdit((selection.getWidgetSelectionCount() != 1) ? RESIZE_WIDGETS : RESIZE_WIDGET, FrameEditorLID.ResizeWidgets);
Set<SimpleWidgetGroup> resizedGroups = new HashSet<SimpleWidgetGroup>();
// Loop through selected widgets
while (selected.hasNext()) {
FrameElement elt = selected.next();
resizeElement(elt, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, false, editSequence);
}
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method moveElements.
private boolean moveElements(FrameEditorSelectionState selection, double moveByX, double moveByY, boolean moveAsGroup) {
String editLabel;
if (selection.getWidgetSelectionCount() == 1) {
editLabel = MOVE_WIDGET;
} else {
editLabel = MOVE_WIDGETS;
}
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, FrameEditorLID.MoveWidgets);
FrameElement[] selected = selection.getSelectedIFrameElements();
// Avoid moving a group more than once
Set<SimpleWidgetGroup> movedGroups = new HashSet<SimpleWidgetGroup>();
Set<IWidget> movedWidgets = new HashSet<IWidget>();
// Move all selected widgets by the specified amount
for (FrameElement eltToMove : selected) {
if (!isMemberOfSelectedGroup(eltToMove, selection)) {
moveElement(FrameEditorLID.MoveWidgets, editLabel, eltToMove, moveByX, moveByY, moveAsGroup, movedGroups, movedWidgets, editSequence);
}
}
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method createUngroupElementsAction.
private IListenerAction createUngroupElementsAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorSelectionState.class;
}
public boolean performAction(Object prms) {
FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
while (selectedElts.hasNext()) {
FrameElement elt = selectedElts.next();
if (elt instanceof FrameElementGroup) {
selectedGroups.add((FrameElementGroup) elt);
} else {
selectedGroups.addAll(elt.getRootElement().getEltGroups());
}
}
if (selectedGroups.size() > 0) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, editSequence);
removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
}
IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {
@Override
public String getPresentationName() {
return UNGROUP_ELEMENTS;
}
@Override
public void redo() {
super.redo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
ungroup(group, null);
}
}
@Override
public void undo() {
super.undo();
Iterator<FrameElementGroup> groups = selectedGroups.iterator();
while (groups.hasNext()) {
FrameElementGroup group = groups.next();
regroup(group);
}
}
};
editSequence.addEdit(edit);
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
return true;
}
interaction.protestNoSelection();
return false;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method setWidgetImages.
/**
* Sets the images on a bunch of widgets
* @param selected an iterator containing the IWidgets
* @param imageData the new image, or null of none
*/
private void setWidgetImages(Iterator<IWidget> selected, final byte[] imageData, final String imageURL) {
String undoRedoLabel = (imageData == null) ? REMOVE_WIDGET_IMG : SET_WIDGET_IMG;
CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveImageProperty : FrameEditorLID.SetImageProperty;
// Create the compound undo
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
// Change the images on all the selected widgets
while (selected.hasNext()) {
setWidgetImage(selected.next(), imageData, imageURL, lid, undoRedoLabel, editSequence);
}
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
}
Aggregations