Search in sources :

Example 6 with GridButton

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

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

the class FrameEditorController method moveGridButtonsEdit.

// moveWidgetGroup
private IDesignUndoableEdit moveGridButtonsEdit(ListenerIdentifier lid, final String presentationLabel, final ReadOnlyList<? extends GridButton> movedButtons, final double widgetMoveByX, final double widgetMoveByY, final double oldHoriz, final double oldVert, final double newHoriz, final double newVert, final GridButton gb) {
    final GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {

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

        @Override
        public void redo() {
            super.redo();
            for (int i = 0; i < movedButtons.size(); i++) {
                GridButton g = movedButtons.get(i);
                DoublePoint p = g.getShape().getOrigin();
                double tempX = Math.max(p.x + widgetMoveByX, 0.0);
                double tempY = Math.max(p.y + widgetMoveByY, 0.0);
                g.setWidgetOrigin(tempX, tempY);
            }
            if (widgetMoveByX == 0) {
                gb.setVertSpace(newVert);
            } else {
                List<GridButton> column = gbg.getColumn(gb);
                for (int i = 0; i < column.size(); i++) {
                    GridButton g = column.get(i);
                    g.setHorizSpace(newHoriz);
                }
            }
            noteEditCheckRegenerate(movedButtons, this);
        }

        @Override
        public void undo() {
            super.undo();
            for (int i = 0; i < movedButtons.size(); i++) {
                GridButton g = movedButtons.get(i);
                DoublePoint p = g.getShape().getOrigin();
                double tempX = Math.max(p.x - widgetMoveByX, 0.0);
                double tempY = Math.max(p.y - widgetMoveByY, 0.0);
                g.setWidgetOrigin(tempX, tempY);
            }
            if (widgetMoveByX == 0) {
                gb.setVertSpace(oldVert);
            } else {
                List<GridButton> column = gbg.getColumn(gb);
                for (int i = 0; i < column.size(); i++) {
                    GridButton g = column.get(i);
                    g.setHorizSpace(oldHoriz);
                }
            }
            noteEditCheckRegenerate(movedButtons, this);
        }
    };
    noteEditCheckRegenerate(movedButtons, edit);
    return edit;
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 8 with GridButton

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

the class FrameUIModel method getRightGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getRightGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultX = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX > startX)) {
            if ((result == null) || (curX < resultX)) {
                result = cur;
                resultX = curX;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 9 with GridButton

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

the class FrameUIModel method getTopGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getTopGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultY = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startX, curX, GridButtonGroup.PIXEL_EPSILON) && (curY < startY)) {
            if ((result == null) || (curY > resultY)) {
                result = cur;
                resultY = curY;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 10 with GridButton

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

the class FrameUIModel method getLeftGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getLeftGridFigure(GraphicalGridButton gridFig) {
    GridButton gb = gridFig.getModel();
    GridButtonGroup group = (GridButtonGroup) gb.getParentGroup();
    Iterator<IWidget> gbs = group.iterator();
    DoubleRectangle bds = gb.getEltBounds();
    double startX = bds.x;
    double startY = bds.y;
    IWidget result = null;
    double resultX = 0.0;
    while (gbs.hasNext()) {
        IWidget cur = gbs.next();
        if (cur == gb) {
            continue;
        }
        bds = cur.getEltBounds();
        double curX = bds.x;
        double curY = bds.y;
        if (PrecisionUtilities.withinEpsilon(startY, curY, GridButtonGroup.PIXEL_EPSILON) && (curX < startX)) {
            if ((result == null) || (curX > resultX)) {
                result = cur;
                resultX = curX;
            }
        }
    }
    return (GraphicalWidget<GridButton>) getWidgetFigure(result);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Aggregations

GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)14 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)7 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)3 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)2 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 Iterator (java.util.Iterator)2 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)1 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)1 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1