Search in sources :

Example 1 with GridButtonGroup

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

the class FrameUIModel method getBottomGridFigure.

@SuppressWarnings("unchecked")
public GraphicalWidget<GridButton> getBottomGridFigure(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 2 with GridButtonGroup

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

the class FrameEditorMouseState method dealWithMouseDragged.

/**
     * Parameterized mouse drags so they can be scaled programatically.
     *
     * Handles mouse drags: moves the viewable area as needed
     *
     * @param figure ignored
     * @param mouseX the location the mouse is pointing to
     * @param mouseY the location the mouse is pointing to
     * @param button the buttons pressed
     * @param state the modifiers being held down
     */
@Override
protected boolean dealWithMouseDragged(IFigure figure, int button, int mouseX, int mouseY, int state) {
    boolean goForward = super.dealWithMouseDragged(figure, button, mouseX, mouseY, state);
    if (goForward && isMouseDownValid) {
        // Get the StandardEditor for handling visuals & scrolling
        StandardDrawingEditor editor = ui.getViewEditor();
        // Update VIEW to ensure mouse point is visible.
        // If outside of the visible canvas, up-click should cancel!
        stopMouseDragTimer = true;
        stopDynamic = editor.movePointNearEdge(mouseX, mouseY, updateDelta);
        double zoom = ui.getZoom();
        // The current mouse down position (scaled)
        double currentScaledX = mouseX / zoom;
        double currentScaledY = mouseY / zoom;
        Iterator<FrameEltSelnFig<?>> selectedEltFigs = selection.getSelectedFigures();
        InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
        // Else this is a new widget
        switch(getMouseState()) {
            // Perform move-related states
            case PotentialMovingWidget:
            case PotentialMovingSelection:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false);
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(SELECT_CURSOR);
                    setMouseState(MovingWidgets);
                // fall through!
                }
            case MovingWidgets:
                {
                    dynamicMoveWidgets(selectedEltFigs, currentScaledX, currentScaledY);
                    ui.repaintEditor();
                    break;
                }
            case PotentialReorderWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    prevCursor = drawLayer.getCursor();
                    ui.hideNondynamicSupport(false, false);
                    setUpReorderFigures();
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(SELECT_CURSOR);
                    setMouseState(ReorderWidget);
                // fall through!
                }
            case ReorderWidget:
                {
                    dynamicReorderWidget(mouseX, mouseY, false);
                    break;
                }
            case PotentialResizingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(true);
                    // Iterate through selected widgets XYZZY openChildren in a loop???
                    while (selectedEltFigs.hasNext()) {
                        FrameEltSelnFig<?> gw = selectedEltFigs.next();
                        if (gw instanceof GraphicalTraversableWidget<?>) {
                            if (gw instanceof GraphicalChildWidget<?, ?>) {
                                ((GraphicalChildWidget<?, ?>) gw).getParentFigure().openChildren();
                            }
                        }
                    }
                    setMouseState(ResizingWidget);
                // fall through!
                }
            // Perform a drag resize of selected widget
            case ResizingWidget:
                {
                    dynamicResizeWidgets(selectedEltFigs, currentScaledX, currentScaledY);
                    ui.repaintEditor();
                    break;
                }
            // Create a new widget
            case PotentialCreatingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    setMouseState(CreatingWidget);
                // fall through!
                }
            case CreatingWidget:
                {
                    redrawTemporaryWidget(currentScaledX, currentScaledY, false);
                    break;
                }
            // Sweeping a region for toggling selection
            case PotentialTogglingSelection:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    setMouseState(TogglingSelection);
                // fall through!
                }
            case TogglingSelection:
                {
                    redrawTemporaryWidget(currentScaledX, currentScaledY, true);
                    break;
                }
            case PotentialDuplicatingWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false, false);
                    duplicatingDynamic = new ArrayList<RectangleFigure>();
                    Iterator<FrameEltSelnFig<?>> selectedFigs = selection.getSelectedFigures();
                    while (selectedFigs.hasNext()) {
                        FrameEltSelnFig<?> currFig = selectedFigs.next();
                        if (currFig instanceof FrameEltGroupHalo) {
                            showSelectionArea(new RectangleFigure(), currFig.getBounds());
                        } else if (!(currFig instanceof GraphicalChildWidget<?, ?>)) {
                            Rectangle widgetBds = new Rectangle(currFig.getBounds());
                            // Must scale widget figure's bounds to zoom factor
                            widgetBds.height = PrecisionUtilities.round(widgetBds.height * zoom);
                            widgetBds.width = PrecisionUtilities.round(widgetBds.width * zoom);
                            widgetBds.x = PrecisionUtilities.round(widgetBds.x * zoom);
                            widgetBds.y = PrecisionUtilities.round(widgetBds.y * zoom);
                            //display the new rectangle object
                            showSelectionArea(new RectangleFigure(), widgetBds);
                        }
                    }
                    setMouseState(DuplicatingWidgets);
                // fall through!
                }
            case DuplicatingWidgets:
                {
                    updateDynamicDuplicate(mouseX, mouseY);
                    break;
                }
            case PotentialInsertDuplicateWidget:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    ui.hideNondynamicSupport(false, false);
                    prevCursor = drawLayer.getCursor();
                    setUpReorderFigures();
                    prevCursor = drawLayer.getCursor();
                    drawLayer.setCursor(DRAW_CURSOR);
                    setMouseState(InsertDuplicateWidget);
                // fall through!
                }
            case InsertDuplicateWidget:
                {
                    dynamicReorderWidget(mouseX, mouseY, true);
                    break;
                }
            case PotentialMovingGridButtons:
                {
                    if (withinHysteresis(mouseX, mouseY)) {
                        return true;
                    }
                    GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
                    GridButton owner = (GridButton) gw.getModel();
                    DoublePoint start = owner.getShape().getOrigin();
                    GridButtonGroup gbg = (GridButtonGroup) owner.getParentGroup();
                    movedGridButtons = gbg.getMovedButtons(moveIsVertical, start.x, start.y);
                    minX = start.x - owner.getHorizSpace();
                    minY = start.y - owner.getVertSpace();
                    prevCursor = drawLayer.getCursor();
                    if (moveIsVertical) {
                        drawLayer.setCursor(MOVE_VERT_CURSOR);
                    } else {
                        drawLayer.setCursor(MOVE_HORIZ_CURSOR);
                    }
                    setMouseState(MovingGridButtons);
                // fall through!
                }
            case MovingGridButtons:
                {
                    dynamicMoveGridButtons(currentScaledX, currentScaledY);
                    break;
                }
        }
        // Repeating timer for causing events to repeat.
        if ((updateDelta.x != 0) || (updateDelta.y != 0)) {
            if (rootFigure == null) {
                rootFigure = ui.getViewEditor().getInteractionFigure();
            }
            stopMouseDragTimer = false;
            // Determine the new point the mouse "moved" too.
            mouseDragTask.setNextMousePosition(mouseX + updateDelta.x, mouseY + updateDelta.y, button, state);
            // Queue the event for 0.1 sec.
            WindowUtil.GLOBAL_DISPLAY.timerExec(100, mouseDragTask);
        }
    }
    lastX = mouseX;
    lastY = mouseY;
    updateDynamic();
    return goForward;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) ArrayList(java.util.ArrayList) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) Rectangle(org.eclipse.draw2d.geometry.Rectangle) FrameEltSelnFig(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltSelnFig) FrameEltGroupHalo(edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo) GraphicalWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) StandardDrawingEditor(edu.cmu.cs.hcii.cogtool.view.StandardDrawingEditor) Iterator(java.util.Iterator) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 3 with GridButtonGroup

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

