One of the more ‘flashy’ features in our Java PDF Viewer is the ‘PageFlow’ mode. Using Java3D, it provides a nice reflective stage with the pages of the PDF file lined up, and you are able to smoothly scroll through.
Unfortunately, to be able to use this feature you have to install Java3D, and even then you are lucky if it installs to the correct place and are able to use it. It’s fair to say that Oracle aren’t giving it very much love.
As JavaFX is now bundled with Java, it makes a lot of sense for us to look into converting the PageFlow mode from Java3D into JavaFX, which is what I have been looking at recently.
My first impressions were that this should be a relatively simple task, but having looked into it further, it seems that it is not the case.
As I have not had any experience before with Java3D, it has also been nice to come in and be able to compare how easy it is to learn and work with Java3D and JavaFX. Java3D can produce a very pretty product, but under the hood it is not so pretty, and lacks the simplicity that JavaFX has.
An example of this is that if you want to add transformations to an image, you have to set a Texture on an Appearance that is put inside a Box that gets added to a TransformGroup that has a Transform3D set. Compared to JavaFX where you set an Image on an ImageView, which you are able to transform directly using methods of the ImageView class.
It is worth a mention that Java3D and JavaFX are not equivalent products, but although they have been designed to do different things, JavaFX can actually do a pretty good job of emulating some of the features of Java3D despite not explicitly having 3D functionality yet. (Though some support is coming soon in FX8.)
Java3D is focused around having a 3 dimensional area that you can put things in and manipulate. Moving things on the z axis will make things smaller or larger as they get closer or further away from you, and you can even put things behind you. Rotating things will change the perspective so that the side closer to you appears larger.
JavaFX uses a 2 dimensional area, but we can emulate z positioning by simply scaling the size down, and rotating objects can be emulated by applying a PerspectiveTransform.
I hope this has given a quick overview of the differences between Java3D and JavaFX, stay tuned in the future as I am sure I will have more to say as I progress through the conversion!
I have written several articles on converting our Java3D usage into JavaFX and you can read the other articles here.
Latest posts by Leon Atherton (see all)
- Upcoming JPDF2HTML5 Changes – Request for Feedback - April 14, 2015
- Using Trello as a tool to manage Sprints for Agile and Scrum - March 17, 2015
- Remote debugging iOS Safari on OS X, Windows and Linux - February 17, 2015
- 4 Reasons why Converting PDF to Responsive EPUB is Impossible - January 20, 2015
- Three ways to convert PDF to HTML5: Text and Fonts - December 16, 2014