glimmer-dsl-swt 4.18.4.4 → 4.18.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/LICENSE.txt +20 -20
  4. data/README.md +43 -5058
  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/docs/reference/GLIMMER_COMMAND.md +591 -0
  11. data/docs/reference/GLIMMER_CONFIGURATION.md +183 -0
  12. data/docs/reference/GLIMMER_GIRB.md +30 -0
  13. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +3367 -0
  14. data/docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md +202 -0
  15. data/docs/reference/GLIMMER_SAMPLES.md +755 -0
  16. data/docs/reference/GLIMMER_STYLE_GUIDE.md +14 -0
  17. data/glimmer-dsl-swt.gemspec +22 -7
  18. data/lib/ext/glimmer.rb +41 -41
  19. data/lib/ext/glimmer/config.rb +167 -167
  20. data/lib/ext/rouge/themes/glimmer.rb +29 -29
  21. data/lib/glimmer-dsl-swt.rb +44 -44
  22. data/lib/glimmer/Rakefile +26 -26
  23. data/lib/glimmer/data_binding/list_selection_binding.rb +72 -72
  24. data/lib/glimmer/data_binding/observable_widget.rb +38 -38
  25. data/lib/glimmer/data_binding/shine.rb +44 -44
  26. data/lib/glimmer/data_binding/table_items_binding.rb +89 -89
  27. data/lib/glimmer/data_binding/tree_items_binding.rb +108 -108
  28. data/lib/glimmer/data_binding/widget_binding.rb +73 -73
  29. data/lib/glimmer/dsl/swt/animation_expression.rb +43 -43
  30. data/lib/glimmer/dsl/swt/async_exec_expression.rb +35 -35
  31. data/lib/glimmer/dsl/swt/bind_expression.rb +58 -58
  32. data/lib/glimmer/dsl/swt/block_property_expression.rb +41 -41
  33. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -61
  34. data/lib/glimmer/dsl/swt/color_expression.rb +40 -40
  35. data/lib/glimmer/dsl/swt/column_properties_expression.rb +45 -45
  36. data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +67 -67
  37. data/lib/glimmer/dsl/swt/cursor_expression.rb +44 -44
  38. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +63 -63
  39. data/lib/glimmer/dsl/swt/data_binding_expression.rb +55 -55
  40. data/lib/glimmer/dsl/swt/dialog_expression.rb +48 -48
  41. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -48
  42. data/lib/glimmer/dsl/swt/display_expression.rb +40 -40
  43. data/lib/glimmer/dsl/swt/dnd_expression.rb +46 -46
  44. data/lib/glimmer/dsl/swt/dsl.rb +63 -63
  45. data/lib/glimmer/dsl/swt/exec_expression.rb +55 -55
  46. data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -60
  47. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -48
  48. data/lib/glimmer/dsl/swt/font_expression.rb +49 -49
  49. data/lib/glimmer/dsl/swt/image_expression.rb +54 -50
  50. data/lib/glimmer/dsl/swt/layout_data_expression.rb +46 -46
  51. data/lib/glimmer/dsl/swt/layout_expression.rb +50 -50
  52. data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +65 -65
  53. data/lib/glimmer/dsl/swt/menu_bar_expression.rb +54 -54
  54. data/lib/glimmer/dsl/swt/menu_expression.rb +53 -53
  55. data/lib/glimmer/dsl/swt/message_box_expression.rb +54 -54
  56. data/lib/glimmer/dsl/swt/multiply_expression.rb +53 -53
  57. data/lib/glimmer/dsl/swt/observe_expression.rb +56 -53
  58. data/lib/glimmer/dsl/swt/pixel_expression.rb +38 -0
  59. data/lib/glimmer/dsl/swt/property_expression.rb +46 -46
  60. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +62 -61
  61. data/lib/glimmer/dsl/swt/rgb_expression.rb +33 -33
  62. data/lib/glimmer/dsl/swt/rgba_expression.rb +33 -33
  63. data/lib/glimmer/dsl/swt/shape_expression.rb +54 -54
  64. data/lib/glimmer/dsl/swt/shell_expression.rb +46 -46
  65. data/lib/glimmer/dsl/swt/swt_expression.rb +46 -46
  66. data/lib/glimmer/dsl/swt/sync_exec_expression.rb +36 -36
  67. data/lib/glimmer/dsl/swt/tab_item_expression.rb +54 -54
  68. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +52 -52
  69. data/lib/glimmer/dsl/swt/transform_expression.rb +55 -55
  70. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +52 -52
  71. data/lib/glimmer/dsl/swt/tree_properties_expression.rb +47 -47
  72. data/lib/glimmer/dsl/swt/widget_expression.rb +67 -66
  73. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +53 -53
  74. data/lib/glimmer/rake_task.rb +220 -220
  75. data/lib/glimmer/rake_task/list.rb +97 -97
  76. data/lib/glimmer/rake_task/package.rb +139 -139
  77. data/lib/glimmer/rake_task/scaffold.rb +765 -765
  78. data/lib/glimmer/swt/color_proxy.rb +108 -107
  79. data/lib/glimmer/swt/cursor_proxy.rb +66 -66
  80. data/lib/glimmer/swt/custom/animation.rb +245 -243
  81. data/lib/glimmer/swt/custom/checkbox_group.rb +181 -181
  82. data/lib/glimmer/swt/custom/code_text.rb +1 -0
  83. data/lib/glimmer/swt/custom/drawable.rb +97 -49
  84. data/lib/glimmer/swt/custom/radio_group.rb +177 -176
  85. data/lib/glimmer/swt/custom/shape.rb +332 -297
  86. data/lib/glimmer/swt/date_time_proxy.rb +85 -85
  87. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -65
  88. data/lib/glimmer/swt/display_proxy.rb +167 -166
  89. data/lib/glimmer/swt/dnd_proxy.rb +51 -51
  90. data/lib/glimmer/swt/expand_item_proxy.rb +97 -97
  91. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -66
  92. data/lib/glimmer/swt/font_proxy.rb +94 -94
  93. data/lib/glimmer/swt/image_proxy.rb +195 -184
  94. data/lib/glimmer/swt/layout_data_proxy.rb +105 -105
  95. data/lib/glimmer/swt/layout_proxy.rb +112 -112
  96. data/lib/glimmer/swt/menu_proxy.rb +126 -126
  97. data/lib/glimmer/swt/message_box_proxy.rb +89 -89
  98. data/lib/glimmer/swt/packages.rb +37 -37
  99. data/lib/glimmer/swt/properties.rb +74 -49
  100. data/lib/glimmer/swt/sash_form_proxy.rb +53 -53
  101. data/lib/glimmer/swt/scrolled_composite_proxy.rb +46 -37
  102. data/lib/glimmer/swt/style_constantizable.rb +157 -157
  103. data/lib/glimmer/swt/styled_text_proxy.rb +38 -38
  104. data/lib/glimmer/swt/swt_proxy.rb +59 -59
  105. data/lib/glimmer/swt/tab_item_proxy.rb +92 -91
  106. data/lib/glimmer/swt/table_column_proxy.rb +57 -57
  107. data/lib/glimmer/swt/transform_proxy.rb +109 -109
  108. data/lib/glimmer/swt/tree_proxy.rb +145 -145
  109. data/lib/glimmer/swt/widget_listener_proxy.rb +64 -64
  110. data/lib/glimmer/swt/widget_proxy.rb +977 -957
  111. data/lib/glimmer/ui/custom_shell.rb +82 -82
  112. data/lib/glimmer/ui/custom_widget.rb +332 -315
  113. data/lib/glimmer/util/proc_tracker.rb +39 -39
  114. data/samples/elaborate/contact_manager.rb +142 -142
  115. data/samples/elaborate/contact_manager/contact.rb +32 -32
  116. data/samples/elaborate/contact_manager/contact_manager_presenter.rb +47 -47
  117. data/samples/elaborate/contact_manager/contact_repository.rb +169 -169
  118. data/samples/elaborate/login.rb +123 -123
  119. data/samples/elaborate/mandelbrot_fractal.rb +354 -0
  120. data/samples/elaborate/tetris.rb +5 -18
  121. data/samples/elaborate/tetris/model/block.rb +48 -48
  122. data/samples/elaborate/tetris/model/past_game.rb +39 -39
  123. data/samples/elaborate/tetris/view/block.rb +1 -1
  124. data/samples/elaborate/tetris/view/playfield.rb +1 -1
  125. data/samples/elaborate/tic_tac_toe.rb +76 -76
  126. data/samples/elaborate/tic_tac_toe/board.rb +145 -145
  127. data/samples/elaborate/tic_tac_toe/cell.rb +48 -48
  128. data/samples/elaborate/user_profile.rb +76 -76
  129. data/samples/hello/hello_browser.rb +31 -31
  130. data/samples/hello/hello_button.rb +46 -46
  131. data/samples/hello/hello_canvas.rb +64 -64
  132. data/samples/hello/hello_canvas_animation.rb +1 -1
  133. data/samples/hello/hello_checkbox.rb +85 -85
  134. data/samples/hello/hello_checkbox_group.rb +71 -71
  135. data/samples/hello/hello_code_text.rb +104 -104
  136. data/samples/hello/hello_combo.rb +63 -63
  137. data/samples/hello/hello_computed.rb +96 -96
  138. data/samples/hello/hello_computed/contact.rb +42 -42
  139. data/samples/hello/hello_cursor.rb +57 -0
  140. data/samples/hello/hello_custom_shell.rb +155 -155
  141. data/samples/hello/hello_custom_widget.rb +86 -86
  142. data/samples/hello/hello_date_time.rb +63 -63
  143. data/samples/hello/hello_dialog.rb +78 -78
  144. data/samples/hello/hello_directory_dialog.rb +60 -60
  145. data/samples/hello/hello_drag_and_drop.rb +50 -50
  146. data/samples/hello/hello_expand_bar.rb +110 -110
  147. data/samples/hello/hello_file_dialog.rb +60 -60
  148. data/samples/hello/hello_group.rb +104 -104
  149. data/samples/hello/hello_link.rb +80 -80
  150. data/samples/hello/hello_list_multi_selection.rb +74 -74
  151. data/samples/hello/hello_list_single_selection.rb +59 -59
  152. data/samples/hello/hello_menu_bar.rb +241 -241
  153. data/samples/hello/hello_message_box.rb +37 -37
  154. data/samples/hello/hello_pop_up_context_menu.rb +84 -84
  155. data/samples/hello/hello_radio.rb +108 -108
  156. data/samples/hello/hello_radio_group.rb +87 -87
  157. data/samples/hello/hello_sash_form.rb +137 -137
  158. data/samples/hello/hello_spinner.rb +69 -69
  159. data/samples/hello/hello_styled_text.rb +138 -138
  160. data/samples/hello/hello_tab.rb +50 -50
  161. data/samples/hello/hello_table.rb +1 -1
  162. data/samples/hello/hello_table/baseball_park.png +0 -0
  163. data/samples/hello/hello_world.rb +29 -29
  164. metadata +19 -4
