Apache Pivot example written in JRuby

Hi,

Has anyone got or found a working Apache Pivot (http://
pivot.apache.org) code example written in JRuby? I’m trying to create
one but
failing miserably. There are numerous Swing code examples written in
JRuby and I’m looking for something similar using Pivot.

Regards,

Chris


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I spent a little time trying to get this to work and they are doing
something unfun with class loaders :frowning:

Here is code which almost works:
----- code ----
require ‘java’

java_import java.awt.Font
java_import org.apache.pivot.wtk.DesktopApplicationContext
java_import org.apache.pivot.wtk.HorizontalAlignment
java_import org.apache.pivot.wtk.VerticalAlignment

class HelloJava
include org.apache.pivot.wtk.Application

def startup(display, properties)
label = org.apache.pivot.wtk.Label.new.tap do |l|
l.text = “Nom Nom Nom!”
l.styles.tap do |s|
s.put(“font”, Font.new(“Arial”, Font::BOLD, 24))
s.put(“color”, java.awt.Color::RED)
s.put(“horizontalAlignment”, HorizontalAlignment::CENTER)
s.put(“verticalAlignment”, VerticalAlignment::CENTER)
end
end

@window = org.apache.pivot.wtk.Window.new.tap do |w|
  w.content = label
  w.title = "HEH HEH HEH!"
  w.maximized = true
  w.open(display);
end

end

def shutdown(optional)
window.close if @window
false
end

def suspend; end
def resume; end
end

HelloJava.new # Unfortunately Java interface not really implemented
until first
# construction
DesktopApplicationContext.main(HelloJava.to_java(java.lang.Class),
[].to_java(:string))

----- code ----

Invocation:
CLASSPATH=lib/pivot-core-1.4.jar:lib/pivot-wtk-1.4.jar:lib/pivot-wtk-terra-1.4.jar:.
jruby hello.rb

---- The error —

java.lang.ClassNotFoundException: HelloJava_591025772
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at
org.apache.pivot.wtk.DesktopApplicationContext$HostFrame.processWindowEvent(Unknown
Source)
at java.awt.Window.processEvent(Window.java:1820)
at java.awt.Component.dispatchEventImpl(Component.java:4714)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4544)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)
at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


So wtk eventing appears to be doing a Class.forName on HelloJava for
some reason (perhaps to not store and pass around original class
reference), and it cannot find it since our classloader loaded it and
not their’s.

If you can tell pivot to use our classloader somehow or get some help
on the pivot side to better understand the issue then perhaps we can
help more. You could use jrubyc --java to generate a Java stub class
as a workaround (then it can load that Java class in its classloader),
but it seems like the above code should work in an ideal world.

Maybe someone on this list may have an idea…

-Tom

On Mon, Apr 19, 2010 at 8:45 AM, Chris D. [email protected] wrote:

Chris


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi,

Just came across this thread. We don’t do anything unusual with class
loaders in Pivot (we don’t use a custom class loader), so in theory this
should work. I’m not familiar with JRuby, though. Does the code below
produce a .class file? If so, you should be able to launch it via
DesktopApplicationContext:

java -cp org.apache.pivot.wtk.DesktopApplicationContext
com.foo.HelloJava

If not, you could potentially create a custom application context, which
might make launching JRuby-based Pivot apps easier. This isn’t terribly
difficult, but it is much easier in Pivot 2.0 (currently under
development)
than it is in earlier versions. You can see an example of a custom
application context here:

http://svn.apache.org/repos/asf/pivot/trunk/examples/src/org/apache/pivot/examples/swing/

The best place to continue this discussion is probably the Pivot mailing
lists:

Mailing Lists | Apache Pivot

Feel free to follow up there and we’ll do what we can to help.

Greg

Thomas E Enebo wrote:

java_import org.apache.pivot.wtk.HorizontalAlignment
s.put(“color”, java.awt.Color::RED)
end

jruby hello.rb
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.awt.Component.dispatchEvent(Component.java:4544)

as a workaround (then it can load that Java class in its classloader),

pivot.apache.org) code example written in JRuby? I’m trying to create one


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


View this message in context:
http://old.nabble.com/Apache-Pivot-example-written-in-JRuby-tp28291677p29262512.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Tom,

Thanks very much for your help. I explored the jrubyc option
yesterday, but my aim is to get to the point where I can just run
a .rb file using the jruby command. I’ll see if I can contact someone
on the Pivot side of things to get around the final roadblock.

Regards,

Chris

On 20 Apr 2010, at 21:27, Thomas E Enebo wrote:

java_import org.apache.pivot.wtk.VerticalAlignment
s.put(“horizontalAlignment”, HorizontalAlignment::CENTER)
end
HelloJava.new # Unfortunately Java interface not really implemented
jruby hello.rb
at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
at java.awt.Component.dispatchEvent(Component.java:4544)
(EventDispatchThread.java:188)
on the pivot side to better understand the issue then perhaps we can

Hi,
Chris


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I just did a little digging and it looks like the question had already
been
posted to the Pivot user list. Apparently I replied, though I didn’t
remember doing so. :slight_smile:

Anyways, another option is to use JRuby script from within a WTKX file
(or
BXML file, as it is called in Pivot 2.0). That would allow you to get
around
the instantiation issue. You could declare your UI in markup, but write
your
event handling code in JRuby. This would certainly be simpler, and might
actually be a better approach (depending on your use case).

G

Greg Brown wrote:

com.foo.HelloJava
The best place to continue this discussion is probably the Pivot mailing

java_import org.apache.pivot.wtk.VerticalAlignment
s.put(“horizontalAlignment”, HorizontalAlignment::CENTER)
end
HelloJava.new # Unfortunately Java interface not really implemented until

at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:635)

but it seems like the above code should work in an ideal world.

one


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


View this message in context:
http://old.nabble.com/Apache-Pivot-example-written-in-JRuby-tp28291677p29262630.html
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email