glimmer-dsl-swt 4.18.4.10 → 4.18.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -0
- data/README.md +14 -5
- data/VERSION +1 -1
- data/bin/glimmer +3 -3
- data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +451 -112
- data/docs/reference/GLIMMER_SAMPLES.md +76 -3
- data/glimmer-dsl-swt.gemspec +23 -13
- data/lib/ext/glimmer/config.rb +3 -7
- data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
- data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
- data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
- data/lib/glimmer/data_binding/widget_binding.rb +12 -27
- data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
- data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +1 -2
- data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
- data/lib/glimmer/dsl/swt/dsl.rb +1 -0
- data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
- data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
- data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
- data/lib/glimmer/launcher.rb +3 -0
- data/lib/glimmer/rake_task/scaffold.rb +3 -0
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/code_text.rb +33 -11
- data/lib/glimmer/swt/custom/drawable.rb +57 -1
- data/lib/glimmer/swt/custom/shape.rb +332 -48
- data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
- data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
- data/lib/glimmer/swt/custom/shape/image.rb +112 -0
- data/lib/glimmer/swt/custom/shape/line.rb +111 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
- data/lib/glimmer/swt/custom/shape/point.rb +49 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +114 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +115 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +105 -0
- data/lib/glimmer/swt/custom/shape/text.rb +85 -0
- data/lib/glimmer/swt/date_time_proxy.rb +9 -3
- data/lib/glimmer/swt/dialog_proxy.rb +92 -0
- data/lib/glimmer/swt/display_proxy.rb +62 -2
- data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
- data/lib/glimmer/swt/font_proxy.rb +13 -7
- data/lib/glimmer/swt/image_proxy.rb +15 -4
- data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
- data/lib/glimmer/swt/layout_proxy.rb +19 -15
- data/lib/glimmer/swt/menu_proxy.rb +2 -2
- data/lib/glimmer/swt/message_box_proxy.rb +21 -7
- data/lib/glimmer/swt/properties.rb +3 -0
- data/lib/glimmer/swt/proxy_properties.rb +145 -0
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
- data/lib/glimmer/swt/shell_proxy.rb +94 -80
- data/lib/glimmer/swt/swt_proxy.rb +16 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
- data/lib/glimmer/swt/table_proxy.rb +32 -11
- data/lib/glimmer/swt/transform_proxy.rb +39 -35
- data/lib/glimmer/swt/tree_proxy.rb +11 -16
- data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
- data/lib/glimmer/swt/widget_proxy.rb +193 -138
- data/lib/glimmer/ui.rb +5 -0
- data/lib/glimmer/ui/custom_shell.rb +11 -5
- data/lib/glimmer/ui/custom_widget.rb +4 -5
- data/samples/elaborate/contact_manager.rb +9 -7
- data/samples/elaborate/login.rb +27 -21
- data/samples/elaborate/mandelbrot_fractal.rb +20 -25
- data/samples/elaborate/meta_sample.rb +2 -1
- data/samples/elaborate/tetris.rb +3 -1
- data/samples/elaborate/tic_tac_toe.rb +18 -14
- data/samples/elaborate/tic_tac_toe/board.rb +5 -5
- data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
- data/samples/elaborate/user_profile.rb +10 -8
- data/samples/hello/hello_browser.rb +2 -0
- data/samples/hello/hello_button.rb +9 -7
- data/samples/hello/hello_canvas.rb +144 -40
- data/samples/hello/hello_canvas_animation.rb +2 -0
- data/samples/hello/hello_canvas_transform.rb +2 -0
- data/samples/hello/hello_checkbox.rb +18 -14
- data/samples/hello/hello_checkbox_group.rb +13 -9
- data/samples/hello/hello_code_text.rb +2 -0
- data/samples/hello/hello_color_dialog.rb +68 -0
- data/samples/hello/hello_combo.rb +16 -12
- data/samples/hello/hello_computed.rb +9 -7
- data/samples/hello/hello_cursor.rb +4 -1
- data/samples/hello/hello_custom_shell.rb +18 -21
- data/samples/hello/hello_custom_widget.rb +6 -6
- data/samples/hello/hello_date_time.rb +16 -12
- data/samples/hello/hello_dialog.rb +2 -0
- data/samples/hello/hello_directory_dialog.rb +9 -7
- data/samples/hello/hello_drag_and_drop.rb +5 -3
- data/samples/hello/hello_expand_bar.rb +10 -8
- data/samples/hello/hello_file_dialog.rb +9 -7
- data/samples/hello/hello_font_dialog.rb +84 -0
- data/samples/hello/hello_group.rb +20 -16
- data/samples/hello/hello_link.rb +2 -0
- data/samples/hello/hello_list_multi_selection.rb +15 -11
- data/samples/hello/hello_list_single_selection.rb +15 -11
- data/samples/hello/hello_menu_bar.rb +2 -0
- data/samples/hello/hello_message_box.rb +2 -0
- data/samples/hello/hello_pop_up_context_menu.rb +2 -0
- data/samples/hello/hello_progress_bar.rb +5 -5
- data/samples/hello/hello_radio.rb +20 -16
- data/samples/hello/hello_radio_group.rb +16 -12
- data/samples/hello/hello_sash_form.rb +2 -0
- data/samples/hello/hello_spinner.rb +9 -7
- data/samples/hello/hello_styled_text.rb +19 -17
- data/samples/hello/hello_tab.rb +7 -5
- data/samples/hello/hello_table.rb +12 -5
- data/samples/hello/hello_tree.rb +485 -0
- data/samples/hello/hello_world.rb +2 -0
- metadata +21 -22
- data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
- data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -42,7 +42,8 @@ module Glimmer
|
|
42
42
|
# Returns a Java TreeItem array to easily set as selection on org.eclipse.swt.Tree if needed
|
43
43
|
def depth_first_search(&condition)
|
44
44
|
found = []
|
45
|
-
|
45
|
+
first_item = DisplayProxy.instance.auto_exec { swt_widget.getItems.first }
|
46
|
+
recursive_depth_first_search(first_item, found, &condition)
|
46
47
|
found.to_java(TreeItem)
|
47
48
|
end
|
48
49
|
|
@@ -51,18 +52,6 @@ module Glimmer
|
|
51
52
|
depth_first_search
|
52
53
|
end
|
53
54
|
|
54
|
-
def widget_property_listener_installers
|
55
|
-
super.merge({
|
56
|
-
Java::OrgEclipseSwtWidgets::Tree => {
|
57
|
-
selection: lambda do |observer|
|
58
|
-
on_widget_selected { |selection_event|
|
59
|
-
observer.call(@swt_widget.getSelection)
|
60
|
-
}
|
61
|
-
end
|
62
|
-
},
|
63
|
-
})
|
64
|
-
end
|
65
|
-
|
66
55
|
def edit_in_progress?
|
67
56
|
!!@edit_in_progress
|
68
57
|
end
|
@@ -127,8 +116,10 @@ module Glimmer
|
|
127
116
|
|
128
117
|
def recursive_depth_first_search(tree_item, found, &condition)
|
129
118
|
return if tree_item.nil?
|
130
|
-
found << tree_item if condition.nil? || condition.call(tree_item)
|
131
|
-
|
119
|
+
found << tree_item if condition.nil? || DisplayProxy.instance.auto_exec {condition.call(tree_item)}
|
120
|
+
# return if found.any? && !has_style?(:multi) # TODO inspect if this is a good optimization when needed
|
121
|
+
tree_items = DisplayProxy.instance.auto_exec {tree_item.getItems}
|
122
|
+
tree_items.each do |child_tree_item|
|
132
123
|
recursive_depth_first_search(child_tree_item, found, &condition)
|
133
124
|
end
|
134
125
|
end
|
@@ -136,7 +127,11 @@ module Glimmer
|
|
136
127
|
def property_type_converters
|
137
128
|
super.merge({
|
138
129
|
selection: lambda do |value|
|
139
|
-
|
130
|
+
if value.is_a?(Array)
|
131
|
+
depth_first_search {|ti| value.include?(ti.getData) }
|
132
|
+
else
|
133
|
+
depth_first_search {|ti| ti.getData == value}
|
134
|
+
end
|
140
135
|
end,
|
141
136
|
})
|
142
137
|
end
|
@@ -53,9 +53,13 @@ module Glimmer
|
|
53
53
|
@swt_display.removeListener(@event_type, @swt_listener)
|
54
54
|
end
|
55
55
|
elsif @event_type
|
56
|
-
|
56
|
+
DisplayProxy.instance.auto_exec do
|
57
|
+
@swt_widget.removeListener(@event_type, @swt_listener)
|
58
|
+
end
|
57
59
|
else
|
58
|
-
|
60
|
+
DisplayProxy.instance.auto_exec do
|
61
|
+
@swt_widget.send(widget_remove_listener_method, @swt_listener)
|
62
|
+
end
|
59
63
|
end
|
60
64
|
end
|
61
65
|
alias unregister deregister # TODO consider dropping unregister (and in Observer too)
|
@@ -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/
|
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,13 +44,13 @@ module Glimmer
|
|
44
44
|
# Follows the Proxy Design Pattern
|
45
45
|
class WidgetProxy
|
46
46
|
include Packages
|
47
|
-
include
|
47
|
+
include ProxyProperties
|
48
48
|
include Custom::Drawable
|
49
49
|
|
50
50
|
DEFAULT_STYLES = {
|
51
51
|
'arrow' => [:arrow],
|
52
52
|
'button' => [:push],
|
53
|
-
'canvas' => [:double_buffered],
|
53
|
+
'canvas' => ([:double_buffered] unless OS.mac?),
|
54
54
|
'checkbox' => [:check],
|
55
55
|
'check' => [:check],
|
56
56
|
'drag_source' => [:drop_copy],
|
@@ -112,13 +112,15 @@ module Glimmer
|
|
112
112
|
# Instantiates the right WidgetProxy subclass for passed in keyword
|
113
113
|
# Args are: keyword, parent, swt_widget_args (including styles)
|
114
114
|
def create(*init_args, swt_widget: nil)
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
DisplayProxy.instance.auto_exec do
|
116
|
+
return swt_widget.get_data('proxy') if swt_widget&.get_data('proxy')
|
117
|
+
keyword, parent, args = init_args
|
118
|
+
selected_widget_proxy_class = widget_proxy_class(keyword || underscored_widget_name(swt_widget))
|
119
|
+
if init_args.empty?
|
120
|
+
selected_widget_proxy_class.new(swt_widget: swt_widget)
|
121
|
+
else
|
122
|
+
selected_widget_proxy_class.new(*init_args)
|
123
|
+
end
|
122
124
|
end
|
123
125
|
end
|
124
126
|
|
@@ -149,31 +151,33 @@ module Glimmer
|
|
149
151
|
#
|
150
152
|
# Styles is a comma separate list of symbols representing SWT styles in lower case
|
151
153
|
def initialize(*init_args, swt_widget: nil)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
@swt_widget
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
on_widget_disposed
|
174
|
-
|
175
|
-
|
176
|
-
|
154
|
+
auto_exec do
|
155
|
+
@image_double_buffered = !!(init_args&.last&.include?(:image_double_buffered) && init_args&.last&.delete(:image_double_buffered))
|
156
|
+
if swt_widget.nil?
|
157
|
+
underscored_widget_name, parent, args = init_args
|
158
|
+
@parent_proxy = parent
|
159
|
+
styles, extra_options = extract_args(underscored_widget_name, args)
|
160
|
+
swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
|
161
|
+
@swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
|
162
|
+
else
|
163
|
+
@swt_widget = swt_widget
|
164
|
+
underscored_widget_name = self.class.underscored_widget_name(@swt_widget)
|
165
|
+
parent_proxy_class = self.class.widget_proxy_class(self.class.underscored_widget_name(@swt_widget.parent))
|
166
|
+
parent = swt_widget.parent
|
167
|
+
@parent_proxy = parent&.get_data('proxy') || parent_proxy_class.new(swt_widget: parent)
|
168
|
+
end
|
169
|
+
if @swt_widget&.get_data('proxy').nil?
|
170
|
+
@swt_widget.set_data('proxy', self)
|
171
|
+
DEFAULT_INITIALIZERS[underscored_widget_name.to_s.to_sym]&.call(@swt_widget)
|
172
|
+
@parent_proxy.post_initialize_child(self)
|
173
|
+
end
|
174
|
+
@keyword = underscored_widget_name.to_s
|
175
|
+
if respond_to?(:on_widget_disposed)
|
176
|
+
on_widget_disposed {
|
177
|
+
clear_shapes
|
178
|
+
deregister_shape_painting
|
179
|
+
}
|
180
|
+
end
|
177
181
|
end
|
178
182
|
end
|
179
183
|
|
@@ -219,81 +223,93 @@ module Glimmer
|
|
219
223
|
[args, extra_options]
|
220
224
|
end
|
221
225
|
end
|
222
|
-
|
223
|
-
def has_attribute_getter?(attribute_getter_name, *args)
|
224
|
-
attribute_getter_name = attribute_getter_name.to_s.underscore
|
225
|
-
return false unless !attribute_getter_name.end_with?('=') && !attribute_getter_name.start_with?('set_')
|
226
|
-
args.empty? && swt_widget.respond_to?(attribute_getter_name)
|
227
|
-
end
|
228
226
|
|
229
|
-
def
|
230
|
-
|
231
|
-
underscored_attribute_setter_name = attribute_setter_name.underscore
|
232
|
-
return false unless attribute_setter_name.end_with?('=') || (attribute_setter_name.start_with?('set_') && !args.empty?)
|
233
|
-
attribute_name = underscored_attribute_setter_name.sub(/^set_/, '').sub(/=$/, '')
|
234
|
-
has_attribute?(attribute_name, *args)
|
227
|
+
def proxy_source_object
|
228
|
+
@swt_widget
|
235
229
|
end
|
236
|
-
|
230
|
+
|
237
231
|
def has_attribute?(attribute_name, *args)
|
238
232
|
# TODO test that attribute getter responds too
|
239
233
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
234
|
+
auto_exec do
|
235
|
+
if widget_custom_attribute
|
236
|
+
@swt_widget.respond_to?(widget_custom_attribute[:setter][:name])
|
237
|
+
else
|
238
|
+
super
|
239
|
+
end
|
244
240
|
end
|
245
241
|
end
|
246
242
|
|
247
243
|
def set_attribute(attribute_name, *args)
|
248
244
|
# TODO Think about widget subclasses overriding set_attribute to add more attributes vs adding as Ruby attributes directly
|
249
245
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
250
|
-
|
251
|
-
|
252
|
-
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
253
|
-
elsif @swt_widget.respond_to?(attribute_setter(attribute_name))
|
254
|
-
@swt_widget.send(attribute_setter(attribute_name), *args) unless @swt_widget.send(attribute_getter(attribute_name)) == args.first
|
255
|
-
elsif @swt_widget.respond_to?(ruby_attribute_setter(attribute_name))
|
256
|
-
@swt_widget.send(ruby_attribute_setter(attribute_name), args)
|
257
|
-
else
|
258
|
-
send(ruby_attribute_setter(attribute_name), args)
|
246
|
+
auto_exec do
|
247
|
+
apply_property_type_converters(normalized_attribute(attribute_name), args)
|
259
248
|
end
|
249
|
+
swt_widget_operation = false
|
250
|
+
result = nil
|
251
|
+
auto_exec do
|
252
|
+
result = if widget_custom_attribute
|
253
|
+
swt_widget_operation = true
|
254
|
+
widget_custom_attribute[:setter][:invoker].call(@swt_widget, args)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
result = super unless swt_widget_operation
|
258
|
+
result
|
260
259
|
end
|
261
260
|
|
262
261
|
def get_attribute(attribute_name)
|
263
262
|
widget_custom_attribute = widget_custom_attribute_mapping[attribute_name.to_s]
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
263
|
+
swt_widget_operation = false
|
264
|
+
result = nil
|
265
|
+
auto_exec do
|
266
|
+
result = if widget_custom_attribute
|
267
|
+
swt_widget_operation = true
|
268
|
+
if widget_custom_attribute[:getter][:invoker]
|
269
|
+
widget_custom_attribute[:getter][:invoker].call(@swt_widget, [])
|
270
|
+
else
|
271
|
+
@swt_widget.send(widget_custom_attribute[:getter][:name])
|
272
|
+
end
|
269
273
|
end
|
270
|
-
elsif @swt_widget.respond_to?(attribute_getter(attribute_name))
|
271
|
-
@swt_widget.send(attribute_getter(attribute_name))
|
272
|
-
elsif @swt_widget.respond_to?(ruby_attribute_getter(attribute_name))
|
273
|
-
@swt_widget.send(ruby_attribute_getter(attribute_name))
|
274
|
-
elsif @swt_widget.respond_to?(attribute_name)
|
275
|
-
@swt_widget.send(attribute_name)
|
276
|
-
elsif respond_to?(ruby_attribute_getter(attribute_name))
|
277
|
-
send(ruby_attribute_getter(attribute_name))
|
278
|
-
else
|
279
|
-
send(attribute_name)
|
280
274
|
end
|
275
|
+
result = super unless swt_widget_operation
|
276
|
+
result
|
281
277
|
end
|
282
278
|
|
283
279
|
def pack_same_size
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
@swt_widget.
|
291
|
-
|
292
|
-
|
280
|
+
auto_exec do
|
281
|
+
bounds = @swt_widget.getBounds
|
282
|
+
listener = on_control_resized {
|
283
|
+
@swt_widget.setSize(bounds.width, bounds.height)
|
284
|
+
@swt_widget.setLocation(bounds.x, bounds.y)
|
285
|
+
}
|
286
|
+
if @swt_widget.is_a?(Composite)
|
287
|
+
@swt_widget.layout(true, true)
|
288
|
+
else
|
289
|
+
@swt_widget.pack(true)
|
290
|
+
end
|
291
|
+
@swt_widget.removeControlListener(listener.swt_listener)
|
293
292
|
end
|
294
|
-
|
293
|
+
end
|
294
|
+
|
295
|
+
def x
|
296
|
+
bounds.x
|
297
|
+
end
|
298
|
+
|
299
|
+
def y
|
300
|
+
bounds.y
|
301
|
+
end
|
302
|
+
|
303
|
+
def width
|
304
|
+
bounds.width
|
305
|
+
end
|
306
|
+
|
307
|
+
def height
|
308
|
+
bounds.height
|
295
309
|
end
|
296
310
|
|
311
|
+
# these work in tandem with the property_type_converters
|
312
|
+
# sometimes, they are specified in subclasses instead
|
297
313
|
def widget_property_listener_installers
|
298
314
|
@swt_widget_property_listener_installers ||= {
|
299
315
|
Java::OrgEclipseSwtWidgets::Control => {
|
@@ -334,6 +350,17 @@ module Glimmer
|
|
334
350
|
}
|
335
351
|
end,
|
336
352
|
},
|
353
|
+
Java::OrgEclipseSwtWidgets::Tree => {
|
354
|
+
:selection => lambda do |observer|
|
355
|
+
on_widget_selected { |selection_event|
|
356
|
+
if has_style?(:multi)
|
357
|
+
observer.call(@swt_widget.getSelection.map(&:get_data))
|
358
|
+
else
|
359
|
+
observer.call(@swt_widget.getSelection.first&.get_data)
|
360
|
+
end
|
361
|
+
}
|
362
|
+
end,
|
363
|
+
},
|
337
364
|
Java::OrgEclipseSwtWidgets::Text => {
|
338
365
|
:text => lambda do |observer|
|
339
366
|
on_modify_text { |modify_event|
|
@@ -546,25 +573,37 @@ module Glimmer
|
|
546
573
|
@flyweight_swt_widget_classes ||= {}
|
547
574
|
end
|
548
575
|
|
576
|
+
# delegates to DisplayProxy
|
549
577
|
def async_exec(&block)
|
550
578
|
DisplayProxy.instance.async_exec(&block)
|
551
579
|
end
|
552
580
|
|
581
|
+
# delegates to DisplayProxy
|
553
582
|
def sync_exec(&block)
|
554
583
|
DisplayProxy.instance.sync_exec(&block)
|
555
584
|
end
|
556
585
|
|
586
|
+
# delegates to DisplayProxy
|
557
587
|
def timer_exec(delay_in_millis, &block)
|
558
588
|
DisplayProxy.instance.timer_exec(delay_in_millis, &block)
|
559
589
|
end
|
560
590
|
|
591
|
+
# delegates to DisplayProxy
|
592
|
+
def auto_exec(override_sync_exec: nil, override_async_exec: nil, &block)
|
593
|
+
DisplayProxy.instance.auto_exec(override_sync_exec: override_sync_exec, override_async_exec: override_async_exec, &block)
|
594
|
+
end
|
595
|
+
|
561
596
|
def has_style?(style)
|
562
597
|
comparison = interpret_style(style)
|
563
|
-
|
598
|
+
auto_exec do
|
599
|
+
(@swt_widget.style & comparison) == comparison
|
600
|
+
end
|
564
601
|
end
|
565
602
|
|
566
603
|
def dispose
|
567
|
-
|
604
|
+
auto_exec do
|
605
|
+
@swt_widget.dispose
|
606
|
+
end
|
568
607
|
end
|
569
608
|
|
570
609
|
def disposed?
|
@@ -574,15 +613,19 @@ module Glimmer
|
|
574
613
|
# TODO Consider renaming these methods as they are mainly used for data-binding
|
575
614
|
|
576
615
|
def can_add_observer?(property_name)
|
577
|
-
|
616
|
+
auto_exec do
|
617
|
+
@swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact.map(&:keys).flatten.map(&:to_s).include?(property_name.to_s)
|
618
|
+
end
|
578
619
|
end
|
579
620
|
|
580
621
|
# Used for data-binding only. Consider renaming or improving to avoid the confusion it causes
|
581
622
|
def add_observer(observer, property_name)
|
582
623
|
if !observer.respond_to?(:binding_options) || !observer.binding_options[:read_only]
|
583
|
-
|
584
|
-
|
585
|
-
|
624
|
+
auto_exec do
|
625
|
+
property_listener_installers = @swt_widget.class.ancestors.map {|ancestor| widget_property_listener_installers[ancestor]}.compact
|
626
|
+
widget_listener_installers = property_listener_installers.map{|installer| installer[property_name.to_s.to_sym]}.compact if !property_listener_installers.empty?
|
627
|
+
widget_listener_installers.to_a.first&.call(observer)
|
628
|
+
end
|
586
629
|
end
|
587
630
|
end
|
588
631
|
|
@@ -619,13 +662,15 @@ module Glimmer
|
|
619
662
|
end
|
620
663
|
|
621
664
|
def can_handle_drag_observation_request?(observation_request)
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
665
|
+
auto_exec do
|
666
|
+
return false unless swt_widget.is_a?(Control)
|
667
|
+
potential_drag_source = @drag_source_proxy.nil?
|
668
|
+
ensure_drag_source_proxy
|
669
|
+
@drag_source_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
670
|
+
if potential_drag_source && !result
|
671
|
+
@drag_source_proxy.swt_widget.dispose
|
672
|
+
@drag_source_proxy = nil
|
673
|
+
end
|
629
674
|
end
|
630
675
|
end
|
631
676
|
rescue => e
|
@@ -634,13 +679,15 @@ module Glimmer
|
|
634
679
|
end
|
635
680
|
|
636
681
|
def can_handle_drop_observation_request?(observation_request)
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
682
|
+
auto_exec do
|
683
|
+
return false unless swt_widget.is_a?(Control)
|
684
|
+
potential_drop_target = @drop_target_proxy.nil?
|
685
|
+
ensure_drop_target_proxy
|
686
|
+
@drop_target_proxy.can_handle_observation_request?(observation_request).tap do |result|
|
687
|
+
if potential_drop_target && !result
|
688
|
+
@drop_target_proxy.swt_widget.dispose
|
689
|
+
@drop_target_proxy = nil
|
690
|
+
end
|
644
691
|
end
|
645
692
|
end
|
646
693
|
end
|
@@ -664,30 +711,26 @@ module Glimmer
|
|
664
711
|
end
|
665
712
|
|
666
713
|
def content(&block)
|
667
|
-
|
714
|
+
auto_exec do
|
715
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::WidgetExpression.new, &block)
|
716
|
+
end
|
668
717
|
end
|
669
718
|
|
670
719
|
def method_missing(method, *args, &block)
|
720
|
+
# TODO push most of this logic down to Properties (and perhaps create Listeners module as well)
|
671
721
|
if can_handle_observation_request?(method)
|
672
722
|
handle_observation_request(method, &block)
|
673
|
-
elsif has_attribute_setter?(method, *args)
|
674
|
-
set_attribute(method, *args)
|
675
|
-
elsif has_attribute_getter?(method, *args)
|
676
|
-
get_attribute(method, *args)
|
677
723
|
else
|
678
|
-
|
724
|
+
super
|
679
725
|
end
|
680
|
-
rescue => e
|
681
|
-
Glimmer::Config.logger.debug { "Neither WidgetProxy nor #{swt_widget.class.name} can handle the method ##{method}" }
|
682
|
-
Glimmer::Config.logger.debug { e.full_message }
|
683
|
-
super
|
684
|
-
# TODO consider get_attribute too
|
685
726
|
end
|
686
727
|
|
687
728
|
def respond_to?(method, *args, &block)
|
688
|
-
super
|
689
|
-
|
690
|
-
|
729
|
+
result = super
|
730
|
+
return true if result
|
731
|
+
auto_exec do
|
732
|
+
can_handle_observation_request?(method)
|
733
|
+
end
|
691
734
|
end
|
692
735
|
|
693
736
|
private
|
@@ -713,22 +756,26 @@ module Glimmer
|
|
713
756
|
# add_listener knowing it will be called for sure afterwards
|
714
757
|
|
715
758
|
def can_add_listener?(underscored_listener_name)
|
716
|
-
|
759
|
+
auto_exec do
|
760
|
+
!self.class.find_listener(@swt_widget.getClass, underscored_listener_name).empty?
|
761
|
+
end
|
717
762
|
end
|
718
763
|
|
719
764
|
def add_listener(underscored_listener_name, &block)
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
765
|
+
auto_exec do
|
766
|
+
widget_add_listener_method, listener_class, listener_method = self.class.find_listener(@swt_widget.getClass, underscored_listener_name)
|
767
|
+
widget_listener_proxy = nil
|
768
|
+
safe_block = lambda do |*args|
|
769
|
+
begin
|
770
|
+
block.call(*args) unless @swt_widget.isDisposed
|
771
|
+
rescue => e
|
772
|
+
Glimmer::Config.logger.error {e}
|
773
|
+
end
|
727
774
|
end
|
775
|
+
listener = listener_class.new(listener_method => safe_block)
|
776
|
+
@swt_widget.send(widget_add_listener_method, listener)
|
777
|
+
WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
|
728
778
|
end
|
729
|
-
listener = listener_class.new(listener_method => safe_block)
|
730
|
-
@swt_widget.send(widget_add_listener_method, listener)
|
731
|
-
WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: listener, widget_add_listener_method: widget_add_listener_method, swt_listener_class: listener_class, swt_listener_method: listener_method)
|
732
779
|
end
|
733
780
|
|
734
781
|
# Looks through SWT class add***Listener methods till it finds one for which
|
@@ -778,11 +825,13 @@ module Glimmer
|
|
778
825
|
end
|
779
826
|
|
780
827
|
def add_swt_event_listener(swt_constant, &block)
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
828
|
+
auto_exec do
|
829
|
+
event_type = SWTProxy[swt_constant]
|
830
|
+
widget_listener_proxy = nil
|
831
|
+
safe_block = lambda { |*args| block.call(*args) unless @swt_widget.isDisposed }
|
832
|
+
@swt_widget.addListener(event_type, &safe_block)
|
833
|
+
widget_listener_proxy = WidgetListenerProxy.new(swt_widget: @swt_widget, swt_listener: @swt_widget.getListeners(event_type).last, event_type: event_type, swt_constant: swt_constant)
|
834
|
+
end
|
786
835
|
end
|
787
836
|
|
788
837
|
def widget_custom_attribute_mapping
|
@@ -867,6 +916,8 @@ module Glimmer
|
|
867
916
|
color_converter = lambda do |value|
|
868
917
|
if value.is_a?(Symbol) || value.is_a?(String)
|
869
918
|
ColorProxy.new(value).swt_color
|
919
|
+
elsif value.is_a?(RGB)
|
920
|
+
ColorProxy.new(value.red, value.green, value.blue).swt_color
|
870
921
|
else
|
871
922
|
value
|
872
923
|
end
|
@@ -905,7 +956,7 @@ module Glimmer
|
|
905
956
|
while last_image_number != image_number
|
906
957
|
last_image_number = image_number
|
907
958
|
sync_exec {
|
908
|
-
redraw
|
959
|
+
redraw unless disposed?
|
909
960
|
}
|
910
961
|
delayTime = loader.data[image_number].delayTime.to_f / 100.0
|
911
962
|
sleep(delayTime)
|
@@ -936,7 +987,7 @@ module Glimmer
|
|
936
987
|
foreground: color_converter,
|
937
988
|
link_foreground: color_converter,
|
938
989
|
font: lambda do |value|
|
939
|
-
if value.is_a?(Hash)
|
990
|
+
if value.is_a?(Hash) || value.is_a?(FontData)
|
940
991
|
font_properties = value
|
941
992
|
FontProxy.new(self, font_properties).swt_font
|
942
993
|
else
|
@@ -954,6 +1005,10 @@ module Glimmer
|
|
954
1005
|
items: lambda do |value|
|
955
1006
|
value.to_java :string
|
956
1007
|
end,
|
1008
|
+
selection: lambda do |value|
|
1009
|
+
value = value.to_f if swt_widget.is_a?(Spinner)
|
1010
|
+
value
|
1011
|
+
end,
|
957
1012
|
text: lambda do |value|
|
958
1013
|
value.to_s
|
959
1014
|
end,
|