Move CSS theme code into its own class, apply CSS theme to all scenes

This commit is contained in:
wiz 2019-09-01 20:14:47 +09:00
parent 0a12676946
commit 04d073fab7
No known key found for this signature in database
GPG Key ID: A394E332255A6173
3 changed files with 61 additions and 22 deletions

View File

@ -30,6 +30,7 @@ import bisq.desktop.main.overlays.windows.ManualPayoutTxWindow;
import bisq.desktop.main.overlays.windows.SendAlertMessageWindow;
import bisq.desktop.main.overlays.windows.ShowWalletDataWindow;
import bisq.desktop.util.ImageUtil;
import bisq.desktop.util.CssTheme;
import bisq.core.alert.AlertManager;
import bisq.core.app.AppOptionKeys;
@ -175,10 +176,7 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
if (scene == null) {
log.warn("Scene not available yet, we create a new scene. The bug might be caused by an exception in a constructor or by a circular dependency in Guice. throwable=" + throwable.toString());
scene = new Scene(new StackPane(), 1000, 650);
scene.getStylesheets().setAll(
"/bisq/desktop/theme-light.css",
"/bisq/desktop/bisq.css",
"/bisq/desktop/images.css");
CssTheme.loadSceneStyles(scene, CssTheme.CSS_THEME_LIGHT);
stage.setScene(scene);
stage.show();
}
@ -231,23 +229,13 @@ public class BisqApp extends Application implements UncaughtExceptionHandler {
addSceneKeyEventHandler(scene, injector);
loadSceneStyles(scene, injector);
injector.getInstance(Preferences.class).getCssThemeProperty().addListener((ov) -> {
loadSceneStyles(scene, injector);
Preferences preferences = injector.getInstance(Preferences.class);
preferences.getCssThemeProperty().addListener((ov) -> {
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
});
return scene;
}
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
private void loadSceneStyles(Scene scene, Injector injector) {
Boolean useDarkMode = (injector.getInstance(Preferences.class).getCssTheme() == 1);
String colorSheet = "/bisq/desktop/theme-light.css";
if (useDarkMode)
colorSheet = "/bisq/desktop/theme-dark.css";
scene.getStylesheets().setAll(
"/bisq/desktop/bisq.css",
"/bisq/desktop/images.css",
"/bisq/desktop/CandleStickChart.css",
colorSheet); // load theme last to override CSS colors
return scene;
}
private void setupStage(Scene scene) {

View File

@ -27,6 +27,7 @@ import bisq.desktop.main.MainView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.TradeDetailsWindow;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.CssTheme;
import bisq.core.alert.PrivateNotificationManager;
import bisq.core.app.AppOptionKeys;
@ -392,9 +393,7 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
});
Scene scene = new Scene(pane);
scene.getStylesheets().setAll("/bisq/desktop/theme-light.css",
"/bisq/desktop/bisq.css",
"/bisq/desktop/images.css");
CssTheme.loadSceneStyles(scene, preferences.getCssTheme());
scene.addEventHandler(KeyEvent.KEY_RELEASED, ev -> {
if (ev.getCode() == KeyCode.ESCAPE) {
ev.consume();

View File

@ -0,0 +1,52 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.util;
import javafx.scene.Scene;
public class CssTheme {
public static final int CSS_THEME_LIGHT = 0;
public static final int CSS_THEME_DARK = 1;
public static void loadSceneStyles(Scene scene, int cssTheme) {
String cssThemeFolder = "/bisq/desktop/";
String cssThemeFile = "";
switch (cssTheme) {
case CSS_THEME_DARK:
cssThemeFile = "theme-dark.css";
break;
case CSS_THEME_LIGHT:
default:
cssThemeFile = "theme-light.css";
break;
}
scene.getStylesheets().setAll(
// load base styles first
cssThemeFolder + "bisq.css",
cssThemeFolder + "images.css",
cssThemeFolder + "CandleStickChart.css",
// load theme last to allow override
cssThemeFolder + cssThemeFile
);
}
}