Search in sources :

Example 21 with AUndoableEdit

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

the class DesignEditorController method setBackgroundImageOnFrames.

/**
	 * Sets the background image for the array of frames
	 *
	 * @param frames an array of IFrames
	 * @param imageData the new image, or null if none
	 * @param imageURL the file path of the new image, or
	 * <code>WidgetAttributes.NO_IMAGE</code>
	 */
protected void setBackgroundImageOnFrames(final Frame[] frames, final byte[] imageData, final String imageURL, CogToolLID editLID) {
    try {
        // compute the size of the new image.
        final DoubleRectangle imageSize = GraphicsUtil.getImageBounds(imageData);
        // save previous data for undo/redo
        final Map<Frame, ImageData> previousImageData = getBackgroundImageData(frames);
        // do operation on all frames
        for (Frame frame : frames) {
            frame.setBackgroundImage(imageData, imageSize);
            frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
        }
        // Add the undo edit
        IUndoableEdit edit = new AUndoableEdit(editLID) {

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

            @Override
            public void redo() {
                super.redo();
                // selected frames
                try {
                    for (Frame frame : frames) {
                        frame.setBackgroundImage(imageData, imageSize);
                        frame.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
                    }
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Redo set background image failed", ex);
                }
            }

            @Override
            public void undo() {
                super.undo();
                try {
                    // iterate through frames
                    Iterator<Entry<Frame, ImageData>> imageEntryIterator = previousImageData.entrySet().iterator();
                    while (imageEntryIterator.hasNext()) {
                        Entry<Frame, ImageData> imageEntry = imageEntryIterator.next();
                        Frame f = imageEntry.getKey();
                        ImageData id = imageEntry.getValue();
                        f.setBackgroundImage(id.data, id.bounds);
                        f.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, id.imageURL);
                    }
                } catch (GraphicsUtil.ImageException ex) {
                    throw new RcvrImageException("Undo set background image failed", ex);
                }
            }
        };
        undoMgr.addEdit(edit);
        for (Frame frame : frames) {
            UndoManager frameMgr = UndoManager.getUndoManager(frame, project);
            frameMgr.addEdit(edit);
        }
    } catch (GraphicsUtil.ImageException e) {
        // setBackgroundImage and GraphicsUtil.getImageBounds may
        // throw ImageException, translating any other exception.
        interaction.protestInvalidImageFile();
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Entry(java.util.Map.Entry) UndoManager(edu.cmu.cs.hcii.cogtool.util.UndoManager) 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)

Example 22 with AUndoableEdit

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

the class FrameEditorController method renderWidget.

// createSetRenderSkinAction
public static void renderWidget(final IWidget w, final boolean rendered, final boolean oldRendered, CompoundUndoableEdit edit) {
    w.setRendered(rendered);
    edit.addEdit(new AUndoableEdit(FrameEditorLID.SetRenderSkin) {

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

        @Override
        public void redo() {
            super.redo();
            w.setRendered(rendered);
        }

        @Override
        public void undo() {
            super.undo();
            w.setRendered(oldRendered);
        }
    });
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 23 with AUndoableEdit

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

the class FrameEditorController method setWidgetImage.

private void setWidgetImage(final IWidget w, final byte[] imageData, final String imageURL, CogToolLID lid, final String undoRedoLabel, IUndoableEditSequence editSequence) {
    // Get existing image
    final byte[] previousImageData = w.getImage();
    final String previousImagePath = (String) w.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
    // Perform operation
    w.setImage(imageData);
    w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
    // Add the undo edit
    editSequence.addEdit(new AUndoableEdit(lid) {

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

        @Override
        public void redo() {
            super.redo();
            w.setImage(imageData);
            w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, imageURL);
        }

        @Override
        public void undo() {
            super.undo();
            w.setImage(previousImageData);
            w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, previousImagePath);
        }
    });
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 24 with AUndoableEdit

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

the class DictEntryGenerator method insertEntries.

public void insertEntries(final DictionaryEditorController dec, final boolean computeAll, final ITermSimilarity oldAlg, final ITermSimilarity alg, Project project, IUndoableEditSequence editSequence) {
    final ISimilarityDictionary dict = (ISimilarityDictionary) design.getAttribute(WidgetAttributes.DICTIONARY_ATTR);
    if ((newDictEntries.size() > 0) || (updatedDictEntries.size() > 0)) {
        dict.insertEntries(newDictEntries, computeAll);
        dict.insertEntries(updatedDictEntries, computeAll);
        IUndoableEdit edit = new AUndoableEdit(ProjectLID.GenerateDictionary) {

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

            @Override
            public void redo() {
                super.redo();
                dict.insertEntries(newDictEntries, computeAll);
                dict.insertEntries(updatedDictEntries, computeAll);
                dec.setCurrentAlgorithm(alg);
            }

            @Override
            public void undo() {
                super.undo();
                dict.removeEntries(newDictEntries);
                dict.insertEntries(oldDictEntries, computeAll);
                dec.setCurrentAlgorithm(oldAlg);
            }
        };
        editSequence.addEdit(edit);
        UndoManager.getUndoManager(dict, project).addEdit(edit);
    } else {
        dec.interaction.setStatusMessage("No entries to compute.");
    }
}
Also used : AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) ISimilarityDictionary(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary)

Example 25 with AUndoableEdit

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

the class DictionaryEditorController method setSimilarity.

protected void setSimilarity(final int rowIndex, final double similarity, final ITermSimilarity algorithm, IUndoableEditSequence editSeq) {
    DictEntry entry = dictionary.getEntry(rowIndex);
    final String goal = entry.goalWord;
    final String search = entry.searchWord;
    DictValue oldV = dictionary.getValue(entry);
    final DictValue oldValue = new DictValue(oldV.similarity, oldV.editedDate);
    final DictValue newValue = new DictValue(similarity);
    if (PrecisionUtilities.withinEpsilon(oldValue.similarity, similarity, 0.001)) {
        interaction.setStatusMessage(SIMIL_UNCHANGED);
        return;
    }
    final ITermSimilarity oldAlg = entry.algorithm;
    dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
    editSeq.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {

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

        @Override
        public void redo() {
            super.redo();
            dictionary.setSimilarity(goal, search, algorithm, newValue, rowIndex);
        }

        @Override
        public void undo() {
            super.undo();
            dictionary.setSimilarity(goal, search, oldAlg, oldValue, rowIndex);
        }
    });
}
Also used : ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) DictValue(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue) DictEntry(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictEntry) PendingDictEntry(edu.cmu.cs.hcii.cogtool.ui.PendingDictEntry) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

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