Add basic settings (de)serialization

This commit is contained in:
Nathan McRae 2025-01-01 20:24:02 -08:00
parent fea5a35240
commit aa42155644
4 changed files with 92 additions and 3 deletions

View File

@ -12,8 +12,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="700.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane prefHeight="700.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="name.nathanmcrae.NumbersStationSettingsController">
<children>
<ScrollPane fitToWidth="true" hbarPolicy="NEVER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="297.0" prefWidth="600.0" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
@ -89,7 +88,7 @@
</ScrollPane>
<FlowPane alignment="CENTER_RIGHT" prefHeight="40.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<Button mnemonicParsing="false" text="Save" textAlignment="RIGHT">
<Button mnemonicParsing="false" onMousePressed="#handleSaveButtonPress" text="Save" textAlignment="RIGHT">
<FlowPane.margin>
<Insets right="10.0" />
</FlowPane.margin>

View File

@ -0,0 +1,31 @@
package name.nathanmcrae;
import java.util.ArrayList;
public class NumbersStationSettings {
private int digitsPerGroup;
private String username;
private int refreshInterval;
private ArrayList<StationSettings> stations;
public ArrayList<StationSettings> getStations() {
return stations;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getRefreshInterval() {
return refreshInterval;
}
public void setRefreshInterval(int refreshInterval) {
this.refreshInterval = refreshInterval;
}
}

View File

@ -0,0 +1,28 @@
package name.nathanmcrae;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.io.IOException;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
public class NumbersStationSettingsController {
private NumbersStationSettings settings;
public NumbersStationSettingsController() throws IOException {
System.out.println("Created settings controller");
File file = new File("setting-test.xml");
XmlMapper xmlMapper = new XmlMapper();
settings = xmlMapper.readValue(file, NumbersStationSettings.class);
settings.setRefreshInterval(settings.getRefreshInterval() + 40);
settings.getStations().add(new StationSettings());
}
@FXML
private void handleSaveButtonPress() throws IOException {
XmlMapper xmlMapper = new XmlMapper();
xmlMapper.writeValue(new File("setting-test.xml"), settings);
}
}

View File

@ -0,0 +1,31 @@
package name.nathanmcrae;
public class StationSettings {
private String name;
private int digitsPerGroup;
private int messageLength;
public String getName() {
return name;
}
public void setName(String newName) {
name = newName;
}
public int getDigitsPerGroup() {
return digitsPerGroup;
}
public void setDigitsPerGroup(int newDigitsPerGroup) {
digitsPerGroup = newDigitsPerGroup;
}
public int getMessageLength() {
return messageLength;
}
public void setMessageLength(int newMessageLength) {
messageLength = newMessageLength;
}
}