glimmer 0.4.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.markdown +324 -59
  3. data/lib/glimmer.rb +54 -63
  4. data/lib/glimmer/data_binding/list_selection_binding.rb +52 -0
  5. data/lib/glimmer/{swt → data_binding}/model_binding.rb +33 -5
  6. data/lib/glimmer/{swt → data_binding}/observable.rb +6 -3
  7. data/lib/glimmer/{swt → data_binding}/observable_array.rb +3 -1
  8. data/lib/glimmer/{swt → data_binding}/observable_model.rb +3 -2
  9. data/lib/glimmer/data_binding/observable_widget.rb +17 -0
  10. data/lib/glimmer/{swt → data_binding}/observer.rb +3 -3
  11. data/lib/glimmer/{shine.rb → data_binding/shine.rb} +2 -2
  12. data/lib/glimmer/{swt → data_binding}/table_items_binding.rb +12 -11
  13. data/lib/glimmer/{swt → data_binding}/tree_items_binding.rb +15 -12
  14. data/lib/glimmer/{swt → data_binding}/widget_binding.rb +2 -1
  15. data/lib/glimmer/dsl.rb +26 -0
  16. data/lib/glimmer/dsl/async_exec_expression.rb +12 -0
  17. data/lib/glimmer/dsl/bind_expression.rb +44 -0
  18. data/lib/glimmer/dsl/color_expression.rb +28 -0
  19. data/lib/glimmer/dsl/column_properties_expression.rb +22 -0
  20. data/lib/glimmer/dsl/combo_selection_data_binding_expression.rb +40 -0
  21. data/lib/glimmer/dsl/custom_widget_expression.rb +35 -0
  22. data/lib/glimmer/dsl/data_binding_expression.rb +33 -0
  23. data/lib/glimmer/dsl/display_expression.rb +12 -0
  24. data/lib/glimmer/dsl/engine.rb +80 -0
  25. data/lib/glimmer/dsl/exec_expression.rb +23 -0
  26. data/lib/glimmer/dsl/expression.rb +44 -0
  27. data/lib/glimmer/dsl/expression_handler.rb +48 -0
  28. data/lib/glimmer/dsl/layout_data_expression.rb +24 -0
  29. data/lib/glimmer/dsl/layout_expression.rb +26 -0
  30. data/lib/glimmer/dsl/list_selection_data_binding_expression.rb +42 -0
  31. data/lib/glimmer/dsl/observe_expression.rb +27 -0
  32. data/lib/glimmer/dsl/parent_expression.rb +12 -0
  33. data/lib/glimmer/dsl/property_expression.rb +20 -0
  34. data/lib/glimmer/dsl/shell_expression.rb +15 -0
  35. data/lib/glimmer/dsl/static_expression.rb +38 -0
  36. data/lib/glimmer/dsl/swt_expression.rb +23 -0
  37. data/lib/glimmer/dsl/sync_exec_expression.rb +13 -0
  38. data/lib/glimmer/dsl/tab_item_expression.rb +31 -0
  39. data/lib/glimmer/dsl/table_items_data_binding_expression.rb +29 -0
  40. data/lib/glimmer/dsl/tree_items_data_binding_expression.rb +30 -0
  41. data/lib/glimmer/dsl/tree_properties_expression.rb +24 -0
  42. data/lib/glimmer/dsl/widget_expression.rb +26 -0
  43. data/lib/glimmer/dsl/widget_listener_expression.rb +27 -0
  44. data/lib/glimmer/error.rb +6 -0
  45. data/lib/glimmer/invalid_keyword_error.rb +6 -0
  46. data/lib/glimmer/launcher.rb +39 -23
  47. data/lib/glimmer/swt/color_proxy.rb +48 -0
  48. data/lib/glimmer/swt/display_proxy.rb +49 -0
  49. data/lib/glimmer/swt/font_proxy.rb +72 -0
  50. data/lib/glimmer/swt/layout_data_proxy.rb +73 -0
  51. data/lib/glimmer/swt/{g_layout.rb → layout_proxy.rb} +24 -25
  52. data/lib/glimmer/swt/packages.rb +13 -0
  53. data/lib/glimmer/swt/shell_proxy.rb +108 -0
  54. data/lib/glimmer/swt/{g_swt.rb → swt_proxy.rb} +12 -5
  55. data/lib/glimmer/swt/tab_item_proxy.rb +59 -0
  56. data/lib/glimmer/swt/widget_listener_proxy.rb +17 -0
  57. data/lib/glimmer/swt/widget_proxy.rb +366 -0
  58. data/lib/glimmer/{swt → ui}/custom_shell.rb +4 -4
  59. data/lib/glimmer/{swt → ui}/custom_widget.rb +67 -51
  60. data/lib/glimmer/{swt → ui}/video.rb +13 -13
  61. data/lib/glimmer/{swt → util}/proc_tracker.rb +1 -1
  62. data/vendor/swt/linux/swt.jar +0 -0
  63. data/vendor/swt/mac/swt.jar +0 -0
  64. data/vendor/swt/windows/swt.jar +0 -0
  65. metadata +66 -70
  66. data/lib/glimmer/command_handler.rb +0 -15
  67. data/lib/glimmer/command_handler_chain_factory.rb +0 -32
  68. data/lib/glimmer/command_handler_chain_link.rb +0 -25
  69. data/lib/glimmer/command_handlers.rb +0 -46
  70. data/lib/glimmer/ext/module.rb +0 -20
  71. data/lib/glimmer/parent.rb +0 -7
  72. data/lib/glimmer/swt/command_handlers/bind_command_handler.rb +0 -56
  73. data/lib/glimmer/swt/command_handlers/color_command_handler.rb +0 -30
  74. data/lib/glimmer/swt/command_handlers/combo_selection_data_binding_command_handler.rb +0 -44
  75. data/lib/glimmer/swt/command_handlers/custom_widget_command_handler.rb +0 -26
  76. data/lib/glimmer/swt/command_handlers/data_binding_command_handler.rb +0 -40
  77. data/lib/glimmer/swt/command_handlers/display_command_handler.rb +0 -20
  78. data/lib/glimmer/swt/command_handlers/layout_command_handler.rb +0 -27
  79. data/lib/glimmer/swt/command_handlers/layout_data_command_handler.rb +0 -27
  80. data/lib/glimmer/swt/command_handlers/list_selection_data_binding_command_handler.rb +0 -49
  81. data/lib/glimmer/swt/command_handlers/observe_command_handler.rb +0 -35
  82. data/lib/glimmer/swt/command_handlers/property_command_handler.rb +0 -24
  83. data/lib/glimmer/swt/command_handlers/shell_command_handler.rb +0 -20
  84. data/lib/glimmer/swt/command_handlers/tab_item_command_handler.rb +0 -34
  85. data/lib/glimmer/swt/command_handlers/table_column_properties_data_binding_command_handler.rb +0 -29
  86. data/lib/glimmer/swt/command_handlers/table_items_data_binding_command_handler.rb +0 -34
  87. data/lib/glimmer/swt/command_handlers/tree_items_data_binding_command_handler.rb +0 -33
  88. data/lib/glimmer/swt/command_handlers/tree_properties_data_binding_command_handler.rb +0 -29
  89. data/lib/glimmer/swt/command_handlers/widget_command_handler.rb +0 -27
  90. data/lib/glimmer/swt/command_handlers/widget_listener_command_handler.rb +0 -48
  91. data/lib/glimmer/swt/g_color.rb +0 -41
  92. data/lib/glimmer/swt/g_display.rb +0 -36
  93. data/lib/glimmer/swt/g_font.rb +0 -71
  94. data/lib/glimmer/swt/g_layout_data.rb +0 -56
  95. data/lib/glimmer/swt/g_runnable.rb +0 -15
  96. data/lib/glimmer/swt/g_shell.rb +0 -106
  97. data/lib/glimmer/swt/g_tab_item_composite.rb +0 -41
  98. data/lib/glimmer/swt/g_widget.rb +0 -349
  99. data/lib/glimmer/swt/g_widget_listener.rb +0 -12
  100. data/lib/glimmer/swt/list_selection_binding.rb +0 -47
  101. data/lib/glimmer/swt_packages.rb +0 -15
  102. data/lib/glimmer/xml/command_handlers/html_command_handler.rb +0 -50
  103. data/lib/glimmer/xml/command_handlers/xml_command_handler.rb +0 -23
  104. data/lib/glimmer/xml/command_handlers/xml_name_space_command_handler.rb +0 -36
  105. data/lib/glimmer/xml/command_handlers/xml_tag_command_handler.rb +0 -28
  106. data/lib/glimmer/xml/command_handlers/xml_text_command_handler.rb +0 -24
  107. data/lib/glimmer/xml/depth_first_search_iterator.rb +0 -20
  108. data/lib/glimmer/xml/name_space_visitor.rb +0 -21
  109. data/lib/glimmer/xml/node.rb +0 -84
  110. data/lib/glimmer/xml/node_visitor.rb +0 -13
  111. data/lib/glimmer/xml/xml_visitor.rb +0 -63
  112. data/lib/glimmer/xml_command_handlers.rb +0 -18
