use of edu.cmu.cs.hcii.cogtool.model.Widget in project cogtool by cogtool.
the class BalsamiqButtonAPIConverter method parseWidgets.
/** Helper function used by importDesign.
* This method is used to parse the tags of each .bmml file in the directory
*
* @param document the root of the XML tree
* @param fileName the specified directory or file
* @return the newly created frame
*/
protected void parseWidgets(Node node, Frame frame) throws IOException {
NodeList children = node.getChildNodes();
if (node.getNodeName().equalsIgnoreCase(CONTROLS_ELT)) {
System.out.println("controls " + children.getLength());
/* The controls xml tag will have a list of children which are control xml tags.
* A Balsamiq control is similar to a CogTool widget */
for (int i = 0; i < children.getLength(); i++) {
Node controlTag = children.item(i);
String nodeName = controlTag.getNodeName();
if (nodeName.equalsIgnoreCase(CONTROL_ELT)) {
String balsamiqControlType = getAttributeValue(controlTag, CONTROL_TYPE_ATTR);
String widgetTypeString = (balsamiqControlType == null) ? null : getBMMLWidgetType(balsamiqControlType);
System.out.println("316-widgetTypeString " + widgetTypeString);
if (widgetTypeString.equals("group")) {
System.out.println("319-calling bmmlgroup");
parseBMMLGroup(controlTag, frame, null, 0.0, 0.0);
} else {
Widget widget = parseBMMLWidget(controlTag, frame, null, 0.0, 0.0);
if (widget != null) {
frame.addWidget(widget);
}
}
}
}
} else {
for (int i = 0; i < children.getLength(); i++) {
parseWidgets(children.item(i), frame);
}
}
}
use of edu.cmu.cs.hcii.cogtool.model.Widget 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.Widget 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.Widget in project cogtool by cogtool.
the class FrameEditorController method createSetRemoteLabelTextAction.
// createUngroupElementsAction
private IListenerAction createSetRemoteLabelTextAction() {
return new IListenerAction() {
public Class<?> getParameterClass() {
return FrameEditorUI.SetRemoteLabelTextParms.class;
}
public boolean performAction(Object prms) {
FrameEditorUI.SetRemoteLabelTextParms p = (FrameEditorUI.SetRemoteLabelTextParms) prms;
// Check p.selectedElement; must be an FrameElementGroup
// or an IWidget of WidgetType Button, PullDownList, Graffiti,
// or TextBox (whether IS_STANDARD or IS_CUSTOM) or an IWidget
// of WidgetType Radio, Check, or ListBoxItem if IS_STANDARD
// (in which case, the label belongs to the parent SimpleWidgetGroup)
FrameElement owningElt = p.selectedElement.getRemoteLabelOwner();
if (owningElt == null) {
interaction.protestUnsupportedLabelOwnerType();
return false;
}
IWidget remoteLabel = (IWidget) owningElt.getAttribute(WidgetAttributes.REMOTE_LABEL_ATTR);
// Already has a label; simply update
if (remoteLabel != null) {
changeTitleProperty(FrameEditorLID.SetRemoteLabelText, SET_REMOTE_LABEL, remoteLabel, p.newText, // not a separator!
false, undoMgr);
} else if ((p.newText != null) && !p.newText.equals("")) {
CompoundUndoableEdit editSequence = new CompoundUndoableEdit(SET_REMOTE_LABEL, FrameEditorLID.SetRemoteLabelText);
final double INITIAL_WIDTH = 100.0;
final double INITIAL_HEIGHT = 16.0;
final double MIN_MARGIN = 5.0;
final double EXTRA_MARGIN = 10.0;
DoubleRectangle eltBds = owningElt.getEltBounds();
double maxY = eltBds.y - INITIAL_HEIGHT - MIN_MARGIN;
DoubleRectangle labelBds;
if (0.0 <= maxY) {
labelBds = new DoubleRectangle(eltBds.x, Math.max(0.0, maxY - EXTRA_MARGIN), INITIAL_WIDTH, INITIAL_HEIGHT);
} else {
double maxX = Math.max(0.0, eltBds.x - INITIAL_WIDTH - MIN_MARGIN);
labelBds = new DoubleRectangle(Math.max(0.0, maxX - EXTRA_MARGIN), eltBds.y, INITIAL_WIDTH, INITIAL_HEIGHT);
}
remoteLabel = new Widget(labelBds, WidgetType.Text);
DefaultCmd.setAttribute(owningElt, demoStateMgr, WidgetAttributes.REMOTE_LABEL_ATTR, remoteLabel, interaction, editSequence);
remoteLabel.setAttribute(WidgetAttributes.IS_STANDARD_ATTR, WidgetAttributes.IS_CUSTOM);
remoteLabel.setAttribute(WidgetAttributes.REMOTE_LABEL_OWNER_ATTR, owningElt);
remoteLabel.setName(generateUniqueWidgetName());
remoteLabel.setTitle(p.newText);
// Add the new widget to the undo system and to the model
editSequence.addEdit(addWidget(remoteLabel));
// Commit the edit
editSequence.end();
// Only add this edit if it is significant
if (editSequence.isSignificant()) {
undoMgr.addEdit(editSequence);
}
}
return true;
}
};
}
use of edu.cmu.cs.hcii.cogtool.model.Widget 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;
}
};
}
Aggregations