Ticket #18747: 18747.1.patch

File 18747.1.patch, 2.2 KB (added by taylor.smock, 4 years ago)
  • .classpath

     
    8282                        <accessrule kind="discouraged" pattern="javafx/scene/media/**"/>
    8383                        <accessrule kind="discouraged" pattern="com/sun/javafx/application/PlatformImpl"/>
    8484                        <accessrule kind="discouraged" pattern="javafx/util/Duration"/>
     85                        <accessrule kind="discouraged" pattern="javafx/scene/**"/>
     86                        <accessrule kind="discouraged" pattern="javafx/embed/swing/JFXPanel"/>
     87                        <accessrule kind="discouraged" pattern="javafx/application/Platform"/>
    8588                </accessrules>
    8689        </classpathentry>
    8790        <classpathentry kind="lib" path="tools/pmd/commons-lang3-3.8.1.jar">
  • src/org/openstreetmap/josm/gui/JavaFXWrapper.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui;
     3
     4import javafx.application.Platform;
     5import javafx.embed.swing.JFXPanel;
     6import javafx.scene.Group;
     7import javafx.scene.Node;
     8import javafx.scene.Scene;
     9
     10/**
     11 * This wrapper class wraps arbitrary JavaFX Nodes, so that they can easily be
     12 * added to a Swing UI.
     13 *
     14 * @author Taylor Smock
     15 * @param <T> Some class that extends {@link Node}
     16 * @since xxx
     17 */
     18public class JavaFXWrapper<T extends Node> extends JFXPanel {
     19    T node;
     20
     21    /**
     22     * @param node The JavaFX node that will be returned later with
     23     *             {@link JavaFXWrapper#getNode}.
     24     */
     25    public JavaFXWrapper(T node) {
     26        super();
     27        this.node = node;
     28        Platform.runLater(() -> initFX());
     29    }
     30
     31    private void initFX() {
     32        Scene scene = createScene();
     33        setScene(scene);
     34    }
     35
     36    private Scene createScene() {
     37        Group group = new Group();
     38        Scene scene = new Scene(group);
     39        group.getChildren().add(node);
     40        return scene;
     41    }
     42
     43    /**
     44     * Get the JavaFX {@link Node}
     45     *
     46     * @return The Node passed to the class during construction
     47     */
     48    public T getNode() {
     49        return node;
     50    }
     51}