Skip to content

Commit 80fa8de

Browse files
committed
StyleTheme implementation
1 parent 7f17447 commit 80fa8de

40 files changed

+3090
-375
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/Control.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ public StringProperty skinClassNameProperty(Control control) {
9494
}
9595
});
9696

97-
// Ensures that the default application user agent stylesheet is loaded
98-
if (Application.getUserAgentStylesheet() == null) {
99-
PlatformImpl.setDefaultPlatformUserAgentStylesheet();
100-
}
97+
// Ensures that the default theme is loaded
98+
PlatformImpl.ensureDefaultTheme();
10199
}
102100

103101
/**

modules/javafx.controls/src/main/java/javafx/scene/control/PopupControl.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ public class PopupControl extends PopupWindow implements Skinnable, Styleable {
8585
public static final double USE_COMPUTED_SIZE = -1;
8686

8787
static {
88-
// Ensures that the default application user agent stylesheet is loaded
89-
if (Application.getUserAgentStylesheet() == null) {
90-
PlatformImpl.setDefaultPlatformUserAgentStylesheet();
91-
}
88+
// Ensures that the default theme is loaded
89+
PlatformImpl.ensureDefaultTheme();
9290
}
9391

9492
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package javafx.scene.control.theme;
27+
28+
import com.sun.javafx.PlatformUtil;
29+
import com.sun.javafx.application.PlatformImpl;
30+
import javafx.application.ConditionalFeature;
31+
import javafx.application.PlatformPreferences;
32+
import javafx.beans.value.WritableValue;
33+
import java.util.Map;
34+
35+
/**
36+
* {@code Caspian} is a built-in JavaFX theme.
37+
*
38+
* @since 20
39+
*/
40+
public class CaspianTheme extends ThemeBase {
41+
42+
private final WritableValue<String> highContrastStylesheet;
43+
44+
/**
45+
* Creates a new instance of the {@code CaspianTheme} class.
46+
*/
47+
public CaspianTheme() {
48+
addLast("com/sun/javafx/scene/control/skin/caspian/caspian.css");
49+
50+
if (PlatformImpl.isSupported(ConditionalFeature.INPUT_TOUCH)) {
51+
addLast("com/sun/javafx/scene/control/skin/caspian/embedded.css");
52+
53+
if (com.sun.javafx.util.Utils.isQVGAScreen()) {
54+
addLast("com/sun/javafx/scene/control/skin/caspian/embedded-qvga.css");
55+
}
56+
57+
if (PlatformUtil.isAndroid()) {
58+
addLast("com/sun/javafx/scene/control/skin/caspian/android.css");
59+
}
60+
61+
if (PlatformUtil.isIOS()) {
62+
addLast("com/sun/javafx/scene/control/skin/caspian/ios.css");
63+
}
64+
}
65+
66+
if (PlatformImpl.isSupported(ConditionalFeature.TWO_LEVEL_FOCUS)) {
67+
addLast("com/sun/javafx/scene/control/skin/caspian/two-level-focus.css");
68+
}
69+
70+
if (PlatformImpl.isSupported(ConditionalFeature.VIRTUAL_KEYBOARD)) {
71+
addLast("com/sun/javafx/scene/control/skin/caspian/fxvk.css");
72+
}
73+
74+
if (!PlatformImpl.isSupported(ConditionalFeature.TRANSPARENT_WINDOW)) {
75+
addLast("com/sun/javafx/scene/control/skin/caspian/caspian-no-transparency.css");
76+
}
77+
78+
highContrastStylesheet = addLast(null);
79+
updateHighContrastTheme();
80+
}
81+
82+
@Override
83+
protected void onPreferencesChanged(Map<String, Object> preferences) {
84+
updateHighContrastTheme();
85+
}
86+
87+
private void updateHighContrastTheme() {
88+
boolean enabled = false;
89+
String overrideThemeName = System.getProperty("com.sun.javafx.highContrastTheme");
90+
if (overrideThemeName != null) {
91+
enabled = true;
92+
}
93+
94+
if (!enabled) {
95+
PlatformPreferences preferences = PlatformImpl.getPlatformPreferences();
96+
if (preferences.getBoolean("Windows.SPI.HighContrastOn", false)) {
97+
enabled = preferences.getString("Windows.SPI.HighContrastColorScheme") != null;
98+
}
99+
}
100+
101+
if (enabled) {
102+
// caspian has only one high contrast theme, use it regardless of the user or platform theme.
103+
highContrastStylesheet.setValue("com/sun/javafx/scene/control/skin/caspian/highcontrast.css");
104+
} else {
105+
highContrastStylesheet.setValue(null);
106+
}
107+
}
108+
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package javafx.scene.control.theme;
27+
28+
import com.sun.javafx.PlatformUtil;
29+
import com.sun.javafx.application.HighContrastScheme;
30+
import com.sun.javafx.application.PlatformImpl;
31+
import javafx.application.ConditionalFeature;
32+
import javafx.application.PlatformPreferences;
33+
import javafx.beans.value.WritableValue;
34+
import java.util.Map;
35+
import java.util.ResourceBundle;
36+
37+
/**
38+
* {@code Modena} is a built-in JavaFX theme.
39+
*
40+
* @since 20
41+
*/
42+
public class ModenaTheme extends ThemeBase {
43+
44+
private final WritableValue<String> highContrastStylesheet;
45+
46+
/**
47+
* Creates a new instance of the {@code ModenaTheme} class.
48+
*/
49+
public ModenaTheme() {
50+
addLast("com/sun/javafx/scene/control/skin/modena/modena.css");
51+
52+
if (PlatformImpl.isSupported(ConditionalFeature.INPUT_TOUCH)) {
53+
addLast("com/sun/javafx/scene/control/skin/modena/touch.css");
54+
}
55+
56+
if (PlatformUtil.isEmbedded()) {
57+
addLast("com/sun/javafx/scene/control/skin/modena/modena-embedded-performance.css");
58+
}
59+
60+
if (PlatformUtil.isAndroid()) {
61+
addLast("com/sun/javafx/scene/control/skin/modena/android.css");
62+
}
63+
64+
if (PlatformUtil.isIOS()) {
65+
addLast("com/sun/javafx/scene/control/skin/modena/ios.css");
66+
}
67+
68+
if (PlatformImpl.isSupported(ConditionalFeature.TWO_LEVEL_FOCUS)) {
69+
addLast("com/sun/javafx/scene/control/skin/modena/two-level-focus.css");
70+
}
71+
72+
if (PlatformImpl.isSupported(ConditionalFeature.VIRTUAL_KEYBOARD)) {
73+
addLast("com/sun/javafx/scene/control/skin/caspian/fxvk.css");
74+
}
75+
76+
if (!PlatformImpl.isSupported(ConditionalFeature.TRANSPARENT_WINDOW)) {
77+
addLast("com/sun/javafx/scene/control/skin/modena/modena-no-transparency.css");
78+
}
79+
80+
highContrastStylesheet = addLast(null);
81+
updateHighContrastTheme();
82+
}
83+
84+
@Override
85+
protected void onPreferencesChanged(Map<String, Object> preferences) {
86+
updateHighContrastTheme();
87+
}
88+
89+
private void updateHighContrastTheme() {
90+
String themeName = null;
91+
String overrideThemeName = System.getProperty("com.sun.javafx.highContrastTheme");
92+
if (overrideThemeName != null) {
93+
themeName = overrideThemeName;
94+
}
95+
96+
if (themeName == null) {
97+
PlatformPreferences preferences = PlatformImpl.getPlatformPreferences();
98+
if (preferences.getBoolean("Windows.SPI.HighContrastOn", false)) {
99+
themeName = preferences.getString("Windows.SPI.HighContrastColorScheme");
100+
}
101+
}
102+
103+
if (themeName != null) {
104+
String stylesheet = switch (themeName.toUpperCase()) {
105+
case "BLACKONWHITE" -> "com/sun/javafx/scene/control/skin/modena/blackOnWhite.css";
106+
case "WHITEONBLACK" -> "com/sun/javafx/scene/control/skin/modena/whiteOnBlack.css";
107+
case "YELLOWONBLACK" -> "com/sun/javafx/scene/control/skin/modena/yellowOnBlack.css";
108+
default -> null;
109+
};
110+
111+
if (stylesheet == null) {
112+
ResourceBundle bundle = ResourceBundle.getBundle("com/sun/glass/ui/win/themes");
113+
String enumValue = HighContrastScheme.fromThemeName(bundle::getString, themeName);
114+
115+
stylesheet = enumValue != null ? switch (HighContrastScheme.valueOf(enumValue)) {
116+
case HIGH_CONTRAST_WHITE -> "com/sun/javafx/scene/control/skin/modena/blackOnWhite.css";
117+
case HIGH_CONTRAST_BLACK -> "com/sun/javafx/scene/control/skin/modena/whiteOnBlack.css";
118+
case HIGH_CONTRAST_1, HIGH_CONTRAST_2 -> "com/sun/javafx/scene/control/skin/modena/yellowOnBlack.css";
119+
} : null;
120+
}
121+
122+
highContrastStylesheet.setValue(stylesheet);
123+
} else {
124+
highContrastStylesheet.setValue(null);
125+
}
126+
}
127+
128+
}

0 commit comments

Comments
 (0)