Reputation: 3842
I am making a a JavaFX GUI application, which uses the javafx webview class. Now i am able to show a webpage in Java. Now i want to make the webpage respond to different touch events. I am pretty sure i have to customise it for different kinds of events,Like stationary move and remove would act like a click, whereas a drag would be scroll. Actually i am not exactly using a touchscreen but something similar. So if there might also be a way to pass the coordinates to touch event explicityly or maybe making a user defined event handler and than using it, and then somehow using it inside the webview.
I am a bit new to JavaFX and a bit of event handling so would like some direction.
Is there a way to pass psuedo-touch events?
I am using TUIO, and I am able to recieve the coordinates etc correctly. I have TUIO event functions responding in their way. Can i pass custom events or change them to touch screen events and pass them to webview? Because they are not actually touch events but if someone can be made pseudo-touch events acting like them, that might work.
Upvotes: 1
Views: 1486
Reputation: 342
Just stumbled over your question. Don't know if it is still relevant to you, but in case anyone else finds this:
JavaFX WebView doesn't really understand TouchEvents, but you can handle them. To pass them to the Browser, JavaScript from Java via the executeScript in WebEngine. In the JavaScript you can create an TouchEvent with document.createEvent('UIEvent')
With that I was for example able to forward TouchEvents down to a Leaflet running inside the WebView.
Upvotes: 0
Reputation: 159291
As you are using WebView which is an HTML component, then you will need to handle the events in WebView, not JavaFX.
You will need to write JavaScript event handlers for use by your page. You can find more information on JavaScript event handlers at the following links:
If you are not actually using a touchscreen it may or may not work (I don't know).
I do not know if WebView understands touch events (I have never tried it).
Is there a way to pass psuedo-touch events?
Use Java 8. In Java 8 there are a variety of touch related event classes such as TouchEvent, SwipeEvent, ZoomEvent, RotateEvent, etc. Each of these Event classes have a constructor you can use to construct the event in code. Then comes the tricky bit, normally what you would do here is determine the node to which the event should apply and invoke node.fireEvent(myCreatedEvent). However that determination step is called picking, for which there is no public API in JavaFX at the moment. A request for a public picking API is currently the highest voted request in the JavaFX issue tracker. So without a public API, you will need to use a private undocumented API (which will probably disappear in future JavaFX versions). If you wish, you can search the JavaFX source to find out what the name of such an API would be.
Can i pass custom events or change them to touch screen events and pass them to web view?
I am not sure, you could try the approach I outlined above, it may or may not work.
I'd recommend using a real touch screen that is supported by your target OS rather than using TUIO, then JavaFX and WebView will probably handle all of your touch input intrinsically without you having to do anything.
Upvotes: 1