-
Notifications
You must be signed in to change notification settings - Fork 504
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
8301302: Platform preferences API #1014
Changes from 2 commits
2d28c85
df03228
ba26271
00e9eb7
dbad68d
e16491a
2d1c7a9
0589078
f8a9c8a
40e2f28
b100c6c
4b9f75d
27022f3
02d6a2f
4172fa6
5081fda
08a3692
2837e33
9cfded0
c8fd0e7
1eaea48
c736dee
aae55f9
cb81762
a893fa4
8a5b213
7e826df
684f48b
167d4e8
ad74e39
38177a8
d012dec
9b607c6
6ec7e99
3cc29e9
9a817d1
bb6071c
a3d0010
17b2b08
9083d3e
9adef99
57c8d0c
bee1bae
89f1c8f
9cc3b4b
dbf24bf
0572a36
f291ea4
a04a8c6
0dff7a4
6c37544
db393fc
0759ddd
a2bd32d
070eab5
515395b
098ca17
eac1d82
efdab27
20cccc5
6457503
3354782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code 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 General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
package com.sun.javafx.application; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.ResourceBundle; | ||
|
||
/** | ||
* Enumeration of possible high contrast scheme values. | ||
* <p> | ||
* For each scheme, a theme key is defined. These keys can be | ||
* used in a resource bundle that defines the theme name values | ||
* for supported locales. | ||
* <p> | ||
* The high contrast feature may not be available on all platforms. | ||
*/ | ||
enum WindowsHighContrastScheme { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather keep the old name: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it never applied to all platforms, it reflects exactly the Windows implementation of high-contrast schemes. It will be moved once we add style themes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
||
HIGH_CONTRAST_BLACK("high.contrast.black.theme"), | ||
HIGH_CONTRAST_WHITE("high.contrast.white.theme"), | ||
HIGH_CONTRAST_1("high.contrast.1.theme"), | ||
HIGH_CONTRAST_2("high.contrast.2.theme"); | ||
|
||
private static final List<ResourceBundle> resourceBundles = Arrays.stream(Locale.getAvailableLocales()) | ||
.map(locale -> ResourceBundle.getBundle("com/sun/glass/ui/win/themes", locale)) | ||
.distinct() | ||
.toList(); | ||
|
||
private final String themeKey; | ||
|
||
WindowsHighContrastScheme(String themeKey) { | ||
this.themeKey = themeKey; | ||
} | ||
|
||
public String getThemeKey() { | ||
return themeKey; | ||
} | ||
|
||
/** | ||
* Given a theme name string, this method finds the possible enum constant | ||
* for which the result of a function, applying its theme key, matches the theme name. | ||
* | ||
* @param themeName a string with the localized theme name (for the locale of the OS, not the JVM) | ||
* @return the enum constant or null if not found | ||
*/ | ||
public static WindowsHighContrastScheme fromThemeName(String themeName) { | ||
if (themeName == null) { | ||
return null; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is called only from Is this method expected to be called from other places as well? If not, the method can be made package visible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method now returns |
||
|
||
// Iterate over all resource bundles and try to find a value that matches the theme name | ||
// we got from the OS. We can't just look in the properties file for the current locale, | ||
// since we might be running on a JVM with a locale that is different from the OS. | ||
for (WindowsHighContrastScheme item : values()) { | ||
for (ResourceBundle resourceBundle : resourceBundles) { | ||
Comment on lines
+83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on how often this is called, might it be worth caching a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class will probably change a bit and be moved around if and when we add style themes, so I think we can revisit it then. |
||
if (themeName.equalsIgnoreCase(resourceBundle.getString(item.getThemeKey()))) { | ||
return item; | ||
} | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: You could eliminate the null check if you defined a new "NONE" or "UNKNOWN" enum and restored the (no-op)
default:
on line 837. It's fine the way you have it, if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a
NONE
constant.