Search code examples
javasvgbatik

Finding objects under mouse in a JSVGCanvas from Batik


I have a JSVGCanvas object from the Batik library from java. In my application, I am rendering several objects in a schematic. I require to know what component is below the mouse so I can render an appropiate tooltip and description that I am rendering from an external source.

My question is, how can I determine what objects are below the cursor at any given time?


Solution

  • If you know the objects, for which you want to add tooltips and descriptions, you can add EventListeners to each Object. I did the same in my applciation.

    For all relevant nodes, you do:

    org.w3c.dom.events.EventTarget t = (EventTarget) node;
    t.addEventListener("mouseover", new SvgOnHoverAction());
    

    where SvgOnHoverAction implements org.w3c.dom.events.EventListener

    there you do:

    public void handleEvent(Event evt) {
        Element target = (Element)evt.getCurrentTarget();
        ...
    }