Search in sources :

Example 6 with AParentWidget

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

the class FrameEditorController method renderChildren.

private void renderChildren(AParentWidget parent, boolean rendered, boolean oldRendered, CompoundUndoableEdit edit) {
    if (parent.hasChildren()) {
        Iterator<IWidget> children = parent.getChildren().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 7 with AParentWidget

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

the class FrameEditorController method setAsSeparator.

// assignActions
private boolean setAsSeparator(final IWidget widget, final Object value, final ChildWidget oldSelectedItem, IUndoableEditSequence editSeq) {
    final String IS_SEP_ATTR = WidgetAttributes.IS_SEPARATOR_ATTR;
    final Object oldValue = widget.getAttribute(IS_SEP_ATTR);
    final DoubleRectangle bounds = widget.getEltBounds();
    final double oldHeight = bounds.height;
    final double newHeight = WidgetAttributes.IS_SEPARATOR.equals(value) ? (oldHeight / FrameEditorUI.SEPARATOR_RATIO) : (oldHeight * FrameEditorUI.SEPARATOR_RATIO);
    final boolean isAuto = widget.isStandard();
    final SimpleWidgetGroup group = widget.getParentGroup();
    final AParentWidget pullDown = (oldSelectedItem != null) ? oldSelectedItem.getParent() : null;
    if (widget.equals(oldSelectedItem)) {
        // the currently selected widget in the pull down
        // has changed to a separator; deselect it
        pullDown.setAttribute(WidgetAttributes.SELECTION_ATTR, WidgetAttributes.NONE_SELECTED);
    }
    widget.setAttribute(IS_SEP_ATTR, value);
    if (isAuto) {
        widget.setWidgetSize(bounds.width, newHeight);
        DesignEditorCmd.repositionChildren(widget.getParentGroup());
    }
    if (editSeq != null) {
        DemoStateManager.IDesignUndoableEdit edit = new DemoStateManager.InvalidatingEdit(CogToolLID.SetAttribute, demoStateMgr) {

            @Override
            public String getPresentationName() {
                return DefaultCmd.SET_ATTRIBUTE;
            }

            @Override
            public void redo() {
                super.redo();
                if (widget.equals(oldSelectedItem)) {
                    pullDown.setAttribute(WidgetAttributes.SELECTION_ATTR, WidgetAttributes.NONE_SELECTED);
                }
                widget.setAttribute(IS_SEP_ATTR, value);
                if (isAuto) {
                    widget.setWidgetSize(bounds.width, newHeight);
                    DesignEditorCmd.repositionChildren(group);
                }
                stateMgr.noteWidgetEdit(widget, this);
            }

            @Override
            public void undo() {
                super.undo();
                if (widget.equals(oldSelectedItem)) {
                    pullDown.setAttribute(WidgetAttributes.SELECTION_ATTR, oldSelectedItem);
                }
                widget.setAttribute(IS_SEP_ATTR, oldValue);
                if (isAuto) {
                    widget.setWidgetSize(bounds.width, oldHeight);
                    DesignEditorCmd.repositionChildren(group);
                }
                stateMgr.noteWidgetEdit(widget, this);
            }
        };
        demoStateMgr.noteWidgetEdit(widget, edit);
        editSeq.addEdit(edit);
    }
    return true;
}
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)

Example 8 with AParentWidget

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

the class FrameEditorController method createSetRenderSkinAction.

private IListenerAction createSetRenderSkinAction() {
    return new IListenerAction() {

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

        public boolean performAction(Object prms) {
            FrameEditorUI.SetRenderSkinParameters p = (FrameEditorUI.SetRenderSkinParameters) prms;
            // Iterate through selected objects.
            Iterator<IWidget> selected = p.selection.getSelectedWidgetsIterator();
            CompoundUndoableEdit editSeq = new CompoundUndoableEdit(CHG_WIDGET_RENDERED, FrameEditorLID.SetRenderSkin);
            while (selected.hasNext()) {
                IWidget w = selected.next();
                if (w instanceof TraversableWidget) {
                    AParentWidget parent = null;
                    if (w instanceof MenuItem) {
                        parent = ((MenuItem) w).getTopHeader();
                        if (parent == null) {
                            // parent is a context menu
                            parent = ((MenuItem) w).getParent();
                        }
                    } else if (w instanceof ChildWidget) {
                        parent = ((ChildWidget) w).getParent();
                    } else if (w instanceof AParentWidget) {
                        parent = (AParentWidget) w;
                    }
                    if (parent != null) {
                        SimpleWidgetGroup group = parent.getParentGroup();
                        if (group != null) {
                            //menu header
                            renderGroup(group, p.rendered, parent.isRendered(), editSeq);
                        } else {
                            //pull down header
                            renderWidget(parent, p.rendered, parent.isRendered(), editSeq);
                            renderChildren(parent, p.rendered, parent.isRendered(), editSeq);
                        }
                    } else if (w.getParentGroup() != null) {
                        //list box item or radio button
                        renderGroup(w.getParentGroup(), p.rendered, w.isRendered(), editSeq);
                    }
                } else {
                    renderWidget(w, p.rendered, w.isRendered(), editSeq);
                }
            }
            editSeq.end();
            // Only add this edit if it is significant
            if (editSeq.isSignificant()) {
                undoMgr.addEdit(editSeq);
            }
            return true;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) CompoundUndoableEdit(edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) IListenerAction(edu.cmu.cs.hcii.cogtool.util.IListenerAction) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Example 9 with AParentWidget

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

Example 10 with AParentWidget

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

the class FrameEditorController method frameSetAttribute.

// setAsSeparator
// xxy for remote label, do we set both directions (here??)
private boolean frameSetAttribute(IAttributed target, final String attrName, final Object value, IUndoableEditSequence editSeq) {
    if (attrName.equals(WidgetAttributes.IS_SEPARATOR_ATTR)) {
        ChildWidget selectedItem = null;
        if (target instanceof PullDownItem) {
            AParentWidget pullDown = ((PullDownItem) target).getParent();
            selectedItem = (ChildWidget) pullDown.getAttribute(WidgetAttributes.SELECTION_ATTR);
        }
        return setAsSeparator((IWidget) target, value, selectedItem, editSeq);
    }
    return DefaultCmd.setAttribute(target, demoStateMgr, attrName, value, interaction, editSeq);
}
Also used : PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) ChildWidget(edu.cmu.cs.hcii.cogtool.model.ChildWidget)

Aggregations

AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)23 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)11 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)11 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)10 DoublePoint (edu.cmu.cs.hcii.cogtool.model.DoublePoint)8 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)5 IDesignUndoableEdit (edu.cmu.cs.hcii.cogtool.controller.DemoStateManager.IDesignUndoableEdit)4 DoubleSize (edu.cmu.cs.hcii.cogtool.model.DoubleSize)4 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)4 FrameElement (edu.cmu.cs.hcii.cogtool.model.FrameElement)3 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)3 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)3 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)2 GraphicalChildWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalChildWidget)2 GraphicalMenuItem (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuItem)2 GraphicalParentWidget (edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget)2