Integration of DukeScript Models with UI defined in FXML and rendered in JavaFX.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Use FXML to define your UI and use @Model to define your MVVM logic. To use the system in your JavaFX application, create standard Scene.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="" >
        <Button layoutX="126" layoutY="90" text="Click Me!" onAction="$controller.handleButtonAction"  />
        <Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" text="${controller.testString}" />
        <ListView layoutX="126" layoutY="160" minHeight="60" minWidth="100" items = "${controller.testList}">

The FXML is referencing properties of your controller class, which can be easily defined using @Model annotation:

@Model(className = "ViewModel", properties = {
    @Property(name = "testString", type = String.class),
    @Property(name = "testList", type = String.class, array = true)
public class SimpleController {
    static void handleButtonAction(ViewModel vm) {
        vm.setTestString("Hello World!");

Such model carries two properties and a function handleButtonAction which acts on the model and gets invoked by the button defined in the FXML file once it is clicked. At the end, one just instantiates the whole scene and binds it together with the controller:

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("SimpleScene.fxml"));
viewModel = new ViewModel("Hallo Hallo", "val1", "val2", "val3");
Parent rootNode = fxmlLoader.load();

Your model view view model completely separated from the JavaFX UI definition has just become reality!