JacpFX and DataFX-flows, a perfect match for JavaFX
Join the DZone community and get the full member experience.
Join For Free
Create a JacpFX application from archetype:
JacpFX provides a simple archetype with two example perspectives (FXML + JavaFX view) and two components, reused in both perspectives. To create a basic JacpFX application use the simple archetype:
mvn archetype:generate -DarchetypeGroupId=org.jacpfx -DarchetypeArtifactId=JacpFX-simple-quickstart -DarchetypeVersion=2.0.2
To integrate the DataFX-flow plugin add following dependency to your pom:
<dependency> <groupId>org.jacpfx</groupId> <artifactId>jacpfx.JavaFXDataFXPlugin</artifactId> <version>1.0</version> <scope>compile</scope> </dependency>
Create a simple Flow between two DataFX-flow controllers
Now we create two DataFX-flow controllers, a WizardStartController and a Wizard1Controller. The Wizard1Controller will contain the JacpFX context and include a textfield, text input will be send via messages to a JacpFX component. The controller will look like this:
@FXMLController(value="/fxml/wizard1.fxml", title = "Wizard: Step 1") public class Wizard1Controller { @FXML @ActionTrigger("back") private Button backButton; @FXML @ActionTrigger("next") private Button nextButton; /** ** The JacpFX context **/ @Resource private Context context; @FXML private TextField name; @PostConstruct public void init() { nextButton.setDisable(true); name.setOnKeyReleased(event->{ context.send(BasicConfig.COMPONENT_BOTTOM, name.getText()); }); } }
Integrate the DataFX-flow into a JacpFX component
@View(id = BasicConfig.COMPONENT_TOP, name = "SimpleView", resourceBundleLocation = "bundles.languageBundle", initialTargetLayoutId = BasicConfig.TARGET_CONTAINER_TOP) public class ComponentLeft implements FXComponent { private Node pane; @Resource private Context context; @Override public Node handle(final Message<Event, Object> message) { // runs in worker thread return null; } @Override public Node postHandle(final Node arg0, final Message<Event, Object> message) { // runs in FX application thread return this.pane; } @PostConstruct public void onPostConstructComponent(final FXComponentLayout arg0, final ResourceBundle resourceBundle) { this.pane = createUI(); } private Node createUI() { final VBox main = new VBox(); Flow flow = new DataFXFlowWrapper(WizardStartController.class,BasicConfig.COMPONENT_TOP). withLink(WizardStartController.class, "next", Wizard1Controller.class). withGlobalBackAction("back"); FlowHandler flowHandler = flow.createHandler(); StackPane pane = null; try { pane = flowHandler.start(new AnimatedFlowContainer(Duration.millis(320), ContainerAnimations.ZOOM_IN)); main.getChildren().add(pane); } catch (FlowException e) { e.printStackTrace(); } return main; } }
JacpFX and DataFX-flow needs Java 8 / JavaFX 8 to run, a packed jar you can download here: http://jacpfx.org/data/SimpleDataFX_JacpFX.jar , simply execute:
java -jar SimpleDataFX_JacpFX.jar
Opinions expressed by DZone contributors are their own.
Comments