glimmer-dsl-swt 4.18.5.0 → 4.18.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,10 +22,15 @@
22
22
  require 'glimmer/swt/swt_proxy'
23
23
  require 'glimmer/swt/widget_proxy'
24
24
  require 'glimmer/swt/display_proxy'
25
+ require 'glimmer/swt/proxy_properties'
25
26
 
26
27
  module Glimmer
27
28
  module SWT
28
- # Proxy for org.eclipse.swt.widgets.DirectoryDialog
29
+ # Proxy for org.eclipse.swt.widgets.Dialog superclass
30
+ # of dialogs like FileDialog, DirectoryDialog, ColorDialog, and FontDialog
31
+ #
32
+ # (if you're seeking the `dialog` keyword, that's just a `shell` variation
33
+ # under ShellProxy instead.
29
34
  #
30
35
  # Automatically uses the current shell if one is open.
31
36
  # Otherwise, it instantiates a new shell parent
@@ -33,14 +38,30 @@ module Glimmer
33
38
  # Optionally takes a shell as an argument
34
39
  #
35
40
  # Follows the Proxy Design Pattern
36
- class DirectoryDialogProxy < WidgetProxy
41
+ class DialogProxy
37
42
  # TODO write rspec tests
43
+ include ProxyProperties
44
+
38
45
  include_package 'org.eclipse.swt.widgets'
46
+ include_package 'org.eclipse.swt.printing'
47
+
48
+ class << self
49
+ include_package 'org.eclipse.swt.widgets'
50
+ include_package 'org.eclipse.swt.printing'
51
+
52
+ def dialog_class(keyword)
53
+ the_class = eval(keyword.camelcase(:upper))
54
+ the_class if the_class.ancestors.include?(org.eclipse.swt.widgets.Dialog)
55
+ end
56
+ end
39
57
 
40
- def initialize(*args, swt_widget: nil)
41
- auto_exec do
42
- if swt_widget
43
- @swt_widget = swt_widget
58
+ attr_reader :swt_dialog
59
+
60
+ def initialize(keyword, *args, swt_dialog: nil)
61
+ DisplayProxy.instance.auto_exec do
62
+ dialog_class = self.class.dialog_class(keyword)
63
+ if swt_dialog
64
+ @swt_dialog = swt_dialog
44
65
  else
45
66
  style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
46
67
  if style_args.any?
@@ -57,10 +78,14 @@ module Glimmer
57
78
  end
58
79
  parent = args[0]
59
80
  @parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
60
- @swt_widget = DirectoryDialog.new(*args)
81
+ @swt_dialog = dialog_class.new(*args)
61
82
  end
62
83
  end
63
84
  end
85
+
86
+ def proxy_source_object
87
+ @swt_dialog
88
+ end
64
89
 
65
90
  end
66
91
  end
@@ -54,13 +54,19 @@ module Glimmer
54
54
  # that is :normal, :bold, or :italic
55
55
  def initialize(widget_proxy = nil, font_properties)
56
56
  @widget_proxy = widget_proxy
57
- @font_properties = font_properties
58
- detect_invalid_font_property(font_properties)
59
- font_properties[:style] = SWTProxy[*font_properties[:style]]
60
- font_data_args = [:name, :height, :style].map do |font_property_name|
61
- font_properties[font_property_name] || send(font_property_name)
57
+ if font_properties.is_a?(FontData)
58
+ font_datum = font_properties
59
+ @font_properties = {name: font_properties.name, height: font_properties.height, style: font_properties.style}
60
+ elsif font_properties.is_a?(Hash)
61
+ @font_properties = font_properties
62
+ detect_invalid_font_property(font_properties)
63
+ font_properties[:style] = SWTProxy[*font_properties[:style]]
64
+ # TODO consider supporting other properties like locale in the future
65
+ font_data_args = [:name, :height, :style].map do |font_property_name|
66
+ font_properties[font_property_name] || send(font_property_name)
67
+ end
68
+ font_datum = FontData.new(*font_data_args)
62
69
  end
63
- font_datum = FontData.new(*font_data_args)
64
70
  @swt_font = Font.new(DisplayProxy.instance.swt_display, font_datum)
65
71
  end
66
72
 
@@ -35,6 +35,7 @@ module Glimmer
35
35
  attr_reader :swt_widget
36
36
 
37
37
  def initialize(parent, style)
38
+ # TODO consider consolidating with DialogProxy if it makes sense
38
39
  if parent.nil?
39
40
  @temporary_parent = parent = Glimmer::SWT::ShellProxy.new.swt_widget
40
41
  end
@@ -69,6 +69,9 @@ module Glimmer
69
69
  Glimmer::SWT::Properties.normalized_attribute(attribute_name)
70
70
  end
71
71
  alias ruby_attribute_getter normalized_attribute
