Search in sources :

Example 6 with AAction

use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.

the class DesignEditorController method createChangeActionAction.

protected IListenerAction createChangeActionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            DesignEditorUI.ChangeActionParameters chgPrms = (DesignEditorUI.ChangeActionParameters) prms;
            if (chgPrms != null) {
                Transition[] transitions = chgPrms.selection.getSelectedTransitions();
                if ((transitions != null) && (transitions.length > 0)) {
                    properties.copyValues(chgPrms.properties);
                    // TODO: Assume one for the moment; ui enforces it!
                    TransitionSource source = transitions[0].getSource();
                    int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
                    int limitMode = ActionProperties.determineChangeActionMode(source);
                    AAction newAction = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (newAction == null) {
                        return false;
                    }
                    newAction = EditActionCmd.ensureActionIsUnique(source, newAction, properties, deviceTypes, limitMode, transitions[0], interaction);
                    if (newAction == null) {
                        return false;
                    }
                    return changeTransitionsAction(transitions, newAction, NO_DELAY_CHANGE, null);
                // TODO: If the given action properties are unusable
                // (e.g., not unique from the source or empty string)
                // and we should therefore return false so that an
                // action that commits property changes can be
                // canceled, assign the ensureActionIsUnique result
                // to a new variable uniqueAction and return the AND of
                // the changeTransitionsAction call (first) with
                // (newAction == uniqueAction).
                }
            }
            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) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 7 with AAction

use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.

the class DesignEditorController method changeTransitionAction.

protected void changeTransitionAction(final Transition transition, final AAction newAction, final double delayInSecs, final String delayLabel, IUndoableEditSequence editSequence) {
    final AAction oldAction = transition.getAction();
    final double oldDelayInSecs = transition.getDelayInSecs();
    final String oldDelayLabel = transition.getDelayLabel();
    // Must check that the transition's source can accept the new action
    if ((!oldAction.equals(newAction)) || ((delayInSecs != NO_DELAY_CHANGE) && ((delayInSecs != oldDelayInSecs) || !oldDelayLabel.equals(delayLabel)))) {
        transition.setAction(newAction);
        if (delayInSecs != NO_DELAY_CHANGE) {
            transition.setDelayInfo(delayInSecs, delayLabel);
        }
        DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.ObsoletingEdit(DesignEditorLID.ChangeWidgetAction, demoStateMgr) {

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

            @Override
            public void redo() {
                super.redo();
                transition.setAction(newAction);
                if (delayInSecs != NO_DELAY_CHANGE) {
                    transition.setDelayInfo(delayInSecs, delayLabel);
                }
                stateMgr.noteTransitionEdit(transition, this);
                if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
                    DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
                }
            }

            @Override
            public void undo() {
                super.undo();
                transition.setAction(oldAction);
                if (delayInSecs != NO_DELAY_CHANGE) {
                    transition.setDelayInfo(oldDelayInSecs, oldDelayLabel);
                }
                stateMgr.noteTransitionEdit(transition, this);
                if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
                    DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
                }
            }
        };
        demoStateMgr.noteTransitionEdit(transition, edit);
        editSequence.addEdit(edit);
        if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
            DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
        }
    }
}
Also used : AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 8 with AAction

use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.

the class DesignEditorController method changeTransitionSource.

// deleteTransitions
protected boolean changeTransitionSource(final Transition transition, final TransitionSource newSource) {
    final TransitionSource oldSource = transition.getSource();
    if (newSource != oldSource) {
        AAction action = transition.getAction();
        // Check that the new source is consistent the transition's action
        if (!newSource.canAccept(action)) {
            interaction.protestInconsistentSource();
            return false;
        }
        while (newSource.getTransition(action) != null) {
            //TODO: allow interaction to change?  Must handle in undo then!
            if (!interaction.protestNotUniqueAction(action, newSource, false)) {
                return false;
            }
        }
        oldSource.removeTransition(transition);
        transition.setSource(newSource);
        newSource.addTransition(transition);
        final boolean invalidating = (newSource.getFrame() != oldSource.getFrame());
        DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.DesignUndoableEdit(DesignEditorLID.ChangeSource, demoStateMgr) {

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

            @Override
            public Boolean getEditNature() {
                return invalidating ? DemoStateManager.INVALIDATING : DemoStateManager.OBSOLETING;
            }

            @Override
            public void redo() {
                super.redo();
                oldSource.removeTransition(transition);
                transition.setSource(newSource);
                newSource.addTransition(transition);
                stateMgr.noteTransitionEdit(transition, this);
                if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
                    DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
                }
            }

            @Override
            public void undo() {
                super.undo();
                newSource.removeTransition(transition);
                transition.setSource(oldSource);
                oldSource.addTransition(transition);
                stateMgr.noteTransitionEdit(transition, this);
                if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
                    DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
                }
            }
        };
        demoStateMgr.noteTransitionEdit(transition, edit);
        undoMgr.addEdit(edit);
        if (!invalidating && CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
            DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
        }
    }
    return true;
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 9 with AAction

