Added SettingsToggleButton
This commit is contained in:
parent
2cba9352df
commit
e4e903b8bf
@ -1,8 +1,6 @@
|
|||||||
package envoy.client.data;
|
package envoy.client.data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@ -10,11 +8,13 @@ import javax.swing.JComponent;
|
|||||||
|
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
|
||||||
|
import envoy.client.ui.SettingsToggleButton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates a persistent value that is directly or indirectly mutable by the
|
* Encapsulates a persistent value that is directly or indirectly mutable by the
|
||||||
* user.<br>
|
* user.<br>
|
||||||
* <br>
|
* <br>
|
||||||
* Project: <strong>envoy-clientChess</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
* File: <strong>SettingsItem.java</strong><br>
|
* File: <strong>SettingsItem.java</strong><br>
|
||||||
* Created: <strong>23.12.2019</strong><br>
|
* Created: <strong>23.12.2019</strong><br>
|
||||||
*
|
*
|
||||||
@ -28,16 +28,10 @@ public class SettingsItem<T> implements Serializable {
|
|||||||
private String userFriendlyName, description;
|
private String userFriendlyName, description;
|
||||||
|
|
||||||
private transient Consumer<T> changeHandler;
|
private transient Consumer<T> changeHandler;
|
||||||
private transient Function<SettingsItem<?>, Node> nodeCreator;
|
private transient Function<SettingsItem<?>, ? extends Node> nodeCreator;
|
||||||
|
|
||||||
private static final Map<Class<?>, Function<SettingsItem<?>, Node>> nodeCreators = new HashMap<>();
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
static {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a {@link SettingsItem}. The default value's class will be mapped
|
* 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}
|
* to a {@link JComponent} that can be used to display this {@link SettingsItem}
|
||||||
@ -53,7 +47,7 @@ public class SettingsItem<T> implements Serializable {
|
|||||||
this.userFriendlyName = userFriendlyName;
|
this.userFriendlyName = userFriendlyName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
||||||
if (nodeCreators.containsKey(value.getClass())) nodeCreator = nodeCreators.get(value.getClass());
|
if (value.getClass() == Boolean.class) nodeCreator = s -> new SettingsToggleButton((SettingsItem<Boolean>) s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import envoy.client.data.Settings;
|
import envoy.client.data.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -17,5 +19,11 @@ public class GeneralSettingsPane extends SettingsPane {
|
|||||||
/**
|
/**
|
||||||
* @since Envoy Client v0.1-beta
|
* @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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
23
src/main/java/envoy/client/ui/SettingsToggleButton.java
Normal file
23
src/main/java/envoy/client/ui/SettingsToggleButton.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.scene.control.ToggleButton;
|
||||||
|
|
||||||
|
import envoy.client.data.SettingsItem;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Project: <strong>envoy-client</strong><br>
|
||||||
|
* File: <strong>SettingsToggleButton.java</strong><br>
|
||||||
|
* Created: <strong>18.04.2020</strong><br>
|
||||||
|
*
|
||||||
|
* @author Kai S. K. Engelbart
|
||||||
|
* @since Envoy Client v0.1-beta
|
||||||
|
*/
|
||||||
|
public final class SettingsToggleButton extends ToggleButton {
|
||||||
|
|
||||||
|
public SettingsToggleButton(SettingsItem<Boolean> settingsItem) {
|
||||||
|
super(settingsItem.getUserFriendlyName());
|
||||||
|
addEventHandler(ActionEvent.ACTION, e -> settingsItem.set(!settingsItem.get()));
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ module envoy {
|
|||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
requires javafx.base;
|
requires javafx.base;
|
||||||
|
requires javafx.graphics;
|
||||||
|
|
||||||
opens envoy.client.ui to javafx.graphics, javafx.fxml;
|
opens envoy.client.ui to javafx.graphics, javafx.fxml;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user