xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Age Bosma <agebo...@gmail.com>
Subject Determine clicked 'use' element
Date Wed, 14 Jan 2009 09:04:10 GMT
Hi,

Is there a way to determine which 'use' element is clicked? The only
thing I'm getting back all the time is the referenced element.

The svg file:
----------------------------------------------------------------------------
<svg ... >
    <g id="device">
        <rect id="rectxx" ... />
        <text ... /> ... </text>
    </g>
    <use id="used_device" xlink:href="#device" ... />
</svg>
----------------------------------------------------------------------------

Attach the listener to the document root:
----------------------------------------------------------------------------
SVGSVGElement svgRoot = svgDoc.getRootElement();

EventTarget et = (EventTarget) svgRoot;
et.addEventListener("click", new DeviceHandler(), false);
----------------------------------------------------------------------------

Listener class:
----------------------------------------------------------------------------
public class DeviceHandler implements EventListener {
    public void handleEvent(Event evt) {
        SVGElement targetElement = (SVGElement) evt.getTarget();
        SVGElement parentElement = (SVGElement) targetElement.getParentNode();

        System.out.println("Target id: no clue...");
        System.out.println("Referenced id: " + targetElement.getId());
        System.out.println("Parent id:" + parentElement.getId());
    }
}
----------------------------------------------------------------------------

The reason I'm attaching the listener to the document root is because
the are quite a few elements of which I want to determine if someone
clicked on it.
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.
Using getCurrentTarget() instead of getTarget() always gives me the
'svg' element, so that doesn't appear to be useful either.

How should one determine which 'use' element is clicked on?

Yours,

Age Bosma

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message