Upload
andy-moncsek
View
690
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Event bus, message passing, and async execution are concepts that are getting more and more popular for server-side applications. JacpFX brings this approach to the client, combining JavaFX with an actorlike component model. It is an UI application framework based on JavaFX, supporting developers in structuring applications with loosely coupled, reusable components. It frees you from the pitfalls of traditional multithreaded programming, helping you separate the task execution from UI changes in your client application. Furthermore, this component model works well with common communication technologies such as WebSocket, SSE, and JMS.
Citation preview
Building non-blocking JavaFX 8 applications with JacpFX
13.04.2023 http://jacpfx.org @ JavaOne 2014 1
[email protected] / @AndyAHCP
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
Agenda
Introduction to JacpFX
Integration example with MQTT
Demo
13.04.2023 http://jacpfx.org @ JavaOne 2014 3
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
Messaging
Non-B
lock
ing U
ILoose coupling
Com
posi
tion
13.04.2023 http://jacpfx.org @ JavaOne 2014 5
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
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
Structuring & composition
@DeclarativeView(initialTargetLayoutId = "MAIN",
viewLocation = "/fxml/View_1.fxml")public class ComponentTwo implements FXComponent {
…}
13.04.2023 http://jacpfx.org @ JavaOne 2014 9
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
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
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
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
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
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
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
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
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
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
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
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
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
Integration
DrawingReceives X,Y from integration
component
13.04.2023 http://jacpfx.org @ JavaOne 2014 27
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
Outlook
Mobile/Embedded friendly UI
New Message bus?Network transparent
Classloader isolation?
More demos / archtypes
13.04.2023 http://jacpfx.org @ JavaOne 2014 30
http://jacpfx.org
[email protected] / @AndyAHCP
[email protected] / @slashPETE
13.04.2023 http://jacpfx.org @ JavaOne 2014 31
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