Search in sources :

Example 1 with MenuItem

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

the class FrameEditorUI method confirmRenameFigure.

protected void confirmRenameFigure() {
    if ((editor != null) && editor.inUse()) {
        String newTitle = editor.getText();
        editor.cleanup();
        // figure whose title is currently being edited
        IFigure figure = (IFigure) editor.getData();
        if (figure instanceof PotentialFigure) {
            if ("".equals(newTitle)) {
                // nothing to do if empty string on potential item!
                return;
            }
            GraphicalTraversableWidget<?> parent = potentialUIFig.getFigureOwner();
            TraversableWidget parentModel = (TraversableWidget) parent.getModel();
            boolean isRightPotentialFigure = (figure == potentialUIFig.getRightFigure());
            WidgetType type = null;
            AParentWidget header = null;
            SimpleWidgetGroup group = null;
            boolean isSeparator = false;
            if (parentModel instanceof MenuItem) {
                type = WidgetType.MenuItem;
                MenuItem parentItem = (MenuItem) parentModel;
                if (isRightPotentialFigure) {
                    // position of selected figure is on the right
                    // parent menuitem becomes a submenu; figure to be
                    // created becomes a child of the submenu
                    parentItem.setSubmenu(true);
                    header = parentItem;
                } else {
                    // if position is on the bottom and the parent is not a
                    // header, put the new widget in the same menu as the
                    // parent item
                    header = parentItem.getParent();
                    // previous item should hide children if it's a submenu
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                }
                if (parentModel.getWidgetType() != WidgetType.Submenu) {
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ContextMenu) {
                header = (ContextMenu) parentModel;
                type = WidgetType.MenuItem;
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof MenuHeader) {
                // and hide children of the previous header
                if (isRightPotentialFigure) {
                    type = WidgetType.Menu;
                    ((GraphicalParentWidget<?, ?>) parent).closeChildren();
                    group = parentModel.getParentGroup();
                } else {
                    header = (MenuHeader) parentModel;
                    type = WidgetType.MenuItem;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownItem) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    PullDownItem parentItem = (PullDownItem) parentModel;
                    header = parentItem.getParent();
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof PullDownHeader) {
                type = WidgetType.PullDownItem;
                if (!isRightPotentialFigure) {
                    header = (PullDownHeader) parentModel;
                    isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
                }
            } else if (parentModel instanceof ListItem) {
                type = WidgetType.ListBoxItem;
                group = parentModel.getParentGroup();
                isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            } else if (parentModel instanceof GridButton) {
                type = parentModel.getWidgetType();
                group = parentModel.getParentGroup();
            }
            Rectangle r = ((PotentialFigure) figure).getUnscaledBounds();
            DoubleRectangle bounds = new DoubleRectangle(r.x, r.y, r.width, r.height);
            performAction(CogToolLID.NewWidget, new FrameEditorUI.NewWidgetParameters(bounds, header, type, view.isAutomaticCreation(), newTitle, group, isSeparator));
        } else {
            boolean isSeparator = GraphicalWidgetRenderer.SEPARATOR_STRING.equals(newTitle);
            performAction(FrameEditorLID.ChangeTitleProperty, new FrameEditorUI.ActionStringParameters(newTitle, selection, isSeparator), true);
        }
    }
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) GraphicalMenuHeader(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalMenuHeader) Rectangle(org.eclipse.draw2d.geometry.Rectangle) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) GraphicalContextMenu(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalContextMenu) AParentWidget(edu.cmu.cs.hcii.cogtool.model.AParentWidget) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) PotentialFigure(edu.cmu.cs.hcii.cogtool.view.PotentialFigure) TraversableWidget(edu.cmu.cs.hcii.cogtool.model.TraversableWidget) GraphicalTraversableWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalTraversableWidget) GraphicalGridButton(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalGridButton) GridButton(edu.cmu.cs.hcii.cogtool.model.GridButton) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) GraphicalListItem(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalListItem) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) GraphicalParentWidget(edu.cmu.cs.hcii.cogtool.uimodel.GraphicalParentWidget) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with MenuItem

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

the class DesignExportToHTML method buildItemsString.

protected String buildItemsString(Iterator<IWidget> children) {
    StringBuilder itemString = new StringBuilder();
    itemString.append("[\n");
    while (children.hasNext()) {
        MenuItem child = (MenuItem) children.next();
        itemString.append("  { text: \"" + child.getTitle() + "\"");
        if (child.isSubmenu()) {
            itemString.append(", submenu: { id: \"" + child.getName() + "\", itemdata: " + buildItemsString(child.getChildren().iterator()) + "} ");
        } else {
            itemString.append(", onclick: { fn: menuTransition, obj: ");
            String menuMap = getMenuMap(child);
            itemString.append(menuMap + "\n}\n");
        }
        itemString.append("},\n");
    }
    itemString.append("  ]");
    return itemString.toString();
}
Also used : MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem)

