Search in sources :

Example 1 with GraphicalChildWidget

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

the class FrameEditorMouseState method dynamicMoveWidgets.

/**
     * Utility to help with dynamic move of selected widgets.
     *
     * @param selectedWFs the set of selected graphical widget figures
     * @param currentScaledX scaled X location of the current mouse position
     * @param currentScaledY scaled Y location of the current mouse position
     * @author mlh/alex
     */
protected void dynamicMoveWidgets(Iterator<FrameEltSelnFig<?>> selectedFigs, double currentScaledX, double currentScaledY) {
    ui.hideNondynamicSupport(true);
    // Iterate through list of selected objects
    while (selectedFigs.hasNext()) {
        FrameEltSelnFig<?> fig = selectedFigs.next();
        // Determine movement amount from initial points.
        double offsetX = currentScaledX - scaledMouseDownX;
        double offsetY = currentScaledY - scaledMouseDownY;
        if (fig instanceof GraphicalChildWidget<?, ?>) {
            continue;
        } else if (fig instanceof FrameEltGroupHalo) {
            ui.moveFrameElementGroup(offsetX, offsetY, ((FrameEltGroupHalo) fig).getModel());
        } else if (fig instanceof GraphicalWidget<?>) {
            GraphicalWidget<?> gw = (GraphicalWidget<?>) fig;
            if ((gw instanceof GraphicalTraversableWidget<?>) && (gw.getModel().getParentGroup() != null)) {
                ui.moveWidgetGroup(offsetX, offsetY, (GraphicalTraversableWidget<?>) gw);
            } else {
                DoublePoint p = gw.getModel().getShape().getOrigin();
                double tempX = offsetX + p.x;
                double tempY = offsetY + p.y;
                // Prevent moving a widget to an origin less than 0.0,0.0
                if (tempX < 0.0) {
                    tempX = 0.0;
                }
                if (tempY < 0.0) {
                    tempY = 0.0;
                }
                // Temporarily move the widget origin to new location.
                ui.setGraphicalWidgetOrigin(tempX, tempY, gw);
            }
        }
    }
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)

Example 2 with GraphicalChildWidget

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

the class FrameEditorMouseState method dealWithMouseDragged.

/**
     * Parameterized mouse drags so they can be scaled programatically.
     *
     * Handles mouse drags: moves the viewable area as needed
     *
     * @param figure ignored
     * @param mouseX the location the mouse is pointing to
     * @param mouseY the location the mouse is pointing to
     * @param button the buttons pressed
     * @param state the modifiers being held down
     */
