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

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

Add settings package which uses reflection to allow changing settings without hard coding the code to change every setting.

  • Currently only works for String/Int/Boolean/Double values
  • Supports default values by looking for fields with the prefix 'default', and will reset unset values to their default if a default exists.
  • For more complex settings (e.g. proxy settings), there is a "onParsed()" callback which can be used to run additional code, and (in the case of the password widget) parse abnormal items.
  • Some of the settings code in FrameUtils.ParseProfile has already been commented out since it's handled by default with the new Settings package. The rest could be moved over to UserSettings.onParsed(). Given the number of settings that remain to be moved, it may be a good idea to add the possibility for setting-specific onParsed() callbacks (could be done quite easily, similarly to how default values are handled).
File size: 5.2 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 public static Method WebViewSetContextMenuEnabled;
28
29 public static Class<?> WebEngine;
30 public static Method WebEngineLoad;
31 public static Method WebEngineGetLocation;
32 public static Method WebEngineGetLoadWorker;
33 public static Method WebEngineGetHistory;
34 public static Method WebEngineReload;
35 public static Method WebEngineExecuteScript;
36
37 public static Class<?> WebHistory;
38 public static Method WebHistoryGo;
39
40 public static Class<?> Worker;
41 public static Method WorkerStateProperty;
42
43 public static Class<?> ReadOnlyObjectProperty;
44 public static Method ReadOnlyObjectPropertyAddListener;
45
46 public static Class<?> ChangeListener;
47
48 public static Class<?> ObservableValue;
49
50 public static Class<?> State;
51 public static List<?> StateConstants;
52
53 public static Class EventHandler;
54
55 public static Class Node;
56 public static Method NodeSetOnMouseClicked;
57
58 public static Class MouseEvent;
59 public static Method MouseEventGetButton;
60
61 public static Class MouseButton;
62
63 public static Class<?> JSObject;
64 public static Method JSObjectEval;
65 public static Method JSObjectCall;
66 public static Method JSObjectGetMember;
67 public static Method JSObjectGetSlot;
68
69 static {
70 String javaLibDir = System.getProperty("java.home") + File.separator + "lib" + File.separator;
71 try {
72 ClassLoader classLoader = ClassLoader.getSystemClassLoader();
73
74 File jar = new File(javaLibDir + "jfxrt.jar");
75
76 Method addURL = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
77 addURL.setAccessible(true);
78 addURL.invoke(classLoader, jar.toURI().toURL());
79
80 JFXPanel = Class.forName("javafx.embed.swing.JFXPanel", false, classLoader);
81
82 Platform = classLoader.loadClass("javafx.application.Platform");
83 PlatformRunLater = Platform.getMethod("runLater", Runnable.class);
84
85 // Setting JFX to not exit when all panels are hidden, otherwise moving, resizing and changing frames will
86 // cause JFX to exit, preventing JFX elements from displaying at all
87 Platform.getMethod("setImplicitExit", boolean.class).invoke(null, false);
88
89 Group = classLoader.loadClass("javafx.scene.Group");
90 GroupGetChildren = Group.getMethod("getChildren");
91
92 Scene = classLoader.loadClass("javafx.scene.Scene");
93 SceneConstructor = Scene.getConstructor(classLoader.loadClass("javafx.scene.Parent"));
94
95 WebView = classLoader.loadClass("javafx.scene.web.WebView");
96 JFXPanelSetScene = JFXPanel.getMethod("setScene", Scene);
97 WebViewSetPrefSize = WebView.getMethod("setPrefSize", double.class, double.class);
98 WebViewGetEngine = WebView.getMethod("getEngine");
99 WebViewSetContextMenuEnabled = WebView.getMethod("setContextMenuEnabled", boolean.class);
100
101 WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine");
102 WebEngineLoad = WebEngine.getMethod("load", String.class);
103 WebEngineGetLocation = WebEngine.getMethod("getLocation");
104 WebEngineGetLoadWorker = WebEngine.getMethod("getLoadWorker");
105 WebEngineGetHistory = WebEngine.getMethod("getHistory");
106 WebEngineReload = WebEngine.getMethod("reload");
107 WebEngineExecuteScript = WebEngine.getMethod("executeScript", String.class);
108
109 WebHistory = classLoader.loadClass("javafx.scene.web.WebHistory");
110 WebHistoryGo = WebHistory.getMethod("go", int.class);
111
112 Worker = classLoader.loadClass("javafx.concurrent.Worker");
113 WorkerStateProperty = Worker.getMethod("stateProperty");
114
115 ChangeListener = classLoader.loadClass("javafx.beans.value.ChangeListener");
116
117 ReadOnlyObjectProperty = classLoader.loadClass("javafx.beans.property.ReadOnlyObjectProperty");
118 ReadOnlyObjectPropertyAddListener = ReadOnlyObjectProperty.getMethod("addListener", ChangeListener);
119
120 ObservableValue = classLoader.loadClass("javafx.beans.value.ObservableValue");
121
122 State = classLoader.loadClass("javafx.concurrent.Worker$State");
123 StateConstants = Arrays.asList(State.getEnumConstants());
124
125 EventHandler = classLoader.loadClass("javafx.event.EventHandler");
126
127 Node = classLoader.loadClass("javafx.scene.Node");
128 NodeSetOnMouseClicked = Node.getMethod("setOnMouseClicked", EventHandler);
129
130 MouseEvent = classLoader.loadClass("javafx.scene.input.MouseEvent");
131 MouseEventGetButton = MouseEvent.getMethod("getButton");
132
133 MouseButton = classLoader.loadClass("javafx.scene.input.MouseButton");
134
135 JSObject = classLoader.loadClass("netscape.javascript.JSObject");
136 JSObjectEval = JSObject.getMethod("eval", String.class);
137 JSObjectCall = JSObject.getMethod("call", String.class, Object[].class);
138 JSObjectGetMember = JSObject.getMethod("getMember", String.class);
139 JSObjectGetSlot = JSObject.getMethod("getSlot", int.class);
140
141 } catch (Exception e) {
142 e.printStackTrace();
143 }
144 }
145}
Note: See TracBrowser for help on using the repository browser.