@@ -0,0 +1,24 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/tree_items_binding'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ # Responsible for providing a readable keyword (command symbol) to capture
8
+ # and return tree properties for use in TreeItemsDataBindingCommandHandler
9
+ class TreePropertiesExpression < StaticExpression
10
+ include_package 'org.eclipse.swt.widgets'
11
+
12
+ def can_interpret?(parent, keyword, *args, &block)
13
+ keyword == "tree_properties" and
14
+ block.nil? and
15
+ widget?(parent) and
16
+ parent.swt_widget.is_a?(Tree)
17
+ end
18
+
19
+ def interpret(parent, keyword, *args, &block)
20
+ args
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'glimmer'
2
+ require 'glimmer/dsl/expression'
3
+ require 'glimmer/dsl/parent_expression'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ class WidgetExpression < Expression
8
+ include ParentExpression
9
+
10
+ EXCLUDED_KEYWORDS = %w[shell display tab_item]
11
+
12
+ def can_interpret?(parent, keyword, *args, &block)
13
+ !EXCLUDED_KEYWORDS.include?(keyword) and
14
+ widget?(parent) and
15
+ SWT::WidgetProxy.widget_exists?(keyword)
16
+ end
17
+
18
+ def interpret(parent, keyword, *args, &block)
19
+ Glimmer.logger.debug "widget styles are: " + args.inspect
20
+ SWT::WidgetProxy.new(keyword, parent, args)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ require 'glimmer/swt/widget_proxy'
@@ -0,0 +1,27 @@
1
+ require 'glimmer/dsl/expression'
2
+
3
+ module Glimmer
4
+ module DSL
5
+ class WidgetListenerExpression < Expression
6
+ include_package 'org.eclipse.swt.widgets'
7
+
8
+ def can_interpret?(parent, keyword, *args, &block)
9
+ Glimmer.logger.debug "keyword starts with on_: #{keyword.start_with?('on_')}"
10
+ return unless keyword.start_with?('on_')
11
+ Glimmer.logger.debug "block exists?: #{!block.nil?}"
12
+ return unless !block.nil?
13
+ widget_parentage = widget?(parent)
14
+ Glimmer.logger.debug "parent is a widget: #{widget_parentage}"
15
+ return unless widget_parentage
16
+ Glimmer.logger.debug "args are empty?: #{args.empty?}"
17
+ return unless args.empty?
18
+ result = parent.can_handle_observation_request?(keyword)
19
+ Glimmer.logger.debug "can add listener? #{result}"
20
+ end
21
+
22
+ def interpret(parent, keyword, *args, &block)
23
+ parent.handle_observation_request(keyword, &block)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ module Glimmer
2
+ # Represents Glimmer errors that occur due to invalid use of Glimmer
3
+ # without handing control flow back to original method_missing
4
+ class Error < RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Glimmer
2
+ # Represents Glimmer errors that occur due to invalid use of Glimmer
3
+ # without handing control flow back to original method_missing
4
+ class InvalidKeywordError < RuntimeError
5
+ end
6
+ end
@@ -4,17 +4,21 @@ module Glimmer
4
4
  class Launcher
