Skip to content

Commit

Permalink
Refactor Framework System
Browse files Browse the repository at this point in the history
Shoes now depends upon one of Shoes Gui Plugins :

WhiteShoes - The "null adapter", this plugin contains the minimum strucutre to pass the basic requirements of a plugin.
SwtShoes - Gui based upon Eclipse SWT Java lib.
SwingShoes - Gui based upon Java Swing.

Specs for WhiteShoes include some expectations that should be set upon every Gui implementation.
These are held in ./spec/white_shoes/shared_examples.
There will be one shared-example for each Shoes::<class>
  • Loading branch information
pjfitzgibbons committed Jan 19, 2012
1 parent 800a475 commit b8093ac
Show file tree
Hide file tree
Showing 31 changed files with 285 additions and 462 deletions.
9 changes: 0 additions & 9 deletions lib/shoes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@
require 'rubygems'
require 'facets/hash'

#$:<< 'lib/shoes'

require 'lib/log4j/log4j-1.2.16.jar'
require 'log4jruby'
require 'log4jruby/logger_for_class'
logger = Log4jruby::Logger.get('test', :tracing => true, :level => :debug )
logger.debug("Shoooes!")

require 'shoes/configuration'
Shoes.configuration.framework ||= 'swing_shoes'

require 'shoes/base_object'



require 'shoes/app'
#require 'shoes/native'
#require 'shoes/element_methods'
Expand Down
105 changes: 61 additions & 44 deletions lib/shoes/app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'shoes/element_methods'
require 'facets/hash'

def window(*a, &b)
Shoes.app(*a, &b)
Expand All @@ -11,18 +12,34 @@ def self.app(opts={}, &blk)
Shoes::App.new(opts, &blk)
end

class App < BaseObject
class App

DEFAULTS = { 'width' => 800, 'height' => 600, 'title' => "Shoooes!"}

include Shoes::ElementMethods

attr_accessor :elements, :framework_adapter
attr_accessor :elements, :gui_container
attr_accessor :opts, :blk

attr_accessor :width, :height, :title

def initialize(opts={}, &blk)
opts.stringify_keys!
opts = DEFAULTS.merge(opts)
self.width = opts['width']
self.height = opts['height']
self.title = opts['title']

self.opts = opts
self.blk = blk

@framework_adapter = self.framework.new self
gui_init

flow do
instance_eval &blk if blk
end

gui_open

end

Expand Down Expand Up @@ -78,46 +95,46 @@ def initialize(opts={}, &blk)
# button
#end

def image(path, opts={})
image = Image.new(path, @current_panel, opts)
@elements[image.identifier] = image
image
end

def edit_line(opts={})
eline = Edit_line.new(@current_panel, opts)
@elements[eline.identifier] = eline
eline
end

def text_box(opts={})
tbox = Text_box.new(@current_panel, opts)
@elements[tbox.identifier] = tbox
tbox
end

def check(opts={}, &blk)
cbox = Check.new(@current_panel, opts)
@elements[cbox.identifier] = cbox
cbox
end

def stack(opts={}, &blk)
tstack = Stack.new(opts)
layout(tstack, &blk)
end

def flow(opts={}, &blk)
tflow = Flow.new(@container, opts, &blk)
#layout(tflow, &blk)
end

def layout(layer, &blk)
parent = @current_panel
@current_panel = layer.panel
instance_eval &blk
parent.add(@current_panel)
@current_panel = parent
end
#def image(path, opts={})
# image = Image.new(path, @current_panel, opts)
# @elements[image.identifier] = image
# image
#end
#
#def edit_line(opts={})
# eline = Edit_line.new(@current_panel, opts)
# @elements[eline.identifier] = eline
# eline
#end
#
#def text_box(opts={})
# tbox = Text_box.new(@current_panel, opts)
# @elements[tbox.identifier] = tbox
# tbox
#end
#
#def check(opts={}, &blk)
# cbox = Check.new(@current_panel, opts)
# @elements[cbox.identifier] = cbox
# cbox
#end
#
#def stack(opts={}, &blk)
# tstack = Stack.new(opts)
# layout(tstack, &blk)
#end
#
##def flow(opts={}, &blk)
## tflow = Flow.new(@container, opts, &blk)
## #layout(tflow, &blk)
##end
#
#def layout(layer, &blk)
# parent = @current_panel
# @current_panel = layer.panel
# instance_eval &blk
# parent.add(@current_panel)
# @current_panel = parent
#end
end
end
44 changes: 17 additions & 27 deletions lib/swing_shoes/app.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SwingShoes

