glimmer-dsl-swt 4.18.4.10 → 4.18.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +71 -0
- data/README.md +14 -5
- data/VERSION +1 -1
- data/bin/glimmer +3 -3
- data/docs/reference/GLIMMER_CONFIGURATION.md +7 -3
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +451 -112
- data/docs/reference/GLIMMER_SAMPLES.md +76 -3
- data/glimmer-dsl-swt.gemspec +23 -13
- data/lib/ext/glimmer/config.rb +3 -7
- data/lib/glimmer/data_binding/list_selection_binding.rb +13 -7
- data/lib/glimmer/data_binding/table_items_binding.rb +22 -17
- data/lib/glimmer/data_binding/tree_items_binding.rb +19 -15
- data/lib/glimmer/data_binding/widget_binding.rb +12 -27
- data/lib/glimmer/dsl/swt/{file_dialog_expression.rb → auto_exec_expression.rb} +6 -18
- data/lib/glimmer/dsl/swt/checkbox_group_selection_data_binding_expression.rb +9 -6
- data/lib/glimmer/dsl/swt/color_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb +16 -14
- data/lib/glimmer/dsl/swt/custom_widget_expression.rb +4 -1
- data/lib/glimmer/dsl/swt/data_binding_expression.rb +1 -2
- data/lib/glimmer/dsl/swt/dialog_expression.rb +18 -9
- data/lib/glimmer/dsl/swt/dsl.rb +1 -0
- data/lib/glimmer/dsl/swt/exec_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +16 -2
- data/lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb +11 -8
- data/lib/glimmer/dsl/swt/pixel_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +8 -5
- data/lib/glimmer/dsl/swt/shape_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/widget_expression.rb +8 -4
- data/lib/glimmer/launcher.rb +3 -0
- data/lib/glimmer/rake_task/scaffold.rb +3 -0
- data/lib/glimmer/swt/color_proxy.rb +1 -1
- data/lib/glimmer/swt/custom/code_text.rb +33 -11
- data/lib/glimmer/swt/custom/drawable.rb +57 -1
- data/lib/glimmer/swt/custom/shape.rb +332 -48
- data/lib/glimmer/swt/custom/shape/arc.rb +60 -0
- data/lib/glimmer/{dsl/swt/directory_dialog_expression.rb → swt/custom/shape/focus.rb} +15 -20
- data/lib/glimmer/swt/custom/shape/image.rb +112 -0
- data/lib/glimmer/swt/custom/shape/line.rb +111 -0
- data/lib/glimmer/swt/custom/shape/oval.rb +61 -0
- data/lib/glimmer/swt/custom/shape/point.rb +49 -0
- data/lib/glimmer/swt/custom/shape/polygon.rb +114 -0
- data/lib/glimmer/swt/custom/shape/polyline.rb +115 -0
- data/lib/glimmer/swt/custom/shape/rectangle.rb +105 -0
- data/lib/glimmer/swt/custom/shape/text.rb +85 -0
- data/lib/glimmer/swt/date_time_proxy.rb +9 -3
- data/lib/glimmer/swt/dialog_proxy.rb +92 -0
- data/lib/glimmer/swt/display_proxy.rb +62 -2
- data/lib/glimmer/swt/expand_item_proxy.rb +18 -12
- data/lib/glimmer/swt/font_proxy.rb +13 -7
- data/lib/glimmer/swt/image_proxy.rb +15 -4
- data/lib/glimmer/swt/layout_data_proxy.rb +21 -15
- data/lib/glimmer/swt/layout_proxy.rb +19 -15
- data/lib/glimmer/swt/menu_proxy.rb +2 -2
- data/lib/glimmer/swt/message_box_proxy.rb +21 -7
- data/lib/glimmer/swt/properties.rb +3 -0
- data/lib/glimmer/swt/proxy_properties.rb +145 -0
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -2
- data/lib/glimmer/swt/shell_proxy.rb +94 -80
- data/lib/glimmer/swt/swt_proxy.rb +16 -0
- data/lib/glimmer/swt/tab_item_proxy.rb +5 -3
- data/lib/glimmer/swt/table_proxy.rb +32 -11
- data/lib/glimmer/swt/transform_proxy.rb +39 -35
- data/lib/glimmer/swt/tree_proxy.rb +11 -16
- data/lib/glimmer/swt/widget_listener_proxy.rb +6 -2
- data/lib/glimmer/swt/widget_proxy.rb +193 -138
- data/lib/glimmer/ui.rb +5 -0
- data/lib/glimmer/ui/custom_shell.rb +11 -5
- data/lib/glimmer/ui/custom_widget.rb +4 -5
- data/samples/elaborate/contact_manager.rb +9 -7
- data/samples/elaborate/login.rb +27 -21
- data/samples/elaborate/mandelbrot_fractal.rb +20 -25
- data/samples/elaborate/meta_sample.rb +2 -1
- data/samples/elaborate/tetris.rb +3 -1
- data/samples/elaborate/tic_tac_toe.rb +18 -14
- data/samples/elaborate/tic_tac_toe/board.rb +5 -5
- data/samples/elaborate/tic_tac_toe/cell.rb +5 -5
- data/samples/elaborate/user_profile.rb +10 -8
- data/samples/hello/hello_browser.rb +2 -0
- data/samples/hello/hello_button.rb +9 -7
- data/samples/hello/hello_canvas.rb +144 -40
- data/samples/hello/hello_canvas_animation.rb +2 -0
- data/samples/hello/hello_canvas_transform.rb +2 -0
- data/samples/hello/hello_checkbox.rb +18 -14
- data/samples/hello/hello_checkbox_group.rb +13 -9
- data/samples/hello/hello_code_text.rb +2 -0
- data/samples/hello/hello_color_dialog.rb +68 -0
- data/samples/hello/hello_combo.rb +16 -12
- data/samples/hello/hello_computed.rb +9 -7
- data/samples/hello/hello_cursor.rb +4 -1
- data/samples/hello/hello_custom_shell.rb +18 -21
- data/samples/hello/hello_custom_widget.rb +6 -6
- data/samples/hello/hello_date_time.rb +16 -12
- data/samples/hello/hello_dialog.rb +2 -0
- data/samples/hello/hello_directory_dialog.rb +9 -7
- data/samples/hello/hello_drag_and_drop.rb +5 -3
- data/samples/hello/hello_expand_bar.rb +10 -8
- data/samples/hello/hello_file_dialog.rb +9 -7
- data/samples/hello/hello_font_dialog.rb +84 -0
- data/samples/hello/hello_group.rb +20 -16
- data/samples/hello/hello_link.rb +2 -0
- data/samples/hello/hello_list_multi_selection.rb +15 -11
- data/samples/hello/hello_list_single_selection.rb +15 -11
- data/samples/hello/hello_menu_bar.rb +2 -0
- data/samples/hello/hello_message_box.rb +2 -0
- data/samples/hello/hello_pop_up_context_menu.rb +2 -0
- data/samples/hello/hello_progress_bar.rb +5 -5
- data/samples/hello/hello_radio.rb +20 -16
- data/samples/hello/hello_radio_group.rb +16 -12
- data/samples/hello/hello_sash_form.rb +2 -0
- data/samples/hello/hello_spinner.rb +9 -7
- data/samples/hello/hello_styled_text.rb +19 -17
- data/samples/hello/hello_tab.rb +7 -5
- data/samples/hello/hello_table.rb +12 -5
- data/samples/hello/hello_tree.rb +485 -0
- data/samples/hello/hello_world.rb +2 -0
- metadata +21 -22
- data/lib/glimmer/swt/directory_dialog_proxy.rb +0 -65
- data/lib/glimmer/swt/file_dialog_proxy.rb +0 -66
@@ -19,6 +19,8 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
include Glimmer
|
23
25
|
|
24
26
|
COLORS = [:white, :red, :yellow, :green, :blue, :magenta, :gray, :black]
|
@@ -19,8 +19,10 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
class HelloProgressBar
|
23
|
-
include Glimmer::UI::
|
25
|
+
include Glimmer::UI::CustomShell
|
24
26
|
|
25
27
|
class ProgressModel
|
26
28
|
attr_accessor :minimum, :maximum, :selection, :delay
|
@@ -110,11 +112,9 @@ class HelloProgressBar
|
|
110
112
|
# (killing is not dangerous since it is only a thread about updating progress)
|
111
113
|
@current_thread&.kill
|
112
114
|
@current_thread = Thread.new {
|
113
|
-
|
115
|
+
@progress_model.selection = @progress_model.minimum
|
114
116
|
(@progress_model.minimum..@progress_model.maximum).to_a.each do |n|
|
115
|
-
|
116
|
-
@progress_model.selection = n
|
117
|
-
}
|
117
|
+
@progress_model.selection = n
|
118
118
|
sleep(@progress_model.delay)
|
119
119
|
end
|
120
120
|
}
|
@@ -19,15 +19,17 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
class HelloRadio
|
23
25
|
class Person
|
24
26
|
attr_accessor :male, :female, :child, :teen, :adult, :senior
|
25
27
|
|
26
28
|
def initialize
|
27
|
-
reset
|
29
|
+
reset!
|
28
30
|
end
|
29
31
|
|
30
|
-
def reset
|
32
|
+
def reset!
|
31
33
|
self.male = nil
|
32
34
|
self.female = nil
|
33
35
|
self.child = nil
|
@@ -37,11 +39,13 @@ class HelloRadio
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
include Glimmer
|
42
|
+
include Glimmer::UI::CustomShell
|
41
43
|
|
42
|
-
|
43
|
-
person = Person.new
|
44
|
-
|
44
|
+
before_body {
|
45
|
+
@person = Person.new
|
46
|
+
}
|
47
|
+
|
48
|
+
body {
|
45
49
|
shell {
|
46
50
|
text 'Hello, Radio!'
|
47
51
|
row_layout :vertical
|
@@ -56,12 +60,12 @@ class HelloRadio
|
|
56
60
|
|
57
61
|
radio {
|
58
62
|
text 'Male'
|
59
|
-
selection bind(person, :male)
|
63
|
+
selection bind(@person, :male)
|
60
64
|
}
|
61
65
|
|
62
66
|
radio {
|
63
67
|
text 'Female'
|
64
|
-
selection bind(person, :female)
|
68
|
+
selection bind(@person, :female)
|
65
69
|
}
|
66
70
|
}
|
67
71
|
|
@@ -75,22 +79,22 @@ class HelloRadio
|
|
75
79
|
|
76
80
|
radio {
|
77
81
|
text 'Child'
|
78
|
-
selection bind(person, :child)
|
82
|
+
selection bind(@person, :child)
|
79
83
|
}
|
80
84
|
|
81
85
|
radio {
|
82
86
|
text 'Teen'
|
83
|
-
selection bind(person, :teen)
|
87
|
+
selection bind(@person, :teen)
|
84
88
|
}
|
85
89
|
|
86
90
|
radio {
|
87
91
|
text 'Adult'
|
88
|
-
selection bind(person, :adult)
|
92
|
+
selection bind(@person, :adult)
|
89
93
|
}
|
90
94
|
|
91
95
|
radio {
|
92
96
|
text 'Senior'
|
93
|
-
selection bind(person, :senior)
|
97
|
+
selection bind(@person, :senior)
|
94
98
|
}
|
95
99
|
}
|
96
100
|
|
@@ -98,11 +102,11 @@ class HelloRadio
|
|
98
102
|
text 'Reset'
|
99
103
|
|
100
104
|
on_widget_selected do
|
101
|
-
person.reset
|
105
|
+
@person.reset!
|
102
106
|
end
|
103
107
|
}
|
104
|
-
}
|
105
|
-
|
108
|
+
}
|
109
|
+
}
|
106
110
|
end
|
107
111
|
|
108
|
-
HelloRadio.
|
112
|
+
HelloRadio.launch
|
@@ -19,6 +19,8 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
# This sample demonstrates the use of a `radio_group` in Glimmer, which provides terser syntax
|
23
25
|
# than HelloRadio for representing multiple radio buttons by relying on data-binding to
|
24
26
|
# automatically spawn the `radio` widgets based on available options on the model.
|
@@ -27,7 +29,7 @@ class HelloRadioGroup
|
|
27
29
|
attr_accessor :gender, :age_group
|
28
30
|
|
29
31
|
def initialize
|
30
|
-
reset
|
32
|
+
reset!
|
31
33
|
end
|
32
34
|
|
33
35
|
def gender_options
|
@@ -38,17 +40,19 @@ class HelloRadioGroup
|
|
38
40
|
['Child', 'Teen', 'Adult', 'Senior']
|
39
41
|
end
|
40
42
|
|
41
|
-
def reset
|
43
|
+
def reset!
|
42
44
|
self.gender = nil
|
43
45
|
self.age_group = 'Adult'
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
47
|
-
include Glimmer
|
49
|
+
include Glimmer::UI::CustomShell
|
48
50
|
|
49
|
-
|
50
|
-
person = Person.new
|
51
|
-
|
51
|
+
before_body {
|
52
|
+
@person = Person.new
|
53
|
+
}
|
54
|
+
|
55
|
+
body {
|
52
56
|
shell {
|
53
57
|
text 'Hello, Radio Group!'
|
54
58
|
row_layout :vertical
|
@@ -60,7 +64,7 @@ class HelloRadioGroup
|
|
60
64
|
|
61
65
|
radio_group {
|
62
66
|
row_layout :horizontal
|
63
|
-
selection bind(person, :gender)
|
67
|
+
selection bind(@person, :gender)
|
64
68
|
}
|
65
69
|
|
66
70
|
label {
|
@@ -70,18 +74,18 @@ class HelloRadioGroup
|
|
70
74
|
|
71
75
|
radio_group {
|
72
76
|
row_layout :horizontal
|
73
|
-
selection bind(person, :age_group)
|
77
|
+
selection bind(@person, :age_group)
|
74
78
|
}
|
75
79
|
|
76
80
|
button {
|
77
81
|
text 'Reset'
|
78
82
|
|
79
83
|
on_widget_selected do
|
80
|
-
person.reset
|
84
|
+
@person.reset!
|
81
85
|
end
|
82
86
|
}
|
83
|
-
}
|
84
|
-
|
87
|
+
}
|
88
|
+
}
|
85
89
|
end
|
86
90
|
|
87
|
-
HelloRadioGroup.
|
91
|
+
HelloRadioGroup.launch
|
@@ -19,19 +19,21 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
class HelloSpinner
|
23
25
|
class Person
|
24
26
|
attr_accessor :donation
|
25
27
|
end
|
26
28
|
|
27
|
-
include Glimmer
|
29
|
+
include Glimmer::UI::CustomShell
|
28
30
|
|
29
|
-
|
31
|
+
before_body {
|
30
32
|
@person = Person.new
|
31
33
|
@person.donation = 500
|
32
|
-
|
34
|
+
}
|
33
35
|
|
34
|
-
|
36
|
+
body {
|
35
37
|
shell {
|
36
38
|
grid_layout
|
37
39
|
|
@@ -62,8 +64,8 @@ class HelloSpinner
|
|
62
64
|
selection bind(@person, :donation) # selection must be set last if other properties are configured to ensure value is within bounds
|
63
65
|
}
|
64
66
|
}
|
65
|
-
}
|
66
|
-
|
67
|
+
}
|
68
|
+
}
|
67
69
|
end
|
68
70
|
|
69
|
-
HelloSpinner.
|
71
|
+
HelloSpinner.launch
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2007-2021 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,18 +19,20 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
verbiage = <<-MULTI_LINE_STRING
|
23
25
|
|
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
|
26
|
+
Glimmer DSL for SWT is a native-GUI cross-platform desktop development library written in JRuby,
|
27
|
+
an OS-threaded faster version of Ruby.
|
28
|
+
Glimmer's main innovation is a declarative Ruby DSL that enables productive and efficient authoring
|
29
|
+
of desktop application user-interfaces while relying on the robust Eclipse SWT library.
|
30
|
+
Glimmer additionally innovates by having built-in data-binding support, which greatly facilitates
|
31
|
+
synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components
|
32
|
+
and enabling developers to solve business problems (test-first) without worrying about GUI concerns.
|
33
|
+
To get started quickly, Glimmer offers scaffolding options for Apps, Gems, and Custom Widgets.
|
34
|
+
Glimmer also includes native-executable packaging support, sorely lacking in other libraries,
|
35
|
+
thus enabling the delivery of desktop apps written in Ruby as truly native DMG/PKG/APP files on
|
34
36
|
the Mac + App Store, MSI/EXE files on Windows, and Gem Packaged Shell Scripts on Linux.
|
35
37
|
|
36
38
|
MULTI_LINE_STRING
|
@@ -74,7 +76,7 @@ shell {
|
|
74
76
|
top_pixel bind(@presenter, :top_pixel)
|
75
77
|
|
76
78
|
# This demonstrates how to set styles via a listener
|
77
|
-
on_line_get_style { |line_style_event|
|
79
|
+
on_line_get_style { |line_style_event|
|
78
80
|
line_offset = line_style_event.lineOffset
|
79
81
|
if @presenter.line_index_for_offset(line_offset) % 52 < 13
|
80
82
|
line_size = line_style_event.lineText.size
|
@@ -95,7 +97,7 @@ shell {
|
|
95
97
|
line_size = line_style_event.lineText.size
|
96
98
|
style_range = StyleRange.new(line_offset, line_size, color(:dark_magenta).swt_color, color(:cyan).swt_color, swt(:normal))
|
97
99
|
style_range.strikeout = true
|
98
|
-
line_style_event.styles = [style_range].to_java(StyleRange)
|
100
|
+
line_style_event.styles = [style_range].to_java(StyleRange)
|
99
101
|
end
|
100
102
|
}
|
101
103
|
}
|
@@ -132,7 +134,7 @@ shell {
|
|
132
134
|
}
|
133
135
|
text {
|
134
136
|
text bind(@presenter, :top_pixel, on_read: ->(o) {"%04d" % [o] })
|
135
|
-
}
|
136
|
-
}
|
137
|
+
}
|
138
|
+
}
|
137
139
|
}
|
138
140
|
}.open
|
data/samples/hello/hello_tab.rb
CHANGED
@@ -19,10 +19,12 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
class HelloTab
|
23
|
-
include Glimmer
|
25
|
+
include Glimmer::UI::CustomShell
|
24
26
|
|
25
|
-
|
27
|
+
body {
|
26
28
|
shell {
|
27
29
|
text 'Hello, Tab!'
|
28
30
|
|
@@ -43,8 +45,8 @@ class HelloTab
|
|
43
45
|
}
|
44
46
|
}
|
45
47
|
}
|
46
|
-
}
|
47
|
-
|
48
|
+
}
|
49
|
+
}
|
48
50
|
end
|
49
51
|
|
50
|
-
HelloTab.
|
52
|
+
HelloTab.launch
|
@@ -19,6 +19,8 @@
|
|
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
|
+
require 'glimmer-dsl-swt'
|
23
|
+
|
22
24
|
class HelloTable
|
23
25
|
class BaseballGame
|
24
26
|
class << self
|
@@ -179,14 +181,19 @@ class HelloTable
|
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
182
|
-
include Glimmer
|
184
|
+
include Glimmer::UI::CustomShell
|
185
|
+
|
186
|
+
before_body {
|
187
|
+
Display.app_name = 'Hello, Table!'
|
188
|
+
}
|
183
189
|
|
184
|
-
|
190
|
+
body {
|
185
191
|
shell {
|
186
192
|
grid_layout
|
187
193
|
|
188
194
|
text 'Hello, Table!'
|
189
195
|
background_image File.expand_path('hello_table/baseball_park.png', __dir__)
|
196
|
+
image File.expand_path('hello_table/baseball_park.png', __dir__)
|
190
197
|
|
191
198
|
label {
|
192
199
|
layout_data :center, :center, true, false
|
@@ -272,8 +279,8 @@ class HelloTable
|
|
272
279
|
book_selected_game
|
273
280
|
}
|
274
281
|
}
|
275
|
-
}
|
276
|
-
|
282
|
+
}
|
283
|
+
}
|
277
284
|
|
278
285
|
def book_selected_game
|
279
286
|
message_box {
|
@@ -283,4 +290,4 @@ class HelloTable
|
|
283
290
|
end
|
284
291
|
end
|
285
292
|
|
286
|
-
HelloTable.
|
293
|
+
HelloTable.launch
|
@@ -0,0 +1,485 @@
|
|
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-dsl-swt'
|
23
|
+
|
24
|
+
class HelloTree
|
25
|
+
EMPLOYEE_ATTRIBUTES = [
|
26
|
+
:first_name, :last_name, :position, :salary,
|
27
|
+
:health_insurance, :desk_location,
|
28
|
+
:sales_bonus_percentage, :merit_bonus,
|
29
|
+
:work_expense, :technology_expense, :travel_expense, :client_expense, :sponsorship_expense, :food_expense, :office_expense,
|
30
|
+
]
|
31
|
+
|
32
|
+
EmployeeStruct ||= Struct.new(*EMPLOYEE_ATTRIBUTES, keyword_init: true)
|
33
|
+
|
34
|
+
class Employee < EmployeeStruct
|
35
|
+
|
36
|
+
NAMES_FIRST = %w[
|
37
|
+
John
|
38
|
+
Noah
|
39
|
+
Bill
|
40
|
+
James
|
41
|
+
Oliver
|
42
|
+
Bob
|
43
|
+
Laura
|
44
|
+
Stephanie
|
45
|
+
Marie
|
46
|
+
Emma
|
47
|
+
Olivia
|
48
|
+
Anna
|
49
|
+
]
|
50
|
+
|
51
|
+
NAMES_LAST = %w[
|
52
|
+
Smith
|
53
|
+
Johnson
|
54
|
+
Williams
|
55
|
+
Brown
|
56
|
+
Jones
|
57
|
+
Harvard
|
58
|
+
Miller
|
59
|
+
Davis
|
60
|
+
Wilson
|
61
|
+
Anderson
|
62
|
+
Taylor
|
63
|
+
Magnus
|
64
|
+
]
|
65
|
+
|
66
|
+
EMPLOYMENT_TYPE_POSITIONS = {
|
67
|
+
'Sales' => 'Sales Person',
|
68
|
+
'HR' => 'HR Staff',
|
69
|
+
'Engineering' => 'Engineer',
|
70
|
+
'Finance' => 'Accountant',
|
71
|
+
}
|
72
|
+
|
73
|
+
SENIORITY_SALARIES = {
|
74
|
+
'Senior' => 111_111,
|
75
|
+
'Standard' => 88_888,
|
76
|
+
'Junior' => 55_555,
|
77
|
+
}
|
78
|
+
|
79
|
+
ALL_HEALTH_INSURANCES = [
|
80
|
+
'Family Plan',
|
81
|
+
'Standard Plan',
|
82
|
+
'Minimal Plan',
|
83
|
+
]
|
84
|
+
|
85
|
+
class << self
|
86
|
+
attr_accessor :selected_employee
|
87
|
+
|
88
|
+
def available_names
|
89
|
+
@available_names ||= NAMES_FIRST.size.times.map { |n| NAMES_FIRST.rotate(n).zip(NAMES_LAST) }.flatten(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
def select_name!
|
93
|
+
available_names.shift
|
94
|
+
end
|
95
|
+
|
96
|
+
def all_desk_locations
|
97
|
+
@all_desk_locations ||= 30.times.map do |n|
|
98
|
+
floor = n + 1
|
99
|
+
[
|
100
|
+
"Floor #{floor} Sales",
|
101
|
+
"Floor #{floor} Engineering",
|
102
|
+
"Floor #{floor} HR",
|
103
|
+
"Floor #{floor} Finance",
|
104
|
+
]
|
105
|
+
end.reduce(:+)
|
106
|
+
end
|
107
|
+
|
108
|
+
def available_desk_locations
|
109
|
+
@available_desk_locations ||= all_desk_locations.clone.reverse
|
110
|
+
end
|
111
|
+
|
112
|
+
def select_desk_location!(type)
|
113
|
+
available_desk_locations.delete(available_desk_locations.detect {|desk_location| desk_location.to_s.end_with?(type)})
|
114
|
+
end
|
115
|
+
|
116
|
+
def ceo
|
117
|
+
@ceo ||= Employee.new(
|
118
|
+
position: 'CEO',
|
119
|
+
salary: 999_999,
|
120
|
+
health_insurance: ALL_HEALTH_INSURANCES[0],
|
121
|
+
desk_location: Employee.select_desk_location!('Sales'),
|
122
|
+
).tap do |employee|
|
123
|
+
employee.subordinates << cto
|
124
|
+
employee.subordinates << cfo
|
125
|
+
employee.subordinates << cio
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def cto
|
130
|
+
@cto ||= Employee.new(
|
131
|
+
position: 'CTO',
|
132
|
+
salary: 777_777,
|
133
|
+
health_insurance: ALL_HEALTH_INSURANCES[0],
|
134
|
+
desk_location: Employee.select_desk_location!('Engineering'),
|
135
|
+
).tap do |employee|
|
136
|
+
employee.subordinates << vp('Engineering')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def cfo
|
141
|
+
@cfo ||= Employee.new(
|
142
|
+
position: 'CFO',
|
143
|
+
salary: 777_777,
|
144
|
+
health_insurance: ALL_HEALTH_INSURANCES[0],
|
145
|
+
desk_location: Employee.select_desk_location!('Finance'),
|
146
|
+
).tap do |employee|
|
147
|
+
employee.subordinates << vp('Finance')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def cio
|
152
|
+
@cio ||= Employee.new(
|
153
|
+
position: 'CIO',
|
154
|
+
salary: 777_777,
|
155
|
+
health_insurance: ALL_HEALTH_INSURANCES[0],
|
156
|
+
desk_location: Employee.select_desk_location!('HR'),
|
157
|
+
).tap do |employee|
|
158
|
+
employee.subordinates << vp('Sales')
|
159
|
+
employee.subordinates << vp('HR')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def vp(type)
|
164
|
+
Employee.new(
|
165
|
+
position: "VP #{type}",
|
166
|
+
salary: 555_555,
|
167
|
+
health_insurance: ALL_HEALTH_INSURANCES[0],
|
168
|
+
desk_location: Employee.select_desk_location!(type),
|
169
|
+
).tap do |employee|
|
170
|
+
2.times { employee.subordinates << director(type) }
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def director(type)
|
175
|
+
Employee.new(
|
176
|
+
position: "Director #{type}",
|
177
|
+
salary: 333_333,
|
178
|
+
health_insurance: ALL_HEALTH_INSURANCES.sample,
|
179
|
+
desk_location: Employee.select_desk_location!(type),
|
180
|
+
).tap do |employee|
|
181
|
+
3.times { employee.subordinates << manager(type) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def manager(type)
|
186
|
+
Employee.new(
|
187
|
+
position: "Manager #{type}",
|
188
|
+
salary: 222_222,
|
189
|
+
health_insurance: ALL_HEALTH_INSURANCES.sample,
|
190
|
+
desk_location: Employee.select_desk_location!(type),
|
191
|
+
).tap do |employee|
|
192
|
+
employee.subordinates << employee(type, 'Senior')
|
193
|
+
employee.subordinates << employee(type, 'Standard')
|
194
|
+
employee.subordinates << employee(type, 'Junior')
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def employee(type, seniority)
|
199
|
+
seniority_title = seniority == 'Standard' ? '' : seniority
|
200
|
+
Employee.new(
|
201
|
+
position: "#{seniority_title} #{EMPLOYMENT_TYPE_POSITIONS[type]}",
|
202
|
+
salary: SENIORITY_SALARIES[seniority],
|
203
|
+
health_insurance: ALL_HEALTH_INSURANCES.sample,
|
204
|
+
desk_location: Employee.select_desk_location!(type),
|
205
|
+
)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def initialize(*args)
|
210
|
+
super(*args)
|
211
|
+
determine_type_from_position
|
212
|
+
if first_name.nil? || last_name.nil?
|
213
|
+
name = Employee.select_name!
|
214
|
+
self.first_name = name.first
|
215
|
+
self.last_name = name.last
|
216
|
+
end
|
217
|
+
self.sales_bonus_percentage = (rand*100).to_i if @type == 'Sales'
|
218
|
+
self.merit_bonus = (rand*99_999).to_i
|
219
|
+
[:work_expense, :technology_expense, :travel_expense, :client_expense, :sponsorship_expense, :food_expense, :office_expense].each do |attribute|
|
220
|
+
self.send("#{attribute}=", rand*9_999)
|
221
|
+
end
|
222
|
+
observer = Glimmer::DataBinding::Observer.proc {
|
223
|
+
notify_observers('to_s')
|
224
|
+
}
|
225
|
+
observer.observe(self, :first_name)
|
226
|
+
observer.observe(self, :last_name)
|
227
|
+
observer.observe(self, :position)
|
228
|
+
end
|
229
|
+
|
230
|
+
def determine_type_from_position(specified_position = nil)
|
231
|
+
specified_position ||= position
|
232
|
+
@type = EMPLOYMENT_TYPE_POSITIONS.keys.detect {|key| position.include?(key)}
|
233
|
+
@type = 'Sales' if position == 'CEO'
|
234
|
+
@type = 'Finance' if position == 'CFO'
|
235
|
+
@type = 'HR' if position == 'CIO'
|
236
|
+
@type = 'Engineering' if position == 'CTO'
|
237
|
+
end
|
238
|
+
|
239
|
+
def position_options
|
240
|
+
[
|
241
|
+
'CEO',
|
242
|
+
'CFO',
|
243
|
+
'CIO',
|
244
|
+
'CTO',
|
245
|
+
'VP Sales',
|
246
|
+
'VP HR',
|
247
|
+
'VP Engineering',
|
248
|
+
'VP Finance',
|
249
|
+
'Sales Director',
|
250
|
+
'HR Director',
|
251
|
+
'Engineering Director',
|
252
|
+
'Finance Director',
|
253
|
+
'Sales Manager',
|
254
|
+
'HR Manager',
|
255
|
+
'Engineering Manager',
|
256
|
+
'Finance Manager',
|
257
|
+
'Senior Sales Person',
|
258
|
+
'Sales Person',
|
259
|
+
'Junior Sales Person',
|
260
|
+
'Senior HR Staff',
|
261
|
+
'HR Staff',
|
262
|
+
'Junior HR Staff',
|
263
|
+
'Senior Engineer',
|
264
|
+
'Engineer',
|
265
|
+
'Junior Engineer',
|
266
|
+
'Senior Accountant',
|
267
|
+
'Accountant',
|
268
|
+
'Junior Accountant',
|
269
|
+
]
|
270
|
+
end
|
271
|
+
|
272
|
+
def health_insurance_options
|
273
|
+
ALL_HEALTH_INSURANCES
|
274
|
+
end
|
275
|
+
|
276
|
+
def desk_location_options
|
277
|
+
Employee.all_desk_locations
|
278
|
+
end
|
279
|
+
|
280
|
+
def subordinates
|
281
|
+
@subordinates ||= []
|
282
|
+
end
|
283
|
+
|
284
|
+
def to_s
|
285
|
+
"#{first_name} #{last_name} (#{position})"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
include Glimmer::UI::CustomShell
|
290
|
+
|
291
|
+
before_body {
|
292
|
+
Employee.selected_employee = Employee.ceo
|
293
|
+
}
|
294
|
+
|
295
|
+
after_body {
|
296
|
+
@tree.items.first.expanded = true
|
297
|
+
}
|
298
|
+
|
299
|
+
body {
|
300
|
+
shell {
|
301
|
+
fill_layout {
|
302
|
+
margin_width 15
|
303
|
+
margin_height 15
|
304
|
+
}
|
305
|
+
text 'Hello, Tree!'
|
306
|
+
minimum_size 900, 600
|
307
|
+
|
308
|
+
sash_form {
|
309
|
+
weights 1, 2
|
310
|
+
|
311
|
+
composite {
|
312
|
+
fill_layout {
|
313
|
+
margin_width 5
|
314
|
+
margin_height 5
|
315
|
+
}
|
316
|
+
@tree = tree {
|
317
|
+
items bind(Employee, :ceo), tree_properties(children: :subordinates, text: :to_s)
|
318
|
+
selection bind(Employee, :selected_employee)
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
composite {
|
323
|
+
grid_layout 2, false
|
324
|
+
|
325
|
+
label {
|
326
|
+
layout_data(:fill, :center, false, false)
|
327
|
+
text 'First Name:'
|
328
|
+
font height: 16, style: :bold
|
329
|
+
}
|
330
|
+
text {
|
331
|
+
layout_data(:fill, :center, true, false)
|
332
|
+
text bind(Employee, "selected_employee.first_name")
|
333
|
+
font height: 16
|
334
|
+
}
|
335
|
+
|
336
|
+
label {
|
337
|
+
layout_data(:fill, :center, false, false)
|
338
|
+
text 'First Name:'
|
339
|
+
font height: 16, style: :bold
|
340
|
+
}
|
341
|
+
text {
|
342
|
+
layout_data(:fill, :center, true, false)
|
343
|
+
text bind(Employee, "selected_employee.last_name")
|
344
|
+
font height: 16
|
345
|
+
}
|
346
|
+
|
347
|
+
label {
|
348
|
+
layout_data(:fill, :center, false, false)
|
349
|
+
text 'Position:'
|
350
|
+
font height: 16, style: :bold
|
351
|
+
}
|
352
|
+
combo {
|
353
|
+
layout_data(:fill, :center, true, false)
|
354
|
+
selection bind(Employee, "selected_employee.position")
|
355
|
+
font height: 16
|
356
|
+
}
|
357
|
+
|
358
|
+
label {
|
359
|
+
layout_data(:fill, :center, false, false)
|
360
|
+
text 'Salary:'
|
361
|
+
font height: 16, style: :bold
|
362
|
+
}
|
363
|
+
composite {
|
364
|
+
layout_data(:fill, :center, true, false)
|
365
|
+
row_layout {
|
366
|
+
margin_width 0
|
367
|
+
margin_height 0
|
368
|
+
}
|
369
|
+
label {
|
370
|
+
text '$'
|
371
|
+
font height: 20
|
372
|
+
}
|
373
|
+
spinner {
|
374
|
+
maximum 999_999
|
375
|
+
minimum 0
|
376
|
+
selection bind(Employee, "selected_employee.salary")
|
377
|
+
font height: 16
|
378
|
+
}
|
379
|
+
}
|
380
|
+
|
381
|
+
label {
|
382
|
+
layout_data(:fill, :center, false, false)
|
383
|
+
text 'Health Insurance:'
|
384
|
+
font height: 16, style: :bold
|
385
|
+
}
|
386
|
+
combo(:read_only) {
|
387
|
+
layout_data(:fill, :center, true, false)
|
388
|
+
selection bind(Employee, "selected_employee.health_insurance")
|
389
|
+
font height: 16
|
390
|
+
}
|
391
|
+
|
392
|
+
label {
|
393
|
+
layout_data(:fill, :center, false, false)
|
394
|
+
text 'Desk Location:'
|
395
|
+
font height: 16, style: :bold
|
396
|
+
}
|
397
|
+
combo(:read_only) {
|
398
|
+
layout_data(:fill, :center, true, false)
|
399
|
+
selection bind(Employee, "selected_employee.desk_location")
|
400
|
+
font height: 16
|
401
|
+
}
|
402
|
+
|
403
|
+
label {
|
404
|
+
layout_data(:fill, :center, false, false)
|
405
|
+
text 'Sales Bonus Percentage:'
|
406
|
+
font height: 16, style: :bold
|
407
|
+
}
|
408
|
+
composite {
|
409
|
+
layout_data(:fill, :center, true, false)
|
410
|
+
row_layout {
|
411
|
+
margin_width 0
|
412
|
+
margin_height 0
|
413
|
+
}
|
414
|
+
spinner {
|
415
|
+
maximum 100
|
416
|
+
minimum 0
|
417
|
+
selection bind(Employee, "selected_employee.sales_bonus_percentage")
|
418
|
+
font height: 16
|
419
|
+
}
|
420
|
+
label {
|
421
|
+
text '%'
|
422
|
+
font height: 20
|
423
|
+
}
|
424
|
+
}
|
425
|
+
|
426
|
+
label {
|
427
|
+
layout_data(:fill, :center, false, false)
|
428
|
+
text 'Merit Bonus:'
|
429
|
+
font height: 16, style: :bold
|
430
|
+
}
|
431
|
+
composite {
|
432
|
+
layout_data(:fill, :center, true, false)
|
433
|
+
row_layout {
|
434
|
+
margin_width 0
|
435
|
+
margin_height 0
|
436
|
+
}
|
437
|
+
label {
|
438
|
+
text '$'
|
439
|
+
font height: 20
|
440
|
+
}
|
441
|
+
spinner {
|
442
|
+
maximum 999_999
|
443
|
+
minimum 0
|
444
|
+
selection bind(Employee, "selected_employee.merit_bonus")
|
445
|
+
font height: 16
|
446
|
+
}
|
447
|
+
}
|
448
|
+
|
449
|
+
[:work_expense, :technology_expense, :travel_expense, :client_expense, :sponsorship_expense, :food_expense, :office_expense].each do |attribute|
|
450
|
+
label {
|
451
|
+
layout_data(:fill, :center, false, false)
|
452
|
+
text "#{attribute.to_s.split('_').map(&:capitalize).join(' ')}:"
|
453
|
+
font height: 16, style: :bold
|
454
|
+
}
|
455
|
+
composite {
|
456
|
+
layout_data(:fill, :center, true, false)
|
457
|
+
row_layout {
|
458
|
+
margin_width 0
|
459
|
+
margin_height 0
|
460
|
+
}
|
461
|
+
label {
|
462
|
+
text '$'
|
463
|
+
font height: 20
|
464
|
+
}
|
465
|
+
spinner {
|
466
|
+
digits 2
|
467
|
+
maximum 999_999_00
|
468
|
+
minimum 0
|
469
|
+
increment 100
|
470
|
+
selection bind(Employee, "selected_employee.#{attribute}", on_read: ->(v) {v.to_f * 100}, on_write: ->(v) {v.to_f / 100})
|
471
|
+
font height: 16
|
472
|
+
}
|
473
|
+
}
|
474
|
+
end
|
475
|
+
|
476
|
+
}
|
477
|
+
|
478
|
+
}
|
479
|
+
|
480
|
+
}
|
481
|
+
|
482
|
+
}
|
483
|
+
end
|
484
|
+
|
485
|
+
HelloTree.launch
|