Search in sources :

Example 1 with AParentWidget

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

the class AbstractGraphicalParentWidget method selectChild.

protected GraphicalWidget<?> selectChild() {
    AParentWidget hdr = getModel();
    SimpleWidgetGroup childItems = hdr.getChildren();
    if ((childItems != null) && (childItems.size() > 0)) {
        return this.figureSpt.getWidgetFigure(childItems.get(0));
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget)

Example 2 with AParentWidget

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

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

the class FrameEditorMouseState method dynamicResizeGroup.

protected void dynamicResizeGroup(Association<?> group, double ratioX, double ratioY, double newLeft, double newTop, boolean childrenToo) {
    Iterator<? extends FrameElement> groupElts = group.iterator();
    while (groupElts.hasNext()) {
        FrameElement elt = groupElts.next();
        if (elt instanceof IWidget) {
            IWidget w = (IWidget) elt;
            GraphicalWidget<?> gw = ui.frameUI.getWidgetFigure(w);
            dynamicResizeWidget(w, gw, ratioX, ratioY, newLeft, newTop);
            if (childrenToo && (w instanceof AParentWidget)) {
                AParentWidget pw = (AParentWidget) w;
                SimpleWidgetGroup children = pw.getChildren();
                if (children != null) {
                    dynamicResizeGroup(children, ratioX, ratioY, newLeft, newTop, childrenToo);
                }
            }
        } else if (elt instanceof Association<?>) {
            dynamicResizeGroup((Association<?>) elt, ratioX, ratioY, newLeft, newTop, childrenToo);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) Association(edu.cmu.cs.hcii.cogtool.model.Association) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 4 with AParentWidget

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

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

the class FrameEditorMouseState method setDividerBounds.

// dynamicMoveWidgets
protected void setDividerBounds(GraphicalWidget<?> widget, int x, int y) {
    double zoom = ui.getZoom();
    Rectangle bounds = widget.getBounds();
    int originX = bounds.x + (bounds.width / 2);
    int originY = bounds.y + (bounds.height / 2);
    originX = PrecisionUtilities.round(originX * zoom);
    originY = PrecisionUtilities.round(originY * zoom);
    double newX = bounds.x;
    double newY = bounds.y;
    double newH = bounds.height;
    double newW = bounds.width;
    int heightInc = 0;
    int widthInc = 0;
    if ((lastClickedWidget instanceof ChildWidget) && (widget instanceof GraphicalParentWidget<?, ?>) && (!(widget instanceof GraphicalMenuItem))) {
        AParentWidget parent = (AParentWidget) widget.getModel();
        int childrenLoc = parent.getChildrenLocation();
        switch(childrenLoc) {
            case AParentWidget.CHILDREN_BELOW:
            case AParentWidget.CHILDREN_CENTER:
                {
                    if (childrenLoc == AParentWidget.CHILDREN_CENTER) {
                        newX += newW / 2.0;
                        newY += newH / 2.0;
                    } else {
                        newY += newH;
                    }
                    if (parent.hasChildren()) {
                        IWidget child = parent.getItem(0);
                        DoubleSize childSize = child.getShape().getSize();
                        newW = childSize.width;
                        newH = childSize.height;
                        Object value = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
                        if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value)) {
                            newH *= FrameEditorUI.SEPARATOR_RATIO;
                        }
                    } else if (parent instanceof MenuHeader) {
                        newW *= FrameEditorUI.MENU_ITEM_RATIO;
                    }
                    newH /= 10.0;
                    newY -= newH / 2.0;
                    heightInc = 1;
                    break;
                }
            case AParentWidget.CHILDREN_RIGHT:
                {
                    newX += newW;
                    if (parent.hasChildren()) {
                        DoubleSize childSize = parent.getItem(0).getShape().getSize();
                        newW = childSize.width;
                        newH = childSize.height;
                    }
                    newW /= 20.0;
                    newX -= newW / 2.0;
                    widthInc = 1;
                    break;
                }
        }
    } else {
        switch(widget.getModel().getParentGroup().getOrientation()) {
            case SimpleWidgetGroup.HORIZONTAL:
                {
                    if (x > originX) {
                        newX += newW;
                    }
                    newW /= 20.0;
                    newX -= newW / 2.0;
                    widthInc = 1;
                    break;
                }
            case SimpleWidgetGroup.VERTICAL:
                {
                    if (y > originY) {
                        newY += newH;
                    }
                    newH /= 10.0;
                    Object value = widget.getModel().getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
                    if (WidgetAttributes.IS_SEPARATOR.equals(value)) {
                        newH *= FrameEditorUI.SEPARATOR_RATIO;
                    }
                    newY -= newH / 2.0;
                    heightInc = 1;
                    break;
                }
        }
    }
    newX *= zoom;
    newY *= zoom;
    double rightX = newX + (newW + widthInc) * zoom;
    double bottomY = newY + (newH + heightInc) * zoom;
    newW = PrecisionUtilities.round(rightX - newX);
    newH = PrecisionUtilities.round(bottomY - newY);
    newX = PrecisionUtilities.round(newX);
    newY = PrecisionUtilities.round(newY);
    dividerLine.setBounds(new Rectangle((int) newX, (int) newY, (int) newW, (int) newH));
    dividerLine.setVisible(true);
}
Also used : GraphicalMenuItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Aggregations

AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)23 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)11 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)11 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)4 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)4 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)4 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)3 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)3 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)2 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2