Problems with getValue

I can’t figure out what I’m doing wrong here. The Java code works. All
the Ruby permutations return nil. How can I get the names I want?

Thanks!

=== deleteme.java ===
import java.io.;
import javax.swing.
;

class Deleteme {
public static void main(String args[]) throws IOException {
String str;
str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
System.out.println("Cut action name is: " + str);
str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
System.out.println("Copy action name is: " + str);
str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
System.out.println("Paste action name is: " + str);
}
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste

=== deleteme.rb ===
require ‘java’

Easier way to do this at file scope? Normally I would just

include_package

‘javax.swing’ in my class.

java_import javax.swing.TransferHandler
java_import javax.swing.Action

name = TransferHandler.getCutAction.getValue(Action.NAME)
puts “Cut action name is: #{name}”
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts “Copy action name is: #{name}”
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts “Paste action name is: #{name}”

try really hard

action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts “Cut action #{action.inspect} name is: #{name}”

try another way; doesn’t work because getValue takes an argument

#name = TransferHandler.getCutAction.value(Action.NAME)
#puts “Cut action name is: #{name}”

try another way

meth = action.java_method(:getValue, [java.lang.String])
puts “Cut action name is: #{meth.call(Action.NAME)}”
puts “Cut action name is: #{meth.call(Action.NAME.to_java)}”
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #Java::JavaxSwing::TransferAction:0x7548c02f name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:…> jruby deleteme.rb
[all names still nil]
C:…> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot™ Client
VM 1.6.0_37-b06 [Windows 7-x86]


Ryan H.
L-3 Communications / Communication Systems West
[email protected]

wow. Can you report this as an issue on our github project? I can
confirm
this does not work. My guess is getValue is public in the interface but
non-public in the concrete class of TransferAction. We actually use
reflection to get around these odd cases so I don’t understand why this
is
not working.

-Tom

Yeah, this is really interesting. I wrote a test script at
https://gist.github.com/keithrbennett/10275705 that also illustrates
that
the Action’s method names are not rubified, i.e. getValue cannot be
accessed as value. I got the same result in JRuby 1.7.1 and 1.7.9.

  • Keith

Yeah, it could be something to do with the inner class relationship too.
Amazed we have not seen this one before. Lots of a folks have done
Swing
stuff using JRuby.

-Tom

I tried to report it on GitHub yesterday, but the buttons weren’t
working. I suspect the corporate firewall/mandated browser are to
blame. I’ll try tonight from home unless someone beats me to it.

Is there any way I can work around it for now (besides writing Java code
:-)?

  • Ryan

From: Thomas E Enebo [mailto:[email protected]]
Sent: Wednesday, April 09, 2014 7:37 AM
To: [email protected]
Subject: Re: [jruby-user] Problems with getValue

wow. Can you report this as an issue on our github project? I can
confirm this does not work. My guess is getValue is public in the
interface but non-public in the concrete class of TransferAction. We
actually use reflection to get around these odd cases so I don’t
understand why this is not working.
-Tom

On Tue, Apr 8, 2014 at 10:10 PM,
<[email protected]mailto:[email protected]> wrote:
I can’t figure out what I’m doing wrong here. The Java code works. All
the Ruby permutations return nil. How can I get the names I want?

Thanks!

=== deleteme.java ===
import java.io.;
import javax.swing.
;

class Deleteme {
public static void main(String args[]) throws IOException {
String str;
str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
System.out.println("Cut action name is: " + str);
str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
System.out.println("Copy action name is: " + str);
str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
System.out.println("Paste action name is: " + str);
}
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste

=== deleteme.rb ===
require ‘java’

Easier way to do this at file scope? Normally I would just

include_package

‘javax.swing’ in my class.

java_import javax.swing.TransferHandler
java_import javax.swing.Action

name = TransferHandler.getCutAction.getValue(Action.NAME)
puts “Cut action name is: #{name}”
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts “Copy action name is: #{name}”
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts “Paste action name is: #{name}”

try really hard

action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts “Cut action #{action.inspect} name is: #{name}”

try another way; doesn’t work because getValue takes an argument

#name = TransferHandler.getCutAction.value(Action.NAME)
#puts “Cut action name is: #{name}”

try another way

meth = action.java_method(:getValue, [java.lang.String])
puts “Cut action name is: #{meth.call(Action.NAME)}”
puts “Cut action name is: #{meth.call(Action.NAME.to_java)}”
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #Java::JavaxSwing::TransferAction:0x7548c02f name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:…> jruby deleteme.rb
[all names still nil]
C:…> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot™ Client
VM 1.6.0_37-b06 [Windows 7-x86]


Ryan H.
L-3 Communications / Communication Systems West
[email protected]

If you can dig out the java_object from the TransferHandler you should
be
able to use Java reflection APIs + setAccessible. If you search for
JRuby
setAccessible something might turn up. It is pretty gruesome workaround
but it should work.

-Tom

Might it be an issue with JRuby’s handling of inner classes in Java?

JRuby reports that the action is an instance
ofJava::JavaxSwing::TransferAction,
whereas a web page at
http://www.cs.rit.edu/usr/local/pub/swm/jdoc1.6.0_19/javax/swing/TransferHandler.TransferAction.htmlsays
that TransferAction is an inner class of TransferHandler.

