Search in sources :

Example 6 with UndoManager

use of edu.cmu.cs.hcii.cogtool.util.UndoManager 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 7 with UndoManager

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

the class ProjectController method openProjectOnCompute.

/**
     * editSeq will be null if no regeneration occurred; otherwise,
     * the edit sequence will contain the undoable edit for the regeneration.
     */
public static boolean openProjectOnCompute(Project project, final Script script, final APredictionResult newResult, CompoundUndoableEdit editSeq) {
    boolean notModified;
    try {
        notModified = UndoManager.isAtSavePoint(project);
    } catch (IllegalStateException ex) {
        System.err.println("Ignoring that isAtSavePoint failed.");
        notModified = false;
    }
    ProjectController c = ProjectController.openController(project, false, notModified);
    final CognitiveModelGenerator modelGen = script.getModelGenerator();
    final IPredictionAlgo computeAlg = newResult.getPredictionAlgorithm();
    final TaskApplication taskApp = script.getDemonstration().getTaskApplication();
    final APredictionResult oldResult = taskApp.getResult(modelGen, computeAlg);
    taskApp.setResult(modelGen, computeAlg, PredictionResultProxy.getLatestResult(newResult));
    UndoManager scriptUndoMgr = UndoManager.getUndoManager(script, project);
    IUndoableEdit edit = new AUndoableEdit(ProjectLID.RecomputeScript) {

        protected APredictionResult redoResult = newResult;

        protected APredictionResult undoResult = oldResult;

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

        @Override
        public void redo() {
            super.redo();
            redoResult = PredictionResultProxy.getLatestResult(redoResult);
            taskApp.setResult(modelGen, computeAlg, redoResult);
        }

        @Override
        public void undo() {
            super.undo();
            undoResult = PredictionResultProxy.getLatestResult(undoResult);
            taskApp.setResult(modelGen, computeAlg, undoResult);
        }
    };
    if (editSeq != null) {
        editSeq.addEdit(edit);
        editSeq.end();
        edit = editSeq;
    }
    // Add to script's undo mgr first to set owner properly
    scriptUndoMgr.addEdit(edit);
    c.undoMgr.addEdit(edit);
    c.takeFocus();
    return true;
}
Also used : RcvrIllegalStateException(edu.cmu.cs.hcii.cogtool.util.RcvrIllegalStateException) IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) APredictionResult(edu.cmu.cs.hcii.cogtool.model.APredictionResult) CognitiveModelGenerator(edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

Example 8 with UndoManager

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

the class DesignEditorController method setWidgetColorForFrames.

/**
	 * Sets the widget color on all widgets contained within the given frames
	 *
	 * @param frames an array of IFrames
	 * @param color integer containing new widget color
	 */
protected void setWidgetColorForFrames(final Frame[] frames, final int color) {
    // save previous data for undo/redo
    final Map<Frame, Integer> previousWidgetColorData = getWidgetColorData(frames);
    // do operation on all frames
    for (Frame frame : frames) {
        frame.setWidgetColor(color);
    }
    // Add the undo edit
    IUndoableEdit edit = new AUndoableEdit(DesignEditorLID.SetWidgetColor) {

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

        @Override
        public void redo() {
            super.redo();
            // selected frames
            for (Frame frame : frames) {
                frame.setWidgetColor(color);
            }
        }

        @Override
        public void undo() {
            super.undo();
            // Iterate through frames, resetting widget colors
            // to old values
            Iterator<Entry<Frame, Integer>> colorEntryIterator = previousWidgetColorData.entrySet().iterator();
            while (colorEntryIterator.hasNext()) {
                Entry<Frame, Integer> colorEntry = colorEntryIterator.next();
                Frame f = colorEntry.getKey();
                int oldColor = colorEntry.getValue().intValue();
                f.setWidgetColor(oldColor);
            }
        }
    };
    undoMgr.addEdit(edit);
    for (Frame frame : frames) {
        UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
        frameMgr.addEdit(edit);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Entry(java.util.Map.Entry) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

UndoManager (edu.cmu.cs.hcii.cogtool.util.UndoManager)8 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)6 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)3 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)2 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)2 Script (edu.cmu.cs.hcii.cogtool.model.Script)2 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)2 AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 GraphicsUtil (edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)2 Entry (java.util.Map.Entry)2 APredictionResult (edu.cmu.cs.hcii.cogtool.model.APredictionResult)1 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)1 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)1 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 IPredictionAlgo (edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo)1 SkinType (edu.cmu.cs.hcii.cogtool.model.SkinType)1