Re: [jruby-user] JRubyFX
Rodrigo Botafogo <[email protected]> Thu, 30 Apr 2015 16:41:25 -0300
| Newsgroups | gmane.comp.lang.jruby.user |
|---|---|
| Message-ID | <CAAKc=GCwA5NEgBmf2nJU2SWvpg-Ev_X7T_nB2w_Y=4uhwmbwHw@mail.gmail.com> |
--001a11c318de2991750514f6498a
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
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]>:
> 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.ja=
r
>
> On Thu, Apr 30, 2015 at 8:49 AM, Christian MICHON <
> [email protected]> wrote:
>
>> 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 bu=
t
>> the full JDK8.
>>
>> 2nd: to confirm javafx is included in your environment, try the followin=
g
>> 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 rub=
y
>> script (preferably after require 'java') :
>>
>> include_class Java::JavafxBeansValue::ChangeListener
>>
>> Good luck!
>>
>> On Wed, Apr 29, 2015 at 8:51 PM, Rodrigo Botafogo <
>> [email protected]> wrote:
>>
>>> Tom,
>>>
>>> No, this doesn=C2=B4t work. Could I do a require in my Ruby code someh=
ow?
>>>
>>> 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 =3D Java.type("javafx.beans.value.ChangeListener");
>>>>
>>>> -Tom
>>>>
>>>> On Wed, Apr 29, 2015 at 1:32 PM, Rodrigo Botafogo <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi Tom,
>>>>>
>>>>> Not sure I follow... so, the following function is defined inside a
>>>>> javascript file and not in a JRuby script. I can=C2=B4t do this impl=
icit
>>>>> coercion. I think I should load the ChangeListener interface and mak=
e it
>>>>> available to javascript. I=C2=B4m still learning all this, so I migh=
t just be
>>>>> confused. If this is any help, I=C2=B4m just trying to follow the bl=
og:
>>>>> https://blogs.oracle.com/nashorn/entry/porting_from_the_browser_to,
>>>>> but instead of using jjs, I=C2=B4m driving nashorn through JRuby.
>>>>>
>>>>>
>>>>> function WebViewWrapper(onload) {
>>>>> var This =3D this;
>>>>> var WebView =3D Java.type("javafx.scene.web.WebView");
>>>>> var webview =3D new WebView();
>>>>>
>>>>> This.webview =3D webview;
>>>>> This.engine =3D webview.engine;
>>>>> This.window =3D undefined;
>>>>> This.document =3D undefined;
>>>>>
>>>>> // Make sure the JavaScript is enabled.
>>>>> This.engine.javaScriptEnabled =3D true;
>>>>>
>>>>> // Complete initialization when page is loaded.
>>>>> This.engine.loadWorker.stateProperty().addListener(new
>>>>> ChangeListener() {
>>>>> changed: function(value, oldState, newState) {
>>>>> if (newState =3D=3D Worker.State.SUCCEEDED) {
>>>>> This.document =3D
>>>>> wrap(This.engine.executeScript("document"));
>>>>> This.window =3D
>>>>> 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]>:
>>>>>
>>>>> 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 <
>>>>>> [email protected]> wrote:
>>>>>>
>>>>>>> Hello....
>>>>>>>
>>>>>>> Sorry if this isn=C2=B4t the right place to post questions about JR=
ubyFX.
>>>>>>>
>>>>>>>
>>>>>>> I=C2=B4m trying to write a JRubyFX application. I=C2=B4m 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 ChangeList=
ener() {
>>>>>>>
>>>>>>>
>>>>>>> ChangeListener() is not found when I run the application. I
>>>>>>> understand that I should load javafx/beans, but I don=C2=B4t know h=
ow to do this
>>>>>>> with JRubyFX. Can anybody help me here or point to the right list =
to ask
>>>>>>> this question?
>>>>>>>
>>>>>>> Thanks
>>>>>>> --
>>>>>>> Rodrigo Botafogo
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> blog: http://blog.enebo.com twitter: tom_enebo
>>>>>> mail: [email protected]
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Rodrigo Botafogo
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> blog: http://blog.enebo.com twitter: tom_enebo
>>>> mail: [email protected]
>>>>
>>>
>>>
>>>
>>> --
>>> Rodrigo Botafogo
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Christian
>>
>
>
>
> --
> Christian
>
--=20
Rodrigo Botafogo
--001a11c318de2991750514f6498a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi Christian,<div><br></div><div>Thanks to your help and t=
he others I managed to get things going.=C2=A0 Basically, I had to add to t=
he LOAD_PATH << .../jre/lib/ext and then on the javascript file do:=
=C2=A0</div><div><br></div><div><div>load("fx:base.js")</div><div=
>load("fx:controls.js");</div><div>load("fx:graphics.js"=
;);</div><div>load("fx:web.js");</div></div><div><br></div><div>T=
hanks....</div><div><br></div><div><br></div></div><div class=3D"gmail_extr=
a"><br><div class=3D"gmail_quote">2015-04-30 3:56 GMT-03:00 Christian MICHO=
N <span dir=3D"ltr"><<a href=3D"mailto:[email protected]" targe=
t=3D"_blank">[email protected]</a>></span>:<br><blockquote clas=
s=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pad=
ding-left:1ex"><div dir=3D"ltr">In case you still wish to require or have a=
look at the jar file containing the class ChangeListener, it's $JAVA_H=
OME/jre/lib/ext/jfxrt.jar</div><div class=3D"gmail_extra"><div><div class=
=3D"h5"><br><div class=3D"gmail_quote">On Thu, Apr 30, 2015 at 8:49 AM, Chr=
istian MICHON <span dir=3D"ltr"><<a href=3D"mailto:christian.michon@gmai=
l.com" target=3D"_blank">[email protected]</a>></span> wrote:<b=
r><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:=
1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Maybe I can help out.<div=
><br></div><div>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 an=
other java-based interpreter.<div><br></div><div>1st: make sure your JDK8 i=
s complete. It should not be the server JRE but the full JDK8.</div><div><b=
r></div><div>2nd: to confirm javafx is included in your environment, try th=
e following lines in jjs.</div><div><br></div><div>If javafx is not in your=
JDK8, you'll see this:</div><div><br></div><div><div>jjs> Java.type=
('javafx.beans.value.ChangeListener')<br></div><div>java.lang.Runti=
meException: java.lang.ClassNotFoundException: javafx.beans.value.ChangeLis=
tener</div></div><div><br></div><div>In that case, it'll never work in =
jruby and you need to reinstall JDK8 properly.</div><div><br></div><div>Thi=
s is how it should look like in jjs if javafx is included in your environme=
nt:</div><div><br></div><div><div>jjs> Java.type('javafx.beans.value=
.ChangeListener')<br></div><div>[JavaClass javafx.beans.value.ChangeLis=
tener]</div></div><div><br></div><div>Once this is ok, you just need to add=
the following line inside your ruby script (preferably after require '=
java') :</div></div><div><br></div><div>include_class Java::JavafxBeans=
Value::ChangeListener<br></div><div><br></div><div>Good luck!</div></div><d=
iv class=3D"gmail_extra"><div><div><br><div class=3D"gmail_quote">On Wed, A=
pr 29, 2015 at 8:51 PM, Rodrigo Botafogo <span dir=3D"ltr"><<a href=3D"m=
ailto:[email protected]" target=3D"_blank">rodrigo@rodrigobotafog=
o.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr">Tom,<div><br></div><div>No, this doesn=C2=B4t work.=C2=A0 Could I do a =
require in my Ruby code somehow?=C2=A0</div><div><br></div><div>require =
9;javafx.beans.value.ChangeListener' does not work as it is expecting a=
jar file, right?=C2=A0 Where is the jar for ChangeListener?</div><div><br>=
</div><div><br></div><div>Thanks,</div></div><div class=3D"gmail_extra"><br=
><div class=3D"gmail_quote">2015-04-29 15:36 GMT-03:00 Thomas E Enebo <span=
dir=3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blank">t=
[email protected]</a>></span>:<div><div><br><blockquote class=3D"gmail_=
quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1=
ex"><div dir=3D"ltr"><div><div>I am less of a help for JS but if you see ho=
w WebView is defined above you can perhaps do he same thing for ChangeListe=
ner is your JS code is barfing because it does not know what that type is:<=
br><br></div>var ChangeListener =3D Java.type("javafx.beans.value.Chan=
geListener");<br><br></div>-Tom<br></div><div><div><div class=3D"gmail=
_extra"><br><div class=3D"gmail_quote">On Wed, Apr 29, 2015 at 1:32 PM, Rod=
rigo Botafogo <span dir=3D"ltr"><<a href=3D"mailto:rodrigo@rodrigobotafo=
go.com" target=3D"_blank">[email protected]</a>></span> wrote:=
<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-lef=
t:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi Tom,<div><br></div><=
div>Not sure I follow... so, the following function is defined inside a jav=
ascript file and not in a JRuby script.=C2=A0 I can=C2=B4t do this implicit=
coercion.=C2=A0 I think I should load the ChangeListener interface and mak=
e it available to javascript.=C2=A0 I=C2=B4m still learning all this, so I =
might just be confused.=C2=A0 If this is any help, I=C2=B4m just trying to =
follow the blog:=C2=A0<a href=3D"https://blogs.oracle.com/nashorn/entry/por=
ting_from_the_browser_to" target=3D"_blank">https://blogs.oracle.com/nashor=
n/entry/porting_from_the_browser_to</a>, but instead of using jjs, I=C2=B4m=
driving nashorn through JRuby.</div><div><br></div><div><br></div><div><di=
v>function WebViewWrapper(onload) {</div><div>=C2=A0 =C2=A0 var This =3D th=
is;</div><div>=C2=A0 =C2=A0 var WebView =3D Java.type("javafx.scene.we=
b.WebView");</div><div>=C2=A0 =C2=A0 var webview =3D new WebView();</d=
iv><div>=C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 This.webview =3D webvie=
w;</div><div>=C2=A0 =C2=A0 This.engine =3D webview.engine;</div><div>=C2=A0=
=C2=A0 This.window =3D undefined;</div><div>=C2=A0 =C2=A0 This.document =
=3D undefined;</div><div>=C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 // Mak=
e sure the JavaScript is enabled.</div><div>=C2=A0 =C2=A0 This.engine.javaS=
criptEnabled =3D true;</div><span><div>=C2=A0 =C2=A0=C2=A0</div><div>=C2=A0=
=C2=A0 // Complete initialization when page is loaded.</div><div>=C2=A0 =
=C2=A0 This.engine.loadWorker.stateProperty().addListener(new ChangeListene=
r() {</div></span><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 changed: function(value,=
oldState, newState) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
if (newState =3D=3D Worker.State.SUCCEEDED) {</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 This.document =3D wrap(This.engine.e=
xecuteScript("document"));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 This.window =3D wrap(This.engine.executeScript(=
"window"));</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 // Call users onload function.</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (onload) {</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 onload(This);</div>=
<div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 }</div><div>=C2=A0 =C2=A0 });</div></div><div><br></div><div><br></d=
iv><div>Thanks....</div></div><div class=3D"gmail_extra"><br><div class=3D"=
gmail_quote">2015-04-29 15:20 GMT-03:00 Thomas E Enebo <span dir=3D"ltr">&l=
t;<a href=3D"mailto:[email protected]" target=3D"_blank">tom.enebo@gmail.=
com</a>></span>:<div><div><br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr"><div><div><div>javafx.beans.value.ChangeListener is an interface so w=
ith implicit closure coercion you should be able to:<br></div><div><br><br>=
</div>```ruby<br></div>This.engine.load_worker.state_property.add_listener =
do |<code>observable, old_value, new_value|<br>=C2=A0 #...<br></code></div>=
<code>end<br></code><div><div>```<br><br></div><div>-Tom<br><br></div></div=
></div><div class=3D"gmail_extra"><div><div><br><div class=3D"gmail_quote">=
On Wed, Apr 29, 2015 at 11:42 AM, Rodrigo Botafogo <span dir=3D"ltr"><<a=
href=3D"mailto:[email protected]" target=3D"_blank">rodrigo@rodr=
igobotafogo.com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><di=
v dir=3D"ltr">Hello....=C2=A0<div><br></div><div>Sorry if this isn=C2=B4t t=
he right place to post questions about JRubyFX. =C2=A0</div><div><br></div>=
<div>I=C2=B4m trying to write a JRubyFX application.=C2=A0 I=C2=B4m followi=
ng a post from Oracle to try to learn JavaFX and JRubyFx.=C2=A0 In the post=
, in a js file there is the following lines:</div><div><br></div><div><pre =
style=3D"margin-top:10px;margin-bottom:10px;color:rgb(85,85,85);font-size:1=
2px;line-height:18px"> // Complete initialization when page is loaded.
This.engine.loadWorker.stateProperty().addListener(new ChangeListener()=
=C2=A0{</pre><pre style=3D"margin-top:10px;margin-bottom:10px;color:rgb(85,=
85,85);font-size:12px;line-height:18px"><br></pre><div>ChangeListener() is =
not found when I run the application.=C2=A0 I understand that I should load=
javafx/beans, but I don=C2=B4t know how to do this with JRubyFX.=C2=A0 Can=
anybody help me here or point to the right list to ask this question?</div=
><div><br></div><div>Thanks</div><span><font color=3D"#888888">-- <br><div>=
<div dir=3D"ltr">Rodrigo Botafogo<div><br><br><div><br></div></div></div></=
div>
</font></span></div></div>
</blockquote></div><br><br clear=3D"all"><br></div></div><span><font color=
=3D"#888888">-- <br><div>blog: <a href=3D"http://blog.enebo.com" target=3D"=
_blank">http://blog.enebo.com</a>=C2=A0 =C2=A0 =C2=A0=C2=A0 twitter: tom_en=
ebo<br>mail: <a href=3D"mailto:[email protected]" target=3D"_blank">tom.e=
[email protected]</a></div>
</font></span></div>
</blockquote></div></div></div><span><font color=3D"#888888"><br><br clear=
=3D"all"><div><br></div>-- <br><div><div dir=3D"ltr">Rodrigo Botafogo<div><=
br><br><div><br></div></div></div></div>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><br>-- <br><div>blog: <a href=3D"h=
ttp://blog.enebo.com" target=3D"_blank">http://blog.enebo.com</a>=C2=A0 =C2=
=A0 =C2=A0=C2=A0 twitter: tom_enebo<br>mail: <a href=3D"mailto:tom.enebo@gm=
ail.com" target=3D"_blank">[email protected]</a></div>
</div>
</div></div></blockquote></div></div></div><span><font color=3D"#888888"><b=
r><br clear=3D"all"><div><br></div>-- <br><div><div dir=3D"ltr">Rodrigo Bot=
afogo<div><br><br><div><br></div></div></div></div>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><div><br></div></div></div><span><=
font color=3D"#888888">-- <br><div>Christian<br></div>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><div><br></div></div></div><span c=
lass=3D"HOEnZb"><font color=3D"#888888">-- <br><div>Christian<br></div>
</font></span></div>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br><div class=
=3D"gmail_signature"><div dir=3D"ltr">Rodrigo Botafogo<div><br><br><div><br=
></div></div></div></div>
</div>
--001a11c318de2991750514f6498a--