Search in sources :

Example 6 with FrameElement

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

the class FrameEditorSelectionState method getNonchildSelectionCount.

/**
     * Get the number of selected non-IChildWidget elements
     */
public int getNonchildSelectionCount() {
    int nonchildCount = 0;
    Iterator<FrameElement> allSelectedElements = getSelectedElementsIterator();
    while (allSelectedElements.hasNext()) {
        FrameElement w = allSelectedElements.next();
        if (!(w instanceof ChildWidget)) {
            nonchildCount++;
        }
    }
    return nonchildCount;
}
Also used : FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Example 7 with FrameElement

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

the class FrameEditorController method createChangeAuxTextPropertyAction.

// changeAuxTextProperty
private IListenerAction createChangeAuxTextPropertyAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.ActionStringParameters p = (FrameEditorUI.ActionStringParameters) prms;
            // While the UI should suppress
            // multiple selection for setting
            // titles, the selection supports it
            Iterator<FrameElement> selected = p.selection.getSelectedElementsIterator();
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(CHG_AUX_TEXT, FrameEditorLID.ChangeAuxTextProperty);
            String newTitle = p.newString;
            // Loop through each item and set the title
            while (selected.hasNext()) {
                FrameElement elt = selected.next();
                changeAuxTextProperty(FrameEditorLID.ChangeAuxTextProperty, CHG_AUX_TEXT, elt, newTitle, editSequence);
            }
            editSequence.end();
            // Don't add empty edits!
            if (editSequence.isSignificant()) {
                undoMgr.addEdit(editSequence);
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)

Example 8 with FrameElement

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

the class FrameEditorController method createSetRemoteLabelTextAction.

// createUngroupElementsAction
private IListenerAction createSetRemoteLabelTextAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRemoteLabelTextParms p = (FrameEditorUI.SetRemoteLabelTextParms) prms;
            // Check p.selectedElement; must be an FrameElementGroup
            // or an IWidget of WidgetType Button, PullDownList, Graffiti,
            // or TextBox (whether IS_STANDARD or IS_CUSTOM) or an IWidget
            // of WidgetType Radio, Check, or ListBoxItem if IS_STANDARD
            // (in which case, the label belongs to the parent SimpleWidgetGroup)
            FrameElement owningElt = p.selectedElement.getRemoteLabelOwner();
            if (owningElt == null) {
                interaction.protestUnsupportedLabelOwnerType();
                return false;
            }
            IWidget remoteLabel = (IWidget) owningElt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
            // Already has a label; simply update
            if (remoteLabel != null) {
                changeTitleProperty(FrameEditorLID.SetRemoteLabelText, SET_REMOTE_LABEL, remoteLabel, p.newText, // not a separator!
                false, undoMgr);
            } else if ((p.newText != null) && !p.newText.equals("")) {
                CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SET_REMOTE_LABEL, FrameEditorLID.SetRemoteLabelText);
                final double INITIAL_WIDTH = 100.0;
                final double INITIAL_HEIGHT = 16.0;
                final double MIN_MARGIN = 5.0;
                final double EXTRA_MARGIN = 10.0;
                DoubleRectangle eltBds = owningElt.getEltBounds();
                double maxY = eltBds.y - INITIAL_HEIGHT - MIN_MARGIN;
                DoubleRectangle labelBds;
                if (0.0 <= maxY) {
                    labelBds = new DoubleRectangle(eltBds.x, Math.max(0.0, maxY - EXTRA_MARGIN), INITIAL_WIDTH, INITIAL_HEIGHT);
                } else {
                    double maxX = Math.max(0.0, eltBds.x - INITIAL_WIDTH - MIN_MARGIN);
                    labelBds = new DoubleRectangle(Math.max(0.0, maxX - EXTRA_MARGIN), eltBds.y, INITIAL_WIDTH, INITIAL_HEIGHT);
                }
                remoteLabel = new Widget(labelBds, WidgetType.Text);
                DefaultCmd.setAttribute(owningElt, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, remoteLabel, interaction, editSequence);
                remoteLabel.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
                remoteLabel.setAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR, owningElt);
                remoteLabel.setName(generateUniqueWidgetName());
                remoteLabel.setTitle(p.newText);
                // Add the new widget to the undo system and to the model
                editSequence.addEdit(addWidget(remoteLabel));
                // Commit the edit
                editSequence.end();
                // Only add this edit if it is significant
                if (editSequence.isSignificant()) {
                    undoMgr.addEdit(editSequence);
                }
            }
            return true;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 9 with FrameElement

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

the class FrameEditorController method createGroupElementsAction.

