diff --git a/src/main/java/envoy/client/data/SettingsItem.java b/src/main/java/envoy/client/data/SettingsItem.java index e9c498c..fc8552c 100644 --- a/src/main/java/envoy/client/data/SettingsItem.java +++ b/src/main/java/envoy/client/data/SettingsItem.java @@ -1,8 +1,6 @@ package envoy.client.data; import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; @@ -10,11 +8,13 @@ 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.
*
- * Project: envoy-clientChess
+ * Project: envoy-client
* File: SettingsItem.java
* Created: 23.12.2019
* @@ -27,17 +27,11 @@ public class SettingsItem implements Serializable { private T value; private String userFriendlyName, description; - private transient Consumer changeHandler; - private transient Function, Node> nodeCreator; - - private static final Map, Function, Node>> nodeCreators = new HashMap<>(); + private transient Consumer changeHandler; + private transient Function, ? extends Node> nodeCreator; private static final long serialVersionUID = 1L; - static { - - } - /** * Initializes a {@link SettingsItem}. The default value's class will be mapped * to a {@link JComponent} that can be used to display this {@link SettingsItem} @@ -53,7 +47,7 @@ public class SettingsItem implements Serializable { this.userFriendlyName = userFriendlyName; this.description = description; - if (nodeCreators.containsKey(value.getClass())) nodeCreator = nodeCreators.get(value.getClass()); + if (value.getClass() == Boolean.class) nodeCreator = s -> new SettingsToggleButton((SettingsItem) s); } /** diff --git a/src/main/java/envoy/client/ui/GeneralSettingsPane.java b/src/main/java/envoy/client/ui/GeneralSettingsPane.java index 20f74f0..29c65d2 100644 --- a/src/main/java/envoy/client/ui/GeneralSettingsPane.java +++ b/src/main/java/envoy/client/ui/GeneralSettingsPane.java @@ -1,5 +1,7 @@ package envoy.client.ui; +import javafx.scene.layout.VBox; + import envoy.client.data.Settings; /** @@ -17,5 +19,11 @@ public class GeneralSettingsPane extends SettingsPane { /** * @since Envoy Client v0.1-beta */ - public GeneralSettingsPane() { super("General"); } + public GeneralSettingsPane() { + super("General"); + var vbox = new VBox(); + for (var name : new String[] { "onCloseMode", "enterToSend" }) + vbox.getChildren().add(settings.getItems().get(name).getNode()); + getChildren().add(vbox); + } } diff --git a/src/main/java/envoy/client/ui/SettingsToggleButton.java b/src/main/java/envoy/client/ui/SettingsToggleButton.java new file mode 100644 index 0000000..f91f7cb --- /dev/null +++ b/src/main/java/envoy/client/ui/SettingsToggleButton.java @@ -0,0 +1,23 @@ +package envoy.client.ui; + +import javafx.event.ActionEvent; +import javafx.scene.control.ToggleButton; + +import envoy.client.data.SettingsItem; + + +/** + * Project: envoy-client
+ * File: SettingsToggleButton.java
+ * Created: 18.04.2020
+ * + * @author Kai S. K. Engelbart + * @since Envoy Client v0.1-beta + */ +public final class SettingsToggleButton extends ToggleButton { + + public SettingsToggleButton(SettingsItem settingsItem) { + super(settingsItem.getUserFriendlyName()); + addEventHandler(ActionEvent.ACTION, e -> settingsItem.set(!settingsItem.get())); + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 2de5fa8..9413967 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -17,6 +17,7 @@ module envoy { requires javafx.controls; requires javafx.fxml; requires javafx.base; + requires javafx.graphics; opens envoy.client.ui to javafx.graphics, javafx.fxml; }