glimmer-dsl-swt 4.17.4.1 → 4.17.8.0

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -3
  3. data/README.md +267 -107
  4. data/VERSION +1 -1
  5. data/glimmer-dsl-swt.gemspec +24 -5
  6. data/lib/glimmer/data_binding/tree_items_binding.rb +20 -2
  7. data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +61 -0
  8. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +2 -0
  9. data/lib/glimmer/dsl/swt/dialog_expression.rb +1 -0
  10. data/lib/glimmer/dsl/swt/directory_dialog_expression.rb +48 -0
  11. data/lib/glimmer/dsl/swt/dsl.rb +2 -0
  12. data/lib/glimmer/dsl/swt/expand_item_expression.rb +60 -0
  13. data/lib/glimmer/dsl/swt/file_dialog_expression.rb +48 -0
  14. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +61 -0
  15. data/lib/glimmer/dsl/swt/shell_expression.rb +4 -4
  16. data/lib/glimmer/dsl/swt/widget_expression.rb +9 -8
  17. data/lib/glimmer/swt/custom/checkbox_group.rb +160 -0
  18. data/lib/glimmer/swt/custom/code_text.rb +25 -18
  19. data/lib/glimmer/swt/custom/radio_group.rb +155 -0
  20. data/lib/glimmer/swt/directory_dialog_proxy.rb +65 -0
  21. data/lib/glimmer/swt/expand_item_proxy.rb +97 -0
  22. data/lib/glimmer/swt/file_dialog_proxy.rb +66 -0
  23. data/lib/glimmer/swt/image_proxy.rb +5 -0
  24. data/lib/glimmer/swt/menu_proxy.rb +5 -5
  25. data/lib/glimmer/swt/sash_form_proxy.rb +1 -1
  26. data/lib/glimmer/swt/shell_proxy.rb +6 -6
  27. data/lib/glimmer/swt/styled_text_proxy.rb +43 -0
  28. data/lib/glimmer/swt/tab_item_proxy.rb +1 -1
  29. data/lib/glimmer/swt/widget_proxy.rb +86 -82
  30. data/lib/glimmer/ui/custom_shell.rb +4 -4
  31. data/lib/glimmer/ui/custom_widget.rb +3 -0
  32. data/samples/elaborate/meta_sample.rb +36 -31
  33. data/samples/hello/hello_checkbox.rb +85 -0
  34. data/samples/hello/hello_checkbox_group.rb +68 -0
  35. data/samples/hello/hello_combo.rb +12 -12
  36. data/samples/hello/hello_directory_dialog.rb +60 -0
  37. data/samples/hello/hello_expand_bar.rb +110 -0
  38. data/samples/hello/hello_file_dialog.rb +60 -0
  39. data/samples/hello/hello_list_multi_selection.rb +23 -23
  40. data/samples/hello/hello_list_single_selection.rb +18 -17
  41. data/samples/hello/hello_radio.rb +108 -0
  42. data/samples/hello/hello_radio_group.rb +84 -0
  43. data/samples/hello/hello_styled_text.rb +138 -0
  44. data/samples/hello/hello_world.rb +4 -4
  45. metadata +23 -4
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2007-2020 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
+ class HelloFileDialog
23
+ include Glimmer
24
+
25
+ attr_accessor :selected_file
26
+
27
+ def initialize
28
+ @selected_file = 'Please select a file.'
29
+ end
30
+
31
+ def launch
32
+ shell {
33
+ minimum_size 400, 0
34
+ grid_layout
35
+
36
+ text 'Hello, File Dialog!'
37
+
38
+ label {
39
+ text 'Selected File:'
40
+ font height: 14, style: :bold
41
+ }
42
+
43
+ label {
44
+ layout_data :fill, :center, true, false
45
+ text bind(self, :selected_file)
46
+ font height: 14
47
+ }
48
+
49
+ button {
50
+ text "Browse..."
51
+
52
+ on_widget_selected {
53
+ self.selected_file = file_dialog.open
54
+ }
55
+ }
56
+ }.open
57
+ end
58
+ end
59
+
60
+ HelloFileDialog.new.launch
@@ -19,30 +19,30 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- class Person
23
- attr_accessor :provinces, :provinces_options
24
-
25
- def initialize
26
- self.provinces_options=[
27
- "",
28
- "Quebec",
29
- "Ontario",
30
- "Manitoba",
31
- "Saskatchewan",
32
- "Alberta",
33
- "British Columbia",
34
- "Nova Skotia",
35
- "Newfoundland"
36
- ]
37
- self.provinces = ["Quebec", "Manitoba", "Alberta"]
38
- end
39
-
40
- def reset_provinces
41
- self.provinces = ["Quebec", "Manitoba", "Alberta"]
42
- end
43
- end
44
-
45
22
  class HelloListMultiSelection
