use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method changeAuxTextProperty.
// createChangeTitlePropertyAction
private void changeAuxTextProperty(ListenerIdentifier lid, final String presentation, FrameElement elt, final String newText, IUndoableEditSequence editSequence) {
if (elt instanceof IWidget) {
final IWidget widget = (IWidget) elt;
final String oldText = widget.getAuxiliaryText();
if (!oldText.equals(newText)) {
widget.setAuxiliaryText(newText);
DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentation;
}
@Override
public void redo() {
// Redo the set auxiliary text
super.redo();
widget.setAuxiliaryText(newText);
noteEditCheckRegenerate(widget, this);
}
@Override
public void undo() {
// Go back to old auxiliary text
super.undo();
widget.setAuxiliaryText(oldText);
noteEditCheckRegenerate(widget, this);
}
};
noteEditCheckRegenerate(widget, edit);
editSequence.addEdit(edit);
}
} else if (elt instanceof FrameElementGroup) {
final FrameElementGroup eltGroup = (FrameElementGroup) elt;
final String oldText = eltGroup.getAuxiliaryText();
if (!oldText.equals(newText)) {
eltGroup.setAuxiliaryText(newText);
IUndoableEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {
@Override
public String getPresentationName() {
return presentation;
}
@Override
public void redo() {
// Redo the set auxiliary text
super.redo();
eltGroup.setAuxiliaryText(newText);
}
@Override
public void undo() {
// Go back to old auxiliary text
super.undo();
eltGroup.setAuxiliaryText(oldText);
}
};
editSequence.addEdit(edit);
}
}
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class DesignEditorController method spaceFramesEqually.
/**
* Spaces the selected frames equally along a certain axis
* @param vertical true for vertical axis; false for horizontal
*/
protected boolean spaceFramesEqually(Map<Frame, DoubleRectangle> frameMap, final boolean vertical) {
final String undoRedoLabel = vertical ? SPACE_VERTICALLY : SPACE_HORIZONTALLY;
CogToolLID lid = vertical ? DesignEditorLID.SpaceVertically : DesignEditorLID.SpaceHorizontally;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
// Order the widgets according to location
// (either from the left or from the top)
Comparator<Map.Entry<Frame, DoubleRectangle>> c = vertical ? frameVerticalComparator : frameHorizontalComparator;
@SuppressWarnings("unchecked") Map.Entry<Frame, DoubleRectangle>[] entries = new Map.Entry[frameMap.size()];
frameMap.entrySet().toArray(entries);
Arrays.sort(entries, c);
// Calculate the spacing between widgets
double sum = 0;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
// this can then be used to do spacing.
for (Entry<Frame, DoubleRectangle> entrie : entries) {
DoubleRectangle bounds = entrie.getValue();
double size = vertical ? bounds.height : bounds.width;
double position = vertical ? bounds.y : bounds.x;
sum += size;
min = Math.min(min, position);
max = Math.max(max, size + position);
}
// Get the spacing to use between each item.
double spacing = ((max - min) - sum) / (entries.length - 1);
// Adjust the spacings to the correct values
for (Entry<Frame, DoubleRectangle> entrie : entries) {
// go through each frame and set the frame's origin
final Frame f = entrie.getKey();
final DoubleRectangle bounds = entrie.getValue();
// TODO (dfm) this is probably the place to walk over the design pre-flighting
// problems we want to warn the user about, and give the opportunity
// to skip the export if desired
// Determine the old point...
final double p_old = vertical ? bounds.y : bounds.x;
final double p_new = min;
// Set the new location
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
// Advance the pointer to the next location
min += spacing + (vertical ? bounds.height : bounds.width);
IUndoableEdit edit = new AUndoableEdit(lid) {
@Override
public String getPresentationName() {
return undoRedoLabel;
}
@Override
public void redo() {
super.redo();
f.setFrameOrigin(vertical ? bounds.x : p_new, vertical ? p_new : bounds.y);
}
@Override
public void undo() {
super.undo();
f.setFrameOrigin(vertical ? bounds.x : p_old, vertical ? p_old : bounds.y);
}
};
editSequence.addEdit(edit);
}
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.IUndoableEdit in project cogtool by cogtool.
the class DesignEditorController method renameDesign.
/**
* Update the design's name.
* The name must be unique.
*
* @param design
* @param newName
* @return
*/
protected boolean renameDesign(final Design design, String tryName) {
final String oldName = design.getName();
boolean notDone = true;
do {
if (tryName.length() == 0) {
tryName = interaction.protestNameCannotBeEmpty("Design");
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
Design designForName = project.getDesign(tryName);
// then no change is necessary!
if (designForName == design) {
notDone = false;
} else if (designForName != null) {
// A non-null design for the tryName indicates a collision
tryName = interaction.protestNameCollision("Design");
// If canceled, indicate so; otherwise, test again
if (tryName == null) {
return false;
}
} else {
// Not canceled, not empty, and not a collision
notDone = false;
final String newName = tryName;
design.setName(newName);
IUndoableEdit edit = new AUndoableEdit(ProjectLID.RenameDesign) {
@Override
public String getPresentationName() {
return renameDesign;
}
@Override
public void redo() {
super.redo();
design.setName(newName);
makeDesignNameUnique(design);
}
@Override
public void undo() {
super.undo();
design.setName(oldName);
makeDesignNameUnique(design);
}
};
undoMgr.addEdit(edit);
}
}
} while (notDone);
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class HCIPACmd method setFunctionName.
public static void setFunctionName(Project project, final AUndertaking renamedTask, final String newName, CognitiveModelGenerator modelGen, final String undoRenameLabel, IUndoableEditSequence editSeq) {
final TaskGroup parentTask = renamedTask.getTaskGroup();
final String oldName = renamedTask.getName();
final Object oldAttr = parentTask.getAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR);
final String newAttr = parseFunctionName(newName);
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
CompoundUndoableEdit edits = new CompoundUndoableEdit(undoRenameLabel, ProjectLID.HCIPARenameTask);
edits.addEdit(new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
renamedTask.setName(newName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, newAttr);
}
@Override
public void undo() {
super.undo();
renamedTask.setName(oldName);
parentTask.setAttribute(WidgetAttributes.HCIPA_FUNCTION_ATTR, oldAttr);
}
});
// change the task's think step label
Iterator<Design> designs = project.getDesigns().iterator();
while (designs.hasNext()) {
final ThinkScriptStep thinkStep = chgFnName(project, renamedTask, designs.next(), modelGen, DECIDE_TO_USE + newAttr);
// Create undo/redo step and add to undo manager
if (thinkStep != null) {
IUndoableEdit edit = new AUndoableEdit(ProjectLID.HCIPARenameTask) {
@Override
public String getPresentationName() {
return undoRenameLabel;
}
@Override
public void redo() {
super.redo();
thinkStep.setLabel(DECIDE_TO_USE + newAttr);
}
@Override
public void undo() {
super.undo();
thinkStep.setLabel(DECIDE_TO_USE + oldAttr);
}
};
edits.addEdit(edit);
}
}
edits.end();
editSeq.addEdit(edits);
}
use of edu.cmu.cs.hcii.cogtool.util.IUndoableEdit in project cogtool by cogtool.
the class DesignEditorCmd method addFrame.
// pasteElements
public static void addFrame(final Project project, final Design design, final DemoStateManager demoStateMgr, final Frame frame, IUndoableEditSequence editSequence) {
design.addFrame(frame);
Collection<Object> objects = FrameTemplateSupport.getFrameTemplate(design);
if ((objects != null) && (objects.size() > 0)) {
CompoundUndoableEdit tplEdit = new CompoundUndoableEdit(USE_TEMPLATE, null);
pasteElements(design, frame, objects, demoStateMgr, tplEdit);
UndoManager undoMgr = UndoManager.getUndoManager(frame, project);
tplEdit.end();
undoMgr.addEdit(tplEdit);
}
IUndoableEdit edit = new DemoStateManager.InvalidatingEdit(DesignEditorLID.NewFrame, demoStateMgr) {
private boolean recoverMgr = false;
@Override
public String getPresentationName() {
return NEW_FRAME;
}
@Override
public void redo() {
super.redo();
recoverMgr = false;
design.addFrame(frame);
demoStateMgr.noteFrameEdit(frame, this);
}
@Override
public void undo() {
super.undo();
recoverMgr = true;
design.removeFrame(frame);
demoStateMgr.noteFrameEdit(frame, this);
}
@Override
public void die() {
super.die();
if (recoverMgr) {
UndoManagerRecovery.recoverManagers(project, frame);
}
}
};
editSequence.addEdit(edit);
}
Aggregations