glimmer-dsl-swt 4.18.5.0 → 4.18.5.5

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/README.md +16 -11
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +179 -33
  6. data/docs/reference/GLIMMER_SAMPLES.md +58 -0
  7. data/glimmer-dsl-swt.gemspec +7 -7
  8. data/lib/glimmer/data_binding/widget_binding.rb +4 -1
  9. data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
  10. data/lib/glimmer/dsl/swt/dsl.rb +1 -0
  11. data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
  12. data/lib/glimmer/dsl/swt/shape_expression.rb +1 -1
  13. data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
  14. data/lib/glimmer/swt/custom/drawable.rb +10 -2
  15. data/lib/glimmer/swt/custom/shape.rb +458 -58
  16. data/lib/glimmer/swt/custom/shape/arc.rb +35 -0
  17. data/lib/glimmer/swt/custom/shape/focus.rb +2 -2
  18. data/lib/glimmer/swt/custom/shape/image.rb +35 -9
  19. data/lib/glimmer/swt/custom/shape/line.rb +88 -4
  20. data/lib/glimmer/swt/custom/shape/oval.rb +18 -0
  21. data/lib/glimmer/swt/custom/shape/point.rb +10 -5
  22. data/lib/glimmer/swt/custom/shape/polygon.rb +105 -15
  23. data/lib/glimmer/swt/custom/shape/polyline.rb +88 -15
  24. data/lib/glimmer/swt/custom/shape/rectangle.rb +19 -0
  25. data/lib/glimmer/swt/custom/shape/text.rb +13 -3
  26. data/lib/glimmer/swt/{directory_dialog_proxy.rb → dialog_proxy.rb} +36 -7
  27. data/lib/glimmer/swt/font_proxy.rb +12 -6
  28. data/lib/glimmer/swt/message_box_proxy.rb +1 -0
  29. data/lib/glimmer/swt/properties.rb +3 -0
  30. data/lib/glimmer/swt/proxy_properties.rb +145 -0
  31. data/lib/glimmer/swt/transform_proxy.rb +39 -35
  32. data/lib/glimmer/swt/widget_proxy.rb +32 -60
  33. data/samples/elaborate/contact_manager.rb +2 -0
  34. data/samples/elaborate/login.rb +2 -0
  35. data/samples/elaborate/mandelbrot_fractal.rb +1 -0
  36. data/samples/elaborate/meta_sample.rb +1 -0
  37. data/samples/elaborate/tetris.rb +2 -1
  38. data/samples/elaborate/tic_tac_toe.rb +2 -0
  39. data/samples/elaborate/user_profile.rb +10 -8
  40. data/samples/hello/hello_browser.rb +2 -0
  41. data/samples/hello/hello_button.rb +2 -0
  42. data/samples/hello/hello_canvas.rb +157 -77
  43. data/samples/hello/hello_canvas_animation.rb +2 -0
  44. data/samples/hello/hello_canvas_transform.rb +2 -0
  45. data/samples/hello/hello_checkbox.rb +2 -0
  46. data/samples/hello/hello_checkbox_group.rb +2 -0
  47. data/samples/hello/hello_code_text.rb +2 -0
  48. data/{lib/glimmer/dsl/swt/directory_dialog_expression.rb → samples/hello/hello_color_dialog.rb} +44 -24
  49. data/samples/hello/hello_combo.rb +2 -0
  50. data/samples/hello/hello_computed.rb +2 -0
  51. data/samples/hello/hello_cursor.rb +2 -0
  52. data/samples/hello/hello_custom_shell.rb +1 -0
  53. data/samples/hello/hello_custom_widget.rb +2 -0
  54. data/samples/hello/hello_date_time.rb +2 -0
  55. data/samples/hello/hello_dialog.rb +2 -0
  56. data/samples/hello/hello_directory_dialog.rb +2 -0
  57. data/samples/hello/hello_drag_and_drop.rb +5 -3
  58. data/samples/hello/hello_expand_bar.rb +2 -0
  59. data/samples/hello/hello_file_dialog.rb +2 -0
  60. data/samples/hello/hello_font_dialog.rb +84 -0
  61. data/samples/hello/hello_group.rb +2 -0
  62. data/samples/hello/hello_link.rb +2 -0
  63. data/samples/hello/hello_list_multi_selection.rb +2 -0
  64. data/samples/hello/hello_list_single_selection.rb +2 -0
  65. data/samples/hello/hello_menu_bar.rb +2 -0
  66. data/samples/hello/hello_message_box.rb +2 -0
  67. data/samples/hello/hello_pop_up_context_menu.rb +2 -0
  68. data/samples/hello/hello_progress_bar.rb +2 -0
  69. data/samples/hello/hello_radio.rb +2 -0
  70. data/samples/hello/hello_radio_group.rb +2 -0
  71. data/samples/hello/hello_sash_form.rb +2 -0
  72. data/samples/hello/hello_spinner.rb +2 -0
  73. data/samples/hello/hello_styled_text.rb +19 -17
  74. data/samples/hello/hello_tab.rb +2 -0
  75. data/samples/hello/hello_table.rb +2 -0
  76. data/samples/hello/hello_world.rb +2 -0
  77. metadata +6 -6
  78. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +0 -48
  79. data/lib/glimmer/swt/file_dialog_proxy.rb +0 -68
