Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
block passing
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  13 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Volkmann  
View profile  
 More options Oct 7 2009, 3:37 pm
From: Mark Volkmann <m...@ociweb.com>
Date: Wed, 7 Oct 2009 14:37:45 -0500
Local: Wed, Oct 7 2009 3:37 pm
Subject: [jruby-user] block passing
Here's a short bit of code from a larger application that is giving me  
a NullPointerException in convertRubyToJavaInt. I can't figure out why  
it is doing that. The problem disappears if you comment out the block  
that is being passed to the JButton initialize method. That's on the  
line that sets ok_button. Any idea what is going on here?

include Java
import javax.swing.JButton
import javax.swing.JFrame

class JButton
   def initialize(name, &block)
     super(name)
     # Not using the block yet, but will later.
   end
end

class GUI < JFrame
   def initialize
     super('Title')
     ok_button = JButton.new('OK') { puts 'pressed OK' }
     content_pane.add(ok_button)
     pack
     self.default_close_operation = JFrame::EXIT_ON_CLOSE
   end
end

GUI.new.visible = true

---
Mark Volkmann
http://www.ociweb.com/mark

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Oct 8 2009, 4:40 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Thu, 8 Oct 2009 14:40:14 -0600
Local: Thurs, Oct 8 2009 4:40 pm
Subject: Re: [jruby-user] block passing

On Wed, Oct 7, 2009 at 1:37 PM, Mark Volkmann <m...@ociweb.com> wrote:
> Here's a short bit of code from a larger application that is giving me a
> NullPointerException in convertRubyToJavaInt. I can't figure out why it is
> doing that. The problem disappears if you comment out the block that is
> being passed to the JButton initialize method. That's on the line that sets
> ok_button. Any idea what is going on here?

Can you show the full NPE trace? And try against 1.4RC1, some of this
has been cleaned up.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
R. Mark Volkmann  
View profile  
 More options Oct 8 2009, 5:15 pm
From: "R. Mark Volkmann" <m...@ociweb.com>
Date: Thu, 08 Oct 2009 16:15:05 -0500
Local: Thurs, Oct 8 2009 5:15 pm
Subject: Re: [jruby-user] block passing
Quoting Charles Oliver Nutter <head...@headius.com>:

> On Wed, Oct 7, 2009 at 1:37 PM, Mark Volkmann <m...@ociweb.com> wrote:
> > Here's a short bit of code from a larger application that is giving me a
> > NullPointerException in convertRubyToJavaInt. I can't figure out why it is
> > doing that. The problem disappears if you comment out the block that is
> > being passed to the JButton initialize method. That's on the line that sets
> > ok_button. Any idea what is going on here?

> Can you show the full NPE trace? And try against 1.4RC1, some of this
> has been cleaned up.

Sure!  See below.  Note how "pressed OK" is output.  That seems wrong because
it's in a block that I pass to the JButton initialize method, but don't
execute.  The code is identical to that in my previous email.

Swing$ jruby gui.rb
pressed OK
org/jruby/javasupport/JavaUtil.java:922:in `convertRubyToJavaInt':
java.lang.NullPointerException: null (NativeException)
        from org/jruby/gen/org/jruby/gen/InterfaceImpl271097958.gen:13:in
`getIconWidth'
        from javax/swing/SwingUtilities.java:890:in `layoutCompoundLabelImpl'
        from javax/swing/SwingUtilities.java:817:in `layoutCompoundLabel'
        from javax/swing/plaf/basic/BasicGraphicsUtils.java:262:in
