glimmer-dsl-swt 4.18.4.3 → 4.18.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/LICENSE.txt +20 -20
  4. data/README.md +76 -60
  5. data/RUBY_VERSION +1 -1
  6. data/VERSION +1 -1
  7. data/bin/girb +31 -31
  8. data/bin/girb_runner.rb +34 -34
  9. data/bin/glimmer +26 -26
  10. data/glimmer-dsl-swt.gemspec +9 -9
  11. data/lib/ext/glimmer.rb +41 -41
  12. data/lib/ext/glimmer/config.rb +167 -167
  13. data/lib/ext/rouge/themes/glimmer.rb +29 -29
  14. data/lib/glimmer-dsl-swt.rb +44 -44
  15. data/lib/glimmer/Rakefile +26 -26
  16. data/lib/glimmer/data_binding/list_selection_binding.rb +72 -72
  17. data/lib/glimmer/data_binding/observable_widget.rb +38 -38
  18. data/lib/glimmer/data_binding/shine.rb +44 -44
  19. data/lib/glimmer/data_binding/table_items_binding.rb +89 -89
  20. data/lib/glimmer/data_binding/tree_items_binding.rb +108 -108
  21. data/lib/glimmer/data_binding/widget_binding.rb +73 -73
  22. data/lib/glimmer/dsl/swt/animation_expression.rb +43 -43
  23. data/lib/glimmer/dsl/swt/async_exec_expression.rb +35 -35
  24. data/lib/glimmer/dsl/swt/bind_expression.rb +58 -58
  25. data/lib/glimmer/dsl/swt/block_property_expression.rb +41 -41
  26. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -61
  27. data/lib/glimmer/dsl/swt/color_expression.rb +40 -40
  28. data/lib/glimmer/dsl/swt/column_properties_expression.rb +45 -45
  29. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +67 -67
  30. data/lib/glimmer/dsl/swt/cursor_expression.rb +44 -44
  31. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
  32. data/lib/glimmer/dsl/swt/data_binding_expression.rb +55 -55
  33. data/lib/glimmer/dsl/swt/dialog_expression.rb +48 -48
  34. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -48
  35. data/lib/glimmer/dsl/swt/display_expression.rb +40 -40
  36. data/lib/glimmer/dsl/swt/dnd_expression.rb +46 -46
  37. data/lib/glimmer/dsl/swt/dsl.rb +63 -63
  38. data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
  39. data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -60
  40. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -48
  41. data/lib/glimmer/dsl/swt/font_expression.rb +49 -49
  42. data/lib/glimmer/dsl/swt/image_expression.rb +50 -50
  43. data/lib/glimmer/dsl/swt/layout_data_expression.rb +46 -46
  44. data/lib/glimmer/dsl/swt/layout_expression.rb +50 -50
  45. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +65 -65
  46. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +54 -54
  47. data/lib/glimmer/dsl/swt/menu_expression.rb +53 -53
  48. data/lib/glimmer/dsl/swt/message_box_expression.rb +54 -54
  49. data/lib/glimmer/dsl/swt/multiply_expression.rb +53 -53
  50. data/lib/glimmer/dsl/swt/observe_expression.rb +53 -53
  51. data/lib/glimmer/dsl/swt/property_expression.rb +46 -46
  52. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +61 -61
  53. data/lib/glimmer/dsl/swt/rgb_expression.rb +33 -33
  54. data/lib/glimmer/dsl/swt/rgba_expression.rb +33 -33
  55. data/lib/glimmer/dsl/swt/shape_expression.rb +54 -54
  56. data/lib/glimmer/dsl/swt/shell_expression.rb +46 -46
  57. data/lib/glimmer/dsl/swt/swt_expression.rb +46 -46
  58. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +36 -36
  59. data/lib/glimmer/dsl/swt/tab_item_expression.rb +54 -54
  60. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +52 -52
  61. data/lib/glimmer/dsl/swt/timer_exec_expression.rb +35 -0
  62. data/lib/glimmer/dsl/swt/transform_expression.rb +55 -55
  63. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +52 -52
  64. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +47 -47
  65. data/lib/glimmer/dsl/swt/widget_expression.rb +66 -66
  66. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +53 -53
  67. data/lib/glimmer/rake_task.rb +220 -220
  68. data/lib/glimmer/rake_task/list.rb +97 -97
  69. data/lib/glimmer/rake_task/package.rb +139 -139
  70. data/lib/glimmer/rake_task/scaffold.rb +765 -765
  71. data/lib/glimmer/swt/color_proxy.rb +107 -107
  72. data/lib/glimmer/swt/cursor_proxy.rb +66 -66
  73. data/lib/glimmer/swt/custom/animation.rb +243 -243
  74. data/lib/glimmer/swt/custom/checkbox_group.rb +181 -181
  75. data/lib/glimmer/swt/custom/code_text.rb +23 -20
  76. data/lib/glimmer/swt/custom/drawable.rb +49 -49
  77. data/lib/glimmer/swt/custom/radio_group.rb +176 -176
  78. data/lib/glimmer/swt/custom/shape.rb +297 -297
  79. data/lib/glimmer/swt/date_time_proxy.rb +85 -85
  80. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -65
  81. data/lib/glimmer/swt/display_proxy.rb +166 -166
  82. data/lib/glimmer/swt/dnd_proxy.rb +51 -51
  83. data/lib/glimmer/swt/expand_item_proxy.rb +97 -97
  84. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -66
  85. data/lib/glimmer/swt/font_proxy.rb +94 -94
  86. data/lib/glimmer/swt/image_proxy.rb +184 -184
  87. data/lib/glimmer/swt/layout_data_proxy.rb +105 -105
  88. data/lib/glimmer/swt/layout_proxy.rb +112 -112
  89. data/lib/glimmer/swt/menu_proxy.rb +126 -126
  90. data/lib/glimmer/swt/message_box_proxy.rb +89 -89
  91. data/lib/glimmer/swt/packages.rb +37 -37
  92. data/lib/glimmer/swt/properties.rb +49 -49
  93. data/lib/glimmer/swt/sash_form_proxy.rb +53 -53
  94. data/lib/glimmer/swt/scrolled_composite_proxy.rb +37 -37
  95. data/lib/glimmer/swt/style_constantizable.rb +157 -157
  96. data/lib/glimmer/swt/styled_text_proxy.rb +38 -38
  97. data/lib/glimmer/swt/swt_proxy.rb +59 -59
  98. data/lib/glimmer/swt/tab_item_proxy.rb +91 -91
  99. data/lib/glimmer/swt/table_column_proxy.rb +57 -57
  100. data/lib/glimmer/swt/transform_proxy.rb +109 -109
  101. data/lib/glimmer/swt/tree_proxy.rb +145 -145
  102. data/lib/glimmer/swt/widget_listener_proxy.rb +64 -64
  103. data/lib/glimmer/swt/widget_proxy.rb +957 -957
  104. data/lib/glimmer/ui/custom_shell.rb +82 -82
  105. data/lib/glimmer/ui/custom_widget.rb +315 -315
  106. data/lib/glimmer/util/proc_tracker.rb +39 -39
  107. data/samples/elaborate/contact_manager.rb +142 -142
  108. data/samples/elaborate/contact_manager/contact.rb +32 -32
  109. data/samples/elaborate/contact_manager/contact_manager_presenter.rb +47 -47
  110. data/samples/elaborate/contact_manager/contact_repository.rb +169 -169
  111. data/samples/elaborate/login.rb +123 -123
  112. data/samples/elaborate/meta_sample.rb +1 -1
  113. data/samples/elaborate/tetris/model/block.rb +48 -48
  114. data/samples/elaborate/tetris/model/past_game.rb +39 -39
  115. data/samples/elaborate/tic_tac_toe.rb +76 -76
  116. data/samples/elaborate/tic_tac_toe/board.rb +145 -145
  117. data/samples/elaborate/tic_tac_toe/cell.rb +48 -48
  118. data/samples/elaborate/user_profile.rb +76 -76
  119. data/samples/hello/hello_browser.rb +31 -31
  120. data/samples/hello/hello_button.rb +46 -46
  121. data/samples/hello/hello_canvas.rb +64 -64
  122. data/samples/hello/hello_canvas_transform.rb +1 -1
  123. data/samples/hello/hello_checkbox.rb +85 -85
  124. data/samples/hello/hello_checkbox_group.rb +71 -71
  125. data/samples/hello/hello_code_text.rb +104 -104
  126. data/samples/hello/hello_combo.rb +63 -63
  127. data/samples/hello/hello_computed.rb +96 -96
  128. data/samples/hello/hello_computed/contact.rb +42 -42
  129. data/samples/hello/hello_custom_shell.rb +155 -155
  130. data/samples/hello/hello_custom_widget.rb +86 -86
  131. data/samples/hello/hello_date_time.rb +63 -63
  132. data/samples/hello/hello_dialog.rb +78 -78
  133. data/samples/hello/hello_directory_dialog.rb +60 -60
  134. data/samples/hello/hello_drag_and_drop.rb +50 -50
  135. data/samples/hello/hello_expand_bar.rb +110 -110
  136. data/samples/hello/hello_file_dialog.rb +60 -60
  137. data/samples/hello/hello_group.rb +104 -104
  138. data/samples/hello/hello_link.rb +80 -80
  139. data/samples/hello/hello_list_multi_selection.rb +74 -74
  140. data/samples/hello/hello_list_single_selection.rb +59 -59
  141. data/samples/hello/hello_menu_bar.rb +241 -241
  142. data/samples/hello/hello_message_box.rb +37 -37
  143. data/samples/hello/hello_pop_up_context_menu.rb +84 -84
  144. data/samples/hello/hello_radio.rb +108 -108
  145. data/samples/hello/hello_radio_group.rb +87 -87
  146. data/samples/hello/hello_sash_form.rb +137 -137
  147. data/samples/hello/hello_spinner.rb +69 -69
  148. data/samples/hello/hello_styled_text.rb +138 -138
  149. data/samples/hello/hello_tab.rb +50 -50
  150. data/samples/hello/hello_world.rb +29 -29
  151. metadata +6 -6
  152. data/samples/elaborate/meta_sample/meta_sample_logo.png +0 -0
  153. data/samples/hello/hello_canvas_transform/hello_canvas_transform_image.png +0 -0
