Use transparent background for code viewer (WebView)

JavaFX 18 feature
This commit is contained in:
mkpaz 2023-02-09 13:29:04 +04:00
parent c707ec5230
commit 90b5ded91f

@ -6,6 +6,7 @@ import atlantafx.sampler.theme.HighlightJSTheme;
import atlantafx.sampler.util.Containers; import atlantafx.sampler.util.Containers;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.scene.web.WebView; import javafx.scene.web.WebView;
import java.io.IOException; import java.io.IOException;
@ -52,10 +53,7 @@ public class CodeViewer extends AnchorPane {
.append("<script>").append(new String(hljsLineNum.readAllBytes(), UTF_8)).append("</script>") .append("<script>").append(new String(hljsLineNum.readAllBytes(), UTF_8)).append("</script>")
.append("<script>" + HLJS_SCRIPT + "</script>") .append("<script>" + HLJS_SCRIPT + "</script>")
.append("</head>") .append("</head>")
// Transparent background is allowed starting from OpenJFX 18. .append("<body>")
// https://bugs.openjdk.org/browse/JDK-8090547
// Until that it should match Highlight JS background.
.append(String.format("<body style=\"background-color:%s;\">", theme.getBackground()))
.append("<pre>") .append("<pre>")
.append("<code class=\"language-java\">") .append("<code class=\"language-java\">")
.append(new String(source.readAllBytes(), UTF_8)) .append(new String(source.readAllBytes(), UTF_8))
@ -65,6 +63,7 @@ public class CodeViewer extends AnchorPane {
.append("</html>") .append("</html>")
.toString(); .toString();
webView.setPageFill(Color.TRANSPARENT);
webView.getEngine().loadContent(content); webView.getEngine().loadContent(content);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);