Search in sources :

Example 1 with FrameEltGroupHalo

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

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

the class FrameEditorMouseState method dealWithMouseReleased.

/**
     * A mouse up event was called.
     * Checks for context selection, then performs actions as dictated
     * by the FSM.
     */
@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 && isMouseDownValid) {
        // Record the mouse down position
        double zoom = ui.getZoom();
        // The current mouse down position (scaled)
        double currentScaledX = x / zoom;
        double currentScaledY = y / zoom;
        switch(getMouseState()) {
            case PotentialCreatingWidget:
            case PotentialMovingWidget:
            case PotentialResizingWidget:
                {
                    // Nothing to do; any action necessary was taken on "down".
                    break;
                }
            case PotentialReorderWidget:
            case PotentialMovingSelection:
                {
                    // Get whatever graphical widget under original down x,y
                    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    MoveHalo halo = null;
                    FrameElement data = null;
                    if (wf == null) {
                        halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                        if (halo != null) {
                            data = halo.getData();
                            if (data instanceof SimpleWidgetGroup) {
                                IWidget[] widgets = selection.getSelectedIWidgets();
                                SimpleWidgetGroup group = (SimpleWidgetGroup) data;
                                for (IWidget widget : widgets) {
                                    if (widget.getParentGroup() != group) {
                                        selection.deselectElement(widget);
                                    }
                                }
                                break;
                            }
                            if (data instanceof IWidget) {
                                wf = ui.frameUI.getWidgetFigure((IWidget) data);
                            }
                        }
                    }
                    if (wf != null) {
                        selection.setSelectedSelnFig(wf);
                    } else {
                        if (halo == null) {
                            halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                            if (halo != null) {
                                data = halo.getData();
                            }
                        }
                        if ((data != null) && (data instanceof FrameElementGroup)) {
                            selection.setSelectedSelnFig((FrameEltGroupHalo) halo);
                        }
                    }
                    break;
                }
            case PotentialTogglingSelection:
                {
                    // If mouse down on a widget, toggle selection.
                    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    MoveHalo halo = ui.moveHaloUnderXY(mouseDownX, mouseDownY);
                    FrameElement data = null;
                    if (halo != null) {
                        data = halo.getData();
                    }
                    if (wf == null) {
                        if (data instanceof IWidget) {
                            wf = ui.frameUI.getWidgetFigure((IWidget) data);
                        }
                    }
                    if (wf != null) {
                        // If the widget is already selected, unselect it.
                        if (selection.isSelectionFigureSelected(wf)) {
                            selection.deselectSelnFig(wf);
                        } else {
                            selection.selectSelnFig(wf);
                        }
                    } else if (data instanceof SimpleWidgetGroup) {
                        Iterator<IWidget> widgets = ((SimpleWidgetGroup) data).iterator();
                        while (widgets.hasNext()) {
                            IWidget w = widgets.next();
                            selection.deselectElement(w);
                        }
                    } else if ((halo instanceof FrameEltGroupHalo) && (data instanceof FrameElementGroup)) {
                        FrameEltGroupHalo groupHalo = (FrameEltGroupHalo) halo;
                        if (selection.isElementSelected(data)) {
                            selection.deselectSelnFig(groupHalo);
                        } else {
                            selection.selectSelnFig(groupHalo);
                        }
                    } else {
                        selection.deselectAll();
                    }
                    break;
                }
            // Move is complete, so apply changes to the model.
            case MovingWidgets:
                {
                    // Get selection, and use the difference between current
                    // and start location.
                    double moveByX = currentScaledX - scaledMouseDownX;
                    double moveByY = currentScaledY - scaledMouseDownY;
                    FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection);
                    ui.performAction(CogToolLID.MoveWidgets, prms);
                    break;
                }
            case ReorderWidget:
                {
                    boolean reorder = reorderWidget(x, y, reorderParms);
                    ui.clearUISupport(true);
                    isReordering = false;
                    if (reorder) {
                        ui.performAction(FrameEditorLID.Reorder, reorderParms);
                    } else {
                        selection.deselectElement(lastClickedWidget);
                    }
                    InteractionDrawingEditor editor = ui.getViewEditor();
                    editor.removeInteractionFigure(reorderFigure);
                    editor.removeInteractionFigure(dividerLine);
                    break;
                }
            // since the user may have flipped the orientation.
            case ResizingWidget:
                {
                    // Switch to quality mode rendering for graphical widgets
                    setWidgetFastRenderMode(false);
                    if (currentScaledX < 0.0) {
                        currentScaledX = 0.0;
                    }
                    if (currentScaledY < 0.0) {
                        currentScaledY = 0.0;
                    }
                    // Deal with any anchoring issues
                    if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
                        switch(currentResizeHandleType) {
                            case FrameEditorUI.TOP_RIGHT:
                                {
                                    // Cannot change Y position
                                    currentScaledY = initialResizeArea.y;
                                    break;
                                }
                            case FrameEditorUI.BOTTOM_LEFT:
                                {
                                    // Cannot change X position
                                    currentScaledX = initialResizeArea.x;
                                    break;
                                }
                            default:
                                {
                                    break;
                                }
                        }
                        // Cannot move left of top-left
                        if (currentScaledX < initialResizeArea.x) {
                            currentScaledX = initialResizeArea.x;
                        }
                        // Cannot move above of top-left
                        if (currentScaledY < initialResizeArea.y) {
                            currentScaledY = initialResizeArea.y;
                        }
                    }
                    double width = Math.abs(currentScaledX - mouseFixedResizeX);
                    double height = Math.abs(currentScaledY - mouseFixedResizeY);
                    FrameEditorUI.ResizeParameters prms = new FrameEditorUI.ResizeParameters(initialResizeArea.x, initialResizeArea.y, Math.min(currentScaledX, mouseFixedResizeX), Math.min(currentScaledY, mouseFixedResizeY), width / initialResizeArea.width, height / initialResizeArea.height, selection);
                    ui.performAction(CogToolLID.ResizeWidgets, prms);
                    break;
                }
            // Finished a mouse drag operation to create a new widget
            case CreatingWidget:
                {
                    if (currentScaledX < 0.0) {
                        currentScaledX = 0.0;
                    }
                    if (currentScaledY < 0.0) {
                        currentScaledY = 0.0;
                    }
                    double width = Math.abs(scaledMouseDownX - currentScaledX);
                    double height = Math.abs(scaledMouseDownY - currentScaledY);
                    double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
                    double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
                    // Turn off the bounding box drawn.
                    ui.stopDrawingTemporaryFigure();
                    // Create a rectangle for the new region.
                    DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
                    // width of 0. Probably this should be less then 2.
                    if ((region.width != 0.0) && (region.height != 0.0)) {
                        ui.performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(region, ui.getCurrentWidgetType(), ui.view.isAutomaticCreation()));
                    }
                    break;
                }
            // Finished a mouse drag operation to select a set of widgets
            case TogglingSelection:
                {
                    // Get the total area selected
                    double width = Math.abs(scaledMouseDownX - currentScaledX);
                    double height = Math.abs(scaledMouseDownY - currentScaledY);
                    // Get top left point.
                    double leftX = (scaledMouseDownX > currentScaledX) ? currentScaledX : scaledMouseDownX;
                    double topY = (scaledMouseDownY > currentScaledY) ? currentScaledY : scaledMouseDownY;
                    // Turn off the bounding box drawn.
                    ui.stopDrawingTemporaryFigure();
                    // Create the final region's area
                    DoubleRectangle region = new DoubleRectangle(leftX, topY, width, height);
                    // Loop through all figures and check for intersections
                    Iterator<GraphicalWidget<?>> gwFigures = ui.getFrameUI().getFigureListIterator();
                    while (gwFigures.hasNext()) {
                        GraphicalWidget<?> gw = gwFigures.next();
                        if (!(gw instanceof GraphicalChildWidget<?, ?>)) {
                            Rectangle bounds = gw.getBounds();
                            if (region.intersects(bounds.x, bounds.y, bounds.width, bounds.height)) {
                                // If the widget is already selected, deselect it.
                                if (selection.isSelectionFigureSelected(gw)) {
                                    selection.deselectSelnFig(gw);
                                } else {
                                    selection.selectSelnFig(gw);
                                }
                            }
                        }
                    }
                    break;
                }
            case PotentialInsertDuplicateWidget:
            case PotentialDuplicatingWidget:
                {
                    GraphicalWidget<?> widgetFig = ui.widgetLocatedAtXY(mouseDownX, mouseDownY);
                    selection.setSelectedSelnFig(widgetFig);
                    break;
                }
            case DuplicatingWidgets:
                {
                    double dx = currentScaledX - scaledMouseDownX;
                    double dy = currentScaledY - scaledMouseDownY;
                    // Remove all the rectangle figures from the display, clear the list
                    clearRectFigures();
                    ui.performAction(FrameEditorLID.Duplicate, new FrameEditorUI.DuplicateParameters(dx, dy, selection));
                    break;
                }
            case InsertDuplicateWidget:
                {
                    double dx = currentScaledX - scaledMouseDownX;
                    double dy = currentScaledY - scaledMouseDownY;
                    isReordering = false;
                    if (reorderWidget(x, y, insertDuplicateParms)) {
                        insertDuplicateParms.moveByX = dx;
                        insertDuplicateParms.moveByY = dy;
                        ui.performAction(FrameEditorLID.InsertDuplicate, insertDuplicateParms);
                    } else {
                        selection.deselectElement(lastClickedWidget);
                    }
                    InteractionDrawingEditor editor = ui.getViewEditor();
                    editor.removeInteractionFigure(reorderFigure);
                    editor.removeInteractionFigure(dividerLine);
                    break;
                }
            case PotentialMovingGridButtons:
                {
                    if (movedGridButtons != null) {
                        movedGridButtons = NO_GRID_BUTTONS;
                    }
                    break;
                }
            case MovingGridButtons:
                {
                    // Get selection, and use the difference between current
                    // and start location.
                    double moveByX;
                    double moveByY;
                    GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
                    GridButton gb = (GridButton) gw.getModel();
                    DoublePoint start = gb.getShape().getOrigin();
                    if (moveIsVertical) {
                        moveByX = 0.0;
                        if (currentScaledY < minY) {
                            moveByY = (minY - start.y);
                        } else {
                            moveByY = currentScaledY - scaledMouseDownY;
                        }
                    } else {
                        moveByY = 0.0;
                        if (currentScaledX < minX) {
                            moveByX = (minX - start.x);
                        } else {
                            moveByX = currentScaledX - scaledMouseDownX;
                        }
                    }
                    if ((moveByX != 0.0) || (moveByY != 0.0)) {
                        FrameEditorUI.MoveParameters prms = new FrameEditorUI.MoveParameters(moveByX, moveByY, selection, false);
                        ui.performAction(CogToolLID.MoveWidgets, prms);
                    }
                    break;
                }
        }
        // Clear the values used.
        lastClickedWidget = null;
        isMouseDownValid = false;
        setMouseState(MouseUp);
    }
    cleanup();
    return goForward;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) InteractionDrawingEditor(edu.cmu.cs.hcii.cogtool.view.InteractionDrawingEditor) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) MoveHalo(edu.cmu.cs.hcii.cogtool.view.MoveHalo) Iterator(java.util.Iterator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 3 with FrameEltGroupHalo

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

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

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

the class FrameEditorMouseState method dynamicResizeWidgets.

/**
     * Utility to help with dynamic resize 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 dynamicResizeWidgets(Iterator<FrameEltSelnFig<?>> selectedWFs, double currentScaledX, double currentScaledY) {
    // an origin less then 0.0,0.0
    if (currentScaledX < 0.0) {
        currentScaledX = 0.0;
    }
    if (currentScaledY < 0.0) {
        currentScaledY = 0.0;
    }
    // Deal with any anchoring issues
    if (ui.resizeHandlesUIFig.isTopLeftAnchored()) {
        switch(currentResizeHandleType) {
            case FrameEditorUI.TOP_RIGHT:
                {
                    // Cannot change Y position
                    currentScaledY = initialResizeArea.y;
                    break;
                }
            case FrameEditorUI.BOTTOM_LEFT:
                {
                    // Cannot change X position
                    currentScaledX = initialResizeArea.x;
                    break;
                }
            default:
                {
                    break;
                }
        }
        // Cannot move left of top-left
        if (currentScaledX < initialResizeArea.x) {
            currentScaledX = initialResizeArea.x;
        }
        // Cannot move above of top-left
        if (currentScaledY < initialResizeArea.y) {
            currentScaledY = initialResizeArea.y;
        }
    }
    double newWidth = Math.abs(currentScaledX - mouseFixedResizeX);
    double newHeight = Math.abs(currentScaledY - mouseFixedResizeY);
    double newLeft = Math.min(currentScaledX, mouseFixedResizeX);
    double newTop = Math.min(currentScaledY, mouseFixedResizeY);
    double ratioX = newWidth / initialResizeArea.width;
    double ratioY = newHeight / initialResizeArea.height;
    // Iterate through selected widgets
    while (selectedWFs.hasNext()) {
        FrameEltSelnFig<?> f = selectedWFs.next();
        if (f instanceof GraphicalWidget<?>) {
            GraphicalWidget<?> gw = (GraphicalWidget<?>) f;
            IWidget w = gw.getModel();
            SimpleWidgetGroup group = w.getParentGroup();
            if ((w instanceof TraversableWidget) && (group != null)) {
                dynamicResizeGroup(group, ratioX, ratioY, newLeft, newTop, false);
            } else {
                dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
            }
        } else if (f instanceof FrameEltGroupHalo) {
            dynamicResizeGroup(((FrameEltGroupHalo) f).getModel(), ratioX, ratioY, newLeft, newTop, true);
        }
    }
}
Also used : TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)6 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)4 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)4 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)3 FrameEltSelnFig (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig)3 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)3 MoveHalo (edu.cmu.cs.hcii.cogtool.view.MoveHalo)3 Iterator (java.util.Iterator)3 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)2 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)2 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)2 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)1 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)1 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)1 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)1 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)1 InteractionDrawingEditor (edu.cmu.cs.hcii.cogtool.view.InteractionDrawingEditor)1