Changeset 897
- Timestamp:
- 02/16/14 00:38:14 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/WebParser.java
r889 r897 284 284 public static void parsePageSimple(final JfxBrowser browserWidget, final WebEngine webEngine, final WebView webView, final Frame frame) { 285 285 try { 286 287 final int verticalScrollPerPage = (int) (FrameGraphics.getMaxFrameSize().getHeight() * 0.85); 288 final int horizontalScrollPerPage = (int) (FrameGraphics.getMaxFrameSize().getWidth() * 0.85); 289 286 290 Platform.runLater(new Runnable() { 287 291 … … 289 293 public void run() { 290 294 browserWidget.setOverlayVisible(true); 291 browserWidget.setWebViewSize(FrameGraphics.getMaxFrameSize().getWidth() * 0.9, FrameGraphics.getMaxFrameSize().getHeight() * 0.9); 295 296 // Webview area is set to slightly larger than the size of a converted page, to give some overlap between each page 297 browserWidget.setWebViewSize(horizontalScrollPerPage * 1.1, verticalScrollPerPage * 1.1); 292 298 browserWidget.setScrollbarsVisible(false); 293 299 } … … 295 301 296 302 final Object notifier = new Object(); 297 298 final MutableBool bottomReached = new MutableBool(false); 299 final MutableBool rightReached = new MutableBool(false); 300 303 301 304 final MutableInt verticalCount = new MutableInt(0); 302 305 final MutableInt horizontalCount = new MutableInt(0); 306 307 final MutableInt pagesVertical = new MutableInt(1); 308 final MutableInt pagesHorizontal = new MutableInt(1); 303 309 304 310 final String pageTitle; … … 318 324 319 325 WebParser.addButton("Return to original frame", frame.getName(), null, 200, frameset, null, 0f, 10f, null); 320 321 326 322 327 Text link = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), pageTitle, null); … … 435 440 // Storing the current scroll position 436 441 + "var originalScrollX = window.pageXOffset;" 437 + "var originalScrollY = window.pageYOffset"); 438 439 440 442 + "var originalScrollY = window.pageYOffset;"); 443 444 window.setMember("horizontalScrollPerPage", horizontalScrollPerPage); 445 window.setMember("verticalScrollPerPage", verticalScrollPerPage); 446 447 448 449 // The scrollPerPage will always be less than the page's height, due to the overlap being added/allowed for between pages, 450 // but if the webpage fits in a single converted page, there's no need for any overlap, so just use 1 as the number of pages 451 if((Boolean) webEngine.executeScript("document.documentElement.scrollHeight > window.innerHeight")) { 452 pagesVertical.setValue((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollHeight") / (float) verticalScrollPerPage)); 453 } 454 455 if((Boolean) webEngine.executeScript("document.documentElement.scrollWidth > window.innerWidth")) { 456 pagesHorizontal.setValue((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollWidth") / (float) horizontalScrollPerPage)); 457 } 458 459 System.out.println(webEngine.executeScript("document.documentElement.scrollWidth") + "/" + horizontalScrollPerPage); 460 System.out.println(pagesVertical.getValue() + "x" + pagesHorizontal.getValue()); 461 441 462 // Setting up the element that contains the CSS to hide all text. Also hiding readability mode buttons. 442 463 // This is wiped before the text is converted, then re-added before taking the screenshot … … 543 564 try { 544 565 progressBar.set((50 * (j + 1)) / nodesLength); 545 } catch (ArrayIndexOutOfBoundsException e) { 566 } catch (Exception e) { 567 // Seems to be a bug somewhere along the line when updating the progressbar, so am catching any exception 568 // thrown here to avoid it stuffing up the rest of the parsing 546 569 e.printStackTrace(); 547 570 } … … 585 608 586 609 // Loop that scrolls the page horizontally 587 while (!rightReached.getValue()) { 588 bottomReached.setValue(false); 589 610 for(int i = 0; i < pagesHorizontal.getValue(); i++) { 611 590 612 Platform.runLater(new Runnable() { 591 613 @Override … … 595 617 webEngine.executeScript("" 596 618 + "scrollCounter = 0;" 597 + "window.scrollTo(scrollCounterHorizontal * 0.9 * window.innerWidth, 0);"619 + "window.scrollTo(scrollCounterHorizontal * horizontalScrollPerPage, 0);" 598 620 + "scrollCounterHorizontal = scrollCounterHorizontal+1;"); 599 600 rightReached.setValue((Boolean) webEngine.executeScript("(window.pageXOffset + window.innerWidth >= document.documentElement.scrollWidth)"));601 621 602 622 } catch (Exception e) { … … 607 627 608 628 // Loop that scrolls the page vertically (for each horizontal scroll position) 609 while (!bottomReached.getValue()) { 629 for(int j = 0; j < pagesVertical.getValue(); j++) { 630 631 try { 632 progressBar.set((int) (50 + ((float)(j+1)/(pagesVertical.getValue() * pagesHorizontal.getValue()) + ((float)(i) / pagesHorizontal.getValue())) * 50)); 633 } catch (Exception e) { 634 e.printStackTrace(); 635 } 636 610 637 Platform.runLater(new Runnable() { 611 638 @Override … … 614 641 // Scrolling down the page 615 642 webEngine.executeScript("" 616 + "window.scrollTo(window.pageXOffset, scrollCounter * 0.9 * window.innerHeight);"643 + "window.scrollTo(window.pageXOffset, scrollCounter * verticalScrollPerPage);" 617 644 + "scrollCounter = scrollCounter+1;"); 618 619 bottomReached.setValue((Boolean) webEngine.executeScript("(window.pageYOffset + window.innerHeight >= document.documentElement.scrollHeight)"));620 645 621 646 synchronized (notifier) {
Note:
See TracChangeset
for help on using the changeset viewer.