diff --git a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java index a10bbe1..1355d31 100644 --- a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java +++ b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsController.java @@ -6,23 +6,31 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper; import java.io.File; import java.io.IOException; import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.Event; import javafx.fxml.FXML; +import javafx.scene.control.RadioButton; import javafx.scene.control.Spinner; import javafx.scene.control.SpinnerValueFactory; import javafx.scene.control.TextField; +import javafx.scene.control.ToggleGroup; import javafx.scene.Node; import javafx.stage.Stage; public class MainSettingsController { + private IntegerProperty digitsPerGroup = new SimpleIntegerProperty(); + private StringProperty externalProgramCommand = new SimpleStringProperty(); + private IntegerProperty messageLength = new SimpleIntegerProperty(); + private ObjectProperty messageMethod = new SimpleObjectProperty<>(); + private StringProperty password = new SimpleStringProperty(); private StationSettings settings; private StringProperty stationAddress = new SimpleStringProperty(); private StringProperty stationName = new SimpleStringProperty(); - private IntegerProperty digitsPerGroup = new SimpleIntegerProperty(); - private IntegerProperty messageLength = new SimpleIntegerProperty(); + private StringProperty username = new SimpleStringProperty(); @FXML private TextField stationNameField; @@ -33,9 +41,33 @@ public class MainSettingsController { @FXML private Spinner digitsPerGroupSpinner; + @FXML + private TextField externalProgramCommandField; + @FXML private Spinner messageLengthSpinner; + @FXML + private ToggleGroup messageMethodGroup; + + @FXML + private RadioButton ftpRadioButton; + + @FXML + private RadioButton sftpRadioButton; + + @FXML + private RadioButton scpRadioButton; + + @FXML + private RadioButton externalProgramRadioButton; + + @FXML + private TextField usernameField; + + @FXML + private TextField passwordField; + public MainSettingsController() throws IOException { // System.out.println("Created settings controller"); // File file = new File("setting-test.xml"); @@ -47,14 +79,49 @@ public class MainSettingsController { @FXML private void initialize() { + externalProgramCommandField.textProperty().bindBidirectional(externalProgramCommand); stationNameField.textProperty().bindBidirectional(stationName); stationAddressField.textProperty().bindBidirectional(stationAddress); + passwordField.textProperty().bindBidirectional(password); + usernameField.textProperty().bindBidirectional(username); digitsPerGroupSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1)); - messageLengthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1)); + messageLengthSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1000, 1)); digitsPerGroupSpinner.getValueFactory().valueProperty().bindBidirectional(digitsPerGroup.asObject()); messageLengthSpinner.getValueFactory().valueProperty().bindBidirectional(messageLength.asObject()); + + messageMethodGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == ftpRadioButton) { + messageMethod.set(StationSettings.MessageMethod.FTP); + } else if (newValue == sftpRadioButton) { + messageMethod.set(StationSettings.MessageMethod.SFTP); + } else if (newValue == scpRadioButton) { + messageMethod.set(StationSettings.MessageMethod.SCP); + } else if (newValue == externalProgramRadioButton) { + messageMethod.set(StationSettings.MessageMethod.EXTERNAL_PROGRAM); + } + }); + + messageMethod.addListener((observable, oldValue, newValue) -> { + if (newValue == StationSettings.MessageMethod.FTP) { + messageMethodGroup.selectToggle(ftpRadioButton); + } else if (newValue == StationSettings.MessageMethod.SFTP) { + messageMethodGroup.selectToggle(sftpRadioButton); + } else if (newValue == StationSettings.MessageMethod.SCP) { + messageMethodGroup.selectToggle(scpRadioButton); + } else if (newValue == StationSettings.MessageMethod.EXTERNAL_PROGRAM) { + messageMethodGroup.selectToggle(externalProgramRadioButton); + } + }); + + // Set user data. Default result is no update. + stationNameField.sceneProperty().addListener((observable, oldScene, newScene) -> { + if (newScene != null) { + Stage stage = (Stage) newScene.getWindow(); + stage.setUserData(false); + } + }); } @FXML @@ -66,7 +133,6 @@ public class MainSettingsController { private void handleCancelButtonPress(Event e) { Node node = (Node) e.getSource(); Stage stage = (Stage) node.getScene().getWindow(); - stage.setUserData(false); stage.close(); } @@ -78,9 +144,13 @@ public class MainSettingsController { @FXML private void handleSaveButtonPress(Event e) { settings.setAddress(stationAddress.get()); - settings.setDigitsPerGroup(digitsPerGroup.get()); + settings.setExternalProgramCommand(externalProgramCommand.get()); settings.setMessageLength(messageLength.get()); + settings.setMessageMethod(messageMethod.get()); + settings.setName(stationName.get()); + settings.setPassword(password.get()); + settings.setUsername(username.get()); Node node = (Node) e.getSource(); Stage stage = (Stage) node.getScene().getWindow(); @@ -88,14 +158,25 @@ public class MainSettingsController { stage.close(); } + @FXML + private void handleTestConnectionButtonPress() { + // TODO + } + public StringProperty stationAddressProperty() { return stationAddress; } public void setStationSettings(StationSettings newSettings) { settings = newSettings; + + stationAddress.set(settings.getAddress()); stationName.set(settings.getName()); digitsPerGroup.set(settings.getDigitsPerGroup()); + externalProgramCommand.set(settings.getExternalProgramCommand()); messageLength.set(settings.getMessageLength()); + messageMethod.set(settings.getMessageMethod()); + username.set(settings.getUsername()); + password.set(settings.getPassword()); } } diff --git a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml index af39332..6fd4342 100644 --- a/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml +++ b/src/main/java/name/nathanmcrae/numbersstation/MainSettingsView.fxml @@ -72,20 +72,34 @@