Search in sources :

Example 36 with IWidget

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

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

the class FrameEditorController method updateWidgetName.

/**
     * Update the widget's name.
     * The name must be unique.
     *
     * @param widget
     * @param newName
     * @return
     */
private boolean updateWidgetName(final IWidget widget, String tryName) {
    final String oldName = widget.getName();
    boolean notDone = true;
    do {
        if (tryName.length() == 0) {
            tryName = interaction.protestNameCannotBeEmpty(DEFAULT_WIDGET_PREFIX);
            // If canceled, indicate so; otherwise, test again
            if (tryName == null) {
                return false;
            }
        } else {
            IWidget widgetForName = model.getWidget(tryName);
            // then no change is necessary!
            if (widgetForName == widget) {
                notDone = false;
            } else if (widgetForName != null) {
                // A non-null widget for the tryName indicates a collision
                tryName = interaction.protestNameCollision(DEFAULT_WIDGET_PREFIX);
                // If canceled, indicate so; otherwise, test again
                if (tryName == null) {
                    return false;
                }
            } else {
                // Not canceled, not empty, and not a collision
                notDone = false;
                final String newName = tryName;
                model.setWidgetName(newName, widget);
                DemoStateManager.ObsoletingEdit edit = new DemoStateManager.ObsoletingEdit(FrameEditorLID.ChangeNameProperty, demoStateMgr) {

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

                    @Override
                    public void redo() {
                        super.redo();
                        model.setWidgetName(newName, widget);
                        noteEditCheckRegenerate(widget, this);
                    }

                    @Override
                    public void undo() {
                        super.undo();
                        model.setWidgetName(oldName, widget);
                        noteEditCheckRegenerate(widget, this);
                    }
                };
                noteEditCheckRegenerate(widget, edit);
                undoMgr.addEdit(edit);
            }
        }
    } while (notDone);
    return true;
}
Also used : IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 38 with IWidget

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

Example 39 with IWidget

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

the class FrameEditorController method renderGroup.

private void renderGroup(SimpleWidgetGroup group, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
    Iterator<IWidget> children = group.iterator();
    while (children.hasNext()) {
        IWidget w = children.next();
        if (w instanceof AParentWidget) {
            renderChildren((AParentWidget) w, rendered, oldRendered, edit);
        }
        renderWidget(w, rendered, oldRendered, edit);
    }
}
Also used : AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 40 with IWidget

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

the class FrameEditorController method getSelectedWidgets.

/**
     * Fetch all widgets referenced by the given selection sorted by
     * the given comparison function.
     */
private IWidget[] getSelectedWidgets(FrameEditorSelectionState seln, Comparator<? super IWidget> c) {
    IWidget[] widgets;
    Set<IWidget> allWidgets = new HashSet<IWidget>();
    Iterator<FrameElement> s = seln.getSelectedElementsIterator();
    while (s.hasNext()) {
        FrameElement elt = s.next();
        if (elt instanceof IWidget) {
            IWidget w = (IWidget) elt;
            SimpleWidgetGroup group = w.getParentGroup();
            if (group != null) {
                Iterator<IWidget> mbrs = group.iterator();
                while (mbrs.hasNext()) {
                    allWidgets.add(mbrs.next());
                }
            } else {
                allWidgets.add(w);
            }
        } else if (elt instanceof FrameElementGroup) {
            Iterator<IWidget> eltGrpWidgets = new ElementAllWidgetIterator((FrameElementGroup) elt);
            while (eltGrpWidgets.hasNext()) {
                allWidgets.add(eltGrpWidgets.next());
            }
        }
    }
    widgets = new IWidget[allWidgets.size()];
    allWidgets.toArray(widgets);
    Arrays.sort(widgets, c);
    return widgets;
}
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) HashSet(java.util.HashSet)

Aggregations

IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)93 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)29 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)20 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)19 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)15 FrameElementGroup (edu.cmu.cs.hcii.cogtool.model.FrameElementGroup)15 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)12 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)11 Point (org.eclipse.draw2d.geometry.Point)11 IListenerAction (edu.cmu.cs.hcii.cogtool.util.IListenerAction)10 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)9 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)9 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)9 HashSet (java.util.HashSet)8 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)7 InputDevice (edu.cmu.cs.hcii.cogtool.model.InputDevice)7 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)7 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)7 Iterator (java.util.Iterator)7 EventObject (java.util.EventObject)6