Search in sources :

Example 36 with CompoundUndoableEdit

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

Example 37 with CompoundUndoableEdit

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

Example 38 with CompoundUndoableEdit

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

Example 39 with CompoundUndoableEdit

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;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashSet(java.util.HashSet)

Example 40 with CompoundUndoableEdit

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

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