Search in sources :

Example 1 with CheckBox

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

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

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

the class BalsamiqButtonAPIConverter method parseBMMLWidget.

/** Helper function used by parseFrame
	 * This method is used to parse the tags of each control tag in Balsamiq XML. A control tag
	 * represents a Balsamiq Widget.
     * 
     * @param  node a node of the tree that represents a Balsamiq widget
     * @frame  frame that the widget is being added to
     * @group  parent group
     * @groupX x coordinate of parent group
     * @groupY y coordinate of parent group
     * @return      the newly created widget
     */
protected Widget parseBMMLWidget(Node node, Frame frame, SimpleWidgetGroup group, double groupX, double groupY) throws IOException {
    System.out.println("parseBMMLWidget " + group + " x: " + groupX + "y: " + groupY);
    NodeList children = node.getChildNodes();
    Widget widget = null;
    WidgetType widgetType = null;
    String balsamiqControlType = getAttributeValue(node, CONTROL_TYPE_ATTR);
    String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
    String widgetName = getAttributeValue(node, CONTROL_ID_ATTR);
    if (widgetName == null) {
    //TODO: make a random widget name and move on. report to the user. need to be unique within the frame. Frame.java has a method for this
    }
    System.out.println("462- wN " + widgetName + "widT " + widgetTypeString);
    if (widgetTypeString == null) {
    //TODO: report to the user
    } else {
        widgetType = getWidgetType(widgetTypeString);
        //Parse the widget name, location and size from the attributes of the XML tag
        //TODO: Error check all of the getAttributeValues()
        double x = Double.parseDouble(getAttributeValue(node, X_ATTR));
        double y = Double.parseDouble(getAttributeValue(node, Y_ATTR));
        //TODO: difference between w and measuredW, same for height
        double width = Integer.parseInt(getAttributeValue(node, BWIDTH_ATTR));
        double height = Integer.parseInt(getAttributeValue(node, BHEIGHT_ATTR));
        double measWidth = Integer.parseInt(getAttributeValue(node, MEASURED_WIDTH_ATTR));
        double measHeight = Integer.parseInt(getAttributeValue(node, MEASURED_HEIGHT_ATTR));
        if (//TODO: make sure the dimensions are positive
        width == -1 && height == -1) {
            System.out.println("493- changing widget dimensions");
            width = measWidth;
            height = measHeight;
        }
        /*bounds is the size and location of the widget*/
        if (group != null) {
            System.out.println("488-Group is not null");
            DoubleRectangle rect = group.getGroupBounds();
            if (rect != null) {
                System.out.println("500-rect is not null");
            //x += groupX;
            //y += groupY;
            }
        }
        x += groupX;
        y += groupY;
        System.out.println("new widget has dimens:" + x + " " + y);
        DoubleRectangle bounds = new DoubleRectangle(x, y, width, height);
        if (widgetType == WidgetType.Check) {
            System.out.println("505-The widget is a check so now make a group for it");
            if (group == null) {
                group = new GridButtonGroup();
                //give it a random widget name										
                group.setName("newName");
                groupRegistry.put("newName", group);
            }
            //if(group instanceof GridButtonGroup)
            //{
            int eltCount = group.elementCount();
            System.out.println("513-group is gridbuttongroup " + group.getName() + " " + eltCount);
            if (eltCount > 0) {
                //TODO: check if the widgets align best horizontally or vertically
                //align the widgets to average coord, first, left or rightmost
                IWidget wid = group.getElement(group.elementCount() - 1);
                DoubleRectangle bounds2 = wid.getEltBounds();
                System.out.println("530 " + bounds2.getX() + " " + bounds2.getWidth() + " " + bounds2.getY() + " " + bounds2.getHeight());
                double diffX = Math.abs(x - bounds2.getX());
                double diffY = Math.abs(y - bounds2.getY());
                System.out.println("diffX " + diffX + " " + diffY);
                DoubleRectangle bounds3 = new DoubleRectangle(bounds2.getX() + bounds2.getWidth(), bounds2.getY(), width, height);
                if (diffX < diffY) {
                    bounds3 = new DoubleRectangle(bounds2.getX(), bounds2.getY() + bounds2.getHeight(), width, height);
                }
                widget = new CheckBox((GridButtonGroup) group, bounds3, widgetName);
            } else {
                widget = new CheckBox((GridButtonGroup) group, bounds, widgetName);
            }
            widget.setWidgetType(widgetType);
        /*}
				else
				{
					System.out.println("517-group2 is gridbuttongroup");
					GridButtonGroup group2 = new GridButtonGroup();
					group2.setName("newNameCheck");										
					groupRegistry.put("newNameCheck", group2);
					widget = new CheckBox(group2, bounds, widgetName);
					//group.addElement((IWidget) group2);

				}*/
        } else {
            widget = new Widget(bounds, widgetType);
        }
        widget.setName(widgetName);
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            String nodeName = child.getNodeName();
            /*Whitespace in the DOM tree is represented as #text. Ignore these nodes. Anywhere between the open and closed tag*/
            if (!nodeName.equals("#text")) {
                if (nodeName.equalsIgnoreCase(CONTROL_PROP_ELT)) {
                    NodeList controlTags = child.getChildNodes();
                    for (int j = 0; j < controlTags.getLength(); j++) {
                        Node controlTag = controlTags.item(j);
                        String propertyTag = controlTag.getNodeName();
                        //CogTool widget Display Label
                        if (propertyTag.equalsIgnoreCase(BALSAMIQ_TEXT_ELT)) {
                            /*Must decode the title. For instance the title in
							    Balsamiq, "First%20Frame" is "First Frame" in CogTool*/
                            String title = getElementText(controlTag);
                            title = URLDecoder.decode(title, "UTF-8");
                            widget.setTitle(title);
                        } else //CogTool transition on the present widget
                        if (propertyTag.equalsIgnoreCase(HREF_ELT)) {
                            String destinationFileName = getElementText(controlTag);
                            File destinationFile = new File(designPathName, destinationFileName);
                            //Make sure the file exists before attempting to parse the file
                            if (destinationFile.exists()) {
                                parseBalsamiqFile(destinationFile);
                                parseTransition(destinationFileName, widget);
                            }
                        } else if (propertyTag.equalsIgnoreCase(STATE_ELT)) {
                            //TODO: work on states
                            //A Balsamiq Button can be normal, selected, or disabled
                            String state = getElementText(controlTag);
                            if (state.equals("selected")) {
                                widget.setAttribute(WidgetAttributes.IS_SELECTED_ATTR, Boolean.TRUE);
                            } else {
                            //TODO: Other Balsamiq states like "disabled", "disabled and selected"
                            }
                        }
                    // END OF STATE OF BUTTON
                    }
                // END OF PROPERTY TAG
                }
            // END OF CONTROL PROPERTIES TAG
            }
        }
    }
    widget.setRendered(true);
    return widget;
}
Also used : CheckBox(edu.cmu.cs.hcii.cogtool.model.CheckBox) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) Widget(edu.cmu.cs.hcii.cogtool.model.Widget) WidgetType(edu.cmu.cs.hcii.cogtool.model.WidgetType) DoubleRectangle(edu.cmu.cs.hcii.cogtool.model.DoubleRectangle) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) GridButtonGroup(edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)

Aggregations

CheckBox (edu.cmu.cs.hcii.cogtool.model.CheckBox)3 GridButtonGroup (edu.cmu.cs.hcii.cogtool.model.GridButtonGroup)3 IWidget (edu.cmu.cs.hcii.cogtool.model.IWidget)3 Widget (edu.cmu.cs.hcii.cogtool.model.Widget)3 AMenuWidget (edu.cmu.cs.hcii.cogtool.model.AMenuWidget)2 AParentWidget (edu.cmu.cs.hcii.cogtool.model.AParentWidget)2 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 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 ContextMenu (edu.cmu.cs.hcii.cogtool.model.ContextMenu)1 DeviceType (edu.cmu.cs.hcii.cogtool.model.DeviceType)1 DoubleRectangle (edu.cmu.cs.hcii.cogtool.model.DoubleRectangle)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 WidgetType (edu.cmu.cs.hcii.cogtool.model.WidgetType)1