72
+
72
73
  end
74
+
73
75
  end
76
+
74
77
  end
@@ -0,0 +1,145 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ # Provides a default implementation for proxy properties, that is
27
+ # properties that come from a proxy object source such as swt_widget
28
+ # having Java camelcase format
29
+ module ProxyProperties
30
+ include Properties
31
+
32
+ # Subclasses must override to privde a proxy source if they want to take advantage of
33
+ # default implementation of attribute setters/getters
34
+ # It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
35
+ def proxy_source_object
36
+ if respond_to?(:swt_widget)
37
+ swt_widget
38
+ elsif respond_to?(:swt_display)
39
+ swt_display
40
+ elsif respond_to?(:swt_image)
41
+ swt_image
42
+ elsif respond_to?(:swt_dialog)
43
+ swt_dialog
44
+ elsif respond_to?(:swt_transform)
45
+ swt_transform
46
+ end
47
+ end
48
+
49
+ def has_attribute_getter?(attribute_getter_name, *args)
50
+ attribute_getter_name = attribute_getter_name.to_s.underscore
51
+ return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
52
+ args.empty? && proxy_source_object&.respond_to?(attribute_getter_name)
53
+ end
54
+
55
+ def has_attribute_setter?(attribute_setter_name, *args)
56
+ attribute_setter_name = attribute_setter_name.to_s
57
+ underscored_attribute_setter_name = attribute_setter_name.underscore
58
+ return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
59
+ attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
60
+ has_attribute?(attribute_name, *args)
61
+ end
62
+
63
+ def has_attribute?(attribute_name, *args)
64
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
65
+ proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) ||
66
+ respond_to?(ruby_attribute_setter(attribute_name), args)
67
+ end
68
+ end
69
+
70
+ def set_attribute(attribute_name, *args)
71
+ swt_widget_operation = false
72
+ result = nil
73
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
74
+ result = if proxy_source_object&.respond_to?(attribute_setter(attribute_name))
75
+ swt_widget_operation = true
76
+ proxy_source_object&.send(attribute_setter(attribute_name), *args) unless proxy_source_object&.send(attribute_getter(attribute_name)) == args.first
77
+ elsif proxy_source_object&.respond_to?(ruby_attribute_setter(attribute_name))
78
+ swt_widget_operation = true
79
+ proxy_source_object&.send(ruby_attribute_setter(attribute_name), args)
80
+ end
81
+ end
82
+ unless swt_widget_operation
83
+ result = send(ruby_attribute_setter(attribute_name), args)
84
+ end
85
+ result
86
+ end
87
+
88
+ def get_attribute(attribute_name)
89
+ swt_widget_operation = false
90
+ result = nil
91
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
92
+ result = if proxy_source_object&.respond_to?(attribute_getter(attribute_name))
93
+ swt_widget_operation = true
94
+ proxy_source_object&.send(attribute_getter(attribute_name))
95
+ elsif proxy_source_object&.respond_to?(ruby_attribute_getter(attribute_name))
96
+ swt_widget_operation = true
97
+ proxy_source_object&.send(ruby_attribute_getter(attribute_name))
98
+ elsif proxy_source_object&.respond_to?(attribute_name)
99
+ swt_widget_operation = true
100
+ proxy_source_object&.send(attribute_name)
101
+ end
102
+ end
103
+ unless swt_widget_operation
104
+ result = if respond_to?(ruby_attribute_getter(attribute_name))
105
+ send(ruby_attribute_getter(attribute_name))
106
+ else
107
+ send(attribute_name)
108
+ end
109
+ end
110
+ result
111
+ end
112
+
113
+ def method_missing(method, *args, &block)
114
+ if has_attribute_setter?(method, *args)
115
+ set_attribute(method, *args)
116
+ elsif has_attribute_getter?(method, *args)
117
+ get_attribute(method, *args)
118
+ else
119
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
120
+ proxy_source_object&.send(method, *args, &block)
121
+ end
122
+ end
123
+ rescue => e
124
+ begin
125
+ super
126
+ rescue Exception => inner_error
127
+ Glimmer::Config.logger.error { "Neither self.class.name nor #{proxy_source_object&.class.name} can handle the method ##{method}" }
128
+ Glimmer::Config.logger.error { e.full_message }
129
+ raise inner_error
130
+ end
131
+ end
132
+
133
+ def respond_to?(method, *args, &block)
134
+ result = super
135
+ return true if result
136
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
137
+ proxy_source_object&.respond_to?(method, *args, &block)
138
+ end
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end
@@ -37,32 +37,36 @@ module Glimmer
37
37
  attr_reader :swt_transform, :parent
38
38
 
39
39
  def initialize(parent, *args, swt_transform: nil, multiply: false)
