Search in sources :

Example 71 with IListenerAction

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

the class ProjectController method assignActions.

/**
     * Registers the set of <code>IListenerAction</code> instances
     * that implement the semantic actions that are possible.
     * <p>
     * For this class, this consists of the actions for a project editor.
     *
     * @author mlh
     */
@Override
public void assignActions() {
    super.assignActions();
    ui.setAction(ProjectLID.Undo, new UndoController.UndoAction(undoMgr, interaction));
    ui.setAction(ProjectLID.Redo, new UndoController.RedoAction(undoMgr, interaction));
    ui.setAction(ProjectLID.DeselectAll, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            SelectionState selection = (SelectionState) prms;
            selection.deselectAll();
            return true;
        }
    });
    ui.setAction(ProjectLID.CopyResultsToClipboard, createCopyResultsAction());
    ui.setAction(ProjectLID.Paste, createPasteAction());
    ui.setAction(ProjectLID.CaptureBehavior, createCaptureAction());
    ui.setAction(ProjectLID.CopyDesign, createCopyDesignAction());
    ui.setAction(ProjectLID.CopyTask, createCopyTaskAction());
    ui.setAction(ProjectLID.CutDesign, createCutDesignAction());
    ui.setAction(ProjectLID.CutTask, createCutTaskAction());
    ui.setAction(ProjectLID.SelectAll, new AListenerAction() {

        public boolean performAction(Object prms) {
            ui.selectAllTasks();
            return true;
        }
    });
    ui.setAction(ProjectLID.NewDesign, createNewDesignAction());
    ui.setAction(ProjectLID.NewDesignFromImport, createNewDesignForImport());
    ui.setAction(ProjectLID.AddDesignDevices, createAddDesignDevicesAction());
    ui.setAction(ProjectLID.NewProjectNewDesign, createNameProjectNewDesignAction());
    ui.setAction(ProjectLID.EditDesign, createEditDesignAction());
    ui.setAction(ProjectLID.EditTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            int selectedTaskCount = selection.getSelectedTaskCount();
            if (selectedTaskCount == 1) {
                AUndertaking selectedTask = selection.getSelectedTask();
                ui.initiateTaskRename(selectedTask);
                return true;
            }
            if (selectedTaskCount == 0) {
                interaction.protestNoSelection();
            } else {
                interaction.protestTooManySelectedTasks();
            }
            return false;
        }
    });
    ui.setAction(ProjectLID.RenameDesign, createRenameDesignAction());
    ui.setAction(ProjectLID.InitiateTaskRename, createInitiateTaskRenameAction());
    ui.setAction(ProjectLID.HCIPARenameTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectUI.TaskRenameEvent evt = (ProjectUI.TaskRenameEvent) prms;
            return hcipaRenameTask(evt.task, evt.task.getName(), evt.newName);
        }
    });
    ui.setAction(ProjectLID.RenameTask, new IListenerAction() {

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

        public boolean performAction(Object prms) {
            ProjectUI.TaskRenameEvent evt = (ProjectUI.TaskRenameEvent) prms;
            return renameTask(evt.task, evt.task.getName(), evt.newName, evt.parent);
        }
    });
    ui.setAction(ProjectLID.EditScript, createScriptEditorAction());
    ui.setAction(ProjectLID.ViewGroupScript, createScriptViewerAction());
    ui.setAction(ProjectLID.DeleteDesign, createDeleteDesignAction());
    ui.setAction(ProjectLID.DeleteTask, createDeleteTaskAction());
    ui.setAction(ProjectLID.NewTask, createNewTaskAction());
    ui.setAction(ProjectLID.NewTaskGroup, createNewTaskGroupAction());
    ui.setAction(ProjectLID.ReorderDesigns, createReorderDesignsAction());
    ui.setAction(ProjectLID.ShowSum, createShowNatureAction(GroupNature.SUM, ProjectLID.ShowSum));
    ui.setAction(ProjectLID.ShowMean, createShowNatureAction(GroupNature.MEAN, ProjectLID.ShowMean));
    ui.setAction(ProjectLID.ShowMin, createShowNatureAction(GroupNature.MIN, ProjectLID.ShowMin));
    ui.setAction(ProjectLID.ShowMax, createShowNatureAction(GroupNature.MAX, ProjectLID.ShowMax));
    ui.setAction(ProjectLID.RegenerateScript, createRegenerateScriptAction());
    ui.setAction(ProjectLID.RecomputeScript, createRecomputeScriptAction());
    ui.setAction(ProjectLID.ShowModelVisualization, createShowModelVisualizationAction());
    ui.setAction(ProjectLID.DisplayTraces, createDisplayTraces());
    ui.setAction(ProjectLID.ExportTraces, createExportTraces());
    ui.setAction(ProjectLID.ExportForSanlab, createExportForSanlab());
    ui.setAction(ProjectLID.ExportActrModelFile, createExportActrModelFile());
    ui.setAction(ProjectLID.ExportDesignToHTML, createExportDesignToHTMLAction());
    ui.setAction(ProjectLID.ExportToHCIPA, createExportToHCIPAAction());
    ui.setAction(ProjectLID.ExportResultsToCSV, createExportResultsToCSVAction());
    ui.setAction(ProjectLID.ImportXML, createImportAction());
    /*for(CogToolLID lid : ProjectLID.getCollection())
        {
            this.ui.setAction(lid,
                              createImportAction());
        }*/
    /*this.ui.setAction(ProjectLID.ImportXML,
        new IListenerAction() {

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

<<<<<<< .mine

          public boolean performAction(Object prms)
          {
              Class convClass =  (Class)prms;

              createImportAction(convClass);
              return true;
          }
      });*/
    ui.setAction(ProjectLID.ImportWebCrawl, createImportWebCrawlAction());
    ui.setAction(ProjectLID.ExportScriptToCSV, createExportScriptToCSVAction());
    ui.setAction(ProjectLID.ExportToXML, createExportDesignToXML());
    ui.setAction(ProjectLID.DuplicateDesign, createDuplicateDesignAction());
    ui.setAction(ProjectLID.DuplicateTask, createDuplicateTasksAction());
    ui.setAction(ProjectLID.ImportHumanCSVFile, createImportHumanCSVFileAction());
    ui.setAction(ProjectLID.SetAlgorithmACTR6, createSetAlgorithmAction(ACTR6PredictionAlgo.ONLY, ProjectLID.SetAlgorithmACTR6, SET_ALG_ACTR6));
    ui.setAction(ProjectLID.SetAlgorithmSNIFACT, createSetAlgorithmAction(SNIFACTPredictionAlgo.ONLY, ProjectLID.SetAlgorithmSNIFACT, SET_ALG_SNIFACT));
    ui.setAction(ProjectLID.SetAlgorithmHuman, createSetAlgorithmHumanAction());
    ui.setAction(ProjectLID.EditACTRModelFile, createEditACTRModelAction());
    ui.setAction(ProjectLID.SetBackgroundComputationDefault, createSetBackgroundComputeAction(TaskApplication.USE_PROJECT_DEFAULT, ProjectLID.SetBackgroundComputationDefault, SET_RUN_PROJECT_DEFAULT));
    ui.setAction(ProjectLID.SetBackgroundComputationTrue, createSetBackgroundComputeAction(TaskApplication.RUN_IN_BACKGROUND, ProjectLID.SetBackgroundComputationTrue, SET_RUN_BACKGROUND));
    ui.setAction(ProjectLID.SetBackgroundComputationFalse, createSetBackgroundComputeAction(TaskApplication.RUN_IN_FOREGROUND, ProjectLID.SetBackgroundComputationFalse, SET_RUN_FOREGROUND));
    ui.setAction(ProjectLID.GenerateACTRModelFile, createGenerateACTRModelAction());
    ui.setAction(ProjectLID.SetProjDefaultAlgoACTR, createSetProjDefaultAlg(ProjectLID.SetProjDefaultAlgoACTR, SET_PROJ_DEFAULT_ACTR, ACTR6PredictionAlgo.ONLY));
    ui.setAction(ProjectLID.SetProjDefaultAlgoSNIFACT, createSetProjDefaultAlg(ProjectLID.SetProjDefaultAlgoSNIFACT, SET_PROJ_DEFAULT_SNIFACT, SNIFACTPredictionAlgo.ONLY));
    ui.setAction(ProjectLID.SetProjExecBackground, createSetProjDefaultExecBkg(ProjectLID.SetProjExecBackground, SET_RUN_BKG_DEFAULT, true));
    ui.setAction(ProjectLID.SetProjExecForeground, createSetProjDefaultExecBkg(ProjectLID.SetProjExecForeground, SET_RUN_FG_DEFAULT, false));
    ui.setAction(ProjectLID.ChangeTaskPosition, createChangeTaskPositionAction());
    ui.setAction(ProjectLID.DuplicateTaskFull, createDuplicateTaskFullAction());
    ui.setAction(ProjectLID.Ungroup, createUngroupAction());
    ui.setAction(ProjectLID.PromoteTask, createPromoteTaskAction());
    ui.setAction(ProjectLID.DemoteTask, createDemoteTaskAction());
    ui.setAction(ProjectLID.MoveTaskEarlier, createMoveTaskEarlierAction());
    ui.setAction(ProjectLID.MoveTaskLater, createMoveTaskLaterAction());
    ui.setAction(ProjectLID.GenerateDictionary, createGenerateDictionaryAction());
    ui.setAction(ProjectLID.EditDictionary, createOpenDictionaryAction());
    ui.setAction(ProjectLID.ExportDictToCSV, createExportDictionaryAction());
    ui.setAction(ProjectLID.ImportDict, createImportDictionaryAction());
    ui.setAction(ProjectLID.MoveTaskApplication, createMoveTaskAppAction());
    ui.setAction(ProjectLID.DuplicateTaskApplication, createDuplicateTaskAppAction());
}
Also used : ProjectUI(edu.cmu.cs.hcii.cogtool.ui.ProjectUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) SelectionState(edu.cmu.cs.hcii.cogtool.ui.SelectionState) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState) ProjectContextSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectContextSelectionState)

