JRubyFX

Hello…

Sorry if this isn´t the right place to post questions about JRubyFX.

I´m trying to write a JRubyFX application. I´m following a post from
Oracle to try to learn JavaFX and JRubyFx. In the post, in a js file
there
is the following lines:

// Complete initialization when page is loaded.
This.engine.loadWorker.stateProperty().addListener(new
ChangeListener() {

ChangeListener() is not found when I run the application. I understand
that I should load javafx/beans, but I don´t know how to do this with
JRubyFX. Can anybody help me here or point to the right list to ask
this
question?

Thanks

javafx.beans.value.ChangeListener is an interface so with implicit
closure
coercion you should be able to:

This.engine.load_worker.state_property.add_listener do |observable,
old_value, new_value|
  #...
end

-Tom

On Wed, Apr 29, 2015 at 11:42 AM, Rodrigo B. <

Hi Tom,

Not sure I follow… so, the following function is defined inside a
javascript file and not in a JRuby script. I can´t do this implicit
coercion. I think I should load the ChangeListener interface and make
it
available to javascript. I´m still learning all this, so I might just
be
confused. If this is any help, I´m just trying to follow the blog:
https://blogs.oracle.com/nashorn/entry/porting_from_the_browser_to, but
instead of using jjs, I´m driving nashorn through JRuby.

function WebViewWrapper(onload) {
var This = this;
var WebView = Java.type(“javafx.scene.web.WebView”);
var webview = new WebView();

This.webview = webview;
This.engine = webview.engine;
This.window = undefined;
This.document = undefined;

// Make sure the JavaScript is enabled.
This.engine.javaScriptEnabled = true;

// Complete initialization when page is loaded.
This.engine.loadWorker.stateProperty().addListener(new 

ChangeListener()
{
changed: function(value, oldState, newState) {
if (newState == Worker.State.SUCCEEDED) {
This.document =
wrap(This.engine.executeScript(“document”));
This.window = wrap(This.engine.executeScript(“window”));

            // Call users onload function.
            if (onload) {
                onload(This);
            }
        }
    }
});

Thanks…

2015-04-29 15:20 GMT-03:00 Thomas E Enebo [email protected]:

Tom,

No, this doesn´t work. Could I do a require in my Ruby code somehow?

require ‘javafx.beans.value.ChangeListener’ does not work as it is
expecting a jar file, right? Where is the jar for ChangeListener?

Thanks,

2015-04-29 15:36 GMT-03:00 Thomas E Enebo [email protected]:

I am less of a help for JS but if you see how WebView is defined above
you
can perhaps do he same thing for ChangeListener is your JS code is
barfing
because it does not know what that type is:

var ChangeListener = Java.type(“javafx.beans.value.ChangeListener”);

-Tom

On Wed, Apr 29, 2015 at 1:32 PM, Rodrigo B. <

Maybe I can help out.

I’ve been toying for months now with Nashorn (jjs) but when I use
Nashorn,
I only use jjs and do not embed the JS engine inside another java-based
interpreter.

1st: make sure your JDK8 is complete. It should not be the server JRE
but
the full JDK8.

2nd: to confirm javafx is included in your environment, try the
following
lines in jjs.

If javafx is not in your JDK8, you’ll see this:

jjs> Java.type(‘javafx.beans.value.ChangeListener’)
java.lang.RuntimeException: java.lang.ClassNotFoundException:
javafx.beans.value.ChangeListener

In that case, it’ll never work in jruby and you need to reinstall JDK8
properly.

This is how it should look like in jjs if javafx is included in your
environment:

jjs> Java.type(‘javafx.beans.value.ChangeListener’)
[JavaClass javafx.beans.value.ChangeListener]

Once this is ok, you just need to add the following line inside your
ruby
script (preferably after require ‘java’) :

include_class Java::JavafxBeansValue::ChangeListener

Good luck!

On Wed, Apr 29, 2015 at 8:51 PM, Rodrigo B. <

In case you still wish to require or have a look at the jar file
containing
the class ChangeListener, it’s $JAVA_HOME/jre/lib/ext/jfxrt.jar

On Thu, Apr 30, 2015 at 8:49 AM, Christian MICHON <

Hi Christian,

Thanks to your help and the others I managed to get things going.
Basically, I had to add to the LOAD_PATH << …/jre/lib/ext and then on
the
javascript file do:

load(“fx:base.js”)
load(“fx:controls.js”);
load(“fx:graphics.js”);
load(“fx:web.js”);

Thanks…

2015-04-30 3:56 GMT-03:00 Christian MICHON [email protected]: