From 5af5a6c5b0470bb728c63881df8680a504d048da Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 2 Oct 2019 14:27:10 +0200 Subject: [PATCH] enhancing fxml loading to add local specific stylesheets, for #754 --- .../java/org/cryptomator/ui/common/FXMLLoaderFactory.java | 7 +++++++ main/ui/src/main/resources/i18n/strings.properties | 3 +++ 2 files changed, 10 insertions(+) diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java b/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java index dcd0072b2..395799f18 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FXMLLoaderFactory.java @@ -1,5 +1,6 @@ package org.cryptomator.ui.common; +import com.google.common.base.Splitter; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; @@ -9,6 +10,8 @@ import javax.inject.Provider; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; +import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -34,6 +37,7 @@ public class FXMLLoaderFactory { /** * Loads the FXML given fxml resource in a new FXMLLoader instance. + * * @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}). * @return The FXMLLoader used to load the file * @throws IOException if an error occurs while loading the FXML file @@ -48,6 +52,7 @@ public class FXMLLoaderFactory { /** * {@link #load(String) Loads} the FXML file and creates a new Scene containing the loaded ui. + * * @param fxmlResourceName Name of the resource (as in {@link Class#getResource(String)}). * @throws UncheckedIOException wrapping any IOException thrown by {@link #load(String)). */ @@ -59,6 +64,8 @@ public class FXMLLoaderFactory { throw new UncheckedIOException("Failed to load " + fxmlResourceName, e); } Parent root = loader.getRoot(); + List addtionalStyleSheets = Splitter.on(',').omitEmptyStrings().splitToList(resourceBundle.getString("additionalStyleSheets")); + addtionalStyleSheets.forEach(styleSheet -> root.getStylesheets().add("/css/" + styleSheet)); return new Scene(root); } diff --git a/main/ui/src/main/resources/i18n/strings.properties b/main/ui/src/main/resources/i18n/strings.properties index df7fa36e0..a5d90a84f 100644 --- a/main/ui/src/main/resources/i18n/strings.properties +++ b/main/ui/src/main/resources/i18n/strings.properties @@ -1,3 +1,6 @@ +# Locale Specific CSS files such as CJK, RTL,... +additionalStyleSheets= + # Generics ## Button generic.button.apply=Apply