Search in sources :

Example 46 with IListenerAction

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

the class DesignEditorController method createInitiateFrameRenameAction.

// createEditTransitionAction
protected IListenerAction createInitiateFrameRenameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            int selectedFrameCount = selection.getSelectedFrameCount();
            if (selectedFrameCount == 1) {
                ui.initiateFrameRename(selection);
                return true;
            }
            if (selectedFrameCount > 1) {
                interaction.protestMultipleFrameSelection();
                return false;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 47 with IListenerAction

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

the class ZoomableController 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 that all CogTool
     * model editing windows support.
     *
     * @author mlh
     */
@Override
protected void assignActions() {
    super.assignActions();
    final ZoomableUI ui = getZoomableUI();
    if (ui != null) {
        ui.setAction(CogToolLID.SetZoom, new IListenerAction() {

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

            public boolean performAction(Object prm) {
                double zoom = ((Double) prm).doubleValue();
                ui.setZoom(zoom);
                return true;
            }
        });
        ui.setAction(CogToolLID.ZoomToFit, new AListenerAction() {

            public boolean performAction(Object prms) {
                ui.zoomToFit();
                return true;
            }
        });
        ui.setAction(CogToolLID.ZoomNormal, new AListenerAction() {

            public boolean performAction(Object prms) {
                ui.zoomToActual();
                return true;
            }
        });
        ui.setAction(CogToolLID.ZoomIn, new AListenerAction() {

            public boolean performAction(Object prms) {
                ui.zoomIn();
                return true;
            }
        });
        ui.setAction(CogToolLID.ZoomOut, new AListenerAction() {

            public boolean performAction(Object prms) {
                ui.zoomOut();
                return true;
            }
        });
    }
}
Also used : ZoomableUI(edu.cmu.cs.hcii.cogtool.ui.ZoomableUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction)

Example 48 with IListenerAction

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

the class ProjectController method createEditACTRModelAction.

// TODO it is a crock that we're cloning this stuff; when we have time
//      we should design a shared mechanism to be used by all back ends
protected IListenerAction createEditACTRModelAction() {
    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);
            for (AUndertaking task : tasks) {
                TaskApplication ta = project.getTaskApplication(task, design);
                if (ta == null) {
                    return false;
                }
                // find the script
                Script script = ta.getScript(KLMCognitiveGenerator.ONLY);
                if (script == null) {
                    return false;
                }
                // get the resourcePath
                String resourcePath = script.getAssociatedPath();
                if (resourcePath == null) {
                    return false;
                }
                try {
                    FileUtil.editFile(new File(resourcePath));
                } catch (UnsupportedOperationException ex) {
                    throw new RcvrUnimplementedFnException("Editing a file is not implemented", ex);
                } catch (IOException ex) {
                    throw new RcvrIOException("Problem when trying to edit a file.", ex);
                }
            }
            return true;
        }
    };
}
Also used : Script(edu.cmu.cs.hcii.cogtool.model.Script) ProjectSelectionState(edu.cmu.cs.hcii.cogtool.ui.ProjectSelectionState) IOException(java.io.IOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) RcvrIOException(edu.cmu.cs.hcii.cogtool.util.RcvrIOException) 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) RcvrUnimplementedFnException(edu.cmu.cs.hcii.cogtool.util.RcvrUnimplementedFnException) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) File(java.io.File)

Example 49 with IListenerAction

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

the class ProjectController method createInitiateTaskRenameAction.

// createCutTaskAction
// Action for InitiateTaskRename
protected IListenerAction createInitiateTaskRenameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            TaskSelectionState selection = (TaskSelectionState) prms;
            int selectedTaskCount = selection.getSelectedTaskCount();
            // No need, therefore, to prune the task list!
            if (selectedTaskCount == 1) {
                ui.initiateTaskRename(selection.getSelectedTask());
                return true;
            }
            if (selectedTaskCount == 0) {
                interaction.protestNoSelection();
            } else {
                interaction.protestTooManySelectedTasks();
            }
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 50 with IListenerAction

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

the class ProjectController method createShowNatureAction.

// Action for ShowSum, ShowMean, ShowMin, and ShowMax
protected IListenerAction createShowNatureAction(final GroupNature nature, final CogToolLID lid) {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            if (prms != null) {
                final List<TaskGroup> groups = new ArrayList<TaskGroup>();
                final List<GroupNature> oldNatures = new ArrayList<GroupNature>();
                TaskSelectionState seln = (TaskSelectionState) prms;
                AUndertaking[] tasks = seln.getSelectedTasks(TaskSelectionState.FAST_SELECTION);
                // Change applies only to task group instances
                for (AUndertaking task : tasks) {
                    if (task.isTaskGroup()) {
                        TaskGroup group = (TaskGroup) task;
                        GroupNature oldNature = group.getNature();
                        // record old value for undo support
                        if (oldNature != nature) {
                            oldNatures.add(oldNature);
                            groups.add(group);
                            group.setNature(nature);
                        }
                    }
                }
                // undo/redo step and add to undo manager
                if (groups.size() > 0) {
                    undoMgr.addEdit(new AUndoableEdit(lid) {

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

                        @Override
                        public void redo() {
                            super.redo();
                            for (int i = 0; i < groups.size(); i++) {
                                TaskGroup group = groups.get(i);
                                group.setNature(nature);
                            }
                        }

                        @Override
                        public void undo() {
                            super.undo();
                            for (int i = 0; i < groups.size(); i++) {
                                TaskGroup group = groups.get(i);
                                GroupNature oldNat = oldNatures.get(i);
                                group.setNature(oldNat);
                            }
                        }
                    });
                }
            }
            return true;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) TaskSelectionState(edu.cmu.cs.hcii.cogtool.ui.TaskSelectionState) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) GroupNature(edu.cmu.cs.hcii.cogtool.model.GroupNature)

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