Search in sources :

Example 76 with IListenerAction

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

the class DictionaryEditorController method createAddNewEntryAction.

protected IListenerAction createAddNewEntryAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            final DictionaryEditorUI.ComputeSimilarityParms parms = (DictionaryEditorUI.ComputeSimilarityParms) actionParms;
            final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
            final double oldSimilarity = pendingEntry.getSimilarity();
            final double similarity;
            if (checkNewEntry(parms.goalString, parms.searchString, parms.algorithm)) {
                interaction.reportProblem(ERROR_TITLE, ENTRY_EXISTS);
                return false;
            }
            if (parms.algorithm == ITermSimilarity.MANUAL) {
                similarity = oldSimilarity;
            } else {
                similarity = computeSimilarity(parms.goalString, parms.searchString, parms.algorithm);
            }
            final String oldGoal = pendingEntry.getDictEntry().goalWord;
            final String oldSearch = pendingEntry.getDictEntry().searchWord;
            pendingEntry.clear();
            final DictValue value = new DictValue(similarity);
            dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
            undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.CreateNewEntry) {

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

                @Override
                public void redo() {
                    super.redo();
                    pendingEntry.clear();
                    dictionary.setSimilarity(parms.goalString, parms.searchString, parms.algorithm, value, parms.rowIndex);
                }

                @Override
                public void undo() {
                    super.undo();
                    dictionary.removeEntry(parms.rowIndex);
                    pendingEntry.setGoal(oldGoal);
                    pendingEntry.setSearch(oldSearch);
                    pendingEntry.setAlgorithm(oldAlg);
                    pendingEntry.setSimilarity(oldSimilarity);
                }
            });
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ITermSimilarity(edu.cmu.cs.hcii.cogtool.model.ITermSimilarity) DictValue(edu.cmu.cs.hcii.cogtool.model.ISimilarityDictionary.DictValue) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

Example 77 with IListenerAction

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

the class DictionaryEditorController method createSetSimilarityAction.

protected IListenerAction createSetSimilarityAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            DictionaryEditorUI.SetSimilarityParms parms = (DictionaryEditorUI.SetSimilarityParms) actionParms;
            DictEntry entry = dictionary.getEntry(parms.rowIndex);
            if (entry == null) {
                final double oldSimil = pendingEntry.getSimilarity();
                final double newSimil = parms.similarity;
                if (PrecisionUtilities.withinEpsilon(oldSimil, newSimil, 0.001)) {
                    interaction.setStatusMessage(SIMIL_UNCHANGED);
                    return true;
                }
                final ITermSimilarity oldAlg = pendingEntry.getDictEntry().algorithm;
                pendingEntry.setSimilarity(newSimil);
                pendingEntry.setAlgorithm(ITermSimilarity.MANUAL);
                undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.SetSimilarity) {

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

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

                    @Override
                    public void undo() {
                        super.undo();
                        pendingEntry.setSimilarity(oldSimil);
                        pendingEntry.setAlgorithm(oldAlg);
                    }
                });
                return true;
            }
            if (PrecisionUtilities.withinEpsilon(dictionary.getValue(entry).similarity, parms.similarity, 0.001)) {
                interaction.setStatusMessage(SIMIL_UNCHANGED);
                return true;
            }
            setSimilarity(parms.rowIndex, parms.similarity, ITermSimilarity.MANUAL, undoMgr);
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) 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 78 with IListenerAction

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

the class FrameEditorController method createCopyWidgetAction.

/**
     * Set up the COPY widget code.
     * Uses the persistence store to generate XML for the copy action.
     * @return
     */
private IListenerAction createCopyWidgetAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState seln = (FrameEditorSelectionState) prms;
            // If selection is non-zero, copy frame elements
            int elementCount = seln.getElementSelectionCount();
            if (elementCount > 0) {
                copyElements(seln, DesignEditorCmd.SAVE_TO_CLIPBOARD);
                if (elementCount == 1) {
                    interaction.setStatusMessage(WIDGET_COPIED);
                } else {
                    interaction.setStatusMessage(WIDGETS_COPIED);
                }
                return true;
            }
            // tell user to select something.
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 79 with IListenerAction

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

the class ProjectController method createSetAlgorithmAction.

protected IListenerAction createSetAlgorithmAction(final IPredictionAlgo alg, final CogToolLID lid, final String actionString) {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            ProjectSelectionState selState = (ProjectSelectionState) actionParms;
            Design design = selState.getSelectedDesign();
            AUndertaking[] tasks = selState.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
            DemoStateManager demoMgr = DemoStateManager.getStateManager(project, design);
            // iterate through tasks and get set of TaskApplications
            final TaskApplication[] taskApps = new TaskApplication[tasks.length];
            final IPredictionAlgo[] oldAlgos = new IPredictionAlgo[tasks.length];
            for (int i = 0; i < tasks.length; i++) {
                // Make sure that the task application exists, and create it
                // if it does not.  No need to ensure a script.
                TaskApplication ta = ensureTaskApplication(tasks[i], design, null, demoMgr);
                taskApps[i] = ta;
                oldAlgos[i] = ta.getActiveAlgorithm();
                // now set the new algorithm
                ta.setActiveAlgorithm(alg);
            }
            undoMgr.addEdit(new AUndoableEdit(lid) {

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

                @Override
                public void redo() {
                    super.redo();
                    for (TaskApplication taskApp : taskApps) {
                        taskApp.setActiveAlgorithm(alg);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    for (int i = 0; i < taskApps.length; i++) {
                        taskApps[i].setActiveAlgorithm(oldAlgos[i]);
                    }
                }
            });
            return true;
        }
    };
}
Also used : IPredictionAlgo(edu.cmu.cs.hcii.cogtool.model.IPredictionAlgo) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) 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)

Example 80 with IListenerAction

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

the class ProjectController method createScriptViewerAction.

protected IListenerAction createScriptViewerAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            if (prms != null) {
                ProjectSelectionState seln = (ProjectSelectionState) prms;
                // Must have selected tasks and design
                Design design = seln.getSelectedDesign();
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.PRUNE_SELECTION);
                if ((design == null) || (tasks == null) || (tasks.length == 0)) {
                    return false;
                }
                boolean viewSuccessful = false;
                // Viewing a script only applies to task groups
                for (AUndertaking task : tasks) {
                    if (task.isTaskGroup()) {
                        TaskGroup group = (TaskGroup) task;
                        List<AUndertaking> childTasks = group.getUndertakings();
                        if (childTasks.size() > 0) {
                            AUndertaking firstTask = childTasks.get(0);
                            TaskApplication ta = project.getTaskApplication(firstTask, design);
                            if (ta != null) {
                                ITaskDesign td = project.getTaskDesign(task, design);
                                ScriptViewerController.openController(td, project);
                                viewSuccessful = true;
                            }
                        }
                    }
                }
                if (!viewSuccessful) {
                    interaction.setStatusMessage(L10N.get("PC.NoScriptsToView", "No scripts to view."));
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Aggregations

IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)94 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)30 Design (edu.cmu.cs.hcii.cogtool.model.Design)29 ITaskDesign (edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign)29 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)23 ProjectSelectionState (edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState)23 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)21 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)19 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)17 IOException (java.io.IOException)14 RcvrIOException (edu.cmu.cs.hcii.cogtool.util.RcvrIOException)13 TaskSelectionState (edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState)12 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)10 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DesignSelectionState (edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)10 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)9 FrameSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState)9 TaskGroup (edu.cmu.cs.hcii.cogtool.model.TaskGroup)8 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)8 File (java.io.File)8