Search in sources :

Example 1 with TransitionSource

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

the class FramePropertiesPane method update.

public void update(Frame frame) {
    Object pathObj = frame.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
    if (NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
        imagePath.setVisible(false);
        imagePathText.setVisible(false);
    } else {
        String imgPath = (String) pathObj;
        imagePath.setVisible(true);
        imagePathText.setVisible(true);
        imagePathText.setText(imgPath);
        imagePathText.setSelection(imgPath.length());
    }
    Set<TransitionSource> children = new LinkedHashSet<TransitionSource>();
    children.addAll(frame.getWidgets());
    children.addAll(frame.getInputDevices());
    widgetUpdater.updateTree(children.iterator());
    if (eltGroupTreeLabel != null) {
        Set<FrameElementGroup> grps = frame.getEltGroups();
        if (!CogToolPref.NESTED_GROUPS_SHOWN_AT_TOP_LEVEL.getBoolean()) {
            grps = filterNestedGroups(grps);
        }
        eltGroupUpdater.updateTree(grps.iterator());
        Set<SimpleWidgetGroup> implicitGroups = new HashSet<SimpleWidgetGroup>();
        for (IWidget w : frame.getWidgets()) {
            SimpleWidgetGroup g = w.getParentGroup();
            if (g != null) {
                implicitGroups.add(g);
            }
        }
        implicitGroupUpdater.updateTree(implicitGroups.iterator());
    }
    setFrameName(frame);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with TransitionSource

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

the class DesignEditorTransition method buildToolTip.

protected void buildToolTip() {
    if (showToolTip) {
        String transitionAction = transition.getAction().getLocalizedString();
        TransitionSource source = transition.getSource();
        StringBuilder toolTipText = new StringBuilder();
        String sourceName = SWTStringUtil.insertEllipsis(source.getName(), 100, StringUtil.EQUAL, FontUtils.SYMBOL_FONT);
        String sourceFrameName = SWTStringUtil.insertEllipsis(source.getFrame().getName(), 150, StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
        String destName = SWTStringUtil.insertEllipsis(transition.getDestination().getName(), StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
        toolTipText.append(KeyDisplayUtil.convertActionToDisplay(transitionAction));
        toolTipText.append("\n    " + L10N.get("DE.Source", "Source") + ": ");
        toolTipText.append(sourceName + " (" + sourceFrameName + ")");
        toolTipText.append("\n    " + L10N.get("DE.Target", "Target") + ": ");
        toolTipText.append(destName);
        Label toolTipLabel = new Label(" " + toolTipText.toString() + " ");
        toolTipLabel.setFont(FontUtils.SYMBOL_FONT);
        setToolTip(toolTipLabel);
    }
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Label(org.eclipse.draw2d.Label)

Example 3 with TransitionSource

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

the class StructureViewUIModel method installFrame.

/**
     * Creates the visible representation of a frame, installing
     * the "postage stamp" version, the devices, and the transitions
     * connecting sources to their corresponding destination frames.
     *
     * @param frame the model of the Frame to install
     * @return the <code>IFigure</code> representing the frame's visible
     *         representation
     * @author mlh
     */
protected DesignEditorFrame installFrame(Frame frame) {
    frame.addHandler(this, NameChangeAlert.class, frameNameChangeHandler);
    // Create the figure for the frame
    // For the handlers below, we need the frame figure in order to
    // fetch the figure corresponding to each "modified" source.
    final DesignEditorFrame frameFig = new DesignEditorFrame(frame, showToolTips, sourceRolloverCursor);
    frameFig.addWidgetShapeChangeHandler(shapeChangeHandler);
    frameFig.addWidgetRecoveryHandler(widgetRecoveryHandler);
    frameFig.addOriginChangeHandler(new OriginChangeHandler(frameFig));
    // Whenever a transition is added or removed from a source,
    // the transition's visible representation must be added or
    // removed as well.
    final AlertHandler transitionHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            TransitionSource.TransitionChange chg = (TransitionSource.TransitionChange) alert;
            if (chg != null) {
                GraphicalSource<?> sourceFigure = frameFig.getSourceFigure((TransitionSource) alert.getSource());
                if (chg.isAdd) {
                    installSourceTransition((Transition) chg.element, sourceFigure);
                } else {
                    uninstallSourceTransition((Transition) chg.element, sourceFigure);
                }
            }
        }
    };
    frameFig.addTransitionChangeHandler(transitionHandler);
    // When a widget is added to or removed from this frame during the
    // editing of this frame (see frame editing), install or remove the
    // visible representations of the widget's transitions.
    AlertHandler widgetHandler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            Frame.WidgetChange chg = (Frame.WidgetChange) alert;
            IWidget chgWidget = chg.getChangeElement();
            if (chg != null) {
                if (chg.action == Frame.WidgetChange.ELEMENT_DELETE) {
                    chgWidget.removeHandler(TransitionSource.TransitionChange.class, transitionHandler);
                } else if (chg.action == Frame.WidgetChange.ELEMENT_ADD) {
                    installSourceTransitions(frameFig, chgWidget);
                    chgWidget.addHandler(frameFig, TransitionSource.TransitionChange.class, transitionHandler);
                }
                // At the end of all widget Change Events, refresh.
                contents.repaint();
            }
        }
    };
    frameFig.addWidgetChangeHandler(widgetHandler);
    // Record the correspondence between the given frame and its figure.
    installedFrames.put(frame, frameFig);
    // Install the visible representation of the frame.
    contents.add(frameFig);
    return frameFig;
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 4 with TransitionSource

use of edu.cmu.cs.hcii.cogtool.model.TransitionSource 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 5 with TransitionSource

use of edu.cmu.cs.hcii.cogtool.model.TransitionSource 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)

Aggregations

TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)16 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)7 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)5 AAction (edu.cmu.cs.hcii.cogtool.model.AAction)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)4 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)2 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 LinkedHashSet (java.util.LinkedHashSet)2 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)1 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)1 DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)1 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 LookAtScriptStep (edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)1 TextActionSegment (edu.cmu.cs.hcii.cogtool.model.TextActionSegment)1