JavaFX – Die neue UITechnologie im JDK 8 Wolfgang Weigend Sen. Leitender Systemberater Java Technologie und Architektur 1 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Agenda • Aktueller Status von JavaFX • JavaFX-Aufbau und Architekturkonzept • Vorteile von JavaFX bei der Entwicklung von JavaFX Anwendungen komplett in der Java Programmiersprache und mit Java Entwicklungswerkzeugen • JavaFX Scene Builder • Open Source Projekt OpenJFX • Kundenbeispiele • Zusammenfassung 3 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Existierende JavaFX Produkt Releases • JavaFX 8 ist Bestandteil vom JDK 8 – General Availability for Windows, Linux, Mac OS – Java SE Development Kit 8 Update 6 for ARM • Starting with JDK 8u33, JavaFX Embedded is removed from the ARM bundle and is not supported • http://www.oracle.com/technetwork/java/javase/jdk-8u33-arm-relnotes-2406696.html • http://mail.openjdk.java.net/pipermail/openjfx-dev/2015-January/016570.html • Development Tools – NetBeans 8.0.2 – JavaFX Scene Builder 2.0 – e(fx)clipse • major release cycle alignment with eclipse roadmap • minor release cycle with JavaFX roadmap 4 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX and JDK for ARM – Kevin Rushforth “Starting with JDK 8u33, JavaFX has been removed from both Oracle JDK for ARM and Oracle Java SE Embedded. This is a resource trade off within Oracle. Included in that difficult trade off decision was the ongoing investment needed to properly support FX in a world where so much the hardware is not standardized -- it really is difficult to have enough hardware and testing resources committed to support FX on ARM. It is important to understand that when we say support, we are not talking about just "running" on a device like the Raspberry PI -- but providing support for paying customers that are almost certainly going to be using hardware that is customized for their embedded product. This does not mean that FX is going away on other platforms, and hopefully does not mean we will be disappearing from ARM completely. The core JavaFX team will continue working on the ARM port as resources permit, hopefully with involvement of members of the OpenJFX community. We have continued to demonstrate this commitment with the moving all of the JavaFX sources to OpenJFX, and maintaining an up to date OpenJFX Wiki which includes detailed articles on building for ARM. We will continue to do what we can to make it easier to build and overlay OpenJFX on top of the ARM JDKs. We hope to arrange for a external build of OpenJFX for ARM so that more people will be able to easily obtain a current build. Most of the FX source code is shared across all ports, and we will continue to do regular internal builds of linux-armv6hf to ensure that it runs. We will continue to maintain the *Monocle glass platform in any case, as we use it for some of our desktop unit tests. We have received a lot of help from the community -- particularly for iOS and Android. Now we hope we can work together to keep Linux ARM viable and interesting.” 5 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. *Monocle is now the default implementation of Glass on embedded platforms. JavaFX Linux on ARM Port created by MicroDoc • MicroDoc creates Linux on ARM Port for JavaFX on their own – Source code and testing included – As well for higher versions of Java, i.e. Java SE 9 • MicroDoc leds own projects • MicroDoc Linux on ARM Port created and shipped – OpenJFX 8 source with Multi-Touch JavaFX build for manufacturing customer in Austria – Debian Linux • MicroDoc has started to create and deploy embedded runtimes in 1999 – MicroDoc worked with customers from a large variety of industries including Automotive, Telematics, Telecommunication, GSM Network Infrastructure, Building Automation, Smart Home, Smart Grid / Smart Metering, Mobile Computing, Airline Traffic Management, Security Systems, Laser Technology, Education 6 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Source: https://www.microdoc.com/ JavaFX Runtime Architektur JavaFX Architektur Komponenten • Glass Windowing Toolkit: Provides native operating services, such as managing the windows, timers, and surfaces • Prism: Graphics pipeline that can run on hardware and software renderers • UI Toolkit: Ties Prism and Glass together and makes them available to the JavaFX APIs 7 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Architektur • Internal API • Course-grained porting layer − FX APIs isolated from implementation details • Allows porting to completely different systems 8 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Architektur • Quantum Toolkit ties Prism and Glass Windowing Toolkit together and makes them available to the JavaFX layer above in the stack • Quantum Toolkit manages the threading rules related to rendering versus events handling 9 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Architektur • Graphics API − Converts the scene graph into rendering calls − Abstracts D3D, OpenGL, Java2D behind a “Graphics” object − Handles “dirty regions”, clipping, and other optimizations − Font support • Use hardware where possible − Fast paths using shaders for ellipses, rectangles, etc. • Reduce context switches − Looking towards possible state sorting optimizations in the future • Fallback to software rendering when necessary − Bad drivers are the main reason for doing so 10 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. − Rasterization JavaFX Architektur • Windowing API − Windows − Mac − Linux − Headless (not done) • Provides basic OS services − Drawing surface − Input events − Event queue 11 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Scenegraph Scenegraph • Instead of remove/add: − group.getChildren().remove(node); − group.getChildren().add(0, node); • node.toFront() • node.toBack() Scenegraph −node.toFront() −node.toBack() 12 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Displaying HTML in JavaFX public class WebViewDemo extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) { WebView webView = new WebView(); webView.getEngine().load("http://java.oracle.com"); Scene scene = new Scene(webView); stage.setScene(scene); stage.setTitle("Web View Demo"); stage.show(); } } 13 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX mit JFXPanel Komponente in Swing Anwendungen einbinden public class Test { Class JFXPanel private static void initFX(JFXPanel fxPanel) { // This method is invoked on JavaFX thread // This method is invoked on Swing thread java.lang.Object JFrame frame = new JFrame("FX"); java.awt.Component Scene scene = createScene(); fxPanel.setScene(scene); final JFXPanel fxPanel = new JFXPanel(); java.awt.Container } frame.add(fxPanel); frame.setVisible(true);javax.swing.JComponent public static void main(String[] args) { javafx.embed.swing.JFXPanel private static void initAndShowGUI() { SwingUtilities.invokeLater(new Runnable() { Platform.runLater(new Runnable() { @Override @Override public void run() { public void run() { initAndShowGUI(); initFX(fxPanel); } } }); }); } } } 14 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. [SwingNode, JFXPanel] Focus issue when mixing JavaFX and Swing multiple times - Runtime RT-39196 public class EmbeddedTestWithFX extends JFrame { • Details: Bug in JDK 8u20 and JDK8u40EA on Windows 8 public EmbeddedTestWithFX() { setSize(new Dimension(300, 300)); • If Swing is embed into JavaFX which is embedded into Swing, the focus of controls have issues JTextArea textArea = new JTextArea(); textArea.setSize(new Dimension(150, 150)); JPanel container = new JPanel(); container.setLayout(null); container.add(textArea); TextArea is shown, but It doesn't get the focus by clicking on it (It's the same for other controls, like jButtons). If a FocusListener on the JTextArea is registered, you see that it becomes the focus after a click, but it loses the focus instantly. JFXPanel jfxPanel = new JFXPanel(); Platform.runLater(() -> { SwingNode swing = new SwingNode(); StackPane stack = new StackPane(swing); Scene scene = new Scene(stack); swing.setContent(container); SwingUtilities.invokeLater(() -> jfxPanel.setScene(scene)); }); The example starts to work with: -Djavafx.embed.singleThread=true setContentPane(jfxPanel); Clicked the TextArea, it holds the focus and text could be entered. } public static void main(String[] args) { new EmbeddedTestWithFX().setVisible(true); } 15 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. } WebView und Swing Interoperabilität WebView Component • Embed Web content in JavaFX applications • HTML rendering based on Webkit • Hardware accelerated rendering using PRISM • DOM access and manipulation 16 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Swing and SWT Interop. Browser Plug-In • Embed JavaFX content into existing Swing applications • Extend existing Swing applications with new JavaFX features such as WebView and highperformance graphics • Applies to SWT* applications as well • Faster loading of JavaFX Web applications based on Prism • Pre-loader for improved user experience with JavaFX Web applications * Feature introduced since JavaFX 2.1 Swing to JavaFX Migration • Swing UI Controls analysieren – Soll “Swing-Behavior” in JavaFX Migration mit eingebaut werden? – Exakt gleiche Darstellung auf Pixel-Ebene? • Layout Manager – Teilweise automatisch überführen – Manuelle Tätigkeit • Geschäftslogik/Code entflechten – Wie stark ist die Verzahnung von Code & UI? • Fachlicher Freeze während der Migration, mit dem Ziel einer möglichst kurzen Code-Freeze-Phase 17 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Design Objectives JavaFX – Moving Client Forward Oracle’s next generation Java client solution • Built on Java in Java • Modular architecture • Migration path for Java client UI technologies • Advanced tooling • Delivering on the cross-platform promise 18 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Java APIs und FXML Java APIs für JavaFX • End-to-end Java development • Java language features - generics, annotations, multi-threading • Fluent API for UI construction • Alternative JVM supported languages (e.g. Groovy, Scala) with JavaFX • Leverage sophisticated Java IDEs, debuggers and profilers • Java APIs preserve convenient JavaFX Script features (e.g., bind) 19 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. FXML • Scriptable, XML-based markup language for defining UI • Convenient alternative to developing UI programmatically in Java • Easy to learn and intuitive for developers familiar with web technologies or other markup based UI technologies • Powerful scripting feature allows embedding scripts within FXML. Any JVM scripting language can be used, including JavaScript, Groovy, and Scala Graphics und Media New Graphics Pipeline Media • New hardware accelerated graphics pipeline (Prism) • New windowing toolkit (Glass) for Prism • Java2D Software Pipeline under Prism • High-level support for making rich graphics simple • Shadows, Blurs, Reflections, Effects, 2D transforms • 3D Transforms today; Full 3D objects in future 20 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. • Stable media framework based on GStreamer • H.264*, VP6; MP3, AAC* playback of Web multimedia content • Low latency audio • Alpha Channel support for full transparency to solid Pixel • Performance improvements • Full screen video * Feature introduced since JavaFX 2.1 New JavaFX Features in JDK 8 • • • • • • • • 21 New Modern Theme: Modena JavaFX 3D Rich Text TreeTableView DatePicker Public API for CSS structure WebView Enhancements Embedded Support Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Modena Modern Theme - New in JavaFX 8 22 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Rich Text - New in JavaFX 8 • Use Cases – text editor, code editor – mixed style Labels, buttons, cells, headings, descriptions, large textual content, etc. • Details – TextFlow, a new layout container – Text is just a nodeZ so you can add effects, event handlers, and animations – You can also use CSS, FXML 23 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. TreeTableView - New in JavaFX 8 • Goal: reuse as many API, or API concepts, as possible from the TreeView and TableView controls API 24 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. DatePicker - New in JavaFX 8 25 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Public API for CSS structure - New in JavaFX 8 • CSS styling is one of the key features for JavaFX • CSS has been implemented exclusively in private API (com.sun.javafx.css package) • Tools (e.g. Scene Builder) require a CSS public API • Developers will be able to define custom CSS styles 26 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Hello World in JavaFX Programming in Java public class JavaFXExample extends Application { @Override public void start(Stage stage){ Scene scene = new Scene( LabelBuilder.create() .text("Hello World!") .layoutX(25) .build()); stage.setTitle("Welcome to JavaFX!"); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } } 27 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Hello World in JavaFX Programming in FXML und Java FXML <BorderPane> <center> <Label text=”%helloworld"/> </center> </BorderPane> Java public class FXMLExample extends Application { @Override public void start(Stage stage) throws Exception { stage.setTitle("FXML Example"); Parent root = FXMLLoader.load(getClass().getResource (“example.fxml"), ResourceBundle.getBundle(“r.fxml_example")); stage.setScene(new Scene(root)); stage.show(); } public static void main(String[] args) { launch(args); } } 28 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Java Entwicklungswerkzeuge • Source editor with improved syntactic highlighting, code completion, refactoring etc. • Full debugger and profiler support • Project wizard for easy creation of JavaFX applications Other Java IDE’s • Source editor with syntactic highlighting, code completion, refactoring etc. • Full debugger and Profiler support 29 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Die Community beteiligt sich The third party developer community has shown interest in JavaFX. Here are a few projects: • e(fx)clipse: plugins for Eclipse and for OSGi • DataFX: data source and cell factories for JavaFX UI controls • ScalaFX, GroovyFX: Scala and Groovy bindings for JavaFX • JFX Flow, eFX, JRebirth: application development frameworks • FXForms2: automatic form generation • JFXtras: UI controls and extensions for JavaFX • XDEV IDE and XDEV Application Framework XAPI 30 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Gluon Ignite library Dependency Injection Frameworks in JavaFX applications • With the Gluon Ignite library, developers can use popular dependency injection frameworks in their JavaFX applications, including inside their FXML controllers • Gluon Ignite creates a common abstraction over several popular dependency injection frameworks: – currently Guice, Spring, and Dagger, and plan to add more as the demand becomes obvious • With full support of JSR-330 Gluon Ignite makes using dependency injection in JavaFX applications trivial • Example of creating an application using the Guice framework and Gluon Ignite: Source: http://gluonhq.com/ open-source/ignite/ 31 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Funktionale Systemtests für JavaFX Automatisiertes Testen für JavaFX UI Controls QF-Test Firma Quality First Software Professionelles GUI-Testen für Java & Web www.qfs.de 32 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. • Functional Testing • UI Controls • Scenegraph QF-Test und JavaFX 8 • • • • • JavaFX ist eine pure Java-Anbindung analog Swing Erfahrungsschatz erlaubt schnelle Erweiterung auf JavaFX Technischer Durchstich bereits erfolgreich vollzogen Offizielle Unterstützung für Java 8 QF-Test Version 4.0.7 freigegeben Java Swing Eclipse/SWT Web 33 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. QF-Test & JavaFX 8 – GUI Testautomatisierung 34 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Scene Builder 2.0 http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html 35 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Scene Builder • UI layout tool for JavaFX • FXML visual editor • Can be used standalone or with all major Java IDEs – Tighter integration with NetBeans IDE • Preview mode • CSS support • Supported on Windows and Mac OS X 36 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Gluon supports Scene Builder • Scene Builder only as source code within the OpenJFX project • Gluon provides Scene Builder builds – Actively work on improvements to Scene Builder, in a public repo, to further drive the functionality of Scene Builder forward – These builds will be the Oracle bits, with additional improvements based on community involvement and our desires to better support third party projects such as ControlsFX, FXyz, DataFX, others • Downloads: Note: Scene Builder is open source and licensed under the BSD license 37 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Source: http://gluonhq.com/open-source/scene-builder/ JavaFX und Open Source http://openjdk.java.net/projects/openjfx OpenJFX 38 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. • UI Controls • Scenegraph • JemmyFX JavaFX via Open Source im JDK 8 Open Source Übergang Standardisierung OpenJFX Project under Common license with Oracle committed to JavaFX standardization First phase to focus on JavaFX included in JSR to be submitted through JCP and JSR expected for JDK 9 OpenJDK UI Controls Java SE Java SE with JDK 8 JavaFX for Java SE Embedded (ARM), see Oracle notes earlier 39 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Open Source und Standardisierung • JavaFX source code being contributed as part of OpenJFX http://openjdk.java.net/projects/openjfx/ – Source code being contributed in phases – Open sourced as of March 2013 • UI Controls • Scene Graph • JemmyFX • Functional Tests • Oracle is committed to standardize JavaFX through JCP – One or more JSRs will be submitted – Expected to be become part of the Java SE specification 40 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Die künftige Ausrichtung von JavaFX Oracle’s Next Generation Java Client Solution • • • • • • 41 Tighter Integration with Java SE Migration Path for Java Client UI Technologies Optimized Web Services Support Advanced Tooling Support for Modern Device Interactions Delivering on the Cross Platform Promise Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX goes Open Source iOS- und Android-Implementierungen • iOS- und Android-Implementierungen sind Open Source • Lizensierung mit eigenem Applikations-Co-Bundle 42 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Alternative usage of RoboVM Develop iPhone and iPad Apps in Java with RoboVM • Java to Native ‒ The RoboVM ahead-of-time compiler translates Java bytecode into native ARM or x86 code ‒ Apps run directly on the CPU, no interpreter or virtual machine involved • Objective-C Bridge ‒ RoboVM includes a Java to Objective-C bridge ‒ Bridged Objective-C objects can be used just like any other Java object ‒ Much of UI-Kit is already bridged and more frameworks will follow • http://blog.robovm.org/2013/05/javafx-openjfx-on-ios-using-robovm.html 43 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFXPorts: JavaFX on Mobile and Tablets Package your JavaFX Application for deployment on iOS and Android • JavaFX on client, desktop, laptop and embedded systems • JavaFX on mobile and tablets • Why is a port needed? - Isn't Java Write Once Run Anywhere? OpenJDK http://javafxports.org/page/home 44 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Kundenbeispiele 45 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX Anwendungen Celer is a trading management platform for every asset class, the true multi asset modular trading platform. Built by traders for traders. • The Celer Trading module is built on top of the Celer framework and combines an execution and order management system in one, giving all the control needed in one easy to use platform. Quick order entry and combination depth deal tickets are just some of the features that the platform can offer customer trading. • Software Development Kit (SDK) The Celer Framework SDK allows to build the next feature to keep customer business ahead of the competition and to adapt to customer needs in the future. 46 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Volkswagen Group Research - Reactive Modeling of Automotive User Interfaces with JavaFX • • • • • • UI series development at Volkswagen Group UI prototyping at Volkswagen Group Research The UI framework Tappas Reactive UI modeling Implementation of reactive models with JavaFX JavaFX on automotive target hardware 47 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Source: Volkswagen Group Research at JavaOne 2014 UI series development at Volkswagen Group • User interfaces for automotive infotainment systems are developed for various models, brands and markets at Volkswagen Group • A high number of variants and skins are required • The development is based on state chart models • Java 1.4 code is generated • Rendering is hardware accelerated using OpenGL ES 48 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Source: Volkswagen Group Research at JavaOne 2014 UI prototyping at Volkswagen Group Research • UI prototypes require fast and flexible development • JavaFX is our technology of choice, replacing Flash Source: Volkswagen Group Research at JavaOne 2014 49 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. JavaFX - UI prototyping at Volkswagen Group Research - Tappas UI framework • UI prototypes require fast and flexible development • JavaFX is our technology of choice, replacing Flash • Tappas UI framework – Highly modular and flexible with OSGi – Different JavaFX center console applications for different hardware and operating concepts • Single screen, split screen or dual screen applications • Hardware keys, direct touch or indirect touch operation – Various JavaFX apps as OSGi bundles, running within the different center console applications • Tuner, media, telephone, contacts, climate, navigation with a 3D map written in JavaFX, etc. – Reactive modeling of screen changes – Quelle: Volkswagen AG, Jens Ehrke & Simon Gerlach, JavaOne 2014, 1. Oktober 2014 • Reactive Modeling of Automotive User Interfaces with JavaFX 50 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Source: Volkswagen Group Research at JavaOne 2014 Zusammenfassung JavaFX is the strategic Java UI technology for rich client applications Unified development of Java and Web applications • Browser Plug-in, Web Start, Native Executables • Hardware Accelerated Graphics (DirectX, OpenGL) • JavaFX with HTML-DOM • ‒ JavaFX with WebView for HTML5 features ‒ Improved JavaScript Engine ‒ JavaFX as applet integrated to run in a web page IDE support for Eclipse e(fx)clipse, IntelliJ, IDEA, NetBeans, etc. Wanted JavaFX for mobile operating systems iOS & Android - desirable Developer community could make use of the JavaFX Open Source process • Get hands-on porting for iOS and Android 51 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Ressourcen • Downloads: http://otn.oracle.com/javafx • OpenJFX: http://openjdk.java.net/projects/openjfx/ • Oracle Premier Support http://www.oracle.com/us/support/software/premier/ • Blogs – http://blogs.oracle.com/javafx – http://fxexperience.com • OTN Forum: https://forums.oracle.com/forums/forum.jspa?forumID=1385 • Twitter: @javafx4you 52 Copyright © 2015 Oracle and/or its affiliates. All rights reserved. Danke! [email protected] Twitter: wolflook 53 Copyright © 2015 Oracle and/or its affiliates. All rights reserved.