diff --git a/bt.rb b/bt.rb index b5876d0..d0938db 100644 --- a/bt.rb +++ b/bt.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby +# XXX: Local hack to pick up the proper SWT classes on FreeBSD $CLASSPATH << '/usr/local/share/java/classes/swt.jar' require 'java' @@ -9,9 +10,13 @@ require 'rubygems' require 'colorize' require 'flickr' - puts 'Starting bt'.green config = YAML.load(File.open('.flickr.yml').read) -puts "Using Flickr API configuration: #{config}".yellow +#puts "Using Flickr API configuration: #{config}".yellow +require_relative 'bt/main' + +puts '..ending bt'.green + +BT::Main.new.run diff --git a/bt/main.rb b/bt/main.rb new file mode 100644 index 0000000..7ee61f7 --- /dev/null +++ b/bt/main.rb @@ -0,0 +1,81 @@ + +module BT + class Main + include_package 'org.eclipse.swt' + include_package 'org.eclipse.swt.layout' + include_package 'org.eclipse.swt.graphics' + include_package 'org.eclipse.swt.widgets' + + attr_reader :display, :shell + def initialize + @display = Display.new + @shell = Shell.new display + end + + def prepare + Display.app_name = 'BT' + + shell.setSize(450, 200) + + layout = RowLayout.new + layout.wrap = true + + shell.layout = layout + shell.text = 'BT in JRuby' + stop_scroll = false + + b = Button.new(shell, SWT::PUSH) + b.add_selection_listener do |event| + if stop_scroll + puts 'starting' + stop_scroll = false + b.text = 'Stop scroll' + else + puts 'stopping' + stop_scroll = true + b.text = 'start scroll' + end + end + b.text = 'stop scroll' + + label = Label.new(shell, SWT::CENTER) + image = Image.new(display, File.expand_path('./jruby.png')) + label.image = image + + Thread.new do + loop do + while stop_scroll do + sleep 0.5 + end + + # Execute the movement in the display thread + display.sync_exec do + p = Point.new(label.location.x, label.location.y + 2) + label.location = p + end + sleep 1 + end + end + + shell.pack + shell.open + end + + def run + prepare + + until shell.is_disposed do + unless display.read_and_dispatch + display.sleep + end + end + + shutdown + end + + def shutdown + display.dispose + end + end +end + diff --git a/build.gradle b/build.gradle index 906e789..9fd5115 100644 --- a/build.gradle +++ b/build.gradle @@ -13,10 +13,13 @@ import com.github.jrubygradle.JRubyExec dependencies { jrubyExec 'rubygems:colorize:0.7.3+' jrubyExec 'rubygems:flickr.rb:1.2.1+' + jrubyExec 'rubygems:pry:0.10.1+' } + task ticker(type: JRubyExec) { - script 'bt' + standardInput System.in + script 'bt.rb' } // vim: ft=groovy diff --git a/jruby.png b/jruby.png new file mode 100644 index 0000000..e3fa83f Binary files /dev/null and b/jruby.png differ