Transcript
Page 1: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Building non-blocking JavaFX 8 applications with JacpFX

13.04.2023 http://jacpfx.org @ JavaOne 2014 1

[email protected] / @AndyAHCP

Page 2: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

About us Andy Moncsek

Java consultant (Trivadis AG Switzerland) mainly working on JacpFX “core framework” Twitter: @AndyAHCP

13.04.2023 http://jacpfx.org @ JavaOne 2014 2

Patrick Symmangk a.k.a. "PETE” Java and web-developer mainly working on UI and custom-

controls Twitter: @slashPETE

Page 3: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Agenda

Introduction to JacpFX

Integration example with MQTT

Demo

13.04.2023 http://jacpfx.org @ JavaOne 2014 3

Page 4: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Introduction to JacpFX RCP on JavaFX

13.04.2023 http://jacpfx.org @ JavaOne 2014 4

2006/7

Jacp

2009

Jacp SWT/Swing

2011/12

JacpFX 1.0

2014

JacpFX 2.0

Page 5: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Messaging

Non-B

lock

ing U

ILoose coupling

Com

posi

tion

13.04.2023 http://jacpfx.org @ JavaOne 2014 5

Page 6: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Structuring & composition

13.04.2023 http://jacpfx.org @ JavaOne 2014 6

Page 7: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Structuring & composition

UI is always hierarchicalControl / know your UI tree

○ Workbench: Main Window, ToolBar○ Perspective(s): Master-View (page

template)○ Component(s): Detail-View (reusable)

Reuse controller / view in different context

13.04.2023 http://jacpfx.org @ JavaOne 2014 7

Page 8: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Structuring & composition

@Perspective(viewLocation = "/fxml/perspectiveOne.fxml")public class PerspectiveOne implements FXPerspective { @FXML HBox cTop, cMain;

@PostConstruct public void onStartPerspective(PerspectiveLayout pl) {

pl.registerTargetLayoutComponent("TOP", cTop); pl.registerTargetLayoutComponent("MAIN", cMain);}

}

13.04.2023 http://jacpfx.org @ JavaOne 2014 8

Page 9: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Structuring & composition

@DeclarativeView(initialTargetLayoutId = "MAIN",

viewLocation = "/fxml/View_1.fxml")public class ComponentTwo implements FXComponent {

…}

13.04.2023 http://jacpfx.org @ JavaOne 2014 9

Page 10: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Loose coupling

13.04.2023 http://jacpfx.org @ JavaOne 2014 10

Page 11: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Loose coupling

No direct references (only by ID)

Move / replace components (at runtime)

Reuse components in different contexts

Easy packaging

13.04.2023 http://jacpfx.org @ JavaOne 2014 11

Page 12: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Loose coupling// annotations@Workbench(id = "id1”, perspectives = {"p01","p02"})

