|
hi- I'm
trying to figure out how to use the Interactors (and why actually, instead of
just using listeners). I made a
small test class that displays an svg document (a couple of circles) and adds a
custom Interactor. I wanted to
print out some info when I clicked on the JSVGCanvas, like what Element was
clicked on. I did this before in a
different way, by adding listeners to the JSVGCanvas (snippet below). I was wondering if the same info could
be obtained from within the Interactor context (some kind of 'casting' java.awt.event.MouseEvent
into an org.w3c.dom.events.MouseEvent)?
In the end I need to write a program that displays svg elements (no big
surprise) and allows the user to modify them (location or other properties) and
so need to know what element is clicked on. -Randy --------------------------- Snippet of code to get info about object clicked on: public void registerListeners() {
Element maindoc = (Element)
document.getDocumentElement();
EventTarget doctarg = (EventTarget) maindoc;
doctarg.addEventListener("click", new OnMouseClick(), false); } /**
Prints out some info about what was clicked on */ public class OnMouseClick implements
EventListener {
public void handleEvent(Event evt) {
int mx, my;
int sx, sy;
Element svgRoot = document.getDocumentElement();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
MouseEvent mevt = (MouseEvent) evt;
mx = mevt.getClientX();
my = mevt.getClientY();
sx = mevt.getScreenX();
sy = mevt.getScreenY();
SVGElement targ = (SVGElement) mevt.getTarget();
System.out.println("
Mouse X:" + mx + " Y: " + my);
System.out.println(" in screen coordinates - x: " +
sx + " y: " + sy);
System.out.println("
Type of event: " + mevt.getType());
System.out.println("
getTarget: " + mevt.getTarget());
System.out.println("
getCurrentTarget: " + mevt.getCurrentTarget());
System.out.println("
Element id = " + targ.getId());
if (targ instanceof
org.apache.batik.dom.svg.SVGOMTextElement) {
double maxX, maxY, minX, minY;
int rx, ry, rw, rh;
SVGOMTextElement ttarg = (SVGOMTextElement) targ;
SVGRect rectsiz = new AnSVGRect();
System.out.println("HIT SOME TEXT");
NodeList nlist = targ.getChildNodes();
System.out.println("
text node length: " +
nlist.getLength());
System.out.println(" text node item: " + " ele: " +
nlist.item(1));
// ....etc. |
- RE: Interactors and MouseEvents Baron, Randy {PRG~Basel}
- RE: Interactors and MouseEvents Thomas E Deweese
- Re: Interactors and MouseEvents Eric Delacroix
