Search in sources :

Example 31 with Transition

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

the class AbstractGraphicalSource method buildToolTipText.

/**
     * Build the ToolTip for this source.
     *
     * @return
     */
public static String buildToolTipText(TransitionSource source, String typeDescription) {
    // Use a string buffer for performance.
    StringBuilder strBuffer = new StringBuilder(source.getNameLabel() + " [" + typeDescription + "]");
    Iterator<Transition> transIter = source.getTransitions().values().iterator();
    IEllipsizer ellipsizer = new SWTStringUtil.SWTEllipsizer(SWTWidthComputer.DEFAULT_WIDTH, StringUtil.NO_FRONT, FontUtils.SYMBOL_FONT);
    while (transIter.hasNext()) {
        Transition transition = transIter.next();
        strBuffer.append("\n    ");
        String text = transition.toString(false, ellipsizer);
        strBuffer.append(text);
    }
    return strBuffer.toString();
}
Also used : Transition(edu.cmu.cs.hcii.cogtool.model.Transition) IEllipsizer(edu.cmu.cs.hcii.cogtool.util.IEllipsizer)

Example 32 with Transition

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

the class AbstractGraphicalSource method setSourceModel.

// Must be called by subclass constructor
protected void setSourceModel(T m) {
    if (m == null) {
        throw new IllegalArgumentException("Cannot set the model of a graphical source to null");
    }
    TransitionSource oldModel = getModel();
    if (oldModel != m) {
        if (oldModel != null) {
            oldModel.removeAllHandlers(this);
        }
        setModel(m);
        buildToolTip();
        getModel().addHandler(this, Widget.WidgetChange.class, this.changeHandler);
        getModel().addHandler(this, TransitionSource.TransitionChange.class, this.transitionChangeHandler);
        Iterator<Transition> modelTransitions = getModel().getTransitions().values().iterator();
        while (modelTransitions.hasNext()) {
            Transition t = modelTransitions.next();
            t.addHandler(this, Transition.ActionChange.class, this.changeHandler);
            t.addHandler(this, Transition.DestinationChange.class, this.changeHandler);
            t.getDestination().addHandler(this, NameChangeAlert.class, this.changeHandler);
        }
        // Inherit attributes from model
        updateAttributes();
    }
}
Also used : TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) Transition(edu.cmu.cs.hcii.cogtool.model.Transition)

Example 33 with Transition

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

the class DesignEditorMouseState method dealWithMouseReleased.

