2015-12-09

Touch is the new click (most of the time)

Recently, I made an interesting discovery. I found out that – while my computer was in touch mode – NetBeans did not respond to double taps. Generally speaking, double taps are a common gesture on touch devices, for example to expand or collapse nodes in tree views, or to open a file. Now you might argue that touch devices are not particularly well-suited for developing purposes, and therefore, it does not matter. That is true. The purpose of this post is to find out what is going on, as NetBeans is a very well-crafted Swing-based application, and it is quite unlikely that NB is doing something wrong here.

My machine is a Surface 3 Pro. If connected to the so-called Type Cover, it is an ordinary Windows 10-PC. The Type Cover has a keyboard and a trackpad which controls mouse pointer movements. In this mode, of course, double clicks on tree views work flawlessly. Touch mode kicks in if the Type Cover is removed. You can still see and use the desktop, and you can still use all apps. There is no mouse pointer, however, so which object is accessed depends on where you touch the screen with your finger. Single taps work like single mouse clicks. Double taps work like double clicks. Well, or should. To see if Java or Swing have issues here, I ran a pre-compiled SwingSet2. Double taps work as expected. So, I then wrote a small program that uses both JavaFX and Swing. Here is the source. And this is how it looks like:

Screenshot of a sample program

Tap detection works as expected, too. At least most of the time. Once in a while the double tap does not get delivered, though.
At that point, I decided to get the NetBeans sources and try to debug then. Building does take some time, but in the end I was able to debug NetBeans - in NetBeans. Guys, this is awesome. I decided to debug org.openide.explorer.view.TreeView. It attaches an instance of PopupSupport which in turn extends MouseAdapter to a ExplorerTree using addMouseListener(). Everything is fine here. Debugging shows that mouseClicked() is correctly called twice when not in touch mode, but only once when touch mode is active. When or where the tap gets lost still needs to be investigated. As of today I would assume that NB has nothing to do with this strange behaviour.

1 comment:

  1. 2016/07/03: Updated the link to Clicker.java (it is now hosted on GitHub)

    ReplyDelete