Search in sources :

Example 41 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class FrameEditorMouseState method getInsertIndex.

protected int getInsertIndex(IWidget widgetModel, int x, int y) {
    double zoom = ui.getZoom();
    DoubleRectangle widgetBds = widgetModel.getEltBounds();
    double centerX = widgetBds.x + (widgetBds.width / 2);
    double centerY = widgetBds.y + (widgetBds.height / 2);
    int originX = PrecisionUtilities.round(centerX * zoom);
    int originY = PrecisionUtilities.round(centerY * zoom);
    SimpleWidgetGroup group = widgetModel.getParentGroup();
    int index = 0;
    if (group != null) {
        index = group.indexOf(widgetModel);
        switch(group.getOrientation()) {
            case SimpleWidgetGroup.HORIZONTAL:
                {
                    if (x > originX) {
                        index++;
                    }
                    break;
                }
            case SimpleWidgetGroup.VERTICAL:
                {
                    if (y > originY) {
                        index++;
                    }
                    break;
                }
            default:
                {
                    index++;
                }
        }
    }
    return index;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 42 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup 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 43 with SimpleWidgetGroup

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

Example 44 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class FrameEditorSelectionState method getSelectedWidgetsParent.

/**
     * If all of the selected items are widgets with the same
     * parent SimpleWidgetGroup, return that parent group.
     */
public SimpleWidgetGroup getSelectedWidgetsParent() {
    SimpleWidgetGroup parentGroup = null;
    Iterator<FrameElement> selectedElts = selectedElements.keySet().iterator();
    while (selectedElts.hasNext()) {
        FrameElement elt = selectedElts.next();
        if (elt instanceof IWidget) {
            SimpleWidgetGroup g = ((IWidget) elt).getParentGroup();
            // Can't share a parent if one is null
            if (g == null) {
                return null;
            }
            // If no parent recorded yet, keep track
            if (parentGroup == null) {
                parentGroup = g;
            } else if (parentGroup != g) {
                // if parents don't match, done
                return null;
            }
        } else {
            // Can't share a parent if not all selected elts are widgets
            return null;
        }
    }
    return parentGroup;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 45 with SimpleWidgetGroup

use of edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup in project cogtool by cogtool.

the class FrameEditorUI method getSelectedWidgetArea.

public DoubleRectangle getSelectedWidgetArea() {
    DoubleRectangle r = null;
    Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
    while (selectedElts.hasNext()) {
        FrameElement elt = selectedElts.next();
        DoubleRectangle bds = null;
        if (elt instanceof IWidget) {
            IWidget w = (IWidget) elt;
            SimpleWidgetGroup wg = w.getParentGroup();
            bds = (wg != null) ? wg.getGroupBounds() : w.getEltBounds();
        } else if (elt instanceof FrameElementGroup) {
            bds = ((FrameElementGroup) elt).getGroupBounds();
        }
        if (bds != null) {
            if (r == null) {
                r = new DoubleRectangle(bds);
            } else {
                r = r.union(bds);
            }
        }
    }
    return r;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)45 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)32 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)16 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)14 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)13 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)10 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 HashSet (java.util.HashSet)8 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)7 Point (org.eclipse.draw2d.geometry.Point)7 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)6 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)6 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)6 Iterator (java.util.Iterator)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)4 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)4 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)4 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)4