Search in sources :

Example 16 with FrameElementGroup

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

the class FrameEditorController method createUngroupElementsAction.

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

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

        public boolean performAction(Object prms) {
            FrameEditorSelectionState selection = (FrameEditorSelectionState) prms;
            Iterator<FrameElement> selectedElts = selection.getSelectedElementsIterator();
            final Set<FrameElementGroup> selectedGroups = new HashSet<FrameElementGroup>();
            while (selectedElts.hasNext()) {
                FrameElement elt = selectedElts.next();
                if (elt instanceof FrameElementGroup) {
                    selectedGroups.add((FrameElementGroup) elt);
                } else {
                    selectedGroups.addAll(elt.getRootElement().getEltGroups());
                }
            }
            if (selectedGroups.size() > 0) {
                CompoundUndoableEdit editSequence = new CompoundUndoableEdit(UNGROUP_ELEMENTS, FrameEditorLID.Ungroup);
                Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                while (groups.hasNext()) {
                    FrameElementGroup group = groups.next();
                    ungroup(group, editSequence);
                    removeRootElement(UNGROUP_ELEMENTS, group, null, editSequence);
                }
                IUndoableEdit edit = new AUndoableEdit(FrameEditorLID.Ungroup) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                        while (groups.hasNext()) {
                            FrameElementGroup group = groups.next();
                            ungroup(group, null);
                        }
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        Iterator<FrameElementGroup> groups = selectedGroups.iterator();
                        while (groups.hasNext()) {
                            FrameElementGroup group = groups.next();
                            regroup(group);
                        }
                    }
                };
                editSequence.addEdit(edit);
                // Commit the edit
                editSequence.end();
                // Only add this edit if it is significant
                if (editSequence.isSignificant()) {
                    undoMgr.addEdit(editSequence);
                }
                return true;
            }
            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) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) HashSet(java.util.HashSet)

Example 17 with FrameElementGroup

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

the class FrameEditorController method removeRootElement.

