Rubish notation does not resolve as expected

I was using a rubish notation for methods instead the real Java names
and had an unexpected resolution and it does not behave the same way in
similar cases:

include Java

comp = javax.swing.JButton.new(“hello”)
puts “#{comp.class} #{comp.preferred_size.nil?} /
#{comp.get_preferred_size.nil?}”

comp = javax.swing.JFormattedTextField.new(“hello”)
puts “#{comp.class} #{comp.preferred_size.nil?} /
#{comp.get_preferred_size.nil?}”

The call to preferred_size when the object is a JFormattedTextField.
returns null (nil) while using the longer name calls the correct method.
But with a JButton object both calls succeed.

I did not make any investigation.

-Jean

On Jun 18, 2010, at 1:00 PM, Jean L. wrote:

The call to preferred_size when the object is a JFormattedTextField. returns null (nil) while using the longer name calls the correct method. But with a JButton object both calls succeed.

I did not make any investigation.

-Jean

Not sure what you are expecting. It seems to work fine for me.

$ jruby -S irb
irb(main):001:0> require ‘java’
=> true
irb(main):002:0> comp = javax.swing.JButton.new(“hello”)
=> #Java::JavaxSwing::JButton:0x6d854b38
irb(main):003:0> comp.preferred_size
=> #Java::JavaAwt::Dimension:0x131a9310
irb(main):004:0> comp.preferred_size.width
=> 75
irb(main):005:0> comp.preferred_size.height
=> 29
irb(main):006:0> comp.preferred_size.nil?
=> false

Can you file this as a bug (http://jira.codehaus.org/browse/JRUBY)?
JFormattedTextField is doing something differently for
preferred_size…which is odd.

-Tom

On Fri, Jun 18, 2010 at 12:00 PM, Jean L. [email protected]
wrote:

comp = javax.swing.JFormattedTextField.new(“hello”)


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


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

I added it as JRUBY-4894 (I left by mistake Major as priority)

-Jean


From: Thomas E Enebo [email protected]
To: [email protected]
Sent: Fri, June 18, 2010 9:27:41 PM
Subject: Re: [jruby-user] rubish notation does not resolve as expected

Can you file this as a bug (http://jira.codehaus.org/browse/JRUBY)?
JFormattedTextField is doing something differently for
preferred_size…which is odd.

-Tom

On Fri, Jun 18, 2010 at 12:00 PM, Jean L. [email protected]
wrote:

comp = javax.swing.JFormattedTextField.new(“hello”)


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,

On Sat, Jun 19, 2010 at 5:24 AM, Trejkaz [email protected] wrote:

Not as odd as one might think. Intuitively, preferred_size called on
a subclass of component would call Component.preferredSize(), not
Component.getPreferredSize(), unless JRuby has done something to
explicitly prefer the latter.

getPreferredSize() delegates to preferredSize() but naturally if you
were to take any class that overrides only getPreferredSize() then
calling the two would naturally have different results.

Indeed, this is the case, thanks for investigating. And I should have
read this thread earlier! Since I looked at the code as well and came
to the same conclusion. :slight_smile: That evil deprecated preferredSize() in
Component gets in the way here, and JRuby does the only sensible thing
left for it to do: invoke the method when the names match.

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

How comes that with JButton we don’t have the same behavior? The
deprecated method is in the Container class, both JButton and
JFormattedTextFiled derive from it…

Vladimir, I copied ‘include Java’ from the sample file ‘swing2.rb’.

Jean


From: Vladimir S. [email protected]
To: [email protected]
Sent: Sat, June 19, 2010 7:51:02 AM
Subject: Re: [jruby-user] rubish notation does not resolve as expected

Hi,

On Sat, Jun 19, 2010 at 5:24 AM, Trejkaz [email protected] wrote:

Not as odd as one might think. Intuitively, preferred_size called on
a subclass of component would call Component.preferredSize(), not
Component.getPreferredSize(), unless JRuby has done something to
explicitly prefer the latter.

getPreferredSize() delegates to preferredSize() but naturally if you
were to take any class that overrides only getPreferredSize() then
calling the two would naturally have different results.

Indeed, this is the case, thanks for investigating. And I should have
read this thread earlier! Since I looked at the code as well and came
to the same conclusion. :slight_smile: That evil deprecated preferredSize() in
Component gets in the way here, and JRuby does the only sensible thing
left for it to do: invoke the method when the names match.

Thanks,
–Vladimir


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sat, Jun 19, 2010 at 5:27 AM, Thomas E Enebo [email protected]
wrote:

Can you file this as a bug (http://jira.codehaus.org/browse/JRUBY)?
JFormattedTextField is doing something differently for
preferred_size…which is odd.

Not as odd as one might think. Intuitively, preferred_size called on
a subclass of component would call Component.preferredSize(), not
Component.getPreferredSize(), unless JRuby has done something to
explicitly prefer the latter.

getPreferredSize() delegates to preferredSize() but naturally if you
were to take any class that overrides only getPreferredSize() then
calling the two would naturally have different results.

TX


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Sun, Jun 20, 2010 at 1:39 AM, Jean L. [email protected]
wrote:

How comes that with JButton we don’t have the same behavior? The deprecated
method is in the Container class, both JButton and JFormattedTextFiled
derive from it…

The problem doesn’t come from the existence of the overridden method,
it comes from classes overriding one and not the other and even then,
only if it results in inconsistent behaviour.

In this case JComponent is the actual culprit, and it’s delegating to
the ComponentUI so the behaviour will be different for all component
types.

It’s a shame Sun never get around to removing deprecated methods.

TX


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email