Compare commits
2 Commits
5e362673d4
...
9cb0eae10f
Author | SHA1 | Date | |
---|---|---|---|
9cb0eae10f | |||
b4ade494d0 |
@ -5,10 +5,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.Optional;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.IntegerProperty;
|
import javafx.beans.property.IntegerProperty;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleIntegerProperty;
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
@ -17,6 +21,7 @@ import javafx.collections.FXCollections;
|
|||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
import javafx.scene.control.DatePicker;
|
import javafx.scene.control.DatePicker;
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.control.RadioButton;
|
import javafx.scene.control.RadioButton;
|
||||||
@ -25,12 +30,15 @@ import javafx.scene.control.SpinnerValueFactory;
|
|||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.control.TextInputDialog;
|
import javafx.scene.control.TextInputDialog;
|
||||||
import javafx.scene.control.ToggleGroup;
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
import javafx.scene.input.KeyEvent;
|
||||||
|
import javafx.scene.input.KeyCode;
|
||||||
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 IntegerProperty digitsPerGroup = new SimpleIntegerProperty();
|
||||||
private StringProperty externalProgramCommand = new SimpleStringProperty();
|
private StringProperty externalProgramCommand = new SimpleStringProperty();
|
||||||
|
private BooleanProperty manageScheduleExternally = new SimpleBooleanProperty();
|
||||||
private IntegerProperty messageLength = new SimpleIntegerProperty();
|
private IntegerProperty messageLength = new SimpleIntegerProperty();
|
||||||
private ObjectProperty<StationSettings.MessageMethod> messageMethod = new SimpleObjectProperty<>();
|
private ObjectProperty<StationSettings.MessageMethod> messageMethod = new SimpleObjectProperty<>();
|
||||||
private ObjectProperty<StationSettings.MessagePeriod> messagePeriod = new SimpleObjectProperty<>();
|
private ObjectProperty<StationSettings.MessagePeriod> messagePeriod = new SimpleObjectProperty<>();
|
||||||
@ -39,6 +47,7 @@ public class MainSettingsController {
|
|||||||
private StringProperty stationAddress = new SimpleStringProperty();
|
private StringProperty stationAddress = new SimpleStringProperty();
|
||||||
private StringProperty stationName = new SimpleStringProperty();
|
private StringProperty stationName = new SimpleStringProperty();
|
||||||
private ObjectProperty<LocalDate> scheduleStartDate = new SimpleObjectProperty<>();
|
private ObjectProperty<LocalDate> scheduleStartDate = new SimpleObjectProperty<>();
|
||||||
|
private StringProperty scheduleStartTime = new SimpleStringProperty();
|
||||||
private StringProperty username = new SimpleStringProperty();
|
private StringProperty username = new SimpleStringProperty();
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -56,6 +65,9 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField externalProgramCommandField;
|
private TextField externalProgramCommandField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox manageScheduleExternallyCheckBox;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Spinner<Integer> messageLengthSpinner;
|
private Spinner<Integer> messageLengthSpinner;
|
||||||
|
|
||||||
@ -77,6 +89,9 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private RadioButton scpRadioButton;
|
private RadioButton scpRadioButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField scheduleStartTimeField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private RadioButton externalProgramRadioButton;
|
private RadioButton externalProgramRadioButton;
|
||||||
|
|
||||||
@ -100,10 +115,12 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
externalProgramCommandField.textProperty().bindBidirectional(externalProgramCommand);
|
externalProgramCommandField.textProperty().bindBidirectional(externalProgramCommand);
|
||||||
|
manageScheduleExternallyCheckBox.selectedProperty().bindBidirectional(manageScheduleExternally);
|
||||||
stationNameField.textProperty().bindBidirectional(stationName);
|
stationNameField.textProperty().bindBidirectional(stationName);
|
||||||
stationAddressField.textProperty().bindBidirectional(stationAddress);
|
stationAddressField.textProperty().bindBidirectional(stationAddress);
|
||||||
passwordField.textProperty().bindBidirectional(password);
|
passwordField.textProperty().bindBidirectional(password);
|
||||||
scheduleStartDatePicker.valueProperty().bindBidirectional(scheduleStartDate);
|
scheduleStartDatePicker.valueProperty().bindBidirectional(scheduleStartDate);
|
||||||
|
scheduleStartTimeField.textProperty().bindBidirectional(scheduleStartTime);
|
||||||
usernameField.textProperty().bindBidirectional(username);
|
usernameField.textProperty().bindBidirectional(username);
|
||||||
|
|
||||||
digitsPerGroupSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1));
|
digitsPerGroupSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 100, 1));
|
||||||
@ -112,6 +129,63 @@ public class MainSettingsController {
|
|||||||
digitsPerGroupSpinner.getValueFactory().valueProperty().bindBidirectional(digitsPerGroup.asObject());
|
digitsPerGroupSpinner.getValueFactory().valueProperty().bindBidirectional(digitsPerGroup.asObject());
|
||||||
messageLengthSpinner.getValueFactory().valueProperty().bindBidirectional(messageLength.asObject());
|
messageLengthSpinner.getValueFactory().valueProperty().bindBidirectional(messageLength.asObject());
|
||||||
|
|
||||||
|
scheduleStartTimeField.addEventFilter(KeyEvent.ANY, event -> {
|
||||||
|
int cursorPosition = scheduleStartTimeField.getCaretPosition();
|
||||||
|
|
||||||
|
String character = event.getCharacter();
|
||||||
|
KeyCode code = event.getCode();
|
||||||
|
|
||||||
|
String str = event.getText();
|
||||||
|
|
||||||
|
// Consume the event to block the default behavior
|
||||||
|
if (!(code == KeyCode.LEFT ||
|
||||||
|
code == KeyCode.RIGHT ||
|
||||||
|
code == KeyCode.UP ||
|
||||||
|
code == KeyCode.DOWN ||
|
||||||
|
code == KeyCode.HOME ||
|
||||||
|
code == KeyCode.END ||
|
||||||
|
code == KeyCode.PAGE_UP ||
|
||||||
|
code == KeyCode.PAGE_DOWN)) {
|
||||||
|
event.consume();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.getEventType() == KeyEvent.KEY_PRESSED &&
|
||||||
|
(code == KeyCode.DIGIT0 ||
|
||||||
|
code == KeyCode.DIGIT1 ||
|
||||||
|
code == KeyCode.DIGIT2 ||
|
||||||
|
code == KeyCode.DIGIT3 ||
|
||||||
|
code == KeyCode.DIGIT4 ||
|
||||||
|
code == KeyCode.DIGIT5 ||
|
||||||
|
code == KeyCode.DIGIT6 ||
|
||||||
|
code == KeyCode.DIGIT7 ||
|
||||||
|
code == KeyCode.DIGIT8 ||
|
||||||
|
code == KeyCode.DIGIT9)) {
|
||||||
|
|
||||||
|
String editedTime = scheduleStartTimeField.getText();
|
||||||
|
|
||||||
|
if (cursorPosition < scheduleStartTimeField.getLength()) {
|
||||||
|
char currentChar = scheduleStartTimeField.getText().charAt(cursorPosition);
|
||||||
|
if (currentChar == ':') {
|
||||||
|
cursorPosition++;
|
||||||
|
}
|
||||||
|
editedTime = editedTime.substring(0, cursorPosition) + str + editedTime.substring(cursorPosition + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the time format
|
||||||
|
String[] timeParts = editedTime.split(":");
|
||||||
|
if (timeParts.length == 3) {
|
||||||
|
int hours = Integer.parseInt(timeParts[0]);
|
||||||
|
int minutes = Integer.parseInt(timeParts[1]);
|
||||||
|
int seconds = Integer.parseInt(timeParts[2]);
|
||||||
|
|
||||||
|
if (!(hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59)) {
|
||||||
|
scheduleStartTimeField.setText(editedTime);
|
||||||
|
scheduleStartTimeField.positionCaret(cursorPosition + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
messageMethodGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
|
messageMethodGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
if (newValue == ftpRadioButton) {
|
if (newValue == ftpRadioButton) {
|
||||||
messageMethod.set(StationSettings.MessageMethod.FTP);
|
messageMethod.set(StationSettings.MessageMethod.FTP);
|
||||||
@ -198,6 +272,7 @@ public class MainSettingsController {
|
|||||||
settings.setAddress(stationAddress.get());
|
settings.setAddress(stationAddress.get());
|
||||||
settings.setDigitsPerGroup(digitsPerGroup.get());
|
settings.setDigitsPerGroup(digitsPerGroup.get());
|
||||||
settings.setExternalProgramCommand(externalProgramCommand.get());
|
settings.setExternalProgramCommand(externalProgramCommand.get());
|
||||||
|
settings.setManageScheduleExternally(manageScheduleExternally.get());
|
||||||
settings.setMessageLength(messageLength.get());
|
settings.setMessageLength(messageLength.get());
|
||||||
settings.setMessageMethod(messageMethod.get());
|
settings.setMessageMethod(messageMethod.get());
|
||||||
settings.setMessagePeriod(messagePeriod.get());
|
settings.setMessagePeriod(messagePeriod.get());
|
||||||
@ -208,6 +283,14 @@ public class MainSettingsController {
|
|||||||
settings.setScheduleStartDate(scheduleStartDatePicker.getValue());
|
settings.setScheduleStartDate(scheduleStartDatePicker.getValue());
|
||||||
settings.setUsername(username.get());
|
settings.setUsername(username.get());
|
||||||
|
|
||||||
|
try {
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||||
|
LocalTime startTime = LocalTime.parse(scheduleStartTimeField.getText(), formatter);
|
||||||
|
settings.setScheduleStartTime(startTime);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
Node node = (Node) e.getSource();
|
Node node = (Node) e.getSource();
|
||||||
Stage stage = (Stage) node.getScene().getWindow();
|
Stage stage = (Stage) node.getScene().getWindow();
|
||||||
stage.setUserData(true);
|
stage.setUserData(true);
|
||||||
@ -230,6 +313,7 @@ public class MainSettingsController {
|
|||||||
stationName.set(settings.getName());
|
stationName.set(settings.getName());
|
||||||
digitsPerGroup.set(settings.getDigitsPerGroup());
|
digitsPerGroup.set(settings.getDigitsPerGroup());
|
||||||
externalProgramCommand.set(settings.getExternalProgramCommand());
|
externalProgramCommand.set(settings.getExternalProgramCommand());
|
||||||
|
manageScheduleExternally.set(settings.getManageScheduleExternally());
|
||||||
messageLength.set(settings.getMessageLength());
|
messageLength.set(settings.getMessageLength());
|
||||||
messageMethod.set(settings.getMessageMethod());
|
messageMethod.set(settings.getMessageMethod());
|
||||||
messagePeriod.set(settings.getMessagePeriod());
|
messagePeriod.set(settings.getMessagePeriod());
|
||||||
@ -238,5 +322,11 @@ public class MainSettingsController {
|
|||||||
System.out.println(settings.getPrefixes());
|
System.out.println(settings.getPrefixes());
|
||||||
prefixListView.getItems().addAll(settings.getPrefixes());
|
prefixListView.getItems().addAll(settings.getPrefixes());
|
||||||
scheduleStartDate.set(settings.getScheduleStartDate());
|
scheduleStartDate.set(settings.getScheduleStartDate());
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||||
|
LocalTime startTime = settings.getScheduleStartTime();
|
||||||
|
if (startTime == null) {
|
||||||
|
startTime = LocalTime.now();
|
||||||
|
}
|
||||||
|
scheduleStartTime.set(startTime.format(formatter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@
|
|||||||
</Label>
|
</Label>
|
||||||
<AnchorPane prefHeight="152.0" prefWidth="578.0">
|
<AnchorPane prefHeight="152.0" prefWidth="578.0">
|
||||||
<children>
|
<children>
|
||||||
<CheckBox layoutX="395.0" mnemonicParsing="false" text="Manage schedule externally" AnchorPane.rightAnchor="14.5" />
|
<CheckBox fx:id="manageScheduleExternallyCheckBox" layoutX="395.0" mnemonicParsing="false" text="Manage schedule externally" AnchorPane.rightAnchor="14.5" />
|
||||||
<RadioButton fx:id="dailyRadioButton" layoutX="14.0" layoutY="8.0" mnemonicParsing="false" text="Daily">
|
<RadioButton fx:id="dailyRadioButton" layoutX="14.0" layoutY="8.0" mnemonicParsing="false" text="Daily">
|
||||||
<toggleGroup>
|
<toggleGroup>
|
||||||
<ToggleGroup fx:id="messagePeriodGroup" />
|
<ToggleGroup fx:id="messagePeriodGroup" />
|
||||||
@ -150,7 +150,7 @@
|
|||||||
</RadioButton>
|
</RadioButton>
|
||||||
<DatePicker fx:id="scheduleStartDatePicker" layoutX="115.0" layoutY="34.0" />
|
<DatePicker fx:id="scheduleStartDatePicker" layoutX="115.0" layoutY="34.0" />
|
||||||
<Label layoutX="115.0" layoutY="8.0" text="Starting from:" />
|
<Label layoutX="115.0" layoutY="8.0" text="Starting from:" />
|
||||||
<TextField layoutX="115.0" layoutY="64.0" text="23:24:49" />
|
<TextField fx:id="scheduleStartTimeField" layoutX="115.0" layoutY="64.0" text="23:24:49" />
|
||||||
<Label layoutX="48.0" layoutY="102.0" text="TODO: Jitter" />
|
<Label layoutX="48.0" layoutY="102.0" text="TODO: Jitter" />
|
||||||
|
|
||||||
</children>
|
</children>
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package name.nathanmcrae.numbersstation;
|
package name.nathanmcrae.numbersstation;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class StationSettings {
|
public class StationSettings {
|
||||||
private String address;
|
private String address;
|
||||||
private int digitsPerGroup;
|
private int digitsPerGroup;
|
||||||
private String externalProgramCommand;
|
private String externalProgramCommand;
|
||||||
|
private boolean manageScheduleExternally;
|
||||||
private int messageLength;
|
private int messageLength;
|
||||||
private MessageMethod messageMethod;
|
private MessageMethod messageMethod;
|
||||||
private MessagePeriod messagePeriod;
|
private MessagePeriod messagePeriod;
|
||||||
@ -14,6 +16,7 @@ public class StationSettings {
|
|||||||
private String password;
|
private String password;
|
||||||
private ArrayList<String> prefixes;
|
private ArrayList<String> prefixes;
|
||||||
private LocalDate scheduleStartDate;
|
private LocalDate scheduleStartDate;
|
||||||
|
private LocalTime scheduleStartTime;
|
||||||
private String username;
|
private String username;
|
||||||
|
|
||||||
public enum MessageMethod {
|
public enum MessageMethod {
|
||||||
@ -61,6 +64,14 @@ public class StationSettings {
|
|||||||
externalProgramCommand = newExternalProgramCommand;
|
externalProgramCommand = newExternalProgramCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getManageScheduleExternally() {
|
||||||
|
return manageScheduleExternally;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManageScheduleExternally(boolean newManageScheduleExternally) {
|
||||||
|
manageScheduleExternally = newManageScheduleExternally;
|
||||||
|
}
|
||||||
|
|
||||||
public int getMessageLength() {
|
public int getMessageLength() {
|
||||||
return messageLength;
|
return messageLength;
|
||||||
}
|
}
|
||||||
@ -116,6 +127,14 @@ public class StationSettings {
|
|||||||
scheduleStartDate = newScheduleStartDate;
|
scheduleStartDate = newScheduleStartDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalTime getScheduleStartTime() {
|
||||||
|
return scheduleStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScheduleStartTime(LocalTime newScheduleStartTime) {
|
||||||
|
scheduleStartTime = newScheduleStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user