package org.expeditee.reflection; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; import java.util.List; public class JavaFX { public static Class JFXPanel; public static Class Platform; public static Method PlatformRunLater; public static Class Group; public static Method GroupGetChildren; public static Class Scene; public static Constructor SceneConstructor; public static Class WebView; public static Method JFXPanelSetScene; public static Method WebViewSetPrefSize; public static Method WebViewGetEngine; public static Method WebViewSetContextMenuEnabled; public static Class WebEngine; public static Method WebEngineLoad; public static Method WebEngineGetLocation; public static Method WebEngineGetLoadWorker; public static Method WebEngineGetHistory; public static Method WebEngineReload; public static Method WebEngineExecuteScript; public static Class WebHistory; public static Method WebHistoryGo; public static Class Worker; public static Method WorkerStateProperty; public static Class ReadOnlyObjectProperty; public static Method ReadOnlyObjectPropertyAddListener; public static Class ChangeListener; public static Class ObservableValue; public static Class State; public static List StateConstants; public static Class EventHandler; public static Class Node; public static Method NodeSetOnMouseClicked; public static Class MouseEvent; public static Method MouseEventGetButton; public static Class MouseButton; public static Class JSObject; public static Method JSObjectEval; public static Method JSObjectCall; public static Method JSObjectGetMember; public static Method JSObjectGetSlot; static { String javaLibDir = System.getProperty("java.home") + File.separator + "lib" + File.separator; try { ClassLoader classLoader = ClassLoader.getSystemClassLoader(); File jar = new File(javaLibDir + "jfxrt.jar"); Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); addURL.setAccessible(true); addURL.invoke(classLoader, jar.toURI().toURL()); JFXPanel = Class.forName("javafx.embed.swing.JFXPanel", false, classLoader); Platform = classLoader.loadClass("javafx.application.Platform"); PlatformRunLater = Platform.getMethod("runLater", Runnable.class); // Setting JFX to not exit when all panels are hidden, otherwise moving, resizing and changing frames will // cause JFX to exit, preventing JFX elements from displaying at all Platform.getMethod("setImplicitExit", boolean.class).invoke(null, false); Group = classLoader.loadClass("javafx.scene.Group"); GroupGetChildren = Group.getMethod("getChildren"); Scene = classLoader.loadClass("javafx.scene.Scene"); SceneConstructor = Scene.getConstructor(classLoader.loadClass("javafx.scene.Parent")); WebView = classLoader.loadClass("javafx.scene.web.WebView"); JFXPanelSetScene = JFXPanel.getMethod("setScene", Scene); WebViewSetPrefSize = WebView.getMethod("setPrefSize", double.class, double.class); WebViewGetEngine = WebView.getMethod("getEngine"); WebViewSetContextMenuEnabled = WebView.getMethod("setContextMenuEnabled", boolean.class); WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine"); WebEngineLoad = WebEngine.getMethod("load", String.class); WebEngineGetLocation = WebEngine.getMethod("getLocation"); WebEngineGetLoadWorker = WebEngine.getMethod("getLoadWorker"); WebEngineGetHistory = WebEngine.getMethod("getHistory"); WebEngineReload = WebEngine.getMethod("reload"); WebEngineExecuteScript = WebEngine.getMethod("executeScript", String.class); WebHistory = classLoader.loadClass("javafx.scene.web.WebHistory"); WebHistoryGo = WebHistory.getMethod("go", int.class); Worker = classLoader.loadClass("javafx.concurrent.Worker"); WorkerStateProperty = Worker.getMethod("stateProperty"); ChangeListener = classLoader.loadClass("javafx.beans.value.ChangeListener"); ReadOnlyObjectProperty = classLoader.loadClass("javafx.beans.property.ReadOnlyObjectProperty"); ReadOnlyObjectPropertyAddListener = ReadOnlyObjectProperty.getMethod("addListener", ChangeListener); ObservableValue = classLoader.loadClass("javafx.beans.value.ObservableValue"); State = classLoader.loadClass("javafx.concurrent.Worker$State"); StateConstants = Arrays.asList(State.getEnumConstants()); EventHandler = classLoader.loadClass("javafx.event.EventHandler"); Node = classLoader.loadClass("javafx.scene.Node"); NodeSetOnMouseClicked = Node.getMethod("setOnMouseClicked", EventHandler); MouseEvent = classLoader.loadClass("javafx.scene.input.MouseEvent"); MouseEventGetButton = MouseEvent.getMethod("getButton"); MouseButton = classLoader.loadClass("javafx.scene.input.MouseButton"); JSObject = classLoader.loadClass("netscape.javascript.JSObject"); JSObjectEval = JSObject.getMethod("eval", String.class); JSObjectCall = JSObject.getMethod("call", String.class, Object[].class); JSObjectGetMember = JSObject.getMethod("getMember", String.class); JSObjectGetSlot = JSObject.getMethod("getSlot", int.class); } catch (Exception e) { e.printStackTrace(); } } }