Search in sources :

Example 1 with GraphicalSource

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource in project cogtool by cogtool.

the class DesignEditorMouseState method dealWithMouseDragged.

@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int eventX, int eventY, int state) {
    boolean goForward = super.dealWithMouseDragged(figure, button, eventX, eventY, state);
    if (goForward && mouseDown) {
        StandardDrawingEditor editor = ui.getViewEditor();
        // Update VIEW to ensure ME point is visible.
        // If outside of the visible canvas, up-click should cancel!
        stopMouseDragTimer = true;
        stopDynamic = editor.movePointNearEdge(eventX, eventY, updateDelta);
        switch(getMouseState()) {
            case PotentialMovingFrame:
            case PotentialMovingSelection:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(MovingFrames);
                // fall through!
                }
            case MovingFrames:
                {
                    updateDynamicMove(eventX, eventY, false);
                    break;
                }
            case PotentialTogglingSelection:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(TogglingSelection);
                // fall through!
                }
            case TogglingSelection:
                {
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialSelectingFrames:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(SelectingFrames);
                // fall through!
                }
            case SelectingFrames:
                {
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialCreatingTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    // Do not allow transitions from menu headers or submenus
                    IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, StructureViewUIModel.SOURCE_ONLY);
                    if ((target instanceof GraphicalParentWidget<?, ?>) && (((GraphicalParentWidget<?, ?>) target).canHaveChildren())) {
                        break;
                    }
                    setMouseState(CreatingTransition);
                    // Ensures proper default action
                    selection.deselectAll();
                // fall through!
                }
            case CreatingTransition:
                {
                    dynamicTransition(eventX, eventY);
                    DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
                    if (targetFigure != potentialTarget) {
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(false);
                        }
                        potentialTarget = targetFigure;
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(true);
                        }
                    }
                    break;
                }
            case PotentialSelectTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    handleMousePressed(StructureViewUIModel.NO_TRANSITION);
                    switch(getMouseState()) {
                        case PotentialMovingFrame:
                            {
                                setMouseState(MovingFrames);
                                updateDynamicMove(eventX, eventY, false);
                                break;
                            }
                        case PotentialSelectingFrames:
                            {
                                setMouseState(SelectingFrames);
                                updateDynamicSelectionArea(eventX, eventY);
                                break;
                            }
                        case PotentialCreatingTransition:
                            {
                                setMouseState(CreatingTransition);
                                dynamicTransition(eventX, eventY);
                                break;
                            }
                    }
                    break;
                }
            case PotentialToggleTransition:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    handleMousePressed(StructureViewUIModel.NO_TRANSITION);
                    setMouseState(TogglingSelection);
                    updateDynamicSelectionArea(eventX, eventY);
                    break;
                }
            case PotentialChangeTarget:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(ChangingTarget);
                    Point start = hitTransition.getStart();
                    hitTransition.setVisible(false);
                    double zoom = ui.getZoom();
                    double startX = start.x * zoom;
                    double startY = start.y * zoom;
                    ensureDynamicTransition(PrecisionUtilities.round(startX), PrecisionUtilities.round(startY));
                // fall through!
                }
            case ChangingTarget:
                {
                    dynamicTransitionTarget(eventX, eventY);
                    DesignEditorFrame targetFigure = ui.structureView.getFrameAtXY(eventX, eventY);
                    if (targetFigure != potentialTarget) {
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(false);
                        }
                        potentialTarget = targetFigure;
                        if (potentialTarget != null) {
                            potentialTarget.dynamicHighlight(true);
                        }
                    }
                    break;
                }
            case PotentialChangeSource:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    setMouseState(ChangingSource);
                    hitTransition.setVisible(false);
                    ensureDynamicTransition(mouseDownX, mouseDownY);
                    Point endPt = hitTransition.getEnd();
                    double zoom = ui.getZoom();
                    double endX = endPt.x * zoom;
                    double endY = endPt.y * zoom;
                    dynamicTransitionTarget(PrecisionUtilities.round(endX), PrecisionUtilities.round(endY));
                    break;
                }
            case ChangingSource:
                {
                    dynamicTransitionSource(eventX, eventY);
                    GraphicalSource<?> sourceFigure = ui.structureView.getSourceAtXY(eventX, eventY);
                    InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
                    if (sourceFigure != null) {
                        drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.DRAW_CURSOR));
                    } else {
                        drawLayer.setCursor(WindowUtil.getCursor(WindowUtil.SELECT_CURSOR));
                    }
                    break;
                }
            case PotentialDuplicatingFrame:
                {
                    if (withinHysteresis(eventX, eventY)) {
                        break;
                    }
                    duplicatingDynamic = new ArrayList<RectangleFigure>();
                    //populate this from selection state
                    double zoom = ui.getZoom();
                    Iterator<DesignEditorFrame> selectedFrames = selection.getSelectedFrameFigures();
                    while (selectedFrames.hasNext()) {
                        RectangleFigure rect = new RectangleFigure();
                        DesignEditorFrame currFrame = selectedFrames.next();
                        //set size of new rectangle object
                        Rectangle frameSize = currFrame.getBounds();
                        frameSize.height = PrecisionUtilities.round(frameSize.height / zoom);
                        frameSize.width = PrecisionUtilities.round(frameSize.width / zoom);
                        frameSize.x = PrecisionUtilities.round(frameSize.x * zoom);
                        frameSize.y = PrecisionUtilities.round(frameSize.y * zoom);
                        rect.setBounds(frameSize);
                        //add new rectangle object to the array list
                        duplicatingDynamic.add(rect);
                        //display the new rectangle object
                        showSelectionArea(rect);
                    }
                    setMouseState(DuplicatingFrames);
                // fall through!
                }
            case DuplicatingFrames:
                {
                    updateDynamicDuplicate(eventX, eventY);
                    break;
                }
        }
        // Repeating timer for causing events to repeat.
        if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
            if (rootFigure == null) {
                rootFigure = ui.getViewEditor().getInteractionFigure();
            }
            stopMouseDragTimer = false;
            // Determine the new point the mouse "moved" too.
            mouseDragTask.setNextMousePosition(eventX + updateDelta.x, eventY + updateDelta.y, button, state);
            // Queue the event for 0.1 sec.
            WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
        }
    }
    lastX = eventX;
    lastY = eventY;
    cleanup();
    return goForward;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalSource(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with GraphicalSource

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource in project cogtool by cogtool.

the class DesignEditorMouseState method handleMousePressed.

// dealWithMouseDoubleClicked
protected void handleMousePressed(int filter) {
    if (filter == StructureViewUIModel.NO_LABEL) {
        ResizeThumb thumb = ui.getResizeAtXY(mouseDownX, mouseDownY);
        if (thumb != null) {
            hitTransition = (DesignEditorTransition) thumb.getData();
            selection.setSelectedTransition(hitTransition);
            if (thumb.thumbType == DesignEditorUI.SOURCE) {
                setMouseState(PotentialChangeSource);
            } else {
                setMouseState(PotentialChangeTarget);
            }
            return;
        }
    }
    IFigure target = ui.structureView.getFigureAtXY(mouseDownX, mouseDownY, filter);
    if (target instanceof DesignEditorTransition) {
        hitTransition = (DesignEditorTransition) target;
        if ((mouseDownState & InputEvent.SHIFT) != 0) {
            setMouseState(PotentialToggleTransition);
        } else {
            setMouseState(PotentialSelectTransition);
        }
    } else if (target instanceof GraphicalSource<?>) {
        potentialTransitionSource = (GraphicalSource<?>) target;
        setMouseState(PotentialCreatingTransition);
    // drag creates arrow
    } else if (target instanceof DesignEditorFrame) {
        DesignEditorFrame frameFigure = (DesignEditorFrame) target;
        Frame frame = frameFigure.getFrame();
        if ((mouseDownState & InputEvent.SHIFT) != 0) {
            setMouseState(PotentialTogglingSelection);
        } else if ((mouseDownState & platformDuplicateModifierKey()) != 0) {
            if (!selection.isFrameSelected(frame)) {
                selection.setSelectedFrame(frameFigure);
            }
            setMouseState(PotentialDuplicatingFrame);
        } else {
            if (selection.isFrameSelected(frame)) {
                setMouseState(PotentialMovingSelection);
            } else {
                selection.setSelectedFrame(frameFigure);
                setMouseState(PotentialMovingFrame);
            }
        }
    } else {
        // out in space
        if ((mouseDownState & InputEvent.SHIFT) != 0) {
            setMouseState(PotentialTogglingSelection);
        } else {
            selection.deselectAll();
            setMouseState(PotentialSelectingFrames);
        }
    }
}
Also used : DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) Frame(edu.cmu.cs.hcii.cogtool.model.Frame) ResizeThumb(edu.cmu.cs.hcii.cogtool.view.ResizeThumb) DesignEditorFrame(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame) DesignEditorTransition(edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition) GraphicalSource(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with GraphicalSource

use of edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource 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

DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)3 GraphicalSource (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource)3 IFigure (org.eclipse.draw2d.IFigure)3 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)2 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)2 DesignEditorTransition (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition)2 InteractionFigure (edu.cmu.cs.hcii.cogtool.view.InteractionFigure)2 Iterator (java.util.Iterator)2 Point (org.eclipse.draw2d.geometry.Point)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 Transition (edu.cmu.cs.hcii.cogtool.model.Transition)1 TransitionSource (edu.cmu.cs.hcii.cogtool.model.TransitionSource)1 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)1 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)1 ResizeThumb (edu.cmu.cs.hcii.cogtool.view.ResizeThumb)1 StandardDrawingEditor (edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor)1 ArrayList (java.util.ArrayList)1 RectangleFigure (org.eclipse.draw2d.RectangleFigure)1