Search in sources :

Example 1 with GraphicalParentWidget

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

the class FrameEditorUI method confirmRenameFigure.

protected void confirmRenameFigure() {
    if ((editor != null) && editor.inUse()) {
        String newTitle = editor.getText();
        editor.cleanup();
        // figure whose title is currently being edited
        IFigure figure = (IFigure) editor.getData();
        if (figure instanceof PotentialFigure) {
            if ("".equals(newTitle)) {
                // nothing to do if empty string on potential item!
                return;
            }
            GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
            TraversableWidget parentModel = (TraversableWidget) parent.getModel();
            boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
            WidgetType type = null;
            AParentWidget header = null;
            SimpleWidgetGroup group = null;
            boolean isSeparator = false;
            if (parentModel instanceof MenuItem) {
                type = WidgetType.MenuItem;
                MenuItem parentItem = (MenuItem) parentModel;
                if (isRightPotentialFigure) {
                    // position of selected figure is on the right
                    // parent menuitem becomes a submenu; figure to be
                    // created becomes a child of the submenu
                    parentItem.setSubmenu(true);
                    header = parentItem;
                } else {
                    // if position is on the bottom and the parent is not a
                    // header, put the new widget in the same menu as the
                    // parent item
                    header = parentItem.getParent();
                    // previous item should hide children if it's a submenu
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                }
                if (parentModel.getWidgetType() != WidgetType.Submenu) {
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ContextMenu) {
                header = (ContextMenu) parentModel;
                type = WidgetType.MenuItem;
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof MenuHeader) {
                // and hide children of the previous header
                if (isRightPotentialFigure) {
                    type = WidgetType.Menu;
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                    group = parentModel.getParentGroup();
                } else {
                    header = (MenuHeader) parentModel;
                    type = WidgetType.MenuItem;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownItem) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    PullDownItem parentItem = (PullDownItem) parentModel;
                    header = parentItem.getParent();
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownHeader) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    header = (PullDownHeader) parentModel;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ListItem) {
                type = WidgetType.ListBoxItem;
                group = parentModel.getParentGroup();
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof GridButton) {
                type = parentModel.getWidgetType();
                group = parentModel.getParentGroup();
            }
            Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
            DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
            performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
        } else {
            boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) GraphicalMenuHeader(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuHeader) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) GraphicalContextMenu(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalContextMenu) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with GraphicalParentWidget

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

the class FrameEditorMouseState method reorderWidget.

protected boolean reorderWidget(int x, int y, FrameEditorUI.ReorderWidgetParameters prms) {
    GraphicalWidget<?> wf = ui.widgetLocatedAtXY(x, y);
    if ((wf == null) && withinReorder(x, y)) {
        wf = lastHoveredWidget;
    }
    prms.widgetGroup = null;
    prms.insertIndex = -1;
    prms.parent = null;
    prms.reorderWidget = lastClickedWidget;
    if (wf != null) {
        IWidget targetWidget = wf.getModel();
        if (!ui.areCompatible(lastClickedWidget, targetWidget)) {
            return false;
        }
        if (!reorderAllowed(targetWidget)) {
            return false;
        }
        prms.insertIndex = getInsertIndex(targetWidget, x, y);
        if (prms.insertIndex < 0) {
            return false;
        }
        if (lastClickedWidget instanceof ChildWidget) {
            if (targetWidget instanceof ChildWidget) {
                prms.widgetGroup = targetWidget.getParentGroup();
                prms.parent = ((ChildWidget) targetWidget).getParent();
            } else if (targetWidget instanceof AParentWidget) {
                // "else if" because only MenuItems are both, and for them
                // we want the ChildWidget behavior (to add the item to
                // a submenu, drag it over the potential figure)
                prms.parent = (AParentWidget) targetWidget;
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
            }
        } else {
            // moving around menu headers or list items
            prms.widgetGroup = targetWidget.getParentGroup();
        }
        return true;
    }
    PotentialFigure pf = ui.potentialWidgetUnderXY(x, y);
    if (pf != null) {
        GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
        if (owner instanceof GraphicalMenuItem) {
            if (pf == ui.potentialUIFig.getRightFigure()) {
                prms.parent = (MenuItem) owner.getModel();
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
                return true;
            }
        } else {
            if ((owner instanceof GraphicalParentWidget<?, ?>) && (pf == ui.potentialUIFig.getBottomFigure())) {
                prms.parent = (AParentWidget) owner.getModel();
                prms.widgetGroup = prms.parent.getChildren();
                prms.insertIndex = 0;
            } else {
                IWidget widget = owner.getModel();
                prms.widgetGroup = widget.getParentGroup();
                prms.insertIndex = prms.widgetGroup.indexOf(widget) + 1;
            }
            return true;
        }
    }
    // out in space
    return ((!prms.requiresTarget()) && !(lastClickedWidget instanceof ChildWidget));
}
Also used : GraphicalMenuItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)

Example 3 with GraphicalParentWidget

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

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

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

GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)5 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)4 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)4 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)3 Point (org.eclipse.draw2d.geometry.Point)3 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalTraversableWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget)2 InteractionFigure (edu.cmu.cs.hcii.cogtool.view.InteractionFigure)2 IFigure (org.eclipse.draw2d.IFigure)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)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 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)1