Search in sources :

Example 31 with CompoundUndoableEdit

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;
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Iterator(java.util.Iterator) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 32 with CompoundUndoableEdit

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;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskParent(edu.cmu.cs.hcii.cogtool.model.TaskParent) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 33 with CompoundUndoableEdit

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;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 34 with CompoundUndoableEdit

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;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

Example 35 with CompoundUndoableEdit

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;
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)42 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)19 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)13 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)13 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)12 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)7 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)6 Design (edu.cmu.cs.hcii.cogtool.model.Design)6 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)6 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)6 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)6 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)5 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)5 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)4 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)4