Skip to content

Commit

Permalink
Added support for Facets 2.9.0 and JRuby 1.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Maleh committed Feb 18, 2011
1 parent 382b308 commit 1f387da
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 193 deletions.
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use jruby@glimmer --create
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'http://rubygems.org'

gem 'facets', '2.9.0'
12 changes: 9 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ data-binding support to greatly facilitate synchronizing UI with domain models.
Instructions for use with stand-alone SWT:
1. Download the "SWT binary and source" archive from the Eclipse site and follow their instructions.
http://www.eclipse.org/swt/
2. Have your program require the file: src/swt.rb
3. Create a class that includes the Glimmer module and you will be able to write Glimmer syntax
2. Download and setup jRuby 1.5.6 (rvm install jruby -v1.5.6)
3. Have your program require the file: src/swt.rb
4. Create a class that includes the Glimmer module and you will be able to write Glimmer syntax

Instructions for use with Eclipse:
1. Download and setup Eclipse 3.4, 3.3 or 3.2
2. Download and setup jRuby 1.1.5
2. Download and setup jRuby 1.5.6 (rvm install jruby -v1.5.6)
3. Modify Java launch command in jRuby script/batch file to include SWT libraries in both:
a. Classpath; must include %ECLIPSE_HOME%/plugins/org.eclipse.swt*.jar
For example with Eclipse 3.2 on Windows, we add the following:
Expand All @@ -31,3 +32,8 @@ Instructions for use with Eclipse:
5. Create a class that includes the Glimmer module and you will be able to write Glimmer syntax

Check samples folder for examples on how to write Glimmer applications.

Note:

In order to run Glimmer on the Mac, you need to pass an extra option to JRuby. For example:
jruby samples/hello_world.rb -XstartOnFirstThread
316 changes: 158 additions & 158 deletions lib/command_handlers/models/r_widget.rb
Original file line number Diff line number Diff line change
@@ -1,159 +1,159 @@
################################################################################
# Copyright (c) 2008 Annas Al Maleh.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Annas Al Maleh - initial API and implementation
################################################################################

require File.dirname(__FILE__) + "/r_widget_listener"
require File.dirname(__FILE__) + "/r_runnable"

class RWidget
require File.dirname(__FILE__) + "/r_widget_packages"

include Parent

attr_reader :widget

#TODO externalize
@@default_styles = {
"text" => SWT::BORDER,
"table" => SWT::BORDER,
"spinner" => SWT::BORDER,
"list" => SWT::BORDER | SWT::V_SCROLL,
"button" => SWT::PUSH,
}

#TODO externalize
@@default_initializers = {
"composite" => Proc.new {|composite| composite.setLayout(GridLayout.new) },
"table" => Proc.new do |table|
table.setHeaderVisible(true)
table.setLinesVisible(true)
end,
"table_column" => Proc.new { |table_column| table_column.setWidth(80) },
"group" => Proc.new {|group| group.setLayout(GridLayout.new) },
}

def initialize(underscored_widget_name, parent, style, &contents)
style = default_style(underscored_widget_name) unless style
@widget = eval underscored_widget_name.to_s.camelcase(true) + '.new(parent, style)'
@@default_initializers[underscored_widget_name].call(@widget) if @@default_initializers[underscored_widget_name]
end

def default_style(underscored_widget_name)
style = @@default_styles[underscored_widget_name] if @@default_styles[underscored_widget_name]
style = SWT::NONE unless style
style
end

def respond_to?(method_symbol, *args)
@widget.respond_to?("set" + method_symbol.to_s.camelcase(true), args)
end

def method_missing(method_symbol, *args)
statement_to_eval = "@widget.send('set' + method_symbol.to_s.camelcase(true)"
statement_to_eval << expand_arguments(args)
statement_to_eval << ")"
eval statement_to_eval
end

def expand_arguments(args)
expanded_args = ""
index = 0
args.each do
expanded_args << ", args[#{index}]"
index += 1
end
expanded_args
end

def self.widget_exists?(underscored_widget_name)
begin
eval underscored_widget_name.camelcase(true)
true
rescue NameError
false
end
end

def widget_listener_exists?(underscored_listener_name)
listener_method_name = underscored_listener_name.camelcase(false)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
return true
end
end
end
end
end
return false
end

def can_add_listener?(underscored_listener_name)
listener_method_name = underscored_listener_name.camelcase(false)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
return true
end
end
end
end
end
return false
end

