source: trunk/src/org/expeditee/reflection/JavaFX.java@ 566

Last change on this file since 566 was 566, checked in by jts21, 11 years ago

Move JavaFX reflection to it's own class so it can be accessed by multiple other classes, add WebParser class for parsing a webpage from a WebEngine into a Frame

File size: 4.4 KB
Line 
1package org.expeditee.reflection;
2
3import java.io.File;
4import java.lang.reflect.Constructor;
5import java.lang.reflect.Method;
6import java.net.URL;
7import java.net.URLClassLoader;
8import java.util.Arrays;
9import java.util.List;
10
11public 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
28 public static Class WebEngine;
29 public static Method WebEngineLoad;
30 public static Method WebEngineGetLocation;
31 public static Method WebEngineGetLoadWorker;
32 public static Method WebEngineGetHistory;
33 public static Method WebEngineReload;
34 public static Method WebEngineExecuteScript;
35
36 public static Class WebHistory;
37 public static Method WebHistoryGo;
38
39 public static Class Worker;
40 public static Method WorkerStateProperty;
41
42 public static Class ReadOnlyObjectProperty;
43 public static Method ReadOnlyObjectPropertyAddListener;
44
45 public static Class ChangeListener;
46
47 public static Class ObservableValue;
48
49 public static Class State;
50 public static List<Object> StateConstants;
51
52 public static Class JSObject;
53 public static Method JSObjectEval;
54 public static Method JSObjectCall;
55 public static Method JSObjectGetMember;
56 public static Method JSObjectGetSlot;
57
58 static {
59 String javaLibDir = System.getProperty("java.home") + File.separator + "lib" + File.separator;
60 try {
61 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
62
63 File jar = new File(javaLibDir + "jfxrt.jar");
64
65 Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
66 addURL.setAccessible(true);
67 addURL.invoke(classLoader, jar.toURI().toURL());
68
69 JFXPanel = Class.forName("javafx.embed.swing.JFXPanel", false, classLoader);
70
71 Platform = classLoader.loadClass("javafx.application.Platform");
72 PlatformRunLater = Platform.getMethod("runLater", Runnable.class);
73
74 // Setting JFX to not exit when all panels are hidden, otherwise moving, resizing and changing frames will
75 // cause JFX to exit, preventing JFX elements from displaying at all
76 Platform.getMethod("setImplicitExit", boolean.class).invoke(null, false);
77
78 Group = classLoader.loadClass("javafx.scene.Group");
79 GroupGetChildren = Group.getMethod("getChildren");
80
81 Scene = classLoader.loadClass("javafx.scene.Scene");
82 SceneConstructor = Scene.getConstructor(classLoader.loadClass("javafx.scene.Parent"));
83
84 WebView = classLoader.loadClass("javafx.scene.web.WebView");
85 JFXPanelSetScene = JFXPanel.getMethod("setScene", Scene);
86 WebViewSetPrefSize = WebView.getMethod("setPrefSize", double.class, double.class);
87 WebViewGetEngine = WebView.getMethod("getEngine");
88
89 WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine");
90 WebEngineLoad = WebEngine.getMethod("load", String.class);
91 WebEngineGetLocation = WebEngine.getMethod("getLocation");
92 WebEngineGetLoadWorker = WebEngine.getMethod("getLoadWorker");
93 WebEngineGetHistory = WebEngine.getMethod("getHistory");
94 WebEngineReload = WebEngine.getMethod("reload");
95 WebEngineExecuteScript = WebEngine.getMethod("executeScript", String.class);
96
97 WebHistory = classLoader.loadClass("javafx.scene.web.WebHistory");
98 WebHistoryGo = WebHistory.getMethod("go", int.class);
99
100 Worker = classLoader.loadClass("javafx.concurrent.Worker");
101 WorkerStateProperty = Worker.getMethod("stateProperty");
102
103 ChangeListener = classLoader.loadClass("javafx.beans.value.ChangeListener");
104
105 ReadOnlyObjectProperty = classLoader.loadClass("javafx.beans.property.ReadOnlyObjectProperty");
106 ReadOnlyObjectPropertyAddListener = ReadOnlyObjectProperty.getMethod("addListener", ChangeListener);
107
108 ObservableValue = classLoader.loadClass("javafx.beans.value.ObservableValue");
109
110 State = classLoader.loadClass("javafx.concurrent.Worker$State");
111 StateConstants = Arrays.asList(State.getEnumConstants());
112
113 JSObject = classLoader.loadClass("netscape.javascript.JSObject");
114 JSObjectEval = JSObject.getMethod("eval", String.class);
115 JSObjectCall = JSObject.getMethod("call", String.class, Object[].class);
116 JSObjectGetMember = JSObject.getMethod("getMember", String.class);
117 JSObjectGetSlot = JSObject.getMethod("getSlot", int.class);
118
119 } catch (Exception e) {
120 e.printStackTrace();
121 }
122 }
123}
Note: See TracBrowser for help on using the repository browser.