5
5
  OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
6
6
  TEXT_USAGE = <<-MULTILINE
7
- Usage: glimmer application.rb
7
+ Usage: glimmer [[-jruby-option]...] application.rb [[application2.rb]...]
8
8
 
9
- Runs a Glimmer application using JRuby, automatically preloading
9
+ Runs Glimmer applications using JRuby, automatically preloading
10
10
  the glimmer ruby gem and SWT jar dependency.
11
11
 
12
- Example: glimmer hello_world.rb
13
- This runs the Glimmer application hello_world.rb
12
+ Optionally, JRuby options may be passed in.
13
+
14
+ Example: glimmer samples/hello_world.rb
15
+ This runs the Glimmer application samples/hello_world.rb
14
16
  MULTILINE
15
17
  GLIMMER_LIB_LOCAL = File.expand_path(File.join(__FILE__, '..', '..', 'glimmer.rb'))
16
18
  GLIMMER_LIB_GEM = 'glimmer'
17
19
 
20
+ @@mutex = Mutex.new
21
+
18
22
  class << self
19
23
  def platform_os
20
24
  OPERATING_SYSTEMS_SUPPORTED.detect {|os| OS.send("#{os}?")}
@@ -32,40 +36,52 @@ module Glimmer
32
36
  "#{jruby_os_specific_options} -J-classpath \"#{swt_jar_file}\""