def add_listener(underscored_listener_name, &block)
listener_method_name = underscored_listener_name.camelcase(false)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
listener_class = Class.new(Object)
listener_class.send :include, (eval listener_type.to_s.sub("interface", ""))
listener = listener_class.new
listener_type.getMethods.each do |t_method|
eval "def listener.#{t_method.getName}(event) end"
end
def listener.block=(block)
@block = block
end
listener.block=block
eval "def listener.#{listener_method.getName}(event) @block.call(event) if @block end"
@widget.send(widget_method.getName, listener)
return RWidgetListener.new(listener)
end
end
end
end
end
end

def process_block(block)
block.call(@widget)
end

def async_exec(&block)
@widget.getDisplay.asyncExec(RRunnable.new(&block))
end

def sync_exec(&block)
@widget.getDisplay.syncExec(RRunnable.new(&block))
end

def has_style?(style)
(widget.style & style) == style
end

################################################################################
# Copyright (c) 2008 Annas Al Maleh.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Annas Al Maleh - initial API and implementation
################################################################################

require File.dirname(__FILE__) + "/r_widget_listener"
require File.dirname(__FILE__) + "/r_runnable"

class RWidget
require File.dirname(__FILE__) + "/r_widget_packages"

include Parent

attr_reader :widget

#TODO externalize
@@default_styles = {
"text" => SWT::BORDER,
"table" => SWT::BORDER,
"spinner" => SWT::BORDER,
"list" => SWT::BORDER | SWT::V_SCROLL,
"button" => SWT::PUSH,
}

#TODO externalize
@@default_initializers = {
"composite" => Proc.new {|composite| composite.setLayout(GridLayout.new) },
"table" => Proc.new do |table|
table.setHeaderVisible(true)
table.setLinesVisible(true)
end,
"table_column" => Proc.new { |table_column| table_column.setWidth(80) },
"group" => Proc.new {|group| group.setLayout(GridLayout.new) },
}

def initialize(underscored_widget_name, parent, style, &contents)
style = default_style(underscored_widget_name) unless style
@widget = eval underscored_widget_name.to_s.camelcase + '.new(parent, style)'
@@default_initializers[underscored_widget_name].call(@widget) if @@default_initializers[underscored_widget_name]
end

def default_style(underscored_widget_name)
style = @@default_styles[underscored_widget_name] if @@default_styles[underscored_widget_name]
style = SWT::NONE unless style
style
end

def respond_to?(method_symbol, *args)
@widget.respond_to?("#{method_symbol.to_s}=", args)
end

def method_missing(method_symbol, *args)
statement_to_eval = "@widget.send(method_symbol.to_s + '='"
statement_to_eval << expand_arguments(args)
statement_to_eval << ")"
eval statement_to_eval
end

def expand_arguments(args)
expanded_args = ""
index = 0
args.each do
expanded_args << ", args[#{index}]"
index += 1
end
expanded_args
end

def self.widget_exists?(underscored_widget_name)
begin
eval underscored_widget_name.camelcase
true
rescue NameError
false
end
end

def widget_listener_exists?(underscored_listener_name)
listener_method_name = underscored_listener_name.listener_method_name(:lower)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
return true
end
end
end
end
end
return false
end

def can_add_listener?(underscored_listener_name)
listener_method_name = underscored_listener_name.camelcase(:lower)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
return true
end
end
end
end
end
return false
end

def add_listener(underscored_listener_name, &block)
listener_method_name = underscored_listener_name.camelcase(:lower)
@widget.getClass.getMethods.each do |widget_method|
if widget_method.getName.match(/add.*Listener/)
widget_method.getParameterTypes.each do |listener_type|
listener_type.getMethods.each do |listener_method|
if (listener_method.getName == listener_method_name)
listener_class = Class.new(Object)
listener_class.send :include, (eval listener_type.to_s.sub("interface", ""))
listener = listener_class.new
listener_type.getMethods.each do |t_method|
eval "def listener.#{t_method.getName}(event) end"
end
def listener.block=(block)
@block = block
end
listener.block=block
eval "def listener.#{listener_method.getName}(event) @block.call(event) if @block end"
@widget.send(widget_method.getName, listener)
return RWidgetListener.new(listener)
end
end
end
end
end
end

def process_block(block)
block.call(@widget)
end

def async_exec(&block)
@widget.getDisplay.asyncExec(RRunnable.new(&block))
end

def sync_exec(&block)
@widget.getDisplay.syncExec(RRunnable.new(&block))
end

def has_style?(style)
(widget.style & style) == style
end

end
Loading

0 comments on commit 1f387da

Please sign in to comment.