From 3dcd3adf0311df0f23ca619a0484c396cef0477d Mon Sep 17 00:00:00 2001 From: Nathan McRae Date: Sun, 5 Jan 2025 11:24:47 -0800 Subject: [PATCH] Add basic station selection --- .../nathanmcrae/NumbersStationController.java | 46 +++++++++-- .../nathanmcrae/NumbersStationSelection.fxml | 11 ++- .../NumbersStationSelectionController.java | 77 +++++++++++++++++++ 3 files changed, 122 insertions(+), 12 deletions(-) create mode 100644 src/main/java/name/nathanmcrae/NumbersStationSelectionController.java diff --git a/src/main/java/name/nathanmcrae/NumbersStationController.java b/src/main/java/name/nathanmcrae/NumbersStationController.java index 4fe7668..569ccc9 100644 --- a/src/main/java/name/nathanmcrae/NumbersStationController.java +++ b/src/main/java/name/nathanmcrae/NumbersStationController.java @@ -1,23 +1,26 @@ package name.nathanmcrae; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ResourceBundle; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.scene.control.Label; +import javafx.scene.control.TextArea; import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyCode; import javafx.scene.Parent; import javafx.scene.Scene; +import javafx.stage.Modality; import javafx.stage.Stage; -import javafx.scene.control.Label; -import javafx.scene.control.TextArea; - -import java.net.URL; -import java.util.ResourceBundle; public class NumbersStationController implements Initializable { private Stage settingsStage; - private Stage selectStationStage; + private NumbersStationSettings settings; @FXML private Label lastRetrievedLabel; @@ -52,10 +55,29 @@ public class NumbersStationController implements Initializable { try { FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("NumbersStationSelection.fxml")); Parent root = fxmlLoader.load(); + + // Pass settings to the controller + NumbersStationSelectionController controller = fxmlLoader.getController(); + controller.setSettings(settings); + selectStationStage = new Stage(); + selectStationStage.initModality(Modality.APPLICATION_MODAL); + selectStationStage.setUserData("test"); selectStationStage.setTitle("Numbers Station Selection"); selectStationStage.setScene(new Scene(root)); selectStationStage.show(); + selectStationStage.setOnHiding(event -> { + String selectedStation = (String) selectStationStage.getUserData(); + if (selectedStation != null) { + StationSettings stationSettings = settings.getStations().stream() + .filter(station -> station.getName().equals(selectedStation)) + .findFirst() + .orElse(null); + if (stationSettings != null) { + System.out.println("Selected Station Settings: " + stationSettings); + } + } + }); } catch (Exception e) { e.printStackTrace(); } @@ -64,8 +86,20 @@ public class NumbersStationController implements Initializable { } } + private void loadSettings() throws IOException { + File file = new File("setting-test.xml"); + XmlMapper xmlMapper = new XmlMapper(); + settings = xmlMapper.readValue(file, NumbersStationSettings.class); + } + @Override public void initialize(URL location, ResourceBundle resources) { + try { + loadSettings(); + } catch (IOException e) { + e.printStackTrace(); + } + messageTextArea.addEventFilter(KeyEvent.ANY, event -> { int cursorPosition = messageTextArea.getCaretPosition(); diff --git a/src/main/java/name/nathanmcrae/NumbersStationSelection.fxml b/src/main/java/name/nathanmcrae/NumbersStationSelection.fxml index 29ca0d1..4ac030f 100644 --- a/src/main/java/name/nathanmcrae/NumbersStationSelection.fxml +++ b/src/main/java/name/nathanmcrae/NumbersStationSelection.fxml @@ -6,18 +6,17 @@ - - + -