Search in sources :

Example 6 with ChildWidget

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

Example 7 with ChildWidget

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

the class FrameEditorController method frameSetAttribute.

// setAsSeparator
// xxy for remote label, do we set both directions (here??)
private boolean frameSetAttribute(IAttributed target, final String attrName, final Object value, IUndoableEditSequence editSeq) {
    if (attrName.equals(WidgetAttributes.IS_SEPARATOR_ATTR)) {
        ChildWidget selectedItem = null;
        if (target instanceof PullDownItem) {
            AParentWidget pullDown = ((PullDownItem) target).getParent();
            selectedItem = (ChildWidget) pullDown.getAttribute(WidgetAttributes.SELECTION_ATTR);
        }
        return setAsSeparator((IWidget) target, value, selectedItem, editSeq);
    }
    return DefaultCmd.setAttribute(target, demoStateMgr, attrName, value, interaction, editSeq);
}
Also used : PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 8 with ChildWidget

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

the class FrameEditorController method duplicateWidget.

// duplicateGroupMember
private IWidget duplicateWidget(IWidget widget, FrameEditorSelectionState selection, double moveByX, double moveByY) {
    // If already copied, simply return the copy.
    IWidget widgetCopy = widgetSituator.getDuplicate(widget);
    if (widgetCopy != null) {
        return widgetCopy;
    }
    // call for the remote "label" in duplicateRemoteLabel().
    if (widget instanceof ChildWidget) {
        return null;
    }
    // (also gets GridButton and ListItem)
    if (widget.getParentGroup() != null) {
        widgetCopy = duplicateGroupMember(widget, selection, moveByX, moveByY);
    } else {
        // This gets PullDownHeader and ContextMenu (but not
        // MenuHeader/Item) and all else but MenuItem and PullDownItem
        // (i.e., children)
        // TODO: Is there any reasonable semantics to
        //       duplicating menu/pull-down items?
        widgetCopy = Frame.duplicateWidget(widget, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
    }
    // If this is a remote label, then check if the owner is also being
    // duplicated; if so, keep the remote label as a remote label.
    // If not, remote the attribute on the copy.
    FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
    if (remoteLabelOwner != null) {
        if ((selection != null) && !selection.isElementSelected(remoteLabelOwner)) {
            // Remove "label"-ness
            widgetCopy.unsetAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
        }
    // otherwise, when the owner gets duplicated, it will replace
    // the owner of this label with its copy; see duplicateRemoteLabel!
    } else {
        Frame.duplicateRemoteLabel(widget, widgetCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
    }
    return widgetCopy;
}
Also used : FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 9 with ChildWidget

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

Example 10 with ChildWidget

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

the class FrameEditorController method insertDuplicateEdit.

private void insertDuplicateEdit(final IWidget duplicatedWidget, final ReadOnlyList<? extends IWidget> widgetCopies, final SimpleWidgetGroup group, final int index, final AParentWidget parent, final double startPosX, final double startPosY, IUndoableEditSequence editSeq) {
    DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {

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

        @Override
        public void redo() {
            super.redo();
            if (duplicatedWidget instanceof ChildWidget) {
                ChildWidget child = (ChildWidget) duplicatedWidget;
                AParentWidget curParent = child.getParent();
                curParent.addItem(index, child);
            } else if (index >= 0) {
                group.add(index, duplicatedWidget);
            } else {
                group.add(duplicatedWidget);
            }
            model.addWidget(duplicatedWidget);
            stateMgr.noteWidgetsEdit(widgetCopies, this);
            if (parent != null) {
                DesignEditorCmd.repositionChildren(parent);
            } else if (group != null) {
                DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
            }
        }

        @Override
        public void undo() {
            super.undo();
            if (duplicatedWidget instanceof ChildWidget) {
                ChildWidget child = (ChildWidget) duplicatedWidget;
                AParentWidget curParent = child.getParent();
                curParent.removeItem(child);
            } else if (duplicatedWidget.getParentGroup() != null) {
                SimpleWidgetGroup parentGroup = duplicatedWidget.getParentGroup();
                parentGroup.remove(duplicatedWidget);
            }
            model.removeWidget(duplicatedWidget);
            stateMgr.noteWidgetsEdit(widgetCopies, this);
            if (parent != null) {
                DesignEditorCmd.repositionChildren(parent);
            } else if (group != null) {
                DesignEditorCmd.repositionChildren(group, startPosX, startPosY);
            }
        }
    };
    editSeq.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) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Aggregations

ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)18 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)8 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)7 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)4 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)4 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)4 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)3 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)2 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)2 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)2 PotentialFigure (edu.cmu.cs.hcii.cogtool.view.PotentialFigure)2 IOException (java.io.IOException)2 Point (org.eclipse.draw2d.geometry.Point)2