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.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
@ -51,6 +53,14 @@ public class MainController implements Initializable {
|
|||||||
Parent root = fxmlLoader.load();
|
Parent root = fxmlLoader.load();
|
||||||
|
|
||||||
MainSettingsController controller = fxmlLoader.getController();
|
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);
|
controller.setStationSettings(selectedStation);
|
||||||
|
|
||||||
settingsStage = new Stage();
|
settingsStage = new Stage();
|
||||||
@ -59,7 +69,7 @@ public class MainController implements Initializable {
|
|||||||
settingsStage.setScene(new Scene(root));
|
settingsStage.setScene(new Scene(root));
|
||||||
settingsStage.show();
|
settingsStage.show();
|
||||||
settingsStage.setOnHiding(event -> {
|
settingsStage.setOnHiding(event -> {
|
||||||
settings.save();
|
updateStationSettings(selectedStation);
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -76,7 +86,6 @@ public class MainController implements Initializable {
|
|||||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StationSelectionView.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StationSelectionView.fxml"));
|
||||||
Parent root = fxmlLoader.load();
|
Parent root = fxmlLoader.load();
|
||||||
|
|
||||||
// Pass settings to the controller
|
|
||||||
StationSelectionController controller = fxmlLoader.getController();
|
StationSelectionController controller = fxmlLoader.getController();
|
||||||
controller.setSettings(settings);
|
controller.setSettings(settings);
|
||||||
|
|
||||||
@ -92,13 +101,7 @@ public class MainController implements Initializable {
|
|||||||
.filter(station -> station.getName().equals(newStationName))
|
.filter(station -> station.getName().equals(newStationName))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
if (newSelectedStation != null) {
|
updateStationSettings(newSelectedStation);
|
||||||
selectedStation = newSelectedStation;
|
|
||||||
selectedStationName.set(newStationName);
|
|
||||||
settings.setSelectedStationName(selectedStationName.get());
|
|
||||||
|
|
||||||
settings.save();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -111,6 +114,7 @@ public class MainController implements Initializable {
|
|||||||
private void loadSettings() throws IOException {
|
private void loadSettings() throws IOException {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
String userHome = System.getProperty("user.home");
|
String userHome = System.getProperty("user.home");
|
||||||
|
// TODO: XDG
|
||||||
Path directoryPath = Paths.get(userHome, ".numbers-station");
|
Path directoryPath = Paths.get(userHome, ".numbers-station");
|
||||||
Path filePath = directoryPath.resolve("settings.xml");
|
Path filePath = directoryPath.resolve("settings.xml");
|
||||||
try {
|
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 StringProperty externalProgramCommand = new SimpleStringProperty();
|
||||||
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 StringProperty password = new SimpleStringProperty();
|
private StringProperty password = new SimpleStringProperty();
|
||||||
private StationSettings settings;
|
private StationSettings settings;
|
||||||
private StringProperty stationAddress = new SimpleStringProperty();
|
private StringProperty stationAddress = new SimpleStringProperty();
|
||||||
@ -43,6 +44,9 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField stationAddressField;
|
private TextField stationAddressField;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private RadioButton dailyRadioButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Spinner<Integer> digitsPerGroupSpinner;
|
private Spinner<Integer> digitsPerGroupSpinner;
|
||||||
|
|
||||||
@ -55,6 +59,12 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ToggleGroup messageMethodGroup;
|
private ToggleGroup messageMethodGroup;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ToggleGroup messagePeriodGroup;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private RadioButton monthlyRadioButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private RadioButton ftpRadioButton;
|
private RadioButton ftpRadioButton;
|
||||||
|
|
||||||
@ -76,6 +86,9 @@ public class MainSettingsController {
|
|||||||
@FXML
|
@FXML
|
||||||
private ListView<String> prefixListView;
|
private ListView<String> prefixListView;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private RadioButton weeklyRadioButton;
|
||||||
|
|
||||||
public MainSettingsController() { }
|
public MainSettingsController() { }
|
||||||
|
|
||||||
@FXML
|
@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.
|
// Set user data. Default result is no update.
|
||||||
stationNameField.sceneProperty().addListener((observable, oldScene, newScene) -> {
|
stationNameField.sceneProperty().addListener((observable, oldScene, newScene) -> {
|
||||||
if (newScene != null) {
|
if (newScene != null) {
|
||||||
@ -160,6 +193,7 @@ public class MainSettingsController {
|
|||||||
settings.setExternalProgramCommand(externalProgramCommand.get());
|
settings.setExternalProgramCommand(externalProgramCommand.get());
|
||||||
settings.setMessageLength(messageLength.get());
|
settings.setMessageLength(messageLength.get());
|
||||||
settings.setMessageMethod(messageMethod.get());
|
settings.setMessageMethod(messageMethod.get());
|
||||||
|
settings.setMessagePeriod(messagePeriod.get());
|
||||||
settings.setName(stationName.get());
|
settings.setName(stationName.get());
|
||||||
settings.setPassword(password.get());
|
settings.setPassword(password.get());
|
||||||
settings.getPrefixes().clear();
|
settings.getPrefixes().clear();
|
||||||
@ -190,6 +224,7 @@ public class MainSettingsController {
|
|||||||
externalProgramCommand.set(settings.getExternalProgramCommand());
|
externalProgramCommand.set(settings.getExternalProgramCommand());
|
||||||
messageLength.set(settings.getMessageLength());
|
messageLength.set(settings.getMessageLength());
|
||||||
messageMethod.set(settings.getMessageMethod());
|
messageMethod.set(settings.getMessageMethod());
|
||||||
|
messagePeriod.set(settings.getMessagePeriod());
|
||||||
username.set(settings.getUsername());
|
username.set(settings.getUsername());
|
||||||
password.set(settings.getPassword());
|
password.set(settings.getPassword());
|
||||||
prefixListView.getItems().addAll(settings.getPrefixes());
|
prefixListView.getItems().addAll(settings.getPrefixes());
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<FlowPane alignment="CENTER_LEFT" prefHeight="41.0" prefWidth="640.0">
|
<FlowPane alignment="CENTER_LEFT" prefHeight="41.0" prefWidth="640.0">
|
||||||
<children>
|
<children>
|
||||||
<Label prefHeight="17.0" prefWidth="49.0" text="Station: " />
|
<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>
|
<FlowPane.margin>
|
||||||
<Insets right="10.0" />
|
<Insets right="10.0" />
|
||||||
</FlowPane.margin>
|
</FlowPane.margin>
|
||||||
@ -133,18 +133,27 @@
|
|||||||
<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 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>
|
||||||
<ToggleGroup fx:id="scheduleFrequency" />
|
<ToggleGroup fx:id="messagePeriodGroup" />
|
||||||
</toggleGroup>
|
</toggleGroup>
|
||||||
</RadioButton>
|
</RadioButton>
|
||||||
<RadioButton layoutX="14.0" layoutY="38.0" mnemonicParsing="false" text="Weekly" toggleGroup="$scheduleFrequency" />
|
<RadioButton fx:id="weeklyRadioButton" layoutX="14.0" layoutY="38.0" mnemonicParsing="false" text="Weekly">
|
||||||
<RadioButton layoutX="14.0" layoutY="68.0" mnemonicParsing="false" text="Monthly" toggleGroup="$scheduleFrequency" />
|
<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" />
|
<DatePicker 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 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>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
|
@ -47,20 +47,17 @@
|
|||||||
<children>
|
<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">
|
<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>
|
<children>
|
||||||
<FlowPane alignment="CENTER_LEFT" prefHeight="41.0" prefWidth="640.0">
|
<AnchorPane>
|
||||||
<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>
|
|
||||||
<VBox.margin>
|
<VBox.margin>
|
||||||
<Insets bottom="10.0" />
|
<Insets bottom="10.0" />
|
||||||
</VBox.margin>
|
</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" />
|
<Separator prefWidth="200.0" />
|
||||||
<AnchorPane prefHeight="50.0" prefWidth="570.0">
|
<AnchorPane prefHeight="50.0" prefWidth="570.0">
|
||||||
<children>
|
<children>
|
||||||
|
@ -8,6 +8,7 @@ public class StationSettings {
|
|||||||
private String externalProgramCommand;
|
private String externalProgramCommand;
|
||||||
private int messageLength;
|
private int messageLength;
|
||||||
private MessageMethod messageMethod;
|
private MessageMethod messageMethod;
|
||||||
|
private MessagePeriod messagePeriod;
|
||||||
private String name;
|
private String name;
|
||||||
private String password;
|
private String password;
|
||||||
private ArrayList<String> prefixes;
|
private ArrayList<String> prefixes;
|
||||||
@ -20,6 +21,12 @@ public class StationSettings {
|
|||||||
EXTERNAL_PROGRAM
|
EXTERNAL_PROGRAM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MessagePeriod {
|
||||||
|
DAILY,
|
||||||
|
WEEKLY,
|
||||||
|
MONTHLY
|
||||||
|
}
|
||||||
|
|
||||||
public StationSettings() {
|
public StationSettings() {
|
||||||
prefixes = new ArrayList<String>();
|
prefixes = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
@ -68,6 +75,14 @@ public class StationSettings {
|
|||||||
messageMethod = newMessageMethod;
|
messageMethod = newMessageMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessagePeriod getMessagePeriod() {
|
||||||
|
return messagePeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessagePeriod(MessagePeriod newMessagePeriod) {
|
||||||
|
messagePeriod = newMessagePeriod;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user