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

8301302: Platform preferences API #1014

Closed
wants to merge 62 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
2d28c85
Platform preferences implementation
mstr2 Jul 4, 2023
df03228
documentation
mstr2 Jul 18, 2023
ba26271
Removed platform-independent preference keys
mstr2 Jul 23, 2023
00e9eb7
doc changes
mstr2 Jul 23, 2023
dbad68d
Move Appearance enum to javafx.application
mstr2 Jul 23, 2023
e16491a
removed unused code
mstr2 Jul 24, 2023
2d1c7a9
Ensure that ColorProperty changes are atomic when observed
mstr2 Jul 24, 2023
0589078
doc changes
mstr2 Jul 24, 2023
f8a9c8a
Added test
mstr2 Jul 24, 2023
40e2f28
Removed application preferences implementation
mstr2 Sep 5, 2023
b100c6c
Addressed review comments
mstr2 Sep 5, 2023
4b9f75d
Revert Application changes
mstr2 Sep 5, 2023
27022f3
Added javadoc link to list of platform preferences
mstr2 Sep 5, 2023
02d6a2f
improve javadoc
mstr2 Sep 6, 2023
4172fa6
Update Eclipse .classpath file
mstr2 Sep 6, 2023
5081fda
Suppress empty change message in test application
mstr2 Sep 6, 2023
08a3692
Format arrays in test application
mstr2 Sep 6, 2023
2837e33
Merge branch 'master' into feature/platform-preferences
mstr2 Sep 6, 2023
9cfded0
Fire only a single invalidation event
mstr2 Sep 6, 2023
c8fd0e7
changes per review
mstr2 Sep 6, 2023
1eaea48
change test class name
mstr2 Sep 6, 2023
c736dee
Add signal handler for gtk-theme-name
mstr2 Sep 6, 2023
aae55f9
Remove javadocs
mstr2 Sep 6, 2023
cb81762
Handle key removals
mstr2 Sep 8, 2023
a893fa4
Merge branch 'master' into feature/platform-preferences
mstr2 Oct 29, 2023
8a5b213
changed parameter name
mstr2 Oct 29, 2023
7e826df
Javadoc change
mstr2 Oct 31, 2023
684f48b
formatting
mstr2 Oct 31, 2023
167d4e8
review changes
mstr2 Nov 1, 2023
ad74e39
changend bool comparison
mstr2 Nov 1, 2023
38177a8
review changes
mstr2 Nov 2, 2023
d012dec
removed extra newline
mstr2 Nov 3, 2023
9b607c6
Rename Appearance to ColorScheme
mstr2 Nov 10, 2023
6ec7e99
Doc changes
mstr2 Nov 17, 2023
3cc29e9
Add eager type checking for typed getters
mstr2 Nov 18, 2023
9a817d1
Remove Preferences.getPaint
mstr2 Nov 18, 2023
bb6071c
Replace HashMap with Map.ofEntries
mstr2 Nov 18, 2023
a3d0010
Support polymorphic values
mstr2 Nov 20, 2023
17b2b08
Use JLS 5.5.1 casting conversion rules
mstr2 Nov 24, 2023
9083d3e
flip S and T
mstr2 Nov 24, 2023
9adef99
address review comments
mstr2 Nov 24, 2023
57c8d0c
rename local variables
mstr2 Nov 24, 2023
bee1bae
typo
mstr2 Nov 24, 2023
89f1c8f
initialize field with NULL
mstr2 Nov 29, 2023
9cc3b4b
initialize field with NULL
mstr2 Nov 30, 2023
dbf24bf
check for pending exceptions in macOS PlatformSupport
mstr2 Dec 1, 2023
0572a36
check for pending exceptions in GTK PlatformSupport
mstr2 Dec 2, 2023
f291ea4
check for pending exceptions in Windows PlatformSupport
mstr2 Dec 2, 2023
a04a8c6
check for null return values of JNI methods
mstr2 Dec 4, 2023
0dff7a4
check return value of JNI functions
mstr2 Dec 4, 2023
6c37544
rename GLASS_CHECK_EXCEPTIONALLY_RETURN
mstr2 Dec 6, 2023
db393fc
null checking
mstr2 Dec 6, 2023
0759ddd
changed error condition check
mstr2 Dec 6, 2023
a2bd32d
consistently use NULL
mstr2 Dec 6, 2023
070eab5
swap message fields
mstr2 Dec 6, 2023
515395b
fixed bug in test application
mstr2 Dec 6, 2023
098ca17
fixed HighContrastScheme
mstr2 Dec 7, 2023
eac1d82
format arrays in test application, indicate added/removed prefs
mstr2 Dec 7, 2023
efdab27
renamed Windows.SPI.HighContrastOn to Windows.SPI.HighContrast
mstr2 Dec 7, 2023
20cccc5
query resource bundles for high-contrast schemes only on Windows
mstr2 Dec 7, 2023
6457503
javadoc
mstr2 Dec 7, 2023
3354782
removed unused import
mstr2 Dec 7, 2023
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
2 changes: 1 addition & 1 deletion modules/javafx.graphics/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<classpathentry combineaccessrules="false" kind="src" path="/base">
<attributes>
<attribute name="module" value="true"/>
<attribute name="add-exports" value="javafx.base/com.sun.javafx.property=javafx.graphics:javafx.base/test.util.memory=javafx.graphics"/>
<attribute name="add-exports" value="javafx.base/com.sun.javafx.property=javafx.graphics:javafx.base/test.javafx.collections=javafx.graphics:javafx.base/test.util.memory=javafx.graphics"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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
Expand Down Expand Up @@ -84,8 +84,7 @@ public void handleOpenFilesAction(Application app, long time, String files[]) {
// currently used only on Mac OS X
public void handleQuitAction(Application app, long time) {
}
public boolean handleThemeChanged(String themeName) {
return false;
public void handlePreferencesChanged(Map<String, Object> preferences) {
}
}

Expand Down Expand Up @@ -259,12 +258,11 @@ protected void notifyWillResignActive() {
}
}