class App < WhiteShoes::App
module App

attr_reader :frame, :container

Expand All @@ -11,44 +11,34 @@ class App < WhiteShoes::App
import java.awt.BorderLayout
import javax.swing.BoxLayout

DEFAULT_HEIGHT = 600
DEFAULT_WIDTH = 800
def gui_init

def initialize(adapted_object)
super
opts = adapted_object.opts
blk = adapted_object.blk
frame = JFrame.new()

opts.stringify_keys!
height = opts['height'] ||= DEFAULT_HEIGHT
width = opts['width'] ||= DEFAULT_WIDTH
self.gui_container = container = frame.get_content_pane

@elements = {}
@frame = JFrame.new()
layout = FlowLayout.new(FlowLayout::LEFT)

@container = @frame.get_content_pane

@layout = FlowLayout.new(FlowLayout::LEFT)

@frame.setLayout(@layout)
frame.setLayout(layout)

instance_eval &blk if blk

@frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
#@container.border = javax.swing.border.LineBorder.new(java.awt.Color::BLUE, 4, true)
#@container.setBackground(java.awt.Color::BLUE)
frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)

#@frame.pack()
if opts['pack']
@frame.pack
frame.pack
else
@frame.setSize(Dimension.new(opts['width'], opts['height']))
@container.setSize(Dimension.new(opts['width'], opts['height']))
frame.setSize(Dimension.new(self.width, self.height))
container.setSize(Dimension.new(self.width, self.height))
end
@frame.set_visible(true)

#debugger; 1
frame.set_visible(true)

end
end
end

module Shoes
class App
include SwingShoes::App
end
end
44 changes: 17 additions & 27 deletions lib/swt_shoes/app.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'shoes'
require 'swt'

#require 'shoes/framework_adapters/swt_shoes/window'
Expand All @@ -8,38 +7,22 @@ module SwtShoes
# Shoes::App.new creates a new Shoes application window!
# The default window is a [flow]
#
class App < WhiteShoes::App
include SwtShoes::ElementMethods
module App

include Log4jruby::LoggerForClass
def gui_init
self.gui_container = container = Swt::Widgets::Shell.new($display, Swt::SWT::CLOSE)

attr_accessor :elements, :frame
attr_accessor :main_shell, :container
opts = self.opts

DEFAULT_WIDTH = 800
DEFAULT_HEIGHT = 600
DEFAULT_TITLE = "Shooes!"
container.setSize(self.width, self.height)
container.setText(self.title)

def initialize(adapted_object)
@elements = {}

opts = adapted_object.opts
blk = adapted_object.blk

@container = Swt::Widgets::Shell.new($display, Swt::SWT::CLOSE)

width, height = opts['width'] || DEFAULT_WIDTH, opts['height'] || DEFAULT_HEIGHT

@container.setSize(width, height)
@container.setText(opts['title'] || DEFAULT_TITLE)

@container.addListener(Swt::SWT::Close, main_window_on_close)
container.addListener(Swt::SWT::Close, main_window_on_close)
end

flow do
instance_eval &blk if blk
end

@container.open
def gui_open
container.open

Swt.event_loop { Swt.display.isDisposed }

Expand All @@ -56,3 +39,10 @@ def main_window_on_close
end
end
end

module Shoes
class App
include SwtShoes::App
end
end

25 changes: 9 additions & 16 deletions lib/white_shoes/app.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
module WhiteShoes
# Adapter Template for the BaseApp methods specific for the framework.
class App < Base
module App

def initialize(adapted_object)
super
def gui_init
self.gui_container = "A new Gui Container Instance"
end

# Runs the application, starting anything the framework needs.
def run
end

# Refreshes the GUI application, running just one event loop.
#
# This method is mostly useful when writing tests. It shouldn't be used
# in normal applications.
def refresh
end

# Exits the application, freeing any resources used by the framework.
def quit
def gui_open
# no-op
end
end
end

class Shoes::App
include WhiteShoes::App
end

21 changes: 21 additions & 0 deletions rspec-white
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env jruby --1.9 --debug
#
# This file was generated by RubyGems.
#
# The application 'rspec-core' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
ARGV.shift
end

gem 'rspec-core', version
load Gem.bin_path('rspec-core', 'rspec', version)

exit 0
32 changes: 0 additions & 32 deletions spec/brown_shoes/check_spec.rb

This file was deleted.

Loading

0 comments on commit b8093ac

Please sign in to comment.