int xOffset = 0;
int yOffset = 0;
// calculating negative offsets;
for (Node node : definition.getNodes()) {
Rectangle constraints = node.getConstraint();
if (constraints.x < xOffset) {
xOffset = constraints.x;
}
if (constraints.y < yOffset) {
yOffset = constraints.y;
}
for (Transition transition : node.getLeavingTransitions()) {
for (Bendpoint bendpoint : transition.getBendpoints()) {
if (bendpoint.getX() < xOffset) {
xOffset = bendpoint.getX();
}
if (bendpoint.getY() < yOffset) {
yOffset = bendpoint.getY();
}
}
}
}
for (Node node : definition.getNodes()) {
Element element = addElement(root, NODE_ELEMENT_NAME);
addAttribute(element, NAME_ATTRIBUTE_NAME, node.getName());
Rectangle constraint = node.getConstraint();
if (constraint.width == 0 || constraint.height == 0) {
throw new Exception("Invalid figure size: " + constraint.getSize());
}
addAttribute(element, X_ATTRIBUTE_NAME, String.valueOf(constraint.x - xOffset));
addAttribute(element, Y_ATTRIBUTE_NAME, String.valueOf(constraint.y - yOffset));
addAttribute(element, WIDTH_ATTRIBUTE_NAME, String.valueOf(constraint.width));
addAttribute(element, HEIGHT_ATTRIBUTE_NAME, String.valueOf(constraint.height));