Skip to content

Commit 8cb8648

Browse files
authored
fix: Remove platform theme url from stylesheets, (#761)
* Remove platform theme url from stylesheets, to prevent user agent from being overwritten * fix typo * Fix preview
1 parent 91f6846 commit 8cb8648

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/EditorPlatform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ public static Theme valueOf(String themeName) {
159159
// no-op
160160
}
161161

162+
public static boolean isPlatformThemeStylesheetURL(String stylesheetURL) {
163+
// Return USER_AGENT css, which is Modena for fx 8.0
164+
return stylesheetURL != null && stylesheetURL.equals(Theme.MODENA.getStylesheetURLs().getFirst());
165+
}
166+
162167
public static String getPlatformThemeStylesheetURL() {
163168
// Return USER_AGENT css, which is Modena for fx 8.0
164169
return Theme.MODENA.getStylesheetURLs().getFirst();

kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/ContentPanelController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ private void themeDidChange() {
10751075
final EditorPlatform.Theme theme = getEditorController().getTheme();
10761076
List<String> themeStylesheets = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(theme));
10771077
themeStylesheets.addAll(theme.getStylesheetURLs());
1078-
workspaceController.setThemeStyleSheet(themeStylesheets, theme);
1078+
workspaceController.setThemeStylesheet(themeStylesheets, theme);
10791079
}
10801080
}
10811081

kit/src/main/java/com/oracle/javafx/scenebuilder/kit/editor/panel/content/WorkspaceController.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,18 @@ public List<String> getThemeStyleSheets() {
163163
return Collections.unmodifiableList(themeStylesheets);
164164
}
165165

166-
public void setThemeStyleSheet(List<String> themeStyleSheets, EditorPlatform.Theme theme) {
167-
assert themeStyleSheets != null;
166+
public void setThemeStylesheet(List<String> themeStylesheets, EditorPlatform.Theme theme) {
167+
assert themeStylesheets != null;
168168
assert theme != null;
169169
List<String> stylesheets = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(theme));
170-
stylesheets.addAll(themeStyleSheets);
171-
contentSubScene.setUserAgentStylesheet(stylesheets.getFirst());
170+
themeStylesheets.stream()
171+
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
172+
.forEach(stylesheets::add);
173+
contentSubScene.setUserAgentStylesheet(stylesheets.stream().findFirst().orElse(null));
172174

173-
ObservableList<String> currentStyleSheets = FXCollections.observableArrayList(stylesheets);
174-
themeStylesheets.clear();
175-
themeStylesheets.addAll(currentStyleSheets);
175+
ObservableList<String> currentStylesheets = FXCollections.observableArrayList(stylesheets);
176+
this.themeStylesheets.clear();
177+
this.themeStylesheets.addAll(currentStylesheets);
176178
contentGroupApplyCss();
177179

178180
// Update scenegraph layout, etc

kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ public void run() {
271271

272272
Object sceneGraphRoot = clone.getDisplayNodeOrSceneGraphRoot();
273273
themeStyleSheetsList = new ArrayList<>(EditorPlatform.getStylesheetsForTheme(editorController.getTheme()));
274-
themeStyleSheetsList.addAll(editorControllerTheme.getStylesheetURLs());
274+
editorControllerTheme.getStylesheetURLs().stream()
275+
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
276+
.forEach(themeStyleSheetsList::add);
275277

276278
if (sceneGraphRoot instanceof Parent) {
277279
((Parent) sceneGraphRoot).setId(NID_PREVIEW_ROOT);

kit/src/main/java/com/oracle/javafx/scenebuilder/kit/util/CssInternal.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.TreeMap;
4747
import java.util.TreeSet;
4848

49+
import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform;
4950
import javafx.beans.property.ReadOnlyProperty;
5051
import javafx.collections.FXCollections;
5152
import javafx.css.CssMetaData;
@@ -151,10 +152,12 @@ public static boolean isThemeClass(Theme theme, String styleClass) {
151152

152153
public static List<String> getThemeStyleClasses(Theme theme) {
153154
Set<String> themeClasses = new HashSet<>();
154-
theme.getStylesheetURLs().forEach(themeStyleSheet -> {
155-
URL resource = Button.class.getResource("/" + themeStyleSheet);
156-
themeClasses.addAll(getStyleClasses(resource));
157-
});
155+
theme.getStylesheetURLs().stream()
156+
.filter(s -> !EditorPlatform.isPlatformThemeStylesheetURL(s))
157+
.forEach(themeStyleSheet -> {
158+
URL resource = Button.class.getResource("/" + themeStyleSheet);
159+
themeClasses.addAll(getStyleClasses(resource));
160+
});
158161
return new ArrayList<>(themeClasses);
159162
}
160163

0 commit comments

Comments
 (0)