Skip to content

Commit

Permalink
Merge branch 'master' into feature/extended-window
Browse files Browse the repository at this point in the history
  • Loading branch information
mstr2 committed Oct 23, 2024
2 parents 7969622 + 076b401 commit a289572
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 351 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.glass.events.KeyEvent;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.preferences.PreferenceMapping;

import java.io.File;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -777,22 +778,25 @@ public Map<String, Object> getPlatformPreferences() {
}

/**
* Returns a map of platform-specific keys to platform-independent keys defined by JavaFX.
* Returns a map of platform-specific keys to platform-independent keys defined by JavaFX, including a
* function that maps the platform-specific value to the platform-independent value.
* <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
* The following platform-independent keys are currently supported, which correspond to the names of
* properties on the {@link com.sun.javafx.application.preferences.PreferenceProperties} class:
* <ul>
* <li>foregroundColor
* <li>backgroundColor
* <li>accentColor
* <li>reducedMotion
* <li>reducedTransparency
* </ul>
*
* @return a map of platform-specific keys to well-known keys
*/
public Map<String, String> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
return Map.of();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.sun.glass.ui.Timer;
import com.sun.glass.ui.View;
import com.sun.glass.ui.Window;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.javafx.util.Logging;
import com.sun.glass.utils.NativeLibLoader;
import com.sun.prism.impl.PrismSettings;
Expand Down Expand Up @@ -477,10 +478,12 @@ protected boolean _supportsExtendedWindows() {
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, String> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
return Map.of(
"GTK.theme_fg_color", "foregroundColor",
"GTK.theme_bg_color", "backgroundColor"
"GTK.theme_fg_color", new PreferenceMapping<>("foregroundColor", Color.class),
"GTK.theme_bg_color", new PreferenceMapping<>("backgroundColor", Color.class),
"GTK.theme_selected_bg_color", new PreferenceMapping<>("accentColor", Color.class),
"GTK.enable_animations", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b)
);
}