private void removeRootElement(final String presentationName, final FrameElement rootElt, final FrameElementGroup fromGrp, IUndoableEditSequence editSequence) {
    Set<FrameElementGroup> rootEltGrps = rootElt.getEltGroups();
    int numGrps = rootEltGrps.size();
    if (numGrps > 0) {
        final List<FrameElementGroup> deleteGrps = new ArrayList<FrameElementGroup>(rootEltGrps);
        final int[] atIndexes = new int[numGrps];
        Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
        int i = 0;
        while (eltGrps.hasNext()) {
            FrameElementGroup grp = eltGrps.next();
            atIndexes[i++] = grp.indexOf(rootElt);
            if (grp != fromGrp) {
                grp.remove(rootElt);
                if (grp.size() == 1) {
                    ungroup(grp, editSequence);
                    removeRootElement(presentationName, grp, fromGrp, editSequence);
                }
            }
        }
        if (editSequence != null) {
            DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(FrameEditorLID.Delete, demoStateMgr) {

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

                @Override
                public void redo() {
                    super.redo();
                    Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
                    while (eltGrps.hasNext()) {
                        FrameElementGroup grp = eltGrps.next();
                        if (grp != fromGrp) {
                            grp.remove(rootElt);
                            if (grp.size() == 1) {
                                ungroup(grp, null);
                            }
                        }
                    }
                }

                @Override
                public void undo() {
                    super.undo();
                    Iterator<FrameElementGroup> eltGrps = deleteGrps.iterator();
                    int i = 0;
                    while (eltGrps.hasNext()) {
                        FrameElementGroup grp = eltGrps.next();
                        if (grp.size() == 1) {
                            regroup(grp);
                        }
                        grp.add(atIndexes[i++], rootElt);
                    }
                }
            };
            editSequence.addEdit(edit);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) IDesignUndoableEdit(edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint)

Example 18 with FrameElementGroup

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

the class DesignEditorCmd method pasteFrameElementGroup.

private static int pasteFrameElementGroup(FrameElementGroup eltGroup, Design design, int currentDeviceTypes, Frame frame, DemoStateManager mgr, IUndoableEditSequence editSeq, Set<FrameElementGroup> groups, Set<IWidget> addedRemoteLabels) {
    int numPasted = 0;
    makeEltGroupNameUnique(eltGroup, frame);
    groups.add(eltGroup);
    groups.addAll(eltGroup.getEltGroups());
    checkForRemoteLabel(eltGroup, addedRemoteLabels);
    Iterator<FrameElement> elementsToAdd = eltGroup.iterator();
    while (elementsToAdd.hasNext()) {
        FrameElement eltToAdd = elementsToAdd.next();
        if (eltToAdd instanceof IWidget) {
            numPasted += pasteWidget((IWidget) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        } else if (eltToAdd instanceof SimpleWidgetGroup) {
            numPasted += pasteWidgetGroup((SimpleWidgetGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        } else if (eltToAdd instanceof FrameElementGroup) {
            numPasted += pasteFrameElementGroup((FrameElementGroup) eltToAdd, design, currentDeviceTypes, frame, mgr, editSeq, groups, addedRemoteLabels);
        }
    }
    return numPasted;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 19 with FrameElementGroup

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

the class DesignEditorCmd method pasteElements.

// pasteFrameElementGroup
public static int pasteElements(Design design, final Frame frame, Collection<Object> objects, DemoStateManager mgr, IUndoableEditSequence editSequence) {
    // If given objects contain widgets, insert into the given frame
    if ((objects != null) && (objects.size() > 0)) {
        Iterator<Object> objIt = objects.iterator();
        Set<SimpleWidgetGroup> addedGroups = new HashSet<SimpleWidgetGroup>();
        final Set<IWidget> addedRemoteLabels = new HashSet<IWidget>();
        final Set<FrameElementGroup> addedEltGroups = new HashSet<FrameElementGroup>();
        int numPasted = 0;
        // May need to add a device
        int currentDeviceTypes = DeviceType.buildDeviceSet(design.getDeviceTypes());
        // create them.
        while (objIt.hasNext()) {
            Object o = objIt.next();
            if (o instanceof IWidget) {
                IWidget widget = (IWidget) o;
                numPasted += pasteWidget(widget, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
                SimpleWidgetGroup group = widget.getParentGroup();
                if (group != null) {
                    addedGroups.add(group);
                }
            } else if (o instanceof FrameElementGroup) {
                numPasted += pasteFrameElementGroup((FrameElementGroup) o, design, currentDeviceTypes, frame, mgr, editSequence, addedEltGroups, addedRemoteLabels);
            }
        }
        Iterator<SimpleWidgetGroup> groupsIter = addedGroups.iterator();
        while (groupsIter.hasNext()) {
            SimpleWidgetGroup group = groupsIter.next();
            repositionChildren(group);
            if (group instanceof GridButtonGroup) {
                ((GridButtonGroup) group).recalculateOffsets();
            }
            addedEltGroups.addAll(group.getEltGroups());
        }
        Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
        while (eltGroups.hasNext()) {
            frame.addEltGroup(eltGroups.next());
        }
        Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
        while (remoteLabels.hasNext()) {
            IWidget remoteLabel = remoteLabels.next();
            if (!frame.containsWidget(remoteLabel)) {
                String uniqueName = NamedObjectUtil.makeNameUnique(remoteLabel.getName(), frame.getWidgets());
                remoteLabel.setName(uniqueName);
                frame.addWidget(remoteLabel);
            }
        }
        IUndoableEdit edit = new AUndoableEdit(CogToolLID.Paste) {

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

            @Override
            public void redo() {
                super.redo();
                Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
                while (eltGroups.hasNext()) {
                    frame.addEltGroup(eltGroups.next());
                }
                Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
                while (remoteLabels.hasNext()) {
                    IWidget remoteLabel = remoteLabels.next();
                    if (!frame.containsWidget(remoteLabel)) {
                        frame.addWidget(remoteLabel);
                    }
                }
            }

            @Override
            public void undo() {
                super.undo();
                Iterator<FrameElementGroup> eltGroups = addedEltGroups.iterator();
                while (eltGroups.hasNext()) {
                    frame.removeEltGroup(eltGroups.next());
                }
                Iterator<IWidget> remoteLabels = addedRemoteLabels.iterator();
                while (remoteLabels.hasNext()) {
                    IWidget remoteLabel = remoteLabels.next();
                    if (frame.containsWidget(remoteLabel)) {
                        frame.removeWidget(remoteLabel);
                    }
                }
            }
        };
        editSequence.addEdit(edit);
        return numPasted;
    }
    return 0;
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) DoublePoint(edu.cmu.cs.hcii.cogtool.model.DoublePoint) AUndoableEdit(edu.cmu.cs.hcii.cogtool.util.AUndoableEdit) IUndoableEdit(edu.cmu.cs.hcii.cogtool.util.IUndoableEdit) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) HashSet(java.util.HashSet) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 20 with FrameElementGroup

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

the class FrameEditorInteraction method confirmDeleteElements.

/**
     * Delete confirmation method.
     */
public boolean confirmDeleteElements(FrameElement[] elements) {
    String msg = "";
    // Choose the message plural or singular.
    if (elements.length > 1) {
        msg = CONFIRM_DELETE_WIDGETS_MSG;
    } else {
        msg = CONFIRM_DELETE_ONE_WIDGET_MSG;
    }
    String[] eltNames = new String[elements.length];
    for (int i = 0; i < elements.length; i++) {
        FrameElement elt = elements[i];
        eltNames[i] = elt.getName();
        if ((elt instanceof FrameElementGroup) && ((eltNames[i] == null) || eltNames[i].equals(""))) {
            eltNames[i] = UNNAMED_WIDGET_GROUP_LABEL;
        }
    }
    return (SWT.OK == WindowUtil.presentConfirmItemsDialog(window, CONFIRM_TITLE, msg, eltNames));
}
Also used : FrameElementGroup(edu.cmu.cs.hcii.cogtool.model.FrameElementGroup) FrameElement(edu.cmu.cs.hcii.cogtool.model.FrameElement)

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