Add basic settings (de)serialization
This commit is contained in:
parent
fea5a35240
commit
aa42155644
@ -12,8 +12,7 @@
|
|||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?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" fx:controller="name.nathanmcrae.NumbersStationSettingsController">
|
||||||
<AnchorPane prefHeight="700.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/23.0.1" xmlns:fx="http://javafx.com/fxml/1">
|
|
||||||
<children>
|
<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">
|
<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>
|
<content>
|
||||||
@ -89,7 +88,7 @@
|
|||||||
</ScrollPane>
|
</ScrollPane>
|
||||||
<FlowPane alignment="CENTER_RIGHT" prefHeight="40.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
<FlowPane alignment="CENTER_RIGHT" prefHeight="40.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" text="Save" textAlignment="RIGHT">
|
<Button mnemonicParsing="false" onMousePressed="#handleSaveButtonPress" text="Save" textAlignment="RIGHT">
|
||||||
<FlowPane.margin>
|
<FlowPane.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</FlowPane.margin>
|
</FlowPane.margin>
|
||||||
|
31
src/main/java/name/nathanmcrae/NumbersStationSettings.java
Normal file
31
src/main/java/name/nathanmcrae/NumbersStationSettings.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
31
src/main/java/name/nathanmcrae/StationSettings.java
Normal file
31
src/main/java/name/nathanmcrae/StationSettings.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user