For months, my Windows users have reported an occasional problem: the user
clicks the mouse once, but sees two click events. (This is on a simple SVG
object, like a rectangle, with an onclick="func()" attribute. The func()
function runs twice.)
After grepping furiously through the source, I find this code in
swing/gvt/AbstractJGVTComponent.java, and it seems to be the source of the
problem:
public void mouseReleased(java.awt.event.MouseEvent e) {
if ((checkClick) && hadDrag) {
int dx = startX-e.getX();
int dy = startY-e.getY();
long cTime = System.currentTimeMillis();
if ((dx*dx+dy*dy < MAX_DISP) &&
(cTime-startTime) < CLICK_TIME) {
// our drag was short! dispatch a CLICK event.
//
MouseEvent click = new MouseEvent
(e.getComponent(),
MouseEvent.MOUSE_CLICKED,
e.getWhen(),
e.getModifiers(), // modifiers
e.getX(),
e.getY(),
e.getClickCount(),
e.isPopupTrigger());
mouseClicked(click);
}
}
checkClick = false;
hadDrag = false;
Originally I thought this was the source of the standard "down+up ->
click" mouse events. But it's not. This code only fires when hadDrag is
true, which occurs when a mouseDragged event shows up.
So if the user clicks the mouse and releases it, this code does *not* run;
a MOUSE_CLICKED event occurs from some other piece of code. But if the
user clicks the mouse, moves it *just a little* (less than MAX_DISP) and
quickly (faster than CLICK_TIME), then this code *does* run -- but the
other click event occurs anyway. So the document sees two onclick events,
and then I get a bug report, and then I weep.
This only seems to happen on Windows. On the Mac, if this bit of code
runs, then the other click event *doesn't* occur. At least, that's what I
see -- I never notice two events coming from the same click.
This code seems to exist in order to tolerate very slight mouse movements
during a click. That's fine, but the value of that is crushed by the
possibility of duplicate events.
(In case it matters: I compiled Batik on the Mac with Java 1.5.0_06-64.
The Windows box I'm testing with has Java 1.5.0_06-b05.)
--Z
--
Andrew Plotkin [EMAIL PROTECTED] Volity Games
*
"And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]