Search in sources :

Example 41 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class HCIPACmd method updateLabels.

public static IUndoableEdit updateLabels(final TaskGroup group, final String newName, final String undoRenameLabel) {
    final String oldName = group.getName();
    final AUndertaking t = group.getUndertakings().get(0);
    group.setName(newName);
    t.setName(IDENTIFY_LABEL + newName);
    return new AUndoableEdit(ProjectLID.HCIPARenameTask) {

        @Override
        public String getPresentationName() {
            return undoRenameLabel;
        }

        @Override
        public void redo() {
            super.redo();
            group.setName(newName);
            t.setName(IDENTIFY_LABEL + newName);
        }

        @Override
        public void undo() {
            super.undo();
            group.setName(oldName);
            t.setName(IDENTIFY_LABEL + oldName);
        }
    };
}
Also used : AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 42 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class ProjectCmd method addNewDesign.

public static void addNewDesign(final Project project, final Design design, final int beforeIndex, final String presentationName, IUndoableEditSequence editSeq) {
    project.addDesign(beforeIndex, design);
    // Create undo/redo step
    editSeq.addEdit(new AUndoableEdit(ProjectLID.NewDesign) {

        // Map from Project.ITaskDesign to TaskApplication
        protected Map<ITaskDesign, TaskApplication> associatedTAs = null;

        protected boolean recoverMgr = false;

        @Override
        public String getPresentationName() {
            return presentationName;
        }

        @Override
        public void redo() {
            super.redo();
            recoverMgr = false;
            project.addDesign(beforeIndex, design);
            if (associatedTAs != null) {
                project.restoreRemovedTaskApplications(associatedTAs);
            }
        }

        @Override
        public void undo() {
            super.undo();
            recoverMgr = true;
            associatedTAs = project.taskApplicationsForRemovedDesign(design);
            project.removeDesign(design);
        }

        @Override
        public void die() {
            super.die();
            if (recoverMgr) {
                UndoManagerRecovery.recoverManagers(project, design, associatedTAs);
                FrameTemplateSupport.clearFrameTemplate(design);
            }
        }
    });
}
Also used : ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication)

Example 43 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method createSetSkinAction.

private AListenerAction createSetSkinAction(final SkinType newSkin, final CogToolLID lid) {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            final SkinType oldSkin = design.getSkin();
            design.setSkin(newSkin);
            IUndoableEdit edit = new AUndoableEdit(lid) {

                @Override
                public String getPresentationName() {
                    return CHANGE_SKIN;
                }

                @Override
                public void redo() {
                    super.redo();
                    design.setSkin(newSkin);
                }

                @Override
                public void undo() {
                    super.undo();
                    design.setSkin(oldSkin);
                }
            };
            UndoManager designUndoMgr = UndoManager.getUndoManager(design, project);
            designUndoMgr.addEdit(edit);
            undoMgr.addEdit(edit);
            return true;
        }
    };
}
Also used : UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) SkinType(edu.cmu.cs.hcii.cogtool.model.SkinType) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 44 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class ProjectController method createDuplicateTaskAppAction.

protected IListenerAction createDuplicateTaskAppAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return ProjectUI.MoveCopyTaskApplicationParms.class;
        }

        public boolean performAction(Object p) {
            if (p != null) {
                ProjectUI.MoveCopyTaskApplicationParms parms = (ProjectUI.MoveCopyTaskApplicationParms) p;
                // Must have selected tasks and design
                if ((parms.design == null) || (parms.fromTask == null) || (parms.toTask == null)) {
                    interaction.protestNoSelection();
                    return false;
                }
                final AUndertaking fromTask = parms.fromTask;
                final AUndertaking toTask = parms.toTask;
                TaskApplication taskApp = project.getTaskApplication(fromTask, parms.design);
                if (taskApp == null) {
                    interaction.protestNoTaskApplication();
                    return false;
                }
                final TaskApplication oldTaskApp = project.removeTaskApplication(parms.toTask, parms.design);
                final TaskApplication newTaskApp = taskApp.duplicate(toTask, parms.design);
                DemoStateManager demoMgr = DemoStateManager.getStateManager(project, parms.design);
                project.setTaskApplication(newTaskApp);
                demoMgr.trackEdits(newTaskApp.getDemonstration());
                IUndoableEdit edit = new AUndoableEdit(ProjectLID.DuplicateTaskApplication) {

                    protected boolean recoverMgrs = false;

                    @Override
                    public String getPresentationName() {
                        return DUPLICATE_TASKAPP;
                    }

                    @Override
                    public void redo() {
                        super.redo();
                        if (oldTaskApp != null) {
                            project.removeTaskApplication(oldTaskApp);
                        }
                        project.setTaskApplication(newTaskApp);
                        recoverMgrs = false;
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        project.removeTaskApplication(newTaskApp);
                        if (oldTaskApp != null) {
                            project.setTaskApplication(oldTaskApp);
                        }
                        recoverMgrs = true;
                    }

                    @Override
                    public void die() {
                        if (recoverMgrs) {
                            recoverManagers(newTaskApp);
                        }
                    }
                };
                undoMgr.addEdit(edit);
            }
            return true;
        }
    };
}
Also used : ProjectUI(edu.cmu.cs.hcii.cogtool.ui.ProjectUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 45 with AUndoableEdit

use of edu.cmu.cs.hcii.cogtool.util.AUndoableEdit in project cogtool by cogtool.

the class FrameEditorController method setBackgroundImage.

/**
     * Sets the background image for the frame
     *
     * @param imageData the new image, or null if none
     */
private void setBackgroundImage(final byte[] imageData, final String imagePath) {
    try {
        // compute the size of the new image.
        final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
        // Get existing image
        final byte[] previousImageData = model.getBackgroundImage();
        final DoubleRectangle previmageSize = model.getBackgroundBounds();
        final String oldPath = (String) model.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
        // Perform operation
        model.setBackgroundImage(imageData, imageSize);
        model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
        CogToolLID lid = (imageData == null) ? FrameEditorLID.RemoveBackgroundImage : FrameEditorLID.SetBackgroundImage;
        // Add the undo edit
        IUndoableEdit edit = new AUndoableEdit(lid) {

            @Override
            public String getPresentationName() {
                return (imageData == null) ? REMOVE_BKG_IMG : SET_BKG_IMG;
            }

            @Override
            public void redo() {
                super.redo();
                try {
                    model.setBackgroundImage(imageData, imageSize);
                    model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imagePath);
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Redo set background image failed", ex);
                }
            }

            @Override
            public void undo() {
                super.undo();
                try {
                    model.setBackgroundImage(previousImageData, previmageSize);
                    model.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, oldPath);
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Undo set background image failed", ex);
                }
            }
        };
        undoMgr.addEdit(edit);
    } catch (GraphicsUtil.ImageException e) {
        interaction.protestInvalidImageFile();
    }
}
Also used : CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) RcvrImageException(edu.cmu.cs.hcii.cogtool.util.RcvrImageException) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)

Aggregations

AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)66 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)34 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)21 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)16 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)14 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)14 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)12 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)10 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)7 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)7 Design (edu.cmu.cs.hcii.cogtool.model.Design)7 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)7 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)7 TaskParent (edu.cmu.cs.hcii.cogtool.model.TaskParent)7 DictEntry (edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry)6 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)6 UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6