Saturday, June 29, 2013

JavaFX in Ignition

You're probably already familiar with the existence of JavaFX, Java's new UI rendering framework. Oracle is intending this to slowly replace Swing, and they've done a good job of creating something with a number of great features and a refreshed look and feel.

If you want to use JavaFX in Ignition, you may find yourself scratching your head. Currently, there is no JavaFX Canvas element built in to the Ignition platform, and libraries aren't importable in the Client or Designer. For the moment, JavaFX isn't "officially" supported by Inductive Automation.

However, if you're excited about JavaFX (like I am) and want to get your hands dirty anyway, Inductive Automation has added a little JavaFX support code and it is possible to get up and running in Ignition.

These are your steps to implement some JavaFX yourself:

1) Enable JavaFX in the client and designer
This can be done by editing your ignition.conf file in your Ignition/data directory. You'll want to add the line:

(where XX is the next number in sequence)

2) Write a module that provides a javafx.swing.embed.JFXPanel component.
(Javadocs Here)
This component would then be accessible to drop on an Ignition window and script through python to add elements to the scenegraph inside the javafx scene in the canvas. On your component, you'll want to set the "zoom-incompatible" property to true, so Ignition doesn't try to repaint / zoom in the designer. This is necessary, since JavaFX canvases have their own rendering thread and repaint methods that work differently than standard components.

Note that JavaFX is only installed by default on Java versions > 7u6. On early version of Java6, I believe the gateway.xml modification (which just adds a line to the .jnlp) has unpredictable consequences. (On the latest version of 6, it works fine, but just doesn't load JavaFX since JavaFX isn't installed by default with Java6.) The computers running the client will need JavaFX, or they won't be able to see the component. It's probably a good idea to test in the client whether the client's java supports JavaFX before trying to display a screen with JavaFX components on it (to keep any ClassNotFound Exceptions from rising). You may also be able to get creative and embed that logic into your component, so a lack of JavaFX would show a regular JLabel on the screen with "Could not render" information, or may simply change the component to gray or hidden.

Good luck! Feel free to post any successes back to the comments. I would love to hear what you're doing with all this.

Ignition: 7.5, 7.6


Post a Comment