23
+ class Person
24
+ attr_accessor :provinces, :provinces_options
25
+
26
+ def initialize
27
+ self.provinces_options=[
28
+ "",
29
+ "Quebec",
30
+ "Ontario",
31
+ "Manitoba",
32
+ "Saskatchewan",
33
+ "Alberta",
34
+ "British Columbia",
35
+ "Nova Skotia",
36
+ "Newfoundland"
37
+ ]
38
+ self.provinces = ["Quebec", "Manitoba", "Alberta"]
39
+ end
40
+
41
+ def reset_provinces
42
+ self.provinces = ["Quebec", "Manitoba", "Alberta"]
43
+ end
44
+ end
45
+
46
46
  include Glimmer
47
47
 
48
48
  def launch
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2020 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -19,21 +19,22 @@
19
19
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- class Person
23
- attr_accessor :country, :country_options
24
-
25
- def initialize
26
- self.country_options=["", "Canada", "US", "Mexico"]
27
- self.country = "Canada"
28
- end
29
-
30
- def reset_country
31
- self.country = "Canada"
32
- end
33
- end
34
-
35
22
  class HelloListSingleSelection
23
+ class Person
24
+ attr_accessor :country, :country_options
25
+
26
+ def initialize
27
+ self.country_options=["", "Canada", "US", "Mexico"]
28
+ self.country = "Canada"
29
+ end
30
+
31
+ def reset_country
32
+ self.country = "Canada"
33
+ end
34
+ end
35
+
36
36
  include Glimmer
37
+
37
38
  def launch
38
39
  person = Person.new
39
40
 
@@ -55,4 +56,4 @@ class HelloListSingleSelection
55
56
  end
56
57
  end
57
58
 
