From 47e0ad7393a15488e71198d40f50beb966d3a83e Mon Sep 17 00:00:00 2001 From: Nathan McRae Date: Wed, 1 Jan 2025 20:24:14 -0800 Subject: [PATCH] Add basic property binding test --- .../nathanmcrae/NumbersStationSettings.fxml | 4 ++-- .../NumbersStationSettingsController.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/name/nathanmcrae/NumbersStationSettings.fxml b/src/main/java/name/nathanmcrae/NumbersStationSettings.fxml index 3212bef..134e56d 100644 --- a/src/main/java/name/nathanmcrae/NumbersStationSettings.fxml +++ b/src/main/java/name/nathanmcrae/NumbersStationSettings.fxml @@ -21,7 +21,7 @@ diff --git a/src/main/java/name/nathanmcrae/NumbersStationSettingsController.java b/src/main/java/name/nathanmcrae/NumbersStationSettingsController.java index 40d6407..d344db6 100644 --- a/src/main/java/name/nathanmcrae/NumbersStationSettingsController.java +++ b/src/main/java/name/nathanmcrae/NumbersStationSettingsController.java @@ -5,11 +5,20 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import java.io.File; import java.io.IOException; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.fxml.FXML; import javafx.scene.control.TextField; public class NumbersStationSettingsController { private NumbersStationSettings settings; + private StringProperty stationNameAndAddress = new SimpleStringProperty(); + + @FXML + private TextField stationNameField; + + @FXML + private TextField stationAddressField; public NumbersStationSettingsController() throws IOException { System.out.println("Created settings controller"); @@ -20,9 +29,19 @@ public class NumbersStationSettingsController { settings.getStations().add(new StationSettings()); } + @FXML + private void initialize() { + stationNameField.textProperty().bindBidirectional(stationNameAndAddress); + stationAddressField.textProperty().bindBidirectional(stationNameAndAddress); + } + @FXML private void handleSaveButtonPress() throws IOException { XmlMapper xmlMapper = new XmlMapper(); xmlMapper.writeValue(new File("setting-test.xml"), settings); } + + public StringProperty stationNameAndAddressProperty() { + return stationNameAndAddress; + } }