glimmer-dsl-swt 4.18.3.5 → 4.18.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -0
- data/LICENSE.txt +20 -20
- data/README.md +782 -716
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/bin/girb +31 -31
- data/bin/girb_runner.rb +34 -34
- data/bin/glimmer +26 -26
- data/glimmer-dsl-swt.gemspec +10 -7
- data/lib/ext/glimmer.rb +41 -41
- data/lib/ext/glimmer/config.rb +167 -167
- data/lib/ext/rouge/themes/glimmer.rb +29 -29
- data/lib/glimmer-dsl-swt.rb +44 -44
- data/lib/glimmer/Rakefile +26 -26
- data/lib/glimmer/data_binding/list_selection_binding.rb +72 -72
- data/lib/glimmer/data_binding/observable_widget.rb +38 -38
- data/lib/glimmer/data_binding/shine.rb +44 -44
- data/lib/glimmer/data_binding/table_items_binding.rb +89 -89
- data/lib/glimmer/data_binding/tree_items_binding.rb +108 -108
- data/lib/glimmer/data_binding/widget_binding.rb +73 -73
- data/lib/glimmer/dsl/swt/animation_expression.rb +43 -43
- data/lib/glimmer/dsl/swt/async_exec_expression.rb +35 -35
- data/lib/glimmer/dsl/swt/bind_expression.rb +58 -58
- data/lib/glimmer/dsl/swt/block_property_expression.rb +41 -41
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -61
- data/lib/glimmer/dsl/swt/color_expression.rb +40 -40
- data/lib/glimmer/dsl/swt/column_properties_expression.rb +45 -45
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +67 -67
- data/lib/glimmer/dsl/swt/cursor_expression.rb +44 -44
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/display_expression.rb +40 -40
- data/lib/glimmer/dsl/swt/dnd_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/dsl.rb +63 -63
- data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -60
- data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -48
- data/lib/glimmer/dsl/swt/font_expression.rb +49 -49
- data/lib/glimmer/dsl/swt/image_expression.rb +50 -50
- data/lib/glimmer/dsl/swt/layout_data_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/layout_expression.rb +50 -50
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +65 -65
- data/lib/glimmer/dsl/swt/menu_bar_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/menu_expression.rb +53 -53
- data/lib/glimmer/dsl/swt/message_box_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/multiply_expression.rb +53 -53
- data/lib/glimmer/dsl/swt/observe_expression.rb +53 -53
- data/lib/glimmer/dsl/swt/property_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +61 -61
- data/lib/glimmer/dsl/swt/rgb_expression.rb +33 -33
- data/lib/glimmer/dsl/swt/rgba_expression.rb +33 -33
- data/lib/glimmer/dsl/swt/shape_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/shell_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/swt_expression.rb +46 -46
- data/lib/glimmer/dsl/swt/sync_exec_expression.rb +36 -36
- data/lib/glimmer/dsl/swt/tab_item_expression.rb +54 -54
- data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +52 -52
- data/lib/glimmer/dsl/swt/timer_exec_expression.rb +35 -0
- data/lib/glimmer/dsl/swt/transform_expression.rb +55 -55
- data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +52 -52
- data/lib/glimmer/dsl/swt/tree_properties_expression.rb +47 -47
- data/lib/glimmer/dsl/swt/widget_expression.rb +66 -66
- data/lib/glimmer/dsl/swt/widget_listener_expression.rb +53 -53
- data/lib/glimmer/rake_task.rb +220 -220
- data/lib/glimmer/rake_task/list.rb +97 -97
- data/lib/glimmer/rake_task/package.rb +139 -139
- data/lib/glimmer/rake_task/scaffold.rb +765 -765
- data/lib/glimmer/swt/color_proxy.rb +107 -107
- data/lib/glimmer/swt/cursor_proxy.rb +66 -66
- data/lib/glimmer/swt/custom/animation.rb +243 -243
- data/lib/glimmer/swt/custom/checkbox_group.rb +181 -181
- data/lib/glimmer/swt/custom/code_text.rb +150 -93
- data/lib/glimmer/swt/custom/drawable.rb +49 -52
- data/lib/glimmer/swt/custom/radio_group.rb +176 -176
- data/lib/glimmer/swt/custom/shape.rb +297 -253
- data/lib/glimmer/swt/date_time_proxy.rb +85 -85
- data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -65
- data/lib/glimmer/swt/display_proxy.rb +166 -155
- data/lib/glimmer/swt/dnd_proxy.rb +51 -51
- data/lib/glimmer/swt/expand_item_proxy.rb +97 -97
- data/lib/glimmer/swt/file_dialog_proxy.rb +66 -66
- data/lib/glimmer/swt/font_proxy.rb +94 -94
- data/lib/glimmer/swt/image_proxy.rb +184 -173
- data/lib/glimmer/swt/layout_data_proxy.rb +105 -105
- data/lib/glimmer/swt/layout_proxy.rb +112 -109
- data/lib/glimmer/swt/menu_proxy.rb +126 -126
- data/lib/glimmer/swt/message_box_proxy.rb +89 -89
- data/lib/glimmer/swt/packages.rb +37 -37
- data/lib/glimmer/swt/properties.rb +49 -49
- data/lib/glimmer/swt/sash_form_proxy.rb +53 -53
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +37 -37
- data/lib/glimmer/swt/shell_proxy.rb +4 -1
- data/lib/glimmer/swt/style_constantizable.rb +157 -157
- data/lib/glimmer/swt/styled_text_proxy.rb +38 -38
- data/lib/glimmer/swt/swt_proxy.rb +59 -59
- data/lib/glimmer/swt/tab_item_proxy.rb +91 -91
- data/lib/glimmer/swt/table_column_proxy.rb +57 -57
- data/lib/glimmer/swt/table_proxy.rb +2 -2
- data/lib/glimmer/swt/transform_proxy.rb +109 -109
- data/lib/glimmer/swt/tree_proxy.rb +145 -145
- data/lib/glimmer/swt/widget_listener_proxy.rb +64 -64
- data/lib/glimmer/swt/widget_proxy.rb +957 -949
- data/lib/glimmer/ui/custom_shell.rb +82 -82
- data/lib/glimmer/ui/custom_widget.rb +315 -315
- data/lib/glimmer/util/proc_tracker.rb +39 -39
- data/samples/elaborate/contact_manager.rb +142 -142
- data/samples/elaborate/contact_manager/contact.rb +32 -32
- data/samples/elaborate/contact_manager/contact_manager_presenter.rb +47 -47
- data/samples/elaborate/contact_manager/contact_repository.rb +169 -169
- data/samples/elaborate/login.rb +123 -123
- data/samples/elaborate/meta_sample.rb +14 -3
- data/samples/elaborate/tetris.rb +16 -6
- data/samples/elaborate/tetris/model/block.rb +48 -48
- data/samples/elaborate/tetris/model/game.rb +2 -3
- data/samples/elaborate/tetris/model/past_game.rb +39 -39
- data/samples/elaborate/tetris/view/block.rb +1 -1
- data/samples/elaborate/tetris/view/high_score_dialog.rb +0 -7
- data/samples/elaborate/tetris/view/playfield.rb +1 -1
- data/samples/elaborate/tetris/view/tetris_menu_bar.rb +13 -11
- data/samples/elaborate/tic_tac_toe.rb +76 -76
- data/samples/elaborate/tic_tac_toe/board.rb +145 -145
- data/samples/elaborate/tic_tac_toe/cell.rb +48 -48
- data/samples/elaborate/user_profile.rb +76 -76
- data/samples/hello/hello_browser.rb +31 -31
- data/samples/hello/hello_button.rb +46 -46
- data/samples/hello/hello_canvas.rb +64 -63
- data/samples/hello/hello_canvas_animation.rb +3 -3
- data/samples/hello/hello_canvas_transform.rb +1 -1
- data/samples/hello/hello_checkbox.rb +85 -85
- data/samples/hello/hello_checkbox_group.rb +71 -71
- data/samples/hello/hello_code_text.rb +104 -84
- data/samples/hello/hello_combo.rb +63 -63
- data/samples/hello/hello_computed.rb +96 -96
- data/samples/hello/hello_computed/contact.rb +42 -42
- data/samples/hello/hello_custom_shell.rb +155 -155
- data/samples/hello/hello_custom_widget.rb +86 -86
- data/samples/hello/hello_date_time.rb +63 -63
- data/samples/hello/hello_dialog.rb +78 -78
- data/samples/hello/hello_directory_dialog.rb +60 -60
- data/samples/hello/hello_drag_and_drop.rb +50 -50
- data/samples/hello/hello_expand_bar.rb +110 -110
- data/samples/hello/hello_file_dialog.rb +60 -60
- data/samples/hello/hello_group.rb +104 -104
- data/samples/hello/hello_link.rb +80 -80
- data/samples/hello/hello_list_multi_selection.rb +74 -74
- data/samples/hello/hello_list_single_selection.rb +59 -59
- data/samples/hello/hello_menu_bar.rb +241 -241
- data/samples/hello/hello_message_box.rb +37 -37
- data/samples/hello/hello_pop_up_context_menu.rb +84 -84
- data/samples/hello/hello_radio.rb +108 -108
- data/samples/hello/hello_radio_group.rb +87 -87
- data/samples/hello/hello_sash_form.rb +137 -137
- data/samples/hello/hello_spinner.rb +69 -69
- data/samples/hello/hello_styled_text.rb +138 -138
- data/samples/hello/hello_tab.rb +50 -50
- data/samples/hello/hello_table.rb +7 -4
- data/samples/hello/hello_table/baseball_park.png +0 -0
- data/samples/hello/hello_world.rb +29 -29
- metadata +7 -4
@@ -1,253 +1,297 @@
|
|
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
|
-
require 'glimmer/swt/swt_proxy'
|
24
|
-
require 'glimmer/swt/display_proxy'
|
25
|
-
require 'glimmer/swt/color_proxy'
|
26
|
-
require 'glimmer/swt/font_proxy'
|
27
|
-
require 'glimmer/swt/transform_proxy'
|
28
|
-
|
29
|
-
module Glimmer
|
30
|
-
module SWT
|
31
|
-
module Custom
|
32
|
-
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
-
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
-
class Shape
|
35
|
-
include Packages
|
36
|
-
include Properties
|
37
|
-
# TODO support textExtent sized shapes nested within text/string
|
38
|
-
# TODO support a Pattern DSL for methods that take Pattern arguments
|
39
|
-
|
40
|
-
class << self
|
41
|
-
def valid?(parent, keyword, *args, &block)
|
42
|
-
gc_instance_methods.include?(method_name(keyword, args))
|
43
|
-
end
|
44
|
-
|
45
|
-
def gc_instance_methods
|
46
|
-
@gc_instance_methods ||= org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
|
47
|
-
end
|
48
|
-
|
49
|
-
def keywords
|
50
|
-
@keywords ||= gc_instance_methods.select do |method_name|
|
51
|
-
!method_name.end_with?('=') && (method_name.start_with?('draw_') || method_name.start_with?('fill_'))
|
52
|
-
end.reject do |method_name|
|
53
|
-
gc_instance_methods.include?("#{method_name}=") || gc_instance_methods.include?("set_#{method_name}")
|
54
|
-
end.map do |method_name|
|
55
|
-
method_name.gsub(/(draw|fill|gradient|round)_/, '')
|
56
|
-
end.uniq.compact.to_a
|
57
|
-
end
|
58
|
-
|
59
|
-
def arg_options(args, extract: false)
|
60
|
-
arg_options_method = extract ? :pop : :last
|
61
|
-
options = args.send(arg_options_method) if args.last.is_a?(Hash)
|
62
|
-
options.nil? ? {} : options.symbolize_keys
|
63
|
-
end
|
64
|
-
|
65
|
-
def method_name(keyword, args)
|
66
|
-
method_arg_options = arg_options(args)
|
67
|
-
unless flyweight_method_names.keys.include?([keyword, method_arg_options])
|
68
|
-
keyword = keyword.to_s
|
69
|
-
gradient = 'gradient_' if method_arg_options[:gradient]
|
70
|
-
round = 'round_' if method_arg_options[:round]
|
71
|
-
gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? 'fill_' : 'draw_'
|
72
|
-
flyweight_method_names[[keyword, method_arg_options]] = "#{gc_instance_method_name_prefix}#{gradient}#{round}#{keyword}"
|
73
|
-
end
|
74
|
-
flyweight_method_names[[keyword, method_arg_options]]
|
75
|
-
end
|
76
|
-
|
77
|
-
def flyweight_method_names
|
78
|
-
@flyweight_method_names ||= {}
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
@
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
@
|
117
|
-
end
|
118
|
-
|
119
|
-
def
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
args[
|
153
|
-
end
|
154
|
-
args
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
args
|
171
|
-
end
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
def
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
def
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
|
228
|
-
def
|
229
|
-
@properties[
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
+
require 'glimmer/swt/swt_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/color_proxy'
|
26
|
+
require 'glimmer/swt/font_proxy'
|
27
|
+
require 'glimmer/swt/transform_proxy'
|
28
|
+
|
29
|
+
module Glimmer
|
30
|
+
module SWT
|
31
|
+
module Custom
|
32
|
+
# Represents a shape (graphics) to be drawn on a control/widget/canvas/display
|
33
|
+
# That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
|
34
|
+
class Shape
|
35
|
+
include Packages
|
36
|
+
include Properties
|
37
|
+
# TODO support textExtent sized shapes nested within text/string
|
38
|
+
# TODO support a Pattern DSL for methods that take Pattern arguments
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def valid?(parent, keyword, *args, &block)
|
42
|
+
gc_instance_methods.include?(method_name(keyword, args))
|
43
|
+
end
|
44
|
+
|
45
|
+
def gc_instance_methods
|
46
|
+
@gc_instance_methods ||= org.eclipse.swt.graphics.GC.instance_methods.map(&:to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
def keywords
|
50
|
+
@keywords ||= gc_instance_methods.select do |method_name|
|
51
|
+
!method_name.end_with?('=') && (method_name.start_with?('draw_') || method_name.start_with?('fill_'))
|
52
|
+
end.reject do |method_name|
|
53
|
+
gc_instance_methods.include?("#{method_name}=") || gc_instance_methods.include?("set_#{method_name}")
|
54
|
+
end.map do |method_name|
|
55
|
+
method_name.gsub(/(draw|fill|gradient|round)_/, '')
|
56
|
+
end.uniq.compact.to_a
|
57
|
+
end
|
58
|
+
|
59
|
+
def arg_options(args, extract: false)
|
60
|
+
arg_options_method = extract ? :pop : :last
|
61
|
+
options = args.send(arg_options_method) if args.last.is_a?(Hash)
|
62
|
+
options.nil? ? {} : options.symbolize_keys
|
63
|
+
end
|
64
|
+
|
65
|
+
def method_name(keyword, args)
|
66
|
+
method_arg_options = arg_options(args)
|
67
|
+
unless flyweight_method_names.keys.include?([keyword, method_arg_options])
|
68
|
+
keyword = keyword.to_s
|
69
|
+
gradient = 'gradient_' if method_arg_options[:gradient]
|
70
|
+
round = 'round_' if method_arg_options[:round]
|
71
|
+
gc_instance_method_name_prefix = !['polyline', 'point', 'image', 'focus'].include?(keyword) && (method_arg_options[:fill] || method_arg_options[:gradient]) ? 'fill_' : 'draw_'
|
72
|
+
flyweight_method_names[[keyword, method_arg_options]] = "#{gc_instance_method_name_prefix}#{gradient}#{round}#{keyword}"
|
73
|
+
end
|
74
|
+
flyweight_method_names[[keyword, method_arg_options]]
|
75
|
+
end
|
76
|
+
|
77
|
+
def flyweight_method_names
|
78
|
+
@flyweight_method_names ||= {}
|
79
|
+
end
|
80
|
+
|
81
|
+
def pattern(*args)
|
82
|
+
found_pattern = flyweigh_patterns[args]
|
83
|
+
if found_pattern.nil? || found_pattern.is_disposed
|
84
|
+
found_pattern = flyweigh_patterns[args] = org.eclipse.swt.graphics.Pattern.new(*args)
|
85
|
+
end
|
86
|
+
found_pattern
|
87
|
+
end
|
88
|
+
|
89
|
+
def flyweigh_patterns
|
90
|
+
@flyweigh_patterns ||= {}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
attr_reader :parent, :name, :args, :options, :paint_listener_proxy
|
95
|
+
|
96
|
+
def initialize(parent, keyword, *args, &property_block)
|
97
|
+
@parent = parent
|
98
|
+
@name = keyword
|
99
|
+
@method_name = self.class.method_name(keyword, args)
|
100
|
+
@options = self.class.arg_options(args, extract: true)
|
101
|
+
@args = args
|
102
|
+
@properties = {}
|
103
|
+
@parent.shapes << self
|
104
|
+
post_add_content if property_block.nil?
|
105
|
+
end
|
106
|
+
|
107
|
+
def draw?
|
108
|
+
!fill?
|
109
|
+
end
|
110
|
+
|
111
|
+
def fill?
|
112
|
+
@options[:fill]
|
113
|
+
end
|
114
|
+
|
115
|
+
def gradient?
|
116
|
+
@options[:gradient]
|
117
|
+
end
|
118
|
+
|
119
|
+
def round?
|
120
|
+
@options[:round]
|
121
|
+
end
|
122
|
+
|
123
|
+
def has_some_background?
|
124
|
+
@properties.keys.map(&:to_s).include?('background') || @properties.keys.map(&:to_s).include?('background_pattern')
|
125
|
+
end
|
126
|
+
|
127
|
+
def has_some_foreground?
|
128
|
+
@properties.keys.map(&:to_s).include?('foreground') || @properties.keys.map(&:to_s).include?('foreground_pattern')
|
129
|
+
end
|
130
|
+
|
131
|
+
def post_add_content
|
132
|
+
amend_method_name_options_based_on_properties
|
133
|
+
setup_painting
|
134
|
+
@content_added = true
|
135
|
+
end
|
136
|
+
|
137
|
+
def apply_property_arg_conversions(method_name, property, args)
|
138
|
+
args = args.dup
|
139
|
+
the_java_method = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.detect {|m| m.name == method_name}
|
140
|
+
if (args.first.is_a?(Symbol) || args.first.is_a?(String))
|
141
|
+
if the_java_method.parameter_types.first == Color.java_class
|
142
|
+
args[0] = ColorProxy.new(args[0])
|
143
|
+
end
|
144
|
+
if the_java_method.parameter_types.first == Java::int.java_class
|
145
|
+
args[0] = SWTProxy.constant(args[0])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
if args.first.is_a?(ColorProxy)
|
149
|
+
args[0] = args[0].swt_color
|
150
|
+
end
|
151
|
+
if args.first.is_a?(Hash) && the_java_method.parameter_types.first == Font.java_class
|
152
|
+
args[0] = FontProxy.new(args[0])
|
153
|
+
end
|
154
|
+
if args.first.is_a?(FontProxy)
|
155
|
+
args[0] = args[0].swt_font
|
156
|
+
end
|
157
|
+
if args.first.is_a?(TransformProxy)
|
158
|
+
args[0] = args[0].swt_transform
|
159
|
+
end
|
160
|
+
if ['setBackgroundPattern', 'setForegroundPattern'].include?(method_name.to_s)
|
161
|
+
args.each_with_index do |arg, i|
|
162
|
+
if arg.is_a?(Symbol) || arg.is_a?(String)
|
163
|
+
args[i] = ColorProxy.new(arg).swt_color
|
164
|
+
elsif arg.is_a?(ColorProxy)
|
165
|
+
args[i] = arg.swt_color
|
166
|
+
end
|
167
|
+
end
|
168
|
+
new_args = [DisplayProxy.instance.swt_display] + args
|
169
|
+
args[0] = pattern(*new_args, type: method_name.to_s.match(/set(.+)Pattern/)[1])
|
170
|
+
args[1..-1] = []
|
171
|
+
end
|
172
|
+
args
|
173
|
+
end
|
174
|
+
|
175
|
+
def apply_shape_arg_conversions(method_name, args)
|
176
|
+
if args.size > 1 && (method_name.include?('polygon') || method_name.include?('polyline'))
|
177
|
+
args[0] = args.dup
|
178
|
+
args[1..-1] = []
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def apply_shape_arg_defaults(method_name, args)
|
183
|
+
if method_name.include?('round_rectangle') && args.size.between?(4, 5)
|
184
|
+
(6 - args.size).times {args << 60}
|
185
|
+
elsif method_name.include?('rectangle') && gradient? && args.size == 4
|
186
|
+
args << true
|
187
|
+
elsif (method_name.include?('text') || method_name.include?('string')) && !@properties.keys.map(&:to_s).include?('background') && args.size == 3
|
188
|
+
args << true
|
189
|
+
end
|
190
|
+
if method_name.include?('image') && args.first.is_a?(String)
|
191
|
+
args[0] = ImageProxy.new(args[0])
|
192
|
+
end
|
193
|
+
if method_name.include?('image') && args.first.is_a?(ImageProxy)
|
194
|
+
@image = args[0] = args[0].swt_image
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
# Tolerates shape extra args added by user by mistake
|
199
|
+
# (e.g. happens when switching from round rectangle to a standard one without removing all extra args)
|
200
|
+
def tolerate_shape_extra_args(method_name, args)
|
201
|
+
the_java_method_arg_count = org.eclipse.swt.graphics.GC.java_class.declared_instance_methods.select do |m|
|
202
|
+
m.name == method_name.camelcase(:lower)
|
203
|
+
end.map(&:parameter_types).map(&:size).max
|
204
|
+
if args.size > the_java_method_arg_count
|
205
|
+
args[the_java_method_arg_count..-1] = []
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def amend_method_name_options_based_on_properties
|
210
|
+
if has_some_background? && !has_some_foreground?
|
211
|
+
@options[:fill] = true
|
212
|
+
elsif !has_some_background? && has_some_foreground?
|
213
|
+
@options[:fill] = false
|
214
|
+
elsif @name == 'rectangle' && has_some_background? && has_some_foreground?
|
215
|
+
@options[:fill] = true
|
216
|
+
@options[:gradient] = true
|
217
|
+
end
|
218
|
+
if @name == 'rectangle' && @args.size > 4 && @args.last.is_a?(Numeric)
|
219
|
+
@options[:round] = true
|
220
|
+
end
|
221
|
+
@method_name = self.class.method_name(@name, @args + [@options])
|
222
|
+
end
|
223
|
+
|
224
|
+
def has_attribute?(attribute_name, *args)
|
225
|
+
self.class.gc_instance_methods.include?(attribute_setter(attribute_name))
|
226
|
+
end
|
227
|
+
|
228
|
+
def set_attribute(attribute_name, *args)
|
229
|
+
@properties[attribute_name] = args
|
230
|
+
if @content_added && !@parent.is_disposed
|
231
|
+
@parent.resetup_shape_painting
|
232
|
+
@parent.redraw
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def get_attribute(attribute_name)
|
237
|
+
@properties.symbolize_keys[attribute_name.to_s.to_sym]
|
238
|
+
end
|
239
|
+
|
240
|
+
def pattern(*args, type: nil)
|
241
|
+
instance_variable_name = "@#{type}_pattern"
|
242
|
+
the_pattern = instance_variable_get(instance_variable_name)
|
243
|
+
if the_pattern.nil?
|
244
|
+
the_pattern = self.class.pattern(*args)
|
245
|
+
end
|
246
|
+
the_pattern
|
247
|
+
end
|
248
|
+
|
249
|
+
def dispose
|
250
|
+
paint_listener_proxy&.unregister
|
251
|
+
@background_pattern&.dispose
|
252
|
+
@background_pattern = nil
|
253
|
+
@foreground_pattern&.dispose
|
254
|
+
@foreground_pattern = nil
|
255
|
+
@image&.dispose
|
256
|
+
@image = nil
|
257
|
+
@parent.shapes.delete(self)
|
258
|
+
end
|
259
|
+
|
260
|
+
def setup_painting
|
261
|
+
# TODO consider moving this method to parent (making the logic polymorphic)
|
262
|
+
return if @parent.is_disposed
|
263
|
+
if parent.respond_to?(:swt_display)
|
264
|
+
@paint_listener_proxy = @parent.on_swt_paint(&method(:paint))
|
265
|
+
elsif parent.respond_to?(:swt_image)
|
266
|
+
paint(parent) # treat parent as paint event since you don't do repaints with images, it's a one time deal.
|
267
|
+
elsif parent.respond_to?(:swt_widget)
|
268
|
+
@paint_listener_proxy = @parent.on_paint_control(&method(:paint))
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
def paint(paint_event)
|
273
|
+
@properties['background'] = [@parent.background] if fill? && !has_some_background?
|
274
|
+
@properties['foreground'] = [@parent.foreground] if @parent.respond_to?(:foreground) && draw? && !has_some_foreground?
|
275
|
+
@properties['font'] = [@parent.font] if @parent.respond_to?(:font) && draw? && !@properties.keys.map(&:to_s).include?('font')
|
276
|
+
@properties['transform'] = [nil] if @parent.respond_to?(:transform) && !@properties.keys.map(&:to_s).include?('transform')
|
277
|
+
@properties.each do |property, args|
|
278
|
+
method_name = attribute_setter(property)
|
279
|
+
converted_args = apply_property_arg_conversions(method_name, property, args)
|
280
|
+
paint_event.gc.send(method_name, *converted_args)
|
281
|
+
if property == 'transform' && args.first.is_a?(TransformProxy)
|
282
|
+
args.first.swt_transform.dispose
|
283
|
+
end
|
284
|
+
end
|
285
|
+
apply_shape_arg_conversions(@method_name, @args)
|
286
|
+
apply_shape_arg_defaults(@method_name, @args)
|
287
|
+
tolerate_shape_extra_args(@method_name, @args)
|
288
|
+
paint_event.gc.send(@method_name, *@args)
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
end
|