1 | package org.expeditee.reflection;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.lang.reflect.Constructor;
|
---|
5 | import java.lang.reflect.Method;
|
---|
6 | import java.net.URL;
|
---|
7 | import java.net.URLClassLoader;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | public class JavaFX {
|
---|
12 | public static Class<?> JFXPanel;
|
---|
13 |
|
---|
14 | public static Class<?> Platform;
|
---|
15 | public static Method PlatformRunLater;
|
---|
16 |
|
---|
17 | public static Class<?> Group;
|
---|
18 | public static Method GroupGetChildren;
|
---|
19 |
|
---|
20 | public static Class<?> Scene;
|
---|
21 | public static Constructor<?> SceneConstructor;
|
---|
22 |
|
---|
23 | public static Class<?> WebView;
|
---|
24 | public static Method JFXPanelSetScene;
|
---|
25 | public static Method WebViewSetPrefSize;
|
---|
26 | public static Method WebViewGetEngine;
|
---|
27 | public static Method WebViewSetContextMenuEnabled;
|
---|
28 |
|
---|
29 | public static Class<?> WebEngine;
|
---|
30 | public static Constructor<?> WebEngineConstructor;
|
---|
31 | public static Method WebEngineLoad;
|
---|
32 | public static Method WebEngineGetLocation;
|
---|
33 | public static Method WebEngineGetLoadWorker;
|
---|
34 | public static Method WebEngineGetHistory;
|
---|
35 | public static Method WebEngineReload;
|
---|
36 | public static Method WebEngineExecuteScript;
|
---|
37 |
|
---|
38 | public static Class<?> WebHistory;
|
---|
39 | public static Method WebHistoryGo;
|
---|
40 |
|
---|
41 | public static Class<?> Worker;
|
---|
42 | public static Method WorkerStateProperty;
|
---|
43 |
|
---|
44 | public static Class<?> ReadOnlyObjectProperty;
|
---|
45 | public static Method ReadOnlyObjectPropertyAddListener;
|
---|
46 |
|
---|
47 | public static Class<?> ChangeListener;
|
---|
48 |
|
---|
49 | public static Class<?> ObservableValue;
|
---|
50 |
|
---|
51 | public static Class<?> State;
|
---|
52 | public static List<?> StateConstants;
|
---|
53 |
|
---|
54 | public static Class EventHandler;
|
---|
55 |
|
---|
56 | public static Class Node;
|
---|
57 | public static Method NodeSetOnMouseClicked;
|
---|
58 |
|
---|
59 | public static Class MouseEvent;
|
---|
60 | public static Method MouseEventGetButton;
|
---|
61 |
|
---|
62 | public static Class MouseButton;
|
---|
63 |
|
---|
64 | public static Class<?> JSObject;
|
---|
65 | public static Method JSObjectEval;
|
---|
66 | public static Method JSObjectCall;
|
---|
67 | public static Method JSObjectGetMember;
|
---|
68 | public static Method JSObjectGetSlot;
|
---|
69 |
|
---|
70 | static {
|
---|
71 | String javaLibDir = System.getProperty("java.home") + File.separator + "lib" + File.separator;
|
---|
72 | try {
|
---|
73 | ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
---|
74 |
|
---|
75 | File jar = new File(javaLibDir + "jfxrt.jar");
|
---|
76 |
|
---|
77 | Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
---|
78 | addURL.setAccessible(true);
|
---|
79 | addURL.invoke(classLoader, jar.toURI().toURL());
|
---|
80 |
|
---|
81 | JFXPanel = Class.forName("javafx.embed.swing.JFXPanel", false, classLoader);
|
---|
82 |
|
---|
83 | Platform = classLoader.loadClass("javafx.application.Platform");
|
---|
84 | PlatformRunLater = Platform.getMethod("runLater", Runnable.class);
|
---|
85 |
|
---|
86 | // Setting JFX to not exit when all panels are hidden, otherwise moving, resizing and changing frames will
|
---|
87 | // cause JFX to exit, preventing JFX elements from displaying at all
|
---|
88 | Platform.getMethod("setImplicitExit", boolean.class).invoke(null, false);
|
---|
89 |
|
---|
90 | Group = classLoader.loadClass("javafx.scene.Group");
|
---|
91 | GroupGetChildren = Group.getMethod("getChildren");
|
---|
92 |
|
---|
93 | Scene = classLoader.loadClass("javafx.scene.Scene");
|
---|
94 | SceneConstructor = Scene.getConstructor(classLoader.loadClass("javafx.scene.Parent"));
|
---|
95 |
|
---|
96 | WebView = classLoader.loadClass("javafx.scene.web.WebView");
|
---|
97 | JFXPanelSetScene = JFXPanel.getMethod("setScene", Scene);
|
---|
98 | WebViewSetPrefSize = WebView.getMethod("setPrefSize", double.class, double.class);
|
---|
99 | WebViewGetEngine = WebView.getMethod("getEngine");
|
---|
100 | WebViewSetContextMenuEnabled = WebView.getMethod("setContextMenuEnabled", boolean.class);
|
---|
101 |
|
---|
102 | WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine");
|
---|
103 | WebEngineConstructor = WebEngine.getConstructor(String.class);
|
---|
104 | WebEngineLoad = WebEngine.getMethod("load", String.class);
|
---|
105 | WebEngineGetLocation = WebEngine.getMethod("getLocation");
|
---|
106 | WebEngineGetLoadWorker = WebEngine.getMethod("getLoadWorker");
|
---|
107 | WebEngineGetHistory = WebEngine.getMethod("getHistory");
|
---|
108 | WebEngineReload = WebEngine.getMethod("reload");
|
---|
109 | WebEngineExecuteScript = WebEngine.getMethod("executeScript", String.class);
|
---|
110 |
|
---|
111 | WebHistory = classLoader.loadClass("javafx.scene.web.WebHistory");
|
---|
112 | WebHistoryGo = WebHistory.getMethod("go", int.class);
|
---|
113 |
|
---|
114 | Worker = classLoader.loadClass("javafx.concurrent.Worker");
|
---|
115 | WorkerStateProperty = Worker.getMethod("stateProperty");
|
---|
116 |
|
---|
117 | ChangeListener = classLoader.loadClass("javafx.beans.value.ChangeListener");
|
---|
118 |
|
---|
119 | ReadOnlyObjectProperty = classLoader.loadClass("javafx.beans.property.ReadOnlyObjectProperty");
|
---|
120 | ReadOnlyObjectPropertyAddListener = ReadOnlyObjectProperty.getMethod("addListener", ChangeListener);
|
---|
121 |
|
---|
122 | ObservableValue = classLoader.loadClass("javafx.beans.value.ObservableValue");
|
---|
123 |
|
---|
124 | State = classLoader.loadClass("javafx.concurrent.Worker$State");
|
---|
125 | StateConstants = Arrays.asList(State.getEnumConstants());
|
---|
126 |
|
---|
127 | EventHandler = classLoader.loadClass("javafx.event.EventHandler");
|
---|
128 |
|
---|
129 | Node = classLoader.loadClass("javafx.scene.Node");
|
---|
130 | NodeSetOnMouseClicked = Node.getMethod("setOnMouseClicked", EventHandler);
|
---|
131 |
|
---|
132 | MouseEvent = classLoader.loadClass("javafx.scene.input.MouseEvent");
|
---|
133 | MouseEventGetButton = MouseEvent.getMethod("getButton");
|
---|
134 |
|
---|
135 | MouseButton = classLoader.loadClass("javafx.scene.input.MouseButton");
|
---|
136 |
|
---|
137 | JSObject = classLoader.loadClass("netscape.javascript.JSObject");
|
---|
138 | JSObjectEval = JSObject.getMethod("eval", String.class);
|
---|
139 | JSObjectCall = JSObject.getMethod("call", String.class, Object[].class);
|
---|
140 | JSObjectGetMember = JSObject.getMethod("getMember", String.class);
|
---|
141 | JSObjectGetSlot = JSObject.getMethod("getSlot", int.class);
|
---|
142 |
|
---|
143 | } catch (Exception e) {
|
---|
144 | e.printStackTrace();
|
---|
145 | }
|
---|
146 | }
|
---|
147 | }
|
---|