Forum: JRuby JRubyFX

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2015-04-29 18:45
(Received via mailing list)
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
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2015-04-29 20:22
(Received via mailing list)
javafx.beans.value.ChangeListener is an interface so with implicit
closure
coercion you should be able to:


```ruby
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 Botafogo <
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2015-04-29 20:34
(Received via mailing list)
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_fro..., 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 <tom.enebo@gmail.com>:
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2015-04-29 20:38
(Received via mailing list)
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 Botafogo <
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2015-04-29 20:53
(Received via mailing list)
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 <tom.enebo@gmail.com>:
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2015-04-30 08:51
(Received via mailing list)
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 Botafogo <
2c0c4cf3ccc8da22f7c3b9586ce1cd70?d=identicon&s=25 Christian MICHON (Guest)
on 2015-04-30 08:57
(Received via mailing list)
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 <
B97f192e676f1a67e0ef18f022671406?d=identicon&s=25 Rodrigo Botafogo (Guest)
on 2015-04-30 21:43
(Received via mailing list)
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 <christian.michon@gmail.com>:
This topic is locked and can not be replied to.