Search in sources :

Example 1 with ChildWidget

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

the class FrameEditorSelectionState method getNonchildSelectionCount.

/**
     * Get the number of selected non-IChildWidget elements
     */
public int getNonchildSelectionCount() {
    int nonchildCount = 0;
    Iterator<FrameElement> allSelectedElements = getSelectedElementsIterator();
    while (allSelectedElements.hasNext()) {
        FrameElement w = allSelectedElements.next();
        if (!(w instanceof ChildWidget)) {
            nonchildCount++;
        }
    }
    return nonchildCount;
}
Also used : FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 2 with ChildWidget

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

the class FrameEditorMouseState method reorderAllowed.

protected boolean reorderAllowed(IWidget targetWidget) {
    // Ensure the targetWidget is not a child of the last clicked widget
    while (targetWidget instanceof ChildWidget) {
        IWidget parent = ((ChildWidget) targetWidget).getParent();
        if (parent == lastClickedWidget) {
            return false;
        }
        targetWidget = parent;
    }
    return true;
}
Also used : GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 3 with ChildWidget

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

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

Example 5 with ChildWidget

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

the class FrameEditorController method createSetRenderSkinAction.

private IListenerAction createSetRenderSkinAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.SetRenderSkinParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
            // Iterate through selected objects.
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
            while (selected.hasNext()) {
                IWidget w = selected.next();
                if (w instanceof TraversableWidget) {
                    AParentWidget parent = null;
                    if (w instanceof MenuItem) {
                        parent = ((MenuItem) w).getTopHeader();
                        if (parent == null) {
                            // parent is a context menu
                            parent = ((MenuItem) w).getParent();
                        }
                    } else if (w instanceof ChildWidget) {
                        parent = ((ChildWidget) w).getParent();
                    } else if (w instanceof AParentWidget) {
                        parent = (AParentWidget) w;
                    }
                    if (parent != null) {
                        SimpleWidgetGroup group = parent.getParentGroup();
                        if (group != null) {
                            //menu header
                            renderGroup(group, p.rendered, parent.isRendered(), editSeq);
                        } else {
                            //pull down header
                            renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
                            renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
                        }
                    } else if (w.getParentGroup() != null) {
                        //list box item or radio button
                        renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
                    }
                } else {
                    renderWidget(w, p.rendered, w.isRendered(), editSeq);
                }
            }
            editSeq.end();
            // Only add this edit if it is significant
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)18 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)8 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)7 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)4 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)4 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)4 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)3 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)2 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)2 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)2 IOException (java.io.IOException)2 Point (org.eclipse.draw2d.geometry.Point)2