Search in sources :

Example 6 with FrameElementGroup

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

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

the class FrameEditorController method deleteGroupMember.

private void deleteGroupMember(FrameElement elt, FrameElementGroup fromGroup, IUndoableEditSequence editSequence) {
    if (elt instanceof IWidget) {
        deleteWidget((IWidget) elt, false, fromGroup, editSequence);
    } else if (elt instanceof FrameElementGroup) {
        deleteFrameEltGroup((FrameElementGroup) elt, fromGroup, editSequence);
    } else if (elt instanceof SimpleWidgetGroup) {
        SimpleWidgetGroup parentGroup = (SimpleWidgetGroup) elt;
        while (parentGroup.size() > 0) {
            IWidget child = parentGroup.get(0);
            // If the widget group is itself a remote label owner,
            // its remote label will be deleted in the first call here.
            deleteWidget(child, false, fromGroup, editSequence);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 8 with FrameElementGroup

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

the class FrameEditorController method duplicateFrameEltGroup.

// duplicateWidget
private FrameElementGroup duplicateFrameEltGroup(FrameElementGroup grp, double moveByX, double moveByY) {
    // Temporarily assign the same name; when added to the Frame
    // we will ensure the name is then unique
    FrameElementGroup newEltGrp = grp.twin();
    Iterator<FrameElement> eltsToDup = grp.iterator();
    while (eltsToDup.hasNext()) {
        FrameElement elt = eltsToDup.next();
        FrameElement eltCopy = null;
        if (elt instanceof IWidget) {
            IWidget widget = (IWidget) elt;
            duplicateWidget(widget, null, moveByX, moveByY);
            eltCopy = widgetSituator.getDuplicate(widget);
        } else if (elt instanceof SimpleWidgetGroup) {
            SimpleWidgetGroup group = (SimpleWidgetGroup) elt;
            SimpleWidgetGroup groupCopy = widgetSituator.getGroup(group);
            Iterator<IWidget> groupWidgets = group.iterator();
            while (groupWidgets.hasNext()) {
                duplicateGroupMember(groupWidgets.next(), null, moveByX, moveByY);
            }
            Frame.duplicateRemoteLabel(group, groupCopy, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
            eltCopy = groupCopy;
        } else if (elt instanceof FrameElementGroup) {
            eltCopy = duplicateFrameEltGroup((FrameElementGroup) elt, moveByX, moveByY);
        }
        if (eltCopy != null) {
            newEltGrp.add(eltCopy);
        }
    }
    widgetSituator.setGroupDuplicate(grp, newEltGrp);
    Frame.duplicateRemoteLabel(grp, newEltGrp, lookupFrameDuplicator, widgetSituator, moveByX, moveByY);
    return newEltGrp;
}
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)

Example 9 with FrameElementGroup

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

the class FrameEditorController method isMemberOfSelectedGroup.

private boolean isMemberOfSelectedGroup(FrameElement elt, FrameEditorSelectionState seln) {
    FrameElement rootElt = elt.getRootElement();
    Iterator<FrameElementGroup> grps = rootElt.getEltGroups().iterator();
    // that is also selected, skip it
    while (grps.hasNext()) {
        if (seln.isElementSelected(grps.next())) {
            return true;
        }
    }
    return false;
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement)

Example 10 with FrameElementGroup

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

the class FrameEditorController method changeAuxTextProperty.

// createChangeTitlePropertyAction
private void changeAuxTextProperty(ListenerIdentifier lid, final String presentation, FrameElement elt, final String newText, IUndoableEditSequence editSequence) {
    if (elt instanceof IWidget) {
        final IWidget widget = (IWidget) elt;
        final String oldText = widget.getAuxiliaryText();
        if (!oldText.equals(newText)) {
            widget.setAuxiliaryText(newText);
            DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {

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

                @Override
                public void redo() {
                    // Redo the set auxiliary text
                    super.redo();
                    widget.setAuxiliaryText(newText);
                    noteEditCheckRegenerate(widget, this);
                }

                @Override
                public void undo() {
                    // Go back to old auxiliary text
                    super.undo();
                    widget.setAuxiliaryText(oldText);
                    noteEditCheckRegenerate(widget, this);
                }
            };
            noteEditCheckRegenerate(widget, edit);
            editSequence.addEdit(edit);
        }
    } else if (elt instanceof FrameElementGroup) {
        final FrameElementGroup eltGroup = (FrameElementGroup) elt;
        final String oldText = eltGroup.getAuxiliaryText();
        if (!oldText.equals(newText)) {
            eltGroup.setAuxiliaryText(newText);
            IUndoableEdit edit = new DemoStateManager.ObsoletingEdit(lid, demoStateMgr) {

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

                @Override
                public void redo() {
                    // Redo the set auxiliary text
                    super.redo();
                    eltGroup.setAuxiliaryText(newText);
                }

                @Override
                public void undo() {
                    // Go back to old auxiliary text
                    super.undo();
                    eltGroup.setAuxiliaryText(oldText);
                }
            };
            editSequence.addEdit(edit);
        }
    }
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)22 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)15 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)14 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 HashSet (java.util.HashSet)6 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)4 Iterator (java.util.Iterator)4 EmptyIterator (edu.cmu.cs.hcii.cogtool.util.EmptyIterator)3 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)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 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)2 FrameEditorSelectionState (edu.cmu.cs.hcii.cogtool.ui.FrameEditorSelectionState)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 Point (org.eclipse.draw2d.geometry.Point)2 Text (org.eclipse.swt.widgets.Text)2