Search in sources :

Example 21 with SimpleWidgetGroup

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

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

the class FrameUIModel method getNextInGroup.

public GraphicalWidget<?> getNextInGroup(GraphicalWidget<?> fromWidgetFig) {
    IWidget modelWidget = fromWidgetFig.getModel();
    SimpleWidgetGroup group = modelWidget.getParentGroup();
    if (group != null) {
        int widgetIndex = group.indexOf(modelWidget);
        if (widgetIndex < group.size() - 1) {
            return getWidgetFigure(group.get(widgetIndex + 1));
        }
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Example 23 with SimpleWidgetGroup

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

the class FrameUIModel method getLastInGroup.

public GraphicalWidget<?> getLastInGroup(GraphicalWidget<?> fromWidgetFig) {
    IWidget modelWidget = fromWidgetFig.getModel();
    SimpleWidgetGroup group = modelWidget.getParentGroup();
    if (group != null) {
        int widgetIndex = group.size() - 1;
        return getWidgetFigure(group.get(widgetIndex));
    }
    return null;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Point(org.eclipse.draw2d.geometry.Point)

Example 24 with SimpleWidgetGroup

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

Example 25 with SimpleWidgetGroup

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

the class FrameEditorController method duplicateGroupMember.

// Assumes that widget is an instance of MenuHeader, ListItem, or
// GridButton
private IWidget duplicateGroupMember(IWidget widget, FrameEditorSelectionState selection, double moveByX, double moveByY) {
    SimpleWidgetGroup existingGroup = widget.getParentGroup();
    SimpleWidgetGroup newGroup = widgetSituator.getGroup(existingGroup);
    // If the first time this group has been seen, populate.
    if (newGroup.size() == 0) {
        Iterator<IWidget> widgets = sortSelectedMbrs(existingGroup, selection);
        while (widgets.hasNext()) {
            Frame.duplicateWidget(widgets.next(), lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
        }
        DesignEditorCmd.repositionChildren(newGroup);
    }
    return widgetSituator.getDuplicate(widget);
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)45 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)32 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)16 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)14 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)13 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)10 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 HashSet (java.util.HashSet)8 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)7 Point (org.eclipse.draw2d.geometry.Point)7 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)6 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)6 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)6 Iterator (java.util.Iterator)6 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)5 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)4 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)4 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)4 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)4