(Microsoft Powerpoint
Total Page:16
File Type:pdf, Size:1020Kb
Entwicklung mit JavaFX Die Java UI-Technologie im JDK 8 Wolfgang Weigend Sen. Leitender Systemberater Java Technologie und Architektur 1 Copyright © 2016 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 © 2016 Oracle and/or its affiliates. All rights reserved. Agenda • Aktueller Status von JavaFX • Entwicklungsressourcen beim Engineering und in der Java Community • Linux on ARM Port • JavaFX-Aufbau und Architekturkonzept • Migration von Swing Komponenten • Barrierefreiheit • Vorteile bei der Entwicklung von JavaFX Anwendungen • SceneBuilder GUI Editor • Automatisiertes Testen von JavaFX GUI Komponenten • Open Source Projekt OpenJFX • Kundenbeispiele, Projekte und relevante Partnerlösungen • Zusammenfassung 3 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. Aktueller Status von JavaFX • JavaFX 8 ist fester Bestandteil der Java SE 8 – General Availability for Windows, Linux, Mac OS – Java SE 8 Roadmap until 2025 and expected JDK 9 until 2028 – 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.2 – JavaFX Scene Builder 2.0 und Version 8.2.0 – e(fx)clipse • major release cycle alignment with eclipse roadmap • minor release cycle with JavaFX roadmap 4 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. Entwicklungsressourcen beim Engineering und in der Java Community • Development Team – Kevin Rushforth – Senior Engineering Manager – [email protected] – Technical Writer and Documentation – Oracle Java Support • Java Community – Gluon – MicroDoc Systems – BestSolution.at EDV Systemhaus GmbH – Saxonia Systems AG, Canoo Engineering AG, open knowledge GmbH – Dirk Lemmermann 5 Copyright © 2016 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 6 Copyright © 2016 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/ 7 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. JavaFX Linux on ARM Port created by MicroDoc • Agreement by Oracle and MicroDoc • 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 • 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 10 Copyright © 2016 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 11 Copyright © 2016 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 12 Copyright © 2016 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 13 Copyright © 2016 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 − Rasterization − 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 14 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. * No direct OpenGL support JavaFX Architektur • Windowing API − Windows − Mac − Linux − Headless (not done) • Provides basic OS services − Drawing surface − Input events − Event queue 15 Copyright © 2016 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() 16 Copyright © 2016 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(); } } 17 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. JavaFX mit JFXPanel Komponente in Swing Anwendungen einbinden public class Test { private staticClass void initAndShowGUI() JFXPanel { private static void initFX(JFXPanel fxPanel) { // This methodjava.lang.Object is invoked on Swing thread // This method is invoked on JavaFX thread JFrame frame =java.awt.Component new JFrame("FX"); Scene scene = createScene(); final JFXPanel fxPanel = new JFXPanel(); fxPanel.setScene(scene); frame.add(fxPanel); java.awt.Container} frame.setVisible(true); javax.swing.JComponent javafx.embed.swing.JFXPanelpublic static void main(String[] args) { Platform.runLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() { @Override @Override public void run() { public void run() { initFX(fxPanel); initAndShowGUI(); } } }); }); } } } 18 Copyright © 2016 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); } } 19 Copyright © 2016 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); } } 20 Copyright © 2016 Oracle and/or its affiliates. All rights reserved. JavaFX Scene Builder 2.0 http://www.oracle.com/technetwork/java/javase/downloads/sb2download-2177776.html 21 Copyright © 2016 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 22 Copyright © 2016 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