Add theme selection in settings

This commit is contained in:
Kai S. K. Engelbart 2020-06-08 10:02:39 +02:00
parent 5e73334e35
commit 1761044e9e
7 changed files with 27 additions and 17 deletions

View File

@ -83,7 +83,7 @@ public class Settings {
* @return the name of the currently active theme
* @since Envoy Client v0.2-alpha
*/
public String getCurrentThemeName() { return (String) items.get("currentTheme").get(); }
public String getCurrentTheme() { return (String) items.get("currentTheme").get(); }
/**
* Sets the name of the current theme.

View File

@ -92,7 +92,7 @@ public final class SceneContext {
private void applyCSS() {
if (!sceneStack.isEmpty()) {
final var styleSheets = stage.getScene().getStylesheets();
final var themeCSS = "/css/" + settings.getCurrentThemeName() + ".css";
final var themeCSS = "/css/" + settings.getCurrentTheme() + ".css";
styleSheets.clear();
styleSheets.addAll(getClass().getResource("/css/base.css").toExternalForm(), getClass().getResource(themeCSS).toExternalForm());
}

View File

@ -2,10 +2,13 @@ package envoy.client.ui.settings;
import java.util.List;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.VBox;
import envoy.client.data.Settings;
import envoy.client.data.SettingsItem;
import envoy.client.event.ThemeChangeEvent;
import envoy.event.EventBus;
/**
* Project: <strong>envoy-client</strong><br>
@ -30,8 +33,17 @@ public class GeneralSettingsPane extends SettingsPane {
List.of("onCloseMode", "enterToSend")
.stream()
.map(settings.getItems()::get)
.map(i -> new SettingsToggleButton((SettingsItem<Boolean>) i))
.map(i -> new SettingsCheckbox((SettingsItem<Boolean>) i))
.forEach(vbox.getChildren()::add);
var combobox = new ComboBox<String>();
combobox.getItems().add("dark");
combobox.getItems().add("light");
combobox.setValue(settings.getCurrentTheme());
combobox.setOnAction(
e -> { settings.setCurrentTheme(combobox.getValue()); EventBus.getInstance().dispatch(new ThemeChangeEvent(combobox.getValue())); });
vbox.getChildren().add(combobox);
getChildren().add(vbox);
}
}

View File

@ -1,7 +1,7 @@
package envoy.client.ui.settings;
import javafx.event.ActionEvent;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.CheckBox;
import envoy.client.data.SettingsItem;
@ -13,20 +13,20 @@ import envoy.client.data.SettingsItem;
* @author Kai S. K. Engelbart
* @since Envoy Client v0.1-beta
*/
public final class SettingsToggleButton extends ToggleButton {
public final class SettingsCheckbox extends CheckBox {
/**
* Creates an instance of {@link SettingsToggleButton}.
* Creates an instance of {@link SettingsCheckbox}.
*
* @param settingsItem the {@link SettingsItem} whose values could be adapted
* @since Envoy Client v0.1-beta
*/
public SettingsToggleButton(SettingsItem<Boolean> settingsItem) {
public SettingsCheckbox(SettingsItem<Boolean> settingsItem) {
super(settingsItem.getUserFriendlyName());
setSelected(settingsItem.get());
// "Schau, es hat sich behindert" - Kai, 2020
addEventHandler(ActionEvent.ACTION, e -> settingsItem.set(!settingsItem.get()));
addEventHandler(ActionEvent.ACTION, e -> settingsItem.set(isSelected()));
}
}

View File

@ -1,5 +1,3 @@
* {
/* -fx-font: 14.0pt "Serif";
-fx-background-color:#000000; */
-fx-opacity:1;
.button {
-fx-background-radius: 5em;
}

View File

@ -1,7 +1,4 @@
.root{
--background=#000000;
background: var(--background);
}
.button{
color: rgb(105,0,153);
-fx-background-color: rgb(105,0,153);
-fx-text-fill: white;
}

View File

@ -0,0 +1,3 @@
.button{
-fx-background-color: snow;
}