Add theme selection in settings
This commit is contained in:
		| @@ -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. | ||||
|   | ||||
| @@ -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()); | ||||
| 		} | ||||
|   | ||||
| @@ -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); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -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())); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user