Ticket #18747: 18747.2.patch

File 18747.2.patch, 1.7 KB (added by taylor.smock, 4 years ago)

Move to javafx package, rename to match javafx naming scheme, still has some issues

  • src/org/openstreetmap/josm/plugins/javafx/gui/JavaFxWrapper.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.plugins.javafx.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    private static final long serialVersionUID = -9186393855754110376L;
     20    T node;
     21
     22    /**
     23     * @param node The JavaFX node that will be returned later with
     24     *             {@link JavaFxWrapper#getNode}.
     25     */
     26    public JavaFxWrapper(T node) {
     27        super();
     28        this.node = node;
     29        Platform.runLater(() -> initFX());
     30    }
     31
     32    private void initFX() {
     33        Scene scene = createScene();
     34        setScene(scene);
     35    }
     36
     37    private Scene createScene() {
     38        Group group = new Group();
     39        Scene scene = new Scene(group);
     40        group.getChildren().add(node);
     41        return scene;
     42    }
     43
     44    /**
     45     * Get the JavaFX {@link Node}
     46     *
     47     * @return The Node passed to the class during construction
     48     */
     49    public T getNode() {
     50        return node;
     51    }
     52}