Search in sources :

Example 11 with GridButton

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

Example 12 with GridButton

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

the class FrameEditorController method moveWidget.

private void moveWidget(ListenerIdentifier lid, String presentationLabel, IWidget widget, double widgetMoveByX, double widgetMoveByY, boolean moveAsGroup, Set<SimpleWidgetGroup> movedGroups, Set<IWidget> movedWidgets, IUndoableEditSequence editSequence) {
    if (movedWidgets.contains(widget)) {
        return;
    }
    movedWidgets.add(widget);
    SimpleWidgetGroup parentGroup = widget.getParentGroup();
    if ((parentGroup == null) || (!moveAsGroup)) {
        if (widget instanceof GridButton) {
            GridButton gb = (GridButton) widget;
            moveGridButton(lid, presentationLabel, gb, widgetMoveByX, widgetMoveByY, gb.getHorizSpace() + widgetMoveByX, gb.getVertSpace() + widgetMoveByY, editSequence);
        } else {
            moveWidget(lid, presentationLabel, widget, widgetMoveByX, widgetMoveByY, editSequence);
        }
    } else if (!(widget instanceof ChildWidget)) {
        // move entire group
        if (!movedGroups.contains(parentGroup)) {
            moveWidgetGroup(lid, presentationLabel, parentGroup, widgetMoveByX, widgetMoveByY, editSequence);
            movedGroups.add(parentGroup);
        }
    }
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 13 with GridButton

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

the class FrameEditorController method moveGridButton.

/**
     * Special case of moveWidget; moves all buttons below or to the right of
     * gb in its group and updates the horizontal and vertical offsets as
     * necessary.
     */
private void moveGridButton(ListenerIdentifier lid, String presentationLabel, GridButton gb, double widgetMoveByX, double widgetMoveByY, double newHoriz, double newVert, IUndoableEditSequence editSequence) {
    // move the list of buttons affected
    DoublePoint oldLocation = gb.getShape().getOrigin();
    double oldX = oldLocation.x;
    double oldY = oldLocation.y;
    GridButtonGroup gbg = (GridButtonGroup) gb.getParentGroup();
    boolean vertical = (widgetMoveByX == 0);
    double oldHoriz = gb.getHorizSpace();
    double oldVert = gb.getVertSpace();
    ReadOnlyList<? extends GridButton> movedButtons = gbg.getMovedButtons(vertical, oldX, oldY);
    for (int i = 0; i < movedButtons.size(); i++) {
        GridButton g = movedButtons.get(i);
        DoublePoint p = g.getShape().getOrigin();
        double tempX = Math.max(p.x + widgetMoveByX, 0.0);
        double tempY = Math.max(p.y + widgetMoveByY, 0.0);
        g.setWidgetOrigin(tempX, tempY);
    }
    if (vertical) {
        gb.setVertSpace(newVert);
    } else {
        List<GridButton> column = gbg.getColumn(gb);
        for (int i = 0; i < column.size(); i++) {
            GridButton g = column.get(i);
            g.setHorizSpace(newHoriz);
        }
    }
    DemoStateManager.IDesignUndoableEdit edit = moveGridButtonsEdit(lid, presentationLabel, movedButtons, widgetMoveByX, widgetMoveByY, oldHoriz, oldVert, newHoriz, newVert, gb);
    editSequence.addEdit(edit);
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 14 with GridButton

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

the class FrameEditorMouseState method dynamicMoveGridButtons.

// mouseDragged
protected void dynamicMoveGridButtons(double currentScaledX, double currentScaledY) {
    GraphicalWidget<?> gw = ui.getPotentialFigureOwner();
    GridButton gb = (GridButton) gw.getModel();
    DoublePoint start = gb.getShape().getOrigin();
    double moveX = 0.0;
    double moveY = 0.0;
    double offsetX = currentScaledX - scaledMouseDownX;
    double offsetY = currentScaledY - scaledMouseDownY;
    ui.hideNondynamicSupport(true);
    if (moveIsVertical) {
        moveY = (currentScaledY < minY) ? (minY - start.y) : offsetY;
    } else {
        moveX = (currentScaledX < minX) ? (minX - start.x) : offsetX;
    }
    // Iterate through list of affected radio buttons
    for (int i = 0; i < movedGridButtons.size(); i++) {
        GridButton w = movedGridButtons.get(i);
        GraphicalWidget<?> wf = ui.frameUI.getWidgetFigure(w);
        DoublePoint p = w.getShape().getOrigin();
        // Temporarily move the widget origin to new location.
        wf.setLocation(new Point(PrecisionUtilities.round(p.x + moveX), PrecisionUtilities.round(p.y + moveY)));
    //  this.ui.setGraphicalWidgetOrigin(p.x + moveX, p.y + moveY, wf);
    }
}
Also used : GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) Point(org.eclipse.draw2d.geometry.Point) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Aggregations

GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)14 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)7 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)7 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)4 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)3 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)3 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)2 FrameEltGroupHalo (edu.cmu.cs.hcii.cogtool.uimodel.FrameEltGroupHalo)2 GraphicalWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalWidget)2 Iterator (java.util.Iterator)2 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)1 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)1 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1