Skip to content

Commit

Permalink
Fixed J2CL compilation issue with apps using javafx-media
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Mar 31, 2024
1 parent 2c9056d commit d3df75d
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package dev.webfx.kit.mapper.peers.javafxgraphics;

import dev.webfx.platform.console.Console;
import dev.webfx.platform.util.function.Factory;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.layout.Region;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

/**
* @author Bruno Salmon
*/
public final class NodePeerFactoryRegistry {

private final static Map<Class<? extends Node>, Factory<? extends NodePeer>> nodePeerFactories = new HashMap<>();
private final static Map<Class<? extends Node>, Supplier<? extends NodePeer>> nodePeerFactories = new HashMap<>();
private final static Map<Class<? extends Node>, Function<String, ? extends NodePeer>> customTagNodePeerFactories = new HashMap<>();
private static Function<Region, NodePeer<Region>> defaultRegionFactory;
private static Function<Group, NodePeer<Group>> defaultGroupFactory;

public static <N extends Node, V extends NodePeer<? super N>> void registerNodePeerFactory(Class<N> nodeClass, Factory<V> factory) {
public static <N extends Node, V extends NodePeer<? super N>> void registerNodePeerFactory(Class<N> nodeClass, Supplier<V> factory) {
nodePeerFactories.put(nodeClass, factory);
}

Expand Down Expand Up @@ -54,9 +54,9 @@ public static <N extends Node, V extends NodePeer<N>> V createNodePeer(N node) {
if (customTagFactory != null)
return (V) customTagFactory.apply(customTag);
}
Factory<? extends NodePeer> factory = nodePeerFactories.get(nodeClass);
Supplier<? extends NodePeer> factory = nodePeerFactories.get(nodeClass);
if (factory != null)
return (V) factory.create();
return (V) factory.get();
// If not found, it can be because it's a derived class
// For regions and groups, we delegate this search to their default factory
if (node instanceof Region && defaultRegionFactory != null)
Expand All @@ -73,7 +73,7 @@ public static <N extends Node, V extends NodePeer<N>> V createNodePeer(N node) {
}
factory = nodePeerFactories.get(nodeClass);
if (factory != null)
return (V) factory.create();
return (V) factory.get();
}
// If still not found, we return null after logging the problem
Console.log("WARNING: No NodePeer factory registered for " + node.getClass());
Expand Down

0 comments on commit d3df75d

Please sign in to comment.