Example 3 with MenuItem

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

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

the class FrameEditorController method createNewWidgetAction.

/**
     * Create a ListenerAction to handle creating a new Widget.
     *
     */
private IListenerAction createNewWidgetAction() {
    return new AListenerAction() {

        public boolean performAction(Object prms) {
            // TODO: Should we provide more input to this default widget?
            // Dialog box with option?
            // Current/last palette setting
            // TODO: Bonnie wanted to have new widgets show up under the
            // mouse.  To do that we need to do something like
            // getCursorLocation() (from display)
            // offset based on the (0,0) of the window
            // Might want to get that based on GetCursorControl().
            // If working with the control, you need to walk the tree to
            // get the actual offset from 0,0, in the display.
            //
            // Alternatively, in specialize, get the mouse pointer position
            // from mousestate (but that would require tracking the mouse
            // state -- on hover at least).
            // Instantiate the appropriate widget. If the class was passed
            // a prms, use that to dictate what to do.
            Widget widget = null;
            CompoundUndoableEdit editSequence = new CompoundUndoableEdit(NEW_WIDGET, FrameEditorLID.NewWidget);
            if (prms instanceof FrameEditorUI.NewWidgetParameters) {
                FrameEditorUI.NewWidgetParameters nwp = (FrameEditorUI.NewWidgetParameters) prms;
                // widget
                if (nwp.parent != null) {
                    if (nwp.type == WidgetType.MenuItem) {
                        // Create menu item; may become a submenu through
                        // user interaction later
                        widget = new MenuItem((AMenuWidget) nwp.parent, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.PullDownItem) {
                        widget = new PullDownItem((PullDownHeader) nwp.parent, nwp.bounds, nwp.widgetTitle);
                        boolean rendered = nwp.parent.isRendered();
                        SimpleWidgetGroup group = widget.getParentGroup();
                        group.setAttribute(WidgetAttributes.IS_RENDERED_ATTR, Boolean.valueOf(rendered));
                    }
                } else // widget group
                if (nwp.parentGroup != null) {
                    if (nwp.type == WidgetType.Menu) {
                        widget = new MenuHeader(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.ListBoxItem) {
                        widget = new ListItem(nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.Radio) {
                        widget = new RadioButton((RadioButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    } else if (nwp.type == WidgetType.Check) {
                        widget = new CheckBox((GridButtonGroup) nwp.parentGroup, nwp.bounds, nwp.widgetTitle);
                    }
                } else {
                    widget = createWidget(nwp.type, nwp.bounds, nwp.widgetTitle, nwp.isAutomatic);
                }
                if (nwp.isSeparator) {
                    frameSetAttribute(widget, WidgetAttributes.IS_SEPARATOR_ATTR, WidgetAttributes.IS_SEPARATOR, editSequence);
                }
            }
            //                if (widget.getWidgetType() == WidgetType.TextBox) {
            //                    widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR,
            //                                        WidgetAttributes.IS_CUSTOM);
            //                }
            // Auto-generate a unique name for the widget
            widget.setName(generateUniqueWidgetName());
            // Build the widget: check for uniqueness and add to the frame
            boolean result = addCreatedWidget(widget, editSequence);
            editSequence.end();
            undoMgr.addEdit(editSequence);
            return result;
        }
    };
}
Also used : SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) AListenerAction(edu.cmu.cs.hcii.cogtool.util.AListenerAction) 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) MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) AMenuWidget(edu.cmu.cs.hcii.cogtool.model.AMenuWidget) RadioButton(edu.cmu.cs.hcii.cogtool.model.RadioButton) FrameEditorUI(edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 5 with MenuItem

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

the class DesignEditorCmd method addChildWidgets.

private static void addChildWidgets(SimpleWidgetGroup widgetGroup, Frame f) {
    if (widgetGroup != null) {
        Iterator<IWidget> children = widgetGroup.iterator();
        while (children.hasNext()) {
            IWidget child = children.next();
            makeWidgetNameUnique(child, f);
            f.addWidget(child);
            if (child instanceof MenuItem) {
                MenuItem item = (MenuItem) child;
                if (item.isSubmenu()) {
                    addChildWidgets(item.getChildren(), f);
                }
            }
        }
    }
}
Also used : MenuItem(edu.cmu.cs.hcii.cogtool.model.MenuItem) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget)

Aggregations

MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)8 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)5 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)4 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)3 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)3 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)2 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)2 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)2 CompoundUndoableEdit (edu.cmu.cs.hcii.cogtool.util.CompoundUndoableEdit)2 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)1 CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)1 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)1 GridButton (edu.cmu.cs.hcii.cogtool.model.GridButton)1 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1 RadioButton (edu.cmu.cs.hcii.cogtool.model.RadioButton)1 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)1