diff --git a/lib/shoes/configuration.rb b/lib/shoes/configuration.rb index 9e246b7c..7f2b9199 100644 --- a/lib/shoes/configuration.rb +++ b/lib/shoes/configuration.rb @@ -7,11 +7,22 @@ class << self attr_accessor :framework def framework=(value) - @framework = value - require value + # Only SWT works this way right now + if value.to_s == 'swt' + @framework = value.to_s.downcase + require "shoes/#{@framework}" + else + @framework = value + require value + end end def framework_class - constant(@framework.camelcase) + # Only SWT works this way right now + if @framework == 'swt' + constant("shoes/#{@framework}".modulize) + else + constant(@framework.camelcase) + end end end diff --git a/lib/swt_shoes.rb b/lib/shoes/swt.rb similarity index 56% rename from lib/swt_shoes.rb rename to lib/shoes/swt.rb index d6e75fde..1b119f62 100644 --- a/lib/swt_shoes.rb +++ b/lib/shoes/swt.rb @@ -7,15 +7,15 @@ def window(*a, &b) Shoes.app(*a, &b) end -require 'swt_shoes/element_methods' -require 'swt_shoes/app' -require 'swt_shoes/layout' -#require 'swt_shoes/window' -require 'swt_shoes/flow' -require 'swt_shoes/button' - -module SwtShoes - module Shoes +require 'shoes/swt/element_methods' +require 'shoes/swt/app' +require 'shoes/swt/layout' +#require 'shoes/swt/window' +require 'shoes/swt/flow' +require 'shoes/swt/button' + +module Shoes + module Swt include Log4jruby::LoggerForClass diff --git a/lib/swt_shoes/animation.rb b/lib/shoes/swt/animation.rb similarity index 100% rename from lib/swt_shoes/animation.rb rename to lib/shoes/swt/animation.rb diff --git a/lib/swt_shoes/app.rb b/lib/shoes/swt/app.rb similarity index 68% rename from lib/swt_shoes/app.rb rename to lib/shoes/swt/app.rb index a843e607..3314fb4a 100644 --- a/lib/swt_shoes/app.rb +++ b/lib/shoes/swt/app.rb @@ -2,7 +2,8 @@ #require 'shoes/framework_adapters/swt_shoes/window' -module SwtShoes +module Shoes +module Swt # Shoes::App.new creates a new Shoes application window! # The default window is a [flow] @@ -10,8 +11,8 @@ module SwtShoes module App def gui_init - self.gui_container = container = Swt::Widgets::Shell.new(Swt.display, Swt::SWT::CLOSE) - layout = Swt::Layout::RowLayout.new + self.gui_container = container = ::Swt::Widgets::Shell.new(::Swt.display, ::Swt::SWT::CLOSE) + layout = ::Swt::Layout::RowLayout.new container.setLayout(layout) opts = self.opts @@ -19,14 +20,14 @@ def gui_init container.setSize(self.width, self.height) container.setText(self.title) - container.addListener(Swt::SWT::Close, main_window_on_close) + container.addListener(::Swt::SWT::Close, main_window_on_close) end def gui_open self.gui_container.open - Swt.event_loop { Swt.display.isDisposed } + ::Swt.event_loop { ::Swt.display.isDisposed } Shoes.logger.debug "Swt.display disposed... exiting Shoes::App.new" end @@ -35,16 +36,17 @@ def gui_open def main_window_on_close lambda { Shoes.logger.debug "main_window on_close block begin... disposing Swt.display" - Swt.display.dispose + ::Swt.display.dispose Shoes.logger.debug "Swt.display disposed" } end end end +end module Shoes class App - include SwtShoes::App + include Swt::App end end diff --git a/lib/swt_shoes/button.rb b/lib/shoes/swt/button.rb similarity index 72% rename from lib/swt_shoes/button.rb rename to lib/shoes/swt/button.rb index 4c4bb51d..896e75a9 100644 --- a/lib/swt_shoes/button.rb +++ b/lib/shoes/swt/button.rb @@ -1,10 +1,11 @@ -module SwtShoes +module Shoes +module Swt module Button def gui_button_init # Create a button on the specified _shell_ #def initialize(container, text = 'Button', opts = {}, &blk) - self.gui_element = button = Swt::Widgets::Button.new(self.gui_container, Swt::SWT::PUSH) + self.gui_element = button = ::Swt::Widgets::Button.new(self.gui_container, ::Swt::SWT::PUSH) button.setText(self.text) #@native_widget.setBounds(10, 10, 150, 30) @@ -14,9 +15,10 @@ def gui_button_init end end +end module Shoes class Button - include SwtShoes::Button + include Swt::Button end end diff --git a/lib/swt_shoes/element_methods.rb b/lib/shoes/swt/element_methods.rb similarity index 97% rename from lib/swt_shoes/element_methods.rb rename to lib/shoes/swt/element_methods.rb index d17a1850..c3cb8c56 100644 --- a/lib/swt_shoes/element_methods.rb +++ b/lib/shoes/swt/element_methods.rb @@ -3,7 +3,8 @@ require 'white_shoes/element_methods' -module SwtShoes +module Shoes + module Swt module ElementMethods include WhiteShoes::ElementMethods @@ -54,4 +55,5 @@ module ElementMethods #end # end + end end diff --git a/lib/swt_shoes/flow.rb b/lib/shoes/swt/flow.rb similarity index 80% rename from lib/swt_shoes/flow.rb rename to lib/shoes/swt/flow.rb index ddc4d8ec..32dd2985 100644 --- a/lib/swt_shoes/flow.rb +++ b/lib/shoes/swt/flow.rb @@ -1,14 +1,15 @@ -module SwtShoes +module Shoes +module Swt # flow takes these options # :margin - integer - add this many pixels to all 4 sides of the layout module Flow def gui_flow_init - self.gui_container = container = Swt::Widgets::Composite.new(self.parent_gui_container, Swt::SWT::NONE) + self.gui_container = container = ::Swt::Widgets::Composite.new(self.parent_gui_container, ::Swt::SWT::NONE) # RowLayout is horizontal by default, wrapping by default - layout = Swt::Layout::RowLayout.new + layout = ::Swt::Layout::RowLayout.new # set the margins set_margin(layout) @@ -35,11 +36,12 @@ def set_margin(layout) end end end +end module Shoes class Flow - include SwtShoes::Flow + include Swt::Flow end end diff --git a/lib/swt_shoes/layout.rb b/lib/shoes/swt/layout.rb similarity index 86% rename from lib/swt_shoes/layout.rb rename to lib/shoes/swt/layout.rb index fac9316c..c6377699 100644 --- a/lib/swt_shoes/layout.rb +++ b/lib/shoes/swt/layout.rb @@ -1,6 +1,7 @@ #require 'shoes/framework_adapters/swt_shoes/element_methods' -module SwtShoes +module Shoes + module Swt class Layout DEFAULT_WIDTH = 800 @@ -8,18 +9,18 @@ class Layout DEFAULT_TITLE = "Shooes!" - include SwtShoes::ElementMethods + include Shoes::Swt::ElementMethods include Log4jruby::LoggerForClass # default initializer for calls to # super() from descendant classes def initialize(composite_parent, opts = {}, &blk) - @container = Swt::Widgets::Composite.new(composite_parent, Swt::SWT::NONE || Swt::SWT::BORDER) + @container = ::Swt::Widgets::Composite.new(composite_parent, ::Swt::SWT::NONE || ::Swt::SWT::BORDER) width, height = opts['width'] || DEFAULT_WIDTH, opts['height'] || DEFAULT_HEIGHT # RowLayout is horizontal by default, wrapping by default - @layout = Swt::Layout::RowLayout.new + @layout = ::Swt::Layout::RowLayout.new @layout.type = opts['layout_type'] if opts['layout_type'] @@ -60,4 +61,5 @@ def set_layout_margins(margin_pixels) end + end end diff --git a/lib/swt_shoes/runnable_block.rb b/lib/shoes/swt/runnable_block.rb similarity index 94% rename from lib/swt_shoes/runnable_block.rb rename to lib/shoes/swt/runnable_block.rb index 71b244e2..c58c0e40 100644 --- a/lib/swt_shoes/runnable_block.rb +++ b/lib/shoes/swt/runnable_block.rb @@ -39,7 +39,7 @@ def run @frame += 1 end def set_next_timer - Swt.display.timer_exec(@ms_per_frame, self) unless @stop + ::Swt.display.timer_exec(@ms_per_frame, self) unless @stop end end diff --git a/spec/swt_shoes/app_spec.rb b/spec/swt_shoes/app_spec.rb index a167ad3e..6e086eba 100644 --- a/spec/swt_shoes/app_spec.rb +++ b/spec/swt_shoes/app_spec.rb @@ -1,14 +1,14 @@ require "spec_helper" require "swt_shoes/spec_helper" -describe SwtShoes::App do +describe Shoes::Swt::App do describe "WhiteShoes requirements" do let(:mock_shell) { mock(:swt_shell, :setSize => true, :setText => true, :addListener => true, :setLayout => true) } before do - Swt::Widgets::Shell.stub(:new) { mock_shell } + ::Swt::Widgets::Shell.stub(:new) { mock_shell } end it_behaves_like "A WhiteShoes Shoes::App" @@ -28,4 +28,4 @@ #end -end \ No newline at end of file +end diff --git a/spec/swt_shoes/button_spec.rb b/spec/swt_shoes/button_spec.rb index 7c0923a0..3f8fd749 100644 --- a/spec/swt_shoes/button_spec.rb +++ b/spec/swt_shoes/button_spec.rb @@ -4,17 +4,17 @@ #require 'support/shared_examples_for_common_elements_spec' -describe SwtShoes::Button do +describe Shoes::Swt::Button do #it_should_behave_like "A Common Element" class ButtonShoeLaces - include SwtShoes::Button + include Shoes::Swt::Button attr_accessor :gui_container, :gui_element, :text, :height, :width, :margin, :click_event_lambda end - let(:stub_gui_parent) { Swt.display } + let(:stub_gui_parent) { ::Swt.display } let(:shoelace) { shoelace = ButtonShoeLaces.new debugger @@ -27,7 +27,7 @@ class ButtonShoeLaces :pack => true )} before do - Swt::Widgets::Button.stub(:new). + ::Swt::Widgets::Button.stub(:new). and_return mock_element end it_behaves_like "A WhiteShoes Shoes::Button" @@ -72,4 +72,4 @@ class ButtonShoeLaces # end #end -end \ No newline at end of file +end diff --git a/spec/swt_shoes/flow_spec.rb b/spec/swt_shoes/flow_spec.rb index c3d19b3a..3db948b8 100644 --- a/spec/swt_shoes/flow_spec.rb +++ b/spec/swt_shoes/flow_spec.rb @@ -2,14 +2,14 @@ require 'swt_shoes/spec_helper' -describe SwtShoes::Flow do +describe Shoes::Swt::Flow do class FlowShoeLaces - include SwtShoes::Flow + include Shoes::Swt::Flow attr_accessor :parent_gui_container, :gui_container, :opts, :width, :height, :margin end - let(:parent_gui_container) { Swt.display } + let(:parent_gui_container) { ::Swt.display } let(:mock_slot) { mock(:slot) } let(:shoelace) { shoelace = FlowShoeLaces.new @@ -19,7 +19,7 @@ class FlowShoeLaces describe "WhiteShoes requirements" do - let(:stub_gui_parent) { Swt::Widgets::Shell.new } + let(:stub_gui_parent) { ::Swt::Widgets::Shell.new } before do subject.parent_gui_container = stub_gui_parent end @@ -31,7 +31,7 @@ class FlowShoeLaces describe "gui_flow_init" do before do - Swt::Widgets::Composite.should_receive(:new).with(parent_gui_container, anything).and_return mock_slot + ::Swt::Widgets::Composite.should_receive(:new).with(parent_gui_container, anything).and_return mock_slot end it "should create a composite and set accessor" do mock_slot.stub(:setLayout) @@ -40,7 +40,7 @@ class FlowShoeLaces end it "should use a RowLayout" do - mock_slot.should_receive(:setLayout).with(an_instance_of(Swt::Layout::RowLayout)) + mock_slot.should_receive(:setLayout).with(an_instance_of(::Swt::Layout::RowLayout)) shoelace.gui_flow_init end @@ -56,7 +56,7 @@ class FlowShoeLaces mock_slot.stub(:setLayout) shoelace.margin = 131 mock_layout = mock(:layout) - Swt::Layout::RowLayout.should_receive(:new).and_return mock_layout + ::Swt::Layout::RowLayout.should_receive(:new).and_return mock_layout mock_layout.should_receive(:marginTop=).with 131 mock_layout.should_receive(:marginRight=).with 131 mock_layout.should_receive(:marginBottom=).with 131 diff --git a/spec/swt_shoes/spec_helper.rb b/spec/swt_shoes/spec_helper.rb index 577b3a9f..052b45e4 100644 --- a/spec/swt_shoes/spec_helper.rb +++ b/spec/swt_shoes/spec_helper.rb @@ -1,4 +1,4 @@ -require "swt_shoes" +require "shoes/swt" -require 'swt' \ No newline at end of file +require 'swt' diff --git a/swt-shoooes b/swt-shoooes index 9b0c9d07..8a038d64 100755 --- a/swt-shoooes +++ b/swt-shoooes @@ -5,8 +5,8 @@ $:<< "lib" require 'shoes' require 'shoes/configuration' -Shoes.configuration.framework = 'swt_shoes' +Shoes.configuration.framework = 'swt' require ARGV[0] -exit 0 \ No newline at end of file +exit 0