Search in sources :

Example 1 with PullDownItem

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

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

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

Example 4 with PullDownItem

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

the class SEDemoController method toggleIfGermane.

private boolean toggleIfGermane(IWidget widget, AScriptStep selfTransitionStep, AAction action) {
    WidgetType widgetType = widget.getWidgetType();
    ActionType actionType = action.getType();
    if (widget.isStandard() && ((actionType == ActionType.Tap) || ((actionType == ActionType.ButtonPress) && (((ButtonAction) action).getButton() == MouseButtonState.Left)))) {
        if (widgetType == WidgetType.Check) {
            selfTransitionStep.overrideAttribute(widget, WidgetAttributes.IS_SELECTED_ATTR, WidgetAttributes.TOGGLE_SELECTION);
        } else if (widgetType == WidgetType.Radio) {
            selfTransitionStep.overrideAttribute(widget.getParentGroup(), WidgetAttributes.SELECTION_ATTR, widget);
        } else if (widgetType == WidgetType.Button) {
            // Override regardless of the button's "toggleability"
            // because the user can always change this attribute in the
            // frame
            selfTransitionStep.overrideAttribute(widget, WidgetAttributes.IS_SELECTED_ATTR, WidgetAttributes.TOGGLE_SELECTION);
        } else if (widgetType == WidgetType.PullDownItem) {
            PullDownItem pdi = (PullDownItem) widget;
            Object value = pdi.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
            if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, value)) {
                selfTransitionStep.overrideAttribute(pdi.getParent(), WidgetAttributes.SELECTION_ATTR, widget);
            }
        }
        return true;
    } else {
        return false;
    }
}
Also used : ActionType(edu.cmu.cs.hcii.cogtool.model.ActionType) PullDownItem(edu.cmu.cs.hcii.cogtool.model.PullDownItem) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType)

Aggregations

PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)4 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)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 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)2 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)2 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)1 ActionType (edu.cmu.cs.hcii.cogtool.model.ActionType)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 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)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