@@ -36,6 +36,41 @@ module Glimmer
36
36
  def parameter_names
37
37
  [:x, :y, :width, :height, :start_angle, :arc_angle]
38
38
  end
39
+
40
+ def bounds
41
+ shape_bounds = geometry.getBounds2D
42
+ org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
43
+ end
44
+
45
+ def size
46
+ shape_bounds = geometry.getBounds2D
47
+ org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
48
+ end
49
+
50
+ def geometry
51
+ java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
52
+ end
53
+
54
+ # checks if shape contains the point denoted by x and y
55
+ def contain?(x, y)
56
+ geometry.contains(x, y)
57
+ end
58
+
59
+ def include?(x, y)
60
+ if filled?
61
+ contain?(x, y)
62
+ else
63
+ # give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
64
+ outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width + 3, calculated_height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
65
+ inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width - 3, calculated_height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
66
+ outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
67
+ end
68
+ end
69
+
70
+ def irregular?
71
+ true
72
+ end
73
+
39
74
  end
40
75
  end
41
76
  end
@@ -29,9 +29,9 @@ require 'glimmer/swt/transform_proxy'
29
29
  module Glimmer
30
30
  module SWT
31
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
32
  class Shape
33
+ # Represents a focus shape to be drawn on a control/widget/canvas/display
34
+ # Helps highlight focus on another selected shape
35
35
  class Focus < Shape
36
36
  def parameter_names
37
37
  [:x, :y, :width, :height]
@@ -62,20 +62,46 @@ module Glimmer
62
62
  end
63
63
  end
64
64
 
65
- def include?(x, y)
66
- self_x = dest_x || self.x
67
- self_y = dest_y || self.y
68
- width = dest_width || image.bounds.width
69
- height = dest_height || image.bounds.height
70
- x.between?(self_x, self_x + width) && y.between?(self_y, self_y + height)
65
+ def x
66
+ dest_x || get_attribute('x')
71
67
  end
72
-
68
+
69
+ def y
70
+ dest_y || get_attribute('y')
71
+ end
72
+
73
+ def width
74
+ dest_width || image.bounds.width
75
+ end
76
+
77
+ def height
78
+ dest_height || image.bounds.height
79
+ end
80
+
81
+ def default_x?
82
+ super ||
83
+ current_parameter_name?(:dest_x) && (dest_x.nil? || dest_x.to_s == 'default')
84
+ end
85
+
86
+ def default_y?
87
+ super ||
88
+ current_parameter_name?(:dest_y) && (dest_y.nil? || dest_y.to_s == 'default')
89
+ end
90
+
73
91
  def move_by(x_delta, y_delta)
74
- if dest_x
92
+ if default_x?
93
+ self.default_x_delta += x_delta
94
+ elsif dest_x
75
95
  self.dest_x += x_delta
76
- self.dest_y += y_delta
77
96
  else
78
97
  self.x += x_delta
98
+ end
99
+
100
+ if default_y?
101
+ self.default_y_delta += y_delta
102
+ elsif dest_y
103
+ self.dest_y += y_delta
104
+ else
79
105
  self.y += y_delta
