Age Bosma wrote:
2009/1/29 <[email protected]>:
Hi Age,
Age Bosma <[email protected]> wrote on 01/28/2009 02:43:51 PM:
Age Bosma wrote:
getTarget() Always gives me the referenced element if someone clicked
on the 'use' element and thus e.g. the id of the rect. This is fine if
someone actually clicked on the 'rect' element but I'd like to know
which 'use' element was clicked (the id of the use element) if someone
clicked on that.
Well you can walk up the tree from the clicked element to the
use element. In Batik the elements are all basically normal DOM elements
(they should be SVGElementInstance references). In anycase you should
be able to use 'getParentNode()' (java) or 'parentNode' (ecmascript) to
walk up the tree checking if the element is a use element or not.
The problem is that I'm unable to get to a use element. If I click on
a use element, I'm getting exactly the same back as when I click on
the element the use element is referencing (getNodeName(), getId(),
etc.). If you look at the initial e-mail describing the situation,
getNodeName() will always be 'rect' even if I click on the use
element. The same goes for the Id.
A use element does not contain any children, it only references an
element to get a clone. getParentNode() is therefor no option to get
to the use element.
Age
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
Hi, Age,
I think this is really a W3C DOM navigation question but I suppose Batik
has something to do with the DOM ;-) I think you need to climb the DOM
from your target and 'escape' from the local use element <defs>
reference using this test of each Node n (quick and dirty):
if (n instanceof SVGOMCSSImportedElementRoot){
n=((SVGOMCSSImportedElementRoot)n).getCSSParentElement();
}
It was a bit of a bear to figure that out and maybe someone could tell
me an easier way or better way!
Then test for the custom attribute that Thomas mentioned. I haven't
implemented your exact case, but in a separate part of my app I supply
an SVGElement as a DOMTreeWalker root with a filter like so:
class ReceptorsAll implements NodeFilter {
public short acceptNode(Node n) {
String segtype = ((SVGElement)n).getAttributeNS(null,
"segtype");
if (n.getNodeType() == Node.ELEMENT_NODE) {
if (segtype.equals("receptor") &&
(n.getNodeName().equalsIgnoreCase("g")
|| n.getNodeName().equalsIgnoreCase("use"))
) {
return FILTER_ACCEPT;
} else return FILTER_SKIP;
} else
return FILTER_SKIP;
}
As you see, the filter is pretty highly coupled to my DOM structure and
looks for the custom attribute. Then I extract all the id's from the
walker's children.
I will probably have to implement some version of what you're doing in
the future, so I'd be curious as to your solution. Hope this helps...
Dan Slater
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]