diff --git a/src/main/java/envoy/client/data/Settings.java b/src/main/java/envoy/client/data/Settings.java index fcde72a..419d22a 100644 --- a/src/main/java/envoy/client/data/Settings.java +++ b/src/main/java/envoy/client/data/Settings.java @@ -88,11 +88,11 @@ public class Settings { /** * Updates the preferences when the save button is clicked. * - * @throws IOException if an error occurs while saving the themes to the theme - * file + * @throws IOException if an error occurs while saving the themes * @since Envoy Client v0.2-alpha */ public void save() throws IOException { + // Save settings to settings file SerializationUtils.write(settingsFile, items); diff --git a/src/main/java/envoy/client/data/SettingsItem.java b/src/main/java/envoy/client/data/SettingsItem.java index fc8552c..98a562d 100644 --- a/src/main/java/envoy/client/data/SettingsItem.java +++ b/src/main/java/envoy/client/data/SettingsItem.java @@ -2,14 +2,9 @@ package envoy.client.data; import java.io.Serializable; import java.util.function.Consumer; -import java.util.function.Function; import javax.swing.JComponent; -import javafx.scene.Node; - -import envoy.client.ui.SettingsToggleButton; - /** * Encapsulates a persistent value that is directly or indirectly mutable by the * user.
@@ -28,7 +23,6 @@ public class SettingsItem implements Serializable { private String userFriendlyName, description; private transient Consumer changeHandler; - private transient Function, ? extends Node> nodeCreator; private static final long serialVersionUID = 1L; @@ -46,8 +40,6 @@ public class SettingsItem implements Serializable { this.value = value; this.userFriendlyName = userFriendlyName; this.description = description; - - if (value.getClass() == Boolean.class) nodeCreator = s -> new SettingsToggleButton((SettingsItem) s); } /** @@ -104,8 +96,4 @@ public class SettingsItem implements Serializable { this.changeHandler = changeHandler; changeHandler.accept(value); } - - public boolean hasNodeCreator() { return nodeCreator != null; } - - public Node getNode() { return nodeCreator.apply(this); } } diff --git a/src/main/java/envoy/client/ui/GeneralSettingsPane.java b/src/main/java/envoy/client/ui/GeneralSettingsPane.java index 29c65d2..b207867 100644 --- a/src/main/java/envoy/client/ui/GeneralSettingsPane.java +++ b/src/main/java/envoy/client/ui/GeneralSettingsPane.java @@ -1,8 +1,11 @@ package envoy.client.ui; +import java.util.List; + import javafx.scene.layout.VBox; import envoy.client.data.Settings; +import envoy.client.data.SettingsItem; /** * Project: envoy-client
@@ -22,8 +25,13 @@ public class GeneralSettingsPane extends SettingsPane { public GeneralSettingsPane() { super("General"); var vbox = new VBox(); - for (var name : new String[] { "onCloseMode", "enterToSend" }) - vbox.getChildren().add(settings.getItems().get(name).getNode()); + + // TODO: Support other value types + List.of("onCloseMode", "enterToSend") + .stream() + .map(settings.getItems()::get) + .map(i -> new SettingsToggleButton((SettingsItem) i)) + .forEach(vbox.getChildren()::add); getChildren().add(vbox); } } diff --git a/src/main/java/envoy/client/ui/SettingsSceneController.java b/src/main/java/envoy/client/ui/SettingsSceneController.java index 743a58c..33f45a6 100644 --- a/src/main/java/envoy/client/ui/SettingsSceneController.java +++ b/src/main/java/envoy/client/ui/SettingsSceneController.java @@ -33,17 +33,22 @@ public class SettingsSceneController { settingsList.setCellFactory(listView -> new ListCell<>() { @Override - protected void updateItem(SettingsPane item, boolean empty) { if (!empty && item != null) setGraphic(new Label(item.getTitle())); } + protected void updateItem(SettingsPane item, boolean empty) { + super.updateItem(item, empty); + if (!empty && item != null) setGraphic(new Label(item.getTitle())); + } }); - // settingsList.getItems().add(new GeneralSettingsPane()); + settingsList.getItems().add(new GeneralSettingsPane()); } @FXML private void settingsListClicked() { final var pane = settingsList.getSelectionModel().getSelectedItem(); - titledPane.setText(pane.getTitle()); - titledPane.setContent(pane); + if (pane != null) { + titledPane.setText(pane.getTitle()); + titledPane.setContent(pane); + } } @FXML