From e21c078e4c92cad78eeb736c0e65e16d6ef3a723 Mon Sep 17 00:00:00 2001 From: Nathan McRae Date: Sat, 11 Jan 2025 13:25:12 -0800 Subject: [PATCH] Bind spinners to settings and save settings values --- .../MainSettingsController.java | 23 +++++++++++++++++++ .../numbersstation/MainSettingsView.fxml | 20 ++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java index ee53f69..a10bbe1 100644 --- a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java +++ b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java @@ -5,10 +5,14 @@ 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.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.Event; import javafx.fxml.FXML; +import javafx.scene.control.Spinner; +import javafx.scene.control.SpinnerValueFactory; import javafx.scene.control.TextField; import javafx.scene.Node; import javafx.stage.Stage; @@ -17,6 +21,8 @@ public class MainSettingsController { private StationSettings settings; private StringProperty stationAddress = new SimpleStringProperty(); private StringProperty stationName = new SimpleStringProperty(); + private IntegerProperty digitsPerGroup = new SimpleIntegerProperty(); + private IntegerProperty messageLength = new SimpleIntegerProperty(); @FXML private TextField stationNameField; @@ -24,6 +30,12 @@ public class MainSettingsController { @FXML private TextField stationAddressField; + @FXML + private Spinner digitsPerGroupSpinner; + + @FXML + private Spinner messageLengthSpinner; + public MainSettingsController() throws IOException { // System.out.println("Created settings controller"); // File file = new File("setting-test.xml"); @@ -37,6 +49,12 @@ public class MainSettingsController { private void initialize() { stationNameField.textProperty().bindBidirectional(stationName); stationAddressField.textProperty().bindBidirectional(stationAddress); + + digitsPerGroupSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1)); + messageLengthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1)); + + digitsPerGroupSpinner.getValueFactory().valueProperty().bindBidirectional(digitsPerGroup.asObject()); + messageLengthSpinner.getValueFactory().valueProperty().bindBidirectional(messageLength.asObject()); } @FXML @@ -61,6 +79,9 @@ public class MainSettingsController { private void handleSaveButtonPress(Event e) { settings.setAddress(stationAddress.get()); + settings.setDigitsPerGroup(digitsPerGroup.get()); + settings.setMessageLength(messageLength.get()); + Node node = (Node) e.getSource(); Stage stage = (Stage) node.getScene().getWindow(); stage.setUserData(true); @@ -74,5 +95,7 @@ public class MainSettingsController { public void setStationSettings(StationSettings newSettings) { settings = newSettings; stationName.set(settings.getName()); + digitsPerGroup.set(settings.getDigitsPerGroup()); + messageLength.set(settings.getMessageLength()); } } diff --git a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml index 41b75d3..af39332 100644 --- a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml +++ b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml @@ -38,7 +38,7 @@ - + @@ -47,17 +47,7 @@ - - - - - - - + @@ -67,13 +57,13 @@ - + - +