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