views:

3706

answers:

3

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.

+2  A: 

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.

James Van Huis
Ouch... really, you have to 'instanceOf' the events? They don't provide callbacks like, processDragEvent, processZoomEvent, etc?
David
As far as I'm aware, they only support a generic "processEvent" call because you may want to add custom gestures which are not native to the framework. This provides that extensibility without having to modify the framework code.
James Van Huis
+1  A: 

How about this: http://kenai.com/projects/macmultitouch

Wayne
+3  A: 

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

Does MT4j allow the developer to create new multitouch gestures, besides the built-in ones? Not immediately apparent from the list of MT4j Features on the webpage.
David
Yes, MT4j certainly does allow to create new multitouch gestures as this is a very important requirement for multitouch applications. All you have to do is create a new so called input processor and register it with a component. Tutorials showing how to do that will be coming soon. Until then you can look at the source code of the existing gestures.