80
106
  end
81
107
  end
@@ -33,17 +33,96 @@ module Glimmer
33
33
  # That is because Shape is drawn on a parent as graphics and doesn't have an SWT widget for itself
34
34
  class Shape
35
35
  class Line < Shape
36
+ class << self
37
+ def include?(x1, y1, x2, y2, x, y)
38
+ distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
39
+ distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
40
+ distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
41
+ (distance1 + distance2).to_i == distance.to_i
42
+ end
43
+ end
44
+
36
45
  def parameter_names
37
46
  [:x1, :y1, :x2, :y2]
38
47
  end
39
48
 
49
+ def location_parameter_names
50
+ parameter_names
51
+ end
52
+
53
+ def bounds
54
+ shape_bounds = geometry.getBounds2D
55
+ org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
56
+ end
57
+
58
+ def size
59
+ shape_bounds = geometry.getBounds2D
60
+ org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
61
+ end
62
+
63
+ def geometry
64
+ java.awt.geom.Line2D::Double.new(absolute_x1, absolute_y1, absolute_x2, absolute_y2)
65
+ end
66
+
67
+ # Logical x coordinate relative to parent
68
+ def x
69
+ x_value = bounds.x
70
+ x_value -= parent.absolute_x if parent.is_a?(Shape)
71
+ x_value
72
+ end
73
+
74
+ # Logical y coordinate relative to parent
75
+ def y
76
+ y_value = bounds.y
77
+ y_value -= parent.absolute_y if parent.is_a?(Shape)
78
+ y_value
79
+ end
80
+
81
+ def width
82
+ bounds.width
83
+ end
84
+
85
+ def height
86
+ bounds.height
87
+ end
88
+
89
+ def absolute_x1
90
+ if parent.is_a?(Shape)
91
+ parent.absolute_x + x1
92
+ else
93
+ x1
94
+ end
95
+ end
96
+
97
+ def absolute_y1
98
+ if parent.is_a?(Shape)
99
+ parent.absolute_y + y1
100
+ else
101
+ y1
102
+ end
103
+ end
104
+
105
+ def absolute_x2
106
+ if parent.is_a?(Shape)
107
+ parent.absolute_x + x2
108
+ else
109
+ x2
110
+ end
111
+ end
112
+
113
+ def absolute_y2
114
+ if parent.is_a?(Shape)
115
+ parent.absolute_y + y1
116
+ else
117
+ y2
118
+ end
119
+ end
120
+
40
121
  def include?(x, y)
41
122
  # TODO must account for line width
42
- distance1 = Math.sqrt((x - x1)**2 + (y - y1)**2)
43
- distance2 = Math.sqrt((x2 - x)**2 + (y2 - y)**2)
44
- distance = Math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
45
- (distance1 + distance2).to_i == distance.to_i
123
+ Line.include?(absolute_x1, absolute_y1, absolute_x2, absolute_y2, x, y)
46
124
  end
125
+ alias contain? include?
47
126
 
48
127
  def move_by(x_delta, y_delta)
49
128
  self.x1 += x_delta
@@ -51,6 +130,11 @@ module Glimmer
51
130
  self.x2 += x_delta
52
131
  self.y2 += y_delta
53
132
  end
133
+
134
+ def irregular?
135
+ true
136
+ end
137
+
54
138
  end
55
139
  end
56
140
  end
@@ -36,6 +36,24 @@ module Glimmer
36
36
  def parameter_names
37
37
  [:x, :y, :width, :height]
38
38
  end
39
+
40
+ # checks if shape contains the point denoted by x and y
41
+ def contain?(x, y)
42
+ shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height)
43
+ shape_geometry.contains(x, y)
44
+ end
45
+
46
+ # checks if drawn or filled oval includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
47
+ def include?(x, y)
48
+ if filled?
49
+ contain?(x, y)
50
+ else
51
+ # give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
52
+ outer_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x - 3, self.absolute_y - 3, calculated_width + 6, calculated_height + 6)
53
+ inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_y + 3, calculated_width - 6, calculated_height - 6)
54
+ outer_shape_geometry.contains(x, y) && !inner_shape_geometry.contains(x, y)
55
+ end
56
+ end
39
57
  end
