+ All Categories
Home > Engineering > JavaFX in Action (devoxx'16)

JavaFX in Action (devoxx'16)

Date post: 17-Feb-2017
Category:
Upload: alexander-casall
View: 207 times
Download: 1 times
Share this document with a friend
90
ALEXANDER CASALL JavaFX in Action
Transcript
Page 1: JavaFX in Action (devoxx'16)

ALEXANDER CASALL

JavaFX in Action

Page 2: JavaFX in Action (devoxx'16)

Alexander Casall

sialcasa

Page 3: JavaFX in Action (devoxx'16)

HISTORY OF JAVAFX USING GOOGLE TRENDS

JavaFX Script1.0

F3

1.3

JavaFX2.0

JavaFX8

Classpath integration3DAPIPrinting

8.XAccessibility,Controls...

JavaAPIOpenJFX

ScriptLanguageFlashSuccessor

Page 4: JavaFX in Action (devoxx'16)

0 20 40 60 80 100 120 140 160

IneverusedJavaFXbefore

IdidsomeexperimentswithJavaFX

IuseJavaFXinaproductiveapplication

IuseJavaFX,buttheprojectisstillindevelopment

Poll:DoyouuseJavaFX?

DoyouuseJavaFX?

Jaxenter poll

38%

29%

20%

10%

Page 5: JavaFX in Action (devoxx'16)

Where can you use JavaFX?

Page 6: JavaFX in Action (devoxx'16)

Embedded (even on ARM)

Page 7: JavaFX in Action (devoxx'16)

TODOMobileScreenshot

Mobile

Page 8: JavaFX in Action (devoxx'16)

Web(Demos later)

Page 9: JavaFX in Action (devoxx'16)

Even for boringDesktop Apps

Page 10: JavaFX in Action (devoxx'16)

Office Management Software of the German AIDS Foundation

Page 11: JavaFX in Action (devoxx'16)
Page 12: JavaFX in Action (devoxx'16)
Page 13: JavaFX in Action (devoxx'16)
Page 14: JavaFX in Action (devoxx'16)

Where to start with FX?

Page 15: JavaFX in Action (devoxx'16)

Hello World

Page 16: JavaFX in Action (devoxx'16)

Stage

Scene

VBox

StackPane

Label Button

extends javafx.scene.Node

ImageView

Page 17: JavaFX in Action (devoxx'16)

Beyond Hello World

Page 18: JavaFX in Action (devoxx'16)

GridPane grid = new GridPane();grid.setHgap(10);grid.setVgap(10);

Text scenetitle = new Text("Antragsgegenstand");scenetitle.setFont(Font.font("SegoeUI", FontWeight.BOLD, 13.0));grid.add(scenetitle, 0, 0, 2, 1);

Label categoryLabel = new Label("Kategorie:");grid.add(categoryLabel, 0, 1);

ComboBox<String> categoryCombo = new ComboBox<>();grid.add(categoryCombo, 1, 1);categoryCombo.setMaxWidth(Double.MAX_VALUE);

Label subjectLabel = new Label("Gegenstand:");grid.add(subjectLabel, 0, 2);

TextField subjectTextField = new TextField();grid.add(subjectTextField, 1, 2);

Label statusLabel = new Label("Status:");grid.add(statusLabel, 0, 3);

ComboBox<String> statusCombo = new ComboBox<>();grid.add(statusCombo, 1, 3);statusCombo.setMaxWidth(Double.MAX_VALUE);

Page 19: JavaFX in Action (devoxx'16)

GridPane grid = new GridPane();grid.setHgap(10);grid.setVgap(10);

Text scenetitle = new Text("Antragsgegenstand");scenetitle.setFont(Font.font("SegoeUI", FontWeight.BOLD, 13.0));grid.add(scenetitle, 0, 0, 2, 1);

Label categoryLabel = new Label("Kategorie:");grid.add(categoryLabel, 0, 1);

ComboBox<String> categoryCombo = new ComboBox<>();grid.add(categoryCombo, 1, 1);

Page 20: JavaFX in Action (devoxx'16)
Page 21: JavaFX in Action (devoxx'16)

FXMLDeclaration of the UI

Page 22: JavaFX in Action (devoxx'16)
Page 23: JavaFX in Action (devoxx'16)

<GridPane fx:controller="de.aidsstiftung.aida.ContractView" …><columnConstraints>…</columnConstraints><rowConstraints>…</rowConstraints><children><TextField fx:id="subjectTextField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<ComboBox fx:id="statusCombo" onAction="#onStatusComboAction" GridPane.columnIndex="1" GridPane.rowIndex="3" />

<ComboBox fx:id="categoryCombo" onAction="#onCategoryComboAction" GridPane.columnIndex="1" GridPane.rowIndex="1" />

<Text strokeType="OUTSIDE" styleClass="headerlabel” text="Antragsgegenstand" />

<Label text="Kategorie" GridPane.rowIndex="1" /><Label text="Gegenstand" GridPane.rowIndex="2" /><Label text="Status" GridPane.rowIndex="3" />

</children></GridPane>

Page 24: JavaFX in Action (devoxx'16)

public class ContractView{

@FXMLprivate TextField subjectTextField;

@FXMLprivate ComboBox<String> statusCombo;

@FXMLprivate ComboBox<String> categoryCombo;

@FXMLvoid onCategoryComboAction(ActionEvent event) {

System.out.println("Category changed: " + categoryCombo.valueProperty());}

@FXMLvoid onStatusComboAction(ActionEvent event) {

System.out.println("Status changed" + statusCombo.valueProperty());}

Page 25: JavaFX in Action (devoxx'16)

URL fxml = getClass().getResource("ContractView.fxml");FXMLLoader loader = new FXMLLoader(fxml);loader.setController(new ContractView());GridPane grid = loader.load();

Page 26: JavaFX in Action (devoxx'16)

http://gluonhq.com/products/downloads/

Use Scene Builder to create UI-Components

Page 27: JavaFX in Action (devoxx'16)

How many FXML Files were used?

Page 28: JavaFX in Action (devoxx'16)
Page 29: JavaFX in Action (devoxx'16)
Page 30: JavaFX in Action (devoxx'16)

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.StackPane?>

<StackPane xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx=…><children>

<fx:include source="child1.fxml" /><fx:include source="child2.fxml" />

</children></StackPane>

Page 31: JavaFX in Action (devoxx'16)

Back to our component

Page 32: JavaFX in Action (devoxx'16)

Coded FXML

Page 33: JavaFX in Action (devoxx'16)

CSSStyling

Page 34: JavaFX in Action (devoxx'16)

<GridPane styleClass="contentgrid"><columnConstraints>…</columnConstraints><rowConstraints>…</rowConstraints><children><TextField fx:id="subjectTextField" GridPane.columnIndex="1" GridPane.rowIndex="2"/>

<ComboBox fx:id="statusCombo" onAction="#onStatusComboAction" GridPane.columnIndex="1" GridPane.rowIndex="3" />

<ComboBox fx:id="categoryCombo" onAction="#onCategoryComboAction" GridPane.columnIndex="1" GridPane.rowIndex="1" />

<Text strokeType="OUTSIDE" styleClass="headerlabel” text="Antragsgegenstand" />

<Label text="Kategorie" GridPane.rowIndex="1" /><Label text="Gegenstand" GridPane.rowIndex="2" /><Label text="Status" GridPane.rowIndex="3" />

</children></GridPane>

Page 35: JavaFX in Action (devoxx'16)

.headerlabel{-fx-font-width:15pt;-fx-font-weight:bold;

}

.contentgrid{-fx-hgap: 10px;-fx-vgap: 10px;

}

.contentgrid > .combo-box{-fx-max-width: infinity;

}

Page 36: JavaFX in Action (devoxx'16)
Page 37: JavaFX in Action (devoxx'16)

SceneBuilder CSS Debugger

Page 38: JavaFX in Action (devoxx'16)

CSS ScopesApplication, Scene, FXML, Control

Page 39: JavaFX in Action (devoxx'16)

APPLICATION SCOPE

Application.setUserAgentStylesheet("file:///style.css");

Page 40: JavaFX in Action (devoxx'16)
Page 41: JavaFX in Action (devoxx'16)

NODE SCOPE

Page 42: JavaFX in Action (devoxx'16)

CONTROL SCOPE

public class Calendar extends Control {…@Overridepublic String getUserAgentStylesheet(){

return "calendar.css";}

}

Page 43: JavaFX in Action (devoxx'16)

Property API

Bindings, Listener

Page 44: JavaFX in Action (devoxx'16)

StringProperty

String

StringProperty

String

Binding

Observer

Property API

Page 45: JavaFX in Action (devoxx'16)
Page 46: JavaFX in Action (devoxx'16)

textfield1.textProperty().bindBidirectional(textfield2.textProperty());

Page 47: JavaFX in Action (devoxx'16)

ColorPicker Example

Page 48: JavaFX in Action (devoxx'16)
Page 49: JavaFX in Action (devoxx'16)

TextField searchTextField = new TextField();Button searchButton = new Button();

searchButton.disableProperty().bind(searchTextField.textProperty().isNotEmpty());

Page 50: JavaFX in Action (devoxx'16)

Button searchButton = new Button();TextField searchTextField = new TextField();

BooleanBinding isNumberBinding = Bindings.createBooleanBinding(() ->

searchTextField.getText().matches(".*\\d+.*"),searchTextField.textProperty());

searchButton.disableProperty().bind(searchTextField.textProperty().isNotEmpty() .and(isNumberBinding));

Page 51: JavaFX in Action (devoxx'16)

Fancy Stuff

Page 52: JavaFX in Action (devoxx'16)

Dropshadow

Page 53: JavaFX in Action (devoxx'16)

Effects

Page 54: JavaFX in Action (devoxx'16)

Animation

Page 55: JavaFX in Action (devoxx'16)
Page 56: JavaFX in Action (devoxx'16)

TIMELINES AND TRANSITIONS

0s 10s

layoutXProperty ==0 layoutXProperty ==250

KeyValue targetPoint = new KeyValue(node.translateXProperty(), 250);KeyFrame keyFrame = new KeyFrame(Duration.seconds(10), targetPoint);Timeline moveTimeline = new Timeline(keyFrame);moveTimeline.play();

TranslateTransition moveTransition = new TranslateTransition(Duration.seconds(10), node);

moveTransition.setByY(250);moveTransition.play();

Page 57: JavaFX in Action (devoxx'16)

More helpful Features

Page 58: JavaFX in Action (devoxx'16)

Multi TouchGestures and More

Page 59: JavaFX in Action (devoxx'16)

Pane taskPane = new TaskPane(task);

taskPane.setOnTouchMoved(new EventHandler<TouchEvent>(){@Overridepublic void handle(TouchEvent event){

calculateScaleOfTask(event.getTouchPoints());}

});

Page 60: JavaFX in Action (devoxx'16)

Shape

Shape

Shape

Rezizable

node.setOnSwipeRight(…);

node.setOnRotate(…);

node.setOnZoom(…);

node.setOnScroll(…);

Multi Touch and Gestures

Page 61: JavaFX in Action (devoxx'16)

WEBVIEWEmbed Webcontent into JavaFX Applications

Page 62: JavaFX in Action (devoxx'16)

Maps Example

Page 63: JavaFX in Action (devoxx'16)

WebView

WebEngine

Loads a Webpage

Manages DOM

Executes JavaScript

JavaScript <-> Java

Node in GraphScene

STRUCTUREWebView

Page 64: JavaFX in Action (devoxx'16)

System.out.println(webEngine.getUserAgent());

Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/538.19 (KHTML, like Gecko) JavaFX/8.0 Safari/538.19

TYP / VERSIONWebEngine

Page 65: JavaFX in Action (devoxx'16)

webEngine.load("http://google");

webEngine.loadContent("<html><body>hello</body></html>");

webEngine.loadHtml("/hello.html");

LOAD CONTENTWebEngine

Page 66: JavaFX in Action (devoxx'16)

INTERACTION

WebView

Page 67: JavaFX in Action (devoxx'16)

LAST BUT NOT LEAST

Page 68: JavaFX in Action (devoxx'16)

Test & Deployment

Page 69: JavaFX in Action (devoxx'16)

Test-Pyramid

Unit Tests

Integration Tests

Acceptance Tests

Page 70: JavaFX in Action (devoxx'16)

TestFX

rightClickOn("#desktop").moveTo("New").clickOn("Text Document"); write("myTextfile.txt").push(ENTER); // when: drag(".file").dropTo("#trash-can"); verifyThat("#desktop", hasChildren(0, ".file"));

Page 71: JavaFX in Action (devoxx'16)

QF-Test

Page 72: JavaFX in Action (devoxx'16)

DEPLOYMENT

Page 73: JavaFX in Action (devoxx'16)

Webstart is an Option

Page 74: JavaFX in Action (devoxx'16)

Package a native app is another option

Page 75: JavaFX in Action (devoxx'16)

javapackager -makeall -appclass src/de/saxsys/javafx/Starter.java -name Example -width 600 -height 600

1. Package

Page 76: JavaFX in Action (devoxx'16)

https://github.com/edvin/fxlauncher

Launcher App.v1

2. Distribute

Über URL erreichbare Ablage

Page 77: JavaFX in Action (devoxx'16)

https://github.com/edvin/fxlauncher

Launcher App.v1

2. Distribute

via URL accessible Space

Page 78: JavaFX in Action (devoxx'16)

https://github.com/edvin/fxlauncher

Launcher App.v1

2. Distribute

App.v1

Page 79: JavaFX in Action (devoxx'16)

https://github.com/edvin/fxlauncher

Launcher App.v2

2. Distribute

App.v1

Page 80: JavaFX in Action (devoxx'16)

Break :-)

Page 81: JavaFX in Action (devoxx'16)

JavaFX runs on mobile using

Page 82: JavaFX in Action (devoxx'16)

JavaFX runs also in the browser using

Page 83: JavaFX in Action (devoxx'16)

Hello World

Page 84: JavaFX in Action (devoxx'16)

controller and model tier (business logic)

Server

JavaFX (JAVA, FXML, CSS)

JVM

Client

HTML5 (CSS, JS, SVG)

view tier (rendering)

Browser

Architecture

Page 85: JavaFX in Action (devoxx'16)

JavaVirtualMachine

JDKAPILibraries&Tools

Java2D/OpenGL/D3D

Prism/GlassWindowingToolkit/MediaEngine/WebEngine

QuantumToolkit

JavaFXPublicAPIsandSceneGraph

How does the magic works

Page 86: JavaFX in Action (devoxx'16)

JavaVirtualMachine

JDKAPILibraries&Tools

Java2D/OpenGL/D3D

Prism/GlassWindowingToolkit/MediaEngine/WebEngine

QuantumToolkit

JavaFXPublicAPIsandSceneGraph

How does the magic works

Page 87: JavaFX in Action (devoxx'16)

● Reasonablenewbrowser● Websocket supported● JavaScriptenabled● Usage of Webspecific APIs

Prerequisites

Page 88: JavaFX in Action (devoxx'16)

Multiview Demo

http://multiview.jpro.io

Page 89: JavaFX in Action (devoxx'16)

jpro.io

Page 90: JavaFX in Action (devoxx'16)

Let‘s answer the question:Who uses JavaFX?


Recommended