Add prefixes to settings

This commit is contained in:
Nathan McRae 2025-01-12 22:32:11 -08:00
parent 6ab5e5d1ca
commit 3b725e3f29
3 changed files with 36 additions and 12 deletions

View File

@ -5,18 +5,23 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.io.IOException;
import java.util.Optional;
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.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.ListView;
import javafx.scene.control.RadioButton;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.control.TextField;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.ToggleGroup;
import javafx.scene.Node;
import javafx.stage.Stage;
@ -68,14 +73,10 @@ public class MainSettingsController {
@FXML
private TextField passwordField;
public MainSettingsController() throws IOException {
// System.out.println("Created settings controller");
// File file = new File("setting-test.xml");
// XmlMapper xmlMapper = new XmlMapper();
// settings = xmlMapper.readValue(file, NumbersStationSettings.class);
// settings.setRefreshInterval(settings.getRefreshInterval() + 40);
// settings.getStations().add(new StationSettings());
}
@FXML
private ListView<String> prefixListView;
public MainSettingsController() { }
@FXML
private void initialize() {
@ -126,7 +127,15 @@ public class MainSettingsController {
@FXML
private void handleAddPrefixButtonPress() {
// TODO
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("New prefix");
dialog.setHeaderText("Add a new prefix");
dialog.setContentText("Enter a message prefix / identifier:");
Optional<String> result = dialog.showAndWait();
result.ifPresent(prefix -> {
prefixListView.getItems().add(prefix);
});
}
@FXML
@ -138,7 +147,10 @@ public class MainSettingsController {
@FXML
private void handleRemovePrefixButtonPress() {
// TODO
int selectedIndex = prefixListView.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
prefixListView.getItems().remove(selectedIndex);
}
}
@FXML
@ -150,6 +162,8 @@ public class MainSettingsController {
settings.setMessageMethod(messageMethod.get());
settings.setName(stationName.get());
settings.setPassword(password.get());
settings.getPrefixes().clear();
settings.getPrefixes().addAll(prefixListView.getItems());
settings.setUsername(username.get());
Node node = (Node) e.getSource();
@ -178,5 +192,6 @@ public class MainSettingsController {
messageMethod.set(settings.getMessageMethod());
username.set(settings.getUsername());
password.set(settings.getPassword());
prefixListView.getItems().addAll(settings.getPrefixes());
}
}

View File

@ -119,7 +119,7 @@
<Insets bottom="10.0" />
</VBox.margin>
</AnchorPane>
<ListView prefHeight="103.0" prefWidth="578.0" />
<ListView fx:id="prefixListView" prefHeight="103.0" prefWidth="578.0" />
<Separator prefWidth="200.0">
<VBox.margin>
<Insets bottom="10.0" top="10.0" />

View File

@ -1,5 +1,7 @@
package name.nathanmcrae.numbersstation;
import java.util.ArrayList;
public class StationSettings {
private String address;
private int digitsPerGroup;
@ -8,6 +10,7 @@ public class StationSettings {
private MessageMethod messageMethod;
private String name;
private String password;
private ArrayList<String> prefixes;
private String username;
public enum MessageMethod {
@ -17,7 +20,9 @@ public class StationSettings {
EXTERNAL_PROGRAM
}
public StationSettings() { }
public StationSettings() {
prefixes = new ArrayList<String>();
}
public StationSettings(String newName) {
name = newName;
@ -79,6 +84,10 @@ public class StationSettings {
password = newPassword;
}
public ArrayList<String> getPrefixes() {
return prefixes;
}
public String getUsername() {
return username;
}