33
37
  end
34
38
 
35
- def launch(application, dev_mode = false, debug_mode = false)
36
- glimmer_lib = GLIMMER_LIB_GEM
37
- if dev_mode
38
- glimmer_lib = GLIMMER_LIB_LOCAL
39
- puts "[DEVELOPMENT MODE] (#{glimmer_lib})"
40
- end
41
- debug_option = ''
42
- if debug_mode
43
- debug_option = '--debug '
44
- puts "[DEBUG MODE]"
39
+ def glimmer_lib
40
+ @@mutex.synchronize do
41
+ unless @glimmer_lib
42
+ @glimmer_lib = GLIMMER_LIB_GEM
43
+ glimmer_gem_listing = `jgem list #{GLIMMER_LIB_GEM}`
44
+ if !glimmer_gem_listing.include?(GLIMMER_LIB_GEM) && File.exists?(GLIMMER_LIB_LOCAL)
45
+ @glimmer_lib = GLIMMER_LIB_LOCAL
46
+ puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})"
47
+ end
48
+ end
45
49
  end
46
- system "jruby #{debug_option}#{jruby_swt_options} -r #{glimmer_lib} -S #{application}"
50
+ @glimmer_lib
51
+ end
52
+
53
+ def launch(application, options = [])
54
+ options_string = options.join(' ') + ' ' if options.any?
55
+ system "jruby #{options_string}#{jruby_swt_options} -r #{glimmer_lib} -S #{application}"
47
56
  end
48
57
  end
49
58
 
50
59
  def initialize(options)
51
- @dev_mode = !!options.delete('--dev')
52
- @debug_mode = !!options.delete('--debug')
53
- @application_path = options.first
60
+ @application_paths = options.select {|option| !option.start_with?('-')}
61
+ @application_paths.each do |application_path|
62
+ options.delete(application_path)
63
+ end
64
+ @options = options
54
65
  end
55
66
 
56
67
  def launch
57
- if @application_path
58
- launch_application
59
- else
68
+ if @application_paths.empty?
60
69
  display_usage
70
+ else
71
+ launch_application
61
72
  end
62
73
  end
63
74
 
64
75
  private
65
76
 
66
77
  def launch_application
67
- puts "Launching Glimmer Application: #{@application_path}" unless @application_path == 'irb'
68
- self.class.launch(@application_path, @dev_mode, @debug_mode)
78
+ threads = @application_paths.map do |application_path|
79
+ puts "Launching Glimmer Application: #{application_path}" unless application_path.to_s.include?('irb')
80
+ Thread.new do
81
+ self.class.launch(application_path, @options)
82
+ end
83
+ end
84
+ threads.each(&:join)
69
85
  end
70
86
 
71
87
  def display_usage
