Enzo

Wednesday, January 9, 2013

Fun with PreView releases...

Aloha,
I was not sure if it is worth the time to blog about something that might be outdated within weeks but it's so much fun that I decided to share it with you.
At Devoxx 2012 I talked to Daniel Blaukopf (Oracle) where he told me that it won't take long until JDK8 for ARM Preview will be released for the Raspberry Pi and in the beginning of December last year it happened...yipppeah
As much as I loved coding for the BeagleBoard...coding for the Raspberry Pi is even more fun and that's not because of Java/JavaFX (which is in principle the same) but more because the setup of the Raspberry Pi is much easier than the BeagleBoard.
Long story short I had a Raspberry Pi already and the second was ordered at that time so that I was able to start coding for the Pi directly after JDK 8 was released.
First of all I have to say that the instructions on the Oracle page are really good this time and you could get something up and running within a short time.
Because I started porting some of my controls to JDK8 already I was really looking forward to use some of these controls on the Pi...BUT...it didn't work :(
I was not sure why and tried different things but in the end the solution was quite simple...the Embedded team and the Desktop team at Oracle just based their SDKs on different snapshots which lead to my problems.
Don't get me wrong...the "normal" Java stuff works fine but when it comes to Custom Controls (and that's the stuff I'm interested in) you will find different behavior in JavaFX between JDK8 SE and JDK8 for ARM. The problem is only because of one class...SkinBase. 
In JDK8 SkinBase moved from 

    com.sun.javafx.scene.control.skin.SkinBase

to 

    javafx.scene.control.SkinBase

In addition to this the constructor changed from

    SkinBase(Control control, ControlBehavior behavior)

to

    SkinBase(Control control)

So that seems to be not a big deal right...you just have to adjust your Skin class and everything should be fine...
This is only correct for the JDK8 SE version because the JDK8 ARM preview is based on a different version it still takes two arguments in the constructor.
The solution for the problem was to extract the jfxrt.jar from the JDK8 ARM preview, link it to your project and compile your project against JDK7 on the Desktop. Most of the time I spent on figuring out how to compile the jar in a way that it works on the Raspberry Pi on JDK8 ARM preview.

Because it's only a temporary version and will change in the near future I won't post any source code here but I will give you the jar with the controls so you can play with it on your Raspberry Pi.

Related to the new name of the css file in JDK8 which is now Modena instead of Caspian I named the lib Enzo because of Enzo Ferrari who's company Ferrari is placed 18 km away from Modena in Italy. (You have to login to Jira to see the images of Modena and Caspian).
The lib contains the following controls:

  • Clock
  • Lcd
  • Led
  • LedBargraph
  • SevenSegment
  • SimpleIndicator

These are the controls that you will also find in the JFXtras-labs project but implemented in a different way. I completely change the style of creating controls after I discussed with Jonathan Giles, Richard Bair and Jasper Potts.
You don't have to decompile the jar file to get the source code because I will blog about Enzo in the near future anyway and for those of you that can't wait you could find a repository on github here.
There's also a radial gauge in the package but it's work in progress so you can't really use it because it has no tickmarks at all at the moment :)

Download:
Binary jar: Enzo7.jar

Because this post has no images right now...here is one to see the controls in Action running on one of my Raspberry Pi's



The image shows my Raspberry Pi no. 3 that is connected to a 10" touch screen. In addition I've attached logitech usb audio speakers and a high power rgb led from yoctopuce. On the display you see two Lcd controls visualizing the temperature measured by my Raspberry Pi no. 1 and no. 2, two SimpleIndicator controls that visualize the temperature range of each pi and a Clock control showing the current time.

I've also recorded a little video of the setup that you could find on YouTube.

Have fun and keep coding...

5 comments:

  1. Have you had any luck with getting the touch screen working with JavaFX applications? I got the same screen and have had no luck.

    ReplyDelete
  2. Hi Gerrit!

    Since you have some experience with embedded JavaFX.. Do you use caching in JavaFX? Do you have any experience with the caching settings? Does setting the setCache(true) on a parent node make sense? I will run some JavaFX on a low-power embedded computer and I am wondering if there is any sense of caching the controls since there will not be much memory to use. What is your overall feeling of the UI on these devices?

    Sincerely
    Martin

    ReplyDelete
    Replies
    1. Hi Martin,
      Caching could be helpful but it doesn't make sense to simply switch it on for every node. It depends on the usage of the node, as long as it doesn't change very often caching will help but if the node will change often caching will bring you the opposite effect because the cache has to be rebuild everytime. I really use caching only where it makes sense ( e.g. the backgounds of the gauges are cached). The ui could run at an acceptable speed but you really have to think about resources (memory and cpu).

      Delete
  3. Nice!
    I just started to play around with Oracle's JVM on Raspberry Pi. Time for me to try and mess around with some JavaFX! As for compiling the bytecode, I plan do that on the Pi itself... while I sleep.

    By the way, I actually live in Maranello, home-town of Enzo Ferrari :)

    ReplyDelete