the class BalsamiqButtonAPIConverter method parseBMMLGroup.

// parseBMMLWidget
//TODO: probably need to give the group dimensions
/** Helper function used by parseFrame
	 * This method is used to parse the tags of each control tag in Balsamiq XML. A control tag
	 * represents a Balsamiq Group.
     * 
     * @param  node a node of the tree that represents a Balsamiq widget
     * @frame  frame that the widget is being added to
     * @group  parent group
     * @groupX x coordinate of parent group
     * @groupY y coordinate of parent group
     * @return      new group containing widgets
     */
public void parseBMMLGroup(Node groupXMLtag, Frame frame, SimpleWidgetGroup parentGroup, double initX, double initY) {
    SimpleWidgetGroup widgetGrp = null;
    NodeList groupSubtags = groupXMLtag.getChildNodes();
    String grpName = getAttributeValue(groupXMLtag, CONTROL_ID_ATTR);
    double x = Double.parseDouble(getAttributeValue(groupXMLtag, X_ATTR));
    double y = Double.parseDouble(getAttributeValue(groupXMLtag, Y_ATTR));
    x += initX;
    y += initY;
    if (grpName == null) {
    //TODO: report to the user
    }
    System.out.println("587-GROUP " + grpName);
    if ((grpName != null) && !"".equals(grpName)) {
        widgetGrp = groupRegistry.get(grpName);
        for (int i = 0; i < groupSubtags.getLength(); i++) {
            Node groupSubtag = groupSubtags.item(i);
            String groupSubtagName = groupSubtag.getNodeName();
            System.out.println("598-nodeName1 " + groupSubtagName);
            /*Whitespace in the DOM tree is represented as #text. Ignore these nodes*/
            if (!groupSubtagName.equals("#text")) {
                if (groupSubtagName.equalsIgnoreCase("groupChildrenDescriptors")) {
                    System.out.println("605-groupchildrendescriptors");
                    WidgetType groupType = checkWidgetGroupType(groupSubtag);
                    if (groupType != null) {
                        System.out.println("630-groupwidgetType " + groupType.getName());
                    } else {
                        System.out.println("groupwidgetType is null");
                    }
                    NodeList children2 = groupSubtag.getChildNodes();
                    for (int j = 0; j < children2.getLength(); j++) {
                        Node child3 = children2.item(j);
                        String nodeName3 = child3.getNodeName();
                        System.out.println("657- nodeName3 " + nodeName3 + " j is " + j + " length " + children2.getLength());
                        if (nodeName3.equalsIgnoreCase(CONTROL_ELT)) {
                            System.out.println("660-This is a control!");
                            Widget widget2 = null;
                            if (widgetGrp == null) {
                                if (groupType == WidgetType.Radio) {
                                    widgetGrp = new RadioButtonGroup();
                                } else if (groupType == WidgetType.Check) {
                                    System.out.println("654-grouptype is a check");
                                    widgetGrp = new GridButtonGroup();
                                } else {
                                    widgetGrp = new SimpleWidgetGroup(1);
                                }
                                widgetGrp.setName(grpName);
                                groupRegistry.put(grpName, widgetGrp);
                            }
                            try {
                                String balsamiqControlType = getAttributeValue(child3, CONTROL_TYPE_ATTR);
                                String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
                                System.out.println("663-widgetTypeString " + widgetTypeString);
                                if (widgetTypeString.equals("group")) {
                                    System.out.println("682-calling bmmlgroup");
                                    parseBMMLGroup(child3, frame, widgetGrp, x, y);
                                }
                                widget2 = parseBMMLWidget(child3, frame, widgetGrp, x, y);
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            int widgetCount = widgetGrp.elementCount();
                            System.out.println("692- WIDGET COUNT for " + grpName + ": " + widgetCount + " " + widget2.getName());
                            if (widget2 != null) {
                                //TODO: check widget does not need to be added here
                                //widgetGrp.addElement(widget2);
                                widget2.setParentGroup(widgetGrp);
                                //frame.addEltGroup(gridWidgetGrp);
                                frame.addWidget(widget2);
                                widgetLoader.set(widget2, Widget.widgetTypeVAR, widget2.getWidgetType());
                            //AShape widgetShape = widget2.getShapeType();
                            //if (widgetShape != null) {
                            // widgetLoader.set(widget2, Widget.shapeVAR, widgetShape);
                            // }
                            }
                            System.out.println("696-widget2 added");
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) RadioButtonGroup(edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup) IOException(java.io.IOException) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 4 with GridButtonGroup

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

the class FrameEditorController method createWidget.

private Widget createWidget(WidgetType defaultType, DoubleRectangle bounds, String widgetTitle, boolean isStandard) {
    Widget widget;
    // the user specified actual bounds interactively
    if (isStandard) {
        if (defaultType == WidgetType.Menu) {
            SimpleWidgetGroup newMenuHeaderGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
            widget = new MenuHeader(newMenuHeaderGroup, bounds, widgetTitle);
        } else if (defaultType == WidgetType.PullDownList) {
            widget = new PullDownHeader(bounds, widgetTitle);
        } else if (defaultType == WidgetType.ContextMenu) {
            widget = new ContextMenu(bounds, widgetTitle);
            // The default value for CONTEXT_MENU_ACTION_ATTR
            // is RIGHT_CLICK; must change to TAP_HOLD if the devices
            // contain a Touchscreen but not a Mouse
            Set<DeviceType> deviceTypes = design.getDeviceTypes();
            if (deviceTypes.contains(DeviceType.Touchscreen) && !deviceTypes.contains(DeviceType.Mouse)) {
                widget.setAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR, WidgetAttributes.TAP_HOLD);
            }
        } else if (defaultType == WidgetType.ListBoxItem) {
            SimpleWidgetGroup newListItemGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
            widget = new ListItem(newListItemGroup, bounds, widgetTitle);
            newListItemGroup.setAttribute(WidgetAttributes.FIRST_VISIBLE_ATTR, widget);
        } else if (defaultType == WidgetType.Radio) {
            RadioButtonGroup newRadioGroup = new RadioButtonGroup();
            widget = new RadioButton(newRadioGroup, bounds, widgetTitle);
        } else if (defaultType == WidgetType.Check) {
            GridButtonGroup newCheckGroup = new GridButtonGroup();
            widget = new CheckBox(newCheckGroup, bounds, widgetTitle);
        } else {
            // Create new widget in specified location
            // Note: could be a child widget;
            //       if so, the user is managing the hierarchy!
            widget = new Widget(bounds, defaultType);
        }
        widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_STANDARD);
    } else {
        // Create new widget in specified location
        // Note: could be a child widget;
        //       if so, the user is managing the hierarchy!
        widget = new Widget(bounds, defaultType);
        widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
    }
    return widget;
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) RadioButtonGroup(edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) RadioButton(edu.cmu.cs.hcii.cogtool.model.RadioButton) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 5 with GridButtonGroup

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

the class FrameEditorController method deleteWidget.

/**
     * This deletes a widget from the model and adds the action to the undo list.
     *
     * @param w is the widget to delete.
     * @param moveSiblings is a flag - if it is true, the other widgets in the
     * group will be moved to close up the space left by the deleted widget.
     * @param editSequence is the compound edit to add this delete operation to.
     */
private void deleteWidget(IWidget w, boolean moveSiblings, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
    // If this is a remote label, delete the attribute indicating so
    // from the point of view of its owner.
    FrameElement remoteLabelOwner = (FrameElement) w.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
    if (remoteLabelOwner != null) {
        DefaultCmd.unsetAttribute(remoteLabelOwner, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, interaction, editSequence);
    } else {
        // Check if this widget is a remote label owner; if so, delete
        // the remote label as well
        deleteRemoteLabel(w, editSequence);
    }
    SimpleWidgetGroup parentGroup = w.getParentGroup();
    int atIndex = (parentGroup != null) ? parentGroup.indexOf(w) : -1;
    double deltaX = 0;
    double deltaY = 0;
    // since we know every item in them will be deleted.
    if (w instanceof AParentWidget) {
        AParentWidget pw = (AParentWidget) w;
        while (pw.itemCount() > 0) {
            deleteWidget(pw.getItem(0), false, fromGroup, editSequence);
        }
    }
    // If the widget is the last object of the its root element,
    // then the root element must be removed from any containing groups
    // and, if the root element is the second to last member of any
    // group, then the group should be removed as well.
    // This must be done before the removeWidget call.
    FrameElement rootElt = w.getRootElement();
    // containing associations
    if (rootElt == w) {
        removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
    } else if (rootElt instanceof SimpleWidgetGroup) {
        // Otherwise, need to do the same only if the root element
        // is a widget group that will become empty.
        SimpleWidgetGroup rootGroup = (SimpleWidgetGroup) rootElt;
        // remove it from containing associations
        if (rootGroup.size() == 1) {
            removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
        }
    }
    model.removeWidget(w);
    if (parentGroup != null) {
        // Check if this parent group is a remote label owner; if so, delete
        // the remote label as well
        deleteRemoteLabel(parentGroup, editSequence);
        if (moveSiblings) {
            int myGroupNum = parentGroup.size();
            if (parentGroup.getOrientation() == SimpleWidgetGroup.HORIZONTAL) {
                deltaX = -w.getEltBounds().width;
            } else if (parentGroup.getOrientation() == SimpleWidgetGroup.VERTICAL) {
                deltaY = -w.getEltBounds().height;
            }
            // This loop will be ineffective for grid buttons
            for (int i = atIndex + 1; i < myGroupNum; i++) {
                IWidget curWidget = parentGroup.get(i);
                curWidget.moveElement(deltaX, deltaY);
            }
        }
        // Otherwise, remove it from its parent group.
        if (w instanceof ChildWidget) {
            ChildWidget child = (ChildWidget) w;
            AParentWidget itemParent = child.getParent();
            itemParent.removeItem(child);
        } else {
            parentGroup.remove(w);
        }
        if (parentGroup instanceof GridButtonGroup) {
            GridButtonGroup gbg = (GridButtonGroup) parentGroup;
            GridButton gb = (GridButton) w;
            DoubleRectangle b = w.getEltBounds();
            double x = b.x + b.width;
            double y = b.y + b.height;
            double newHoriz = gb.getHorizSpace();
            double newVert = gb.getVertSpace();
            ReadOnlyList<GridButton> movedButtons = null;
            GridButton top = null;
            double dx = 0.0;
            double dy = 0.0;
            if (gbg.getColumn(gb).size() == 0) {
                // w was the only widget in the column; need to move next
                // column over
                movedButtons = gbg.getMovedButtons(false, x, b.y);
                if (movedButtons.size() > 0) {
                    top = movedButtons.get(0);
                    DoublePoint p = top.getShape().getOrigin();
                    dx = b.x - p.x;
                }
            } else {
                // need to move lower widgets up to fill the hole
                movedButtons = gbg.getMovedButtons(true, b.x, y);
                if (movedButtons.size() > 0) {
                    top = movedButtons.get(0);
                    DoublePoint p = top.getShape().getOrigin();
                    dy = b.y - p.y;
                }
            }
            if (top != null) {
                moveGridButton(FrameEditorLID.Delete, DELETE_WIDGET, top, dx, dy, newHoriz, newVert, editSequence);
            }
        }
    }
    DemoStateManager.IDesignUndoableEdit edit;
    // Add the deletion to the undoable history
    if (w instanceof ChildWidget) {
        ChildWidget child = (ChildWidget) w;
        final AParentWidget itemParent = child.getParent();
        edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {

            @Override
            public void redoHelper() {
                itemParent.removeItem((ChildWidget) widget);
            }

            @Override
            public void undoHelper() {
                itemParent.addItem(atIndex, (ChildWidget) widget);
            }
        };
    } else {
        edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {

            @Override
            public void redoHelper() {
                parentGroup.remove(widget);
            }

            @Override
            public void undoHelper() {
                parentGroup.add(atIndex, widget);
            }
        };
    }
    demoStateMgr.noteWidgetEdit(w, edit);
    editSequence.addEdit(edit);
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Aggregations

GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)15 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)12 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)9 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)7 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)6 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)6 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)5 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)3 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)3 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 RadioButtonGroup (edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup)3 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)3 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)2 RadioButton (edu.cmu.cs.hcii.cogtool.model.RadioButton)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2