use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.

the class SEDemoController method performEditSelfTransition.

// performChangeDelay
protected boolean performEditSelfTransition(ActionScriptStep step) {
    TransitionSource source = step.getStepFocus();
    AAction action = step.getAction();
    Design design = source.getFrame().getDesign();
    int deviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
    int limitMode = ActionProperties.determineChangeActionMode(source);
    properties.updateProperties(step, action, source);
    if (!interaction.determineNewAction(properties, deviceTypes, limitMode, EDIT_SELF_TRANSITION)) {
        return false;
    }
    action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
    if (action == null) {
        return false;
    }
    action = EditActionCmd.ensureActionIsUnique(source, action, properties, deviceTypes, limitMode, null, interaction);
    if (action == null) {
        return false;
    }
    return changeSelfTransition(step, action, properties.delayInSecs, properties.delayLabel);
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Design(edu.cmu.cs.hcii.cogtool.model.Design) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Example 10 with AAction

use of edu.cmu.cs.hcii.cogtool.model.AAction in project cogtool by cogtool.

the class SEDemoController method createInsertSelfTransitionAction.

protected IListenerAction createInsertSelfTransitionAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object actionParms) {
            SEDemoUI.SelfTransition prms = (SEDemoUI.SelfTransition) actionParms;
            if (prms.target != null) {
                TaskApplication taskApp = script.getDemonstration().getTaskApplication();
                Set<DeviceType> deviceTypeSet = taskApp.getDesign().getDeviceTypes();
                int deviceTypes = DeviceType.buildDeviceSet(deviceTypeSet);
                int limitMode = ActionProperties.determineChangeActionMode(prms.target);
                AAction action = prms.action;
                if (prms.action == null) {
                    properties.resetValues();
                    properties.setInitialActionType(prms.target, deviceTypeSet);
                    if (!interaction.determineNewAction(properties, deviceTypes, limitMode, L10N.get("DE.SetActionType", "Set Action Type"))) {
                        return false;
                    }
                    action = EditActionCmd.buildActionFromProperties(properties, deviceTypes, limitMode, interaction);
                    if (action == null) {
                        return false;
                    }
                }
                action = EditActionCmd.ensureActionIsUnique(prms.target, action, properties, deviceTypes, limitMode, null, interaction);
                if (action == null) {
                    return false;
                }
                return performSelfTransition(prms.selection, prms.target, action, properties.delayInSecs, properties.delayLabel);
            }
            return false;
        }
    };
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) SEDemoUI(edu.cmu.cs.hcii.cogtool.ui.SEDemoUI) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) AAction(edu.cmu.cs.hcii.cogtool.model.AAction)

Aggregations

AAction (edu.cmu.cs.hcii.cogtool.model.AAction)18 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)13 ButtonAction (edu.cmu.cs.hcii.cogtool.model.ButtonAction)6 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)5 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)4 MousePressType (edu.cmu.cs.hcii.cogtool.model.MousePressType)4 TapAction (edu.cmu.cs.hcii.cogtool.model.TapAction)4 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 MouseButtonState (edu.cmu.cs.hcii.cogtool.model.MouseButtonState)3 TapPressType (edu.cmu.cs.hcii.cogtool.model.TapPressType)3 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)3 GraffitiAction (edu.cmu.cs.hcii.cogtool.model.GraffitiAction)2 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)2 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)2 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)2 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)1 Design (edu.cmu.cs.hcii.cogtool.model.Design)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1