Search in sources :

Example 1 with ResizeThumb

use of edu.cmu.cs.hcii.cogtool.view.ResizeThumb in project cogtool by cogtool.

the class DesignEditorTransition method setSelected.

/**
     * This exists because the editor doesn't when most DesignEditorTransition
     * instances are created!
     */
public void setSelected(InteractionDrawingEditor editor, boolean selected) {
    if (selected) {
        sourceHandle = new ResizeThumb(SOURCE);
        targetHandle = new ResizeThumb(TARGET);
        sourceHandle.setData(this);
        targetHandle.setData(this);
        setLineWidth(2);
        editor.addInteractionFigure(sourceHandle);
        editor.addInteractionFigure(targetHandle);
    } else {
        editor.removeInteractionFigure(sourceHandle);
        editor.removeInteractionFigure(targetHandle);
        sourceHandle.dispose();
        targetHandle.dispose();
        sourceHandle = null;
        targetHandle = null;
        setLineWidth(1);
    }
    repaintSelection(editor);
}
Also used : ResizeThumb(edu.cmu.cs.hcii.cogtool.view.ResizeThumb)

Example 2 with ResizeThumb

use of edu.cmu.cs.hcii.cogtool.view.ResizeThumb 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 3 with ResizeThumb

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

Aggregations

ResizeThumb (edu.cmu.cs.hcii.cogtool.view.ResizeThumb)3 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)1 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)1 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)1 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)1 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)1 DesignEditorFrame (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorFrame)1 DesignEditorTransition (edu.cmu.cs.hcii.cogtool.uimodel.DesignEditorTransition)1 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)1 FrameEltSelnFig (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig)1 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)1 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)1 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)1 GraphicalSource (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalSource)1 MoveHalo (edu.cmu.cs.hcii.cogtool.view.MoveHalo)1 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)1 RadioButtonSash (edu.cmu.cs.hcii.cogtool.view.RadioButtonSash)1 RemoteLinkage (edu.cmu.cs.hcii.cogtool.view.RemoteLinkage)1 IFigure (org.eclipse.draw2d.IFigure)1 Point (org.eclipse.draw2d.geometry.Point)1