Search in sources :

Example 11 with FrameElement

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

the class FrameEditorController method duplicateFrameEltGroup.

// duplicateWidget
private FrameElementGroup duplicateFrameEltGroup(FrameElementGroup grp, double moveByX, double moveByY) {
    // Temporarily assign the same name; when added to the Frame
    // we will ensure the name is then unique
    FrameElementGroup newEltGrp = grp.twin();
    Iterator<FrameElement> eltsToDup = grp.iterator();
    while (eltsToDup.hasNext()) {
        FrameElement elt = eltsToDup.next();
        FrameElement eltCopy = null;
        if (elt instanceof IWidget) {
            IWidget widget = (IWidget) elt;
            duplicateWidget(widget, null, moveByX, moveByY);
            eltCopy = widgetSituator.getDuplicate(widget);
        } else if (elt instanceof SimpleWidgetGroup) {
            SimpleWidgetGroup group = (SimpleWidgetGroup) elt;
            SimpleWidgetGroup groupCopy = widgetSituator.getGroup(group);
            Iterator<IWidget> groupWidgets = group.iterator();
            while (groupWidgets.hasNext()) {
                duplicateGroupMember(groupWidgets.next(), null, moveByX, moveByY);
            }
            Frame.duplicateRemoteLabel(group, groupCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
            eltCopy = groupCopy;
        } else if (elt instanceof FrameElementGroup) {
            eltCopy = duplicateFrameEltGroup((FrameElementGroup) elt, moveByX, moveByY);
        }
        if (eltCopy != null) {
            newEltGrp.add(eltCopy);
        }
    }
    widgetSituator.setGroupDuplicate(grp, newEltGrp);
    Frame.duplicateRemoteLabel(grp, newEltGrp, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
    return newEltGrp;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) EmptyIterator(edu.cmu.cs.hcii.cogtool.util.EmptyIterator) Iterator(java.util.Iterator) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 12 with FrameElement

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

the class FrameEditorController method isMemberOfSelectedGroup.

private boolean isMemberOfSelectedGroup(FrameElement elt, FrameEditorSelectionState seln) {
    FrameElement rootElt = elt.getRootElement();
    Iterator<FrameElementGroup> grps = rootElt.getEltGroups().iterator();
    // that is also selected, skip it
    while (grps.hasNext()) {
        if (seln.isElementSelected(grps.next())) {
            return true;
        }
    }
    return false;
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement)

Example 13 with FrameElement

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

the class FrameEditorController method getSelectedWidgets.

/**
     * Fetch all widgets referenced by the given selection sorted by
     * the given comparison function.
     */
private IWidget[] getSelectedWidgets(FrameEditorSelectionState seln, Comparator<? super IWidget> c) {
    IWidget[] widgets;
    Set<IWidget> allWidgets = new HashSet<IWidget>();
    Iterator<FrameElement> s = seln.getSelectedElementsIterator();
    while (s.hasNext()) {
        FrameElement elt = s.next();
        if (elt instanceof IWidget) {
            IWidget w = (IWidget) elt;
            SimpleWidgetGroup group = w.getParentGroup();
            if (group != null) {
                Iterator<IWidget> mbrs = group.iterator();
                while (mbrs.hasNext()) {
                    allWidgets.add(mbrs.next());
                }
            } else {
                allWidgets.add(w);
            }
        } else if (elt instanceof FrameElementGroup) {
            Iterator<IWidget> eltGrpWidgets = new ElementAllWidgetIterator((FrameElementGroup) elt);
            while (eltGrpWidgets.hasNext()) {
                allWidgets.add(eltGrpWidgets.next());
            }
        }
    }
    widgets = new IWidget[allWidgets.size()];
    allWidgets.toArray(widgets);
    Arrays.sort(widgets, c);
    return widgets;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) EmptyIterator(edu.cmu.cs.hcii.cogtool.util.EmptyIterator) Iterator(java.util.Iterator) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

Example 14 with FrameElement

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

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

the class FrameEditorController method duplicateWidgetsAction.

// duplicateFrameEltGroup
private IListenerAction duplicateWidgetsAction() {
    return new IListenerAction() {

        public Class<?> getParameterClass() {
            return FrameEditorUI.DuplicateParameters.class;
        }

        public boolean performAction(Object prms) {
            FrameEditorUI.DuplicateParameters parameters = (FrameEditorUI.DuplicateParameters) prms;
            int elementCount = parameters.selection.getElementSelectionCount();
            // If selection is non zero, copy widgets
            if (elementCount > 0) {
                Map<IWidget, IWidget> widgetCopies = new LinkedHashMap<IWidget, IWidget>();
                final Map<FrameElementGroup, FrameElementGroup> groupCopies = new LinkedHashMap<FrameElementGroup, FrameElementGroup>();
                widgetSituator.reset(widgetCopies, groupCopies);
                Set<FrameElement> selectedElements = getSelectedElements(parameters.selection, elementLevelComparator);
                Iterator<FrameElement> elements = selectedElements.iterator();
                // Iterate through the widgets and duplicate.
                while (elements.hasNext()) {
                    FrameElement elt = elements.next();
                    if (elt instanceof IWidget) {
                        duplicateWidget((IWidget) elt, parameters.selection, parameters.moveByX, parameters.moveByY);
                    } else if (elt instanceof FrameElementGroup) {
                        duplicateFrameEltGroup((FrameElementGroup) elt, parameters.moveByX, parameters.moveByY);
                    }
                }
                widgetSituator.completeWork();
                final Iterable<? extends IWidget> widgetDuplicates = new ReadOnlyList<IWidget>(new ArrayList<IWidget>(widgetCopies.values()));
                Iterator<? extends IWidget> copiedWidgets = widgetDuplicates.iterator();
                Set<GridButtonGroup> dupGridGroups = new HashSet<GridButtonGroup>();
                while (copiedWidgets.hasNext()) {
                    IWidget widgetCopy = copiedWidgets.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);
                    if (widgetCopy instanceof GridButton) {
                        GridButtonGroup gbg = (GridButtonGroup) widgetCopy.getParentGroup();
                        // for each grid button group
                        if (!dupGridGroups.contains(gbg)) {
                            gbg.recalculateOffsets();
                            dupGridGroups.add(gbg);
                        }
                    }
                }
                Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                while (copiedGroups.hasNext()) {
                    FrameElementGroup copiedGroup = copiedGroups.next();
                    // Ensure name is unique, then add to frame immediately
                    // Otherwise, it would be possible to generate presumed
                    // unique names that weren't.
                    makeEltGroupNameUnique(copiedGroup);
                    model.addEltGroup(copiedGroup);
                }
                DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Duplicate, demoStateMgr) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<? extends IWidget> addCopies = widgetDuplicates.iterator();
                        while (addCopies.hasNext()) {
                            IWidget widgetCopy = addCopies.next();
                            model.addWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.addEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Iterator<? extends IWidget> removeCopies = widgetDuplicates.iterator();
                        while (removeCopies.hasNext()) {
                            IWidget widgetCopy = removeCopies.next();
                            model.removeWidget(widgetCopy);
                        }
                        Iterator<FrameElementGroup> copiedGroups = groupCopies.values().iterator();
                        while (copiedGroups.hasNext()) {
                            model.removeEltGroup(copiedGroups.next());
                        }
                        demoStateMgr.noteWidgetsEdit(widgetDuplicates, this);
                    }
                };
                demoStateMgr.noteWidgetsEdit(widgetDuplicates, edit);
                undoMgr.addEdit(edit);
                return true;
            }
            // tell user to select something.
            interaction.protestNoSelection();
            return false;
        }
    };
}
Also used : IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) LinkedHashMap(java.util.LinkedHashMap) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) HashSet(java.util.HashSet) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) ReadOnlyList(edu.cmu.cs.hcii.cogtool.util.ReadOnlyList) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)31 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)20 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)16 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)14 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)9 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)7 HashSet (java.util.HashSet)6 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)5 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)5 Iterator (java.util.Iterator)5 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 Point (org.eclipse.draw2d.geometry.Point)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)3 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)3 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)3 EmptyIterator (edu.cmu.cs.hcii.cogtool.util.EmptyIterator)3 MoveHalo (edu.cmu.cs.hcii.cogtool.view.MoveHalo)3 CogToolLID (edu.cmu.cs.hcii.cogtool.CogToolLID)2