Monday, 11 June 2007

Fixed an elementary bug in the touchgraph library.

Last Friday I was pleased to get to the bottom of a bug that had been noticed by a number of people for a while now. The eProfile project uses the touchgraph library and it had been noticed by various people that certain popup menus only ever appeared on the Windows platform; never on Mac or Linux. For a cross-platform technology like Java, this had always struck me as daft! Anyway, it was actually quite an elementary mistake in the touchgraph library. There are numerous MouseListener inner-class adapters throughout the code that get informed of various types of mouse event. There is in fact a isPopupTrigger() method on the MouseEvent class that gets passed as a parameter to these adapters. All I did was hovered my mouse over the isPopupTrigger() method to get the javadoc - this is what it said:

Returns whether or not this mouse event is the popup menu trigger event for the platform.

Note: Popup menus are triggered differently on different systems. Therefore, isPopupTrigger should be checked in both mousePressed and mouseReleased for proper cross-platform functionality.


Code was only looking for this in the mouseReleased() event, not the corresponding mousePressed() event too! Therefore, to make it cross-platform compatible all I had to do was extract the code that responded to the popup trigger to a private method and add it to mousePressed() method too (within an if-else clause with the code that was already there).

eProfile is actually written against v1.21 of the touchgraph library (from 03/04/2002); the most recent version is actually v1.22 (from 04/12/2002), but I saw that the bug is still present in that code too. The touchgraph library is an excellent library for forced-graph visualization (especially if you look at their Amazon and Google demos). Part of the problem (from reading their web-site) is that they are still working out how to separate proprietary from open-source portions of their code, so the stuff they are making available, they refer to themselves are older touchgraph components. One might assume that if these libraries were maintained as fully-fledged open-source projects, then such bugs would have been knocked out by members of the community a long time ago ;-).

No comments: