Search in sources :

Example 11 with CompoundUndoableEdit

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

the class FrameEditorController method createChangeAuxTextPropertyAction.

// changeAuxTextProperty
private IListenerAction createChangeAuxTextPropertyAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.ActionStringParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.ActionStringParameters p = (FrameEditorUI.ActionStringParameters) prms;
            // While the UI should suppress
            // multiple selection for setting
            // titles, the selection supports it
            Iterator<FrameElement> selected = p.selection.getSelectedElementsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_AUX_TEXT, FrameEditorLID.ChangeAuxTextProperty);
            String newTitle = p.newString;
            // Loop through each item and set the title
            while (selected.hasNext()) {
                FrameElement elt = selected.next();
                changeAuxTextProperty(FrameEditorLID.ChangeAuxTextProperty, CHG_AUX_TEXT, elt, newTitle, 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) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)

Example 12 with CompoundUndoableEdit

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

the class FrameEditorController method renderUnRenderAll.

public static void renderUnRenderAll(Design d, boolean render, CogToolLID lid, UndoManager mgr) {
    CompoundUndoableEdit edits = new CompoundUndoableEdit((render ? RENDER_ALL : UN_RENDER), lid);
    for (Frame f : d.getFrames()) {
        for (IWidget w : f.getWidgets()) {
            renderWidget(w, render, w.isRendered(), edits);
        }
    }
    edits.end();
    if (edits.isSignificant()) {
        mgr.addEdit(edits);
    }
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 13 with CompoundUndoableEdit

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

the class FrameEditorController method createSetRemoteLabelTextAction.

// createUngroupElementsAction
private IListenerAction createSetRemoteLabelTextAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.SetRemoteLabelTextParms.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRemoteLabelTextParms p = (FrameEditorUI.SetRemoteLabelTextParms) prms;
            // Check p.selectedElement; must be an FrameElementGroup
            // or an IWidget of WidgetType Button, PullDownList, Graffiti,
            // or TextBox (whether IS_STANDARD or IS_CUSTOM) or an IWidget
            // of WidgetType Radio, Check, or ListBoxItem if IS_STANDARD
            // (in which case, the label belongs to the parent SimpleWidgetGroup)
            FrameElement owningElt = p.selectedElement.getRemoteLabelOwner();
            if (owningElt == null) {
                interaction.protestUnsupportedLabelOwnerType();
                return false;
            }
            IWidget remoteLabel = (IWidget) owningElt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
            // Already has a label; simply update
            if (remoteLabel != null) {
                changeTitleProperty(FrameEditorLID.SetRemoteLabelText, SET_REMOTE_LABEL, remoteLabel, p.newText, // not a separator!
                false, undoMgr);
            } else if ((p.newText != null) && !p.newText.equals("")) {
                CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SET_REMOTE_LABEL, FrameEditorLID.SetRemoteLabelText);
                final double INITIAL_WIDTH = 100.0;
                final double INITIAL_HEIGHT = 16.0;
                final double MIN_MARGIN = 5.0;
                final double EXTRA_MARGIN = 10.0;
                DoubleRectangle eltBds = owningElt.getEltBounds();
                double maxY = eltBds.y - INITIAL_HEIGHT - MIN_MARGIN;
                DoubleRectangle labelBds;
                if (0.0 <= maxY) {
                    labelBds = new DoubleRectangle(eltBds.x, Math.max(0.0, maxY - EXTRA_MARGIN), INITIAL_WIDTH, INITIAL_HEIGHT);
                } else {
                    double maxX = Math.max(0.0, eltBds.x - INITIAL_WIDTH - MIN_MARGIN);
                    labelBds = new DoubleRectangle(Math.max(0.0, maxX - EXTRA_MARGIN), eltBds.y, INITIAL_WIDTH, INITIAL_HEIGHT);
                }
                remoteLabel = new Widget(labelBds, WidgetType.Text);
                DefaultCmd.setAttribute(owningElt, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, remoteLabel, interaction, editSequence);
                remoteLabel.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
                remoteLabel.setAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR, owningElt);
                remoteLabel.setName(generateUniqueWidgetName());
                remoteLabel.setTitle(p.newText);
                // Add the new widget to the undo system and to the model
                editSequence.addEdit(addWidget(remoteLabel));
                // Commit the edit
                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) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 14 with CompoundUndoableEdit

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

