Hi Scheit,
Scheit Christoph wrote:
I have a problem to fill elements of a group. I tried the following:
if (elemToMark.getTagName().equals("g")) {
System.out.println("Group found: " + elemToMark.getId());
elemToMark.setAttributeNS(null, "stroke-width", "6.0");
elemToMark.setAttributeNS(null, "stroke", "black");
elemToMark.setAttributeNS(null, "fill", "blue");
}
I noticed, that setting the stroke attribute works, but not filling
the elements of the group....
This will only set the fill of the children if they don't
already have a fill/stroke specification. I suspect the
children of the group already have a fill but perhaps not a
stroke (or at least not a stroke-width specification).
I also had the idea to loop over all elements of the group, but
I had some problems to get the SVGElements from the group,
I just get the Nodes....
First you should use the DOM 2 classes not the Batik internal
implementation classes for DOM. You want to check the node type:
Node childNode = ...;
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Element childElem = (Element)child;
for (int i = 0; i < size; i++) {
Node node = nodeList.item(i);
SVGOMElement child = (SVGOMElement) node;
child.setAttribute(....)
I will also mention that the basic structure of DOM
is a linked list, so using Element.getFirstChild() and
getNextSibling() are significantly more efficient than using
the nodeList interface.
.... and end up in a ClassCastException if I try this (of course).
Is there a proper way to change the attributes of the elements
of a group?
It is also possible to do this using CSS style sheets with
selectors (take a look at the CSS 2 spec) as a general solution
it isn't great but in some cases it can be quite convenient.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]