`getPreferredButtonSize'
        from apple/laf/CUIAquaButton.java:450:in `getPreferredSize'
        from javax/swing/JComponent.java:1624:in `getPreferredSize'
        from java/awt/BorderLayout.java:690:in `preferredLayoutSize'
        from java/awt/Container.java:1558:in `preferredSize'
         ... 10 levels...
        from gui.rb:15:in `initialize'
        from gui.rb:22:in `new_proxy'
        from gui.rb:22
Swing$ jruby -v
jruby 1.4.0RC1 (ruby 1.8.7 patchlevel 174) (2009-09-30 80c263b) (Java
HotSpot(TM) Client VM 1.5.0_19) [i386-java]

--
R. Mark Volkmann
Object Computing, Inc.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Sizikov  
View profile  
 More options Oct 9 2009, 5:26 am
From: Vladimir Sizikov <vsizi...@gmail.com>
Date: Fri, 9 Oct 2009 11:26:44 +0200
Local: Fri, Oct 9 2009 5:26 am
Subject: Re: [jruby-user] block passing
Hi Mark,

On Wed, Oct 7, 2009 at 9:37 PM, Mark Volkmann <m...@ociweb.com> wrote:
> Here's a short bit of code from a larger application that is giving me a
> NullPointerException in convertRubyToJavaInt. I can't figure out why it is
> doing that. The problem disappears if you comment out the block that is
> being passed to the JButton initialize method. That's on the line that sets
> ok_button. Any idea what is going on here?

Sure, the way you construct the OK button is not 100% correct. You
provide a block to the constructor, but JButton's two-arg constructor
is JButton(text, *icon*). So, essentially, instead of icon you supply
a block, and when the Frame tries to layout itself, it asks the "icon"
to report its width via getIconWidth(), and that block gets confused.
:)

The fix is simple, instead of:
ok_button = JButton.new('OK') { puts 'pressed OK' }

do

ok_button = JButton.new('OK')
ok_button.add_action_listener { puts 'pressed OK!' }

This should work.

Thanks,
  --Vladimir

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Volkmann  
View profile  
 More options Oct 9 2009, 8:47 am
From: Mark Volkmann <m...@ociweb.com>
Date: Fri, 9 Oct 2009 07:47:27 -0500
Local: Fri, Oct 9 2009 8:47 am
Subject: Re: [jruby-user] block passing
On Oct 9, 2009, at 4:26 AM, Vladimir Sizikov wrote:

Interesting. However, this code worked with an earlier version of  
JRuby. I wonder what changed. That JButton constructor isn't new.

> The fix is simple, instead of:
> ok_button = JButton.new('OK') { puts 'pressed OK' }

> do

> ok_button = JButton.new('OK')
> ok_button.add_action_listener { puts 'pressed OK!' }

> This should work.

Thanks! That does work, but I thought it was more elegant to be able  
to pass to the constructor the block of code I want to execute when  
the button is pressed.

---
Mark Volkmann
http://www.ociweb.com/mark

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Sizikov  
View profile  
 More options Oct 9 2009, 9:10 am
From: Vladimir Sizikov <vsizi...@gmail.com>
Date: Fri, 9 Oct 2009 15:10:37 +0200
Local: Fri, Oct 9 2009 9:10 am
Subject: Re: [jruby-user] block passing
Hi Mark,

On Fri, Oct 9, 2009 at 2:47 PM, Mark Volkmann <m...@ociweb.com> wrote:
> Interesting. However, this code worked with an earlier version of JRuby. I
> wonder what changed.

Indeed, it stopped working since July 2008, after one of Charlie's
commits that fixed various java-integration bugs.
Before that, the code worked somewhat, but was printing 'pressed OK'
when container tried to obtain the size of the button. :)

So it seems that it worked before due to bugs in JRuby.

> Thanks! That does work, but I thought it was more elegant to be able to pass
> to the constructor the block of code I want to execute when the button is
> pressed.

Well, yeah, for this particular case, yes, but hard to figure out what
to do in general case, not to mention that there could be multiple
listeners and different users would like to do different things.

Thanks,
  --Vladimir

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Oct 9 2009, 3:27 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Fri, 9 Oct 2009 13:27:49 -0600
Local: Fri, Oct 9 2009 3:27 pm
Subject: Re: [jruby-user] block passing

On Fri, Oct 9, 2009 at 6:47 AM, Mark Volkmann <m...@ociweb.com> wrote:
> On Oct 9, 2009, at 4:26 AM, Vladimir Sizikov wrote:
>> Sure, the way you construct the OK button is not 100% correct. You
>> provide a block to the constructor, but JButton's two-arg constructor
>> is JButton(text, *icon*). So, essentially, instead of icon you supply
>> a block, and when the Frame tries to layout itself, it asks the "icon"
>> to report its width via getIconWidth(), and that block gets confused.
>> :)

We do need to fix this so it doesn't NPE...that should not happen. At
worse it should provide a type error of some kind.

> Interesting. However, this code worked with an earlier version of JRuby. I
> wonder what changed. That JButton constructor isn't new.

I'm not sure this ever worked...it doesn't seem possible. How early
was that other version? The issue here is that we're trying to force
the block to act like it's an Icon, when of course that's a little
absurd. Passing a block to JButton.new never would have worked in the
past, unless some other library added a block version of "new" that
wired up the action listener for you.

>> ok_button = JButton.new('OK')
>> ok_button.add_action_listener { puts 'pressed OK!' }

> Thanks! That does work, but I thought it was more elegant to be able to pass
> to the constructor the block of code I want to execute when the button is
> pressed.

JRuby handles blocks passed to Java by trying to implement an
interface for the last argument. That's all it has ever done, and
before this time last year it pretty much just ignored it.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Oct 9 2009, 3:37 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Fri, 9 Oct 2009 13:37:33 -0600
Local: Fri, Oct 9 2009 3:37 pm
Subject: Re: [jruby-user] block passing

On Fri, Oct 9, 2009 at 7:10 AM, Vladimir Sizikov <vsizi...@gmail.com> wrote:
> Hi Mark,

> On Fri, Oct 9, 2009 at 2:47 PM, Mark Volkmann <m...@ociweb.com> wrote:
>> Interesting. However, this code worked with an earlier version of JRuby. I
>> wonder what changed.

> Indeed, it stopped working since July 2008, after one of Charlie's
> commits that fixed various java-integration bugs.
> Before that, the code worked somewhat, but was printing 'pressed OK'
> when container tried to obtain the size of the button. :)

> So it seems that it worked before due to bugs in JRuby.

Ahh...interesting. Well if we fixed that NPE it might start "working"
again, but obviously it's not the expected result. Which commit was
it?

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Volkmann  
View profile  
 More options Oct 9 2009, 3:39 pm
From: Mark Volkmann <m...@ociweb.com>
Date: Fri, 9 Oct 2009 14:39:43 -0500
Local: Fri, Oct 9 2009 3:39 pm
Subject: Re: [jruby-user] block passing

On Oct 9, 2009, at 2:27 PM, Charles Oliver Nutter wrote:

I gave a talk on JRuby to the St. Louis Java User Group in May 2007.  
This was before the 1.0 release of JRuby, but I don't know exactly  
which version I was using. Here is some code I demoed in that talk  
that worked at the time. Note how I'm passing a block to the JButton  
constructor.

include Java

BorderLayout = java.awt.BorderLayout
JButton = javax.swing.JButton
JFrame = javax.swing.JFrame
JLabel = javax.swing.JLabel
JOptionPane = javax.swing.JOptionPane
JPanel = javax.swing.JPanel
JTextField = javax.swing.JTextField

class BlockActionListener < java.awt.event.ActionListener
   # super call is needed for now - see JRUBY-66 in JIRA
   def initialize(&block); super; @block = block; end
   def actionPerformed(e); @block.call(e); end
end

class JButton
   def initialize(name, &block)
     super(name)
     addActionListener(BlockActionListener.new(&block))
   end
end

class HelloFrame < JFrame
   def initialize
     super("Hello Swing!")
     populate
     pack
     self.resizable = false
     self.defaultCloseOperation = JFrame::EXIT_ON_CLOSE
   end

   def populate
     name_panel = JPanel.new
     name_panel.add JLabel.new("Name:")
     name_field = JTextField.new(20)
     name_panel.add name_field
     button_panel = JPanel.new

     greet_button = JButton.new("Greet") do
       name = name_field.text
       msg = %(<html>Hello <span style="color:red">#{name}</span>!</
html>)
       JOptionPane.showMessageDialog self, msg
     end
     button_panel.add greet_button

     clear_button = JButton.new("Clear") { name_field.text = "" }
     button_panel.add clear_button

     contentPane.add name_panel, BorderLayout::CENTER
     contentPane.add button_panel, BorderLayout::SOUTH
   end
end # of HelloFrame class

HelloFrame.new.visible = true

---
Mark Volkmann
http://www.ociweb.com/mark


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Sizikov  
View profile  
 More options Oct 9 2009, 4:19 pm
From: Vladimir Sizikov <vsizi...@gmail.com>
Date: Fri, 9 Oct 2009 22:19:37 +0200
Local: Fri, Oct 9 2009 4:19 pm
Subject: Re: [jruby-user] block passing
On Fri, Oct 9, 2009 at 9:37 PM, Charles Oliver Nutter

<head...@headius.com> wrote:
> Ahh...interesting. Well if we fixed that NPE it might start "working"
> again, but obviously it's not the expected result. Which commit was
> it?

git bisect points to: c306f7f4b19162a83c1fa8f3b983e7e6c70083d9:
"Wire in closure-conversion logic for constructors, add specs for it,
and add more specs (and fix bugs discovered)"

Thanks,
   --Vladimir

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas E Enebo  
View profile  
 More options Oct 12 2009, 11:45 am
From: Thomas E Enebo <tom.en...@gmail.com>
Date: Mon, 12 Oct 2009 10:45:42 -0500
Local: Mon, Oct 12 2009 11:45 am
Subject: Re: [jruby-user] block passing
On Fri, Oct 9, 2009 at 2:37 PM, Charles Oliver Nutter

Another possible breaker is Rubeus...It actively made a whole
framework around suppluing blocks to all Swing component constructors
(I am not sure how it is implemented yet to know):

http://code.google.com/p/rubeus/source/browse/trunk/examples/nyanco_v...

-Tom

--
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.en...@gmail.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Oct 12 2009, 12:17 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Mon, 12 Oct 2009 10:17:48 -0600
Local: Mon, Oct 12 2009 12:17 pm
Subject: Re: [jruby-user] block passing
On Mon, Oct 12, 2009 at 9:45 AM, Thomas E Enebo <tom.en...@gmail.com> wrote:

> Another possible breaker is Rubeus...It actively made a whole
> framework around suppluing blocks to all Swing component constructors
> (I am not sure how it is implemented yet to know):

I'm pretty sure they monkey-patched "new" on those Java classes to
take blocks and run them, so they'd probably be fine.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Oliver Nutter  
View profile  
 More options Oct 12 2009, 12:23 pm
From: Charles Oliver Nutter <head...@headius.com>
Date: Mon, 12 Oct 2009 10:23:49 -0600
Local: Mon, Oct 12 2009 12:23 pm
Subject: Re: [jruby-user] block passing

On Fri, Oct 9, 2009 at 2:19 PM, Vladimir Sizikov <vsizi...@gmail.com> wrote:
> git bisect points to: c306f7f4b19162a83c1fa8f3b983e7e6c70083d9:
> "Wire in closure-conversion logic for constructors, add specs for it,
> and add more specs (and fix bugs discovered)"

Filed http://jira.codehaus.org/browse/JRUBY-4087 for it. Marked as
minor since the block-to-Icon is unexpected and wouldn't be useful
even if this was working.

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »