I have an existing document which has already been rendered. Now I
want to add another label to the document framed by a rectangle.
I construct the new node like this:
protected Element nodeRectangularVertexIdentifier(String name, String
rx) {
String[] parts = name.split(" to ");
Element node = getSVGDocument().createElementNS(svg, "rect");
node.setAttributeNS(null, "id", "f"+getIdNumber());
node.setAttributeNS(null, "width", "1");
node.setAttributeNS(null, "height", "1");
node.setAttributeNS(null, "rx", rx);
Element gNode = getSVGDocument().createElementNS(svg, "g");
gNode.setAttributeNS(null, "id", "t"+getIdNumber());
for (int i = 0; i < parts.length; i += 1) {
Element tNode = getSVGDocument().createElementNS(svg,
"text");
tNode.setAttributeNS(null, "id",
"t"+getIdNumber()+"-"+i);
tNode.setNodeValue(parts[i]);
gNode.appendChild(tNode);
}
node.appendChild(gNode);
return node;
}
Then I insert the node into the document:
getSVGDocument().getElementById("labels").appendChild(gNode);
Then I want to center the text and adjust the rectangle size so it
frames the text:
protected void bindRectangularVertexIdentifierSize() {
// System.out.println("bind sizes for "+object);
SVGTextElement textNode =
(SVGTextElement)getElementById("t"+getIdNumber()+"-0");
SVGRectElement rectNode =
(SVGRectElement)getElementById("f"+getIdNumber());
SVGRect box = textNode.getBBox();
float dx = box.getX()+box.getWidth()/2;
float dy = box.getY()+box.getHeight()/2;
textNode.setAttributeNS(null, "x", Float.toString(-dx));
textNode.setAttributeNS(null, "y", Float.toString(-dy));
box = textNode.getBBox();
rectNode.setAttributeNS(null, "x",
Float.toString(box.getX()-5));
rectNode.setAttributeNS(null, "y",
Float.toString(box.getY()-5));
rectNode.setAttributeNS(null, "width",
Float.toString(box.getWidth()+10));
rectNode.setAttributeNS(null, "height",
Float.toString(box.getHeight()+10));
}
But textNode.getBBox() returns null, because the text hasn't been rendered yet.
Is there any way to prompt the rendering to happen or to be notified
that the rendering is completed?
-- rec --
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]