FX Experience Has Gone Read-Only

I've been maintaining FX Experience for a really long time now, and I love hearing from people who enjoy my weekly links roundup. One thing I've noticed recently is that maintaining two sites (FX Experience and JonathanGiles.net) takes more time than ideal, and splits the audience up. Therefore, FX Experience will become read-only for new blog posts, but weekly posts will continue to be published on JonathanGiles.net. If you follow @FXExperience on Twitter, I suggest you also follow @JonathanGiles. This is not the end - just a consolidation of my online presence to make my life a little easier!

tl;dr: Follow me on Twitter and check for the latest news on JonathanGiles.net.

SWT Interop

SWT Interop

With JavaFX 2.0.2, we’ve included support for interop with SWT in the same way that we support interop with Swing. That is, you can embed JavaFX within your SWT applications! Although e(fx)clipse has been doing this for a little while by embedding FX -> Swing -> SWT, you can now skip the intermediate embedding into Swing and just go straight to SWT. Because FX and SWT share the same basic threading model, this is really easy to do.


(more…)

OpenJDK Discussion About JavaFX

I just sent the following letter to the OpenJDK community “discuss” mailing list:

Hi OpenJDK community!

As announced at JavaOne we (Oracle) would love to contribute JavaFX into OpenJDK as a new project called “JFX”. For some who have been following along, we’ve talked about this for a long time but finally (finally!) we’re ready to act on it and open source the platform. We are not just interested in open sourcing the code, however, we also want to move into an open development model. We already have an open bug database[1]. The project uses Mercurial, so we should fit in pretty well into OpenJDK.

Our basic motivation for wanting to open source JFX is to built a community and ecosystem support and adoption around JavaFX by increasing transparency. Of course we are also interested in getting patches and early feedback from the community[2]! Our goal is to provide the next-generation Java client toolkit, and JFX would be the next step along that path, which hopefully culminates in a JSR for the Java 9 timeframe and including JFX as proper part of the JDK. I would be the initial Project lead for JFX.

A little bit about our project:
It is a significant contribution to the corpus of open source code
It includes over 6000+ public API members (methods / constructors / etc)
It includes over 11,500 unit tests
Core libraries such as observable collections and binding
Scene graph, effects, graphics
CSS support for JavaFX
Media
WebView
Prism (hardware accelerated graphics, including openGL and D3D and java2D implementations)
Glass (windowing system, base porting layer, including mac, linux, and windows implementations)
UI Controls and Charts

Our builds are all Ant, with JUnit for testing (there is some ‘make’ in there for native parts). We also have NetBeans projects setup for each area. There is a lot of code that we’ll be releasing, so as a matter of practicality we’re going to release different parts of JavaFX over the course of the next few months, starting with UI controls followed by charts. We’ll put up a full roadmap onto our project pages, should we be approved to become part of OpenJDK. We’ll make sure that the open source code is always fully buildable by anybody using the sources + a binary plug (which will become unnecessary as we open source the remaining pieces). All of the above listed modules will be open sourced and fully buildable.

What do you think? I’d love to hear any issues and hopefully be able to resolve those prior to requesting an official vote.

Thanks
Richard

[1] http://javafx-jira.kenai.com
[2] A good example of the sort of interesting stuff going on out there can be found here: http://jroller.com/neugens/entry/embed_swing_inside_javafx_2

This is the first step towards open sourcing JavaFX into OpenJDK. First I wanted to talk with the community about it, and if it looks favorable, I’ll follow up with an official project proposal. Here’s hoping! If you are a subscriber to “discuss”, please go and throw in some good word for the idea and if you have any questions I’d like to hear those too. If you aren’t a member of “discuss”, go join :-). You can do so here.

It feels good to finally be getting this all out in the open source!

FXML + Guice

FXML + Guice

There has been a very interesting thread in the JavaFX OTN forums about FXML and dependency injection. I went and downloaded Google Guice and wrote a small sample to try it all out. Things are not perfect quite yet (I still need full Unified Expression Language support added to FXML), but so very, very, very close!

What I ultimately hope to accomplish with FXML and CSS in JavaFX enterprise applications is that we (a) fully separate the visuals from the “controller”, (b) are left with a very simple “controller” that is highly testable, and (c) everything is highly modular.

CSS allows the designer to come in after the fact and modify the look of a UI without the developer’s help, and without a full build cycle. FXML allows a developer or designer to alter the structure of the view without a full build cycle. So (a) should be well in hand, especially if the controller itself can be injected rather than declared directly in the FXML file as it is today. (I’m OK with, even prefer, saying “I would like to have a FooController for this FXML file, if you please”, but what would really rock is if the FooController were an interface or abstract class rather than always being a concrete class, such that a DI framework like Guice could find the appropriate implementation and supply it).
(more…)

Correctly Checking KeyEvents

I was just writing a quick little application and I wanted to do something special whenever the user released the enter key inside a TextArea. You might be tempted to do it like this:

final TextArea editor = new TextArea();
editor.setOnKeyReleased(new EventHandler<KeyEvent>() {
    public void handle(KeyEvent t) {
        if (t.getCode() == KeyCode.ENTER) {
            System.out.println(editor.getText());
        }
    }
});

Can anybody spot the problem in this code? It correctly gets the key event, and it only prints out the text if the code of the key event is ENTER. The problem is that it also executes this code if you typed ALT+ENTER, or CTRL+ENTER, or any other combination of modifiers with the key code! JavaFX 2.0 contains a handy little class called KeyCombination which will handle all the annoying checking of key modifiers + key code to see if a specific key event matches. Here is the more correct version:

final TextArea editor = new TextArea();
editor.setOnKeyReleased(new EventHandler<KeyEvent>() {
    final KeyCombination combo = new KeyCodeCombination(KeyCode.ENTER);
    public void handle(KeyEvent t) {
        if (combo.match(t)) {
            System.out.println(editor.getText());
        }
    }
});

One extra line of code, and you get correct matching of the key events. Sweet!