Aloha,
again a short post about using the touch api in JavaFX to interact with a control. I played around with the touch api last week and used it to move the pointer of a gauge with my fingers.
That was something I would like to do for months and I really was surprised how easy it was to realize.
This morning I read a comment on one of my last posts where someone created a gauge where you could drag the pointer to a certain value and I thought it might be a good idea to share this touch thing with you, so here we go...
First of all I created one of my gauges with the following code...
final Gauge radial =
GaugeBuilder.create()
.prefWidth(600)
.prefHeight(600)
.valueAnimationEnabled(false)
.frameDesign(FrameDesign.STEEL)
.backgroundDesign(BackgroundDesign.BRUSHED_METAL)
.pointerType(PointerType.TYPE15)
.valueColor(ColorDef.CYAN)
.ledColor(LedColor.CYAN)
.build();
which leads to the following gauge...
By the way...it shows the new brushed metal background that is now also available in the JFXtras gauges :)
In the next step we have to add the EventHandler for the RotateEvent...
private double value = 0;
radial.addEventHandler(RotateEvent.ROTATION_STARTED,
new EventHandler<RotateEvent>() {
@Override public void handle(RotateEvent event) {
value = radial.getValue();
}
});
radial.addEventHandler(RotateEvent.ROTATE,
new EventHandler<RotateEvent>() {
@Override public void handle(RotateEvent event) {
radial.setValue(value + event.getTotalAngle() /
radial.getAngleStep());
}
});
And that's all I have to do to receive rotation events from the touchpad of my Macbook Pro and use the values to rotate the pointer of my gauge...nice isn't it...
For those of you who would like to see it in action I recorded a short video with my iPad (so the quality might be not ideal)...here you go...
That's all I wanted to share with you so...keep coding...
Very, very cool Gerrit!!! I was playing around with touch on Windows 7 recently and am just amazed how easy it is to implement stuff.
ReplyDeleteHi gerrit,
ReplyDeletei'm trying to do many gestures and other new events but not quiet easy at all. My computer doesn't support any of them. I've android device with 1ghz can i run javafx implicitly using rooted Operating system.
Thanks
Narayan
Hi Narayan,
ReplyDeleteI think it won't work on an Android device at the moment. An idea would be to buy the Apple MagicPad (not sure if they have Linux drivers but it should work on OS X and Windows) because it seems to be the same technology as the MBP trackpad (which works).
Cheers,
Gerrit