Hi All, Trying to convert a Scene Graph demo "Nodes" to JRuby. https://scenegraph-demos.dev.java.net/demos.html This line: Composer.register(AffineTransform.class, TransformComposer.class) gives this error: C:/Users/paulAdmin/Documents/NetbeansProjects/scene_graph_work/lib/scene_graph.rb:1: expected [java.lang.Class, java.lang.Class]; got: [org.jruby.RubyClass,org.jruby.RubyClass]; error: argument type mismatch (TypeError) I am probably out of my depth here, but are the experts able to help? How do I "cast" an "org.jruby.RubyClass" to a "java.lang.Class" or what procedure should be used in this case? Thanks Paul Fraser --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 03:45
on 08.08.2008 04:03
On Thu, Aug 7, 2008 at 6:44 PM, Paul Fraser <paulf@relax.com.au> wrote: > (TypeError) > > I am probably out of my depth here, but are the experts able to help? > How do I "cast" an "org.jruby.RubyClass" to a "java.lang.Class" or what > procedure should be used in this case? What does the Ruby code you wrote look like? /Nick --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:21
Paul Fraser wrote: > (TypeError) > > I am probably out of my depth here, but are the experts able to help? > How do I "cast" an "org.jruby.RubyClass" to a "java.lang.Class" or what > procedure should be used in this case? If AffineTransform is a Java class, you want to call .java_class to get it out. I know, it's gross. I'm hoping to improve that post 1.1.4. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:23
Nick Sieger wrote: >> expected [java.lang.Class, java.lang.Class]; got: >> [org.jruby.RubyClass,org.jruby.RubyClass]; error: argument type mismatch >> (TypeError) >> >> I am probably out of my depth here, but are the experts able to help? >> How do I "cast" an "org.jruby.RubyClass" to a "java.lang.Class" or what >> procedure should be used in this case? >> > > What does the Ruby code you wrote look like? > Hi Nick, I did not write it, just converting it , this is how some of it looks at present, a bit messy at this stage, but, does this help? require 'java' import com.sun.scenario.animation.Clip; import com.sun.scenario.animation.Composer; import com.sun.scenario.animation.Interpolators; import com.sun.scenario.animation.Timeline; import com.sun.scenario.scenegraph.JSGPanel; import com.sun.scenario.scenegraph.SGComponent; import com.sun.scenario.scenegraph.SGComposite; import com.sun.scenario.scenegraph.SGGroup; import com.sun.scenario.scenegraph.SGImage; import com.sun.scenario.scenegraph.SGShape; import com.sun.scenario.scenegraph.SGText; import com.sun.scenario.scenegraph.SGTransform; import com.sun.scenario.scenegraph.fx.FXNode; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.LinearGradientPaint; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.AffineTransform; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.UIManager; class TransformComposer < Composer # def initialize super(6) end # def decompose(o,v) o.getMatrix(v) return v end # def compose(v) return AffineTransform.new(v) end end # class TransformComposer # # class Nodes include ActionListener # SCREEN_W = 300, SCREEN_H = 400; FADE_DUR = 500; CLIP_DUR = 500; TEXT_X = 100; TEXT_Y = 40; IMAGE_X = 23; IMAGE_Y = 3; IMAGES_LABEL = "Images "; SHAPES_LABEL = "Shapes "; COMPONENTS_LABEL = "Components "; TEXT_LABEL = "Text "; ANIMATION_LABEL = "Animation "; TRANSLUCENCY_LABEL = "Translucency "; # # # Composer.register(AffineTransform.class, TransformComposer.class); <<<<<<<<<<<<<<<<<<<<<<<<<<<< trouble # # def initialize @rootNode = SGGroup.new # # JPanel controlPanel; # # SGTransform componentScaler; # # private Clip textFadeIn, textFadeOut; # # private Clip imageFadeIn, imageFadeOut; # # private Clip shapeFadeIn, shapeFadeOut; # # private Clip bgFadeIn, bgFadeOut; # # private Clip componentScaleOut, componentScaleIn; @nodeGroupMover = Timeline.new @numSelected = 0; # # private SGComposite componentTranslucency; # # private AffineTransform cpScaleLarge; @duke = nil # # # // preload image # # try { # imageURL = getClass.getResource("images/duke.gif") # duke = ImageIO.read(imageURL) # # } catch (Exception e) { # # System.out.println("problem loading image: " + e); # # } # # # # // Create actual window frame f = JFrame.new("Nodes Demo") # # try { # # UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); # # } catch (Exception e) { # # System.out.println("problem with l&f: " + e); # # } f.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE) # # setupNodes setupPanel(f) # # f.invalidate f.pack f.setLocationRelativeTo(nil) f.setVisible(true) # # end # def initialize --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:25
On Thu, Aug 7, 2008 at 9:22 PM, Paul Fraser <paulf@relax.com.au> wrote: >>> Composer.register(AffineTransform.class, TransformComposer.class) >>> >> >> What does the Ruby code you wrote look like? >> > > Hi Nick, > > I did not write it, just converting it , this is how some of it looks at > present, a bit messy at this stage, but, does this help? > > Composer.register(AffineTransform.class, TransformComposer.class); > <<<<<<<<<<<<<<<<<<<<<<<<<<<< trouble AffineTransform.java_class, TransforComposer.java_class Calling .class gets Ruby class versus the Java class. -Tom -- Blog: http://www.bloglines.com/blog/ThomasEEnebo Email: enebo@acm.org , tom.enebo@gmail.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:33
Charles Oliver Nutter wrote: >> [org.jruby.RubyClass,org.jruby.RubyClass]; error: argument type >> mismatch (TypeError) >> >> I am probably out of my depth here, but are the experts able to help? >> How do I "cast" an "org.jruby.RubyClass" to a "java.lang.Class" or >> what procedure should be used in this case? > > If AffineTransform is a Java class, you want to call .java_class to > get it out. I know, it's gross. I'm hoping to improve that post 1.1.4. > > - Charlie Charlie, Both of these fail: Composer.register(AffineTransform.class.java_class, TransformComposer.class.java_class) error: C:/Users/paulAdmin/Documents/NetbeansProjects/scene_graph_work/lib/scene_graph.rb:79: undefined method `java_class' for Class:Class (NoMethodError) Composer.register(AffineTransform.java_class, TransformComposer.java_class) error runtime: com/sun/scenario/animation/Composer.java:162:in `register': java.lang.IllegalArgumentException: Problem constructing appropriate Composer for type class java.awt.geom.AffineTransform: (NativeException) What form should the call take? Thanks Paul Fraser --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:43
Paul Fraser wrote: >>> expected [java.lang.Class, java.lang.Class]; got: >> - Charlie > > Charlie, > > Both of these fail: > Composer.register(AffineTransform.class.java_class, > TransformComposer.class.java_class) > error: AffineTransform.java_class - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 04:45
Paul Fraser wrote: > error runtime: > com/sun/scenario/animation/Composer.java:162:in `register': > java.lang.IllegalArgumentException: Problem constructing appropriate > Composer for type class java.awt.geom.AffineTransform: (NativeException) > > What form should the call take? Gah, previous mail sent too soon. In the latter case it looks like it worked exactly like it's supposed to; it was able to receive the AffineTransform class correctly. That exception is coming out of Sun's library, not out of JRuby... Perhaps that method is not supposed to take a Class? - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 05:25
Charles Oliver Nutter wrote: > The only problem here is that the java version works :-( So, possibly static has something to do with it! Ah Ha, Ask the question again, how should the following be coded in JRuby? :-) static { Composer.register(AffineTransform.class, TransformComposer.class); } Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 05:55
Paul Fraser wrote: >> - Charlie >> > The only problem here is that the java version works :-( So, > possibly static has something to do with it! > Ah Ha, Ask the question again, how should the following be coded in > JRuby? :-) > > static { > Composer.register(AffineTransform.class, TransformComposer.class); > } Are you running 1.1.3? The code from before with .java_class should be correct, but I suspect a bug fixed in 1.1.3 might be involved here. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 08.08.2008 06:14
Charles Oliver Nutter wrote: >>> Perhaps that method is not supposed to take a Class? >> } > > Are you running 1.1.3? The code from before with .java_class should be > correct, but I suspect a bug fixed in 1.1.3 might be involved here. > > - Charlie 1.1.3 Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 09.08.2008 05:58
>>> The only problem here is that the java version works :-( So, >>> possibly static has something to do with it! >>> Ah Ha, Ask the question again, how should the following be coded >>> in JRuby? :-) >>> >>> static { >>> Composer.register(AffineTransform.class, TransformComposer.class) The code being called is : public static void register(Class<?> type, Class<? extends Composer> implClass) { Composer impl; try { Constructor<? extends Composer> ctor = implClass.getConstructor(); impl = (Composer)ctor.newInstance(); } catch (Exception e) { throw new IllegalArgumentException("Problem constructing " + "appropriate Composer for type " + type + ":", e); } impls.put(type, impl); } Is there any clue here as to cause of failure in JRuby. As previously stated, it works in Java. Are generics perhaps a problem here? Thanks Paul Fraser --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 09.08.2008 06:27
Where can I download the scenegraph lib you're using? I want to give this a try and help you make it work. Paul Fraser wrote: >>>>> > Class<? extends Composer> implClass) > } > --------------------------------------------------------------------- > 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
on 09.08.2008 08:05
Charles Oliver Nutter wrote: > Where can I download the scenegraph lib you're using? I want to give > this a try and help you make it work. > Hi Charlie, https://scenegraph.dev.java.net/ https://scenegraph.dev.java.net/source/browse/scenegraph/ Thanks Paul Fraser --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 09.08.2008 08:18
Paul Fraser wrote: > Thanks > Paul Fraser Also, Charlie, Have a look at the demo,s, they are quite exciting, especially the Nodes demo. The techniques extend the methods outlined in "Filthy Rich Clients" Scenegraph might be the future of desktop apps in the java space as all swing components can be used as well as the animations etc.. It is not only for JavaFx. Paul --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 10.08.2008 08:07
Paul Fraser wrote: > Have a look at the demo,s, they are quite exciting, especially the Nodes > demo. The techniques extend the methods outlined in "Filthy Rich Clients" > Scenegraph might be the future of desktop apps in the java space as all > swing components can be used as well as the animations etc.. > It is not only for JavaFx. Yer damn right it's not, and I've just been waiting for someone to try exactly this. So I found the problem..it's a known issue I really dislike, and honestly I need to try to find a better way to fix it than the way we did in 1.1.3. Your TransformComposer is < Composer, which is cool. But in cases of Ruby clases extending Java classes, java_class points at *the wrong class*. You need to use java_class.java_proxy_class in this case. So that's bug number one. Unfortunately bug number two is a bit more problematic. Because our Ruby subclasses of Java classes have some JRuby baggage, I don't think the logic in the Composer class is going to work correctly. It looks up a default constructor using reflection and tries to call it, but in our case that doesn't properly set up the class. Here's the error that results if I use java_proxy_class (and also construct an instance of TransformComposer to force our lazy creation of the proxy class): Caused by: java.lang.NoSuchMethodException: org.jruby.proxy.com.sun.scenario.animation.Composer$Proxy0.<init>() Grr. So this particular path to getting scenegraph working has some roadblocks, but they're roadblocks I want to look at trying to fix for this upcoming release. So I'm looking into some of them right now. - Charlie --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
on 18.09.2008 13:14
Hi Paul, Don't know if this is the JRuby to cast objects, but this worked for me: put your object in an one-element-array. Casts it's elements to the desired Java class and get the first element: include_class 'java.lang.Class' obj = Object.new # Let's say this is your Ruby object casted = [obj].to_java(java.lang.Class)[0]