Search in sources :

Example 11 with DoubleSize

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

the class FrameEditorController method insertDuplicateWidget.

/**
     * If group or parent is non-null, duplicate the widget within the given
     * group.  If they are both null, the widget was dragged to empty space, so
     * give it a new group.
     */
private boolean insertDuplicateWidget(IWidget widget, SimpleWidgetGroup group, int index, AParentWidget parent, double moveByX, double moveByY) {
    Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
    double startPosX = 0.0;
    double startPosY = 0.0;
    DoubleSize newSize;
    if (parent != null) {
        newSize = getNewWidgetSize(parent);
        newSize.height *= getHeightFactor(widget, parent.getChildren());
    } else if ((group == null) || (group.size() == 0)) {
        newSize = widget.getShape().getSize();
    } else {
        DoublePoint startPos = group.get(0).getShape().getOrigin();
        startPosX = startPos.x;
        startPosY = startPos.y;
        newSize = group.get(0).getShape().getSize();
        if (widget instanceof ListItem) {
            newSize.height *= getHeightFactor(widget, group);
        }
    }
    widgetSituator.reset(widgetCopies, null);
    IWidget newWidget = null;
    if (parent != null) {
        if (widget instanceof ChildWidget) {
            newWidget = ((ChildWidget) widget).duplicate(parent, lookupFrameDuplicator, widgetSituator, index);
            newWidget.setWidgetSize(newSize.width, newSize.height);
            if (newWidget instanceof AParentWidget) {
                resizeChildren(newWidget);
                DesignEditorCmd.repositionChildren((AParentWidget) newWidget);
            }
            DesignEditorCmd.repositionChildren(parent);
        }
    } else if (group != null) {
        if (widget instanceof MenuHeader) {
            newWidget = ((MenuHeader) widget).duplicate(group, lookupFrameDuplicator, widgetSituator, index);
        } else if (widget instanceof ListItem) {
            newWidget = ((ListItem) widget).duplicate(group, lookupFrameDuplicator, index);
        }
        newWidget.setWidgetSize(newSize.width, newSize.height);
        resizeChildren(newWidget);
        widgetSituator.placeInContext(widget, newWidget);
        DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
    } else {
        // Duplicating into space
        if ((widget instanceof MenuHeader) || (widget instanceof ListItem)) {
            SimpleWidgetGroup newGroup = null;
            if (widget instanceof MenuHeader) {
                newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
                newWidget = ((MenuHeader) widget).duplicate(newGroup, lookupFrameDuplicator, widgetSituator);
            } else {
                // (widget instanceof ListItem)
                newGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
                newWidget = ((ListItem) widget).duplicate(newGroup, lookupFrameDuplicator);
            }
            group = newGroup;
            widgetSituator.placeInContext(widget, newWidget);
            newWidget.moveElement(moveByX, moveByY);
            group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(widget.isRendered()));
        }
    }
    widgetSituator.completeWork();
    Collection<IWidget> duplicateWidgets = widgetCopies.values();
    Iterator<IWidget> copies = duplicateWidgets.iterator();
    while (copies.hasNext()) {
        IWidget widgetCopy = copies.next();
        // Warning: it is important that each widget be added
        // to the frame *before* we make the next widget name
        // unique, or we can end up with non-unique names.
        makeWidgetNameUnique(widgetCopy);
        model.addWidget(widgetCopy);
    }
    SimpleWidgetGroup newGroup = (group != null) ? group : newWidget.getParentGroup();
    Object rendered = newGroup.getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
    boolean groupRendered = ((Boolean) rendered).booleanValue();
    boolean widgetRendered = widget.isRendered();
    if (groupRendered != widgetRendered) {
        newWidget.setRendered(groupRendered);
    }
    insertDuplicateEdit(newWidget, new ReadOnlyList<IWidget>(new ArrayList<IWidget>(duplicateWidgets)), group, index, parent, startPosX, startPosY, undoMgr);
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) ArrayList(java.util.ArrayList) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) LinkedHashMap(java.util.LinkedHashMap) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 12 with DoubleSize

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

the class FrameEditorController method reorderChildWidget.

