Search in sources :

Example 86 with IListenerAction

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

the class DesignEditorController method createDuplicateFrameAction.

protected IListenerAction createDuplicateFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            // From DesignEditorUI
            DesignEditorUI.DuplicateParameters parameters = (DesignEditorUI.DuplicateParameters) prms;
            Frame[] framesToDuplicate = parameters.selection.getSelectedFrames();
            if ((framesToDuplicate != null) && (framesToDuplicate.length > 0)) {
                FrameSubsetDuplicator duplicator = new FrameSubsetDuplicator(framesToDuplicate);
                Frame[] duplicatedFrames = new Frame[framesToDuplicate.length];
                for (int i = 0; i < framesToDuplicate.length; i++) {
                    Frame duplicatedFrame = duplicator.getOrDuplicate(framesToDuplicate[i]);
                    duplicatedFrames[i] = duplicatedFrame;
                    duplicatedFrame.moveFrameOrigin(parameters.dx, parameters.dy);
                }
                design.addFrames(duplicatedFrames);
                undoMgr.addEdit(createDuplicateFramesEdit(duplicatedFrames));
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 87 with IListenerAction

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

the class DesignEditorController method createEditFrameAction.

protected IListenerAction createEditFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState selection = (FrameSelectionState) prms;
            Frame[] frames = selection.getSelectedFrames();
            if ((frames == null) || (frames.length == 0)) {
                interaction.protestNoSelection();
                return false;
            }
            for (Frame frame : frames) {
                try {
                    FrameEditorController.openController(frame, design, project);
                } catch (GraphicsUtil.ImageException ex) {
                    interaction.protestInvalidImageFile();
                }
            }
            return true;
        }
    };
}
Also used : FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) GraphicsUtil(edu.cmu.cs.hcii.cogtool.util.GraphicsUtil)

Example 88 with IListenerAction

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

the class DesignEditorController method createEditTransitionAction.

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

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

        public boolean performAction(Object prms) {
            DesignEditorUI.EditTransitionParameters parms = (DesignEditorUI.EditTransitionParameters) prms;
            Transition[] transitions = parms.selection.getSelectedTransitions();
            // Probably only one transition selected
            if ((transitions != null) && (transitions.length > 0)) {
                if (transitions.length == 1) {
                    TransitionSource source = transitions[0].getSource();
                    AAction action = transitions[0].getAction();
                    int limitMode = ActionProperties.determineChangeActionMode(source);
                    int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
                    if (!interaction.determineNewAction(transitions[0], properties, parms.useWhichParts, deviceTypes, limitMode, L10N.get("DE.ChangeActionType", "Change Action Type"))) {
                        return false;
                    }
                    action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (action == null) {
                        return false;
                    }
                    action = EditActionCmd.ensureActionIsUnique(source, action, properties, deviceTypes, limitMode, transitions[0], interaction);
                    if (action == null) {
                        return false;
                    }
                    return changeTransitionsAction(transitions, action, properties.delayInSecs, properties.delayLabel);
                } else {
                    interaction.protestMultipleTransitionSelection();
                }
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) DesignEditorUI(edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) AAction(edu.cmu.cs.hcii.cogtool.model.AAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 89 with IListenerAction

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

the class Controller 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 windows support.
     *
     * @author mlh
     */
protected void assignActions() {
    UI ui = getUI();
    if (ui != null) {
        ui.setAction(CogToolLID.About, ui.popAboutBox());
        // Set "open" action
        ui.setAction(CogToolLID.OpenProject, new AListenerAction() {

            public boolean performAction(Object prms) {
                // open expects null in that case.
                if (!(prms instanceof DoublePoint)) {
                    prms = null;
                }
                // Ask the user to select a CogTool project to open
                File[] openLocs = getUI().getStandardInteraction().selectFileSources();
                return open((DoublePoint) prms, openLocs);
            }
        });
        ui.setAction(CogToolLID.OpenProjectFile, new IListenerAction() {

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

            public boolean performAction(Object actionParms) {
                File[] openLoc = { new File((String) actionParms) };
                return open(null, openLoc);
            }
        });
        // Set "new project" action
        ui.setAction(CogToolLID.NewProject, createNewProjectAction());
        // Set "quit/exit" action
        ui.setAction(CogToolLID.ExitApplication, createExitAction());
        ui.setAction(CogToolLID.ClearRecent, new AListenerAction() {

            public boolean performAction(Object actionParms) {
                CogToolPref.clearRecent();
                Interaction interaction = getUI().getStandardInteraction();
                interaction.setStatusMessage(L10N.get("AC.RecentClear", "Recent file data cleared."));
                return true;
            }
        });
    }
}
Also used : UI(edu.cmu.cs.hcii.cogtool.ui.UI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) Interaction(edu.cmu.cs.hcii.cogtool.ui.Interaction) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) File(java.io.File)

Example 90 with IListenerAction

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

the class DesignEditorController method createCopyFrameAction.

protected IListenerAction createCopyFrameAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameSelectionState seln = (FrameSelectionState) prms;
            Frame[] frames = seln.getSelectedFrames();
            if ((frames != null) && (frames.length > 0)) {
                copyFrames(frames);
                if (frames.length == 1) {
                    interaction.setStatusMessage(FRAME_COPIED);
                } else {
                    interaction.setStatusMessage(FRAMES_COPIED);
                }
                return true;
            }
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : FrameSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameSelectionState) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction)

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