glimmer-dsl-jfx 0.0.1

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.
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 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/static_expression'
23
+ require 'glimmer/dsl/top_level_expression'
24
+ require 'glimmer/dsl/observe_expression'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module JFX
29
+ class ObserveExpression < StaticExpression
30
+ include TopLevelExpression
31
+ include Glimmer::DSL::ObserveExpression
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 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/expression'
23
+ require 'glimmer/jfx/control_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module JFX
28
+ class OperationExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ parent.is_a?(Glimmer::JFX::ControlProxy) and
31
+ block.nil? and
32
+ parent.respond_to?(keyword, *args)
33
+ end
34
+
35
+ def interpret(parent, keyword, *args, &block)
36
+ parent.send(keyword, *args)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 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/expression'
23
+ require 'glimmer/jfx/control_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module JFX
28
+ class PropertyExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ ( parent.is_a?(Glimmer::JFX::ControlProxy) or
31
+ parent.is_a?(Glimmer::JFX::WindowProxy)
32
+ ) and
33
+ block.nil? and
34
+ parent.respond_to?("#{keyword}=", *args)
35
+ end
36
+
37
+ def interpret(parent, keyword, *args, &block)
38
+ parent.send("#{keyword}=", *args)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 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/static_expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/jfx/packages'
25
+ require 'glimmer/jfx/window_proxy'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module JFX
30
+ class WindowExpression < StaticExpression
31
+ include ParentExpression
32
+ include Glimmer::JFX::Packages
33
+
34
+ def interpret(parent, keyword, *args, &block)
35
+ Glimmer::JFX::WindowProxy.new(parent, keyword, *args, &block)
36
+ end
37
+
38
+ def add_content(parent, keyword, *args, &block)
39
+ super
40
+ parent.post_add_content
41
+ end
42
+
43
+ def around(parent, keyword, args, block, &interpret_and_add_content)
44
+ # TODO check if parent content is added and if it is not, do not have platform wrap around yield (in case of reopening content)
45
+ javafx.application.Platform.startup do
46
+ yield
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ require 'glimmer/jfx/control_proxy'
@@ -0,0 +1,52 @@
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
+ module Glimmer
23
+ module JFX
24
+ # NOT USED AT THE MOMENT THOUGH IT BECOMES USEFUL WHEN SUPPORTING REGISTRATION
25
+ # OF MULTIPLE LISTENERS ON THE SAME EVENT WITH SOME CHANGES NEEDED TO THIS CLASS
26
+ # (E.G. NO ADD_LISTENER LINGO)
27
+ #
28
+ # Proxy for control listeners
29
+ #
30
+ # Follows the Proxy Design Pattern
31
+ class ControlListenerProxy
32
+ attr_reader :control, :listener, :control_add_listener_method, :listener_class, :listener_method
33
+
34
+ def initialize(control: nil, listener:, control_add_listener_method: nil, listener_class: nil, listener_method: nil)
35
+ @control = control
36
+ @listener = listener
37
+ @control_add_listener_method = control_add_listener_method
38
+ @listener_class = listener_class
39
+ @listener_method = listener_method
40
+ end
41
+
42
+ def control_remove_listener_method
43
+ @control_add_listener_method.sub('add', 'remove')
44
+ end
45
+
46
+ def deregister
47
+ @control.send(control_remove_listener_method, @listener)
48
+ end
49
+ alias unregister deregister # TODO consider dropping unregister (and in Observer too)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,168 @@
1
+ # Copyright (c) 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/jfx/packages'
23
+
24
+ module Glimmer
25
+ module JFX
26
+ # Proxy for JavaFX control objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ControlProxy
30
+ include Packages
31
+
32
+ class << self
33
+ include Packages
34
+
35
+ def exist?(keyword)
36
+ !!control_class(keyword)
37
+ end
38
+
39
+ def create(parent, keyword, *args, &block)
40
+ control_proxy_class(keyword).new(parent, keyword, *args, &block)
41
+ end
42
+
43
+ def control_proxy_class(keyword)
44
+ begin
45
+ class_name = control_proxy_class_symbol(keyword)
46
+ Glimmer::JFX::ControlProxy.const_get(class_name)
47
+ rescue => e
48
+ Glimmer::Config.logger.debug e.full_message
49
+ Glimmer::JFX::ControlProxy
50
+ end
51
+ end
52
+
53
+ def control_proxy_class_symbol(keyword)
54
+ "#{keyword.camelcase(:upper)}Proxy".to_sym
55
+ end
56
+
57
+ def control_class_symbol(keyword)
58
+ keyword.camelcase(:upper).to_sym
59
+ end
60
+
61
+ def keyword(control_proxy_class)
62
+ control_proxy_class.to_s.underscore.sub(/_proxy$/, '')
63
+ end
64
+
65
+ def control_class_manual_entries
66
+ # add mappings for any classes (minus the namespace) that conflict with standard Ruby classes
67
+ {
68
+ # example:
69
+ # 'date_time' => Java::OrgEclipseSwtWidgets::DateTime
70
+ }
71
+ end
72
+
73
+ def control_class(keyword)
74
+ unless flyweight_control_class[keyword]
75
+ begin
76
+ control_class_name = control_class_symbol(keyword).to_s
77
+ control_class = eval(control_class_name)
78
+ unless control_class.ancestors.include?(Java::JavafxScene::Node)
79
+ control_class = control_class_manual_entries[keyword]
80
+ if control_class.nil?
81
+ Glimmer::Config.logger.debug {"Class #{control_class} matching #{keyword} is not a subclass of javafx.scene.Node"}
82
+ return nil
83
+ end
84
+ end
85
+ flyweight_control_class[keyword] = control_class
86
+ rescue SyntaxError, NameError => e
87
+ Glimmer::Config.logger.debug {e.full_message}
88
+ nil
89
+ rescue => e
90
+ Glimmer::Config.logger.debug {e.full_message}
91
+ nil
92
+ end
93
+ end
94
+ flyweight_control_class[keyword]
95
+ end
96
+
97
+ # Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
98
+ def flyweight_control_class
99
+ @flyweight_control_class ||= {}
100
+ end
101
+ end
102
+
103
+ attr_reader :parent_proxy, :jfx, :args, :keyword, :block
104
+
105
+ def initialize(parent, keyword, *args, &block)
106
+ @parent_proxy = parent
107
+ @keyword = keyword
108
+ @args = args
109
+ @block = block
110
+ build
111
+ post_add_content if @block.nil?
112
+ end
113
+
114
+ # Subclasses may override to perform post add_content work (normally must call super)
115
+ def post_add_content
116
+ @parent_proxy&.post_initialize_child(self)
117
+ end
118
+
119
+ # Subclasses may override to perform post initialization work on an added child (normally must also call super)
120
+ def post_initialize_child(child)
121
+ children.add(child.jfx) if respond_to?(:children) && child.is_a?(ControlProxy)
122
+ end
123
+
124
+ def respond_to?(method_name, *args, &block)
125
+ respond_to_jfx?(method_name, *args, &block) ||
126
+ super(method_name, true)
127
+ end
128
+
129
+ def respond_to_jfx?(method_name, *args, &block)
130
+ @jfx.respond_to?(method_name, true) || @jfx.respond_to?("set_#{method_name}", true)
131
+ end
132
+
133
+ def send_to_jfx(method_name, *args, &block)
134
+ @jfx.send(method_name, *normalize_args(args), &block)
135
+ end
136
+
137
+ def method_missing(method_name, *args, &block)
138
+ if respond_to?("#{method_name}=", true) && !args.empty?
139
+ send("#{method_name}=", *args)
140
+ elsif @jfx.respond_to?("set_#{method_name}", true) && !args.empty?
141
+ send_to_jfx("set_#{method_name}", *args, &block)
142
+ elsif @jfx.respond_to?(method_name, true)
143
+ send_to_jfx(method_name, *args, &block)
144
+ else
145
+ super
146
+ end
147
+ end
148
+
149
+ def content(&block)
150
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::JFX::ControlExpression.new, @keyword, &block)
151
+ end
152
+
153
+ private
154
+
155
+ def build
156
+ @jfx = ControlProxy.control_class(keyword).new(*normalize_args(args))
157
+ end
158
+
159
+ def normalize_args(args)
160
+ args.map do |arg|
161
+ arg.is_a?(ControlProxy) ? arg.jfx : arg
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+
168
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -0,0 +1,82 @@
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/config'
23
+
24
+ module Glimmer
25
+ module Config
26
+ DEFAULT_IMPORT_JAVA_PACKAGES = %w[
27
+ javafx.scene.chart
28
+ javafx.scene.control
29
+ javafx.scene.control.cell
30
+ javafx.scene.control.skin
31
+ javafx.animation
32
+ javafx.application
33
+ javafx.concurrent
34
+ javafx.css
35
+ javafx.css.converter
36
+ javafx.geometry
37
+ javafx.print
38
+ javafx.scene
39
+ javafx.scene.canvas
40
+ javafx.scene.effect
41
+ javafx.scene.image
42
+ javafx.scene.input
43
+ javafx.scene.layout
44
+ javafx.scene.paint
45
+ javafx.scene.robot
46
+ javafx.scene.shape
47
+ javafx.scene.text
48
+ javafx.scene.transform
49
+ javafx.stage
50
+ javafx.scene.media
51
+ javafx.embed.swing
52
+ javafx.scene.web
53
+ ]
54
+
55
+ class << self
56
+ # Tells Glimmer to import Java packages into including class (default: true)
57
+ def import_java_packages=(value)
58
+ @@import_java_packages = value
59
+ end
60
+
61
+ # Returns whether Glimmer will import SWT packages into including class
62
+ def import_java_packages
63
+ @@import_java_packages = DEFAULT_IMPORT_JAVA_PACKAGES if !defined?(@@import_java_packages) || (defined?(@@import_java_packages) && @@import_java_packages == true)
64
+ @@import_java_packages
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
74
+ method = method_symbol.to_s
75
+ result = false
76
+ return true if method == 'load_iseq'
77
+ return true if method == 'post_initialize_child'
78
+ return true if method == 'handle'
79
+ return true if method.end_with?('=')
80
+ end
81
+
82
+ Glimmer::Config.loop_max_count = 300
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 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/jfx/packages'
23
+
24
+ module Glimmer
25
+ class << self
26
+ def included(klass)
27
+ if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:Dependencies)
28
+ begin
29
+ ActiveSupport::Dependencies.unhook!
30
+ rescue => e
31
+ # noop TODO support logging unimportant details below debug level
32
+ end
33
+ end
34
+ if Config.import_java_packages
35
+ klass.include(JFX::Packages)
36
+ klass.extend(JFX::Packages)
37
+ end
38
+ klass.extend(Glimmer)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ # Copyright (c) 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/jfx/ext/glimmer/config'
23
+
24
+ module Glimmer
25
+ module JFX
26
+ # This contains Java imports of SWT Java packages
27
+ module Packages
28
+ class << self
29
+ def included(klass)
30
+ Glimmer::Config.import_java_packages.to_a.each do |package|
31
+ include_package(package) if package.is_a?(String)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,96 @@
1
+ # Copyright (c) 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/jfx/packages'
23
+ require 'glimmer/jfx/control_proxy'
24
+
25
+ module Glimmer
26
+ module JFX
27
+ # WindowProxy is a Proxy for JavaFX Stage/Scene objects, abstracing their details away.
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class WindowProxy < ControlProxy
31
+ include Packages
32
+
33
+ DEFAULT_WIDTH = 190
34
+ DEFAULT_HEIGHT = 150
35
+
36
+ attr_accessor :jfx, :scene
37
+ attr_reader :parent_proxy, :application, :args, :keyword, :block
38
+ alias stage jfx
39
+ alias stage= jfx=
40
+
41
+ def post_add_content
42
+ super
43
+ stage.width = DEFAULT_WIDTH if stage.width == 0 || stage.width.nan?
44
+ stage.height = DEFAULT_HEIGHT if stage.height == 0 || stage.height.nan?
45
+ stage.show
46
+ end
47
+
48
+ # Subclasses may override to perform post initialization work on an added child (normally must also call super)
49
+ def post_initialize_child(child)
50
+ self.scene = Scene.new(child.jfx)
51
+ stage.set_scene(scene)
52
+ end
53
+
54
+ def respond_to?(method_name, *args, &block)
55
+ respond_to_scene?(method_name, *args, &block) ||
56
+ super(method_name, true)
57
+ end
58
+
59
+ def respond_to_scene?(method_name, *args, &block)
60
+ @scene.respond_to?(method_name, true) || @scene.respond_to?("set_#{method_name}", true)
61
+ end
62
+
63
+ def send_to_scene(method_name, *args, &block)
64
+ @scene.send(method_name, *normalize_args(args), &block)
65
+ end
66
+
67
+ def method_missing(method_name, *args, &block)
68
+ if respond_to?("#{method_name}=", true) && !args.empty?
69
+ send("#{method_name}=", *args)
70
+ elsif @scene.respond_to?("set_#{method_name}", true) && !args.empty?
71
+ send_to_scene("set_#{method_name}", *args, &block)
72
+ elsif @scene.respond_to?(method_name, true)
73
+ send_to_scene(method_name, *args, &block)
74
+ else
75
+ super
76
+ end
77
+ end
78
+
79
+ def content(&block)
80
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::JFX::WindowExpression.new, @keyword, &block)
81
+ end
82
+
83
+ private
84
+
85
+ def build
86
+ self.stage = javafx.stage.Stage.new
87
+ end
88
+
89
+ def normalize_args(args)
90
+ args.map do |arg|
91
+ arg.is_a?(ControlProxy) ? arg.jfx : arg
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 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
+ module Glimmer
23
+ module JFX
24
+ end
25
+ end