@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int mouseX, int mouseY, int state) {
    boolean goForward = super.dealWithMouseDragged(figure, button, mouseX, mouseY, state);
    if (goForward && isMouseDownValid) {
        // Get the StandardEditor for handling visuals & scrolling
        StandardDrawingEditor editor = ui.getViewEditor();
        // Update VIEW to ensure mouse point is visible.
        // If outside of the visible canvas, up-click should cancel!
        stopMouseDragTimer = true;
        stopDynamic = editor.movePointNearEdge(mouseX, mouseY, updateDelta);
        double zoom = ui.getZoom();
        // The current mouse down position (scaled)
        double currentScaledX = mouseX / zoom;
        double currentScaledY = mouseY / zoom;
        Iterator<FrameEltSelnFig<?>> selectedEltFigs = selection.getSelectedFigures();
        InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
        // Else this is a new widget
        switch(getMouseState()) {
            // Perform move-related states
            case PotentialMovingWidget:
            case PotentialMovingSelection:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false);
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(SELECT_CURSOR);
                    setMouseState(MovingWidgets);
                // fall through!
                }
            case MovingWidgets:
                {
                    dynamicMoveWidgets(selectedEltFigs, currentScaledX, currentScaledY);
                    ui.repaintEditor();
                    break;
                }
            case PotentialReorderWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    prevCursor = drawLayer.getCursor();
                    ui.hideNondynamicSupport(false, false);
                    setUpReorderFigures();
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(SELECT_CURSOR);
                    setMouseState(ReorderWidget);
                // fall through!
                }
            case ReorderWidget:
                {
                    dynamicReorderWidget(mouseX, mouseY, false);
                    break;
                }
            case PotentialResizingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(true);
                    // Iterate through selected widgets XYZZY openChildren in a loop???
                    while (selectedEltFigs.hasNext()) {
                        FrameEltSelnFig<?> gw = selectedEltFigs.next();
                        if (gw instanceof GraphicalTraversableWidget<?>) {
                            if (gw instanceof GraphicalChildWidget<?, ?>) {
                                ((GraphicalChildWidget<?, ?>) gw).getParentFigure().openChildren();
                            }
                        }
                    }
                    setMouseState(ResizingWidget);
                // fall through!
                }
            // Perform a drag resize of selected widget
            case ResizingWidget:
                {
                    dynamicResizeWidgets(selectedEltFigs, currentScaledX, currentScaledY);
                    ui.repaintEditor();
                    break;
                }
            // Create a new widget
            case PotentialCreatingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    setMouseState(CreatingWidget);
                // fall through!
                }
            case CreatingWidget:
                {
                    redrawTemporaryWidget(currentScaledX, currentScaledY, false);
                    break;
                }
            // Sweeping a region for toggling selection
            case PotentialTogglingSelection:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    setMouseState(TogglingSelection);
                // fall through!
                }
            case TogglingSelection:
                {
                    redrawTemporaryWidget(currentScaledX, currentScaledY, true);
                    break;
                }
            case PotentialDuplicatingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false, false);
                    duplicatingDynamic = new ArrayList<RectangleFigure>();
                    Iterator<FrameEltSelnFig<?>> selectedFigs = selection.getSelectedFigures();
                    while (selectedFigs.hasNext()) {
                        FrameEltSelnFig<?> currFig = selectedFigs.next();
                        if (currFig instanceof FrameEltGroupHalo) {
                            showSelectionArea(new RectangleFigure(), currFig.getBounds());
                        } else if (!(currFig instanceof GraphicalChildWidget<?, ?>)) {
                            Rectangle widgetBds = new Rectangle(currFig.getBounds());
                            // Must scale widget figure's bounds to zoom factor
                            widgetBds.height = PrecisionUtilities.round(widgetBds.height * zoom);
                            widgetBds.width = PrecisionUtilities.round(widgetBds.width * zoom);
                            widgetBds.x = PrecisionUtilities.round(widgetBds.x * zoom);
                            widgetBds.y = PrecisionUtilities.round(widgetBds.y * zoom);
                            //display the new rectangle object
                            showSelectionArea(new RectangleFigure(), widgetBds);
                        }
                    }
                    setMouseState(DuplicatingWidgets);
                // fall through!
                }
            case DuplicatingWidgets:
                {
                    updateDynamicDuplicate(mouseX, mouseY);
                    break;
                }
            case PotentialInsertDuplicateWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false, false);
                    prevCursor = drawLayer.getCursor();
                    setUpReorderFigures();
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(DRAW_CURSOR);
                    setMouseState(InsertDuplicateWidget);
                // fall through!
                }
            case InsertDuplicateWidget:
                {
                    dynamicReorderWidget(mouseX, mouseY, true);
                    break;
                }
            case PotentialMovingGridButtons:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
                    GridButton owner = (GridButton) gw.getModel();
                    DoublePoint start = owner.getShape().getOrigin();
                    GridButtonGroup gbg = (GridButtonGroup) owner.getParentGroup();
                    movedGridButtons = gbg.getMovedButtons(moveIsVertical, start.x, start.y);
                    minX = start.x - owner.getHorizSpace();
                    minY = start.y - owner.getVertSpace();
                    prevCursor = drawLayer.getCursor();
                    if (moveIsVertical) {
                        drawLayer.setCursor(MOVE_VERT_CURSOR);
                    } else {
                        drawLayer.setCursor(MOVE_HORIZ_CURSOR);
                    }
                    setMouseState(MovingGridButtons);
                // fall through!
                }
            case MovingGridButtons:
                {
                    dynamicMoveGridButtons(currentScaledX, currentScaledY);
                    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(mouseX + updateDelta.x, mouseY + updateDelta.y, button, state);
            // Queue the event for 0.1 sec.
            WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
        }
    }
    lastX = mouseX;
    lastY = mouseY;
    updateDynamic();
    return goForward;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) ArrayList(java.util.ArrayList) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) FrameEltSelnFig(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) Iterator(java.util.Iterator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 3 with GraphicalChildWidget

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

Example 4 with GraphicalChildWidget

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

the class FrameEditorMouseState method handleMousePressed.

/**
     * Called on mouse presses
     * Determines if the mouse pressed on a resize widget.
     * Raises a resizeAlert or a mouseOperations alert.
     *
     * Alerts contain X,Y coordinates in 1:1 scale.
     */
protected void handleMousePressed(int x, int y, int state) {
    ui.view.getEditor().getSWTEditorSubstrate().setFocus();
    // Check to see if the pressed event is on the resize handlers.
    // Use the ZOOMED scale because the resize widgets are in the
    // interaction layer and they're not affected by zoom.
    ResizeThumb resize = ui.widgetResizeUnderXY(x, y);
    PotentialFigure pWidget = ui.potentialWidgetUnderXY(x, y);
    RadioButtonSash sash = ui.radioSashUnderXY(x, y);
    // Check to see if the mouse press happened on a resize widget
    if (resize != null) {
        // Need this because we want the actual AREA,
        // not the center of the thumb.
        initialResizeArea = ui.getSelectedWidgetArea();
        // Set the fixed point of the resize
        double fixedX = 0.0;
        double fixedY = 0.0;
        // Move through the possible types and set the fixed point.
        currentResizeHandleType = resize.thumbType;
        switch(resize.thumbType) {
            case FrameEditorUI.TOP_LEFT:
                fixedX = initialResizeArea.x + initialResizeArea.width;
                fixedY = initialResizeArea.y + initialResizeArea.height;
                break;
            case FrameEditorUI.BOTTOM_LEFT:
                fixedX = initialResizeArea.x + initialResizeArea.width;
                fixedY = initialResizeArea.y;
                break;
            case FrameEditorUI.TOP_RIGHT:
                fixedX = initialResizeArea.x;
                fixedY = initialResizeArea.y + initialResizeArea.height;
                break;
            case FrameEditorUI.BOTTOM_RIGHT:
                fixedX = initialResizeArea.x;
                fixedY = initialResizeArea.y;
                break;
            default:
                // and this code wasn't modified.
                throw new IllegalStateException("Unknown type of Resize Thumb selected");
        }
        // Specify the fixed resize point.
        mouseFixedResizeX = fixedX;
        mouseFixedResizeY = fixedY;
        // Set the state to "resize" as the next action.
        // TODO:  Should we implement the other types of resizing?
        int nextState = PotentialResizingWidget;
        setMouseState(nextState);
        // Switch to fast mode rendering for graphical widgets
        setWidgetFastRenderMode(true);
    } else if (sash != null) {
        moveIsVertical = sash.isVertical();
        setMouseState(PotentialMovingGridButtons);
    } else if (pWidget != null) {
        ui.initiateRetitleFigure(pWidget);
    } else {
        // Get whatever graphical widget under x,y
        GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
        MoveHalo halo = ui.moveHaloUnderXY(x, y);
        RemoteLinkage linkage = ui.linkageUnderXY(x, y);
        GraphicalParentWidget<?, ?> currentParent = null;
        // If SHIFT is held, always treat as start of a drag toggle select.
        if ((state & InputEvent.SHIFT) != 0) {
            setMouseState(PotentialTogglingSelection);
        } else if (wf != null) {
            IWidget widget = wf.getModel();
            SimpleWidgetGroup group = widget.getParentGroup();
            lastClickedWidget = widget;
            if ((state & platformDuplicateModifierKey()) != 0) {
                if (!selection.isElementSelected(widget)) {
                    selection.setSelectedSelnFig(wf);
                }
                if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM) && (selection.getWidgetSelectionCount() == 1)) {
                    setMouseState(PotentialInsertDuplicateWidget);
                } else {
                    setMouseState(PotentialDuplicatingWidget);
                }
            } else {
                if ((group != null) && (group.getOrientation() != SimpleWidgetGroup.FREEFORM)) {
                    if (!selection.isElementSelected(widget)) {
                        selection.setSelectedSelnFig(wf);
                    }
                    setMouseState(PotentialReorderWidget);
                } else // possible move.
                if (selection.isSelectionFigureSelected(wf)) {
                    setMouseState(PotentialMovingSelection);
                } else {
                    selection.setSelectedSelnFig(wf);
                    setMouseState(PotentialMovingWidget);
                }
            }
            if (wf instanceof GraphicalMenuItem) {
                GraphicalMenuItem menuItemFig = (GraphicalMenuItem) wf;
                if (menuItemFig.isSubmenu()) {
                    currentParent = menuItemFig;
                } else {
                    currentParent = menuItemFig.getParentFigure();
                }
            } else if (wf instanceof GraphicalParentWidget<?, ?>) {
                currentParent = (GraphicalParentWidget<?, ?>) wf;
            } else if (wf instanceof GraphicalChildWidget<?, ?>) {
                currentParent = ((GraphicalChildWidget<?, ?>) wf).getParentFigure();
            }
        } else if (halo != null) {
            if (halo instanceof FrameEltGroupHalo) {
                FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
                if ((state & platformDuplicateModifierKey()) != 0) {
                    if (!selection.isElementSelected(halo.getData())) {
                        selection.setSelectedSelnFig(groupHalo);
                    }
                    setMouseState(PotentialDuplicatingWidget);
                } else {
                    selection.setSelectedSelnFig(groupHalo);
                    setMouseState(PotentialMovingSelection);
                }
            } else {
                /*                if (wf != null) {
                    IWidget widget = wf.getWidgetModel();
                    SimpleWidgetGroup group = widget.getParentGroup();

                    if ((state & platformDuplicateModifierKey()) != 0) {
                        if (! this.selection.isWidgetSelected(widget)) {
                            this.selection.setSelectedWidget(wf);
                        }

                        if ((group != null) &&
                            (group.getOrientation() != SimpleWidgetGroup.FREEFORM) &&
                            (this.selection.getWidgetSelectionCount() == 1))
                        {
                            setMouseState(PotentialInsertDuplicateWidget);
                        }
                        else {
                            setMouseState(PotentialDuplicatingWidget);
                        }
                    }
                    else {
                        setMouseState(PotentialMovingSelection);
                    }
                }
                else { */
                setMouseState(PotentialMovingSelection);
            }
        //                }
        } else if (linkage != null) {
            FrameElement owner = linkage.getOwner();
            IWidget remoteLabel = linkage.getRemoteLabel();
            // Ensure both are selected; if not yet, then set them
            // both selected.
            FrameEltSelnFig<?> ownerRepresentative = isSomeElementSelected(owner);
            if ((!selection.isElementSelected(remoteLabel)) || (ownerRepresentative == null)) {
                if (ownerRepresentative == null) {
                    ownerRepresentative = getRepresentativeElt(owner);
                }
                selection.setSelectedSelnFig(linkage.getRemoteLabelFigure());
                if (ownerRepresentative != null) {
                    selection.selectSelnFig(ownerRepresentative);
                }
            }
            setMouseState(PotentialMovingSelection);
        } else // Otherwise, out in space and SHIFT not held; deselect all and
        // prepare to create
        {
            selection.deselectAll();
            setMouseState(PotentialCreatingWidget);
        }
        ui.hideAllChildren();
        if (currentParent != null) {
            currentParent.openChildren();
            ui.resetVisibleArea();
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) RadioButtonSash(edu.cmu.cs.hcii.cogtool.view.RadioButtonSash) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) FrameEltSelnFig(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ResizeThumb(edu.cmu.cs.hcii.cogtool.view.ResizeThumb) GraphicalMenuItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) RemoteLinkage(edu.cmu.cs.hcii.cogtool.view.RemoteLinkage) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)

