Search in sources :

Example 21 with AParentWidget

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

the class DesignEditorCmd method addWidgetUndoableEdit.

public static IDesignUndoableEdit addWidgetUndoableEdit(Frame frame, IWidget widget, DemoStateManager mgr) {
    if (widget instanceof ChildWidget) {
        ChildWidget childWidget = (ChildWidget) widget;
        final AParentWidget itemParent = childWidget.getParent();
        final int atIndex = itemParent.indexOf(childWidget);
        return new AddWidgetUndoableEdit(frame, widget, mgr) {

            @Override
            protected void redoHelper() {
                itemParent.addItem(atIndex, (ChildWidget) widget);
            }

            @Override
            protected void undoHelper() {
                itemParent.removeItem((ChildWidget) widget);
            }
        };
    }
    final SimpleWidgetGroup parentGroup = widget.getParentGroup();
    final int atIndex = (parentGroup != null) ? parentGroup.indexOf(widget) : -1;
    return new AddWidgetUndoableEdit(frame, widget, mgr) {

        @Override
        protected void redoHelper() {
            if (parentGroup != null) {
                parentGroup.add(atIndex, widget);
            // TODO:mlh reposition items/headers following!
            }
        }

        @Override
        protected void undoHelper() {
            if (parentGroup != null) {
                parentGroup.remove(widget);
            // TODO:mlh reposition items/headers following!
            }
        }
    };
}
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)

Example 22 with AParentWidget

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

the class DesignEditorCmd method repositionChildren.

/**
     * TODO: If we ever allow children above or left of a parent,
     * we need to pass in childrenLocation here in addition to the group.
     */
public static void repositionChildren(SimpleWidgetGroup group, double x, double y) {
    int orientation = group.getOrientation();
    if (orientation == SimpleWidgetGroup.FREEFORM) {
        return;
    }
    Iterator<IWidget> groupIter = group.iterator();
    while (groupIter.hasNext()) {
        IWidget widget = groupIter.next();
        widget.setWidgetOrigin(x, y);
        if (orientation == SimpleWidgetGroup.HORIZONTAL) {
            x += widget.getEltBounds().width;
        } else if (orientation == SimpleWidgetGroup.VERTICAL) {
            y += widget.getEltBounds().height;
        }
        if (widget instanceof AParentWidget) {
            repositionChildren((AParentWidget) widget);
        }
    }
}
Also used : AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 23 with AParentWidget

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

the class DesignEditorCmd method pasteWidget.

private static int pasteWidget(IWidget widget, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSequence, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
    if (frame.getWidgets().contains(widget)) {
        return 0;
    }
    int requiresOneOf = widget.getWidgetType().requiresOneOf();
    if (!DeviceType.intersects(requiresOneOf, currentDeviceTypes)) {
        // Missing either Mouse or Touchscreen
        if (DeviceType.Touchscreen.isMember(requiresOneOf)) {
            DesignCmd.addDevice(design, DeviceType.Touchscreen);
        } else if (DeviceType.Mouse.isMember(requiresOneOf)) {
            DesignCmd.addDevice(design, DeviceType.Mouse);
        }
    }
    makeWidgetNameUnique(widget, frame);
    frame.addWidget(widget);
    IDesignUndoableEdit edit = addWidgetUndoableEdit(frame, widget, mgr);
    mgr.noteWidgetEdit(widget, edit);
    editSequence.addEdit(edit);
    if (widget instanceof AParentWidget) {
        AParentWidget parent = (AParentWidget) widget;
        addChildWidgets(frame, parent.getChildren(), mgr, editSequence);
    }
    groups.addAll(widget.getEltGroups());
    checkForRemoteLabel(widget, addedRemoteLabels);
    return 1;
}
Also used : IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

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