40
58
  end
41
59
  end
@@ -37,14 +37,19 @@ module Glimmer
37
37
  [:x, :y]
38
38
  end
39
39
 
40
- def include?(x, y)
41
- x.to_i.between?(self.x.to_i - 2, self.x.to_i + 2) && y.to_i.between?(self.y.to_i - 2, self.y.to_i + 2)
40
+ def width
41
+ 1
42
+ end
43
+
44
+ def height
45
+ 1
42
46
  end
43
47
 
44
- def move_by(x_delta, y_delta)
45
- self.x += x_delta
46
- self.y += y_delta
48
+ def include?(x, y)
49
+ # give it some fuzz (helps makes mouse clicking easier)
50
+ x.to_i.between?(self.absolute_x.to_i - 2, self.absolute_x.to_i + 2) && y.to_i.between?(self.absolute_y.to_i - 2, self.absolute_y.to_i + 2)
47
51
  end
52
+ alias contain? include?
48
53
  end
49
54
  end
50
55
  end
@@ -37,35 +37,125 @@ module Glimmer
37
37
  [:point_array]
38
38
  end
39
39
 
40
- def size
41
- point_array.size / 2
40
+ def location_parameter_names
41
+ parameter_names
42
+ end
43
+
44
+ def point_count
45
+ point_array.count / 2
42
46
  end
43
47
 
44
48
  def [](index)
45
- index = 0 if index == size
49
+ index = 0 if index == point_count
46
50
  org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
47
51
  end
48
52
 
49
- def include?(x, y)
50
- c = false
51
- i = -1
52
- j = self.size
53
- while (i += 1) < (self.size + 1)
54
- if ((self[i].y <= y && y < self[j].y) ||
55
- (self[j].y <= y && y < self[i].y))
56
- if (x < (self[j].x - self[i].x) * (y - self[i].y) /
57
- (self[j].y - self[i].y) + self[i].x)
58
- c = !c
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
+ def absolute_point_array
66
+ if parent.is_a?(Shape)
67
+ point_array.each_with_index.map do |coordinate, i|
68
+ if i.even?
69
+ parent.absolute_x + coordinate
70
+ else
71
+ parent.absolute_y + coordinate
59
72
  end
60
- j = i
61
73
  end
74
+ else
75
+ point_array
62
76
  end
63
- c
64
77
  end
65
78
 
79
+ def absolute_x_array
80
+ absolute_point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
81
+ end
82
+
83
+ def absolute_y_array
84
+ absolute_point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
85
+ end
86
+
87
+ def absolute_point_xy_array
88
+ absolute_x_array.zip(absolute_y_array)
89
+ end
90
+
91
+ def bounds
92
+ the_point_array = point_array
93
+ if the_point_array != @bounds_point_array
94
+ @bounds_point_array = point_array
95
+ shape_bounds = geometry.getBounds2D
96
+ @bounds = org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
97
+ end
98
+ @bounds
99
+ end
100
+
101
+ def size
102
+ the_point_array = point_array
103
+ if the_point_array != @size_point_array
104
+ @size_point_array = point_array
105
+ shape_bounds = geometry.getBounds2D
106
+ @size = org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
107
+ end
108
+ @size
109
+ end
110
+
111
+ def geometry
112
+ the_point_array = point_array
113
+ if the_point_array != @geometry_point_array
114
+ @geometry_point_array = point_array
115
+ @geometry = java.awt.Polygon.new(absolute_x_array.to_java(:int), absolute_y_array.to_java(:int), point_count)
116
+ end
117
+ @geometry
118
+ end
119
+
120
+ # Logical x coordinate relative to parent
121
+ def x
122
+ x_value = bounds.x
123
+ x_value -= parent.absolute_x if parent.is_a?(Shape)
124
+ x_value
125
+ end
126
+
127
+ # Logical y coordinate relative to parent
128
+ def y
129
+ y_value = bounds.y
130
+ y_value -= parent.absolute_y if parent.is_a?(Shape)
131
+ y_value
132
+ end
133
+
134
+ def width
135
+ bounds.width
136
+ end
137
+
138
+ def height
139
+ bounds.height
140
+ end
141
+
142
+ def contain?(x, y)
143
+ geometry.contains(x, y)
144
+ end
145
+
146
+ def include?(x, y)
147
+ comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
148
+ comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
149
+ end
150
+
66
151
  def move_by(x_delta, y_delta)