Example 5 with GraphicalChildWidget

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

the class FrameEditorMouseState method dynamicReorderWidget.

protected void dynamicReorderWidget(int x, int y, boolean duplicate) {
    int dx = x - lastX;
    int dy = y - lastY;
    Point frameOrigin = reorderFigure.getLocation();
    frameOrigin.x += dx;
    frameOrigin.y += dy;
    reorderFigure.setLocation(frameOrigin);
    GraphicalWidget<?> curWidgetFig = ui.widgetLocatedAtXY(x, y);
    PotentialFigure potential = ui.potentialWidgetUnderXY(x, y);
    ui.resizeHandlesUIFig.hide();
    dividerLine.setVisible(false);
    if ((curWidgetFig != null) && ui.areCompatible(lastClickedWidget, curWidgetFig.getModel()) && (duplicate || reorderAllowed(curWidgetFig.getModel()))) {
        boolean isChildWidget = lastClickedWidget instanceof ChildWidget;
        boolean changedWidget = curWidgetFig.getModel() != lastClickedWidget;
        lastHoveredWidget = curWidgetFig;
        // If the dragged widget is not a child, it won't make sense to
        // drag it onto a potential figure
        // MLHQ: How do you know this cast will succeed?
        ui.hideNonhaloSupport(!isChildWidget, changedWidget, (GraphicalTraversableWidget<?>) curWidgetFig);
        setDividerBounds(curWidgetFig, x, y);
        if (lastClickedWidget instanceof ChildWidget) {
            if (curWidgetFig instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> child = (GraphicalChildWidget<?, ?>) curWidgetFig;
                child.getParentFigure().openChildren();
            }
            if (curWidgetFig instanceof GraphicalParentWidget<?, ?>) {
                if (changedWidget) {
                    ((GraphicalParentWidget<?, ?>) curWidgetFig).openChildren();
                }
            }
        }
    } else if (potential != null) {
        GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
        if (owner instanceof GraphicalChildWidget<?, ?>) {
            ((GraphicalChildWidget<?, ?>) owner).getParentFigure().openChildren();
        }
        ui.potentialUIFig.setSelection(potential);
    } else {
        if (withinReorder(x, y)) {
            setDividerBounds(lastHoveredWidget, x, y);
            if (lastHoveredWidget instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> gcw = (GraphicalChildWidget<?, ?>) lastHoveredWidget;
                gcw.getParentFigure().openChildren();
            }
        } else if ((lastClickedWidget instanceof ChildWidget) || !duplicate) {
            ui.hideNondynamicSupport(true, false);
            InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
            drawLayer.setCursor(NOT_ALLOWED_CURSOR);
        }
    }
}
Also used : Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure)

Aggregations

DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)5 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)5 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)3 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)3 InteractionFigure (edu.cmu.cs.hcii.cogtool.view.InteractionFigure)3 Point (org.eclipse.draw2d.geometry.Point)3 FrameEltSelnFig (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig)2 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)2 Iterator (java.util.Iterator)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)1 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)1 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1