@Perspective(id = "p01”, components = {"c01","c02"})

@View(id = "c01”, initialTargetLayoutId = "TOP")

// render target registrationpl.registerTargetLayoutComponent("TOP", cTop);

13.04.2023 http://jacpfx.org @ JavaOne 2014 12

Page 13: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Messaging

13.04.2023 http://jacpfx.org @ JavaOne 2014 13

Page 14: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Messaging

Lightweight communicationState changing (know the lifecycle)Asynchronous

Decouple cause and effect

Easy to understandAddressing: “perspectiveId .

componentId”

13.04.2023 http://jacpfx.org @ JavaOne 2014 14

Page 15: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Messaging// message to yourselfctx.send("Hello World")

// message to perspective p01ctx.send("p01","Hello World")

// message to component c01 in perspective p01ctx.send("p01.c01","Hello World")

13.04.2023 http://jacpfx.org @ JavaOne 2014 15

Page 16: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Non-Blocking UI

13.04.2023 http://jacpfx.org @ JavaOne 2014 16

Page 17: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Non-Blocking UI

Triggered by messagesSequential message handling

Separate tasks from state changingExecute tasks in worker threadUpdate view in FXApplication thread

13.04.2023 http://jacpfx.org @ JavaOne 2014 17

Page 18: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Non-Blocking UI@View(id="c01",…)public class ComponentTwo implements FXComponent { public Node handle(Message m) throws Exception { // executed in workers thread on message return new HBox(); } public Node postHandle(Node n, Message m) throws Exception{ // in FX Thread after "handle(...)" is finished

parent.getChildren().add(n); return parent; }}

13.04.2023 http://jacpfx.org @ JavaOne 2014 18

Page 19: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Extras

ToolBar, Dialog, Option Button

Context & Resource injection

Lifecycle annotations

(Dependency Injection)Depends on „Launcher“

implementation

13.04.2023 http://jacpfx.org @ JavaOne 2014 19

Page 20: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

JACPToolbar Extended JavaFX Toolbar

Add Regions to front/top, center/end

Automatic or manual button management

13.04.2023 http://jacpfx.org @ JavaOne 2014 20

Page 21: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Dialog

Modal Dialog on top of a blurry UIDialog and blur on separate layers

Base for JACPOptionPaneDialog with Button-Support

13.04.2023 http://jacpfx.org @ JavaOne 2014 21

Page 22: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration example with MQTT

13.04.2023 http://jacpfx.org @ JavaOne 2014 22

Page 23: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration

Example: remote drawing

Connected via Topic to MQTT BrokerMQTT (Message Queue Telemetry

Transport): machine-to-machine connectivity protocol for lightweight publish/subscribe messaging

13.04.2023 http://jacpfx.org @ JavaOne 2014 23

Page 24: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration Non UI Component

Move impl. to extra componentHide integration from UIIntegrate via internal message bus

13.04.2023 http://jacpfx.org @ JavaOne 2014 24

Page 25: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration

@Component(id="MQTT01")public class Mqtt implements CallbackComponent, MqttCallback {

public Object handle(Message m) throws Exception { if (m.isMessageBodyTypeOf(ConnProperties.class)) // subscribe to topic else if (m.isMessageBodyTypeOf(CPoint.class)) // publish to topic return null;

}

public void messageArrived(String s, MqttMessage m){...}}

13.04.2023 http://jacpfx.org @ JavaOne 2014 25

Page 26: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration

Mouse EventCoordinates on the Canvas send via

message bus

c.addEventHandler(MOUSE_DRAGGED,(e) ->ctx.send("p01.MQTT01", new CPoint(e.getX(), e.getY(), Type.DRAW)));

13.04.2023 http://jacpfx.org @ JavaOne 2014 26

Page 27: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration

DrawingReceives X,Y from integration

component

13.04.2023 http://jacpfx.org @ JavaOne 2014 27

Page 28: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Integration@DeclarativeViewpublic class CanvasComponent implements FXComponent {...

public Node postHandle(Node n, Message m) throws Exception { if (m.isMessageBodyTypeOf(CPoint.class)) {

CPoint p= m.getTypedMessageBody(CPoint.class); gc.lineTo(p.getX(), p.getY());

... } return null; }

}

13.04.2023 http://jacpfx.org @ JavaOne 2014 28

Page 29: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

DEMO

13.04.2023 http://jacpfx.org @ JavaOne 2014 29

Page 30: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

Outlook

Mobile/Embedded friendly UI

New Message bus?Network transparent

Classloader isolation?

More demos / archtypes

13.04.2023 http://jacpfx.org @ JavaOne 2014 30

Page 31: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

http://jacpfx.org

[email protected] / @AndyAHCP

[email protected] / @slashPETE

13.04.2023 http://jacpfx.org @ JavaOne 2014 31

Page 32: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

QA

13.04.2023 http://jacpfx.org @ JavaOne 2014 32

Page 33: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]

References

http://jacpfx.org https://github.com/JacpFX/JacpFX www.javafxdata.org http://mqtt.org http://vertx.io

13.04.2023 http://jacpfx.org @ JavaOne 2014 33


Recommended