Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Remove imports from css and use a list of stylesheets instead #745

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* Copyright (c) 2016, 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -2317,15 +2317,15 @@ public boolean isSelected() {
res = (currentTheme == theme || currentTheme == EditorPlatform.Theme.CASPIAN_EMBEDDED_QVGA_HIGH_CONTRAST);
break;
case MODENA_HIGH_CONTRAST_BLACK_ON_WHITE:
res = EditorPlatform.isModenaBlackonwhite(currentTheme)
res = EditorPlatform.isModenaBlackOnWhite(currentTheme)
&& EditorPlatform.isModenaHighContrast(currentTheme);
break;
case MODENA_HIGH_CONTRAST_WHITE_ON_BLACK:
res = EditorPlatform.isModenaWhiteonblack(currentTheme)
res = EditorPlatform.isModenaWhiteOnBlack(currentTheme)
&& EditorPlatform.isModenaHighContrast(currentTheme);
break;
case MODENA_HIGH_CONTRAST_YELLOW_ON_BLACK:
res = EditorPlatform.isModenaYellowonblack(currentTheme)
res = EditorPlatform.isModenaYellowOnBlack(currentTheme)
&& EditorPlatform.isModenaHighContrast(currentTheme);
break;
case MODENA:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,41 @@ public static OS get() {
public static final EditorPlatform.GluonTheme DEFAULT_GLUON_THEME = GluonTheme.LIGHT;

interface StylesheetProvider {
String getStylesheetURL();
List<String> getStylesheetURLs();
}

private static final String MODENA_PATH = "com/sun/javafx/scene/control/skin/modena/";
private static final String CASPIAN_PATH = "com/sun/javafx/scene/control/skin/caspian/";
/**
* Themes supported by Scene Builder Kit.
*/
public enum Theme implements StylesheetProvider {
GLUON_MOBILE_LIGHT(GlistenStyleClasses.impl_loadResource("glisten.css")),
GLUON_MOBILE_DARK(GlistenStyleClasses.impl_loadResource("glisten.css")),
MODENA("com/sun/javafx/scene/control/skin/modena/modena.bss"),
MODENA_TOUCH("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch.css"),
MODENA_HIGH_CONTRAST_BLACK_ON_WHITE("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-blackOnWhite.css"),
MODENA_HIGH_CONTRAST_WHITE_ON_BLACK("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-whiteOnBlack.css"),
MODENA_HIGH_CONTRAST_YELLOW_ON_BLACK("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-highContrast-yellowOnBlack.css"),
MODENA_TOUCH_HIGH_CONTRAST_BLACK_ON_WHITE("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-blackOnWhite.css"),
MODENA_TOUCH_HIGH_CONTRAST_WHITE_ON_BLACK("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-whiteOnBlack.css"),
MODENA_TOUCH_HIGH_CONTRAST_YELLOW_ON_BLACK("com/oracle/javafx/scenebuilder/kit/util/css/modena/modena-touch-highContrast-yellowOnBlack.css"),
CASPIAN("com/sun/javafx/scene/control/skin/caspian/caspian.bss"),
CASPIAN_HIGH_CONTRAST("com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-highContrast.css"),
CASPIAN_EMBEDDED("com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded.css"),
CASPIAN_EMBEDDED_HIGH_CONTRAST("com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-highContrast.css"),
CASPIAN_EMBEDDED_QVGA("com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-qvga.css"),
CASPIAN_EMBEDDED_QVGA_HIGH_CONTRAST("com/oracle/javafx/scenebuilder/kit/util/css/caspian/caspian-embedded-qvga-highContrast.css");

private String url;

Theme(String url) {
this.url = url;
MODENA(MODENA_PATH + "modena.css"),
MODENA_TOUCH(MODENA_PATH + "modena.css", MODENA_PATH + "touch.css"),
MODENA_HIGH_CONTRAST_BLACK_ON_WHITE(MODENA_PATH + "modena.css", MODENA_PATH + "blackOnWhite.css"),
MODENA_HIGH_CONTRAST_WHITE_ON_BLACK(MODENA_PATH + "modena.css", MODENA_PATH + "whiteOnBlack.css"),
MODENA_HIGH_CONTRAST_YELLOW_ON_BLACK(MODENA_PATH + "modena.css", MODENA_PATH + "yellowOnBlack.css"),
MODENA_TOUCH_HIGH_CONTRAST_BLACK_ON_WHITE(MODENA_PATH + "modena.css", MODENA_PATH + "touch.css", MODENA_PATH + "blackOnWhite.css"),
MODENA_TOUCH_HIGH_CONTRAST_WHITE_ON_BLACK(MODENA_PATH + "modena.css", MODENA_PATH + "touch.css", MODENA_PATH + "whiteOnBlack.css"),
MODENA_TOUCH_HIGH_CONTRAST_YELLOW_ON_BLACK(MODENA_PATH + "modena.css", MODENA_PATH + "touch.css", MODENA_PATH + "yellowOnBlack.css"),
CASPIAN(CASPIAN_PATH + "caspian.css"),
CASPIAN_HIGH_CONTRAST(CASPIAN_PATH + "caspian.css", CASPIAN_PATH + "highcontrast.css"),
CASPIAN_EMBEDDED(CASPIAN_PATH + "caspian.css", CASPIAN_PATH + "embedded.css"),
CASPIAN_EMBEDDED_HIGH_CONTRAST(CASPIAN_PATH + "caspian.css", CASPIAN_PATH + "embedded.css", CASPIAN_PATH + "highcontrast.css"),
CASPIAN_EMBEDDED_QVGA(CASPIAN_PATH + "caspian.css", CASPIAN_PATH + "embedded.css", CASPIAN_PATH + "embedded-qvga.css"),
CASPIAN_EMBEDDED_QVGA_HIGH_CONTRAST(CASPIAN_PATH + "caspian.css", CASPIAN_PATH + "embedded.css", CASPIAN_PATH + "embedded-qvga.css", CASPIAN_PATH + "highcontrast.css");

private final List<String> urls;

Theme(String... urls) {
this.urls = List.of(urls);
}

@Override
public String getStylesheetURL() {
return url;
public List<String> getStylesheetURLs() {
return urls;
}

@Override
Expand Down Expand Up @@ -194,15 +196,15 @@ public String toString() {
}

@Override
public String getStylesheetURL() {
return GlistenStyleClasses.impl_loadResource("swatch_" + name().toLowerCase(Locale.ROOT) + ".css");
public List<String> getStylesheetURLs() {
return List.of(GlistenStyleClasses.impl_loadResource("swatch_" + name().toLowerCase(Locale.ROOT) + ".css"));
}

public Color getColor() {
if (color == null) {
URL url = null;
try {
url = new URL(getStylesheetURL());
url = new URL(getStylesheetURLs().getFirst());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
String s = reader.readLine();
while (s != null) {
Expand Down Expand Up @@ -246,8 +248,8 @@ public String toString() {
}

@Override
public String getStylesheetURL() {
return GlistenStyleClasses.impl_loadResource("theme_" + name().toLowerCase(Locale.ROOT) + ".css");
public List<String> getStylesheetURLs() {
return List.of(GlistenStyleClasses.impl_loadResource("theme_" + name().toLowerCase(Locale.ROOT) + ".css"));
}
}

Expand All @@ -257,7 +259,7 @@ public String getStylesheetURL() {

public static String getPlatformThemeStylesheetURL() {
// Return USER_AGENT css, which is Modena for fx 8.0
return Theme.MODENA.getStylesheetURL();
return Theme.MODENA.getStylesheetURLs().getFirst();
}

public static String getGluonDocumentStylesheetURL() {
Expand All @@ -268,17 +270,17 @@ public static boolean isModena(Theme theme) {
return theme.toString().startsWith("MODENA");
}

public static boolean isModenaBlackonwhite(Theme theme) {
public static boolean isModenaBlackOnWhite(Theme theme) {
return isModena(theme)
&& theme.toString().contains("BLACK_ON_WHITE");
}

public static boolean isModenaWhiteonblack(Theme theme) {
public static boolean isModenaWhiteOnBlack(Theme theme) {
return isModena(theme)
&& theme.toString().contains("WHITE_ON_BLACK");
}

public static boolean isModenaYellowonblack(Theme theme) {
public static boolean isModenaYellowOnBlack(Theme theme) {
return isModena(theme)
&& theme.toString().contains("YELLOW_ON_BLACK");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* Copyright (c) 2016, 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -1091,8 +1091,7 @@ private void themeDidChange() {
final EditorPlatform.Theme theme = getEditorController().getTheme();
final EditorPlatform.GluonSwatch gluonSwatch = getEditorController().getGluonSwatch();
final EditorPlatform.GluonTheme gluonTheme = getEditorController().getGluonTheme();
final String themeStyleSheet = theme.getStylesheetURL();
workspaceController.setThemeStyleSheet(themeStyleSheet, theme, gluonSwatch, gluonTheme);
workspaceController.setThemeStyleSheet(theme.getStylesheetURLs(), theme, gluonSwatch, gluonTheme);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Gluon and/or its affiliates.
* Copyright (c) 2017, 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -163,24 +163,26 @@ public List<String> getThemeStyleSheets() {
return Collections.unmodifiableList(themeStylesheets);
}

public void setThemeStyleSheet(String themeStyleSheet, EditorPlatform.Theme theme, EditorPlatform.GluonSwatch gluonSwatch, EditorPlatform.GluonTheme gluonTheme) {
assert themeStyleSheet != null;
public void setThemeStyleSheet(List<String> themeStyleSheets, EditorPlatform.Theme theme, EditorPlatform.GluonSwatch gluonSwatch, EditorPlatform.GluonTheme gluonTheme) {
assert themeStyleSheets != null;
assert theme != null;
assert gluonSwatch != null;
assert gluonTheme != null;
String gluonDocumentStylesheet = EditorPlatform.getGluonDocumentStylesheetURL();
String gluonSwatchStylesheet = gluonSwatch.getStylesheetURL();
String gluonThemeStylesheet = gluonTheme.getStylesheetURL();
String previousGluonSwatchStylesheet = editorController.getGluonSwatch().getStylesheetURL();
String previousGluonThemeStylesheet = editorController.getGluonTheme().getStylesheetURL();
String gluonSwatchStylesheet = gluonSwatch.getStylesheetURLs().getFirst();
String gluonThemeStylesheet = gluonTheme.getStylesheetURLs().getFirst();
String previousGluonSwatchStylesheet = editorController.getGluonSwatch().getStylesheetURLs().getFirst();
String previousGluonThemeStylesheet = editorController.getGluonTheme().getStylesheetURLs().getFirst();
if (theme == EditorPlatform.Theme.GLUON_MOBILE_LIGHT || theme == EditorPlatform.Theme.GLUON_MOBILE_DARK) {
contentSubScene.setUserAgentStylesheet(EditorPlatform.Theme.MODENA.getStylesheetURL());
contentSubScene.setUserAgentStylesheet(EditorPlatform.Theme.MODENA.getStylesheetURLs().getFirst());
ObservableList<String> currentStyleSheets = FXCollections.observableArrayList(contentGroup.getStylesheets());
currentStyleSheets.remove(previousGluonSwatchStylesheet);
currentStyleSheets.remove(previousGluonThemeStylesheet);
if (!currentStyleSheets.contains(themeStyleSheet)) {
currentStyleSheets.add(themeStyleSheet);
}
themeStyleSheets.forEach(themeStyleSheet -> {
if (!currentStyleSheets.contains(themeStyleSheet)) {
currentStyleSheets.add(themeStyleSheet);
}
});
if (!currentStyleSheets.contains(gluonDocumentStylesheet)) {
currentStyleSheets.add(gluonDocumentStylesheet);
}
Expand All @@ -195,13 +197,11 @@ public void setThemeStyleSheet(String themeStyleSheet, EditorPlatform.Theme them
contentGroupApplyCss();
// setPreviewStyleSheets(Arrays.asList(themeStyleSheet));
} else {
contentSubScene.setUserAgentStylesheet(themeStyleSheet);

String gluonMobileStyleSheet = EditorPlatform.Theme.GLUON_MOBILE_LIGHT.getStylesheetURL(); // We can call this with GLUON_MOBILE_LIGHT or GLUON_MOBILE_DARK
themeStylesheets.remove(gluonMobileStyleSheet);
themeStylesheets.remove(gluonDocumentStylesheet);
themeStylesheets.remove(previousGluonSwatchStylesheet);
themeStylesheets.remove(previousGluonThemeStylesheet);
contentSubScene.setUserAgentStylesheet(themeStyleSheets.getFirst());
ObservableList<String> currentStyleSheets = FXCollections.observableArrayList(themeStyleSheets);
themeStylesheets.clear();
themeStylesheets.addAll(currentStyleSheets);
contentGroupApplyCss();
}

// Update scenegraph layout, etc
Expand All @@ -216,9 +216,9 @@ public void setPreviewStyleSheets(List<String> previewStyleSheets) {
themeStylesheets.clear();
themeStylesheets.addAll(previewStyleSheets);
if (currentTheme == EditorPlatform.Theme.GLUON_MOBILE_LIGHT || currentTheme == EditorPlatform.Theme.GLUON_MOBILE_DARK) {
themeStylesheets.add(EditorPlatform.Theme.GLUON_MOBILE_LIGHT.getStylesheetURL()); // We can call this with GLUON_MOBILE_LIGHT or GLUON_MOBILE_DARK
themeStylesheets.add(editorController.getGluonSwatch().getStylesheetURL());
themeStylesheets.add(editorController.getGluonTheme().getStylesheetURL());
themeStylesheets.add(EditorPlatform.Theme.GLUON_MOBILE_LIGHT.getStylesheetURLs().getFirst()); // We can call this with GLUON_MOBILE_LIGHT or GLUON_MOBILE_DARK
themeStylesheets.add(editorController.getGluonSwatch().getStylesheetURLs().getFirst());
themeStylesheets.add(editorController.getGluonTheme().getStylesheetURLs().getFirst());
themeStylesheets.add(EditorPlatform.getGluonDocumentStylesheetURL());
}
contentGroupApplyCss();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2022, Gluon and/or its affiliates.
* Copyright (c) 2016, 2024, Gluon and/or its affiliates.
* Copyright (c) 2012, 2014, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
Expand Down Expand Up @@ -273,7 +273,7 @@ public void run() {
// => we must wrap the code into a Runnable object and call the Platform.runLater
Platform.runLater(() -> {
final FXOMDocument fxomDocument = editorController.getFxomDocument();
String themeStyleSheetString = null;
List<String> themeStyleSheetsString = null;
if (fxomDocument != null) {
// We clone the FXOMDocument
FXOMDocument clone;
Expand All @@ -290,7 +290,7 @@ public void run() {
}

Object sceneGraphRoot = clone.getDisplayNodeOrSceneGraphRoot();
themeStyleSheetString = editorControllerTheme.getStylesheetURL();
themeStyleSheetsString = editorControllerTheme.getStylesheetURLs();

if (sceneGraphRoot instanceof Parent) {
((Parent) sceneGraphRoot).setId(NID_PREVIEW_ROOT);
Expand Down Expand Up @@ -341,16 +341,17 @@ public void run() {
}

getScene().setRoot(getRoot());
if (themeStyleSheetString != null) {
if (themeStyleSheetsString != null) {
String gluonDocumentStylesheet = EditorPlatform.getGluonDocumentStylesheetURL();
String gluonSwatchStylesheet = editorControllerGluonSwatch.getStylesheetURL();
String gluonThemeStylesheet = editorControllerGluonTheme.getStylesheetURL();
String gluonSwatchStylesheet = editorControllerGluonSwatch.getStylesheetURLs().getFirst();
String gluonThemeStylesheet = editorControllerGluonTheme.getStylesheetURLs().getFirst();
if (editorControllerTheme == Theme.GLUON_MOBILE_LIGHT || editorControllerTheme == Theme.GLUON_MOBILE_DARK) {
ObservableList<String> newStylesheets = FXCollections.observableArrayList(getScene().getStylesheets());

if (!newStylesheets.contains(themeStyleSheetString)) {
newStylesheets.add(themeStyleSheetString);
}
themeStyleSheetsString.forEach(themeStyleSheetString -> {
if (!newStylesheets.contains(themeStyleSheetString)) {
newStylesheets.add(themeStyleSheetString);
}
});
if (!newStylesheets.contains(gluonDocumentStylesheet)) {
newStylesheets.add(gluonDocumentStylesheet);
}
Expand All @@ -360,16 +361,14 @@ public void run() {
if (!newStylesheets.contains(gluonThemeStylesheet)) {
newStylesheets.add(gluonThemeStylesheet);
}
getScene().setUserAgentStylesheet(Theme.MODENA.getStylesheetURL());
getScene().setUserAgentStylesheet(Theme.MODENA.getStylesheetURLs().getFirst());
getScene().getStylesheets().clear();
getScene().getStylesheets().addAll(newStylesheets);
} else {
String gluonStylesheet = Theme.GLUON_MOBILE_LIGHT.getStylesheetURL();
getScene().setUserAgentStylesheet(themeStyleSheetString);
getScene().getStylesheets().remove(gluonStylesheet);
getScene().getStylesheets().remove(gluonDocumentStylesheet);
getScene().getStylesheets().remove(gluonSwatchStylesheet);
getScene().getStylesheets().remove(gluonThemeStylesheet);
getScene().setUserAgentStylesheet(themeStyleSheetsString.getFirst());
ObservableList<String> newStylesheets = FXCollections.observableArrayList(themeStyleSheetsString);
getScene().getStylesheets().clear();
getScene().getStylesheets().addAll(newStylesheets);
}
}
updateWindowSize();
Expand Down
Loading