Ticket #18925: 18925.1.patch

File 18925.1.patch, 5.2 KB (added by taylor.smock, 2 months ago)

Ask user to disable plugin if JavaFX is missing

  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPlugin.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.plugins.javafx;
     3import static org.openstreetmap.josm.tools.I18n.tr;
    34
    45import java.io.File;
    56import java.io.IOException;
     
    1415import java.nio.file.StandardCopyOption;
    1516import java.nio.file.attribute.BasicFileAttributes;
    1617import java.security.CodeSource;
     18import java.util.Arrays;
     19import java.util.Collections;
    1720import java.util.Enumeration;
    1821import java.util.List;
    1922import java.util.Objects;
     
    2124import java.util.zip.ZipFile;
    2225
    2326import org.openstreetmap.josm.data.Preferences;
     27import org.openstreetmap.josm.gui.MainApplication;
    2428import org.openstreetmap.josm.io.audio.AudioPlayer;
    2529import org.openstreetmap.josm.plugins.DynamicURLClassLoader;
    2630import org.openstreetmap.josm.plugins.Plugin;
     31import org.openstreetmap.josm.plugins.PluginHandler;
    2732import org.openstreetmap.josm.plugins.PluginInformation;
    2833import org.openstreetmap.josm.plugins.javafx.io.audio.JavaFxMediaPlayer;
    2934import org.openstreetmap.josm.tools.Logging;
     35import org.openstreetmap.josm.tools.Utils;
    3036
     37
    3138/**
    3239 * OpenJFX plugin brings OpenJFX (JavaFX) to other plugins.
    3340 */
    3441abstract class JavaFxPlugin extends Plugin {
    3542
     43    Exception e;
    3644    /**
    3745     * Constructs a new {@code OpenJfxPlugin}.
    3846     * @param info plugin info
     
    4149     */
    4250    protected JavaFxPlugin(PluginInformation info, String ext, List<String> orderedNativeLibraries) {
    4351        super(info);
     52        boolean isJavaFx = Utils.getSystemProperty("javafx.runtime.version") != null || Arrays.asList("Oracle Corporation").contains(Utils.getSystemProperty("java.vendor"));
     53        if (!isJavaFx && Utils.getJavaVersion() >= 10) {
     54            extractNativeLibs(ext);
     55            loadNativeLibs(ext, orderedNativeLibraries);
     56        } else if (!isJavaFx) {
     57            Logging.error("JavaFX is not available");
     58            if (PluginHandler.confirmDisablePlugin(MainApplication.getMainFrame(), tr("JavaFX is not available"), info.getName())) {
     59                PluginHandler.removePlugins(Collections.singletonList(info));
     60            }
     61            return;
     62        }
    4463        AudioPlayer.setSoundPlayerClass(JavaFxMediaPlayer.class);
    45         extractNativeLibs(ext);
    46         loadNativeLibs(ext, orderedNativeLibraries);
    4764    }
    4865
    4966    private static void extractNativeLibs(String ext) {
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginOsx.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginOsx}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginOsx(PluginInformation info) {
     20    public JavaFxPluginOsx(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".dylib", Arrays.asList());
    1922    }
    2023}
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginUnixoid.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginUnixoid}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginUnixoid(PluginInformation info) {
     20    public JavaFxPluginUnixoid(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".so", Arrays.asList());
    1922    }
    2023}
  • src/org/openstreetmap/josm/plugins/javafx/JavaFxPluginWindows.java

     
    33
    44import java.util.Arrays;
    55
     6import javax.swing.UnsupportedLookAndFeelException;
     7
    68import org.openstreetmap.josm.plugins.PluginInformation;
    79
    810/**
     
    1315    /**
    1416     * Constructs a new {@code JavaFxPluginWindows}.
    1517     * @param info plugin info
     18     * @throws UnsupportedLookAndFeelException if JavaFX is not available (< Java 10)
    1619     */
    17     public JavaFxPluginWindows(PluginInformation info) {
     20    public JavaFxPluginWindows(PluginInformation info) throws UnsupportedLookAndFeelException {
    1821        super(info, ".dll", Arrays.asList("fxplugins.dll"));
    1922    }
    2023}