58
- HelloListSingleSelection.new.launch
59
+ HelloListSingleSelection.new.launch
@@ -0,0 +1,108 @@
1
+ # Copyright (c) 2007-2020 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
+ class HelloRadio
23
+ class Person
24
+ attr_accessor :male, :female, :child, :teen, :adult, :senior
25
+
26
+ def initialize
27
+ reset
28
+ end
29
+
30
+ def reset
31
+ self.male = nil
32
+ self.female = nil
33
+ self.child = nil
34
+ self.teen = nil
35
+ self.adult = true
36
+ self.senior = nil
37
+ end
38
+ end
39
+
40
+ include Glimmer
41
+
42
+ def launch
43
+ person = Person.new
44
+
45
+ shell {
46
+ text 'Hello, Radio!'
47
+ row_layout :vertical
48
+
49
+ label {
50
+ text 'Gender:'
51
+ font style: :bold
52
+ }
53
+
54
+ composite {
55
+ row_layout
56
+
57
+ radio {
58
+ text 'Male'
59
+ selection bind(person, :male)
60
+ }
61
+
62
+ radio {
63
+ text 'Female'
64
+ selection bind(person, :female)
65
+ }
66
+ }
67
+
68
+ label {
69
+ text 'Age Group:'
70
+ font style: :bold
71
+ }
72
+
73
+ composite {
74
+ row_layout
75
+
76
+ radio {
77
+ text 'Child'
78
+ selection bind(person, :child)
79
+ }
80
+
81
+ radio {
82
+ text 'Teen'
83
+ selection bind(person, :teen)
84
+ }
85
+
86
+ radio {
87
+ text 'Adult'
88
+ selection bind(person, :adult)
89
+ }
90
+
91
+ radio {
92
+ text 'Senior'
93
+ selection bind(person, :senior)
94
+ }
95
+ }
96
+
97
+ button {
98
+ text 'Reset'
99
+
100
+ on_widget_selected do
101
+ person.reset
102
+ end
103
+ }
104
+ }.open
105
+ end
106
+ end
107
+
108
+ HelloRadio.new.launch
@@ -0,0 +1,84 @@
1
+ # Copyright (c) 2007-2020 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
+ class HelloRadioGroup
23
+ class Person
24
+ attr_accessor :gender, :age_group
25
+
26
+ def initialize
27
+ reset
28
+ end
29
+
30
+ def gender_options
31
+ ['Male', 'Female']
32
+ end
33
+
34
+ def age_group_options
35
+ ['Child', 'Teen', 'Adult', 'Senior']
36
+ end
37
+
38
+ def reset
39
+ self.gender = nil
40
+ self.age_group = 'Adult'
41
+ end
42
+ end
43
+
44
+ include Glimmer
45
+
46
+ def launch
47
+ person = Person.new
48
+
49
+ shell {
50
+ text 'Hello, Radio Group!'
51
+ row_layout :vertical
52
+
53
+ label {
54
+ text 'Gender:'
55
+ font style: :bold
56
+ }
57
+
58
+ radio_group {
59
+ row_layout :horizontal
60
+ selection bind(person, :gender)
61
+ }
62
+
63
+ label {
64
+ text 'Age Group:'
65
+ font style: :bold
66
+ }
67
+
68
+ radio_group {
69
+ row_layout :horizontal
70
+ selection bind(person, :age_group)
71
+ }
72
+
73
+ button {
74
+ text 'Reset'
75
+
76
+ on_widget_selected do
77
+ person.reset
78
+ end
79
+ }
80
+ }.open
81
+ end
82
+ end
83
+
84
+ HelloRadioGroup.new.launch
@@ -0,0 +1,138 @@
1
+ # Copyright (c) 2007-2020 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
+ verbiage = <<-MULTI_LINE_STRING
23
+
24
+ Glimmer DSL for SWT is a native-GUI cross-platform desktop development library written in JRuby,
25
+ an OS-threaded faster version of Ruby.
26
+ Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring
27
+ of desktop application user-interfaces while relying on the robust Eclipse SWT library.
28
+ Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates
29
+ synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components
30
+ and enabling developers to solve business problems (test-first) without worrying about GUI concerns.
31
+ To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets.
32
+ Glimmer also includes native-executable packaging support, sorely lacking in other libraries,
33
+ thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on
34
+ the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.
35
+
36
+ MULTI_LINE_STRING
37
+
38
+ class StyledTextPresenter
39
+ include Glimmer
40
+ attr_accessor :text, :caret_offset, :selection_count, :selection, :top_pixel
41
+
42
+ def line_index_for_offset(line_offset)
43
+ text[0..line_offset].split("\n").size
44
+ end
45
+ end
46
+
47
+ include Glimmer
48
+
49
+ @presenter = StyledTextPresenter.new
50
+ @presenter.text = verbiage*8
51
+ @presenter.caret_offset = 0
52
+ @presenter.selection_count = 0
53
+ @presenter.selection = Point.new(0, 0)
54
+ @presenter.top_pixel = 0
55
+
56
+ shell {
57
+ text 'Hello, Styled Text!'
58
+
59
+ composite {
60
+ @styled_text = styled_text {
61
+ layout_data :fill, :fill, true, true
62
+ text bind(@presenter, :text)
63
+ left_margin 5
64
+ top_margin 5
65
+ right_margin 5
66
+ bottom_margin 5
67
+ # caret offset scrolls text to view when out of page
68
+ caret_offset bind(@presenter, :caret_offset)
69
+ # selection_count is not needed if selection is used
70
+ selection_count bind(@presenter, :selection_count)
71
+ # selection contains both caret_offset and selection_count, but setting it does not scroll text into view if out of page
72
+ selection bind(@presenter, :selection)
73
+ # top_pixel indicates vertically what pixel scrolling is at in a long multi-page text document
74
+ top_pixel bind(@presenter, :top_pixel)
75
+
76
+ # This demonstrates how to set styles via a listener
77
+ on_line_get_style { |line_style_event|
78
+ line_offset = line_style_event.lineOffset
79
+ if @presenter.line_index_for_offset(line_offset) % 52 < 13
80
+ line_size = line_style_event.lineText.size
81
+ style_range = StyleRange.new(line_offset, line_size, color(:blue).swt_color, nil, swt(:italic))
82
+ style_range.font = Font.new(display.swt_display, 'Times New Roman', 18, swt(:normal))
83
+ line_style_event.styles = [style_range].to_java(StyleRange)
84
+ elsif @presenter.line_index_for_offset(line_offset) % 52 < 26
85
+ line_size = line_style_event.lineText.size
86
+ style_range = StyleRange.new(line_offset, line_size, color(:dark_green).swt_color, color(:yellow).swt_color, swt(:bold))
87
+ line_style_event.styles = [style_range].to_java(StyleRange)
88
+ elsif @presenter.line_index_for_offset(line_offset) % 52 < 39
89
+ line_size = line_style_event.lineText.size
90
+ style_range = StyleRange.new(line_offset, line_size, color(:red).swt_color, nil, swt(:normal))
91
+ style_range.underline = true
92
+ style_range.font = Font.new(display.swt_display, 'Arial', 16, swt(:normal))
93
+ line_style_event.styles = [style_range].to_java(StyleRange)
94
+ else
95
+ line_size = line_style_event.lineText.size
96
+ style_range = StyleRange.new(line_offset, line_size, color(:dark_magenta).swt_color, color(:cyan).swt_color, swt(:normal))
97
+ style_range.strikeout = true
98
+ line_style_event.styles = [style_range].to_java(StyleRange)
99
+ end
100
+ }
101
+ }
102
+
103
+ composite {
104
+ row_layout :horizontal
105
+
106
+ label {
107
+ text 'Caret Offset:'
108
+ }
109
+ text {
110
+ text bind(@presenter, :caret_offset, on_read: ->(o) {"%04d" % [o] })
111
+ }
112
+ label {
113
+ text 'Selection Count:'
114
+ }
115
+ text {
116
+ text bind(@presenter, :selection_count, on_read: ->(o) {"%04d" % [o] })
117
+ }
118
+ label {
119
+ text 'Selection Start:'
120
+ }
121
+ text {
122
+ text bind(@presenter, 'selection.x', on_read: ->(o) {"%04d" % [o] })
123
+ }
124
+ label {
125
+ text 'Selection End:'
126
+ }
127
+ text {
128
+ text bind(@presenter, 'selection.y', on_read: ->(o) {"%04d" % [o] })
129
+ }
130
+ label {
131
+ text 'Top Pixel:'
132
+ }
133
+ text {
134
+ text bind(@presenter, :top_pixel, on_read: ->(o) {"%04d" % [o] })
135
+ }
136
+ }
137
+ }
138
+ }.open