use of org.w3c.dom.NodeList in project cogtool by cogtool.
the class BalsamiqButtonAPIConverter method checkWidgetGroupType.
//TODO: check if the widgets align best horizontally or vertically
//align the widgets to average coord, first, left or rightmost
//prohibit the dimensions at the api level
/** Helper function used by parseWidget
* This method is used to verify that all widgets in a group are of the same type
*
* @param groupXMLNode the node that represents a group
*/
public WidgetType checkWidgetGroupType(Node groupXMLNode) {
NodeList children = groupXMLNode.getChildNodes();
String balsamiqGroupControlType = null;
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
String nodeName = child.getNodeName();
String balsamiqControlType = getAttributeValue(child, CONTROL_TYPE_ATTR);
/*double x =
Double.parseDouble(getAttributeValue(child, X_ATTR));
double y =
Double.parseDouble(getAttributeValue(child, Y_ATTR));*/
System.out.println("713 - WidgetGroupType- nodeName " + nodeName + " " + balsamiqControlType);
if (balsamiqGroupControlType != null && balsamiqControlType != null && !balsamiqGroupControlType.equals(balsamiqControlType)) {
return null;
} else if (balsamiqControlType != null) {
balsamiqGroupControlType = balsamiqControlType;
}
/*if(j==0){
initialX = x;
initialY = y;
}
else
{
if(x != initialX){
xCoordAlign = false;
}
if(y != initialY){
yCoordAlign = false;
}
}*/
}
String widgetTypeString = (balsamiqGroupControlType == null) ? null : getBMMLWidgetType(balsamiqGroupControlType);
System.out.println("724 " + widgetTypeString);
/*if(xCoordAlign || yCoordAlign)
{*/
return getWidgetType(widgetTypeString);
/*}
else
{
return null;
}*/
}
use of org.w3c.dom.NodeList 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 org.w3c.dom.NodeList in project cogtool by cogtool.
the class BalsamiqButtonAPIConverter method parseFrame.
/** Helper function used by importDesign.
* This method is used to parse the tags of each .bmml file and assign the
* attributes of the frame to the frame object
*
* @param document the root of the XML tree
* @param fileName the specified directory or file
* @return the newly created frame
*/
protected Frame parseFrame(Node document, String fileName) throws IOException {
// This adds the created frame to the design
Frame frame = getFrame(fileName);
if (frame == null) {
throw new RcvrImportException("Null Frame.");
}
//addAttributes(frame, node);
Frame.setFrameDevices(frame, design.getDeviceTypes());
NodeList children = document.getChildNodes();
double frameWidth = 0;
double frameHeight = 0;
if (children != null) {
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeName().equalsIgnoreCase(MOCKUP_ELT)) {
frameWidth = Integer.parseInt(getAttributeValue(child, MEASURED_WIDTH_ATTR));
frameHeight = Integer.parseInt(getAttributeValue(child, MEASURED_HEIGHT_ATTR));
}
}
}
//TODO: if it doesnt import anything, a new frame window should still be imported?
parseWidgets(document, frame);
return frame;
}
use of org.w3c.dom.NodeList in project cw-omnibus by commonsguy.
the class WeatherFragment method buildForecasts.
private ArrayList<Forecast> buildForecasts(String raw) throws Exception {
ArrayList<Forecast> forecasts = new ArrayList<Forecast>();
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(raw)));
NodeList times = doc.getElementsByTagName("start-valid-time");
for (int i = 0; i < times.getLength(); i++) {
Element time = (Element) times.item(i);
Forecast forecast = new Forecast();
forecasts.add(forecast);
forecast.setTime(time.getFirstChild().getNodeValue());
}
NodeList temps = doc.getElementsByTagName("value");
for (int i = 0; i < temps.getLength(); i++) {
Element temp = (Element) temps.item(i);
Forecast forecast = forecasts.get(i);
forecast.setTemp(Integer.valueOf(temp.getFirstChild().getNodeValue()));
}
NodeList icons = doc.getElementsByTagName("icon-link");
for (int i = 0; i < icons.getLength(); i++) {
Element icon = (Element) icons.item(i);
Forecast forecast = forecasts.get(i);
forecast.setIcon(icon.getFirstChild().getNodeValue());
}
return (forecasts);
}
use of org.w3c.dom.NodeList in project cw-android by commonsguy.
the class StaticFileDemo method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
try {
InputStream in = getResources().openRawResource(R.raw.words);
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(in, null);
NodeList words = doc.getElementsByTagName("word");
for (int i = 0; i < words.getLength(); i++) {
items.add(((Element) words.item(i)).getAttribute("value"));
}
in.close();
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
}
Aggregations