Changeset 533 for trunk/src/org/expeditee/items/widgets
- Timestamp:
- 11/26/13 11:43:54 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r517 r533 7 7 import java.awt.event.ComponentListener; 8 8 import java.io.File; 9 import java.io.IOException; 9 10 import java.lang.reflect.Constructor; 10 11 import java.lang.reflect.InvocationTargetException; … … 16 17 17 18 import javax.swing.JPanel; 18 import javax.swing.border.EmptyBorder;19 19 20 20 import org.expeditee.items.Text; … … 25 25 * @author ngw8 26 26 * @author jts21 27 *28 27 */ 29 28 public class JfxBrowser extends DataFrameWidget { 30 31 29 private WebBrowserPanel _browser; 32 30 … … 52 50 static { 53 51 String javaLibDir = System.getProperty("java.home") + File.separator + "lib" + File.separator; 54 55 52 try { 56 53 System.out.println(javaLibDir); 57 54 ClassLoader classLoader = ClassLoader.getSystemClassLoader(); 55 58 56 59 57 File jar = new File(javaLibDir + "jfxrt.jar"); … … 63 61 addURL.invoke(classLoader, jar.toURI().toURL()); 64 62 65 63 System.out.println(System.getProperty("java.class.path")); 64 66 65 JFXPanel = Class.forName("javafx.embed.swing.JFXPanel", false, classLoader); 66 67 final File f = new File(JFXPanel.getProtectionDomain().getCodeSource().getLocation().getPath()); 68 System.out.println(f.getPath()); 67 69 68 70 Platform = classLoader.loadClass("javafx.application.Platform"); 69 71 PlatformRunLater = Platform.getMethod("runLater", Runnable.class); 72 73 // Setting JFX to not exit when all panels are hidden, otherwise moving, resizing and changing frames will 74 // cause JFX to exit, preventing JFX elements from displaying at all 75 Platform.getMethod("setImplicitExit", boolean.class).invoke(null, false); 70 76 71 77 Group = classLoader.loadClass("javafx.scene.Group"); … … 83 89 WebEngineLoad = WebEngine.getMethod("load", String.class); 84 90 91 85 92 } catch (MalformedURLException e) { 86 93 e.printStackTrace(); … … 96 103 e.printStackTrace(); 97 104 } catch (InvocationTargetException e) { 105 e.printStackTrace(); 106 } catch (IOException e) { 98 107 e.printStackTrace(); 99 108 } … … 118 127 this.add((Component) jfxPanel); 119 128 129 // Removing the gap between the top of the panel and the JFXPanel 120 130 ((FlowLayout) this.getLayout()).setVgap(0); 121 this.setBackground(Color.cyan); 122 this.setBorder(new EmptyBorder(0, 0, 0, 0)); 131 132 // Setting bg color to be the same as bg color of widgets when they're being dragged/resized 133 this.setBackground(new Color(100, 100, 100)); 123 134 124 135 PlatformRunLater.invoke(null, new Runnable() { … … 140 151 141 152 /** 142 * Sets up the browser frame. JFX requires itto be run on a new thread.153 * Sets up the browser frame. JFX requires this to be run on a new thread. 143 154 * 144 155 * @param url … … 147 158 private void initFx(String url) { 148 159 try { 149 Object group = Group.newInstance(); 150 Object scene = SceneConstructor.newInstance(group); 160 this.webview = WebView.newInstance(); 161 WebViewSetPrefSize.invoke(this.webview, this.getWidth(), this.getHeight()); 162 163 Object scene = SceneConstructor.newInstance(this.webview); 151 164 152 165 JFXPanelSetScene.invoke(jfxPanel, scene); 153 154 this.webview = WebView.newInstance();155 156 WebViewSetPrefSize.invoke(this.webview, this.getWidth(), this.getHeight());157 158 ((List) GroupGetChildren.invoke(group)).add(this.webview);159 166 160 167 WebEngineLoad.invoke(WebViewGetEngine.invoke(this.webview), url); … … 167 174 } catch (InstantiationException e) { 168 175 e.printStackTrace(); 176 } catch (SecurityException e) { 177 e.printStackTrace(); 169 178 } 170 179 } … … 180 189 @Override 181 190 public void componentResized(ComponentEvent e) { 191 // Webview is initialized in a 'run later' thread, so must check that it has actually been created before 192 // trying to resize 182 193 if (webview != null) { 183 194 try { … … 189 200 } catch (InvocationTargetException e1) { 190 201 e1.printStackTrace(); 202 } catch (SecurityException e1) { 203 e1.printStackTrace(); 191 204 } 192 205 } 193 194 206 } 195 207 … … 197 209 public void componentShown(ComponentEvent e) { 198 210 } 199 200 201 211 } 202 212 203 213 public JfxBrowser(Text source, String[] args) { 204 super(source, new WebBrowserPanel("http://waikato.ac.nz"), 100, 500, -1, 100, 300, -1);214 super(source, new WebBrowserPanel("http://waikato.ac.nz"), -1, 500, -1, -1, 300, -1); 205 215 206 216 _browser = (WebBrowserPanel) _swingComponent; 207 }208 209 @Override210 protected String[] getArgs() {211 return null;212 217 } 213 218 … … 222 227 e.printStackTrace(); 223 228 } 229 } 230 231 @Override 232 protected String[] getArgs() { 233 return null; 224 234 } 225 235 … … 236 246 return _textRepresentation.getData(); 237 247 } 238 239 248 }
Note:
See TracChangeset
for help on using the changeset viewer.