Created
August 1, 2013 16:56
-
-
Save amiracam/6133205 to your computer and use it in GitHub Desktop.
Working mods to komax javafx service example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See: http://docs.oracle.com/javafx/2/threads/jfxpub-threads.htm | |
require 'jrubyfx' | |
require 'open-uri' | |
class FirstLineURLTask < Java::javafx.concurrent.Task | |
attr_accessor :url | |
#def initialize(url) | |
# @url = url | |
#end | |
def call | |
puts "calling" | |
puts "Url is: #{@url}" | |
first_line = open(@url) do |f| | |
puts "reading line" | |
f.readline | |
end | |
puts first_line.inspect | |
return first_line | |
#puts "Url is: #{@url}" | |
#(1..5).each { |ea| puts "#{ea}" } | |
#'hi there' | |
end | |
end | |
class FirstLineService < Java::javafx.concurrent.Service | |
include JRubyFX | |
attr_accessor :url | |
protected | |
def createTask | |
task = FirstLineURLTask.new | |
task.url = @url | |
task | |
end | |
end | |
class FirstLineServiceApp < JRubyFX::Application | |
def start(stage) | |
service = FirstLineService.new | |
service.url = "http://google.com" | |
service.setOnSucceeded { puts "done" } | |
service.start() | |
with(stage, | |
title: "Service Demo: Retrieves first line of URL in background", width: 300, height: 150) do | |
layout_scene do | |
label(id: "result", text: "working") | |
end | |
end | |
stage.show | |
end | |
end | |
FirstLineServiceApp.launch | |
# This now works with some mods | |
# There seems to be an issue with "cascaded " calls to initialize and possibly the call to super in the subsequent | |
# initialize i.e. Service construction then subsequent Task construction , got rid of those that got me past the | |
# error below. However , the open uri called was failing since the string property was being passed as opposed to the | |
# string for the url. BTW, This was just getting stuck in IDEA i.e. no crash | |
# Since there was no binding being setup in this example I simply got rid of the | |
# property_accessor / StringProperty use, and just captured the url in a straight Ruby inst var | |
#Prior error and comment from komax | |
# I'll get | |
=begin | |
% jruby url_service_demo.rb | |
Exception running Application: | |
#<ArgumentError: wrong number of arguments (1 for 0)> | |
url_service_demo.rb:39:in `start' | |
/home/max/Programmierung/gsoc/jruby/lib/ruby/gems/shared/gems/jrubyfx-1.0.0-java/lib/jrubyfx/java_fx_impl.rb:120:in `launch_app_after_platform' | |
org/jruby/gen/InterfaceImpl299080017.gen:13:in `run' | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment