Changeset 560 for trunk/src/org/expeditee/items/widgets
- Timestamp:
- 12/02/13 14:51:52 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r557 r560 30 30 import javax.swing.text.BadLocationException; 31 31 32 import org.apache.xerces.impl.xs.opti.NamedNodeMapImpl; 32 33 import org.expeditee.gui.DisplayIO; 33 34 import org.expeditee.gui.FrameMouseActions; … … 37 38 import org.expeditee.items.Item; 38 39 import org.expeditee.items.Text; 40 import org.jfree.chart.labels.IntervalCategoryItemLabelGenerator; 41 import org.w3c.dom.Document; 42 import org.w3c.dom.Element; 43 import org.w3c.dom.Node; 44 import org.w3c.dom.NodeList; 45 import org.w3c.dom.css.CSSStyleDeclaration; 39 46 40 47 /** … … 75 82 static Method WebEngineGetHistory; 76 83 static Method WebEngineReload; 77 //static Method WebEngineGetDocument;84 static Method WebEngineExecuteScript; 78 85 79 86 static Class WebHistory; … … 92 99 static Class State; 93 100 static List<Object> StateConstants; 101 102 static Class JSObject; 103 static Method JSObejctEval; 104 static Method JSObejctCall; 105 static Method JSObejctGetMember; 94 106 95 107 static { … … 130 142 WebEngineGetHistory = WebEngine.getMethod("getHistory"); 131 143 WebEngineReload = WebEngine.getMethod("reload"); 144 WebEngineExecuteScript = WebEngine.getMethod("executeScript", String.class); 132 145 133 146 WebHistory = classLoader.loadClass("javafx.scene.web.WebHistory"); … … 146 159 State = classLoader.loadClass("javafx.concurrent.Worker$State"); 147 160 StateConstants = Arrays.asList(State.getEnumConstants()); 161 162 JSObject = classLoader.loadClass("netscape.javascript.JSObject"); 163 JSObejctEval = JSObject.getMethod("eval", String.class); 164 JSObejctCall = JSObject.getMethod("call", String.class, Object[].class); 165 JSObejctGetMember = JSObject.getMethod("getMember", String.class); 148 166 149 167 } catch (Exception e) { … … 194 212 toolBar.add(urlField); 195 213 214 JButton convertButton = new JButton("Convert"); 215 toolBar.add(convertButton); 216 196 217 backButton.addActionListener(new ActionListener() { 197 218 @Override … … 205 226 public void actionPerformed(ActionEvent arg0) { 206 227 owner.navigateForward(); 228 } 229 }); 230 231 convertButton.addActionListener(new ActionListener() { 232 @Override 233 public void actionPerformed(ActionEvent arg0) { 234 owner.getFrame(); 207 235 } 208 236 }); … … 585 613 */ 586 614 public void getFrame() { 587 MessageBay.displayMessage("I haven't been implemented yet");588 615 try { 616 // Reference to the webEngine, to make it easier/possible to get to it inside the run() 589 617 final Object webEngine = WebViewGetEngine.invoke(this._browser.webview); 590 618 591 619 try { 592 620 PlatformRunLater.invoke(null, new Runnable() { … … 594 622 public void run() { 595 623 try { 596 // TODO: parse html to get expeditee frame 624 Document doc = (Document) WebEngineExecuteScript.invoke(webEngine, "document"); 625 Object window = WebEngineExecuteScript.invoke(webEngine, "window"); 626 NodeList nodes = doc.getElementsByTagName("*"); 627 System.out.println(nodes.getLength()); 628 629 Element e; 630 Object bounds; 631 float x, y; 632 633 for (int i = 0; i < nodes.getLength(); i++) { 634 e = (Element) nodes.item(i); 635 bounds = JSObejctCall.invoke(e, "getBoundingClientRect", new Object[] {}); 636 637 x = Float.valueOf(JSObejctGetMember.invoke(bounds, "left").toString()) + Float.valueOf(WebEngineExecuteScript.invoke(webEngine, "window.pageXOffset").toString()); 638 y = Float.valueOf(JSObejctGetMember.invoke(bounds, "top").toString()) + Float.valueOf(WebEngineExecuteScript.invoke(webEngine, "window.pageYOffset").toString()); 639 640 System.out.println(y + " " + e.toString()); 641 642 Object style = JSObejctCall.invoke(window, "getComputedStyle", new Object[] { e }); 643 String color = (String) JSObejctCall.invoke(style, "getPropertyValue", new Object[] { "color" }); 644 645 color = color.substring(4, color.length() - 1); 646 647 String[] colors = color.split(", "); 648 649 650 651 Text t = DisplayIO.getCurrentFrame().createNewText("x"); 652 t.setPosition(x, y); 653 654 t.setColor(new Color(Integer.valueOf(colors[0]), Integer.valueOf(colors[1]), Integer.valueOf(colors[2]))); 655 656 } 657 658 // Object img = JSObejctCall.invoke(logo, "getBoundingClientRect", new Object[] {}); 659 // System.out.println((int) WebEngineExecuteScript.invoke(webEngine, "window.pageYOffset") 660 // + (int) WebEngineExecuteScript.invoke(webEngine, 661 // "document.getElementById('hplogo').getBoundingClientRect().top")); 662 597 663 } catch (Exception e) { 598 664 e.printStackTrace(); 599 665 } 666 667 // while(elem && !isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)) { 668 // xl_ += elem.offsetLeft - elem.scrollLeft; 669 // yt_ += elem.offsetTop - elem.scrollTop; 670 // lem = elem.offsetParent; 671 // } 600 672 } 601 673 }); … … 609 681 610 682 /** 611 * Used to drop text items onto JfxBrowser widget. Does nothing if a text item is not attached to cursor. 612 * "back" -> navigates back a page in browser's session history 613 * "forward" -> navigates forward a page in browser's session history 614 * "refresh" -> reloads current page 615 * "getFrame" -> attempts to parse page into an expeditee frame 616 * url -> all other text is assumed to be a url which browser attempts to navigate to 617 * return Whether a JfxBrowser specific event is run. 683 * Used to drop text items onto JfxBrowser widget. Does nothing if a text item is not attached to cursor. <br> 684 * "back" -> navigates back a page in browser's session history <br> 685 * "forward" -> navigates forward a page in browser's session history <br> 686 * "refresh" -> reloads current page <br> 687 * "getFrame" -> attempts to parse page into an expeditee frame <br> 688 * url -> all other text is assumed to be a url which browser attempts to navigate to 689 * 690 * @return Whether a JfxBrowser specific event is run. 691 * 618 692 */ 619 693 @Override
Note:
See TracChangeset
for help on using the changeset viewer.