  • Keith

That does sound gruesome. I have a less-gruesome (but more evil) hack
implemented right now. I’ll submit the bug report, and hopefully the
hack will last long enough for the bug to be fixed and released.

Thanks!

  • Ryan

From: Thomas E Enebo [mailto:[email protected]]
Sent: Wednesday, April 09, 2014 11:42 AM
To: [email protected]
Subject: Re: [jruby-user] Problems with getValue

If you can dig out the java_object from the TransferHandler you should
be able to use Java reflection APIs + setAccessible. If you search for
JRuby setAccessible something might turn up. It is pretty gruesome
workaround but it should work.
-Tom

On Wed, Apr 9, 2014 at 11:35 AM,
<[email protected]mailto:[email protected]> wrote:
I tried to report it on GitHub yesterday, but the buttons weren’t
working. I suspect the corporate firewall/mandated browser are to
blame. I’ll try tonight from home unless someone beats me to it.

Is there any way I can work around it for now (besides writing Java code
:-)?

  • Ryan

From: Thomas E Enebo
[mailto:[email protected]mailto:[email protected]]
Sent: Wednesday, April 09, 2014 7:37 AM
To: [email protected]mailto:[email protected]
Subject: Re: [jruby-user] Problems with getValue

wow. Can you report this as an issue on our github project? I can
confirm this does not work. My guess is getValue is public in the
interface but non-public in the concrete class of TransferAction. We
actually use reflection to get around these odd cases so I don’t
understand why this is not working.
-Tom

On Tue, Apr 8, 2014 at 10:10 PM,
<[email protected]mailto:[email protected]> wrote:
I can’t figure out what I’m doing wrong here. The Java code works. All
the Ruby permutations return nil. How can I get the names I want?

Thanks!

=== deleteme.java ===
import java.io.;
import javax.swing.
;

class Deleteme {
public static void main(String args[]) throws IOException {
String str;
str =
(String)TransferHandler.getCutAction().getValue(Action.NAME);
System.out.println("Cut action name is: " + str);
str =
(String)TransferHandler.getCopyAction().getValue(Action.NAME);
System.out.println("Copy action name is: " + str);
str =
(String)TransferHandler.getPasteAction().getValue(Action.NAME);
System.out.println("Paste action name is: " + str);
}
}
=== END deleteme.java ===

$ javac deleteme.java
$ java Deleteme
Cut action name is: cut
Copy action name is: copy
Paste action name is: paste

=== deleteme.rb ===
require ‘java’

Easier way to do this at file scope? Normally I would just

include_package

‘javax.swing’ in my class.

java_import javax.swing.TransferHandler
java_import javax.swing.Action

name = TransferHandler.getCutAction.getValue(Action.NAME)
puts “Cut action name is: #{name}”
name = TransferHandler.getCopyAction.getValue(Action.NAME)
puts “Copy action name is: #{name}”
name = TransferHandler.getPasteAction.getValue(Action.NAME)
puts “Paste action name is: #{name}”

try really hard

action = TransferHandler.getCutAction
name = action.java_send(:getValue, [java.lang.String], Action.NAME)
puts “Cut action #{action.inspect} name is: #{name}”

try another way; doesn’t work because getValue takes an argument

#name = TransferHandler.getCutAction.value(Action.NAME)
#puts “Cut action name is: #{name}”

try another way

meth = action.java_method(:getValue, [java.lang.String])
puts “Cut action name is: #{meth.call(Action.NAME)}”
puts “Cut action name is: #{meth.call(Action.NAME.to_java)}”
=== END deleteme.rb ===

$ jruby deleteme.rb
Cut action name is:
Copy action name is:
Paste action name is:
Cut action #Java::JavaxSwing::TransferAction:0x7548c02f name is:
Cut action name is:
Cut action name is:
$ jruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on OpenJDK 64-Bit Server VM
1.6.0_22-b22 [linux-amd64]

C:…> jruby deleteme.rb
[all names still nil]
C:…> jruby --version
jruby 1.7.10 (1.9.3p392) 2014-01-09 c4ecd6b on Java HotSpot™ Client
VM 1.6.0_37-b06 [Windows 7-x86]


Ryan H.
L-3 Communications / Communication Systems West
[email protected]


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs