Search in sources :

Example 11 with AParentWidget

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

the class FrameEditorController method resizeWidget.

/**
     * Implementation on a per widget bases for resize.
     * Calculates the new size be the difference between the fixed point and the
     * released point.
     *
     * @param widget The widget to resize
     * @param mouseReleased The point where the mouse was let up
     * @param fixedPoint The point which will not move after resize
     * @param edit The Compound undoable edit
     */
private void resizeWidget(final IWidget widget, double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, final double ratioX, final double ratioY, final boolean childrenToo, IUndoableEditSequence editSequence) {
    // Get the old shape bounds for the undo
    DoubleRectangle oldBounds = widget.getEltBounds();
    final double oldWidgetX = oldBounds.x;
    final double oldWidgetY = oldBounds.y;
    final double oldWidth = oldBounds.width;
    final double oldHeight = oldBounds.height;
    final double newWidgetX = ratioX * (oldBounds.x - oldResizeX) + newResizeX;
    final double newWidgetY = ratioY * (oldBounds.y - oldResizeY) + newResizeY;
    final double newWidth = Math.max(ratioX * oldBounds.width, 1.0);
    final double newHeight = Math.max(ratioY * oldBounds.height, 1.0);
    final double oldHoriz = (widget instanceof GridButton) ? ((GridButton) widget).getHorizSpace() : 0.0;
    final double oldVert = (widget instanceof GridButton) ? ((GridButton) widget).getVertSpace() : 0.0;
    // Actually make the changes to the model.
    widget.setWidgetOrigin(newWidgetX, newWidgetY);
    widget.setWidgetSize(newWidth, newHeight);
    if (widget instanceof GridButton) {
        GridButton gb = (GridButton) widget;
        gb.setHorizSpace(oldHoriz * ratioX);
        gb.setVertSpace(oldVert * ratioY);
    } else if (widget instanceof AParentWidget) {
        if (childrenToo) {
            resizeChildren(widget);
        }
        DesignEditorCmd.repositionChildren((AParentWidget) widget);
    }
    // Add the undo support
    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ResizeWidgets, demoStateMgr) {

        @Override
        public String getPresentationName() {
            return RESIZE_WIDGET;
        }

        @Override
        public void redo() {
            super.redo();
            widget.setWidgetOrigin(newWidgetX, newWidgetY);
            widget.setWidgetSize(newWidth, newHeight);
            if (widget instanceof GridButton) {
                GridButton gb = (GridButton) widget;
                gb.setHorizSpace(oldHoriz * ratioX);
                gb.setVertSpace(oldVert * ratioY);
            } else if (widget instanceof AParentWidget) {
                if (childrenToo) {
                    resizeChildren(widget);
                }
                DesignEditorCmd.repositionChildren((AParentWidget) widget);
            }
            noteEditCheckRegenerate(widget, this);
        }

        @Override
        public void undo() {
            super.undo();
            widget.setWidgetOrigin(oldWidgetX, oldWidgetY);
            widget.setWidgetSize(oldWidth, oldHeight);
            if (widget instanceof GridButton) {
                GridButton gb = (GridButton) widget;
                gb.setHorizSpace(oldHoriz);
                gb.setVertSpace(oldVert);
            } else if (widget instanceof AParentWidget) {
                if (childrenToo) {
                    // technically, this won't restore the sizes if they were changed manuallythes
                    resizeChildren(widget);
                }
                DesignEditorCmd.repositionChildren((AParentWidget) widget);
            }
            noteEditCheckRegenerate(widget, this);
        }
    };
    noteEditCheckRegenerate(widget, edit);
    editSequence.addEdit(edit);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)

Example 12 with AParentWidget

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

the class FrameEditorController method renderGroup.

private void renderGroup(SimpleWidgetGroup group, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
    Iterator<IWidget> children = group.iterator();
    while (children.hasNext()) {
        IWidget w = children.next();
        if (w instanceof AParentWidget) {
            renderChildren((AParentWidget) w, rendered, oldRendered, edit);
        }
        renderWidget(w, rendered, oldRendered, edit);
    }
}
Also used : AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 13 with AParentWidget

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

the class GraphicalMenuItem method getParentFigure.

@SuppressWarnings("unchecked")
public GraphicalParentWidget<AMenuWidget, MenuItem> getParentFigure() {
    MenuItem menuWidget = getModel();
    AParentWidget parent = menuWidget.getParent();
    return (GraphicalMenuWidget<AMenuWidget>) figureSpt.getWidgetFigure(parent);
}
Also used : MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget)

Example 14 with AParentWidget

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

the class AbstractGraphicalParentWidget method setChildrenVisible.

public void setChildrenVisible(boolean visible) {
    AParentWidget parentWidget = model;
    int numChildren = parentWidget.itemCount();
    for (int i = 0; i < numChildren; i++) {
        GraphicalWidget<?> gw = this.figureSpt.getWidgetFigure(parentWidget.getItem(i));
        if (gw != null) {
            gw.setVisible(visible);
            IFigure parent = gw.getParent();
            if (visible && (parent != null)) {
                parent.add(gw, gw.getBounds(), -1);
            }
        }
    }
}
Also used : AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IFigure(org.eclipse.draw2d.IFigure)

Example 15 with AParentWidget

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

the class AbstractGraphicalParentWidget method getFigureAt.

@SuppressWarnings("unchecked")
public GraphicalChildWidget<P, C> getFigureAt(int index) {
    AParentWidget parentWidget = model;
    ChildWidget child = parentWidget.getItem(index);
    if (child == null) {
        return null;
    }
    return (GraphicalChildWidget<P, C>) this.figureSpt.getWidgetFigure(child);
}
Also used : AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

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