40
- @parent = parent
41
- @multiply = multiply
42
- if swt_transform.nil?
43
- if !args.first.is_a?(Display) && !args.first.is_a?(DisplayProxy)
44
- args.prepend DisplayProxy.instance.swt_display
45
- end
46
- if args.first.is_a?(DisplayProxy)
47
- args[0] = args[0].swt_display
48
- end
49
- if args.last.is_a?(TransformProxy)
50
- args[-1] = args[-1].swt_transform
51
- end
52
- if args.last.nil? || args.last.is_a?(Transform)
53
- @swt_transform = args.last
54
- @parent&.set_attribute('transform', self)
40
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
41
+ @parent = parent
42
+ @multiply = multiply
43
+ if swt_transform.nil?
44
+ if !args.first.is_a?(Display) && !args.first.is_a?(DisplayProxy)
45
+ args.prepend DisplayProxy.instance.swt_display
46
+ end
47
+ if args.first.is_a?(DisplayProxy)
48
+ args[0] = args[0].swt_display
49
+ end
50
+ if args.last.is_a?(TransformProxy)
51
+ args[-1] = args[-1].swt_transform
52
+ end
53
+ if args.last.nil? || args.last.is_a?(Transform)
54
+ @swt_transform = args.last
55
+ @parent&.set_attribute('transform', self)
56
+ else
57
+ @swt_transform = Transform.new(*args)
58
+ end
55
59
  else
56
- @swt_transform = Transform.new(*args)
60
+ @swt_transform = swt_transform
57
61
  end
58
- else
59
- @swt_transform = swt_transform
60
62
  end
61
63
  end
62
64
 
63
65
  def post_add_content
64
66
  if @multiply
65
- @parent.multiply(@swt_transform)
67
+ Glimmer::SWT::DisplayProxy.instance.auto_exec {
68
+ @parent.multiply(@swt_transform)
69
+ }
66
70
  else
67
71
  @parent&.set_attribute('transform', self)
68
72
  end
@@ -72,28 +76,12 @@ module Glimmer
72
76
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::TransformExpression.new, &block)
73
77
  end
74
78
 
75
- def has_attribute?(attribute_name, *args)
76
- @swt_transform.respond_to?(attribute_name) || @swt_transform.respond_to?(attribute_setter(attribute_name))
77
- end
78
-
79
- def set_attribute(attribute_name, *args)
80
- if @swt_transform.respond_to?(attribute_name)
81
- @swt_transform.send(attribute_name, *args)
82
- elsif @swt_transform.respond_to?(attribute_setter(attribute_name))
83
- @swt_transform.send(attribute_setter(attribute_name), *args)
84
- end
85
- end
86
-
87
- def get_attribute(attribute_name)
88
- if @swt_transform.respond_to?(attribute_getter(attribute_name))
89
- @swt_transform.send(attribute_getter(attribute_name))
90
- else
91
- @swt_transform.send(attribute_name)
92
- end
79
+ def proxy_source_object
80
+ @swt_transform
93
81
  end
94
82
 
95
83
  def method_missing(method_name, *args, &block)
96
- result = @swt_transform.send(method_name, *args, &block)
84
+ result = Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.send(method_name, *args, &block) }
97
85
  result.nil? ? self : result
98
86
  rescue => e
99
87
  Glimmer::Config.logger.debug {"Neither MessageBoxProxy nor #{@swt_transform.class.name} can handle the method ##{method}"}
@@ -26,7 +26,7 @@ require 'glimmer/swt/swt_proxy'
26
26
  require 'glimmer/swt/display_proxy'
27
27
  require 'glimmer/swt/dnd_proxy'
28
28
  require 'glimmer/swt/image_proxy'
29
- require 'glimmer/swt/properties'
29
+ require 'glimmer/swt/proxy_properties'
30
30
  require 'glimmer/swt/custom/drawable'
31
31
 
32
32
  # TODO refactor to make file smaller and extract sub-widget-proxies out of this
@@ -44,7 +44,7 @@ module Glimmer
44
44
  # Follows the Proxy Design Pattern
45
45
  class WidgetProxy
46
46
  include Packages
47
- include Properties
47
+ include ProxyProperties
48
48
  include Custom::Drawable
49
49
 
