Ticket #18747: 18747.patch

File 18747.patch, 2.3 KB (added by taylor.smock, 6 years ago)

Initial patch

  • .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> {
     19  JFXPanel jfxPanel;
     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    jfxPanel = new JFXPanel();
     28    this.node = node;
     29    Platform.runLater(() -> initFX());
     30  }
     31
     32  private void initFX() {
     33    Scene scene = createScene();
     34    jfxPanel.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 JFXPanel to add to a Swing UI
     46   *
     47   * @return The JFXPanel
     48   */
     49  public JFXPanel getPanel() {
     50    return jfxPanel;
     51  }
     52
     53  /**
     54   * Get the JavaFX {@link Node}
     55   *
     56   * @return The Node passed to the class during construction
     57   */
     58  public T getNode() {
     59    return node;
     60  }
     61}