67
152
  self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
68
153
  end
154
+
155
+ def irregular?
156
+ true
157
+ end
158
+
69
159
  end
70
160
  end
71
161
  end
@@ -37,35 +37,108 @@ module Glimmer
37
37
  [:point_array]
38
38
  end
39
39
 
40
- def size
41
- point_array.size / 2
40
+ def location_parameter_names
41
+ parameter_names
42
+ end
43
+
44
+ def point_count
45
+ point_array.count / 2
42
46
  end
43
47
 
44
48
  def [](index)
45
- index = 0 if index == size
49
+ index = 0 if index == point_count
46
50
  org.eclipse.swt.graphics.Point.new(point_array[index * 2], point_array[index * 2 + 1])
47
51
  end
48
52
 
49
- def include?(x, y)
50
- c = false
51
- i = -1
52
- j = self.size
53
- while (i += 1) < (self.size + 1)
54
- if ((self[i].y <= y && y < self[j].y) ||
55
- (self[j].y <= y && y < self[i].y))
56
- if (x < (self[j].x - self[i].x) * (y - self[i].y) /
57
- (self[j].y - self[i].y) + self[i].x)
58
- c = !c
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
+ def absolute_point_array
66
+ if parent.is_a?(Shape)
67
+ point_array.each_with_index.map do |coordinate, i|
68
+ if i.even?
69
+ parent.absolute_x + coordinate
70
+ else
71
+ parent.absolute_y + coordinate
59
72
  end
60
- j = i
61
73
  end
74
+ else
75
+ point_array
62
76
  end
63
- c
64
77
  end
65
78
 
79
+ def absolute_x_array
80
+ absolute_point_array.each_with_index.select {|pair| pair.last.even?}.map(&:first)
81
+ end
82
+
83
+ def absolute_y_array
84
+ absolute_point_array.each_with_index.select {|pair| pair.last.odd?}.map(&:first)
85
+ end
86
+
87
+ def absolute_point_xy_array
88
+ absolute_x_array.zip(absolute_y_array)
89
+ end
90
+
91
+ def bounds
92
+ shape_bounds = geometry.getBounds2D
93
+ org.eclipse.swt.graphics.Rectangle.new(shape_bounds.x, shape_bounds.y, shape_bounds.width, shape_bounds.height)
94
+ end
95
+
96
+ def size
97
+ shape_bounds = geometry.getBounds2D
98
+ org.eclipse.swt.graphics.Point.new(shape_bounds.width, shape_bounds.height)
99
+ end
100
+
101
+ def geometry
102
+ java.awt.Polygon.new(absolute_x_array.to_java(:int), absolute_y_array.to_java(:int), point_count)
103
+ end
104
+
105
+ # Logical x coordinate relative to parent
106
+ def x
107
+ x_value = bounds.x
108
+ x_value -= parent.absolute_x if parent.is_a?(Shape)
109
+ x_value
110
+ end
111
+
112
+ # Logical y coordinate relative to parent
113
+ def y
114
+ y_value = bounds.y
115
+ y_value -= parent.absolute_y if parent.is_a?(Shape)
116
+ y_value
117
+ end
118
+
119
+ def width
120
+ bounds.width
121
+ end
122
+
123
+ def height
124
+ bounds.height
125
+ end
126
+
127
+ def include?(x, y)
128
+ comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
129
+ comparison_lines.pop # ignore last pair since you don't want to compare last point with first point
130
+ comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
131
+ end
132
+ alias contain? include?
133
+
66
134
  def move_by(x_delta, y_delta)
67
135
  self.point_array = point_array.each_with_index.map {|coordinate, i| i.even? ? coordinate + x_delta : coordinate + y_delta}
68
136
  end
137
+
138
+ def irregular?
139
+ true
140
+ end
141
+
69
142
  end
70
143
  end
71
144
  end