Compare commits
4 Commits
b1d1acad2f
...
008d1e2d6b
Author | SHA1 | Date | |
---|---|---|---|
008d1e2d6b | |||
102c16e318 | |||
f645cdccc7 | |||
55dc4c0181 |
@ -7,12 +7,14 @@ import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Random;
|
||||
import java.util.ResourceBundle;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.beans.property.StringProperty;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
@ -51,6 +53,14 @@ public class MainController implements Initializable {
|
||||
Parent root = fxmlLoader.load();
|
||||
|
||||
MainSettingsController controller = fxmlLoader.getController();
|
||||
if (selectedStation == null) {
|
||||
Alert alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("Invalid Station Selected");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Invalid station selected. Please choose a station.");
|
||||
alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
controller.setStationSettings(selectedStation);
|
||||
|
||||
settingsStage = new Stage();
|
||||
@ -59,7 +69,7 @@ public class MainController implements Initializable {
|
||||
settingsStage.setScene(new Scene(root));
|
||||
settingsStage.show();
|
||||
settingsStage.setOnHiding(event -> {
|
||||
settings.save();
|
||||
updateStationSettings(selectedStation);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -76,7 +86,6 @@ public class MainController implements Initializable {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StationSelectionView.fxml"));
|
||||
Parent root = fxmlLoader.load();
|
||||
|
||||
// Pass settings to the controller
|
||||
StationSelectionController controller = fxmlLoader.getController();
|
||||
controller.setSettings(settings);
|
||||
|
||||
@ -92,13 +101,7 @@ public class MainController implements Initializable {
|
||||
.filter(station -> station.getName().equals(newStationName))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (newSelectedStation != null) {
|
||||
selectedStation = newSelectedStation;
|
||||
selectedStationName.set(newStationName);
|
||||
settings.setSelectedStationName(selectedStationName.get());
|
||||
|
||||
settings.save();
|
||||
}
|
||||
updateStationSettings(newSelectedStation);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -111,6 +114,7 @@ public class MainController implements Initializable {
|
||||
private void loadSettings() throws IOException {
|
||||
XmlMapper xmlMapper = new XmlMapper();
|
||||
String userHome = System.getProperty("user.home");
|
||||
// TODO: XDG
|
||||
Path directoryPath = Paths.get(userHome, ".numbers-station");
|
||||
Path filePath = directoryPath.resolve("settings.xml");
|
||||
try {
|
||||
@ -203,4 +207,31 @@ public class MainController implements Initializable {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateStationSettings(StationSettings newStationSettings) {
|
||||
if (newStationSettings == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedStation = newStationSettings;
|
||||
selectedStationName.set(newStationSettings.getName());
|
||||
settings.setSelectedStationName(selectedStationName.get());
|
||||
|
||||
settings.save();
|
||||
|
||||
// TODO: Load message from file
|
||||
// If the message we're overwriting is different from its file, then prompt to confirm
|
||||
|
||||
Random random = new Random();
|
||||
StringBuilder messageBuilder = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < selectedStation.getMessageLength(); i++) {
|
||||
if (i > 0 && i % selectedStation.getDigitsPerGroup() == 0) {
|
||||
messageBuilder.append(" ");
|
||||
}
|
||||
messageBuilder.append(random.nextInt(10));
|
||||
}
|
||||
|
||||
messageTextArea.setText(messageBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public class MainSettingsController {
|
||||
private StringProperty externalProgramCommand = new SimpleStringProperty();
|
||||
private IntegerProperty messageLength = new SimpleIntegerProperty();
|
||||
private ObjectProperty<StationSettings.MessageMethod> messageMethod = new SimpleObjectProperty<>();
|
||||
private ObjectProperty<StationSettings.MessagePeriod> messagePeriod = new SimpleObjectProperty<>();
|
||||
private StringProperty password = new SimpleStringProperty();
|
||||
private StationSettings settings;
|
||||
private StringProperty stationAddress = new SimpleStringProperty();
|
||||
@ -43,6 +44,9 @@ public class MainSettingsController {
|
||||
@FXML
|
||||
private TextField stationAddressField;
|
||||
|
||||
@FXML
|
||||
private RadioButton dailyRadioButton;
|
||||
|
||||
@FXML
|
||||
private Spinner<Integer> digitsPerGroupSpinner;
|
||||
|
||||
@ -55,6 +59,12 @@ public class MainSettingsController {
|
||||
@FXML
|
||||
private ToggleGroup messageMethodGroup;
|
||||
|
||||
@FXML
|
||||
private ToggleGroup messagePeriodGroup;
|
||||
|
||||
@FXML
|
||||
private RadioButton monthlyRadioButton;
|
||||
|
||||
@FXML
|
||||
private RadioButton ftpRadioButton;
|
||||
|
||||
@ -76,6 +86,9 @@ public class MainSettingsController {
|
||||
@FXML
|
||||
private ListView<String> prefixListView;
|
||||
|
||||
@FXML
|
||||
private RadioButton weeklyRadioButton;
|
||||
|
||||
public MainSettingsController() { }
|
||||
|
||||
@FXML
|
||||
@ -116,6 +129,26 @@ public class MainSettingsController {
|
||||
}
|
||||
});
|
||||
|
||||
messagePeriodGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == dailyRadioButton) {
|
||||
messagePeriod.set(StationSettings.MessagePeriod.DAILY);
|
||||
} else if (newValue == monthlyRadioButton) {
|
||||
messagePeriod.set(StationSettings.MessagePeriod.MONTHLY);
|
||||
} else if (newValue == weeklyRadioButton) {
|
||||
messagePeriod.set(StationSettings.MessagePeriod.WEEKLY);
|
||||
}
|
||||
});
|
||||
|
||||
messagePeriod.addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue == StationSettings.MessagePeriod.DAILY) {
|
||||
messagePeriodGroup.selectToggle(dailyRadioButton);
|
||||
} else if (newValue == StationSettings.MessagePeriod.MONTHLY) {
|
||||
messagePeriodGroup.selectToggle(monthlyRadioButton);
|
||||
} else if (newValue == StationSettings.MessagePeriod.WEEKLY) {
|
||||
messagePeriodGroup.selectToggle(weeklyRadioButton);
|
||||
}
|
||||
});
|
||||
|
||||
// Set user data. Default result is no update.
|
||||
stationNameField.sceneProperty().addListener((observable, oldScene, newScene) -> {
|
||||
if (newScene != null) {
|
||||
@ -160,6 +193,7 @@ public class MainSettingsController {
|
||||
settings.setExternalProgramCommand(externalProgramCommand.get());
|
||||
settings.setMessageLength(messageLength.get());
|
||||
settings.setMessageMethod(messageMethod.get());
|
||||
settings.setMessagePeriod(messagePeriod.get());
|
||||
settings.setName(stationName.get());
|
||||
settings.setPassword(password.get());
|
||||
settings.getPrefixes().clear();
|
||||
@ -190,6 +224,7 @@ public class MainSettingsController {
|
||||
externalProgramCommand.set(settings.getExternalProgramCommand());
|
||||
messageLength.set(settings.getMessageLength());
|
||||
messageMethod.set(settings.getMessageMethod());
|
||||
messagePeriod.set(settings.getMessagePeriod());
|
||||
username.set(settings.getUsername());
|
||||
password.set(settings.getPassword());
|
||||
prefixListView.getItems().addAll(settings.getPrefixes());
|
||||
|
@ -27,7 +27,7 @@
|
||||
<FlowPane alignment="CENTER_LEFT" prefHeight="41.0" prefWidth="640.0">
|
||||
<children>
|
||||
<Label prefHeight="17.0" prefWidth="49.0" text="Station: " />
|
||||
<TextField fx:id="stationNameField" editable="false" style="-fx-background-color: #EEEEEE; -fx-border-color: #AAAAAA;" text="My Station">
|
||||
<TextField fx:id="stationNameField" style="-fx-border-color: #AAAAAA;" text="My Station">
|
||||
<FlowPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
@ -133,18 +133,27 @@
|
||||
<AnchorPane prefHeight="152.0" prefWidth="578.0">
|
||||
<children>
|
||||
<CheckBox layoutX="395.0" mnemonicParsing="false" text="Manage schedule externally" AnchorPane.rightAnchor="14.5" />
|
||||
<RadioButton 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 fx:id="scheduleFrequency" />
|
||||
<ToggleGroup fx:id="messagePeriodGroup" />
|
||||
</toggleGroup>
|
||||
</RadioButton>
|
||||
<RadioButton layoutX="14.0" layoutY="38.0" mnemonicParsing="false" text="Weekly" toggleGroup="$scheduleFrequency" />
|
||||
<RadioButton layoutX="14.0" layoutY="68.0" mnemonicParsing="false" text="Monthly" toggleGroup="$scheduleFrequency" />
|
||||
<RadioButton fx:id="weeklyRadioButton" layoutX="14.0" layoutY="38.0" mnemonicParsing="false" text="Weekly">
|
||||
<toggleGroup>
|
||||
<fx:reference source="messagePeriodGroup" />
|
||||
</toggleGroup>
|
||||
</RadioButton>
|
||||
<RadioButton fx:id="monthlyRadioButton" layoutX="14.0" layoutY="68.0" mnemonicParsing="false" text="Monthly">
|
||||
<toggleGroup>
|
||||
<fx:reference source="messagePeriodGroup" />
|
||||
</toggleGroup>
|
||||
</RadioButton>
|
||||
<DatePicker layoutX="115.0" layoutY="34.0" />
|
||||
<Label layoutX="115.0" layoutY="8.0" text="Starting from:" />
|
||||
<TextField layoutX="115.0" layoutY="64.0" text="23:24:49" />
|
||||
<Label layoutX="48.0" layoutY="102.0" text="TODO: Jitter" />
|
||||
</children>
|
||||
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
<padding>
|
||||
|
@ -47,20 +47,17 @@
|
||||
<children>
|
||||
<VBox maxHeight="1.7976931348623157E308" minWidth="400.0" prefHeight="400.0" prefWidth="640.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<children>
|
||||
<FlowPane alignment="CENTER_LEFT" prefHeight="41.0" prefWidth="640.0">
|
||||
<children>
|
||||
<Label prefHeight="17.0" prefWidth="49.0" text="Station: " />
|
||||
<TextField fx:id="stationNameField" editable="false" style="-fx-background-color: #EEEEEE; -fx-border-color: #AAAAAA;" text="My Station">
|
||||
<FlowPane.margin>
|
||||
<Insets right="10.0" />
|
||||
</FlowPane.margin>
|
||||
</TextField>
|
||||
<Button mnemonicParsing="false" onAction="#handleSelectStationButtonPress" text="Select Station" />
|
||||
</children>
|
||||
<AnchorPane>
|
||||
<VBox.margin>
|
||||
<Insets bottom="10.0" />
|
||||
</VBox.margin>
|
||||
</FlowPane>
|
||||
<children>
|
||||
<Button layoutX="209.0" layoutY="1.0" mnemonicParsing="false" onAction="#handleSelectStationButtonPress" text="Select Station" />
|
||||
<Label layoutY="5.0" prefHeight="17.0" prefWidth="49.0" text="Station: " />
|
||||
<TextField fx:id="stationNameField" editable="false" layoutX="49.0" style="-fx-background-color: #EEEEEE; -fx-border-color: #AAAAAA;" text="My Station" />
|
||||
<Button layoutX="602.0" layoutY="1.0" mnemonicParsing="false" text="Help" AnchorPane.rightAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Separator prefWidth="200.0" />
|
||||
<AnchorPane prefHeight="50.0" prefWidth="570.0">
|
||||
<children>
|
||||
|
@ -8,6 +8,7 @@ public class StationSettings {
|
||||
private String externalProgramCommand;
|
||||
private int messageLength;
|
||||
private MessageMethod messageMethod;
|
||||
private MessagePeriod messagePeriod;
|
||||
private String name;
|
||||
private String password;
|
||||
private ArrayList<String> prefixes;
|
||||
@ -20,6 +21,12 @@ public class StationSettings {
|
||||
EXTERNAL_PROGRAM
|
||||
}
|
||||
|
||||
public enum MessagePeriod {
|
||||
DAILY,
|
||||
WEEKLY,
|
||||
MONTHLY
|
||||
}
|
||||
|
||||
public StationSettings() {
|
||||
prefixes = new ArrayList<String>();
|
||||
}
|
||||
@ -68,6 +75,14 @@ public class StationSettings {
|
||||
messageMethod = newMessageMethod;
|
||||
}
|
||||
|
||||
public MessagePeriod getMessagePeriod() {
|
||||
return messagePeriod;
|
||||
}
|
||||
|
||||
public void setMessagePeriod(MessagePeriod newMessagePeriod) {
|
||||
messagePeriod = newMessagePeriod;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user