Changeset 733
- Timestamp:
- 01/21/14 17:16:40 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/WebParser.java
r713 r733 3 3 import java.awt.Color; 4 4 import java.awt.Font; 5 import java.awt. FontMetrics;5 import java.awt.Graphics; 6 6 import java.awt.image.BufferedImage; 7 7 import java.io.File; … … 14 14 15 15 import javax.imageio.ImageIO; 16 import javax.swing.JComponent; 16 17 17 18 import org.expeditee.gui.Frame; 19 import org.expeditee.gui.FrameCreator; 18 20 import org.expeditee.gui.FrameIO; 19 21 import org.expeditee.gui.FrameUtils; … … 25 27 import org.expeditee.items.Text; 26 28 import org.expeditee.reflection.JavaFX; 27 import org.w3c.dom.Element;28 29 import org.w3c.dom.Node; 29 30 import org.w3c.dom.html.HTMLBodyElement; … … 214 215 + "currentNode.parentElement.removeChild(currentNode);" 215 216 216 + "for (var i = 0; i < words.length; i++) {" + " addToSpan(words[i]);" 217 + "for (var i = 0; i < words.length; i++) {" 218 + " addToSpan(words[i]);" 217 219 + "}" 218 220 … … 221 223 + " par.removeChild(prevSpan);" 222 224 + "}" 223 );225 ); 224 226 225 227 // Will never reach 100% here, as the processing is not quite finished - progress is set to 100% at the end of … … 261 263 } 262 264 } 265 266 /** 267 * Converts a loaded page to Expeditee frame(s) 268 * 269 * @param webEngine 270 * The JavaFX WebEngine in which the page to be converted is loaded 271 * @param frame 272 * The Expeditee frame to output the converted page to 273 */ 274 public static void parsePageSimple(final Object webEngine, final Object webView, final JComponent jfxPanel, final Frame frame) { 275 try { 276 final Object notifier = new Object(); 277 final MutableBool notAtBottom = new MutableBool(true); 278 279 JavaFX.PlatformRunLater.invoke(null, new Runnable() { 280 @Override 281 public void run() { 282 try { 283 // Initializing the counter used when scrolling the page 284 JavaFX.WebEngineExecuteScript.invoke(webEngine, "var scrollCounter = 0"); 285 } catch (Exception ex) { 286 ex.printStackTrace(); 287 } 288 289 synchronized (notifier) { 290 notifier.notify(); 291 } 292 } 293 }); 294 295 synchronized (notifier) { 296 try { 297 // Waiting for the JavaFX thread to finish 298 notifier.wait(); 299 } catch (InterruptedException e) { 300 // TODO Auto-generated catch block 301 e.printStackTrace(); 302 } 303 } 304 305 int tick = 0; 306 Frame frameToAddTo = frame; 307 308 while (notAtBottom.getValue()) { 309 JavaFX.PlatformRunLater.invoke(null, new Runnable() { 310 @Override 311 public void run() { 312 try { 313 // Scrolling down the page 314 JavaFX.WebEngineExecuteScript.invoke(webEngine, "" 315 + "window.scrollTo(0, scrollCounter * window.innerHeight);" 316 + "scrollCounter = scrollCounter+1;"); 317 318 notAtBottom.setValue((boolean) JavaFX.WebEngineExecuteScript.invoke(webEngine, "(window.pageYOffset + window.innerHeight < document.documentElement.scrollHeight)")); 319 320 synchronized (notifier) { 321 notifier.notify(); 322 } 323 324 } catch (Exception e) { 325 e.printStackTrace(); 326 } 327 } 328 }); 329 330 synchronized (notifier) { 331 try { 332 // Waiting for the JavaFX thread to finish 333 notifier.wait(); 334 } catch (InterruptedException e) { 335 // TODO Auto-generated catch block 336 e.printStackTrace(); 337 } 338 } 339 340 BufferedImage image = new BufferedImage(jfxPanel.getWidth(), jfxPanel.getHeight(), BufferedImage.TYPE_INT_ARGB); 341 342 Graphics graphics = image.createGraphics(); 343 344 // Drawing the JfxPanel (containing the webview) to the image 345 jfxPanel.paint(graphics); 346 347 try { 348 int hashcode = Arrays.hashCode(image.getData().getPixels(0, 0, image.getWidth(), image.getHeight(), (int[]) null)); 349 350 File out = new File(FrameIO.IMAGES_PATH + "webpage-" + Integer.toHexString(hashcode) + ".png"); 351 out.mkdirs(); 352 ImageIO.write(image, "png", out); 353 354 Text link = new Text("Next"); 355 link.setPosition(500, 20); 356 frameToAddTo.addItem(link); 357 358 frameToAddTo = FrameIO.CreateFrame(frame.getFramesetName(), Integer.toHexString(hashcode), null); 359 360 link.setLink(frameToAddTo.getName()); 361 362 // Adding the image 363 frameToAddTo.addText(0, 0, "@i: " + out.getName(), null); 364 365 // Button to go to the next page 366 Text nextButton = (Text) FrameCreator.createButton("Next", null, null, 10F, 10F); 367 nextButton.setID(frameToAddTo.getNextItemID()); 368 nextButton.addAction("next"); 369 frameToAddTo.addItem(nextButton); 370 371 FrameIO.SaveFrame(frameToAddTo); 372 373 } catch (IOException e) { 374 e.printStackTrace(); 375 } 376 graphics.dispose(); 377 image.flush(); 378 379 System.out.println("C"); 380 381 synchronized (notifier) { 382 notifier.notify(); 383 } 384 385 tick = 0; 386 387 } 388 389 } catch (Exception ex) { 390 ex.printStackTrace(); 391 } 392 393 394 395 } 263 396 264 397 /** … … 755 888 pic.getSource().anchor(); 756 889 } 890 891 private static class MutableBool { 892 private boolean value; 893 894 public MutableBool(boolean value) { 895 this.value = value; 896 } 897 898 public boolean getValue() { 899 return value; 900 } 901 902 public void setValue(boolean value) { 903 this.value = value; 904 } 905 } 757 906 } -
trunk/src/org/expeditee/items/widgets/InteractiveWidget.java
r725 r733 1121 1121 * @param parent 1122 1122 */ 1123 pr ivatevoid layout(Component parent) {1123 protected void layout(Component parent) { 1124 1124 1125 1125 parent.validate(); -
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r655 r733 20 20 21 21 import javax.swing.JButton; 22 import javax.swing.JComponent; 22 23 import javax.swing.JLabel; 23 24 import javax.swing.JPanel; … … 92 93 toolBar.setFloatable(false); 93 94 94 95 95 JButton backButton = new JButton("Back"); 96 96 toolBar.add(backButton); … … 105 105 toolBar.add(convertButton); 106 106 107 JButton convertButtonNew = new JButton("Convert (New Method)"); 108 toolBar.add(convertButtonNew); 109 107 110 backButton.addActionListener(new ActionListener() { 108 111 @Override … … 123 126 public void actionPerformed(ActionEvent arg0) { 124 127 owner.getFrame(); 128 } 129 }); 130 131 convertButtonNew.addActionListener(new ActionListener() { 132 @Override 133 public void actionPerformed(ActionEvent arg0) { 134 owner.getFrameNew(); 125 135 } 126 136 }); … … 408 418 // Initial page is either the page stored in the arguments (if there is one stored) or the homepage 409 419 super(source, new WebBrowserPanel((args != null && args.length > 0) ? args[0] : NetworkSettings.HomePage.get()), -1, 500, -1, -1, 300, -1); 420 410 421 _browser = (WebBrowserPanel) _swingComponent; 411 422 _browser.owner = this; … … 555 566 } 556 567 568 public void getFrameNew() { 569 // this.setSize(1000, 100000); 570 // this._browser.setBounds(getX(), getY(), getWidth(), getHeight()); 571 572 // this.layout(this._browser); 573 try { 574 WebParser.parsePageSimple(JavaFX.WebViewGetEngine.invoke(this._browser.webview), this._browser.webview, (JComponent) this._browser.jfxPanel, DisplayIO.getCurrentFrame()); 575 } catch (Exception e) { 576 e.printStackTrace(); 577 } 578 } 579 557 580 /** 558 581 * Used to drop text items onto JfxBrowser widget. Does nothing if a text item is not attached to cursor. <br> -
trunk/src/org/expeditee/reflection/JavaFX.java
r628 r733 26 26 public static Method WebViewGetEngine; 27 27 public static Method WebViewSetContextMenuEnabled; 28 public static Method WebViewSnapshot; 29 30 public static Class<?> SnapshotParameters; 31 public static Class<?> WritableImage; 32 33 public static Class<?> Image; 34 35 public static Class<?> SwingFXUtils; 36 public static Method SwingFXUtilsFromFXImage; 28 37 29 38 public static Class<?> WebEngine; … … 95 104 SceneConstructor = Scene.getConstructor(classLoader.loadClass("javafx.scene.Parent")); 96 105 106 SnapshotParameters = classLoader.loadClass("javafx.scene.SnapshotParameters"); 107 WritableImage = classLoader.loadClass("javafx.scene.image.WritableImage"); 108 97 109 WebView = classLoader.loadClass("javafx.scene.web.WebView"); 98 110 JFXPanelSetScene = JFXPanel.getMethod("setScene", Scene); … … 100 112 WebViewGetEngine = WebView.getMethod("getEngine"); 101 113 WebViewSetContextMenuEnabled = WebView.getMethod("setContextMenuEnabled", boolean.class); 114 WebViewSnapshot = WebView.getMethod("snapshot", SnapshotParameters, WritableImage); 115 116 Image = classLoader.loadClass("javafx.scene.image.Image"); 117 118 SwingFXUtils = classLoader.loadClass("javafx.embed.swing.SwingFXUtils"); 119 SwingFXUtilsFromFXImage = SwingFXUtils.getMethod("fromFXImage", Image, java.awt.image.BufferedImage.class); 102 120 103 121 WebEngine = classLoader.loadClass("javafx.scene.web.WebEngine");
Note:
See TracChangeset
for help on using the changeset viewer.