use of edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup in project cogtool by cogtool.
the class BalsamiqButtonAPIConverter method parseBMMLGroup.
// parseBMMLWidget
//TODO: probably need to give the group dimensions
/** 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 Group.
*
* @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 new group containing widgets
*/
public void parseBMMLGroup(Node groupXMLtag, Frame frame, SimpleWidgetGroup parentGroup, double initX, double initY) {
SimpleWidgetGroup widgetGrp = null;
NodeList groupSubtags = groupXMLtag.getChildNodes();
String grpName = getAttributeValue(groupXMLtag, CONTROL_ID_ATTR);
double x = Double.parseDouble(getAttributeValue(groupXMLtag, X_ATTR));
double y = Double.parseDouble(getAttributeValue(groupXMLtag, Y_ATTR));
x += initX;
y += initY;
if (grpName == null) {
//TODO: report to the user
}
System.out.println("587-GROUP " + grpName);
if ((grpName != null) && !"".equals(grpName)) {
widgetGrp = groupRegistry.get(grpName);
for (int i = 0; i < groupSubtags.getLength(); i++) {
Node groupSubtag = groupSubtags.item(i);
String groupSubtagName = groupSubtag.getNodeName();
System.out.println("598-nodeName1 " + groupSubtagName);
/*Whitespace in the DOM tree is represented as #text. Ignore these nodes*/
if (!groupSubtagName.equals("#text")) {
if (groupSubtagName.equalsIgnoreCase("groupChildrenDescriptors")) {
System.out.println("605-groupchildrendescriptors");
WidgetType groupType = checkWidgetGroupType(groupSubtag);
if (groupType != null) {
System.out.println("630-groupwidgetType " + groupType.getName());
} else {
System.out.println("groupwidgetType is null");
}
NodeList children2 = groupSubtag.getChildNodes();
for (int j = 0; j < children2.getLength(); j++) {
Node child3 = children2.item(j);
String nodeName3 = child3.getNodeName();
System.out.println("657- nodeName3 " + nodeName3 + " j is " + j + " length " + children2.getLength());
if (nodeName3.equalsIgnoreCase(CONTROL_ELT)) {
System.out.println("660-This is a control!");
Widget widget2 = null;
if (widgetGrp == null) {
if (groupType == WidgetType.Radio) {
widgetGrp = new RadioButtonGroup();
} else if (groupType == WidgetType.Check) {
System.out.println("654-grouptype is a check");
widgetGrp = new GridButtonGroup();
} else {
widgetGrp = new SimpleWidgetGroup(1);
}
widgetGrp.setName(grpName);
groupRegistry.put(grpName, widgetGrp);
}
try {
String balsamiqControlType = getAttributeValue(child3, CONTROL_TYPE_ATTR);
String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
System.out.println("663-widgetTypeString " + widgetTypeString);
if (widgetTypeString.equals("group")) {
System.out.println("682-calling bmmlgroup");
parseBMMLGroup(child3, frame, widgetGrp, x, y);
}
widget2 = parseBMMLWidget(child3, frame, widgetGrp, x, y);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int widgetCount = widgetGrp.elementCount();
System.out.println("692- WIDGET COUNT for " + grpName + ": " + widgetCount + " " + widget2.getName());
if (widget2 != null) {
//TODO: check widget does not need to be added here
//widgetGrp.addElement(widget2);
widget2.setParentGroup(widgetGrp);
//frame.addEltGroup(gridWidgetGrp);
frame.addWidget(widget2);
widgetLoader.set(widget2, Widget.widgetTypeVAR, widget2.getWidgetType());
//AShape widgetShape = widget2.getShapeType();
//if (widgetShape != null) {
// widgetLoader.set(widget2, Widget.shapeVAR, widgetShape);
// }
}
System.out.println("696-widget2 added");
}
}
}
}
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup 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;
}
use of edu.cmu.cs.hcii.cogtool.model.RadioButtonGroup in project cogtool by cogtool.
the class WidgetPropertiesPane method showAttributeWidgets.
public void showAttributeWidgets(IWidget widget) {
WidgetType type = widget.getWidgetType();
widgetTitle.setText(DISPLAYED_LABEL);
Object pathObj = widget.getAttribute(WidgetAttributes.IMAGE_PATH_ATTR);
if (!NullSafe.equals(WidgetAttributes.NO_IMAGE, pathObj)) {
String imgPath = (String) pathObj;
imagePath.setVisible(true);
imagePathText.setVisible(true);
imagePathText.setText(imgPath);
imagePathText.setSelection(imgPath.length());
}
if ((type == WidgetType.MenuItem) || (type == WidgetType.PullDownItem) || (type == WidgetType.ListBoxItem)) {
isSeparator.setVisible(true);
Object value = widget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
boolean isSep = NullSafe.equals(WidgetAttributes.IS_SEPARATOR, value);
isSeparator.setSelection(isSep);
widgetTitleText.setEnabled(!isSep);
widgetAuxText.setEnabled(!isSep);
}
// Remote label support
// First check if this is a remote label
FrameElement remoteLabelOwner = (FrameElement) widget.getAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR);
if (remoteLabelOwner != null) {
String ownerWidgetName = remoteLabelOwner.getName();
if ((ownerWidgetName == null) || ownerWidgetName.equals("")) {
if (remoteLabelOwner instanceof RadioButtonGroup) {
ownerWidgetName = "[ anonymous radio button group ]";
} else if (remoteLabelOwner instanceof GridButtonGroup) {
ownerWidgetName = "[ anonymous checkbox group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ anonymous widget group ]";
} else if (remoteLabelOwner instanceof SimpleWidgetGroup) {
ownerWidgetName = "[ unnamed element group ]";
} else {
ownerWidgetName = "[ unnamed widget ]";
}
}
this.remoteLabelOwner.setVisible(true);
remoteLabelOwnerName.setVisible(true);
remoteLabelOwnerName.setText("<a>" + ownerWidgetName + "</a>");
remoteLabelType.setVisible(true);
remoteLabelTypeCombo.setVisible(true);
selectCurrentValue(remoteLabelTypeCombo, widgetTypeChoices, widget.getWidgetType());
imagePath.setLayoutData(isRemoteLabelAlign);
} else {
// Otherwise, check if this widget has a remote label
remoteLabelOwner = widget.getRemoteLabelOwner();
// reset layout to eliminate space for the remote label
if (remoteLabelOwner == null) {
imagePath.setLayoutData(noRemoteLabelAlign);
} else {
IWidget remoteLabelWidget = (IWidget) remoteLabelOwner.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
if (remoteLabelWidget != null) {
remoteLabelText.setText(remoteLabelWidget.getTitle());
remoteLabelFind.setVisible(true);
} else {
// Display an empty remote label stuff to allow one to be set
remoteLabelText.setText("");
remoteLabelFind.setVisible(false);
}
remoteLabel.setVisible(true);
remoteLabelText.setVisible(true);
imagePath.setLayoutData(hasRemoteLabelAlign);
}
}
if (!widget.isStandard()) {
layout();
return;
}
if ((type == WidgetType.Menu) || (type == WidgetType.ContextMenu)) {
submenuActionLabel.setVisible(true);
submenuAction.setVisible(true);
submenuDelayLabel.setVisible(true);
submenuDelay.setVisible(true);
Integer submenuAction = (Integer) widget.getAttribute(WidgetAttributes.SUBMENU_ACTION_ATTR);
selectCurrentValue(this.submenuAction, submenuActions, submenuAction);
Double delay = (Double) widget.getAttribute(WidgetAttributes.SUBMENU_DELAY_ATTR);
if (NullSafe.equals(WidgetAttributes.NO_SUBMENU_DELAY, delay)) {
submenuDelay.select(0);
} else if (NullSafe.equals(WidgetAttributes.PC_SUBMENU_DELAY, delay)) {
submenuDelay.select(1);
} else {
submenuDelay.setText(delay.toString() + " s");
}
if (type == WidgetType.ContextMenu) {
contextMenuActionLabel.setVisible(true);
contextMenuAction.setVisible(true);
Integer contextAction = (Integer) widget.getAttribute(WidgetAttributes.CONTEXT_MENU_ACTION_ATTR);
selectCurrentValue(contextMenuAction, contextMenuActions, contextAction);
}
}
if (type == WidgetType.Check) {
isInitiallySelected.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isInitiallySelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.Button) {
// TODO: "clicked-on" for Link?
isToggleable.setVisible(true);
Boolean selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_TOGGLEABLE_ATTR);
isToggleable.setSelection(selected.booleanValue());
isButtonSelected.setEnabled(selected.booleanValue());
isButtonSelected.setVisible(true);
selected = (Boolean) widget.getAttribute(WidgetAttributes.IS_SELECTED_ATTR);
isButtonSelected.setSelection(selected.booleanValue());
} else if (type == WidgetType.TextBox) {
// this.isMultiLine.setVisible(true);
//
// Boolean multi =
// (Boolean) widget.getAttribute(WidgetType.IS_MULTILINE_ATTR);
//
// this.isMultiLine.setSelection(multi.booleanValue());
widgetTitle.setText(TEXT_CONTENTS);
} else if (type == WidgetType.Radio) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
RadioButtonGroup group = (RadioButtonGroup) widget.getParentGroup();
if (group != null) {
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
map[i++] = curWidget;
String name = curWidget.getNameLabel();
initiallySelected.add(name);
}
// This works because null isn't in the list so indexOf
// returns -1 if SELECT_NONE is chosen
int index = group.indexOf(group.getSelection()) + 1;
initiallySelected.select(index);
selectionAttrListener.setAttributeHelper(RADIO_HELPER, map);
}
} else if (type == WidgetType.PullDownList) {
selectLabel.setVisible(true);
initiallySelected.setVisible(true);
initiallySelected.removeAll();
initiallySelected.add(SELECT_NONE);
initiallySelected.select(0);
SimpleWidgetGroup group = ((AParentWidget) widget).getChildren();
Iterator<IWidget> widgets = group.iterator();
IWidget[] map = new IWidget[group.size()];
int i = 0;
Widget selected = (Widget) widget.getAttribute(WidgetAttributes.SELECTION_ATTR);
while (widgets.hasNext()) {
IWidget curWidget = widgets.next();
Object isSep = curWidget.getAttribute(WidgetAttributes.IS_SEPARATOR_ATTR);
if (NullSafe.equals(WidgetAttributes.NON_SEPARATOR, isSep)) {
String name = curWidget.getNameLabel();
initiallySelected.add(name);
if (curWidget == selected) {
initiallySelected.select(i + 1);
}
map[i++] = curWidget;
}
}
selectionAttrListener.setAttributeHelper(PULLDOWN_HELPER, map);
}
// TODO implement list box support
// else if (type == WidgetType.ListBoxItem) {
// this.selectLabel.setVisible(true);
// this.initiallySelected.setVisible(true);
// this.initiallySelected.removeAll();
// this.initiallySelected.add(SELECT_NONE);
// this.visibleLabel.setVisible(true);
// this.firstVisible.setVisible(true);
// this.firstVisible.removeAll();
// this.numVisibleLabel.setVisible(true);
// this.numVisible.setVisible(true);
//
// SimpleWidgetGroup group = widget.getParentGroup();
//
// Integer num =
// (Integer) group.getAttribute(WidgetType.NUM_VISIBLE_ATTR);
// this.numVisible.setSelection(num.intValue());
//
// Iterator<IWidget> widgets = group.getAllWidgets();
// while (widgets.hasNext()) {
// IWidget curWidget = widgets.next();
// String name = curWidget.getDisplayLabel();
// this.initiallySelected.add(name);
// this.firstVisible.add(name);
// }
//
// IWidget init =
// (IWidget) group.getAttribute(WidgetType.SELECTION_ATTR);
// int ind = group.indexOf(init) + 1;
// this.initiallySelected.select(ind);
// init = (IWidget) group.getAttribute(WidgetType.FIRST_VISIBLE_ATTR);
// ind = group.indexOf(init);
// this.firstVisible.select(ind);
// }
layout();
}
Aggregations