50
50
  DEFAULT_STYLES = {
@@ -223,23 +223,11 @@ module Glimmer
223
223
  [args, extra_options]
224
224
  end
225
225
  end
226
-
227
- def has_attribute_getter?(attribute_getter_name, *args)
228
- attribute_getter_name = attribute_getter_name.to_s.underscore
229
- return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
230
- auto_exec do
231
- args.empty? && swt_widget.respond_to?(attribute_getter_name)
232
- end
233
- end
234
226
 
235
- def has_attribute_setter?(attribute_setter_name, *args)
236
- attribute_setter_name = attribute_setter_name.to_s
237
- underscored_attribute_setter_name = attribute_setter_name.underscore
238
- return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
239
- attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
240
- has_attribute?(attribute_name, *args)
227
+ def proxy_source_object
228
+ @swt_widget
241
229
  end
242
-
230
+
243
231
  def has_attribute?(attribute_name, *args)
244
232
  # TODO test that attribute getter responds too
245
233
  widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
@@ -247,7 +235,7 @@ module Glimmer
247
235
  if widget_custom_attribute
248
236
  @swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
249
237
  else
250
- @swt_widget.respond_to?(attribute_setter(attribute_name), args) || respond_to?(ruby_attribute_setter(attribute_name), args)
238
+ super
251
239
  end
252
240
  end
253
241
  end
@@ -264,17 +252,9 @@ module Glimmer
264
252
  result = if widget_custom_attribute
265
253
  swt_widget_operation = true
266
254
  widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
267
- elsif @swt_widget.respond_to?(attribute_setter(attribute_name))
268
- swt_widget_operation = true
269
- @swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
270
- elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name))
271
- swt_widget_operation = true
272
- @swt_widget.send(ruby_attribute_setter(attribute_name), args)
273
255
  end
274
256
  end
275
- unless swt_widget_operation
276
- result = send(ruby_attribute_setter(attribute_name), args)
277
- end
257
+ result = super unless swt_widget_operation
278
258
  result
279
259
  end
280
260
 
@@ -290,24 +270,9 @@ module Glimmer
290
270
  else
291
271
  @swt_widget.send(widget_custom_attribute[:getter][:name])
292
272
  end
293
- elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
294
- swt_widget_operation = true
295
- @swt_widget.send(attribute_getter(attribute_name))
296
- elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name))
297
- swt_widget_operation = true
298
- @swt_widget.send(ruby_attribute_getter(attribute_name))
299
- elsif @swt_widget.respond_to?(attribute_name)
300
- swt_widget_operation = true
301
- @swt_widget.send(attribute_name)
302
- end
303
- end
304
- unless swt_widget_operation
305
- result = if respond_to?(ruby_attribute_getter(attribute_name))
306
- send(ruby_attribute_getter(attribute_name))
307
- else
308
- send(attribute_name)
309
273
  end
310
274
  end
275
+ result = super unless swt_widget_operation
311
276
  result
312
277
  end
313
278
 
@@ -327,6 +292,8 @@ module Glimmer
327
292
  end
328
293
  end
329
294
 
295
+ # these work in tandem with the property_type_converters
296
+ # sometimes, they are specified in subclasses instead
330
297
  def widget_property_listener_installers
331
298
  @swt_widget_property_listener_installers ||= {
332
299
  Java::OrgEclipseSwtWidgets::Control => {
@@ -734,24 +701,11 @@ module Glimmer
734
701
  end
735
702
 
736
703
  def method_missing(method, *args, &block)
704
+ # TODO push most of this logic down to Properties (and perhaps create Listeners module as well)
737
705
  if can_handle_observation_request?(method)
738
706
  handle_observation_request(method, &block)
739
- elsif has_attribute_setter?(method, *args)
740
- set_attribute(method, *args)
741
- elsif has_attribute_getter?(method, *args)
742
- get_attribute(method, *args)
743
707
  else
744
- auto_exec do
745
- swt_widget.send(method, *args, &block)
746
- end
747
- end
748
- rescue => e
749
- begin
750
708
  super
751
- rescue Exception => inner_error
752
- Glimmer::Config.logger.error { "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}" }
753
- Glimmer::Config.logger.error { e.full_message }
754
- raise inner_error
755
709
  end
756
710
  end
757
711
 
@@ -759,7 +713,7 @@ module Glimmer
759
713
  result = super
760
714
  return true if result
761
715
  auto_exec do
762
- can_handle_observation_request?(method) || swt_widget.respond_to?(method, *args, &block)
716
+ can_handle_observation_request?(method)
763
717
  end
764
718
  end
765
719
 
@@ -946,6 +900,8 @@ module Glimmer
946
900
  color_converter = lambda do |value|
947
901
  if value.is_a?(Symbol) || value.is_a?(String)
948
902
  ColorProxy.new(value).swt_color
903
+ elsif value.is_a?(RGB)
904
+ ColorProxy.new(value.red, value.green, value.blue).swt_color
949
905
  else
950
906
  value
951
907
  end
@@ -1015,7 +971,7 @@ module Glimmer
1015
971
  foreground: color_converter,
1016
972
  link_foreground: color_converter,
1017
973
  font: lambda do |value|
1018
- if value.is_a?(Hash)
974
+ if value.is_a?(Hash) || value.is_a?(FontData)
1019
975
  font_properties = value
1020
976
  FontProxy.new(self, font_properties).swt_font
1021
977
  else