Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
-
Upload
andy-moncsek -
Category
Technology
-
view
693 -
download
2
description
Transcript of Building non-blocking JavaFX 8 applications with JacpFX [CON1823]
![Page 1: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/1.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/2.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/3.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/4.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/5.jpg)
Messaging
Non-B
lock
ing U
ILoose coupling
Com
posi
tion
13.04.2023 http://jacpfx.org @ JavaOne 2014 5
![Page 7: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/7.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/8.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/9.jpg)
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 11: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/11.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/12.jpg)
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 14: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/14.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/15.jpg)
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 17: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/17.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/18.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/19.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/20.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/21.jpg)
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 23: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/23.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/24.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/25.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/26.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/27.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/28.jpg)
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 30: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/30.jpg)
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]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/31.jpg)
http://jacpfx.org
[email protected] / @AndyAHCP
[email protected] / @slashPETE
13.04.2023 http://jacpfx.org @ JavaOne 2014 31
![Page 33: Building non-blocking JavaFX 8 applications with JacpFX [CON1823]](https://reader036.fdocuments.net/reader036/viewer/2022081502/5579a527d8b42ac1148b4a42/html5/thumbnails/33.jpg)
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