Example 72 with IListenerAction

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

the class ProjectController method createCopyDesignAction.

// Action for CopyDesign
protected IListenerAction createCopyDesignAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignSelectionState seln = (DesignSelectionState) prms;
            Design design = seln.getSelectedDesign();
            // Can only copy if a design is currently selected.
            if (design != null) {
                try {
                    ObjectSaver s = CogToolClipboard.startClipboardDesignSave(project, CogToolClipboard.SAVE_TO_CLIPBOARD);
                    saveDesignToClipboard(design, s);
                    s.finish();
                    interaction.setStatusMessage(DESIGN_COPIED);
                    return true;
                } catch (IOException e) {
                    throw new RcvrClipboardException(e);
                } catch (OutOfMemoryError error) {
                    throw new RcvrOutOfMemoryException("Copying Design", error);
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) ITaskDesign(edu.cmu.cs.hcii.cogtool.model.Project.ITaskDesign) ObjectSaver(edu.cmu.cs.hcii.cogtool.util.ObjectSaver) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) DesignSelectionState(edu.cmu.cs.hcii.cogtool.ui.DesignSelectionState)

Example 73 with IListenerAction

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

the class FrameEditorController method createChangeTypeAction.

/**
     * Create a listener action for changing the type.
     * Changing the type can be a dangerous option.
     * If you change the type and thus change what kind of
     * transition you can use, it may play havoc on scripts, and design view.
     * @return
     */