the class DictionaryEditorController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return DictionaryEditorUI.SetAlgorithmParms.class;
        }

        public boolean performAction(Object actionParms) {
            DictionaryEditorUI.SetAlgorithmParms parms = (DictionaryEditorUI.SetAlgorithmParms) actionParms;
            double similarity;
            if (parms.rowIndices.length == 0) {
                interaction.reportProblem(ERROR_TITLE, NO_SELECTION);
                return false;
            }
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(SET_ALGORITHM, DictionaryEditorLID.SetAlgorithm);
            for (int rowIndice : parms.rowIndices) {
                DictEntry entry = dictionary.getEntry(rowIndice);
                if (entry == null) {
                    final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
                    final double oldSimilarity = pendingEntry.getSimilarity();
                    final ITermSimilarity newAlg = parms.algorithm;
                    boolean equal = (newAlg == null) ? oldAlg == null : newAlg.equals(oldAlg);
                    if (equal) {
                        interaction.setStatusMessage(ALG_UNCHANGED);
                        continue;
                    }
                    pendingEntry.setAlgorithm(newAlg);
                    pendingEntry.setSimilarity(ITermSimilarity.UNKNOWN);
                    editSeq.addEdit(new AUndoableEdit(DictionaryEditorLID.SetAlgorithm) {

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

                        @Override
                        public void redo() {
                            super.redo();
                            pendingEntry.setAlgorithm(newAlg);
                            pendingEntry.setSimilarity(ITermSimilarity.UNKNOWN);
                        }

                        @Override
                        public void undo() {
                            super.undo();
                            pendingEntry.setAlgorithm(oldAlg);
                            pendingEntry.setSimilarity(oldSimilarity);
                        }
                    });
                    interaction.setStatusMessage(ALG_CHANGED);
                    continue;
                }
                if (parms.algorithm.equals(entry.algorithm)) {
                    interaction.setStatusMessage(ALG_UNCHANGED);
                    continue;
                }
                if (checkNewEntry(entry.goalWord, entry.searchWord, parms.algorithm)) {
                    interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
                    continue;
                }
                if (parms.algorithm != ITermSimilarity.MANUAL) {
                    similarity = computeSimilarity(entry.goalWord, entry.searchWord, parms.algorithm);
                } else {
                    similarity = dictionary.getValue(entry).similarity;
                }
                setSimilarity(rowIndice, similarity, parms.algorithm, editSeq);
            }
            editSeq.end();
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
                interaction.setStatusMessage(ALG_CHANGED);
            }
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) 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)

Example 15 with CompoundUndoableEdit

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

the class DictionaryEditorController method createSetStringAction.

protected IListenerAction createSetStringAction(final int column) {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return DictionaryEditorUI.SetStringParms.class;
        }

        public boolean performAction(Object actionParms) {
            DictionaryEditorUI.SetStringParms p = (DictionaryEditorUI.SetStringParms) actionParms;
            if (p != null) {
                final int rowIndex = p.rowIndex;
                final String newString = p.string;
                IUndoableEdit edit = null;
                DictEntry entry = dictionary.getEntry(rowIndex);
                if (entry == null) {
                    interaction.reportProblem(ERROR_TITLE, NO_ENTRY);
                    return true;
                }
                CogToolLID lid;
                final String goal;
                final String search;
                final String oldGoal;
                final String oldSearch;
                if (column == 0) {
                    goal = newString;
                    oldGoal = entry.goalWord;
                    if (goal.equals(oldGoal)) {
                        interaction.setStatusMessage(STRING_UNCHANGED);
                        return true;
                    }
                    search = entry.searchWord;
                    oldSearch = search;
                    lid = DictionaryEditorLID.SetGoalString;
                } else {
                    goal = entry.goalWord;
                    oldGoal = goal;
                    search = newString;
                    oldSearch = entry.searchWord;
                    if (search.equals(oldSearch)) {
                        interaction.setStatusMessage(STRING_UNCHANGED);
                        return true;
                    }
                    lid = DictionaryEditorLID.SetSearchString;
                }
                if (checkNewEntry(goal, search, entry.algorithm)) {
                    interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
                    return false;
                }
                dictionary.updateEntry(rowIndex, goal, search);
                CompoundUndoableEdit editSeq = new CompoundUndoableEdit(MODIFY_TERM, lid);
                edit = new AUndoableEdit(lid) {

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

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

                    @Override
                    public void undo() {
                        super.undo();
                        dictionary.updateEntry(rowIndex, oldGoal, oldSearch);
                    }
                };
                editSeq.addEdit(edit);
                if (entry.algorithm != ITermSimilarity.MANUAL) {
                    double similarity = computeSimilarity(goal, search, entry.algorithm);
                    setSimilarity(rowIndex, similarity, entry.algorithm, editSeq);
                }
                editSeq.end();
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) 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) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)

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