Search in sources :

Example 16 with ChildWidget

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

the class DesignEditorCmd method copyElements.

public static void copyElements(Design design, FrameElement[] selectedElts, Iterator<FrameElement> eltsToCopy, boolean saveToClipboard) {
    try {
        // Set up a clipboard saver.  Indicate that no transitions
        // should be copied.
        CogToolClipboard.ClipboardClassSaver s = CogToolClipboard.startClipboardSave(CogToolClipboard.CopyWidgets, selectedElts, saveToClipboard);
        // Iterate through the widgets and save the selected items.
        while (eltsToCopy.hasNext()) {
            FrameElement elt = eltsToCopy.next();
            //       get pasted.
            if (!(elt instanceof ChildWidget)) {
                s.saveObject(elt);
            }
        }
        s.finish();
        if (!saveToClipboard) {
            FrameTemplateSupport.setFrameTemplate(design, s.getSavedString());
        }
    } catch (IOException e) {
        throw new RcvrClipboardException(e);
    } catch (OutOfMemoryError error) {
        throw new RcvrOutOfMemoryException("Copying Widgets", error);
    }
}
Also used : RcvrOutOfMemoryException(edu.cmu.cs.hcii.cogtool.util.RcvrOutOfMemoryException) CogToolClipboard(edu.cmu.cs.hcii.cogtool.CogToolClipboard) RcvrClipboardException(edu.cmu.cs.hcii.cogtool.util.RcvrClipboardException) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IOException(java.io.IOException) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 17 with ChildWidget

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

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

the class FrameEditorMouseState method dynamicReorderWidget.

protected void dynamicReorderWidget(int x, int y, boolean duplicate) {
    int dx = x - lastX;
    int dy = y - lastY;
    Point frameOrigin = reorderFigure.getLocation();
    frameOrigin.x += dx;
    frameOrigin.y += dy;
    reorderFigure.setLocation(frameOrigin);
    GraphicalWidget<?> curWidgetFig = ui.widgetLocatedAtXY(x, y);
    PotentialFigure potential = ui.potentialWidgetUnderXY(x, y);
    ui.resizeHandlesUIFig.hide();
    dividerLine.setVisible(false);
    if ((curWidgetFig != null) && ui.areCompatible(lastClickedWidget, curWidgetFig.getModel()) && (duplicate || reorderAllowed(curWidgetFig.getModel()))) {
        boolean isChildWidget = lastClickedWidget instanceof ChildWidget;
        boolean changedWidget = curWidgetFig.getModel() != lastClickedWidget;
        lastHoveredWidget = curWidgetFig;
        // If the dragged widget is not a child, it won't make sense to
        // drag it onto a potential figure
        // MLHQ: How do you know this cast will succeed?
        ui.hideNonhaloSupport(!isChildWidget, changedWidget, (GraphicalTraversableWidget<?>) curWidgetFig);
        setDividerBounds(curWidgetFig, x, y);
        if (lastClickedWidget instanceof ChildWidget) {
            if (curWidgetFig instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> child = (GraphicalChildWidget<?, ?>) curWidgetFig;
                child.getParentFigure().openChildren();
            }
            if (curWidgetFig instanceof GraphicalParentWidget<?, ?>) {
                if (changedWidget) {
                    ((GraphicalParentWidget<?, ?>) curWidgetFig).openChildren();
                }
            }
        }
    } else if (potential != null) {
        GraphicalTraversableWidget<?> owner = ui.getPotentialFigureOwner();
        if (owner instanceof GraphicalChildWidget<?, ?>) {
            ((GraphicalChildWidget<?, ?>) owner).getParentFigure().openChildren();
        }
        ui.potentialUIFig.setSelection(potential);
    } else {
        if (withinReorder(x, y)) {
            setDividerBounds(lastHoveredWidget, x, y);
            if (lastHoveredWidget instanceof GraphicalChildWidget<?, ?>) {
                GraphicalChildWidget<?, ?> gcw = (GraphicalChildWidget<?, ?>) lastHoveredWidget;
                gcw.getParentFigure().openChildren();
            }
        } else if ((lastClickedWidget instanceof ChildWidget) || !duplicate) {
            ui.hideNondynamicSupport(true, false);
            InteractionFigure drawLayer = ui.getViewEditor().getInteractionFigure();
            drawLayer.setCursor(NOT_ALLOWED_CURSOR);
        }
    }
}
Also used : Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) GraphicalChildWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) InteractionFigure(edu.cmu.cs.hcii.cogtool.view.InteractionFigure)

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