private boolean reorderChildWidget(final ChildWidget widget, final SimpleWidgetGroup newGroup, final int newIndex, final AParentWidget newParent) {
    final SimpleWidgetGroup prevGroup = widget.getParentGroup();
    final int prevIndex = prevGroup.indexOf(widget);
    int index = newIndex;
    if (prevGroup == newGroup) {
        if (prevIndex < newIndex) {
            index--;
        }
        if (index == prevIndex) {
            return true;
        }
    }
    final AParentWidget prevParent = widget.getParent();
    DoubleSize prevSize = widget.getShape().getSize();
    final double prevWidth = prevSize.width;
    final double prevHeight = prevSize.height;
    DoubleSize newSize = getNewWidgetSize(newParent);
    final double newWidth = newSize.width;
    final double newHeight = newSize.height * getHeightFactor(widget, newGroup);
    final boolean widgetRendered = widget.isRendered();
    reorderChildWidget(widget, newWidth, newHeight, index, prevParent, newParent);
    Object rendered = widget.getParentGroup().getAttribute(WidgetAttributes.IS_RENDERED_ATTR);
    final boolean groupRendered = ((Boolean) rendered).booleanValue();
    if (widgetRendered != groupRendered) {
        widget.setRendered(groupRendered);
    }
    DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.Reorder, demoStateMgr) {

        private ChildWidget child = widget;

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

        @Override
        public void redo() {
            super.redo();
            int index = newIndex;
            if (prevGroup == newGroup) {
                if (prevIndex < newIndex) {
                    index--;
                }
            }
            reorderChildWidget(child, newWidth, newHeight, index, prevParent, newParent);
            if (widgetRendered != groupRendered) {
                widget.setRendered(groupRendered);
            }
            noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), this);
        }

        @Override
        public void undo() {
            super.undo();
            reorderChildWidget(child, prevWidth, prevHeight, prevIndex, newParent, prevParent);
            if (widgetRendered != groupRendered) {
                widget.setRendered(widgetRendered);
            }
            noteEditCheckRegenerate(newParent.getChildren(), prevParent.getChildren(), this);
        }
    };
    noteEditCheckRegenerate(prevParent.getChildren(), newParent.getChildren(), edit);
    undoMgr.addEdit(edit);
    if (CogToolPref.REGENERATE_AUTOMATICALLY.getBoolean()) {
        DemoScriptCmd.regenerateDesignScripts(project, design, interaction);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 13 with DoubleSize

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

the class FrameEditorController method resizeChildren.

private void resizeChildren(IWidget widget) {
    if (widget instanceof AParentWidget) {
        AParentWidget parent = (AParentWidget) widget;
        DoubleSize size = parent.getShape().getSize();
        if (parent instanceof MenuHeader) {
            size.width *= FrameEditorUI.MENU_ITEM_RATIO;
        }
        int numItems = parent.itemCount();
        for (int i = 0; i < numItems; i++) {
            ChildWidget child = parent.getItem(i);
            double h = size.height;
            Object isSep = child.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
            if (NullSafe.equals(WidgetAttributes.IS_SEPARATOR, isSep)) {
                h /= FrameEditorUI.SEPARATOR_RATIO;
            }
            child.setWidgetSize(size.width, h);
            resizeChildren(child);
        }
    }
}
Also used : MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 14 with DoubleSize

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

the class DesignEditorCmd method getFirstChildPosition.

private static DoublePoint getFirstChildPosition(AParentWidget parent) {
    AShape parentShape = parent.getShape();
    DoublePoint pos = parentShape.getOrigin();
    DoubleSize extent = parentShape.getSize();
    switch(parent.getChildrenLocation()) {
        case AParentWidget.CHILDREN_BELOW:
            {
                pos.y += extent.height;
                break;
            }
        case AParentWidget.CHILDREN_RIGHT:
            {
                pos.x += extent.width;
                break;
            }
        case AParentWidget.CHILDREN_CENTER:
            {
                pos.x += extent.width / 2.0;
                pos.y += extent.height / 2.0;
                break;
            }
    }
    return pos;
}
Also used : DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AShape(edu.cmu.cs.hcii.cogtool.model.AShape) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Example 15 with DoubleSize

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

the class SEFrameChooserUI method resetVisibleArea.

// ctor
@Override
public void resetVisibleArea() {
    StandardDrawingEditor e = view.getEditor();
    e.getLWS().getUpdateManager().performUpdate();
    DoubleSize extent = structureView.getPreferredSize();
    e.setMinVisibleArea(PrecisionUtilities.round(extent.width), PrecisionUtilities.round(extent.height), false);
}
Also used : StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) DoubleSize(edu.cmu.cs.hcii.cogtool.model.DoubleSize)

Aggregations

DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)17 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)4 StandardDrawingEditor (edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)3 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)3 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)3 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 ScalableFrameFigure (edu.cmu.cs.hcii.cogtool.view.ScalableFrameFigure)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 XYLayout (org.eclipse.draw2d.XYLayout)2 Image (org.eclipse.swt.graphics.Image)2 CogToolWorkThread (edu.cmu.cs.hcii.cogtool.CogToolWorkThread)1 AShape (edu.cmu.cs.hcii.cogtool.model.AShape)1 FrameUIModel (edu.cmu.cs.hcii.cogtool.uimodel.FrameUIModel)1 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)1 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)1