Set up binding/saving for message method settings
This commit is contained in:
parent
e21c078e4c
commit
6ab5e5d1ca
@ -6,23 +6,31 @@ import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
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.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.RadioButton;
|
||||||
import javafx.scene.control.Spinner;
|
import javafx.scene.control.Spinner;
|
||||||
import javafx.scene.control.SpinnerValueFactory;
|
import javafx.scene.control.SpinnerValueFactory;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
public class MainSettingsController {
|
public class MainSettingsController {
|
||||||
|
private IntegerProperty digitsPerGroup = new SimpleIntegerProperty();
|
||||||
|
private StringProperty externalProgramCommand = new SimpleStringProperty();
|
||||||
|
private IntegerProperty messageLength = new SimpleIntegerProperty();
|
||||||
|
private ObjectProperty<StationSettings.MessageMethod> messageMethod = new SimpleObjectProperty<>();
|
||||||
|
private StringProperty password = new SimpleStringProperty();
|
||||||
private StationSettings settings;
|
private StationSettings settings;
|
||||||
private StringProperty stationAddress = new SimpleStringProperty();
|
private StringProperty stationAddress = new SimpleStringProperty();
|
||||||
private StringProperty stationName = new SimpleStringProperty();
|
private StringProperty stationName = new SimpleStringProperty();
|
||||||
private IntegerProperty digitsPerGroup = new SimpleIntegerProperty();
|
private StringProperty username = new SimpleStringProperty();
|
||||||
private IntegerProperty messageLength = new SimpleIntegerProperty();
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField stationNameField;
|
private TextField stationNameField;
|
||||||
@ -33,9 +41,33 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Spinner<Integer> digitsPerGroupSpinner;
|
private Spinner<Integer> digitsPerGroupSpinner;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField externalProgramCommandField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Spinner<Integer> messageLengthSpinner;
|
private Spinner<Integer> 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 {
|
public MainSettingsController() 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");
|
||||||
@ -47,14 +79,49 @@ public class MainSettingsController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
|
externalProgramCommandField.textProperty().bindBidirectional(externalProgramCommand);
|
||||||
stationNameField.textProperty().bindBidirectional(stationName);
|
stationNameField.textProperty().bindBidirectional(stationName);
|
||||||
stationAddressField.textProperty().bindBidirectional(stationAddress);
|
stationAddressField.textProperty().bindBidirectional(stationAddress);
|
||||||
|
passwordField.textProperty().bindBidirectional(password);
|
||||||
|
usernameField.textProperty().bindBidirectional(username);
|
||||||
|
|
||||||
digitsPerGroupSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1));
|
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());
|
digitsPerGroupSpinner.getValueFactory().valueProperty().bindBidirectional(digitsPerGroup.asObject());
|
||||||
messageLengthSpinner.getValueFactory().valueProperty().bindBidirectional(messageLength.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
|
@FXML
|
||||||
@ -66,7 +133,6 @@ public class MainSettingsController {
|
|||||||
private void handleCancelButtonPress(Event e) {
|
private void handleCancelButtonPress(Event e) {
|
||||||
Node node = (Node) e.getSource();
|
Node node = (Node) e.getSource();
|
||||||
Stage stage = (Stage) node.getScene().getWindow();
|
Stage stage = (Stage) node.getScene().getWindow();
|
||||||
stage.setUserData(false);
|
|
||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +144,13 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void handleSaveButtonPress(Event e) {
|
private void handleSaveButtonPress(Event e) {
|
||||||
settings.setAddress(stationAddress.get());
|
settings.setAddress(stationAddress.get());
|
||||||
|
|
||||||
settings.setDigitsPerGroup(digitsPerGroup.get());
|
settings.setDigitsPerGroup(digitsPerGroup.get());
|
||||||
|
settings.setExternalProgramCommand(externalProgramCommand.get());
|
||||||
settings.setMessageLength(messageLength.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();
|
Node node = (Node) e.getSource();
|
||||||
Stage stage = (Stage) node.getScene().getWindow();
|
Stage stage = (Stage) node.getScene().getWindow();
|
||||||
@ -88,14 +158,25 @@ public class MainSettingsController {
|
|||||||
stage.close();
|
stage.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void handleTestConnectionButtonPress() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public StringProperty stationAddressProperty() {
|
public StringProperty stationAddressProperty() {
|
||||||
return stationAddress;
|
return stationAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStationSettings(StationSettings newSettings) {
|
public void setStationSettings(StationSettings newSettings) {
|
||||||
settings = newSettings;
|
settings = newSettings;
|
||||||
|
|
||||||
|
stationAddress.set(settings.getAddress());
|
||||||
stationName.set(settings.getName());
|
stationName.set(settings.getName());
|
||||||
digitsPerGroup.set(settings.getDigitsPerGroup());
|
digitsPerGroup.set(settings.getDigitsPerGroup());
|
||||||
|
externalProgramCommand.set(settings.getExternalProgramCommand());
|
||||||
messageLength.set(settings.getMessageLength());
|
messageLength.set(settings.getMessageLength());
|
||||||
|
messageMethod.set(settings.getMessageMethod());
|
||||||
|
username.set(settings.getUsername());
|
||||||
|
password.set(settings.getPassword());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,19 +72,33 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<Label layoutX="170.0" layoutY="9.0" text="Numbers station address:" />
|
<Label layoutX="170.0" layoutY="9.0" text="Numbers station address:" />
|
||||||
<TextField fx:id="stationAddressField" layoutX="188.0" layoutY="33.0" prefHeight="25.0" prefWidth="390.0" AnchorPane.leftAnchor="188.0" AnchorPane.rightAnchor="0.0" />
|
<TextField fx:id="stationAddressField" layoutX="188.0" layoutY="33.0" prefHeight="25.0" prefWidth="390.0" AnchorPane.leftAnchor="188.0" AnchorPane.rightAnchor="0.0" />
|
||||||
<RadioButton layoutX="16.0" layoutY="44.0" mnemonicParsing="false" text="FTP" AnchorPane.leftAnchor="16.0" AnchorPane.topAnchor="44.0">
|
<RadioButton fx:id="ftpRadioButton" layoutX="16.0" layoutY="44.0" mnemonicParsing="false" text="FTP">
|
||||||
<toggleGroup>
|
<toggleGroup>
|
||||||
<ToggleGroup fx:id="messageMethod" />
|
<ToggleGroup fx:id="messageMethodGroup" />
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton fx:id="sftpRadioButton" layoutX="16.0" layoutY="74.0" mnemonicParsing="false" text="SFTP">
|
||||||
|
<toggleGroup>
|
||||||
|
<fx:reference source="messageMethodGroup" />
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton fx:id="scpRadioButton" layoutX="16.0" layoutY="104.0" mnemonicParsing="false" text="SCP">
|
||||||
|
<toggleGroup>
|
||||||
|
<fx:reference source="messageMethodGroup" />
|
||||||
|
</toggleGroup>
|
||||||
|
</RadioButton>
|
||||||
|
<RadioButton fx:id="externalProgramRadioButton" layoutX="16.0" layoutY="134.0" mnemonicParsing="false" text="External program:">
|
||||||
|
<toggleGroup>
|
||||||
|
<fx:reference source="messageMethodGroup" />
|
||||||
</toggleGroup>
|
</toggleGroup>
|
||||||
</RadioButton>
|
</RadioButton>
|
||||||
<RadioButton layoutX="16.0" layoutY="74.0" mnemonicParsing="false" text="SFTP" toggleGroup="$messageMethod" AnchorPane.leftAnchor="16.0" AnchorPane.topAnchor="74.0" />
|
|
||||||
<RadioButton layoutX="16.0" layoutY="104.0" mnemonicParsing="false" text="SCP" toggleGroup="$messageMethod" AnchorPane.leftAnchor="16.0" AnchorPane.topAnchor="104.0" />
|
|
||||||
<RadioButton layoutX="16.0" layoutY="134.0" mnemonicParsing="false" text="External program:" toggleGroup="$messageMethod" AnchorPane.leftAnchor="16.0" AnchorPane.topAnchor="134.0" />
|
|
||||||
<Label layoutX="380.0" layoutY="69.0" text="Username:" AnchorPane.rightAnchor="142.0" />
|
<Label layoutX="380.0" layoutY="69.0" text="Username:" AnchorPane.rightAnchor="142.0" />
|
||||||
<Label layoutX="380.0" layoutY="99.0" text="Password:" AnchorPane.rightAnchor="142.0" />
|
<Label layoutX="380.0" layoutY="99.0" text="Password:" AnchorPane.rightAnchor="142.0" />
|
||||||
<TextField fx:id="usernameField" layoutX="444.0" layoutY="65.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
|
<TextField fx:id="usernameField" layoutX="444.0" layoutY="65.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
|
||||||
<PasswordField fx:id="passwordField" layoutX="444.0" layoutY="95.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
|
<PasswordField fx:id="passwordField" layoutX="444.0" layoutY="95.0" prefHeight="25.0" prefWidth="135.0" AnchorPane.rightAnchor="0.0" />
|
||||||
<TextField fx:id="externalProgramField" layoutX="140.0" layoutY="131.0" prefHeight="25.0" prefWidth="438.0" AnchorPane.leftAnchor="140.0" AnchorPane.rightAnchor="0.0" />
|
<TextField fx:id="externalProgramCommandField" layoutX="140.0" layoutY="131.0" prefHeight="25.0" prefWidth="438.0" AnchorPane.leftAnchor="140.0" AnchorPane.rightAnchor="0.0" />
|
||||||
|
<Button layoutX="188.0" layoutY="65.0" mnemonicParsing="false" onMousePressed="#handleTestConnectionButtonPress" text="Test connection" />
|
||||||
|
|
||||||
</children>
|
</children>
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" />
|
<Insets bottom="10.0" />
|
||||||
|
@ -1,10 +1,21 @@
|
|||||||
package name.nathanmcrae.numbersstation;
|
package name.nathanmcrae.numbersstation;
|
||||||
|
|
||||||
public class StationSettings {
|
public class StationSettings {
|
||||||
private String name;
|
|
||||||
private int digitsPerGroup;
|
|
||||||
private int messageLength;
|
|
||||||
private String address;
|
private String address;
|
||||||
|
private int digitsPerGroup;
|
||||||
|
private String externalProgramCommand;
|
||||||
|
private int messageLength;
|
||||||
|
private MessageMethod messageMethod;
|
||||||
|
private String name;
|
||||||
|
private String password;
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
public enum MessageMethod {
|
||||||
|
FTP,
|
||||||
|
SFTP,
|
||||||
|
SCP,
|
||||||
|
EXTERNAL_PROGRAM
|
||||||
|
}
|
||||||
|
|
||||||
public StationSettings() { }
|
public StationSettings() { }
|
||||||
|
|
||||||
@ -12,30 +23,6 @@ public class StationSettings {
|
|||||||
name = newName;
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
@ -44,6 +31,62 @@ public class StationSettings {
|
|||||||
address = newAddress;
|
address = newAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDigitsPerGroup() {
|
||||||
|
return digitsPerGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDigitsPerGroup(int newDigitsPerGroup) {
|
||||||
|
digitsPerGroup = newDigitsPerGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExternalProgramCommand() {
|
||||||
|
return externalProgramCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalProgramCommand(String newExternalProgramCommand) {
|
||||||
|
externalProgramCommand = newExternalProgramCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMessageLength() {
|
||||||
|
return messageLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageLength(int newMessageLength) {
|
||||||
|
messageLength = newMessageLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageMethod getMessageMethod() {
|
||||||
|
return messageMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessageMethod(MessageMethod newMessageMethod) {
|
||||||
|
messageMethod = newMessageMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String newName) {
|
||||||
|
name = newName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String newPassword) {
|
||||||
|
password = newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String newUsername) {
|
||||||
|
username = newUsername;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name;
|
return name;
|
||||||
|
Loading…
Reference in New Issue
Block a user