Anticipating the day when multi-touch interfaces become more pervasive, are there libraries in Java that can be used for developing touch applications? I'm looking for interfaces similar to MouseListener / MouseMotionListener / MouseWheelListener.
Sparsh is still in my bookmarks from the last time I was investigating multitouch java solutions.
While not as straight forward as the typical mouse listener or click listener, it still provides a reasonable interface.
You need your listening class to implement sparshui.client.Client
, which requires the processEvent
method definition.
public void processEvent(int groupID, Event event) {
if(event instanceof TouchEvent) {
TouchEvent e = (TouchEvent)event;
if(e.getState() == TouchState.BIRTH) {
//do initial touch stuff
} else if(e.getState() == TouchState.MOVE) {
//do dragging stuff
}
}
else if(event instanceof DragEvent) {
DragEvent e = (DragEvent)event;
//do DragEvent specific stuff
} else if(event instanceof RotateEvent) {
RotateEvent e = (RotateEvent)event;
//do RotateEvent specific stuff
} else if(event instanceof ZoomEvent) {
ZoomEvent e = (ZoomEvent)event;
//do ZoomEvent specific stuff
}
//several other gesture types....
}
After that, you need to start up the gesture recognition server, passing in your component
new ServerConnection("localhost", objectImplementingClientInterface);
Looking at the code examples on the site should give you a pretty good idea of the framework.
The MT4j project has everything you need to develop multitouch applications in java. All the well known multitouch gestures are already built in and can be accessed as simple as listening to mouse events (for example: component.addGestureListener(..)). It also features a hardware accelerated scene graph, similar to JavaFX. You can even simulate multitouch input by connecting one ore more mice to your machine. Check it out at http://www.mt4j.org