private IListenerAction createGroupElementsAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            int selectedEltCount = selection.getElementSelectionCount();
            if (selectedEltCount > 1) {
                final FrameElementGroup newGroup = new FrameElementGroup();
                assignUniqueEltGroupName(newGroup);
                Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
                while (selectedElts.hasNext()) {
                    FrameElement rootElt = selectedElts.next().getRootElement();
                    // that the element is a member of the group
                    if (!newGroup.contains(rootElt)) {
                        newGroup.add(rootElt);
                    }
                }
                model.addEltGroup(newGroup);
                IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Group) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<FrameElement> groupElts = newGroup.iterator();
                        // back to the frame
                        while (groupElts.hasNext()) {
                            groupElts.next().addToEltGroup(newGroup);
                        }
                        model.addEltGroup(newGroup);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.removeEltGroup(newGroup);
                        Iterator<FrameElement> groupElts = newGroup.iterator();
                        // association from the element.
                        while (groupElts.hasNext()) {
                            groupElts.next().removeFromEltGroup(newGroup);
                        }
                    }
                };
                undoMgr.addEdit(edit);
                return true;
            }
            if (selectedEltCount == 1) {
                interaction.protestTooFewWidgets();
            } else {
                interaction.protestNoSelection();
            }
            return false;
        }
    };
}
Also used : IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) FrameEditorSelectionState(edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 10 with FrameElement

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

the class FrameEditorController method deleteWidget.

/**
     * This deletes a widget from the model and adds the action to the undo list.
     *
     * @param w is the widget to delete.
     * @param moveSiblings is a flag - if it is true, the other widgets in the
     * group will be moved to close up the space left by the deleted widget.
     * @param editSequence is the compound edit to add this delete operation to.
     */
private void deleteWidget(IWidget w, boolean moveSiblings, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
    // If this is a remote label, delete the attribute indicating so
    // from the point of view of its owner.
    FrameElement remoteLabelOwner = (FrameElement) w.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
    if (remoteLabelOwner != null) {
        DefaultCmd.unsetAttribute(remoteLabelOwner, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, interaction, editSequence);
    } else {
        // Check if this widget is a remote label owner; if so, delete
        // the remote label as well
        deleteRemoteLabel(w, editSequence);
    }
    SimpleWidgetGroup parentGroup = w.getParentGroup();
    int atIndex = (parentGroup != null) ? parentGroup.indexOf(w) : -1;
    double deltaX = 0;
    double deltaY = 0;
    // since we know every item in them will be deleted.
    if (w instanceof AParentWidget) {
        AParentWidget pw = (AParentWidget) w;
        while (pw.itemCount() > 0) {
            deleteWidget(pw.getItem(0), false, fromGroup, editSequence);
        }
    }
    // If the widget is the last object of the its root element,
    // then the root element must be removed from any containing groups
    // and, if the root element is the second to last member of any
    // group, then the group should be removed as well.
    // This must be done before the removeWidget call.
    FrameElement rootElt = w.getRootElement();
    // containing associations
    if (rootElt == w) {
        removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
    } else if (rootElt instanceof SimpleWidgetGroup) {
        // Otherwise, need to do the same only if the root element
        // is a widget group that will become empty.
        SimpleWidgetGroup rootGroup = (SimpleWidgetGroup) rootElt;
        // remove it from containing associations
        if (rootGroup.size() == 1) {
            removeRootElement(DELETE_WIDGET, rootElt, fromGroup, editSequence);
        }
    }
    model.removeWidget(w);
    if (parentGroup != null) {
        // Check if this parent group is a remote label owner; if so, delete
        // the remote label as well
        deleteRemoteLabel(parentGroup, editSequence);
        if (moveSiblings) {
            int myGroupNum = parentGroup.size();
            if (parentGroup.getOrientation() == SimpleWidgetGroup.HORIZONTAL) {
                deltaX = -w.getEltBounds().width;
            } else if (parentGroup.getOrientation() == SimpleWidgetGroup.VERTICAL) {
                deltaY = -w.getEltBounds().height;
            }
            // This loop will be ineffective for grid buttons
            for (int i = atIndex + 1; i < myGroupNum; i++) {
                IWidget curWidget = parentGroup.get(i);
                curWidget.moveElement(deltaX, deltaY);
            }
        }
        // Otherwise, remove it from its parent group.
        if (w instanceof ChildWidget) {
            ChildWidget child = (ChildWidget) w;
            AParentWidget itemParent = child.getParent();
            itemParent.removeItem(child);
        } else {
            parentGroup.remove(w);
        }
        if (parentGroup instanceof GridButtonGroup) {
            GridButtonGroup gbg = (GridButtonGroup) parentGroup;
            GridButton gb = (GridButton) w;
            DoubleRectangle b = w.getEltBounds();
            double x = b.x + b.width;
            double y = b.y + b.height;
            double newHoriz = gb.getHorizSpace();
            double newVert = gb.getVertSpace();
            ReadOnlyList<GridButton> movedButtons = null;
            GridButton top = null;
            double dx = 0.0;
            double dy = 0.0;
            if (gbg.getColumn(gb).size() == 0) {
                // w was the only widget in the column; need to move next
                // column over
                movedButtons = gbg.getMovedButtons(false, x, b.y);
                if (movedButtons.size() > 0) {
                    top = movedButtons.get(0);
                    DoublePoint p = top.getShape().getOrigin();
                    dx = b.x - p.x;
                }
            } else {
                // need to move lower widgets up to fill the hole
                movedButtons = gbg.getMovedButtons(true, b.x, y);
                if (movedButtons.size() > 0) {
                    top = movedButtons.get(0);
                    DoublePoint p = top.getShape().getOrigin();
                    dy = b.y - p.y;
                }
            }
            if (top != null) {
                moveGridButton(FrameEditorLID.Delete, DELETE_WIDGET, top, dx, dy, newHoriz, newVert, editSequence);
            }
        }
    }
    DemoStateManager.IDesignUndoableEdit edit;
    // Add the deletion to the undoable history
    if (w instanceof ChildWidget) {
        ChildWidget child = (ChildWidget) w;
        final AParentWidget itemParent = child.getParent();
        edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {

            @Override
            public void redoHelper() {
                itemParent.removeItem((ChildWidget) widget);
            }

            @Override
            public void undoHelper() {
                itemParent.addItem(atIndex, (ChildWidget) widget);
            }
        };
    } else {
        edit = new DeleteWidgetUndoableEdit(w, parentGroup, atIndex, deltaX, deltaY) {

            @Override
            public void redoHelper() {
                parentGroup.remove(widget);
            }

            @Override
            public void undoHelper() {
                parentGroup.add(atIndex, widget);
            }
        };
    }
    demoStateMgr.noteWidgetEdit(w, edit);
    editSequence.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) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

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