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
@@ -0,0 +1,115 @@
|
|
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/custom/shape'
|
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
|
+
class Polyline < Shape
|
36
|
+
def parameter_names
|
37
|
+
[:point_array]
|
38
|
+
end
|
39
|
+
|
40
|
+
def location_parameter_names
|
41
|
+
parameter_names
|
42
|
+
end
|
43
|
+
|
44
|
+
def point_count
|
45
|
+
point_array.count / 2
|
46
|
+
end
|
47
|
+
|
48
|
+
def [](index)
|
49
|
+
index = 0 if index == point_count
|
50
|
+
org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
|
51
|
+
end
|
52
|
+
|
53
|
+
def x_array
|
54
|
+
point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
|
55
|
+
end
|
56
|
+
|
57
|
+
def y_array
|
58
|
+
point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
|
59
|
+
end
|
60
|
+
|
61
|
+
def point_xy_array
|
62
|
+
x_array.zip(y_array)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Logical x coordinate. Always assumes the first point in the polyline to be the x coordinate.
|
66
|
+
def x
|
67
|
+
x_array.first
|
68
|
+
end
|
69
|
+
|
70
|
+
# Logical y coordinate. Always assumes the first point in the polyline to be the y coordinate.
|
71
|
+
def y
|
72
|
+
y_array.first
|
73
|
+
end
|
74
|
+
|
75
|
+
def absolute_point_array
|
76
|
+
if parent.is_a?(Shape)
|
77
|
+
point_array.each_with_index.map do |coordinate, i|
|
78
|
+
if i.even?
|
79
|
+
parent.absolute_x + coordinate
|
80
|
+
else
|
81
|
+
parent.absolute_y + coordinate
|
82
|
+
end
|
83
|
+
end
|
84
|
+
else
|
85
|
+
point_array
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def absolute_x_array
|
90
|
+
absolute_point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
|
91
|
+
end
|
92
|
+
|
93
|
+
def absolute_y_array
|
94
|
+
absolute_point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
|
95
|
+
end
|
96
|
+
|
97
|
+
def absolute_point_xy_array
|
98
|
+
absolute_x_array.zip(absolute_y_array)
|
99
|
+
end
|
100
|
+
|
101
|
+
def include?(x, y)
|
102
|
+
comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
|
103
|
+
comparison_lines.pop # ignore last pair since you don't want to compare last point with first point
|
104
|
+
comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
|
105
|
+
end
|
106
|
+
alias contain? include?
|
107
|
+
|
108
|
+
def move_by(x_delta, y_delta)
|
109
|
+
self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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/custom/shape'
|
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
|
+
class Rectangle < Shape
|
36
|
+
def parameter_names
|
37
|
+
if @args.to_a.size >= 6
|
38
|
+
rectangle_round_parameter_names
|
39
|
+
elsif @args.to_a.size == 5
|
40
|
+
rectangle_gradient_parameter_names
|
41
|
+
elsif @args.to_a.size == 1
|
42
|
+
rectangle_rectangle_parameter_names
|
43
|
+
else
|
44
|
+
rectangle_parameter_names
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def possible_parameter_names
|
49
|
+
# TODO refactor and improve this method through meta-programming (and share across other shapes)
|
50
|
+
(rectangle_round_parameter_names + rectangle_gradient_parameter_names + rectangle_parameter_names + rectangle_rectangle_parameter_names).uniq
|
51
|
+
end
|
52
|
+
|
53
|
+
def rectangle_round_parameter_names
|
54
|
+
[:x, :y, :width, :height, :arc_width, :arc_height]
|
55
|
+
end
|
56
|
+
|
57
|
+
def rectangle_gradient_parameter_names
|
58
|
+
[:x, :y, :width, :height, :vertical]
|
59
|
+
end
|
60
|
+
|
61
|
+
def rectangle_parameter_names
|
62
|
+
[:x, :y, :width, :height]
|
63
|
+
end
|
64
|
+
|
65
|
+
def rectangle_rectangle_parameter_names
|
66
|
+
# this receives a Rectangle object
|
67
|
+
[:rectangle]
|
68
|
+
end
|
69
|
+
|
70
|
+
def parameter_index(attribute_name)
|
71
|
+
####TODO refactor and improve this method through meta-programming (and share across other shapes)
|
72
|
+
if rectangle_round_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
73
|
+
rectangle_round_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
74
|
+
elsif rectangle_gradient_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
75
|
+
rectangle_gradient_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
76
|
+
elsif rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
77
|
+
rectangle_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
78
|
+
elsif rectangle_rectangle_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
79
|
+
rectangle_rectangle_parameter_names.map(&:to_s).index(attribute_name.to_s)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def point_xy_array
|
84
|
+
[[x, y], [x + width, y], [x + width, y + height], [x, y + height]]
|
85
|
+
end
|
86
|
+
|
87
|
+
def absolute_point_xy_array
|
88
|
+
[[absolute_x, absolute_y], [absolute_x + width, absolute_y], [absolute_x + width, absolute_y + height], [absolute_x, absolute_y + height]]
|
89
|
+
end
|
90
|
+
|
91
|
+
# checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
|
92
|
+
def include?(x, y)
|
93
|
+
if filled?
|
94
|
+
contain?(x, y)
|
95
|
+
else
|
96
|
+
comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
|
97
|
+
comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,85 @@
|
|
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/custom/shape'
|
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
|
+
class Text < Shape
|
36
|
+
attr_accessor :extent
|
37
|
+
|
38
|
+
def parameter_names
|
39
|
+
@parameter_names || text_parameter_names
|
40
|
+
end
|
41
|
+
|
42
|
+
def possible_parameter_names
|
43
|
+
# TODO refactor and improve this method through meta-programming (and share across other shapes)
|
44
|
+
(text_parameter_names + text_transparent_parameter_names + text_flags_parameter_names).uniq
|
45
|
+
end
|
46
|
+
|
47
|
+
def text_parameter_names
|
48
|
+
[:string, :x, :y]
|
49
|
+
end
|
50
|
+
|
51
|
+
def text_transparent_parameter_names
|
52
|
+
[:string, :x, :y, :is_transparent]
|
53
|
+
end
|
54
|
+
|
55
|
+
def text_flags_parameter_names
|
56
|
+
[:string, :x, :y, :flags]
|
57
|
+
end
|
58
|
+
|
59
|
+
def set_parameter_attribute(attribute_name, *args)
|
60
|
+
return super if @parameter_names.to_a.map(&:to_s).include?(attribute_name.to_s)
|
61
|
+
if text_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
62
|
+
@parameter_names = text_parameter_names
|
63
|
+
elsif text_transparent_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
64
|
+
@parameter_names = text_transparent_parameter_names
|
65
|
+
elsif text_flags_parameter_names.map(&:to_s).include?(attribute_name.to_s)
|
66
|
+
@parameter_names = text_flags_parameter_names
|
67
|
+
end
|
68
|
+
super
|
69
|
+
end
|
70
|
+
|
71
|
+
def width
|
72
|
+
extent&.x
|
73
|
+
end
|
74
|
+
|
75
|
+
def height
|
76
|
+
extent&.y
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
String = Text
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -43,7 +43,9 @@ module Glimmer
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def date=(date_value)
|
46
|
-
|
46
|
+
auto_exec do
|
47
|
+
swt_widget.setDate(date_value.year, date_value.month - 1, date_value.day)
|
48
|
+
end
|
47
49
|
end
|
48
50
|
|
49
51
|
def time
|
@@ -58,11 +60,15 @@ module Glimmer
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def month
|
61
|
-
|
63
|
+
auto_exec do
|
64
|
+
swt_widget.month + 1
|
65
|
+
end
|
62
66
|
end
|
63
67
|
|
64
68
|
def month=(new_value)
|
65
|
-
|
69
|
+
auto_exec do
|
70
|
+
swt_widget.month = new_value - 1
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
74
|
def set_attribute(attribute_name, *args)
|
@@ -0,0 +1,92 @@
|
|
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/swt_proxy'
|
23
|
+
require 'glimmer/swt/widget_proxy'
|
24
|
+
require 'glimmer/swt/display_proxy'
|
25
|
+
require 'glimmer/swt/proxy_properties'
|
26
|
+
|
27
|
+
module Glimmer
|
28
|
+
module SWT
|
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.
|
34
|
+
#
|
35
|
+
# Automatically uses the current shell if one is open.
|
36
|
+
# Otherwise, it instantiates a new shell parent
|
37
|
+
#
|
38
|
+
# Optionally takes a shell as an argument
|
39
|
+
#
|
40
|
+
# Follows the Proxy Design Pattern
|
41
|
+
class DialogProxy
|
42
|
+
# TODO write rspec tests
|
43
|
+
include ProxyProperties
|
44
|
+
|
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
|
57
|
+
|
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
|
65
|
+
else
|
66
|
+
style_args = args.select {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
|
67
|
+
if style_args.any?
|
68
|
+
style_arg_start_index = args.index(style_args.first)
|
69
|
+
style_arg_last_index = args.index(style_args.last)
|
70
|
+
args[style_arg_start_index..style_arg_last_index] = SWTProxy[style_args]
|
71
|
+
end
|
72
|
+
if args.first.respond_to?(:swt_widget) && args.first.swt_widget.is_a?(Shell)
|
73
|
+
args[0] = args[0].swt_widget
|
74
|
+
end
|
75
|
+
if !args.first.is_a?(Shell)
|
76
|
+
current_shell = DisplayProxy.instance.swt_display.shells.first
|
77
|
+
args.unshift(current_shell.nil? ? ShellProxy.new : current_shell)
|
78
|
+
end
|
79
|
+
parent = args[0]
|
80
|
+
@parent_proxy = parent.is_a?(Shell) ? ShellProxy.new(swt_widget: parent) : parent
|
81
|
+
@swt_dialog = dialog_class.new(*args)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def proxy_source_object
|
87
|
+
@swt_dialog
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -58,10 +58,16 @@ module Glimmer
|
|
58
58
|
# Returns singleton instance
|
59
59
|
def instance(*args)
|
60
60
|
if @instance.nil? || @instance.swt_display.nil? || @instance.swt_display.isDisposed
|
61
|
+
@thread = Thread.current
|
61
62
|
@instance = new(*args)
|
62
63
|
end
|
63
64
|
@instance
|
64
65
|
end
|
66
|
+
|
67
|
+
def thread
|
68
|
+
instance # ensure instance
|
69
|
+
@thread
|
70
|
+
end
|
65
71
|
end
|
66
72
|
|
67
73
|
# SWT Display object wrapped
|
@@ -71,6 +77,7 @@ module Glimmer
|
|
71
77
|
Display.app_name ||= 'Glimmer'
|
72
78
|
@swt_display = Display.new(*args)
|
73
79
|
@swt_display.set_data('proxy', self)
|
80
|
+
@execs_in_progress = {}
|
74
81
|
on_swt_Dispose {
|
75
82
|
clear_shapes
|
76
83
|
}
|
@@ -80,18 +87,71 @@ module Glimmer
|
|
80
87
|
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::DisplayExpression.new, &block)
|
81
88
|
end
|
82
89
|
|
90
|
+
# asynchronously executes the block (required from threads other than first GUI thread)
|
91
|
+
# does not return the value produced by the block since it is async, running after the return
|
83
92
|
def async_exec(&block)
|
84
|
-
@swt_display.asyncExec
|
93
|
+
@swt_display.asyncExec do
|
94
|
+
execs_in_progress << :async_exec
|
95
|
+
begin
|
96
|
+
result = block.call
|
97
|
+
ensure
|
98
|
+
execs_in_progress.pop
|
99
|
+
end
|
100
|
+
end
|
85
101
|
end
|
86
102
|
|
103
|
+
# synchronously executes the block (required from threads other than first GUI thread)
|
104
|
+
# returns the value produced by the block
|
87
105
|
def sync_exec(&block)
|
88
|
-
|
106
|
+
result = nil
|
107
|
+
@swt_display.syncExec do
|
108
|
+
execs_in_progress << :sync_exec
|
109
|
+
begin
|
110
|
+
result = block.call
|
111
|
+
ensure
|
112
|
+
execs_in_progress.pop
|
113
|
+
end
|
114
|
+
end
|
115
|
+
result
|
89
116
|
end
|
90
117
|
|
91
118
|
def timer_exec(delay_in_millis, &block)
|
92
119
|
@swt_display.timerExec(delay_in_millis, &block)
|
93
120
|
end
|
94
121
|
|
122
|
+
# Indicates whether `sync_exec` is required because of running in a different thread from the GUI thread
|
123
|
+
# `async_exec` could be used as an alternative to `sync_exec` when required.
|
124
|
+
def sync_exec_required?
|
125
|
+
Thread.current != DisplayProxy.thread
|
126
|
+
end
|
127
|
+
|
128
|
+
def async_exec_in_progress?
|
129
|
+
execs_in_progress.last == :async_exec
|
130
|
+
end
|
131
|
+
|
132
|
+
def sync_exec_in_progress?
|
133
|
+
execs_in_progress.include?(:sync_exec)
|
134
|
+
end
|
135
|
+
|
136
|
+
def execs_in_progress
|
137
|
+
@execs_in_progress[Thread.current] ||= []
|
138
|
+
end
|
139
|
+
|
140
|
+
# Invoke block with `sync_exec` only when necessary (running from a separate thread)
|
141
|
+
# Override sync_exec as `true` to force using or `false` to force avoiding
|
142
|
+
# Override async_exec as `true` to force using or `:unless_in_progress` to force using only if no `async_exec` is in progress
|
143
|
+
# Disable auto execution of `sync_exec` via `Glimmer::Config.auto_sync_exec = false`
|
144
|
+
# Otherwise, runs normally, thus allowing SWT to decide how to batch/optimize GUI updates
|
145
|
+
def auto_exec(override_sync_exec: nil, override_async_exec: nil, &block)
|
146
|
+
if override_sync_exec || override_sync_exec.nil? && !override_async_exec && sync_exec_required? && Config.auto_sync_exec? && !sync_exec_in_progress? && !async_exec_in_progress?
|
147
|
+
sync_exec(&block)
|
148
|
+
elsif override_async_exec || override_async_exec.to_s == 'unless_in_progress' && !async_exec_in_progress?
|
149
|
+
async_exec(&block)
|
150
|
+
else
|
151
|
+
block.call
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
95
155
|
def on_widget_disposed(&block)
|
96
156
|
on_swt_Dispose(&block)
|
97
157
|
end
|