private IListenerAction createChangeTypeAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.TypeChangeParameters p = (FrameEditorUI.TypeChangeParameters) prms;
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_WIDGET_TYPE, FrameEditorLID.ChangeTypeProperty);
            while (selected.hasNext()) {
                IWidget widget = selected.next();
                // Check if the widget types match
                // TODO: deal with the following
                // WidgetType.compatibleTransitions(oldWidgetType,
                //                                  p.newWidgetType)
                // if it returns false, show interaction..
                // auto delete transition?
                changeWidgetType(FrameEditorLID.ChangeTypeProperty, CHG_WIDGET_TYPE, widget, p.newWidgetType, 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) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 74 with IListenerAction

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

the class FrameEditorController method captureImageAction.

// createChangeAuxTextPropertyAction
/**
     * Create a ListenerAction which will handle capturing a background image.
     * @return
     */
private IListenerAction captureImageAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CAPTURE_BKG_IMG, FrameEditorLID.CaptureImageProperty);
            // Get the selection.
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            Iterator<IWidget> selected = selection.getSelectedWidgetsIterator();
            // Iterate over every selected widget
            while (selected.hasNext()) {
                final IWidget w = selected.next();
                DoubleRectangle bounds = w.getEltBounds();
                // Get the image from the background, and crop to shape
                final byte[] bg = GraphicsUtil.cropImage(model.getBackgroundImage(), bounds.x, bounds.y, bounds.width, bounds.height);
                // Get the old image, could be null.
                final byte[] old = w.getImage();
                final String previousImagePath = (String) w.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
                w.setImage(bg);
                w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, WidgetAttributes.NO_IMAGE);
                editSequence.addEdit(new AUndoableEdit(FrameEditorLID.CaptureImageProperty) {

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

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

                    @Override
                    public void undo() {
                        super.undo();
                        w.setImage(old);
                        w.setAttribute(WidgetAttributes.IMAGE_PATH_ATTR, previousImagePath);
                    }
                });
            }
            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) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 75 with IListenerAction

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

the class DictionaryEditorController method createAddNewTermAction.

protected IListenerAction createAddNewTermAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            final DictionaryEditorUI.AddStringParms parms = (DictionaryEditorUI.AddStringParms) actionParms;
            final String oldString;
            if (parms.isGoal) {
                oldString = pendingEntry.getDictEntry().goalWord;
                if (parms.newString.equals(oldString)) {
                    interaction.setStatusMessage(STRING_UNCHANGED);
                    return true;
                }
                pendingEntry.setGoal(parms.newString);
            } else {
                oldString = pendingEntry.getDictEntry().searchWord;
                if (parms.newString.equals(oldString)) {
                    interaction.setStatusMessage(STRING_UNCHANGED);
                    return true;
                }
                pendingEntry.setSearch(parms.newString);
            }
            undoMgr.addEdit(new AUndoableEdit(DictionaryEditorLID.StartNewEntry) {

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

                @Override
                public void redo() {
                    super.redo();
                    if (parms.isGoal) {
                        pendingEntry.setGoal(parms.newString);
                    } else {
                        pendingEntry.setSearch(parms.newString);
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    if (parms.isGoal) {
                        pendingEntry.setGoal(oldString);
                    } else {
                        pendingEntry.setSearch(oldString);
                    }
                }
            });
            return true;
        }
    };
}
Also used : DictionaryEditorUI(edu.cmu.cs.hcii.cogtool.ui.DictionaryEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)

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