@@ -1,107 +1,107 @@
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/display_proxy'
24
-
25
- module Glimmer
26
- module SWT
27
- # Proxy for org.eclipse.swt.graphics.Color
28
- #
29
- # Invoking `#swt_color` returns the SWT Color object wrapped by this proxy
30
- #
31
- # Follows the Proxy Design Pattern and Flyweight Design Pattern (caching memoization)
32
- class ColorProxy
33
- include_package 'org.eclipse.swt.graphics'
34
-
35
- class << self
36
- def flyweight(*args)
37
- flyweight_color_proxies[args] ||= new(*args)
38
- end
39
-
40
- # Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
41
- def flyweight_color_proxies
42
- @flyweight_color_proxies ||= {}
43
- end
44
- end
45
-
46
- # Initializes a proxy for an SWT Color object
47
- #
48
- # Takes a standard color single argument, rgba 3 args, or rgba 4 args
49
- #
50
- # A standard color is a string/symbol representing one of the
51
- # SWT.COLOR_*** constants like SWT.COLOR_RED, but in underscored string
52
- # format (e.g :color_red).
53
- # Glimmer can also accept standard color names without the color_ prefix,
54
- # and it will automatically figure out the SWT.COLOR_*** constant
55
- # (e.g. :red)
56
- #
57
- # rgb is 3 arguments representing Red, Green, Blue numeric values
58
- #
59
- # rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
60
- #
61
- def initialize(*args)
62
- @args = args
63
- ensure_arg_values_within_valid_bounds
64
- end
65
-
66
- def swt_color
67
- unless @swt_color
68
- case @args.size
69
- when 1
70
- if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
71
- standard_color = @args.first
72
- standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
73
- @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
74
- else
75
- @swt_color = @args.first
76
- end
77
- when 3..4
78
- red, green, blue, alpha = @args
79
- @swt_color = Color.new(*[red, green, blue, alpha].compact)
80
- end
81
- end
82
- @swt_color
83
- end
84
-
85
- def method_missing(method, *args, &block)
86
- swt_color.send(method, *args, &block)
87
- rescue => e
88
- Glimmer::Config.logger.debug {"Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"}
89
- super
90
- end
91
-
92
- def respond_to?(method, *args, &block)
93
- super || swt_color.respond_to?(method, *args, &block)
94
- end
95
-
96
- private
97
-
98
- def ensure_arg_values_within_valid_bounds
99
- if @args.to_a.size >= 3
100
- @args = @args.map do |value|
101
- [[value, 255].min, 0].max
102
- end
103
- end
104
- end
105
- end
106
- end
107
- end
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/display_proxy'
24
+
25
+ module Glimmer
26
+ module SWT
27
+ # Proxy for org.eclipse.swt.graphics.Color
28
+ #
29
+ # Invoking `#swt_color` returns the SWT Color object wrapped by this proxy
30
+ #
31
+ # Follows the Proxy Design Pattern and Flyweight Design Pattern (caching memoization)
32
+ class ColorProxy
33
+ include_package 'org.eclipse.swt.graphics'
34
+
35
+ class << self
36
+ def flyweight(*args)
37
+ flyweight_color_proxies[args] ||= new(*args)
38
+ end
39
+
40
+ # Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
41
+ def flyweight_color_proxies
42
+ @flyweight_color_proxies ||= {}
43
+ end
44
+ end
45
+
46
+ # Initializes a proxy for an SWT Color object
47
+ #
48
+ # Takes a standard color single argument, rgba 3 args, or rgba 4 args
49
+ #
50
+ # A standard color is a string/symbol representing one of the
51
+ # SWT.COLOR_*** constants like SWT.COLOR_RED, but in underscored string
52
+ # format (e.g :color_red).
53
+ # Glimmer can also accept standard color names without the color_ prefix,
54
+ # and it will automatically figure out the SWT.COLOR_*** constant
55
+ # (e.g. :red)
56
+ #
57
+ # rgb is 3 arguments representing Red, Green, Blue numeric values
58
+ #
59
+ # rgba is 4 arguments representing Red, Green, Blue, and Alpha numeric values
60
+ #
61
+ def initialize(*args)
62
+ @args = args
63
+ ensure_arg_values_within_valid_bounds
64
+ end
65
+
66
+ def swt_color
67
+ unless @swt_color
68
+ case @args.size
69
+ when 1
70
+ if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
71
+ standard_color = @args.first
72
+ standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
73
+ @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
74
+ else
75
+ @swt_color = @args.first
76
+ end
77
+ when 3..4
78
+ red, green, blue, alpha = @args
79
+ @swt_color = Color.new(*[red, green, blue, alpha].compact)
80
+ end
81
+ end
82
+ @swt_color
83
+ end
84
+
85
+ def method_missing(method, *args, &block)
86
+ swt_color.send(method, *args, &block)
87
+ rescue => e
88
+ Glimmer::Config.logger.debug {"Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"}
89
+ super
90
+ end
91
+
92
+ def respond_to?(method, *args, &block)
93
+ super || swt_color.respond_to?(method, *args, &block)
94
+ end
95
+
96
+ private
97
+
98
+ def ensure_arg_values_within_valid_bounds
99
+ if @args.to_a.size >= 3
100
+ @args = @args.map do |value|
101
+ [[value, 255].min, 0].max
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -1,66 +1,66 @@
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/error'
23
- require 'glimmer/swt/swt_proxy'
24
- require 'glimmer/swt/display_proxy'
25
-
26
- module Glimmer
27
- module SWT
28
- # Proxy for org.eclipse.swt.graphics.Cursor
29
- #
30
- # Invoking `#swt_cursor` returns the SWT Cursor object wrapped by this proxy
31
- #
32
- # Follows the Proxy Design Pattern
33
- class CursorProxy
34
- CURSOR_STYLES = org.eclipse.swt.SWT.constants.select {|c| c.to_s.downcase.start_with?('cursor_')}.map {|c| c.to_s.downcase.sub('cursor_', '').to_sym}
35
- ERROR_INVALID_CURSOR_STYLE = " is an invalid cursor style! Valid values are #{CURSOR_STYLES.map(&:to_s).join(", ")}"
36
-
37
- include_package 'org.eclipse.swt.graphics'
38
-
39
- attr_reader :swt_cursor, :cursor_style
40
-
41
- # Builds a new CursorProxy from passed in cursor SWT style (e.g. :appstarting, :hand, or :help)
42
- #
43
- # Cursor SWT styles are those that begin with "CURSOR_" prefix
44
- #
45
- # They are expected to be passed in in short form without the prefix (but would work with the prefix too)
46
- def initialize(cursor_style)
47
- @cursor_style = cursor_style
48
- @cursor_style = SWTProxy.reverse_lookup(@cursor_style).detect { |symbol| symbol.to_s.downcase.start_with?('cursor_') } if cursor_style.is_a?(Integer)
49
- @cursor_style = @cursor_style.to_s.downcase
50
- @cursor_style = @cursor_style.sub(/^cursor\_/, '') if @cursor_style.start_with?('cursor_')
51
- detect_invalid_cursor_style
52
- @swt_cursor = DisplayProxy.instance.swt_display.get_system_cursor(SWTProxy[swt_style])
53
- end
54
-
55
- def swt_style
56
- @swt_style ||= @cursor_style.upcase.start_with?('CURSOR_') ? @cursor_style : "CURSOR_#{@cursor_style}"
57
- end
58
-
59
- private
60
-
61
- def detect_invalid_cursor_style
62
- raise Error, cursor_style.to_s + ERROR_INVALID_CURSOR_STYLE unless CURSOR_STYLES.include?(cursor_style.to_s.downcase.to_sym)
63
- end
64
- end
65
- end
66
- end
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/error'
23
+ require 'glimmer/swt/swt_proxy'
24
+ require 'glimmer/swt/display_proxy'
25
+
26
+ module Glimmer
27
+ module SWT
28
+ # Proxy for org.eclipse.swt.graphics.Cursor
29
+ #
30
+ # Invoking `#swt_cursor` returns the SWT Cursor object wrapped by this proxy
31
+ #
32
+ # Follows the Proxy Design Pattern
33
+ class CursorProxy
34
+ CURSOR_STYLES = org.eclipse.swt.SWT.constants.select {|c| c.to_s.downcase.start_with?('cursor_')}.map {|c| c.to_s.downcase.sub('cursor_', '').to_sym}
35
+ ERROR_INVALID_CURSOR_STYLE = " is an invalid cursor style! Valid values are #{CURSOR_STYLES.map(&:to_s).join(", ")}"
36
+
37
+ include_package 'org.eclipse.swt.graphics'
38
+
39
+ attr_reader :swt_cursor, :cursor_style
40
+
41
+ # Builds a new CursorProxy from passed in cursor SWT style (e.g. :appstarting, :hand, or :help)
42
+ #
43
+ # Cursor SWT styles are those that begin with "CURSOR_" prefix
44
+ #
45
+ # They are expected to be passed in in short form without the prefix (but would work with the prefix too)
46
+ def initialize(cursor_style)
47
+ @cursor_style = cursor_style
48
+ @cursor_style = SWTProxy.reverse_lookup(@cursor_style).detect { |symbol| symbol.to_s.downcase.start_with?('cursor_') } if cursor_style.is_a?(Integer)
49
+ @cursor_style = @cursor_style.to_s.downcase
50
+ @cursor_style = @cursor_style.sub(/^cursor\_/, '') if @cursor_style.start_with?('cursor_')
51
+ detect_invalid_cursor_style
52
+ @swt_cursor = DisplayProxy.instance.swt_display.get_system_cursor(SWTProxy[swt_style])
53
+ end
54
+
55
+ def swt_style
56
+ @swt_style ||= @cursor_style.upcase.start_with?('CURSOR_') ? @cursor_style : "CURSOR_#{@cursor_style}"
57
+ end
58
+
59
+ private
60
+
61
+ def detect_invalid_cursor_style
62
+ raise Error, cursor_style.to_s + ERROR_INVALID_CURSOR_STYLE unless CURSOR_STYLES.include?(cursor_style.to_s.downcase.to_sym)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,243 +1,243 @@
1
- # Copyright (c) 2007-2021 Andy Maleh
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining
4
- # a copy of this software and associated documentation files (the
5
- # "Software"), to deal in the Software without restriction, including
6
- # without limitation the rights to use, copy, modify, merge, publish,
7
- # distribute, sublicense, and/or sell copies of the Software, and to
8
- # permit persons to whom the Software is furnished to do so, subject to
9
- # the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be
12
- # included in all copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- require 'glimmer/swt/properties'
23
-
24
- module Glimmer
25
- module SWT
26
- module Custom
27
- # Represents an animation declaratively
28
- class Animation
29
- include Properties # TODO rename to Properties
30
-
31
- class << self
32
- def schedule_frame_animation(animation, &frame_animation_block)
33
- frame_animation_queue(animation).prepend(frame_animation_block)
34
- swt_display.async_exec do
35
- frame_animation_queue(next_animation)&.pop&.call
36
- end
37
- end
38
-
39
- def next_animation
40
- animation = nil
41
- while frame_animation_queues.values.reduce(:+)&.any? && (animation.nil? || frame_animation_queue(animation).last.nil?)
42
- animation = frame_animation_queues.keys[next_animation_index]
43
- frame_animation_queues.delete(animation) if frame_animation_queues.values.reduce(:+)&.any? && !animation.nil? && frame_animation_queue(animation).empty?
44
- end
45
- animation
46
- end
47
-
48
- def next_animation_index
49
- next_schedule_index % frame_animation_queues.keys.size
50
- end
51
-
52
- def next_schedule_index
53
- unless defined? @@next_schedule_index
54
- @@next_schedule_index = 0
55
- else
56
- @@next_schedule_index += 1
57
- end
58
- end
59
-
60
- def frame_animation_queues
61
- unless defined? @@frame_animation_queues
62
- @@frame_animation_queues = {}
63
- end
64
- @@frame_animation_queues
65
- end
66
-
67
- def frame_animation_queue(animation)
68
- frame_animation_queues[animation] ||= []
69
- end
70
-
71
- def swt_display
72
- unless defined? @@swt_display
73
- @@swt_display = DisplayProxy.instance.swt_display
74
- end
75
- @@swt_display
76
- end
77
- end
78
-
79
- attr_reader :parent, :options, :frame_index, :cycle
80
- alias current_frame_index frame_index
81
- attr_accessor :frame_block, :every, :cycle_count, :frame_count, :started, :duration_limit
82
- alias started? started
83
- # TODO consider supporting an async: false option
84
-
85
- def initialize(parent)
86
- @parent = parent
87
- @started = true
88
- @frame_index = 0
89
- @cycle_count_index = 0
90
- @start_number = 0 # denotes the number of starts (increments on every start)
91
- self.class.swt_display # ensures initializing variable to set from GUI thread
92
- end
93
-
94
- def post_add_content
95
- @parent.on_widget_disposed { stop }
96
- start if started?
97
- end
98
-
99
- # Starts an animation that is indefinite or has never been started before (i.e. having `started: false` option).
100
- # Otherwise, resumes a stopped animation that has not been completed.
101
- def start
102
- return if @start_number > 0 && started?
103
- @start_number += 1
104
- @started = true
105
- @start_time = Time.now
106
- @original_start_time = @start_time if @duration.nil?
107
- # TODO track when finished in a variable for finite animations (whether by frame count, cycle count, or duration limit)
108
- Thread.new do
109
- start_number = @start_number
110
- if cycle_count.is_a?(Integer) && cycle.is_a?(Array)
111
- (cycle_count * cycle.length).times do
112
- break unless draw_frame(start_number)
113
- end
114
- else
115
- loop do
116
- # this code has to be duplicated to break from a loop (break keyword only works when literally in a loop block)
117
- break unless draw_frame(start_number)
118
- end
119
- end
120
- end
121
- end
122
-
123
- def stop
124
- return if stopped?
125
- @started = false
126
- @duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
127
- end
128
-
129
- # Restarts an animation (whether indefinite or not and whether stopped or not)
130
- def restart
131
- @original_start_time = @start_time = nil
132
- @duration = nil
133
- @frame_index = 0
134
- @cycle_count_index = 0
135
- stop
136
- start
137
- end
138
-
139
- def stopped?
140
- !started?
141
- end
142
-
143
- def finite?
144
- frame_count_limited? || cycle_limited? || duration_limited?
145
- end
146
-
147
- def infinite?
148
- !finite?
149
- end
150
- alias indefinite? infinite?
151
-
152
- def has_attribute?(attribute_name, *args)
153
- respond_to?(ruby_attribute_setter(attribute_name)) && respond_to?(ruby_attribute_getter(attribute_name))
154
- end
155
-
156
- def set_attribute(attribute_name, *args)
157
- send(ruby_attribute_setter(attribute_name), *args)
158
- end
159
-
160
- def get_attribute(attribute_name)
161
- send(ruby_attribute_getter(attribute_name))
162
- end
163
-
164
- def cycle=(*args)
165
- if args.size == 1
166
- if args.first.is_a?(Array)
167
- @cycle = args.first
168
- else
169
- @cycle = [args.first]
170
- end
171
- elsif args.size > 1
172
- @cycle = args
173
- end
174
- end
175
-
176
- def cycle_enabled?
177
- @cycle.is_a?(Array)
178
- end
179
-
180
- def cycle_limited?
181
- cycle_enabled? && @cycle_count.is_a?(Integer)
182
- end
183
-
184
- def duration_limited?
185
- @duration_limit.is_a?(Integer)
186
- end
187
-
188
- def frame_count_limited?
189
- @frame_count.is_a?(Integer)
190
- end
191
-
192
- def surpassed_duration_limit?
193
- duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
194
- end
195
-
196
- def within_duration_limit?
197
- !surpassed_duration_limit?
198
- end
199
-
200
- private
201
-
202
- # Returns true on success of painting a frame and false otherwise
203
- def draw_frame(start_number)
204
- return false if stopped? ||
205
- start_number != @start_number ||
206
- (frame_count_limited? && @frame_index == @frame_count) ||
207
- (cycle_limited? && @cycle_count_index == @cycle_count) ||
208
- surpassed_duration_limit?
209
- block_args = [@frame_index]
210
- block_args << @cycle[@frame_index % @cycle.length] if cycle_enabled?
211
- current_frame_index = @frame_index
212
- current_cycle_count_index = @cycle_count_index
213
- self.class.schedule_frame_animation(self) do
214
- if started? && start_number == @start_number && within_duration_limit?
215
- @parent.clear_shapes
216
- @parent.content {
217
- frame_block.call(*block_args)
218
- }
219
- @parent.redraw
220
- else
221
- if stopped? && @frame_index > current_frame_index
222
- @started = false
223
- @frame_index = current_frame_index
224
- @cycle_count_index = current_cycle_count_index
225
- end
226
- end
227
- end
228
- @frame_index += 1
229
- @cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
230
- sleep(every) if every.is_a?(Numeric)
231
- true
232
- rescue => e
233
- Glimmer::Config.logger.error {e}
234
- false
235
- end
236
-
237
- end
238
-
239
- end
240
-
241
- end
242
-
243
- end
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer/swt/properties'
23
+
24
+ module Glimmer
25
+ module SWT
26
+ module Custom
27
+ # Represents an animation declaratively
28
+ class Animation
29
+ include Properties # TODO rename to Properties
30
+
31
+ class << self
32
+ def schedule_frame_animation(animation, &frame_animation_block)
33
+ frame_animation_queue(animation).prepend(frame_animation_block)
34
+ swt_display.async_exec do
35
+ frame_animation_queue(next_animation)&.pop&.call
36
+ end
37
+ end
38
+
39
+ def next_animation
40
+ animation = nil
41
+ while frame_animation_queues.values.reduce(:+)&.any? && (animation.nil? || frame_animation_queue(animation).last.nil?)
42
+ animation = frame_animation_queues.keys[next_animation_index]
43
+ frame_animation_queues.delete(animation) if frame_animation_queues.values.reduce(:+)&.any? && !animation.nil? && frame_animation_queue(animation).empty?
44
+ end
45
+ animation
46
+ end
47
+
48
+ def next_animation_index
49
+ next_schedule_index % frame_animation_queues.keys.size
50
+ end
51
+
52
+ def next_schedule_index
53
+ unless defined? @@next_schedule_index
54
+ @@next_schedule_index = 0
55
+ else
56
+ @@next_schedule_index += 1
57
+ end
58
+ end
59
+
60
+ def frame_animation_queues
61
+ unless defined? @@frame_animation_queues
62
+ @@frame_animation_queues = {}
63
+ end
64
+ @@frame_animation_queues
65
+ end
66
+
67
+ def frame_animation_queue(animation)
68
+ frame_animation_queues[animation] ||= []
69
+ end
70
+
71
+ def swt_display
72
+ unless defined? @@swt_display
73
+ @@swt_display = DisplayProxy.instance.swt_display
74
+ end
75
+ @@swt_display
76
+ end
77
+ end
78
+
79
+ attr_reader :parent, :options, :frame_index, :cycle
80
+ alias current_frame_index frame_index
81
+ attr_accessor :frame_block, :every, :cycle_count, :frame_count, :started, :duration_limit
82
+ alias started? started
83
+ # TODO consider supporting an async: false option
84
+
85
+ def initialize(parent)
86
+ @parent = parent
87
+ @started = true
88
+ @frame_index = 0
89
+ @cycle_count_index = 0
90
+ @start_number = 0 # denotes the number of starts (increments on every start)
91
+ self.class.swt_display # ensures initializing variable to set from GUI thread
92
+ end
93
+
94
+ def post_add_content
95
+ @parent.on_widget_disposed { stop }
96
+ start if started?
97
+ end
98
+
99
+ # Starts an animation that is indefinite or has never been started before (i.e. having `started: false` option).
100
+ # Otherwise, resumes a stopped animation that has not been completed.
101
+ def start
102
+ return if @start_number > 0 && started?
103
+ @start_number += 1
104
+ @started = true
105
+ @start_time = Time.now
106
+ @original_start_time = @start_time if @duration.nil?
107
+ # TODO track when finished in a variable for finite animations (whether by frame count, cycle count, or duration limit)
108
+ Thread.new do
109
+ start_number = @start_number
110
+ if cycle_count.is_a?(Integer) && cycle.is_a?(Array)
111
+ (cycle_count * cycle.length).times do
112
+ break unless draw_frame(start_number)
113
+ end
114
+ else
115
+ loop do
116
+ # this code has to be duplicated to break from a loop (break keyword only works when literally in a loop block)
117
+ break unless draw_frame(start_number)
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ def stop
124
+ return if stopped?
125
+ @started = false
126
+ @duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
127
+ end
128
+
129
+ # Restarts an animation (whether indefinite or not and whether stopped or not)
130
+ def restart
131
+ @original_start_time = @start_time = nil
132
+ @duration = nil
133
+ @frame_index = 0
134
+ @cycle_count_index = 0
135
+ stop
136
+ start
137
+ end
138
+
139
+ def stopped?
140
+ !started?
141
+ end
142
+
143
+ def finite?
144
+ frame_count_limited? || cycle_limited? || duration_limited?
145
+ end
146
+
147
+ def infinite?
148
+ !finite?
149
+ end
150
+ alias indefinite? infinite?
151
+
152
+ def has_attribute?(attribute_name, *args)
153
+ respond_to?(ruby_attribute_setter(attribute_name)) && respond_to?(ruby_attribute_getter(attribute_name))
154
+ end
155
+
156
+ def set_attribute(attribute_name, *args)
157
+ send(ruby_attribute_setter(attribute_name), *args)
158
+ end
159
+
160
+ def get_attribute(attribute_name)
161
+ send(ruby_attribute_getter(attribute_name))
162
+ end
163
+
164
+ def cycle=(*args)
165
+ if args.size == 1
166
+ if args.first.is_a?(Array)
167
+ @cycle = args.first
168
+ else
169
+ @cycle = [args.first]
170
+ end
171
+ elsif args.size > 1
172
+ @cycle = args
173
+ end
174
+ end
175
+
176
+ def cycle_enabled?
177
+ @cycle.is_a?(Array)
178
+ end
179
+
180
+ def cycle_limited?
181
+ cycle_enabled? && @cycle_count.is_a?(Integer)
182
+ end
183
+
184
+ def duration_limited?
185
+ @duration_limit.is_a?(Integer)
186
+ end
187
+
188
+ def frame_count_limited?
189
+ @frame_count.is_a?(Integer)
190
+ end
191
+
192
+ def surpassed_duration_limit?
193
+ duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
194
+ end
195
+
196
+ def within_duration_limit?
197
+ !surpassed_duration_limit?
198
+ end
199
+
200
+ private
201
+
202
+ # Returns true on success of painting a frame and false otherwise
203
+ def draw_frame(start_number)
204
+ return false if stopped? ||
205
+ start_number != @start_number ||
206
+ (frame_count_limited? && @frame_index == @frame_count) ||
207
+ (cycle_limited? && @cycle_count_index == @cycle_count) ||
208
+ surpassed_duration_limit?
209
+ block_args = [@frame_index]
210
+ block_args << @cycle[@frame_index % @cycle.length] if cycle_enabled?
211
+ current_frame_index = @frame_index
212
+ current_cycle_count_index = @cycle_count_index
213
+ self.class.schedule_frame_animation(self) do
214
+ if started? && start_number == @start_number && within_duration_limit?
215
+ @parent.clear_shapes
216
+ @parent.content {
217
+ frame_block.call(*block_args)
218
+ }
219
+ @parent.redraw
220
+ else
221
+ if stopped? && @frame_index > current_frame_index
222
+ @started = false
223
+ @frame_index = current_frame_index
224
+ @cycle_count_index = current_cycle_count_index
225
+ end
226
+ end
227
+ end
228
+ @frame_index += 1
229
+ @cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
230
+ sleep(every) if every.is_a?(Numeric)
231
+ true
232
+ rescue => e
233
+ Glimmer::Config.logger.error {e}
234
+ false
235
+ end
236
+
237
+ end
238
+
239
+ end
240
+
241
+ end
242
+
243
+ end