Skip to content

Commit 170a4c1

Browse files
author
Michael Strauß
committed
8301302: Platform preferences API
Reviewed-by: kcr, angorya, jpereda
1 parent 2108ecf commit 170a4c1

35 files changed

+3324
-145
lines changed

modules/javafx.graphics/.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<classpathentry combineaccessrules="false" kind="src" path="/base">
3131
<attributes>
3232
<attribute name="module" value="true"/>
33-
<attribute name="add-exports" value="javafx.base/com.sun.javafx.property=javafx.graphics:javafx.base/test.util.memory=javafx.graphics"/>
33+
<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"/>
3434
</attributes>
3535
</classpathentry>
3636
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">

modules/javafx.graphics/src/main/java/com/sun/glass/ui/Application.java

+51-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -84,8 +84,7 @@ public void handleOpenFilesAction(Application app, long time, String files[]) {
8484
// currently used only on Mac OS X
8585
public void handleQuitAction(Application app, long time) {
8686
}
87-
public boolean handleThemeChanged(String themeName) {
88-
return false;
87+
public void handlePreferencesChanged(Map<String, Object> preferences) {
8988
}
9089
}
9190

@@ -259,12 +258,11 @@ protected void notifyWillResignActive() {
259258
}
260259
}
261260

262-
protected boolean notifyThemeChanged(String themeName) {
261+
protected void notifyPreferencesChanged(Map<String, Object> preferences) {
263262
EventHandler handler = getEventHandler();
264263
if (handler != null) {
265-
return handler.handleThemeChanged(themeName);
264+
handler.handlePreferencesChanged(preferences);
266265
}
267-
return false;
268266
}
269267

270268
protected void notifyDidResignActive() {
@@ -675,19 +673,6 @@ protected abstract FileChooserResult staticCommonDialogs_showFileChooser(Window
675673
protected abstract int staticView_getMultiClickMaxX();
676674
protected abstract int staticView_getMultiClickMaxY();
677675

678-
public String getHighContrastScheme(String themeName) {
679-
return themeName;
680-
}
681-
682-
/**
683-
* Gets the Name of the currently active high contrast theme.
684-
* If null, then high contrast is not enabled.
685-
*/
686-
public String getHighContrastTheme() {
687-
checkEventThread();
688-
return null;
689-
}
690-
691676
protected boolean _supportsInputMethods() {
692677
// Overridden in subclasses
693678
return false;
@@ -768,4 +753,51 @@ public final Optional<Boolean> isKeyLocked(int keyCode) {
768753
return Optional.empty();
769754
}
770755
}
756+
757+
/**
758+
* Returns the current set of platform properties as a map of platform-specific keys to
759+
* arbitrary values. This is a snapshot, and won't be updated. There are no guarantees on
760+
* the implementation type, modifiability or serializability of the returned {@code Map}.
761+
*
762+
* @return the current set of platform preferences
763+
*/
764+
public Map<String, Object> getPlatformPreferences() {
765+
return Map.of();
766+
}
767+
768+
/**
769+
* Returns a map of platform-specific keys to platform-independent keys defined by JavaFX.
770+
* <p>
771+
* For example, the platform-specific key "Windows.UIColor.Foreground" is mapped to the key "foregroundColor",
772+
* which makes it easier to write shared code without depending on platform-specific details.
773+
* <p>
774+
* The following platform-independent keys are currently supported, which correspond to the names of color
775+
* properties on the {@link com.sun.javafx.application.preferences.PreferenceProperties} class:
776+
* <ul>
777+
* <li>foregroundColor
778+
* <li>backgroundColor
779+
* <li>accentColor
780+
* </ul>
781+
*
782+
* @return a map of platform-specific keys to well-known keys
783+
*/
784+
public Map<String, String> getPlatformKeyMappings() {
785+
return Map.of();
786+
}
787+
788+
/**
789+
* Returns a mapping of platform-specific keys to the types of their values.
790+
* Polymorphic types are supported by specifying the common base type; for example, a key can
791+
* be mapped to {@code Paint.class} to support any type of paint.
792+
* <p>
793+
* Implementors must keep this map in sync with the mappings reported by the native Glass toolkit.
794+
* If a native toolkit reports mappings for keys that are not contained in this map, the typed getters
795+
* in {@link javafx.application.Platform.Preferences} might not throw {@code IllegalArgumentException}
796+
* as specified.
797+
*
798+
* @return a map of platform-specific keys to types
799+
*/
800+
public Map<String, Class<?>> getPlatformKeys() {
801+
return Map.of();
802+
}
771803
}

modules/javafx.graphics/src/main/java/com/sun/glass/ui/gtk/GtkApplication.java

+37
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.sun.glass.utils.NativeLibLoader;
4141
import com.sun.prism.impl.PrismSettings;
4242
import com.sun.javafx.logging.PlatformLogger;
43+
import javafx.scene.paint.Color;
4344

4445
import java.io.File;
4546
import java.nio.ByteBuffer;
@@ -467,4 +468,40 @@ protected boolean _supportsInputMethods() {
467468
@Override
468469
protected native int _isKeyLocked(int keyCode);
469470

471+
@Override
472+
public native Map<String, Object> getPlatformPreferences();
473+
474+
@Override
475+
public Map<String, String> getPlatformKeyMappings() {
476+
return Map.of(
477+
"GTK.theme_fg_color", "foregroundColor",
478+
"GTK.theme_bg_color", "backgroundColor"
479+
);
480+
}
481+
482+
// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for GTK.
483+
@Override
484+
public Map<String, Class<?>> getPlatformKeys() {
485+
return Map.ofEntries(
486+
Map.entry("GTK.theme_name", String.class),
487+
Map.entry("GTK.theme_fg_color", Color.class),
488+
Map.entry("GTK.theme_bg_color", Color.class),
489+
Map.entry("GTK.theme_base_color", Color.class),
490+
Map.entry("GTK.theme_selected_bg_color", Color.class),
491+
Map.entry("GTK.theme_selected_fg_color", Color.class),
492+
Map.entry("GTK.theme_unfocused_fg_color", Color.class),
493+
Map.entry("GTK.theme_unfocused_bg_color", Color.class),
494+
Map.entry("GTK.theme_unfocused_base_color", Color.class),
495+
Map.entry("GTK.theme_unfocused_selected_bg_color", Color.class),
496+
Map.entry("GTK.theme_unfocused_selected_fg_color", Color.class),
497+
Map.entry("GTK.insensitive_bg_color", Color.class),
498+
Map.entry("GTK.insensitive_fg_color", Color.class),
499+
Map.entry("GTK.insensitive_base_color", Color.class),
500+
Map.entry("GTK.borders", Color.class),
501+
Map.entry("GTK.unfocused_borders", Color.class),
502+
Map.entry("GTK.warning_color", Color.class),
503+
Map.entry("GTK.error_color", Color.class),
504+
Map.entry("GTK.success_color", Color.class)
505+
);
506+
}
470507
}

modules/javafx.graphics/src/main/java/com/sun/glass/ui/mac/MacApplication.java

+67
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
3030
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
3131
import com.sun.javafx.util.Logging;
32+
import javafx.scene.paint.Color;
3233

3334
import java.io.File;
3435
import java.nio.ByteBuffer;
3536
import java.nio.IntBuffer;
3637

3738
import java.security.AccessController;
3839
import java.security.PrivilegedAction;
40+
import java.util.Map;
3941
import java.util.concurrent.CountDownLatch;
4042
import java.util.concurrent.TimeUnit;
4143

@@ -388,4 +390,69 @@ public String getDataDirectory() {
388390

389391
@Override
390392
protected native int _isKeyLocked(int keyCode);
393+
394+
@Override
395+
public native Map<String, Object> getPlatformPreferences();
396+
397+
@Override
398+
public Map<String, String> getPlatformKeyMappings() {
399+
return Map.of(
400+
"macOS.NSColor.textColor", "foregroundColor",
401+
"macOS.NSColor.textBackgroundColor", "backgroundColor",
402+
"macOS.NSColor.controlAccentColor", "accentColor"
403+
);
404+
}
405+
406+
// This list needs to be kept in sync with PlatformSupport.m in the Glass toolkit for macOS.
407+
@Override
408+
public Map<String, Class<?>> getPlatformKeys() {
409+
return Map.ofEntries(
410+
Map.entry("macOS.NSColor.labelColor", Color.class),
411+
Map.entry("macOS.NSColor.secondaryLabelColor", Color.class),
412+
Map.entry("macOS.NSColor.tertiaryLabelColor", Color.class),
413+
Map.entry("macOS.NSColor.quaternaryLabelColor", Color.class),
414+
Map.entry("macOS.NSColor.textColor", Color.class),
415+
Map.entry("macOS.NSColor.placeholderTextColor", Color.class),
416+
Map.entry("macOS.NSColor.selectedTextColor", Color.class),
417+
Map.entry("macOS.NSColor.textBackgroundColor", Color.class),
418+
Map.entry("macOS.NSColor.selectedTextBackgroundColor", Color.class),
419+
Map.entry("macOS.NSColor.keyboardFocusIndicatorColor", Color.class),
420+
Map.entry("macOS.NSColor.unemphasizedSelectedTextColor", Color.class),
421+
Map.entry("macOS.NSColor.unemphasizedSelectedTextBackgroundColor", Color.class),
422+
Map.entry("macOS.NSColor.linkColor", Color.class),
423+
Map.entry("macOS.NSColor.separatorColor", Color.class),
424+
Map.entry("macOS.NSColor.selectedContentBackgroundColor", Color.class),
425+
Map.entry("macOS.NSColor.unemphasizedSelectedContentBackgroundColor", Color.class),
426+
Map.entry("macOS.NSColor.selectedMenuItemTextColor", Color.class),
427+
Map.entry("macOS.NSColor.gridColor", Color.class),
428+
Map.entry("macOS.NSColor.headerTextColor", Color.class),
429+
Map.entry("macOS.NSColor.alternatingContentBackgroundColors", Color[].class),
430+
Map.entry("macOS.NSColor.controlAccentColor", Color.class),
431+
Map.entry("macOS.NSColor.controlColor", Color.class),
432+
Map.entry("macOS.NSColor.controlBackgroundColor", Color.class),
433+
Map.entry("macOS.NSColor.controlTextColor", Color.class),
434+
Map.entry("macOS.NSColor.disabledControlTextColor", Color.class),
435+
Map.entry("macOS.NSColor.selectedControlColor", Color.class),
436+
Map.entry("macOS.NSColor.selectedControlTextColor", Color.class),
437+
Map.entry("macOS.NSColor.alternateSelectedControlTextColor", Color.class),
438+
Map.entry("macOS.NSColor.currentControlTint", String.class),
439+
Map.entry("macOS.NSColor.windowBackgroundColor", Color.class),
440+
Map.entry("macOS.NSColor.windowFrameTextColor", Color.class),
441+
Map.entry("macOS.NSColor.underPageBackgroundColor", Color.class),
442+
Map.entry("macOS.NSColor.findHighlightColor", Color.class),
443+
Map.entry("macOS.NSColor.highlightColor", Color.class),
444+
Map.entry("macOS.NSColor.shadowColor", Color.class),
445+
Map.entry("macOS.NSColor.systemBlueColor", Color.class),
446+
Map.entry("macOS.NSColor.systemBrownColor", Color.class),
447+
Map.entry("macOS.NSColor.systemGrayColor", Color.class),
448+
Map.entry("macOS.NSColor.systemGreenColor", Color.class),
449+
Map.entry("macOS.NSColor.systemIndigoColor", Color.class),
450+
Map.entry("macOS.NSColor.systemOrangeColor", Color.class),
451+
Map.entry("macOS.NSColor.systemPinkColor", Color.class),
452+
Map.entry("macOS.NSColor.systemPurpleColor", Color.class),
453+
Map.entry("macOS.NSColor.systemRedColor", Color.class),
454+
Map.entry("macOS.NSColor.systemTealColor", Color.class),
455+
Map.entry("macOS.NSColor.systemYellowColor", Color.class)
456+
);
457+
}
391458
}

modules/javafx.graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java

+40-14
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,20 @@
2727
import com.sun.glass.ui.*;
2828
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
2929
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
30-
import com.sun.javafx.application.PlatformImpl;
3130
import com.sun.prism.impl.PrismSettings;
3231
import com.sun.javafx.tk.Toolkit;
32+
import javafx.scene.paint.Color;
3333

3434
import java.io.File;
3535
import java.nio.ByteBuffer;
3636
import java.nio.IntBuffer;
3737
import java.security.AccessController;
3838
import java.security.PrivilegedAction;
39-
import java.util.ResourceBundle;
39+
import java.util.Map;
4040

4141
final class WinApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
4242

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

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

344-
@Override
345-
public String getHighContrastScheme(String themeName) {
346-
return PlatformImpl.HighContrastScheme.fromThemeName(ResourceBundle.getBundle(BASE_NAME)::getString, themeName);
347-
}
348-
349-
private native String _getHighContrastTheme();
350-
@Override public String getHighContrastTheme() {
351-
checkEventThread();
352-
return getHighContrastScheme(_getHighContrastTheme());
353-
}
354-
355343
@Override
356344
protected boolean _supportsInputMethods() {
357345
return true;
@@ -380,4 +368,42 @@ public String getDataDirectory() {
380368

381369
@Override
382370
protected native int _isKeyLocked(int keyCode);
371+
372+
@Override
373+
public native Map<String, Object> getPlatformPreferences();
374+
375+
@Override
376+
public Map<String, String> getPlatformKeyMappings() {
377+
return Map.of(
378+
"Windows.UIColor.ForegroundColor", "foregroundColor",
379+
"Windows.UIColor.BackgroundColor", "backgroundColor",
380+
"Windows.UIColor.AccentColor", "accentColor"
381+
);
382+
}
383+
384+
// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for Windows.
385+
@Override
386+
public Map<String, Class<?>> getPlatformKeys() {
387+
return Map.ofEntries(
388+
Map.entry("Windows.SPI.HighContrast", Boolean.class),
389+
Map.entry("Windows.SPI.HighContrastColorScheme", String.class),
390+
Map.entry("Windows.SysColor.COLOR_3DFACE", Color.class),
391+
Map.entry("Windows.SysColor.COLOR_BTNTEXT", Color.class),
392+
Map.entry("Windows.SysColor.COLOR_GRAYTEXT", Color.class),
393+
Map.entry("Windows.SysColor.COLOR_HIGHLIGHT", Color.class),
394+
Map.entry("Windows.SysColor.COLOR_HIGHLIGHTTEXT", Color.class),
395+
Map.entry("Windows.SysColor.COLOR_HOTLIGHT", Color.class),
396+
Map.entry("Windows.SysColor.COLOR_WINDOW", Color.class),
397+
Map.entry("Windows.SysColor.COLOR_WINDOWTEXT", Color.class),
398+
Map.entry("Windows.UIColor.Background", Color.class),
399+
Map.entry("Windows.UIColor.Foreground", Color.class),
400+
Map.entry("Windows.UIColor.AccentDark3", Color.class),
401+
Map.entry("Windows.UIColor.AccentDark2", Color.class),
402+
Map.entry("Windows.UIColor.AccentDark1", Color.class),
403+
Map.entry("Windows.UIColor.Accent", Color.class),
404+
Map.entry("Windows.UIColor.AccentLight1", Color.class),
405+
Map.entry("Windows.UIColor.AccentLight2", Color.class),
406+
Map.entry("Windows.UIColor.AccentLight3", Color.class)
407+
);
408+
}
383409
}

0 commit comments

Comments
 (0)