Changeset 541
- Timestamp:
- 11/27/13 12:24:38 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r540 r541 7 7 import java.awt.event.ComponentListener; 8 8 import java.io.File; 9 import java.io.IOException;10 9 import java.lang.reflect.Constructor; 11 10 import java.lang.reflect.InvocationTargetException; 12 11 import java.lang.reflect.Method; 13 import java.net.MalformedURLException;14 12 import java.net.URL; 15 13 import java.net.URLClassLoader; 14 import java.util.Arrays; 15 import java.util.List; 16 16 17 17 import javax.swing.JPanel; 18 18 19 19 import org.expeditee.gui.FreeItems; 20 import org.expeditee.gui.MessageBay; 20 21 import org.expeditee.items.Text; 21 22 … … 44 45 static Method WebViewSetPrefSize; 45 46 static Method WebViewGetEngine; 46 47 47 48 static Class WebEngine; 48 49 static Method WebEngineLoad; 49 50 static Method WebEngineGetLocation; 51 static Method WebEngineGetLoadWorker; 52 53 static Class Worker; 54 static Method WorkerStateProperty; 55 56 static Class ReadOnlyObjectProperty; 57 static Method ReadOnlyObjectPropertyAddListener; 58 59 static Class ChangeListener; 60 61 static Class ObservableValue; 62 63 static Class State; 64 static List<Object> StateConstants; 50 65 51 66 static { … … 54 69 ClassLoader classLoader = ClassLoader.getSystemClassLoader(); 55 70 56 57 71 File jar = new File(javaLibDir + "jfxrt.jar"); 58 72 … … 80 94 WebViewSetPrefSize = WebView.getMethod("setPrefSize", double.class, double.class); 81 95 WebViewGetEngine = WebView.getMethod("getEngine"); 82 96 83 97 WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine"); 84 98 WebEngineLoad = WebEngine.getMethod("load", String.class); 85 99 WebEngineGetLocation = WebEngine.getMethod("getLocation"); 86 87 88 } catch (MalformedURLException e) { 100 WebEngineGetLoadWorker = WebEngine.getMethod("getLoadWorker"); 101 102 Worker = classLoader.loadClass("javafx.concurrent.Worker"); 103 WorkerStateProperty = Worker.getMethod("stateProperty"); 104 105 ChangeListener = classLoader.loadClass("javafx.beans.value.ChangeListener"); 106 107 ReadOnlyObjectProperty = classLoader.loadClass("javafx.beans.property.ReadOnlyObjectProperty"); 108 ReadOnlyObjectPropertyAddListener = ReadOnlyObjectProperty.getMethod("addListener", ChangeListener); 109 110 ObservableValue = classLoader.loadClass("javafx.beans.value.ObservableValue"); 111 112 State = classLoader.loadClass("javafx.concurrent.Worker$State"); 113 StateConstants = Arrays.asList(State.getEnumConstants()); 114 System.out.println(StateConstants); 115 116 } catch (Exception e) { 89 117 e.printStackTrace(); 90 } catch (ClassNotFoundException e) {91 e.printStackTrace();92 } catch (NoSuchMethodException e) {93 e.printStackTrace();94 } catch (SecurityException e) {95 e.printStackTrace();96 } catch (IllegalAccessException e) {97 e.printStackTrace();98 } catch (IllegalArgumentException e) {99 e.printStackTrace();100 } catch (InvocationTargetException e) {101 e.printStackTrace();102 } catch (IOException e) {103 e.printStackTrace();104 118 } 105 119 } 106 120 107 121 private static class WebBrowserPanel extends JPanel implements ComponentListener { 108 122 109 123 private static final long serialVersionUID = 1L; 110 124 111 125 Object webview; 112 126 Object jfxPanel; 113 127 114 128 /** 115 * @return A JPanel that either contains a JavaFX Webview or an empty 116 * panel if the JFX panel can't beinitialized129 * @return A JPanel that either contains a JavaFX Webview or an empty panel if the JFX panel can't be 130 * initialized 117 131 */ 118 132 public WebBrowserPanel(final String url) { … … 160 174 161 175 JFXPanelSetScene.invoke(jfxPanel, scene); 176 177 ReadOnlyObjectPropertyAddListener.invoke(WorkerStateProperty.invoke(WebEngineGetLoadWorker 178 .invoke(WebViewGetEngine.invoke(this.webview))), java.lang.reflect.Proxy.newProxyInstance( 179 ChangeListener.getClassLoader(), new java.lang.Class[] { ChangeListener }, 180 new java.lang.reflect.InvocationHandler() { 181 @Override 182 public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) 183 throws java.lang.Throwable { 184 String method_name = method.getName(); 185 // Class<?>[] classes = method.getParameterTypes(); 186 // public void changed(ObservableValue ov, State oldState, State newState) 187 if (method_name.equals("changed")) { 188 // changed takes 3 args 189 if (args == null || args.length != 3) { 190 return null; 191 } 192 // args[0] is the ObservableValue 193 System.out.println(args[0]); 194 System.out.println(args[0].getClass()); 195 // args[2] is the new State 196 if (args[2].getClass() == State) { 197 int id = StateConstants.indexOf(args[2]); 198 switch (id) { 199 case 0: // READY 200 MessageBay.displayMessage("WebEngine ready"); 201 break; 202 case 1: // SCHEDULED 203 MessageBay.displayMessage("Scheduled page load"); 204 break; 205 case 2: // RUNNING 206 MessageBay.displayMessage("WebEngine running"); 207 break; 208 case 3: // SUCCEEDED 209 MessageBay.displayMessage("Finished loading page"); 210 break; 211 case 4: // CANCELLED 212 MessageBay.displayMessage("Cancelled loading page"); 213 break; 214 case 5: // FAILED 215 MessageBay.displayMessage("Failed to load page"); 216 break; 217 } 218 } 219 System.out.println("\n"); 220 } 221 return null; 222 } 223 })); 224 225 // webEngine.getLoadWorker().stateProperty().addListener( 226 // new ChangeListener<State>() { 227 // public void changed(ObservableValue ov, State oldState, State newState) { 228 // if (newState == State.SUCCEEDED) { 229 // stage.setTitle(webEngine.getLocation()); 230 // } 231 // } 232 // }); 162 233 163 234 WebEngineLoad.invoke(WebViewGetEngine.invoke(this.webview), url); … … 209 280 public JfxBrowser(Text source, String[] args) { 210 281 // Initial page is either the page stored in the arguments (if there is one stored) or Google 211 //super(source, new WebBrowserPanel((args != null && args.length > 0) ? args[0] : "http://google.com"), -1, 500, -1, -1, 300, -1); 282 283 // super(source, new WebBrowserPanel((args != null && args.length > 0) ? args[0] : "http://google.com"), -1, 500, -1, -1, 300, -1); 212 284 super(source, new WebBrowserPanel(args[0]), -1, 500, -1, -1, 300, -1); 213 285 _browser = (WebBrowserPanel) _swingComponent; … … 231 303 } 232 304 } 233 305 234 306 @Override 235 307 public boolean ItemsLeftClickDropped() { 236 308 Text carried = null; 237 if ((carried = FreeItems.getTextAttachedToCursor()) != null) {309 if ((carried = FreeItems.getTextAttachedToCursor()) != null) { 238 310 this.navigate(carried.getText()); 239 311 return true;
Note:
See TracChangeset
for help on using the changeset viewer.