Changeset 898
- Timestamp:
- 02/16/14 14:28:45 (10 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/WebParser.java
r897 r898 513 513 514 514 // Using Javascript to get an array of all the text nodes in the document so they can be wrapped in spans. Have to 515 // loop through twice (once to build the array and onceactually going through the array, otherwise when the515 // loop through twice (once here to build the array and once later actually going through the array, otherwise when the 516 516 // textnode is removed from the document items end up being skipped) 517 JSObject textNodes = (JSObject) webEngine.executeScript("" 518 + "function getTextNodes(rootNode){" 519 + "var node;" 520 + "var textNodes=[];" 521 + "var walk = document.createTreeWalker(rootNode, NodeFilter.SHOW_TEXT);" 522 + "while(node=walk.nextNode()) {" 517 webEngine.executeScript("" 518 + "var node;" 519 + "var textNodes=[];" 520 + "var walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);" 521 ); 522 523 while(webEngine.executeScript("node=walk.nextNode()") != null && browserWidget.isParserRunning()) { 524 525 webEngine.executeScript("" 523 526 + "if((node.textContent.trim().length > 0)) { " 524 527 + "textNodes.push(node);" 525 + "}" 526 + "}" 527 + "return textNodes;" 528 + "}; " 529 + "getTextNodes(document.body)" 528 + "}" 530 529 ); 531 530 } 531 532 JSObject textNodes = (JSObject) webEngine.executeScript("textNodes"); 533 532 534 int nodesLength = (Integer) textNodes.getMember("length"); 533 535 534 536 // Looping through all the text nodes in the document 535 for (int j = 0; j < nodesLength ; j++) {537 for (int j = 0; j < nodesLength && browserWidget.isParserRunning(); j++) { 536 538 Node currentNode = (Node) textNodes.getSlot(j); 537 539 … … 608 610 609 611 // Loop that scrolls the page horizontally 610 for(int i = 0; i < pagesHorizontal.getValue() ; i++) {612 for(int i = 0; i < pagesHorizontal.getValue() && browserWidget.isParserRunning(); i++) { 611 613 612 614 Platform.runLater(new Runnable() { … … 627 629 628 630 // Loop that scrolls the page vertically (for each horizontal scroll position) 629 for(int j = 0; j < pagesVertical.getValue() ; j++) {631 for(int j = 0; j < pagesVertical.getValue() && browserWidget.isParserRunning(); j++) { 630 632 631 633 try { … … 682 684 } 683 685 684 progressBar.set(100); 686 if(browserWidget.isParserRunning()) { 687 progressBar.set(100); 688 } else { 689 MessageBay.displayMessage("Web page conversion cancelled"); 690 } 691 692 browserWidget.parserFinished(); 685 693 686 694 Platform.runLater(new Runnable() { -
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r894 r898 10 10 */ 11 11 import java.awt.Point; 12 import java.awt.event.KeyListener; 12 13 import java.io.BufferedReader; 13 14 import java.io.IOException; … … 105 106 private StackPane _overlay; 106 107 108 private boolean _parserRunning; 109 107 110 private MouseButton _buttonDownId = MouseButton.NONE; 108 111 private MouseEvent _backupEvent = null; … … 129 132 130 133 _panel = (JFXPanel) _swingComponent; 134 135 // Quick & easy way of having a cancel function for the web parser. 136 // Can't just have a JFX button, as the JFX thread is occupied with running JavaScript so it wouldn't receive the click event straight away 137 _swingComponent.addKeyListener(new KeyListener() { 138 139 @Override 140 public void keyReleased(java.awt.event.KeyEvent e) { 141 if(e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) { 142 JfxBrowser.this.cancel(); 143 } 144 } 145 146 @Override 147 public void keyPressed(java.awt.event.KeyEvent e) { 148 } 149 150 @Override 151 public void keyTyped(java.awt.event.KeyEvent e) { 152 } 153 }); 131 154 132 155 Platform.runLater(new Runnable() { … … 838 861 839 862 public void getFrameNew() { 840 // this.setSize(1000, 1000); 841 // this._browser.setBounds(getX(), getY(), getWidth(), getHeight()); 842 // this.layout(this._browser); 843 863 864 this._parserRunning = true; 865 844 866 try { 845 867 // hack to make sure we don't try parsing the page from within the JavaFX thread, … … 852 874 } catch (Exception e) { 853 875 e.printStackTrace(); 876 this._parserRunning = false; 854 877 } 855 878 } … … 1106 1129 return (urlLower.startsWith("http://") || url.startsWith("https://") || urlLower.startsWith("ftp://") || urlLower.startsWith("file://")); 1107 1130 } 1131 1132 /** 1133 * @return Whether the parser is running. If this is true then the parser is running, 1134 * however even if it is false, the parser may still be running (but it has been requested to stop) 1135 */ 1136 public boolean isParserRunning() { 1137 return this._parserRunning; 1138 } 1139 1140 /** 1141 * Should be called when the web parser has finished converting a page 1142 */ 1143 public void parserFinished() { 1144 this._parserRunning = false; 1145 } 1146 1147 /** 1148 * Cancels the current action being performed by the browser, such as loading a page or converting a page 1149 */ 1150 public void cancel() { 1151 if(isParserRunning()) { 1152 this._parserRunning = false; 1153 } else { 1154 Platform.runLater(new Runnable() { 1155 1156 @Override 1157 public void run() { 1158 JfxBrowser.this._webEngine.getLoadWorker().cancel(); 1159 } 1160 }); 1161 } 1162 } 1108 1163 }
Note:
See TracChangeset
for help on using the changeset viewer.