@Override
protected boolean dealWithMouseReleased(IFigure figure, int button, int x, int y, int state) {
    boolean goForward = super.dealWithMouseReleased(figure, button, x, y, state);
    // Clear any mouse drag timer, that may be running
    stopMouseDragTimer = true;
    if (goForward) {
        // This must be done before the hideAllMenuItems!
        IFigure figureAtXY = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
        // Record the mouse down position.
        // Convert mouse coordinates into model coordinates
        double zoom = ui.getZoom();
        double scaledMouseUpX = x / zoom;
        double scaledMouseUpY = y / zoom;
        DesignEditorFrame frameAtXY = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
        if (frameAtXY != null) {
            frameAtXY.hideAllChildren();
            ui.resetHiddenTransitionSources();
        }
        int leftX = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? scaledMouseUpX : scaledMouseDownX);
        int topY = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? scaledMouseUpY : scaledMouseDownY);
        int width = PrecisionUtilities.round((scaledMouseUpX < scaledMouseDownX) ? (scaledMouseDownX - scaledMouseUpX + 1) : (scaledMouseUpX - scaledMouseDownX + 1));
        int height = PrecisionUtilities.round((scaledMouseUpY < scaledMouseDownY) ? (scaledMouseDownY - scaledMouseUpY + 1) : (scaledMouseUpY - scaledMouseDownY + 1));
        Rectangle selectionBox = new Rectangle(leftX, topY, width, height);
        switch(getMouseState()) {
            case PotentialMovingFrame:
                {
                    // set on mouse down.
                    break;
                }
            case PotentialMovingSelection:
                {
                    DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
                    selection.setSelectedFrame(frameFig);
                    break;
                }
            case PotentialSelectingFrames:
                {
                    break;
                }
            case PotentialCreatingTransition:
                {
                    if (figureAtXY instanceof GraphicalParentWidget<?, ?>) {
                        GraphicalParentWidget<?, ?> parentToOpen = (GraphicalParentWidget<?, ?>) figureAtXY;
                        if (!parentToOpen.canHaveChildren()) {
                            parentToOpen = ((GraphicalChildWidget<?, ?>) parentToOpen).getParentFigure();
                        }
                        parentToOpen.openChildren();
                        ui.resetHiddenTransitionSources();
                    }
                    break;
                }
            case MovingFrames:
                {
                    updateDynamicMove(x, y, true);
                    break;
                }
            case PotentialTogglingSelection:
                {
                    dynamicSelectionArea.setVisible(false);
                    DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
                    if (frameFig != null) {
                        if (selection.isFrameSelected(frameFig.getFrame())) {
                            selection.deselectFrame(frameFig);
                        } else {
                            if (selection.getSelectedTransitionCount() > 0) {
                                selection.deselectAll();
                            }
                            selection.selectFrame(frameFig);
                        }
                    }
                    break;
                }
            case TogglingSelection:
                {
                    dynamicSelectionArea.setVisible(false);
                    Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
                    while (frameFigures.hasNext()) {
                        DesignEditorFrame frameFig = frameFigures.next();
                        Frame frame = frameFig.getFrame();
                        if (frameFig.intersects(selectionBox)) {
                            if (selection.isFrameSelected(frame)) {
                                selection.deselectFrame(frameFig);
                            } else {
                                if (selection.getSelectedTransitionCount() > 0) {
                                    selection.deselectAll();
                                }
                                selection.selectFrame(frameFig);
                            }
                        }
                    }
                    break;
                }
            case SelectingFrames:
                {
                    dynamicSelectionArea.setVisible(false);
                    Iterator<DesignEditorFrame> frameFigures = ui.structureView.getAllFrameFigures();
                    while (frameFigures.hasNext()) {
                        DesignEditorFrame frameFig = frameFigures.next();
                        if (frameFig.intersects(selectionBox)) {
                            selection.selectFrame(frameFig);
                        }
                    }
                    break;
                }
            case CreatingTransition:
                {
                    stopDynamicTransition();
                    if (potentialTarget != null) {
                        potentialTarget.dynamicHighlight(false);
                        potentialTarget = null;
                    }
                    if (potentialTransitionSource != null) {
                        DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(x, y);
                        TransitionSource source = potentialTransitionSource.getModel();
                        Frame target = (targetFigure != null) ? targetFigure.getFrame() : (Frame) null;
                        // Convert mouse coordinates into model coordinates
                        DesignEditorUI.NewTransitionParameters prms = new DesignEditorUI.NewTransitionParameters(source, target, scaledMouseUpX, scaledMouseUpY);
                        ui.performAction(DesignEditorLID.NewTransition, prms);
                    }
                    break;
                }
            case PotentialSelectTransition:
            case PotentialChangeTarget:
            case PotentialChangeSource:
                {
                    selection.setSelectedTransition(hitTransition);
                    Transition transition = hitTransition.getTransition();
                    ui.getInteraction().setTransitionStatusMessage(transition);
                    hitTransition = null;
                    break;
                }
            case PotentialToggleTransition:
                {
                    Transition transition = hitTransition.getTransition();
                    if (selection.isTransitionSelected(transition)) {
                        selection.deselectTransition(hitTransition);
                    } else {
                        if (selection.getSelectedFrameCount() > 0) {
                            selection.deselectAll();
                        }
                        selection.selectTransition(hitTransition);
                    }
                    hitTransition = null;
                    break;
                }
            case ChangingTarget:
                {
                    stopDynamicTransition();
                    if (potentialTarget != null) {
                        potentialTarget.dynamicHighlight(false);
                        potentialTarget = null;
                    }
                    DesignEditorFrame newTargetFigure = ui.structureView.getFrameAtXY(x, y);
                    if (newTargetFigure != null) {
                        Transition transition = hitTransition.getTransition();
                        DesignEditorUI.ChangeTargetParameters prms = new DesignEditorUI.ChangeTargetParameters(transition, newTargetFigure.getFrame());
                        ui.performAction(DesignEditorLID.ChangeTarget, prms);
                        ui.getInteraction().setTransitionStatusMessage(transition);
                    }
                    hitTransition.setVisible(true);
                    break;
                }
            case ChangingSource:
                {
                    stopDynamicTransition();
                    InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
                    drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
                    GraphicalSource<?> newSourceFigure = ui.structureView.getSourceAtXY(x, y);
                    hitTransition.setVisible(true);
                    if (newSourceFigure != null) {
                        Transition transition = hitTransition.getTransition();
                        DesignEditorUI.ChangeSourceParameters prms = new DesignEditorUI.ChangeSourceParameters(transition, newSourceFigure.getModel());
                        ui.performAction(DesignEditorLID.ChangeSource, prms);
                        ui.getInteraction().setTransitionStatusMessage(transition);
                    }
                    hitTransition = null;
                    break;
                }
            case PotentialDuplicatingFrame:
                {
                    DesignEditorFrame frameFig = ui.structureView.getFrameAtXY(mouseDownX, mouseDownY);
                    selection.setSelectedFrame(frameFig);
                    break;
                }
            case DuplicatingFrames:
                {
                    double dx = scaledMouseUpX - scaledMouseDownX;
                    double dy = scaledMouseUpY - scaledMouseDownY;
                    // Remove all the rectangle figures from the display, clear the list
                    clearRectFigures();
                    DesignEditorUI.DuplicateParameters prm = new DesignEditorUI.DuplicateParameters(dx, dy, selection);
                    ui.performAction(DesignEditorLID.DuplicateFrame, prm);
                    break;
                }
        }
    }
    setMouseState(MouseUp);
    mouseDown = false;
    cleanup();
    return goForward;
}
Also used : DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) Rectangle(org.eclipse.draw2d.geometry.Rectangle) GraphicalSource(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) Iterator(java.util.Iterator) DesignEditorTransition(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition) Transition(edu.cmu.cs.hcii.cogtool.model.Transition) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

Transition (edu.cmu.cs.hcii.cogtool.model.Transition)33 AAction (edu.cmu.cs.hcii.cogtool.model.AAction)13 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)11 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)7 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)7 ButtonAction (edu.cmu.cs.hcii.cogtool.model.ButtonAction)6 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)5 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)5 MousePressType (edu.cmu.cs.hcii.cogtool.model.MousePressType)4 TapAction (edu.cmu.cs.hcii.cogtool.model.TapAction)4 DesignEditorTransition (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition)4 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)4 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)3 MouseButtonState (edu.cmu.cs.hcii.cogtool.model.MouseButtonState)3 TapPressType (edu.cmu.cs.hcii.cogtool.model.TapPressType)3 DesignEditorUI (edu.cmu.cs.hcii.cogtool.ui.DesignEditorUI)3 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)3 GraffitiAction (edu.cmu.cs.hcii.cogtool.model.GraffitiAction)2 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2