Added UI theme switcher (issue #930)

This commit is contained in:
Sebastian Stenzel
2019-07-22 15:05:23 +02:00
parent cf2e026f75
commit c917fb6a57
9 changed files with 105 additions and 9 deletions
@@ -2,7 +2,11 @@ package org.cryptomator.ui;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.Observable;
import javafx.beans.value.ObservableValue;
import javafx.stage.Stage;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.UiTheme;
import org.cryptomator.ui.mainwindow.MainWindowComponent;
import org.cryptomator.ui.preferences.PreferencesComponent;
import org.slf4j.Logger;
@@ -17,17 +21,22 @@ public class FxApplication extends Application {
private static final Logger LOG = LoggerFactory.getLogger(FxApplication.class);
private final Settings settings;
private final MainWindowComponent.Builder mainWindow;
private final PreferencesComponent.Builder preferencesWindow;
@Inject
FxApplication(MainWindowComponent.Builder mainWindow, PreferencesComponent.Builder preferencesWindow) {
FxApplication(Settings settings, MainWindowComponent.Builder mainWindow, PreferencesComponent.Builder preferencesWindow) {
this.settings = settings;
this.mainWindow = mainWindow;
this.preferencesWindow = preferencesWindow;
}
public void start() {
LOG.trace("FxApplication.start()");
settings.theme().addListener(this::themeChanged);
loadSelectedStyleSheet(settings.theme().get());
if (Desktop.getDesktop().isSupported(Desktop.Action.APP_PREFERENCES)) {
Desktop.getDesktop().setPreferencesHandler(this::handlePreferences);
@@ -49,5 +58,25 @@ public class FxApplication extends Application {
preferencesWindow.build().showPreferencesWindow();
}
private void themeChanged(@SuppressWarnings("unused") ObservableValue<? extends UiTheme> observable, @SuppressWarnings("unused") UiTheme oldValue, UiTheme newValue) {
loadSelectedStyleSheet(newValue);
}
private void loadSelectedStyleSheet(UiTheme theme) {
switch (theme) {
case CUSTOM:
// TODO
Application.setUserAgentStylesheet(getClass().getResource("/css/win_theme.css").toString());
break;
case DARK:
// TODO
Application.setUserAgentStylesheet(getClass().getResource("/css/mac_theme.css").toString());
break;
case LIGHT:
default:
Application.setUserAgentStylesheet(getClass().getResource("/css/theme.css").toString());
break;
}
}
}
@@ -6,7 +6,6 @@
package org.cryptomator.ui;
import dagger.Subcomponent;
import javafx.application.Application;
import javafx.application.Platform;
@FxApplicationScoped
@@ -18,7 +17,6 @@ public interface FxApplicationComponent {
default void start() {
Platform.startup(() -> {
assert Platform.isFxApplicationThread();
Application.setUserAgentStylesheet(getClass().getResource("/css/theme.css").toString());
application().start();
});
}
@@ -8,6 +8,7 @@ import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextField;
import javafx.util.StringConverter;
import org.cryptomator.common.settings.Settings;
import org.cryptomator.common.settings.UiTheme;
import org.cryptomator.common.settings.VolumeImpl;
import org.cryptomator.common.settings.WebDavUrlScheme;
import org.cryptomator.ui.common.FxController;
@@ -20,6 +21,7 @@ public class PreferencesController implements FxController {
private final Settings settings;
private final BooleanBinding showWebDavSettings;
public ChoiceBox<UiTheme> themeChoiceBox;
public CheckBox checkForUpdatesCheckbox;
public CheckBox debugModeCheckbox;
public ChoiceBox<VolumeImpl> volumeTypeChoicBox;
@@ -34,6 +36,10 @@ public class PreferencesController implements FxController {
}
public void initialize() {
themeChoiceBox.getItems().addAll(UiTheme.values());
themeChoiceBox.valueProperty().bindBidirectional(settings.theme());
themeChoiceBox.setConverter(new UiThemeConverter());
checkForUpdatesCheckbox.selectedProperty().bindBidirectional(settings.checkForUpdates());
debugModeCheckbox.selectedProperty().bindBidirectional(settings.debugMode());
@@ -77,6 +83,19 @@ public class PreferencesController implements FxController {
/* Helper classes */
private static class UiThemeConverter extends StringConverter<UiTheme> {
@Override
public String toString(UiTheme impl) {
return impl.getDisplayName();
}
@Override
public UiTheme fromString(String string) {
throw new UnsupportedOperationException();
}
}
private static class WebDavUrlSchemeConverter extends StringConverter<WebDavUrlScheme> {
@Override
@@ -17,6 +17,11 @@
<Insets bottom="12" left="12" right="12" top="12"/>
</padding>
<children>
<HBox spacing="6" alignment="BASELINE_LEFT">
<Label text="%preferences.theme"/>
<ChoiceBox fx:id="themeChoiceBox"/>
</HBox>
<CheckBox fx:id="checkForUpdatesCheckbox" text="%preferences.autoUpdateCheck"/>
<CheckBox fx:id="debugModeCheckbox" text="%preferences.debugLogging"/>
@@ -2,5 +2,6 @@ main.closeBtn.tooltip=Close
main.settingsBtn.tooltip=Settings
preferences.autoUpdateCheck=Check for updates automatically
preferences.debugLogging=Enable debug logging
preferences.theme=Look & Feel
preferences.volumeType=Volume type
vaultlist.emptyList.onboardingInstruction=Click here to add a vault
@@ -2,5 +2,6 @@ main.closeBtn.tooltip=Close
main.settingsBtn.tooltip=Settings
preferences.autoUpdateCheck=Check for updates automatically
preferences.debugLogging=Enable debug logging
preferences.theme=Look & Feel
preferences.volumeType=Volume type
vaultlist.emptyList.onboardingInstruction=Click here to add a vault