Batik provides a fairly complete implementation of the
SVG DOM. The SVG DOM provides all the functionality most
applications require. In particular the DOM implements
DOM Events including mutation and UI Events.
DOM events allow you to get notified when the cursor
moves over elements of interest:
| | |
|
// Element of Interest.
Element theElem;
((EventTarget)theElem).addEventListener("mouseover", mouseOverListener, true);
| |
| | |
Where mouseOverListener implements the
org.w3c.dom.events.EventListener interface.
This interface consists of the method:
| | |
|
public void handleEvent(Event evt);
| |
| | |
This is called whenever the event occurs with the
element it is registered on. It is worth reviewing the
DOM Events specification as there are many useful features
to this interface that are not immediately obvious.
It is also worth looking at the DOM interfaces defined
by the SVG specification as they provide a large number
of useful methods, in particular the SVGLocatable:
| | |
|
// Returns Bounding box of SVG Element.
public SVGRect getBBox ( );
// Returns the transformation matrix to the screen.
public SVGMatrix getScreenCTM ( );
// Returns the transformation matrix to the given element.
public SVGMatrix getTransformToElement ( SVGElement element )
throws SVGException;
| |
| | |
In particular getScreenCTM is very useful for
taking the 'clientX', 'clientY' attributes of the
DOM UIEvent and mapping them to the coordinate system
of an element in the SVG document:
| | |
|
SVGMatrix mat = elem.getScreenCTM();
SVGMatrix imat = mat.inverse();
SVGPoint cPt = document.getRootElement().createSVGPoint();
cPt.setX(uiEvt.clientX);
cPt.setY(uiEvt.clientY);
cPt = cPt.matrixTransform(imat);
| |
| | |