How to develop multi-touch applications in Java?
Asked Answered
M

5

19

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.

Mischa answered 15/12, 2008 at 18:38 Comment(0)
G
9

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

Geiss answered 6/9, 2009 at 12:56 Comment(3)
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.Mischa
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.Geiss
MT4j looks great - unfortunately it's GPL and thus not suited for commercial apps.Airing
F
5

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.

Flotilla answered 15/12, 2008 at 19:10 Comment(2)
Ouch... really, you have to 'instanceOf' the events? They don't provide callbacks like, processDragEvent, processZoomEvent, etc?Mischa
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.Flotilla
D
1

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

Dongola answered 20/8, 2009 at 16:59 Comment(1)
Hi Wayne, please refrain from using link-only answers as off-site links may die and become useless.Eventual
N
0

I am primarily working in Processing and designing my UI from the ground up. I've been looking for a solution which doesn't prescribe a UI framework which both MT4J and JavaFX appear to do. Furthermore, MT4J appears to be abandoned.

This looks like a promising solution at least for Windows but I'm unsure if it's actually released yet: http://wiki.gestureworks.com/index.php/GestureWorksCore:Gestureworks_Core_Tutorials

This is specifically for Processing, cross-platform, open-source and active: https://github.com/vialab/SMT

Newton answered 29/4, 2014 at 21:9 Comment(0)
M
0

MT4J doesn't work with Windows 8.

If the applicatin is only for one user, you can use JavaFX. There are different listener for touch events. But it is not possible to process two gestures at the same time, because all touch points will merge to one gesture. For big multi touch screens it is a disadvange. For normal screens, where is only one user its ok.

But there is also GestureWorks. There you can define new gesture or use the predefined gesture. The gestures are defined in a XML File (called GML). Any object can handle there own gestures. But you have to implement the hitTest and the point assignment manually. But there is a greate tutorial.

Another library, which i don't tested, ist the Multi Touch SDK by PQ Lab.

Muldoon answered 30/7, 2014 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.