Fixed issues around java7/8 with macOSX and JavaFX
This commit is contained in:
parent
26e985e032
commit
54fb3a0d1d
@ -19,6 +19,7 @@ package dorkbox.systemTray.util;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
import dorkbox.systemTray.SystemTray;
|
||||||
|
import dorkbox.util.OS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for JavaFX.
|
* Utility methods for JavaFX.
|
||||||
@ -31,17 +32,34 @@ class JavaFX {
|
|||||||
// Methods are cached for performance
|
// Methods are cached for performance
|
||||||
private static final Method dispatchMethod;
|
private static final Method dispatchMethod;
|
||||||
private static final Method isEventThreadMethod;
|
private static final Method isEventThreadMethod;
|
||||||
|
private static final Object isEventThreadObject;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Method _isEventThreadMethod = null;
|
Method _isEventThreadMethod = null;
|
||||||
Method _dispatchMethod = null;
|
Method _dispatchMethod = null;
|
||||||
|
Object _isEventThreadObject = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName("javafx.application.Platform");
|
Class<?> clazz = Class.forName("javafx.application.Platform");
|
||||||
_dispatchMethod = clazz.getMethod("runLater", Runnable.class);
|
_dispatchMethod = clazz.getMethod("runLater", Runnable.class);
|
||||||
|
|
||||||
|
// JAVA 7
|
||||||
|
// javafx.application.Platform.isFxApplicationThread();
|
||||||
|
|
||||||
|
// JAVA 8
|
||||||
|
// com.sun.javafx.tk.Toolkit.getToolkit().isFxUserThread();
|
||||||
|
if (OS.javaVersion <= 7) {
|
||||||
clazz = Class.forName("javafx.application.Platform");
|
clazz = Class.forName("javafx.application.Platform");
|
||||||
_isEventThreadMethod = clazz.getMethod("isFxApplicationThread");
|
_isEventThreadMethod = clazz.getMethod("isFxApplicationThread");
|
||||||
|
_isEventThreadObject = null;
|
||||||
|
} else {
|
||||||
|
clazz = Class.forName("com.sun.javafx.tk.Toolkit");
|
||||||
|
_isEventThreadMethod = clazz.getMethod("getToolkit");
|
||||||
|
|
||||||
|
_isEventThreadObject = _isEventThreadMethod.invoke(null);
|
||||||
|
_isEventThreadMethod = _isEventThreadObject.getClass()
|
||||||
|
.getMethod("isFxUserThread", null);
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (SystemTray.DEBUG) {
|
if (SystemTray.DEBUG) {
|
||||||
SystemTray.logger.error("Cannot initialize JavaFX", e);
|
SystemTray.logger.error("Cannot initialize JavaFX", e);
|
||||||
@ -50,6 +68,7 @@ class JavaFX {
|
|||||||
|
|
||||||
dispatchMethod = _dispatchMethod;
|
dispatchMethod = _dispatchMethod;
|
||||||
isEventThreadMethod = _isEventThreadMethod;
|
isEventThreadMethod = _isEventThreadMethod;
|
||||||
|
isEventThreadObject = _isEventThreadObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static
|
public static
|
||||||
@ -77,10 +96,18 @@ class JavaFX {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
boolean isEventThread() {
|
boolean isEventThread() {
|
||||||
|
// JAVA 7
|
||||||
// javafx.application.Platform.isFxApplicationThread();
|
// javafx.application.Platform.isFxApplicationThread();
|
||||||
|
|
||||||
|
// JAVA 8
|
||||||
|
// com.sun.javafx.tk.Toolkit.getToolkit().isFxUserThread();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (OS.javaVersion <= 7) {
|
||||||
return (Boolean) isEventThreadMethod.invoke(null);
|
return (Boolean) isEventThreadMethod.invoke(null);
|
||||||
|
} else {
|
||||||
|
return (Boolean) isEventThreadMethod.invoke(isEventThreadObject, null);
|
||||||
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
SystemTray.logger.error("Unable to check if JavaFX is in the event thread. Please create an issue with your OS and Java " +
|
SystemTray.logger.error("Unable to check if JavaFX is in the event thread. Please create an issue with your OS and Java " +
|
||||||
"version so we may further investigate this issue.");
|
"version so we may further investigate this issue.");
|
||||||
|
Loading…
Reference in New Issue
Block a user