use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class ProjectController method recomputeScripts.
protected boolean recomputeScripts(ProjectSelectionState seln) {
Design design = seln.getSelectedDesign();
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
ComputeMessages computeMsgs = new ComputeMessages();
String editLabel = ui.hasMultipleScripts(seln) ? RECOMPUTE_SCRIPTS : RECOMPUTE_SCRIPT;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, ProjectLID.RecomputeScript);
editSequence.setManager(undoMgr);
if (design != null) {
DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
if ((tasks != null) && (tasks.length > 0)) {
for (int i = 0; i < tasks.length; i++) {
if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
} else {
Iterator<AUndertaking> allTasks = project.getUndertakings().iterator();
while (allTasks.hasNext()) {
if (!recomputeScripts(allTasks.next(), design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
}
} else if ((tasks != null) && (tasks.length > 0)) {
for (int i = 0; i < tasks.length; i++) {
Iterator<Design> allDesigns = project.getDesigns().iterator();
while (allDesigns.hasNext()) {
design = allDesigns.next();
DemoStateManager demoStateMgr = DemoStateManager.getStateManager(project, design);
if (!recomputeScripts(tasks[i], design, demoStateMgr, computeMsgs, editSequence)) {
return false;
}
}
}
}
if (editSequence.isSignificant()) {
editSequence.end();
undoMgr.addEdit(editSequence);
}
computeMsgs.presentMessages();
return true;
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class ProjectController method createDuplicateTasksAction.
protected IListenerAction createDuplicateTasksAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return TaskSelectionState.class;
}
public boolean performAction(Object prms) {
TaskSelectionState seln = (TaskSelectionState) prms;
AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.ORDER_SELECTION);
// Can only duplicate if one or more tasks are selected
if ((tasks != null) && (tasks.length > 0)) {
String presentationName = (tasks.length > 1) ? DUPLICATE_TASKS : DUPLICATE_TASK;
CompoundUndoableEdit editSeq = new CompoundUndoableEdit(presentationName, ProjectLID.DuplicateTask);
AUndertaking lastDuplicate = null;
for (AUndertaking task : tasks) {
TaskParent parent = project.getTaskParent(task);
List<AUndertaking> parentUndertakings = parent.getUndertakings();
int atIndex = parentUndertakings.indexOf(task) + 1;
lastDuplicate = duplicateTask(task, atIndex, parent, parentUndertakings, ProjectLID.DuplicateTask, presentationName, editSeq);
}
// Done with undo/redo steps; add the compound change
// to the undo manager.
editSeq.end();
undoMgr.addEdit(editSeq);
if (tasks.length == 1) {
ui.initiateTaskRename(lastDuplicate);
}
} else {
interaction.protestNoSelection();
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit in project cogtool by cogtool.
the class FrameEditorController method createChangeTypeAction.
/**
* Create a listener action for changing the type.
* Changing the type can be a dangerous option.
* If you change the type and thus change what kind of
* transition you can use, it may play havoc on scripts, and design view.
* @return
*/
private IListenerAction createChangeTypeAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.TypeChangeParameters.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.TypeChangeParameters p = (FrameEditorUI.TypeChangeParameters) prms;
Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_WIDGET_TYPE, FrameEditorLID.ChangeTypeProperty);
while (selected.hasNext()) {
IWidget widget = selected.next();
// Check if the widget types match
// TODO: deal with the following
// WidgetType.compatibleTransitions(oldWidgetType,
// p.newWidgetType)
// if it returns false, show interaction..
// auto delete transition?
changeWidgetType(FrameEditorLID.ChangeTypeProperty, CHG_WIDGET_TYPE, widget, p.newWidgetType, editSequence);
}
editSequence.end();
// Don't add empty edits!
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 spaceElementsEqually.
/**
* Spaces the selected frame elements equally along a certain axis
* @param vertical true for vertical axis; false for horizontal
*/
private boolean spaceElementsEqually(FrameEditorSelectionState selection, boolean vertical) {
// Order the widgets according to location
// (either from the left or from the top)
Comparator<FrameElement> c = vertical ? elementVerticalComparator : elementHorizontalComparator;
Set<FrameElement> elements = getSelectedElements(selection, c);
if (elements.size() <= 2) {
interaction.protestTooFewElements();
return false;
}
// Calculate the spacing between widgets
double sum = 0;
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
// Go through each element that is selected
// Determine the size, min & max of the region.
// this can then be used to do spacing.
Iterator<FrameElement> eltIter = elements.iterator();
while (eltIter.hasNext()) {
DoubleRectangle bounds = eltIter.next().getEltBounds();
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) / (elements.size() - 1);
String undoRedoLabel = vertical ? SPACE_VERTICALLY : SPACE_HORIZONTALLY;
CogToolLID lid = vertical ? FrameEditorLID.SpaceVertically : FrameEditorLID.SpaceHorizontally;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
// Avoid moving a group more than once
Set<SimpleWidgetGroup> movedGroups = new HashSet<SimpleWidgetGroup>();
Set<IWidget> movedWidgets = new HashSet<IWidget>();
// Adjust the spacings to the correct values and go through
// each element performing the appropriate move.
eltIter = elements.iterator();
while (eltIter.hasNext()) {
FrameElement elt = eltIter.next();
DoubleRectangle bounds = elt.getEltBounds();
// Determine the amount to move each element
double deltaX = vertical ? 0.0 : (min - bounds.x);
double deltaY = vertical ? (min - bounds.y) : 0.0;
// Set the new location, adding the undoable edit
moveElement(lid, undoRedoLabel, elt, deltaX, deltaY, true, movedGroups, movedWidgets, editSequence);
// Advance the pointer to the next location
min += spacing + (vertical ? bounds.height : bounds.width);
}
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 deleteElements.
/**
* Delete currently selected widgets.
*/
protected boolean deleteElements(FrameEditorSelectionState selection) {
String editLabel = (selection.getElementSelectionCount() > 1) ? DELETE_WIDGETS : DELETE_WIDGET;
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, FrameEditorLID.Delete);
FrameElement[] selectedElts = selection.getSelectedIFrameElements();
// Check to see if any items are selected
if (selectedElts.length > 0) {
if (interaction.confirmDeleteElements(selectedElts)) {
Set<IWidget> frameWidgets = model.getWidgets();
Set<FrameElementGroup> frameAssocs = model.getEltGroups();
for (FrameElement selectedElt : selectedElts) {
if (selectedElt instanceof FrameElementGroup) {
// component of another group
if (frameAssocs.contains(selectedElt)) {
deleteFrameEltGroup((FrameElementGroup) selectedElt, null, editSequence);
}
} else if (selectedElt instanceof IWidget) {
// of another widget (e.g., menu item part of a menu)
if (frameWidgets.contains(selectedElt)) {
deleteWidget((IWidget) selectedElt, true, null, editSequence);
}
}
}
editSequence.end();
undoMgr.addEdit(editSequence);
return true;
}
} else {
interaction.protestNoSelection();
}
return false;
}
Aggregations