Search in sources :

Example 1 with RadioButton

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

the class FrameEditorController method createWidget.

private Widget createWidget(WidgetType defaultType, DoubleRectangle bounds, String widgetTitle, boolean isStandard) {
    Widget widget;
    // the user specified actual bounds interactively
    if (isStandard) {
        if (defaultType == WidgetType.Menu) {
            SimpleWidgetGroup newMenuHeaderGroup = new SimpleWidgetGroup(SimpleWidgetGroup.HORIZONTAL);
            widget = new MenuHeader(newMenuHeaderGroup, bounds, widgetTitle);
        } else if (defaultType == WidgetType.PullDownList) {
            widget = new PullDownHeader(bounds, widgetTitle);
        } else if (defaultType == WidgetType.ContextMenu) {
            widget = new ContextMenu(bounds, widgetTitle);
            // The default value for CONTEXT_MENU_ACTION_ATTR
            // is RIGHT_CLICK; must change to TAP_HOLD if the devices
            // contain a Touchscreen but not a Mouse
            Set<DeviceType> deviceTypes = design.getDeviceTypes();
            if (deviceTypes.contains(DeviceType.Touchscreen) && !deviceTypes.contains(DeviceType.Mouse)) {
                widget.setAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR, WidgetAttributes.TAP_HOLD);
            }
        } else if (defaultType == WidgetType.ListBoxItem) {
            SimpleWidgetGroup newListItemGroup = new SimpleWidgetGroup(SimpleWidgetGroup.VERTICAL);
            widget = new ListItem(newListItemGroup, bounds, widgetTitle);
            newListItemGroup.setAttribute(WidgetAttributes.FIRST_VISIBLE_ATTR, widget);
        } else if (defaultType == WidgetType.Radio) {
            RadioButtonGroup newRadioGroup = new RadioButtonGroup();
            widget = new RadioButton(newRadioGroup, bounds, widgetTitle);
        } else if (defaultType == WidgetType.Check) {
            GridButtonGroup newCheckGroup = new GridButtonGroup();
            widget = new CheckBox(newCheckGroup, bounds, widgetTitle);
        } else {
            // Create new widget in specified location
            // Note: could be a child widget;
            //       if so, the user is managing the hierarchy!
            widget = new Widget(bounds, defaultType);
        }
        widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_STANDARD);
    } else {
        // Create new widget in specified location
        // Note: could be a child widget;
        //       if so, the user is managing the hierarchy!
        widget = new Widget(bounds, defaultType);
        widget.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
    }
    return widget;
}
Also used : DeviceType(edu.cmu.cs.hcii.cogtool.model.DeviceType) SimpleWidgetGroup(edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup) MenuHeader(edu.cmu.cs.hcii.cogtool.model.MenuHeader) CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) 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) RadioButtonGroup(edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup) ContextMenu(edu.cmu.cs.hcii.cogtool.model.ContextMenu) PullDownHeader(edu.cmu.cs.hcii.cogtool.model.PullDownHeader) ListItem(edu.cmu.cs.hcii.cogtool.model.ListItem) RadioButton(edu.cmu.cs.hcii.cogtool.model.RadioButton) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Example 2 with RadioButton

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

Aggregations

AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)2 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)2 CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)2 ChildWidget (edu.cmu.cs.hcii.cogtool.model.ChildWidget)2 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)2 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)2 ListItem (edu.cmu.cs.hcii.cogtool.model.ListItem)2 MenuHeader (edu.cmu.cs.hcii.cogtool.model.MenuHeader)2 RadioButton (edu.cmu.cs.hcii.cogtool.model.RadioButton)2 SimpleWidgetGroup (edu.cmu.cs.hcii.cogtool.model.SimpleWidgetGroup)2 TraversableWidget (edu.cmu.cs.hcii.cogtool.model.TraversableWidget)2 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)2 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)1 MenuItem (edu.cmu.cs.hcii.cogtool.model.MenuItem)1 PullDownHeader (edu.cmu.cs.hcii.cogtool.model.PullDownHeader)1 PullDownItem (edu.cmu.cs.hcii.cogtool.model.PullDownItem)1 RadioButtonGroup (edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup)1 FrameEditorUI (edu.cmu.cs.hcii.cogtool.ui.FrameEditorUI)1 AListenerAction (edu.cmu.cs.hcii.cogtool.util.AListenerAction)1