@@ -0,0 +1,48 @@
1
+ require 'glimmer/swt/swt_proxy'
2
+ require 'glimmer/swt/display_proxy'
3
+
4
+ module Glimmer
5
+ module SWT
6
+ # Proxy for org.eclipse.swt.graphics.Color
7
+ #
8
+ # Invoking `#swt_color` returns the SWT color object wrapped by this proxy
9
+ #
10
+ # Follows the Proxy Design Pattern
11
+ class ColorProxy
12
+ include_package 'org.eclipse.swt.graphics'
13
+
14
+ attr_reader :swt_color
15
+
16
+ # Initializes a proxy for an SWT Color object
17
+ #
18
+ # Takes a standard color single argument, rgba 3 args, or rgba 4 args
19
+ #
20
+ # A standard color is a string/symbol representing one of the
21
+ # SWT.COLOR_*** constants like SWT.COLOR_RED, but in underscored string
22
+ # format (e.g :color_red).
23
+ # Glimmer can also accept standard color names without the color_ prefix,
24
+ # and it will automatically figure out the SWT.COLOR_*** constant
25
+ # (e.g. :red)
26
+ #
27
+ # rgb is 3 arguments representing Red, Green, Blue numeric values
28
+ #
29
+ # rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
30
+ #
31
+ def initialize(*args)
32
+ case args.size
33
+ when 1
34
+ if args.first.is_a?(String) || args.first.is_a?(Symbol)
35
+ standard_color = args.first
36
+ standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
37
+ @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
38
+ else
39
+ @swt_color = args.first
40
+ end
41
+ when 3..4
42
+ red, green, blue, alpha = args
43
+ @swt_color = Color.new(DisplayProxy.instance.swt_display, *[red, green, blue, alpha].compact)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ module Glimmer
2
+ module SWT
3
+ # Proxy for org.eclipse.swt.widgets.Display
4
+ #
5
+ # Maintains a singleton instance since SWT only supports
6
+ # a single active display at a time.
7
+ #
8
+ # Supports SWT Display's very useful asyncExec and syncExec methods
9
+ # to support proper multi-threaded manipulation of SWT UI objects
10
+ #
11
+ # Invoking `#swt_display` returns the SWT Display object wrapped by this proxy
12
+ #
13
+ # Follows the Proxy Design Pattern
14
+ class DisplayProxy
15
+ include_package 'org.eclipse.swt.widgets'
16
+
17
+ class << self
18
+ # Returns singleton instance
19
+ def instance(*args)
20
+ if @instance.nil? || @instance.swt_display.isDisposed
21
+ @instance = new(*args)
22
+ end
23
+ @instance
24
+ end
25
+ end
26
+
27
+ # SWT Display object wrapped
28
+ attr_reader :swt_display
29
+
30
+ def initialize(*args)
31
+ @swt_display = Display.new(*args)
32
+ end
33
+
34
+ def dispose
35
+ @swt_display.dispose
36
+ end
37
+
38
+ # Executes code block asynchronously with respect to SWT UI thread
39
+ def async_exec(&block)
40
+ @swt_display.asyncExec(&block)
41
+ end
42
+
43
+ # Executes code block synchronously with respect to SWT UI thread
44
+ def sync_exec(&block)
45
+ @swt_display.syncExec(&block)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,72 @@
1
+ require 'glimmer/error'
2
+ require 'glimmer/swt/swt_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
+
5
+ module Glimmer
6
+ module SWT
7
+ # Proxy for org.eclipse.swt.graphics.Font
8
+ #
9
+ # This class is meant to be used with WidgetProxy to manipulate
10
+ # an SWT widget font.
11
+ #
12
+ # It is not meant to create new SWT fonts form scratch without
13
+ # a widget proxy.
14
+ #
15
+ # Invoking `#swt_font` returns the SWT Font object wrapped by this proxy
16
+ #
17
+ # Follows the Proxy Design Pattern
18
+ class FontProxy
19
+ ERROR_INVALID_FONT_STYLE = " is an invalid font style! Valid values are :normal, :bold, and :italic"
20
+ FONT_STYLES = [:normal, :bold, :italic]
21
+
22
+ include_package 'org.eclipse.swt.graphics'
23
+
24
+ attr_reader :widget_proxy, :swt_font
25
+
26
+ # Builds a new font proxy from passed in widget_proxy and font_properties hash,
27
+ #
28
+ # It begins with existing SWT widget font and amends it with font properties.
29
+ #
30
+ # Font properties consist of: :name, :height, and :style (one needed minimum)
31
+ #
32
+ # Style (:style value) can only be one of FontProxy::FONT_STYLES values:
33
+ # that is :normal, :bold, or :italic
34
+ def initialize(widget_proxy, font_properties)
35
+ @widget_proxy = widget_proxy
36
+ detect_invalid_font_property(font_properties)
37
+ font_properties[:style] = SWTProxy[*font_properties[:style]]
38
+ font_data_args = [:name, :height, :style].map do |font_property_name|
39
+ font_properties[font_property_name] || send(font_property_name)
40
+ end
41
+ font_datum = FontData.new(*font_data_args)
42
+ @swt_font = Font.new(DisplayProxy.instance.swt_display, font_datum)
43
+ end
44
+
45
+ def name
46
+ font_datum.getName
47
+ end
48
+
49
+ def height
50
+ font_datum.getHeight
51
+ end
52
+
53
+ def style
54
+ font_datum.getStyle
55
+ end
56
+
57
+ private
58
+
59
+ def font_datum
60
+ @font_datum ||= @widget_proxy.swt_widget.getFont.getFontData[0]
61
+ end
62
+
63
+ def detect_invalid_font_property(font_properties)
64
+ [font_properties[:style]].flatten.select do |style|
65
+ style.is_a?(Symbol) || style.is_a?(String)
66
+ end.each do |style|
67
+ raise Error, style.to_s + ERROR_INVALID_FONT_STYLE if !FONT_STYLES.include?(style.to_sym)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,73 @@
1
+ require 'glimmer'
2
+ require 'glimmer/swt/swt_proxy'
3
+
4
+ module Glimmer
5
+ module SWT
6
+ # Generic proxy for all SWT layout data objects, such as GridData & RowData
7
+ #
8
+ # This class is meant to be used with an existing WidgetProxy
9
+ # as it figures out the right SWT layout data class name
10
+ # by convention from the parent SWT widget layout class name
11
+ #
12
+ # The convention is:
13
+ # - Start with the parent widget layout package/class name (e.g. org.eclipse.swt.layout.RowLayout)
14
+ # - Replace the word "Layout" with "Data" in the class name
15
+ #
16
+ # Examples of figuring out SWT layout data class:
17
+ # - org.eclipse.swt.layout.RowData for org.eclipse.swt.layout.RowLayout
18
+ # - org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
19
+ #
20
+ # Follows the Proxy Design Pattern
21
+ class LayoutDataProxy
22
+ include_package 'org.eclipse.swt.layout'
23
+
24
+ attr_reader :widget_proxy
25
+ attr_reader :swt_layout_data
26
+
27
+ # Inititalizes with owning widget proxy and layout data arguments
28
+ def initialize(widget_proxy, args)
29
+ @widget_proxy = widget_proxy
30
+ args = SWTProxy.constantify_args(args)
31
+ begin
32
+ @swt_layout_data = swt_layout_data_class.new(*args)
33
+ rescue => e
34
+ Glimmer.logger.debug "#{e.message}\n#{e.backtrace.join("\n")}"
35
+ @swt_layout_data = args.first if args.count == 1
36
+ end
37
+ @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
38
+ end
39
+
40
+ # This figures out the right SWT layout data class name
41
+ # by convention from the parent SWT widget layout class name
42
+ #
43
+ # Supports layout data classes in and out of basic SWT library
44
+ #
45
+ # The convention is:
46
+ # - Start with the parent widget layout package/class name (e.g. org.eclipse.swt.layout.RowLayout)
47
+ # - Replace the word "Layout" with "Data" in the class name
48
+ #
49
+ # Examples of figuring out SWT layout data class:
50
+ # - org.eclipse.swt.layout.RowData for org.eclipse.swt.layout.RowLayout
51
+ # - org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
52
+ #
53
+ def swt_layout_data_class
54
+ parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
55
+ layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
56
+ eval(layout_data_class_name)
57
+ end
58
+
59
+ def has_attribute?(attribute_name, *args)
60
+ @swt_layout_data.respond_to?(attribute_setter(attribute_name), args)
61
+ end
62
+
63
+ def set_attribute(attribute_name, *args)
64
+ args = SWTProxy.constantify_args(args)
65
+ @swt_layout_data.send(attribute_setter(attribute_name), *args)
66
+ end
67
+
68
+ def attribute_setter(attribute_name)
69
+ "#{attribute_name.to_s.camelcase(:lower)}="
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,18 +1,20 @@
1
- require_relative '../parent'
2
- require_relative 'g_swt'
1
+ require 'glimmer'
2
+ require 'glimmer/swt/swt_proxy'
3
3
 
