the tutorial is
http://www.xith.org/tutes/GettingStarted/html/picking.html
By my counts the mutex stuff will allow many mouse events to go past the rendering thread. OK for this example, but if you want to do something like mouse panning then you cant afford to lose a single mouse event. It could be the mouse release event.
Here is my bodged solution
synchronized (pickParamsMutex) {
while (mutexCount > 0) {
try {
if (e.getID() == MouseEvent.MOUSE_MOVED) {
return;
}
if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
return;
}
pickParamsMutex.wait();
} catch (InterruptedException e1) {
System.out.println("waiting AWT thread woken up");
}
}
mutexCount++;
}
lastMouseEvent = e;
Combined with
synchronized (pickParamsMutex) {
state = state.changeState(state, lastMouseEvent, canvas);
mutexCount--;
pickParamsMutex.notify();
}
this way all incoming mouse event are stopped at the top and are only let through one at a time. I have a supsicion the order may not be preserved though. So those who need it might need a list or something. I have also in my example thrown out the dragged and moved if they have to be delayed. Some will still get through, its jsut so I don’t get a massive pilup of those inessential events, enough will get through to my underlying behavour
Tom