@@ -1,107 +1,108 @@
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
+ @options = args.last.is_a?(Hash) ? args.pop : {}
63
+ @args = args
64
+ @args = @args.first if @args.first.is_a?(Array)
65
+ ensure_arg_values_within_valid_bounds unless @options[:ensure_bounds] == false
66
+ end
67
+
68
+ def swt_color
69
+ unless @swt_color
70
+ case @args.size
71
+ when 1
72
+ if @args.first.is_a?(String) || @args.first.is_a?(Symbol)
73
+ standard_color = @args.first
74
+ standard_color = "color_#{standard_color}".to_sym unless standard_color.to_s.downcase.include?('color_')
75
+ @swt_color = DisplayProxy.instance.swt_display.getSystemColor(SWTProxy[standard_color])
76
+ else
77
+ @swt_color = @args.first
78
+ end
79
+ when 3..4
80
+ @swt_color = Color.new(*@args)
81
+ end
82
+ end
83
+ @swt_color
84
+ end
85
+
86
+ def method_missing(method, *args, &block)
87
+ swt_color.send(method, *args, &block)
88
+ rescue => e
89
+ Glimmer::Config.logger.debug {"Neither ColorProxy nor #{swt_color.class.name} can handle the method ##{method}"}
90
+ super
91
+ end
92
+
93
+ def respond_to?(method, *args, &block)
94
+ super || swt_color.respond_to?(method, *args, &block)
95
+ end
96
+
97
+ private
98
+
99
+ def ensure_arg_values_within_valid_bounds
100
+ if @args.to_a.size >= 3
101
+ @args = @args.map do |value|
102
+ [[value, 255].min, 0].max
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
108
+ 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,245 @@
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
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
+ @parent.requires_shape_disposal = true
88
+ @started = true
89
+ @frame_index = 0
90
+ @cycle_count_index = 0
91
+ @start_number = 0 # denotes the number of starts (increments on every start)
92
+ self.class.swt_display # ensures initializing variable to set from GUI thread
93
+ end
94
+
95
+ def post_add_content
96
+ if @dispose_listener_registration.nil?
97
+ @dispose_listener_registration = @parent.on_widget_disposed { stop }
98
+ start if started?
99
+ end
100
+ end
101
+
102
+ # Starts an animation that is indefinite or has never been started before (i.e. having `started: false` option).
103
+ # Otherwise, resumes a stopped animation that has not been completed.
104
+ def start
105
+ return if @start_number > 0 && started?
106
+ @start_number += 1
107
+ @started = true
108
+ @start_time = Time.now
109
+ @original_start_time = @start_time if @duration.nil?
110
+ # TODO track when finished in a variable for finite animations (whether by frame count, cycle count, or duration limit)
111
+ Thread.new do
112
+ start_number = @start_number
113
+ if cycle_count.is_a?(Integer) && cycle.is_a?(Array)
114
+ (cycle_count * cycle.length).times do
115
+ break unless draw_frame(start_number)
116
+ end
117
+ else
118
+ loop do
119
+ # this code has to be duplicated to break from a loop (break keyword only works when literally in a loop block)
120
+ break unless draw_frame(start_number)
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ def stop
127
+ return if stopped?
128
+ @started = false
129
+ @duration = (Time.now - @start_time) + @duration.to_f if duration_limited? && !@start_time.nil?
130
+ end
131
+
132
+ # Restarts an animation (whether indefinite or not and whether stopped or not)
133
+ def restart
134
+ @original_start_time = @start_time = nil
135
+ @duration = nil
136
+ @frame_index = 0
137
+ @cycle_count_index = 0
138
+ stop
139
+ start
140
+ end
141
+
142
+ def stopped?
143
+ !started?
144
+ end
145
+
146
+ def finite?
147
+ frame_count_limited? || cycle_limited? || duration_limited?
148
+ end
149
+
150
+ def infinite?
151
+ !finite?
152
+ end
153
+ alias indefinite? infinite?
154
+
155
+ def has_attribute?(attribute_name, *args)
156
+ respond_to?(ruby_attribute_setter(attribute_name)) && respond_to?(ruby_attribute_getter(attribute_name))
157
+ end
158
+
159
+ def set_attribute(attribute_name, *args)
160
+ send(ruby_attribute_setter(attribute_name), *args)
161
+ end
162
+
163
+ def get_attribute(attribute_name)
164
+ send(ruby_attribute_getter(attribute_name))
165
+ end
166
+
167
+ def cycle=(*args)
168
+ if args.size == 1
169
+ if args.first.is_a?(Array)
170
+ @cycle = args.first
171
+ else
172
+ @cycle = [args.first]
173
+ end
174
+ elsif args.size > 1
175
+ @cycle = args
176
+ end
177
+ end
178
+
179
+ def cycle_enabled?
180
+ @cycle.is_a?(Array)
181
+ end
182
+
183
+ def cycle_limited?
184
+ cycle_enabled? && @cycle_count.is_a?(Integer)
185
+ end
186
+
187
+ def duration_limited?
188
+ @duration_limit.is_a?(Integer)
189
+ end
190
+
191
+ def frame_count_limited?
192
+ @frame_count.is_a?(Integer)
193
+ end
194
+
195
+ def surpassed_duration_limit?
196
+ duration_limited? && ((Time.now - @start_time) > (@duration_limit - @duration.to_f))
197
+ end
198
+
199
+ def within_duration_limit?
200
+ !surpassed_duration_limit?
201
+ end
202
+
203
+ private
204
+
205
+ # Returns true on success of painting a frame and false otherwise
206
+ def draw_frame(start_number)
207
+ return false if stopped? ||
208
+ start_number != @start_number ||
209
+ (frame_count_limited? && @frame_index == @frame_count) ||
210
+ (cycle_limited? && @cycle_count_index == @cycle_count) ||
211
+ surpassed_duration_limit?
212
+ block_args = [@frame_index]
213
+ block_args << @cycle[@frame_index % @cycle.length] if cycle_enabled?
214
+ current_frame_index = @frame_index
215
+ current_cycle_count_index = @cycle_count_index
216
+ self.class.schedule_frame_animation(self) do
217
+ if started? && start_number == @start_number && within_duration_limit?
218
+ unless @parent.isDisposed
219
+ @parent.clear_shapes # TODO adjust this to clear only the shapes of this animation (not all shapes) to allow simultaneous animations to occur on the same parent
220
+ @parent.content { frame_block.call(*block_args) }
221
+ end
222
+ else
223
+ if stopped? && @frame_index > current_frame_index
224
+ @started = false
225
+ @frame_index = current_frame_index
226
+ @cycle_count_index = current_cycle_count_index
227
+ end
228
+ end
229
+ end
230
+ @frame_index += 1
231
+ @cycle_count_index += 1 if cycle_limited? && (@frame_index % @cycle&.length&.to_i) == 0
232
+ sleep(every) if every.is_a?(Numeric)
233
+ true
234
+ rescue => e
235
+ Glimmer::Config.logger.error {e}
236
+ false
237
+ end
238
+
239
+ end
240
+
241
+ end
242
+
243
+ end
244
+
245
+ end