4
4
  module Glimmer
5
5
  module SWT
6
- class GLayout
7
- include_package 'org.eclipse.swt.layout'
8
-
9
- include Parent
10
-
11
- attr_reader :composite
12
- attr_reader :layout
6
+ # Proxy for org.eclipse.swt.widgets.Layout
7
+ #
8
+ # This is meant to be used with a WidgetProxy where it will
9
+ # set the layout in the SWT widget upon instantiation.
10
+ #
11
+ # Follows the Proxy Design Pattern
12
+ class LayoutProxy
13
+ attr_reader :widget_proxy, :swt_layout
13
14
 
14
15
  class << self
15
16
  include_package 'org.eclipse.swt.layout'
17
+ include_package 'org.eclipse.swt.widgets'
16
18
 
17
19
  def layout_exists?(underscored_layout_name)
18
20
  begin
@@ -23,44 +25,41 @@ module Glimmer
23
25
  end
24
26
  end
25
27
 
26
- # This supports layouts in and out of basic SWT
28
+ # This supports layouts in and out of basic SWT library
27
29
  def swt_layout_class_for(underscored_layout_name)
28
30
  swt_layout_name = underscored_layout_name.camelcase(:upper)
29
31
  swt_layout_class = eval(swt_layout_name)
30
- unless swt_layout_class.ancestors.include?(org.eclipse.swt.widgets.Layout)
32
+ unless swt_layout_class.ancestors.include?(Layout)
31
33
  raise NameError, "Class #{swt_layout_class} matching #{underscored_layout_name} is not a subclass of org.eclipse.swt.widgets.Layout"
