xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lolling, Jan" <Jan.Loll...@t-systems.com>
Subject AW: Interactors and MouseEvents
Date Thu, 13 Mar 2003 15:32:22 GMT
Your way using interactors is correct. I do the same and it works fine.
Be aware, that your interactor will be invoked at the correct mouse-event.
The first think you must check is the startInteraction-method. I put into these method a System.out.println("invoke...")
debug output.

Adding your interactor to the actions is not necessary !

The next trick is to realize´: what returns my interactor at endInteraction().

Check the former messages in the mailing-list. I had added my example of an interactor-class.
My first example was the zoomInteractor too.

Yor method to manipulate the elements via DOM is absolut correct ! I also manipulate the DOM
but I don not need the 
class SVGGeneratorContext. We (me colleque and I) have build for each shape his own interactor

I recommend you to extends JSVGCanvas and create an new member variable to notify what element
tag you want to create and in the startInteraction() method ask for it.


-----Ursprüngliche Nachricht-----
Von: Eric Delacroix [mailto:edelax_tfe@hotmail.com]
Gesendet: Donnerstag, 13. März 2003 16:17
An: batik-users@xml.apache.org
Betreff: Re: Interactors and MouseEvents


I'm currently trying to do the same. I load a document in a Panel where 
there is an expension of the JSVGCanvas. I already use the zoom interactors 
that I customized and registered.
Now I want to make a new interactor, following the example of the zoom's 
So I made a class StiffAction, that extends AbstractAction, where I define 
the actionPerformed as a function that adds a shape to the DOM (I think I'll 
be doing that through the DOM, with an SVGGeneratorContext, somebody could 
tell me if I'm totally wrong)
I also wrote an AbstractStiffInteractor, where the methods for drawing the 
pre-shape on the canvas are defined. And In my extension of JSVGCanvas, I 
made an interactor extending this class.
Finally, I add this interactor in the constructor of MySVGCanvas (by doing 
getInteractor.add(stiffInteractor); and I also add this in the 
actionMap.But... it doesn't work :(
I'm explaining all this hoping somebody would understand the way I'm trying 
to do it, and maybe correct me.
The first problem I have is that when I add my new interactor, the 
link-function I made doesn't work anymore...
I know I'm not so clear, but the problem I have seems even nebulous...
Every help here is always a good help, thank you

Eric Delacroix
Faculté des Sciences appliquées
ULB Brussels

>From: "Baron, Randy {PRG~Basel}" <RANDY.BARON@Roche.COM>
>Reply-To: "Batik Users" <batik-users@xml.apache.org>
>To: batik-users@xml.apache.org
>Subject: Interactors and MouseEvents
>Date: Thu, 13 Mar 2003 12:54:48 +0100
>   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.
>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: " +
>             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: " +
>                 System.out.println(" text node item: " + " ele: " +
>          //   ....etc.

Utilisez votre MSN Messenger via votre GSM ! 

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

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

View raw message