Expand All @@ -506,7 +509,8 @@ public Map<String, Class<?>> getPlatformKeys() {
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)
Map.entry("GTK.success_color", Color.class),
Map.entry("GTK.enable_animations", Boolean.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.sun.glass.ui.*;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.javafx.util.Logging;
import javafx.scene.paint.Color;

Expand Down Expand Up @@ -444,11 +445,13 @@ public String getDataDirectory() {
public native Map<String, Object> getPlatformPreferences();

@Override
public Map<String, String> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
return Map.of(
"macOS.NSColor.textColor", "foregroundColor",
"macOS.NSColor.textBackgroundColor", "backgroundColor",
"macOS.NSColor.controlAccentColor", "accentColor"
"macOS.NSColor.textColor", new PreferenceMapping<>("foregroundColor", Color.class),
"macOS.NSColor.textBackgroundColor", new PreferenceMapping<>("backgroundColor", Color.class),
"macOS.NSColor.controlAccentColor", new PreferenceMapping<>("accentColor", Color.class),
"macOS.NSWorkspace.accessibilityDisplayShouldReduceMotion", new PreferenceMapping<>("reducedMotion", Boolean.class),
"macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", new PreferenceMapping<>("reducedTransparency", Boolean.class)
);
}

Expand Down Expand Up @@ -501,7 +504,9 @@ public Map<String, Class<?>> getPlatformKeys() {
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)
Map.entry("macOS.NSColor.systemYellowColor", Color.class),
Map.entry("macOS.NSWorkspace.accessibilityDisplayShouldReduceMotion", Boolean.class),
Map.entry("macOS.NSWorkspace.accessibilityDisplayShouldReduceTransparency", Boolean.class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.sun.glass.ui.*;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.CommonDialogs.FileChooserResult;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.prism.impl.PrismSettings;
import com.sun.javafx.tk.Toolkit;
import javafx.scene.paint.Color;
Expand Down Expand Up @@ -379,11 +380,13 @@ public String getDataDirectory() {

// This list needs to be kept in sync with PlatformSupport.cpp in the Glass toolkit for Windows.
@Override
public Map<String, String> getPlatformKeyMappings() {
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
return Map.of(
"Windows.UIColor.Foreground", "foregroundColor",
"Windows.UIColor.Background", "backgroundColor",
"Windows.UIColor.Accent", "accentColor"
"Windows.UIColor.Foreground", new PreferenceMapping<>("foregroundColor", Color.class),
"Windows.UIColor.Background", new PreferenceMapping<>("backgroundColor", Color.class),
"Windows.UIColor.Accent", new PreferenceMapping<>("accentColor", Color.class),
"Windows.UISettings.AdvancedEffectsEnabled", new PreferenceMapping<>("reducedTransparency", Boolean.class, b -> !b),
"Windows.SPI.ClientAreaAnimation", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b)
);
}

Expand All @@ -393,6 +396,7 @@ 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.SPI.ClientAreaAnimation", Boolean.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),
Expand All @@ -409,7 +413,8 @@ public Map<String, Class<?>> getPlatformKeys() {
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)
Map.entry("Windows.UIColor.AccentLight3", Color.class),
Map.entry("Windows.UISettings.AdvancedEffectsEnabled", Boolean.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.sun.javafx.FXPermissions.CREATE_TRANSPARENT_WINDOW_PERMISSION;
import com.sun.javafx.PlatformUtil;
import com.sun.javafx.application.preferences.PlatformPreferences;
import com.sun.javafx.application.preferences.PreferenceMapping;
import com.sun.javafx.css.StyleManager;
import com.sun.javafx.tk.TKListener;
import com.sun.javafx.tk.TKStage;
Expand Down Expand Up @@ -1013,7 +1014,7 @@ public static PlatformPreferences getPlatformPreferences() {
* @param preferences the initial set of platform preferences
*/
public static void initPreferences(Map<String, Class<?>> platformKeys,
Map<String, String> platformKeyMappings,
Map<String, PreferenceMapping<?>> platformKeyMappings,
Map<String, Object> preferences) {
platformPreferences = new PlatformPreferences(platformKeys, platformKeyMappings);
platformPreferences.update(preferences);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, 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 @@ -29,6 +29,7 @@
import javafx.application.ColorScheme;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.collections.MapChangeListener;
import javafx.scene.paint.Color;
Expand All @@ -50,7 +51,7 @@
* When the operating system signals that a preference has changed, the mappings are updated
* by calling the {@link #update(Map)} method.
*/
public class PlatformPreferences extends AbstractMap<String, Object> implements Platform.Preferences {
public final class PlatformPreferences extends AbstractMap<String, Object> implements Platform.Preferences {

/**
* Contains mappings from platform-specific keys to their types. This information is
Expand All @@ -63,7 +64,7 @@ public class PlatformPreferences extends AbstractMap<String, Object> implements
* Contains mappings from platform-specific keys to well-known keys, which are used
* in the implementation of the property-based API in {@link PreferenceProperties}.
*/
private final Map<String, String> platformKeyMappings;
private final Map<String, PreferenceMapping<?>> platformKeyMappings;

/**
* Contains the current set of effective preferences, i.e. the set of preferences that
Expand All @@ -86,7 +87,8 @@ public class PlatformPreferences extends AbstractMap<String, Object> implements
* @throws NullPointerException if {@code platformKeys} or {@code platformKeyMappings} is {@code null} or
* contains {@code null} keys or values
*/
public PlatformPreferences(Map<String, Class<?>> platformKeys, Map<String, String> platformKeyMappings) {
public PlatformPreferences(Map<String, Class<?>> platformKeys,
Map<String, PreferenceMapping<?>> platformKeyMappings) {
this.platformKeys = Map.copyOf(platformKeys);
this.platformKeyMappings = Map.copyOf(platformKeyMappings);
}
Expand Down Expand Up @@ -201,6 +203,26 @@ public Optional<Color> getColor(String key) {
return getValue(key, Color.class);
}

@Override
public ReadOnlyBooleanProperty reducedMotionProperty() {
return properties.reducedMotionProperty();
}

@Override
public boolean isReducedMotion() {
return properties.isReducedMotion();
}

@Override
public ReadOnlyBooleanProperty reducedTransparencyProperty() {
return properties.reducedTransparencyProperty();
}

@Override
public boolean isReducedTransparency() {
return properties.isReducedTransparency();
}

@Override
public ReadOnlyObjectProperty<ColorScheme> colorSchemeProperty() {
return properties.colorSchemeProperty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2024, 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.preferences;

import com.sun.javafx.util.Logging;
import java.util.Objects;
import java.util.function.Function;

/**
* A mapping from platform-specific keys to platform-independent keys defined by JavaFX, including a
* function that maps the platform-specific value to the platform-independent value.
*/
public record PreferenceMapping<T>(String keyName, Class<T> valueType, Function<T, T> valueMapper) {

public PreferenceMapping {
Objects.requireNonNull(keyName, "keyName cannot be null");
Objects.requireNonNull(valueType, "valueType cannot be null");
Objects.requireNonNull(valueMapper, "valueMapper cannot be null");
}

public PreferenceMapping(String keyName, Class<T> valueType) {
this(keyName, valueType, Function.identity());
}

@SuppressWarnings("unchecked")
public T map(Object value) {
if (valueType.isInstance(value)) {
return valueMapper.apply((T)value);
}

if (value != null) {
Logging.getJavaFXLogger().warning(
"Unexpected value of " + keyName + " platform preference, " +
"using default value instead (expected = " + valueType.getName() +
", actual = " + value.getClass().getName() + ")");
}

return null;
}
}
Loading

0 comments on commit a289572

Please sign in to comment.