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]



Reply via email to