protected boolean notifyThemeChanged(String themeName) {
protected void notifyPreferencesChanged(Map<String, Object> preferences) {
EventHandler handler = getEventHandler();
if (handler != null) {
return handler.handleThemeChanged(themeName);
handler.handlePreferencesChanged(preferences);
}
return false;
}

protected void notifyDidResignActive() {
Expand Down Expand Up @@ -675,19 +673,6 @@ protected abstract FileChooserResult staticCommonDialogs_showFileChooser(Window
protected abstract int staticView_getMultiClickMaxX();
protected abstract int staticView_getMultiClickMaxY();

public String getHighContrastScheme(String themeName) {
return themeName;
}

/**
* Gets the Name of the currently active high contrast theme.
* If null, then high contrast is not enabled.
*/
public String getHighContrastTheme() {
checkEventThread();
return null;
}

protected boolean _supportsInputMethods() {
// Overridden in subclasses
return false;
Expand Down Expand Up @@ -768,4 +753,51 @@ public final Optional<Boolean> isKeyLocked(int keyCode) {
return Optional.empty();
}
}

/**
* Returns the current set of platform properties as a map of platform-specific keys to
* arbitrary values. This is a snapshot, and won't be updated. There are no guarantees on
* the implementation type, modifiability or serializability of the returned {@code Map}.
*
* @return the current set of platform preferences
*/
public Map<String, Object> getPlatformPreferences() {
return Map.of();
}

/**
* Returns a map of platform-specific keys to platform-independent keys defined by JavaFX.
* <p>
* For example, the platform-specific key "Windows.UIColor.Foreground" is mapped to the key "foregroundColor",
* which makes it easier to write shared code without depending on platform-specific details.
* <p>
* The following platform-independent keys are currently supported, which correspond to the names of color
* properties on the {@link com.sun.javafx.application.preferences.PreferenceProperties} class:
* <ul>
* <li>foregroundColor
* <li>backgroundColor
* <li>accentColor
* </ul>
*
* @return a map of platform-specific keys to well-known keys
*/
public Map<String, String> getPlatformKeyMappings() {
return Map.of();
}

/**
* Returns a mapping of platform-specific keys to the types of their values.
* Polymorphic types are supported by specifying the common base type; for example, a key can
* be mapped to {@code Paint.class} to support any type of paint.
* <p>
* Implementors must keep this map in sync with the mappings reported by the native Glass toolkit.
* If a native toolkit reports mappings for keys that are not contained in this map, the typed getters
* in {@link javafx.application.Platform.Preferences} might not throw {@code IllegalArgumentException}
* as specified.
*
* @return a map of platform-specific keys to types
*/
public Map<String, Class<?>> getPlatformKeys() {
return Map.of();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.sun.glass.utils.NativeLibLoader;
import com.sun.prism.impl.PrismSettings;
import com.sun.javafx.logging.PlatformLogger;
import javafx.scene.paint.Color;

import java.io.File;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -467,4 +468,40 @@ protected boolean _supportsInputMethods() {
@Override
protected native int _isKeyLocked(int keyCode);

@Override
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, String> getPlatformKeyMappings() {
return Map.of(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should be returned from a private static final

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. This is an overridden method, do you propose to introduce another private static final method, and getPlatformKeyMappings then calls out to this other method?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that it is a constant, which I think would be good to extract. I think you may have mentioned it isn't called a whole lot, but recreating an immutable sometimes (large) map just seems unnecessary.

    private static final Map<String, String> MAPPINGS = Map.of(
        "GTK.theme_fg_color", "foregroundColor",
        "GTK.theme_bg_color", "backgroundColor"
    );

    @Override
    public Map<String, String> getPlatformKeyMappings() {
        return MAPPINGS;
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only called once to initialize PlatformPreferences, so we should be fine.

"GTK.theme_fg_color", "foregroundColor",
"GTK.theme_bg_color", "backgroundColor"
);
}

// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for GTK.
@Override
public Map<String, Class<?>> getPlatformKeys() {
return Map.ofEntries(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this should be returned from a private static final

Same for the other two MacApplication, WinApplication.

Map.entry("GTK.theme_name", String.class),
Map.entry("GTK.theme_fg_color", Color.class),
Map.entry("GTK.theme_bg_color", Color.class),
Map.entry("GTK.theme_base_color", Color.class),
Map.entry("GTK.theme_selected_bg_color", Color.class),
Map.entry("GTK.theme_selected_fg_color", Color.class),
Map.entry("GTK.theme_unfocused_fg_color", Color.class),
Map.entry("GTK.theme_unfocused_bg_color", Color.class),
Map.entry("GTK.theme_unfocused_base_color", Color.class),
Map.entry("GTK.theme_unfocused_selected_bg_color", Color.class),
Map.entry("GTK.theme_unfocused_selected_fg_color", Color.class),
Map.entry("GTK.insensitive_bg_color", Color.class),
Map.entry("GTK.insensitive_fg_color", Color.class),
Map.entry("GTK.insensitive_base_color", Color.class),
Map.entry("GTK.borders", Color.class),
Map.entry("GTK.unfocused_borders", Color.class),
Map.entry("GTK.warning_color", Color.class),
Map.entry("GTK.error_color", Color.class),
Map.entry("GTK.success_color", Color.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.util.Logging;
import javafx.scene.paint.Color;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -388,4 +390,69 @@ public String getDataDirectory() {

@Override
protected native int _isKeyLocked(int keyCode);

@Override
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, String> getPlatformKeyMappings() {
return Map.of(
"macOS.NSColor.textColor", "foregroundColor",
"macOS.NSColor.textBackgroundColor", "backgroundColor",
"macOS.NSColor.controlAccentColor", "accentColor"
);
}

// This list needs to be kept in sync with PlatformSupport.m in the Glass toolkit for macOS.
@Override
public Map<String, Class<?>> getPlatformKeys() {
return Map.ofEntries(
Map.entry("macOS.NSColor.labelColor", Color.class),
Map.entry("macOS.NSColor.secondaryLabelColor", Color.class),
Map.entry("macOS.NSColor.tertiaryLabelColor", Color.class),
Map.entry("macOS.NSColor.quaternaryLabelColor", Color.class),
Map.entry("macOS.NSColor.textColor", Color.class),
Map.entry("macOS.NSColor.placeholderTextColor", Color.class),
Map.entry("macOS.NSColor.selectedTextColor", Color.class),
Map.entry("macOS.NSColor.textBackgroundColor", Color.class),
Map.entry("macOS.NSColor.selectedTextBackgroundColor", Color.class),
Map.entry("macOS.NSColor.keyboardFocusIndicatorColor", Color.class),
Map.entry("macOS.NSColor.unemphasizedSelectedTextColor", Color.class),
Map.entry("macOS.NSColor.unemphasizedSelectedTextBackgroundColor", Color.class),
Map.entry("macOS.NSColor.linkColor", Color.class),
Map.entry("macOS.NSColor.separatorColor", Color.class),
Map.entry("macOS.NSColor.selectedContentBackgroundColor", Color.class),
Map.entry("macOS.NSColor.unemphasizedSelectedContentBackgroundColor", Color.class),
Map.entry("macOS.NSColor.selectedMenuItemTextColor", Color.class),
Map.entry("macOS.NSColor.gridColor", Color.class),
Map.entry("macOS.NSColor.headerTextColor", Color.class),
Map.entry("macOS.NSColor.alternatingContentBackgroundColors", Color[].class),
Map.entry("macOS.NSColor.controlAccentColor", Color.class),
Map.entry("macOS.NSColor.controlColor", Color.class),
Map.entry("macOS.NSColor.controlBackgroundColor", Color.class),
Map.entry("macOS.NSColor.controlTextColor", Color.class),
Map.entry("macOS.NSColor.disabledControlTextColor", Color.class),
Map.entry("macOS.NSColor.selectedControlColor", Color.class),
Map.entry("macOS.NSColor.selectedControlTextColor", Color.class),
Map.entry("macOS.NSColor.alternateSelectedControlTextColor", Color.class),
Map.entry("macOS.NSColor.currentControlTint", String.class),
Map.entry("macOS.NSColor.windowBackgroundColor", Color.class),
Map.entry("macOS.NSColor.windowFrameTextColor", Color.class),
Map.entry("macOS.NSColor.underPageBackgroundColor", Color.class),
Map.entry("macOS.NSColor.findHighlightColor", Color.class),
Map.entry("macOS.NSColor.highlightColor", Color.class),
Map.entry("macOS.NSColor.shadowColor", Color.class),
Map.entry("macOS.NSColor.systemBlueColor", Color.class),
Map.entry("macOS.NSColor.systemBrownColor", Color.class),
Map.entry("macOS.NSColor.systemGrayColor", Color.class),
Map.entry("macOS.NSColor.systemGreenColor", Color.class),
Map.entry("macOS.NSColor.systemIndigoColor", Color.class),
Map.entry("macOS.NSColor.systemOrangeColor", Color.class),
Map.entry("macOS.NSColor.systemPinkColor", Color.class),
Map.entry("macOS.NSColor.systemPurpleColor", Color.class),
Map.entry("macOS.NSColor.systemRedColor", Color.class),
Map.entry("macOS.NSColor.systemTealColor", Color.class),
Map.entry("macOS.NSColor.systemYellowColor", Color.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@
import com.sun.glass.ui.*;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.PlatformImpl;
import com.sun.prism.impl.PrismSettings;
import com.sun.javafx.tk.Toolkit;
import javafx.scene.paint.Color;

import java.io.File;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ResourceBundle;
import java.util.Map;

final class WinApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {

static float overrideUIScale;
private static final String BASE_NAME = "com/sun/glass/ui/win/themes";

private static boolean getBoolean(String propname, boolean defval, String description) {
String str = System.getProperty(propname);
Expand Down Expand Up @@ -341,17 +340,6 @@ public Pixels createPixels(int width, int height, IntBuffer data, float scalex,
}
}

@Override
public String getHighContrastScheme(String themeName) {
return PlatformImpl.HighContrastScheme.fromThemeName(ResourceBundle.getBundle(BASE_NAME)::getString, themeName);
}

private native String _getHighContrastTheme();
@Override public String getHighContrastTheme() {
checkEventThread();
return getHighContrastScheme(_getHighContrastTheme());
}

@Override
protected boolean _supportsInputMethods() {
return true;
Expand Down Expand Up @@ -380,4 +368,42 @@ public String getDataDirectory() {

@Override
protected native int _isKeyLocked(int keyCode);

@Override
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, String> getPlatformKeyMappings() {
return Map.of(
"Windows.UIColor.ForegroundColor", "foregroundColor",
"Windows.UIColor.BackgroundColor", "backgroundColor",
"Windows.UIColor.AccentColor", "accentColor"
);
}

// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for Windows.
@Override
public Map<String, Class<?>> getPlatformKeys() {
return Map.ofEntries(
Map.entry("Windows.SPI.HighContrast", Boolean.class),
Map.entry("Windows.SPI.HighContrastColorScheme", String.class),
Map.entry("Windows.SysColor.COLOR_3DFACE", Color.class),
Map.entry("Windows.SysColor.COLOR_BTNTEXT", Color.class),
Map.entry("Windows.SysColor.COLOR_GRAYTEXT", Color.class),
Map.entry("Windows.SysColor.COLOR_HIGHLIGHT", Color.class),
Map.entry("Windows.SysColor.COLOR_HIGHLIGHTTEXT", Color.class),
Map.entry("Windows.SysColor.COLOR_HOTLIGHT", Color.class),
Map.entry("Windows.SysColor.COLOR_WINDOW", Color.class),
Map.entry("Windows.SysColor.COLOR_WINDOWTEXT", Color.class),
Map.entry("Windows.UIColor.Background", Color.class),
Map.entry("Windows.UIColor.Foreground", Color.class),
Map.entry("Windows.UIColor.AccentDark3", Color.class),
Map.entry("Windows.UIColor.AccentDark2", Color.class),
Map.entry("Windows.UIColor.AccentDark1", Color.class),
Map.entry("Windows.UIColor.Accent", Color.class),
Map.entry("Windows.UIColor.AccentLight1", Color.class),
Map.entry("Windows.UIColor.AccentLight2", Color.class),
Map.entry("Windows.UIColor.AccentLight3", Color.class)
);
}
}
Loading