32
34
  end
33
35
  swt_layout_class
34
36
  rescue => e
35
- Glimmer.logger.debug "#{e.message}\n#{e.backtrace.join("\n")}"
37
+ Glimmer.logger.debug e.message
38
+ # Glimmer.logger.debug "#{e.message}\n#{e.backtrace.join("\n")}"
36
39
  raise e
37
40
  end
38
41
  end
39
42
 
40
- def initialize(underscored_layout_name, composite, args)
43
+ def initialize(underscored_layout_name, widget_proxy, args)
41
44
  @underscored_layout_name = underscored_layout_name
42
- @composite = composite
43
- args = GSWT.constantify_args(args)
44
- @layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
45
- @composite.setLayout(@layout)
46
- end
47
-
48
- def process_block(block)
49
- block.call(self)
45
+ @widget_proxy = widget_proxy
46
+ args = SWTProxy.constantify_args(args)
47
+ @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
48
+ @widget_proxy.swt_widget.setLayout(@swt_layout)
50
49
  end
51
50
 
52
51
  def has_attribute?(attribute_name, *args)
53
- @layout.respond_to?(attribute_setter(attribute_name), args)
52
+ @swt_layout.respond_to?(attribute_setter(attribute_name), args)
54
53
  end
55
54
 
56
55
  def set_attribute(attribute_name, *args)
57
56
  apply_property_type_converters(attribute_name, args)
58
- @layout.send(attribute_setter(attribute_name), *args)
57
+ @swt_layout.send(attribute_setter(attribute_name), *args)
59
58
  end
60
59
 
61
60
  def apply_property_type_converters(attribute_name, args)
62
- if args.count == 1 && GSWT.has_constant?(args.first)
63
- args[0] = GSWT.constant(args.first)
61
+ if args.count == 1 && SWTProxy.has_constant?(args.first)
62
+ args[0] = SWTProxy.constant(args.first)
64
63
  end
65
64
  end
66
65