sundar@1352: #// Usage: jjs -fx browser_dom.js sundar@1120: sundar@1120: /* sundar@1120: * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. sundar@1120: * sundar@1120: * Redistribution and use in source and binary forms, with or without sundar@1120: * modification, are permitted provided that the following conditions sundar@1120: * are met: sundar@1120: * sundar@1120: * - Redistributions of source code must retain the above copyright sundar@1120: * notice, this list of conditions and the following disclaimer. sundar@1120: * sundar@1120: * - Redistributions in binary form must reproduce the above copyright sundar@1120: * notice, this list of conditions and the following disclaimer in the sundar@1120: * documentation and/or other materials provided with the distribution. sundar@1120: * sundar@1120: * - Neither the name of Oracle nor the names of its sundar@1120: * contributors may be used to endorse or promote products derived sundar@1120: * from this software without specific prior written permission. sundar@1120: * sundar@1120: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS sundar@1120: * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, sundar@1120: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR sundar@1120: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR sundar@1120: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, sundar@1120: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, sundar@1120: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR sundar@1120: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF sundar@1120: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING sundar@1120: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS sundar@1120: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. sundar@1120: */ sundar@1120: sundar@1120: if (!$OPTIONS._fx) { sundar@1352: print("Usage: jjs -fx browser_dom.js"); sundar@1120: exit(1); sundar@1120: } sundar@1120: sundar@1120: // JavaFX classes used sundar@1120: var ChangeListener = Java.type("javafx.beans.value.ChangeListener"); sundar@1120: var Scene = Java.type("javafx.scene.Scene"); sundar@1120: var WebView = Java.type("javafx.scene.web.WebView"); sundar@1120: sundar@1120: // JavaFX start method sundar@1120: function start(stage) { sundar@1120: start.title = "Web View"; sundar@1120: var wv = new WebView(); sundar@1120: wv.engine.loadContent(< sundar@1120: sundar@1120: sundar@1120: This is the title sundar@1120: sundar@1120: sundar@1120: sundar@1120: sundar@1120: Button from the input html
sundar@1120:
sundar@1120: sundar@1120: sundar@1120: EOF, "text/html"); sundar@1120: sundar@1120: // attach onload handler sundar@1120: wv.engine.loadWorker.stateProperty().addListener( sundar@1120: new ChangeListener() { sundar@1120: changed: function() { sundar@1120: // DOM document element sundar@1120: var document = wv.engine.document; sundar@1120: // DOM manipulation sundar@1120: var btn = document.createElement("button"); sundar@1120: var n = 0; sundar@1120: // attach a button handler - nashorn function! sundar@1352: btn.onclick = function() { sundar@1120: n++; print("You clicked " + n + " time(s)"); sundar@1120: print("you clicked OK " + wv.engine.executeScript("okCount")); sundar@1352: }; sundar@1120: // attach text to button sundar@1120: var t = document.createTextNode("Click Me!"); sundar@1120: btn.appendChild(t); sundar@1120: // attach button to the document sundar@1120: document.body.appendChild(btn); sundar@1120: } sundar@1120: } sundar@1120: ); sundar@1120: stage.scene = new Scene(wv, 750, 500); sundar@1120: stage.show(); sundar@1120: }