Search in sources :

Example 16 with FrameElement

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

the class FrameEditorController method spaceElementsEqually.

/**
     * Spaces the selected frame elements equally along a certain axis
     * @param vertical true for vertical axis; false for horizontal
     */
private boolean spaceElementsEqually(FrameEditorSelectionState selection, boolean vertical) {
    // Order the widgets according to location
    // (either from the left or from the top)
    Comparator<FrameElement> c = vertical ? elementVerticalComparator : elementHorizontalComparator;
    Set<FrameElement> elements = getSelectedElements(selection, c);
    if (elements.size() <= 2) {
        interaction.protestTooFewElements();
        return false;
    }
    // Calculate the spacing between widgets
    double sum = 0;
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    // Go through each element that is selected
    // Determine the size, min & max of the region.
    // this can then be used to do spacing.
    Iterator<FrameElement> eltIter = elements.iterator();
    while (eltIter.hasNext()) {
        DoubleRectangle bounds = eltIter.next().getEltBounds();
        double size = vertical ? bounds.height : bounds.width;
        double position = vertical ? bounds.y : bounds.x;
        sum += size;
        min = Math.min(min, position);
        max = Math.max(max, size + position);
    }
    // Get the spacing to use between each item.
    double spacing = ((max - min) - sum) / (elements.size() - 1);
    String undoRedoLabel = vertical ? SPACE_VERTICALLY : SPACE_HORIZONTALLY;
    CogToolLID lid = vertical ? FrameEditorLID.SpaceVertically : FrameEditorLID.SpaceHorizontally;
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(undoRedoLabel, lid);
    // Avoid moving a group more than once
    Set<SimpleWidgetGroup> movedGroups = new HashSet<SimpleWidgetGroup>();
    Set<IWidget> movedWidgets = new HashSet<IWidget>();
    // Adjust the spacings to the correct values and go through
    // each element performing the appropriate move.
    eltIter = elements.iterator();
    while (eltIter.hasNext()) {
        FrameElement elt = eltIter.next();
        DoubleRectangle bounds = elt.getEltBounds();
        // Determine the amount to move each element
        double deltaX = vertical ? 0.0 : (min - bounds.x);
        double deltaY = vertical ? (min - bounds.y) : 0.0;
        // Set the new location, adding the undoable edit
        moveElement(lid, undoRedoLabel, elt, deltaX, deltaY, true, movedGroups, movedWidgets, editSequence);
        // Advance the pointer to the next location
        min += spacing + (vertical ? bounds.height : bounds.width);
    }
    editSequence.end();
    // Only add this edit if it is significant
    if (editSequence.isSignificant()) {
        undoMgr.addEdit(editSequence);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) CogToolLID(edu.cmu.cs.hcii.cogtool.CogToolLID) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

Example 17 with FrameElement

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

the class FrameEditorController method deleteElements.

/**
     * Delete currently selected widgets.
     */
protected boolean deleteElements(FrameEditorSelectionState selection) {
    String editLabel = (selection.getElementSelectionCount() > 1) ? DELETE_WIDGETS : DELETE_WIDGET;
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, FrameEditorLID.Delete);
    FrameElement[] selectedElts = selection.getSelectedIFrameElements();
    // Check to see if any items are selected
    if (selectedElts.length > 0) {
        if (interaction.confirmDeleteElements(selectedElts)) {
            Set<IWidget> frameWidgets = model.getWidgets();
            Set<FrameElementGroup> frameAssocs = model.getEltGroups();
            for (FrameElement selectedElt : selectedElts) {
                if (selectedElt instanceof FrameElementGroup) {
                    // component of another group
                    if (frameAssocs.contains(selectedElt)) {
                        deleteFrameEltGroup((FrameElementGroup) selectedElt, null, editSequence);
                    }
                } else if (selectedElt instanceof IWidget) {
                    // of another widget (e.g., menu item part of a menu)
                    if (frameWidgets.contains(selectedElt)) {
                        deleteWidget((IWidget) selectedElt, true, null, editSequence);
                    }
                }
            }
            editSequence.end();
            undoMgr.addEdit(editSequence);
            return true;
        }
    } else {
        interaction.protestNoSelection();
    }
    return false;
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 18 with FrameElement

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

the class FrameEditorController method deleteFrameEltGroup.

private void deleteFrameEltGroup(final FrameElementGroup grp, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
    // Check if this element group is a remote label owner; if so, delete
    // the remote label as well
    deleteRemoteLabel(grp, editSequence);
    Iterator<FrameElement> members = grp.iterator();
    while (members.hasNext()) {
        deleteGroupMember(members.next(), grp, editSequence);
    }
    model.removeEltGroup(grp);
    removeRootElement(DELETE_GROUP, grp, fromGroup, editSequence);
    DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Delete, demoStateMgr) {

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

        @Override
        public void redo() {
            super.redo();
            model.removeEltGroup(grp);
        }

        @Override
        public void undo() {
            super.undo();
            model.addEltGroup(grp);
        }
    };
    editSequence.addEdit(edit);
}
Also used : IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement)

Example 19 with FrameElement

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

the class FrameEditorController method resizeElements.

/**
     * Resize the selected set of elements based on where the mouse was released
     * and the fixed point in the resize.
     *
     * While it supports multiple selection, its behavior is correct if called
     * with more then one selected widget.
     */
private boolean resizeElements(double oldResizeX, double oldResizeY, double newResizeX, double newResizeY, double ratioX, double ratioY, FrameEditorSelectionState selection) {
    Iterator<FrameElement> selected = selection.getSelectedElementsIterator();
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit((selection.getWidgetSelectionCount() != 1) ? RESIZE_WIDGETS : RESIZE_WIDGET, FrameEditorLID.ResizeWidgets);
    Set<SimpleWidgetGroup> resizedGroups = new HashSet<SimpleWidgetGroup>();
    // Loop through selected widgets
    while (selected.hasNext()) {
        FrameElement elt = selected.next();
        resizeElement(elt, oldResizeX, oldResizeY, newResizeX, newResizeY, ratioX, ratioY, resizedGroups, false, editSequence);
    }
    editSequence.end();
    // Only add this edit if it is significant
    if (editSequence.isSignificant()) {
        undoMgr.addEdit(editSequence);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) HashSet(java.util.HashSet)

Example 20 with FrameElement

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

the class FrameEditorController method moveElements.

private boolean moveElements(FrameEditorSelectionState selection, double moveByX, double moveByY, boolean moveAsGroup) {
    String editLabel;
    if (selection.getWidgetSelectionCount() == 1) {
        editLabel = MOVE_WIDGET;
    } else {
        editLabel = MOVE_WIDGETS;
    }
    CompoundUndoableEdit editSequence = new CompoundUndoableEdit(editLabel, FrameEditorLID.MoveWidgets);
    FrameElement[] selected = selection.getSelectedIFrameElements();
    // Avoid moving a group more than once
    Set<SimpleWidgetGroup> movedGroups = new HashSet<SimpleWidgetGroup>();
    Set<IWidget> movedWidgets = new HashSet<IWidget>();
    // Move all selected widgets by the specified amount
    for (FrameElement eltToMove : selected) {
        if (!isMemberOfSelectedGroup(eltToMove, selection)) {
            moveElement(FrameEditorLID.MoveWidgets, editLabel, eltToMove, moveByX, moveByY, moveAsGroup, movedGroups, movedWidgets, editSequence);
        }
    }
    editSequence.end();
    // Only add this edit if it is significant
    if (editSequence.isSignificant()) {
        undoMgr.addEdit(editSequence);
    }
    return true;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet)

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