Save settings when settings dialog save button pressed
This commit is contained in:
parent
9f59fc813f
commit
b434a52fa2
@ -49,10 +49,18 @@ public class NumbersStationController implements Initializable {
|
||||
try {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("NumbersStationSettings.fxml"));
|
||||
Parent root = fxmlLoader.load();
|
||||
|
||||
NumbersStationSettingsController controller = fxmlLoader.getController();
|
||||
controller.setStationSettings(selectedStation);
|
||||
|
||||
settingsStage = new Stage();
|
||||
settingsStage.initModality(Modality.APPLICATION_MODAL);
|
||||
settingsStage.setTitle("Numbers Station Settings");
|
||||
settingsStage.setScene(new Scene(root));
|
||||
settingsStage.show();
|
||||
settingsStage.setOnHiding(event -> {
|
||||
settings.save();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -93,7 +93,7 @@
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</Button>
|
||||
<Button mnemonicParsing="false" text="Cancel">
|
||||
<Button mnemonicParsing="false" onMousePressed="#handleCancelButtonPress" text="Cancel">
|
||||
<opaqueInsets>
|
||||
<Insets />
|
||||
</opaqueInsets>
|
||||
|
@ -7,12 +7,16 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.Node;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class NumbersStationSettingsController {
|
||||
private NumbersStationSettings settings;
|
||||
private StringProperty stationNameAndAddress = new SimpleStringProperty();
|
||||
private StationSettings settings;
|
||||
private StringProperty stationAddress = new SimpleStringProperty();
|
||||
private StringProperty stationName = new SimpleStringProperty();
|
||||
|
||||
@FXML
|
||||
private TextField stationNameField;
|
||||
@ -21,27 +25,44 @@ public class NumbersStationSettingsController {
|
||||
private TextField stationAddressField;
|
||||
|
||||
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());
|
||||
// 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 initialize() {
|
||||
stationNameField.textProperty().bindBidirectional(stationNameAndAddress);
|
||||
stationAddressField.textProperty().bindBidirectional(stationNameAndAddress);
|
||||
stationNameField.textProperty().bindBidirectional(stationName);
|
||||
stationAddressField.textProperty().bindBidirectional(stationAddress);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleSaveButtonPress() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
xmlMapper.writeValue(new File("setting-test.xml"), settings);
|
||||
private void handleSaveButtonPress(Event e) {
|
||||
settings.setAddress(stationAddress.get());
|
||||
|
||||
Node node = (Node) e.getSource();
|
||||
Stage stage = (Stage) node.getScene().getWindow();
|
||||
stage.setUserData(true);
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public StringProperty stationNameAndAddressProperty() {
|
||||
return stationNameAndAddress;
|
||||
@FXML
|
||||
private void handleCancelButtonPress(Event e) {
|
||||
Node node = (Node) e.getSource();
|
||||
Stage stage = (Stage) node.getScene().getWindow();
|
||||
stage.setUserData(false);
|
||||
stage.close();
|
||||
}
|
||||
|
||||
public StringProperty stationAddressProperty() {
|
||||
return stationAddress;
|
||||
}
|
||||
|
||||
public void setStationSettings(StationSettings newSettings) {
|
||||
settings = newSettings;
|
||||
stationName.set(settings.getName());
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ public class StationSettings {
|
||||
private String name;
|
||||
private int digitsPerGroup;
|
||||
private int messageLength;
|
||||
private String address;
|
||||
|
||||
public StationSettings() { }
|
||||
|
||||
@ -35,6 +36,14 @@ public class StationSettings {
|
||||
messageLength = newMessageLength;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String newAddress) {
|
||||
address = newAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user