Hi Grant,

Grant Mc Auley wrote:
Thank you for your reply.

I read through the FAQ about the UpdateManager, but I think my question
is more about how DOM events are related to AWT events.

In my code both DOM and AWT events are triggered by the same mouse
click, since the 'element' is also an EventTarget (whoops, should have
included EventTarget element = (EventTarget) element; in the code).
Here I need to ensure that mouseClicked() runs before handleEvent()
(which puts the element update in the UpdateManager's queue).

I would not mix the two - I would push everything one way or the other most likely to DOM as it contains the most information.

    In your example it would appear that you are not aware that the DOM MouseEvent
includes the fields clientX/Y (perhaps this is just a bad example?).  I believe
that essentially all the information from the AWT event is forwarded to DOM.

I guess I could set up some kind of wait()/notify() or join() scheme,
but I thought there might be a "best practice" guideline for this
situation.

Well I can tell you that generally (ignoring mouse event compression) the runnable is posted to the update manager from the event thread. So if you can get your AWT listener for mouse events fired before the canvas's you can ensure your code runs first (I believe there is some way to order AWT event listeners). Otherwise you need to move all this to a third thread where the two can synchronize (I don't suggest blocking either dispatch thread).

-----Original Message-----
From: Thomas DeWeese [mailto:[EMAIL PROTECTED] Sent: Monday, August 25, 2003 3:45 AM
To: Batik Users
Subject: Re: DOM vs. AWT Event timing



Grant Mc Auley wrote:


In my code below, I want to update an Element based on the

position of


the mouse in the JSVGCanvas.

Please read the FAQ on the Batik site, in particular the items that reference the UpdateManager.


Before adding "Thread.sleep(50)", I sometimes observed that the
'element' would update with an old 'xpos', i.e. apparently

the thread


that handles DOM events ran before the AWT Event thread.

My questions are: (1) am I correct in my DOM/AWT thread

diagnosis? If


so, what is the relationship between b/w such threads? (2)

is there a


preferred way to coordinate DOM and AWT events? (using a

Thread.sleep()


seems like a fragile solution in an environment when many

other threads


will be running)

// -------

canvas.addMouseListener(new MouseAdapter() {

     public void mouseClicked(MouseEvent e) {
       xpos = e.getX();
       ypos = e.getY();
     }

});

element.addEventListener("click", new EventListener() {

public void handleEvent(Event e) {

          UpdateManager um = canvas.getUpdateManager();
       um.getUpdateRunnableQueue().invokeLater(new Runnable() {

         public void run() {
           try {
             Thread.sleep(50);
           }
           catch (InterruptedException ex) {
           }

           element.setAttribute("x", Integer.toString(xpos));
         }

       });
     }

}

, false);

// -------





---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to