glimmer-dsl-swing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecbd6a72ae4955c7f90995ef135f1aac59fc4b3294377fa4b7957b1b22069715
4
+ data.tar.gz: a58db866e29fd2d2f6620314918b629a94095cbe717ce7ca6c998d30a6d4348d
5
+ SHA512:
6
+ metadata.gz: 1c675e8abe364913657308555622a3969d7eed06b0e95894946686fa01e9493bf56e2a016bb5c135edcb1e6ac2a11fea91809c248724257f2d2ab4db59607d0a
7
+ data.tar.gz: a7c4ccc5cac6eececddf64760737c9765f9ef7c9b40efa6a6a77eb326b2257a425d222297087cb3a93a9589b215d9edbe8ddff27452ac0fcc14582aab228b6b8
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ ## 0.0.1
4
+
5
+ - Initial version of Glimmer DSL for Swing
6
+ - General component support
7
+ - General component property support
8
+ - General component listener support
9
+ - Hello, World! sample
10
+ - Hello, Button! sample
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
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.
data/README.md ADDED
@@ -0,0 +1,199 @@
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for Swing 0.0.1
2
+ ## JRuby Swing Desktop Development GUI Library
3
+ [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swing.svg)](http://badge.fury.io/rb/glimmer-dsl-swing)
4
+ [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
+
6
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) enables building desktop applications with [Java Swing](https://docs.oracle.com/javase/tutorial/uiswing/), [Java AWT](https://docs.oracle.com/javase/8/docs/technotes/guides/awt/index.html), [Java Foundation Classes](https://docs.oracle.com/javase/tutorial/uiswing/start/about.html) and [Java 2D](https://docs.oracle.com/javase/tutorial/2d/index.html) via [JRuby](https://www.jruby.org/).
7
+
8
+ There has been a great divide between two big GUI toolkits in Java in the past:
9
+ - [Eclipse SWT](https://www.eclipse.org/swt/)
10
+ - [Java Swing/AWT/JFC/2D](https://docs.oracle.com/javase/tutorial/uiswing/)
11
+
12
+ [Glimmer](https://github.com/AndyObtiva/glimmer) intentionally avoided [Swing](https://docs.oracle.com/javase/tutorial/uiswing/)-like GUI toolkits in the past because they produced non-native looking graphical user interfaces that not only looked out of place in various operating systems, but also degraded usability, user experience, and the professional look of applications significantly, especially given that unlike [SWT](https://www.eclipse.org/swt/), [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) performance is affected by [Java Garbage Collection](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/performissues003.html) pauses. As such, [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) was initially born as the premiere [Glimmer](https://github.com/AndyObtiva/glimmer) DSL.
13
+
14
+ That said, from a balanced software engineering point of view, there are sometimes non-functional requirements that might target [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) as an appropriate GUI toolkit solution. Like in the case of extending legacy [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) applications or developing rare applications that require fully custom looking graphical user interfaces (typically not recommended), such as traffic control planning or diagramming applications. In the latter case, it would not matter whether to use [SWT](https://www.eclipse.org/swt/) or [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) as they both provide support for building non-native components (in addition to native widgets in the case of [SWT](https://www.eclipse.org/swt/)).
15
+
16
+ [Glimmer DSL for Swing](https://rubygems.org/gems/glimmer-dsl-swing) aims to supercharge productivity and maintainability in developing [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) applications by providing a DSL similar to [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) having:
17
+ - Declarative DSL syntax that visually maps to the GUI component hierarchy
18
+ - Convention over configuration via smart defaults and automation of low-level details
19
+ - Requiring the least amount of syntax possible to build GUI
20
+ - Custom Keyword support
21
+ - Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
22
+ - Scaffolding for new custom components, apps, and gems
23
+ - Native-Executable packaging on Mac, Windows, and Linux.
24
+
25
+ Hello, World!
26
+
27
+ ![screenshots/glimmer-dsl-swing-mac-hello-world.png](screenshots/glimmer-dsl-swing-mac-hello-world.png)
28
+
29
+ ```ruby
30
+ jframe('Hello, World!') {
31
+ jlabel('Hello, World!')
32
+ }.show
33
+ ```
34
+
35
+ NOTE: Glimmer DSL for Swing is currently in early alpha mode (incomplete proof-of-concept). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
36
+
37
+ Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
38
+ - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
39
+ - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Pure Ruby Web GUI and Auto-Webifier of Desktop Apps)
40
+ - [glimmer-dsl-tk](https://github.com/AndyObtiva/glimmer-dsl-tk): Glimmer DSL for Tk (MRI Ruby Desktop Development GUI Library)
41
+ - [glimmer-dsl-gtk](https://github.com/AndyObtiva/glimmer-dsl-gtk): Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library)
42
+ - [glimmer-dsl-libui](https://github.com/AndyObtiva/glimmer-dsl-libui): Glimmer DSL for Tk (Prerequisite-Free Ruby Desktop Development GUI Library)
43
+ - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
44
+ - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS
45
+
46
+ ## Prerequisites
47
+
48
+ - JDK 8 (find at https://www.oracle.com/java/technologies/downloads/#java8)
49
+ - [RVM](http://rvm.io) on Mac & Linux (not available on Windows)
50
+ - JRuby 9.2.19.0 (supporting Ruby 2.5.x syntax) (get via [RVM](http://rvm.io) on Mac and Linux by running `rvm install jruby-9.2.19.0`; On Windows, find at [https://www.jruby.org/download](https://www.jruby.org/download))
51
+
52
+ Note: On the Mac, if you have [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) installed, and it added `export JRUBY_OPTS="$JRUBY_OPTS -J-XstartOnFirstThread"` to your `.zprofile`, `.zshrc`, `.bash_profile`, or `.bashrc`, make sure to disable it before using Glimmer DSL for Swing. Unfortunately, it is not compatible with it and will hang its apps until disabled.
53
+
54
+ ## Setup
55
+
56
+ ### Option 1: Install
57
+
58
+ Run this command to install directly:
59
+ ```
60
+ gem install glimmer-dsl-swing
61
+ ```
62
+
63
+ ### Option 2: Bundler
64
+
65
+ Add the following to `Gemfile`:
66
+ ```
67
+ gem 'glimmer-dsl-swing', '~> 0.0.1'
68
+ ```
69
+
70
+ And, then run:
71
+ ```
72
+ bundle
73
+ ```
74
+
75
+ ## Usage
76
+
77
+ Require the library and mixin the `Glimmer` module to utilize the Glimmer GUI DSL for Swing:
78
+
79
+ ```ruby
80
+ require 'glimmer-dsl-swing'
81
+
82
+ include Glimmer
83
+
84
+ jframe('Hello, World!') {
85
+ jlabel('Hello, World!')
86
+ }.show
87
+ ```
88
+
89
+ ## Girb (Glimmer IRB)
90
+
91
+ You can run the `girb` command (`bin/girb` if you cloned the project locally):
92
+
93
+ ```
94
+ girb
95
+ ```
96
+
97
+ This gives you `irb` with the `glimmer-dsl-gtk` gem loaded and the `Glimmer` module mixed into the main object for easy experimentation with GUI.
98
+
99
+ ## Samples
100
+
101
+ ### Hello Samples
102
+
103
+ #### Hello, World!
104
+
105
+ ![screenshots/glimmer-dsl-swing-mac-hello-world.png](screenshots/glimmer-dsl-swing-mac-hello-world.png)
106
+
107
+ ```ruby
108
+ require 'glimmer-dsl-swing'
109
+
110
+ include Glimmer
111
+
112
+ jframe('Hello, World!') {
113
+ jlabel('Hello, World!')
114
+ }.show
115
+ ```
116
+
117
+ #### Hello, Button!
118
+
119
+ ![screenshots/glimmer-dsl-swing-mac-hello-button.png](screenshots/glimmer-dsl-swing-mac-hello-button.png)
120
+
121
+ ```ruby
122
+ require 'glimmer-dsl-swing'
123
+
124
+ include Glimmer
125
+
126
+ jframe('Hello, Button!') {
127
+ @button = jbutton('Click To Increment: 0') {
128
+ on_action_performed {
129
+ button_text_match = @button.text.match(/(.*)(\d+)$/)
130
+ count = button_text_match[2].to_i + 1
131
+ @button.text = "#{button_text_match[1]}#{count}"
132
+ }
133
+ }
134
+ }.show
135
+ ```
136
+
137
+ ## Resources
138
+
139
+ - Oracle Swing Tutorial: https://docs.oracle.com/javase/tutorial/uiswing/
140
+ - Oracle Java 2D Tutorial: https://docs.oracle.com/javase/tutorial/2d/index.html
141
+ - Oracle Swing JavaDoc: https://docs.oracle.com/javase/8/docs/api/javax/swing/package-summary.html
142
+ - Oracle AWT JavaDoc: https://docs.oracle.com/javase/8/docs/api/java/awt/package-summary.html
143
+ - Oracle AWT Geom JavaDoc: https://docs.oracle.com/javase/8/docs/api/java/awt/geom/package-summary.html
144
+
145
+ ## Process
146
+
147
+ [Glimmer Process](https://github.com/AndyObtiva/glimmer/blob/master/PROCESS.md)
148
+
149
+ ## Help
150
+
151
+ ### Issues
152
+
153
+ If you encounter [issues](https://github.com/AndyObtiva/glimmer-dsl-swing/issues) that are not reported, discover missing features that are not mentioned in [TODO.md](TODO.md), or think up better ways to use [Swing](https://docs.oracle.com/javase/tutorial/uiswing/) than what is possible with [Glimmer DSL for Swing](https://rubygems.org/gems/glimmer-dsl-swing), you may submit an [issue](https://github.com/AndyObtiva/glimmer-dsl-swing/issues/new) or [pull request](https://github.com/AndyObtiva/glimmer-dsl-swing/compare) on [GitHub](https://github.com). In the meantime while waiting for a fix, you may try older gem versions of [Glimmer DSL for Swing](https://rubygems.org/gems/glimmer-dsl-swing) in case you find one that does not have the issue and actually works.
154
+
155
+ ### Chat
156
+
157
+ If you need live help, try to [![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
158
+
159
+ ## Planned Features and Feature Suggestions
160
+
161
+ These features have been planned or suggested. You might see them in a future version of [Glimmer DSL for Swing](https://rubygems.org/gems/glimmer-dsl-swing). You are welcome to contribute more feature suggestions.
162
+
163
+ [TODO.md](TODO.md)
164
+
165
+ ## Change Log
166
+
167
+ [CHANGELOG.md](CHANGELOG.md)
168
+
169
+ ## Contributing
170
+
171
+ - Check out the latest master to make sure the feature hasn't been
172
+ implemented or the bug hasn't been fixed yet.
173
+ - Check out the issue tracker to make sure someone already hasn't
174
+ requested it and/or contributed it.
175
+ - Fork the project.
176
+ - Start a feature/bugfix branch.
177
+ - Commit and push until you are happy with your contribution.
178
+ - Make sure to add tests for it. This is important so I don't break it
179
+ in a future version unintentionally.
180
+ - Please try not to mess with the Rakefile, version, or history. If
181
+ you want to have your own version, or is otherwise necessary, that
182
+ is fine, but please isolate to its own commit so I can cherry-pick
183
+ around it.
184
+
185
+ ## Contributors
186
+
187
+ * [Andy Maleh](https://github.com/AndyObtiva) (Founder)
188
+
189
+ [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-swing/graphs/contributors)
190
+
191
+ ## Copyright
192
+
193
+ [MIT](LICENSE.txt)
194
+
195
+ Copyright (c) 2021 Andy Maleh.
196
+
197
+ --
198
+
199
+ [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (DSL Framework).
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/girb ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env jruby
2
+
3
+ # Copyright (c) 2007-2021 Andy Maleh
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining
6
+ # a copy of this software and associated documentation files (the
7
+ # "Software"), to deal in the Software without restriction, including
8
+ # without limitation the rights to use, copy, modify, merge, publish,
9
+ # distribute, sublicense, and/or sell copies of the Software, and to
10
+ # permit persons to whom the Software is furnished to do so, subject to
11
+ # the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ # This script was written for Windows and Linux only
25
+
26
+ ENV['JRUBY_OPTS'] = ARGV.select {|arg| arg.start_with?('-')}.join(' ')
27
+
28
+ require_relative 'girb_runner'
29
+
30
+ require 'irb'
31
+
32
+ IRB.start('.')
@@ -0,0 +1,29 @@
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 'puts_debuggerer'
23
+ require_relative '../lib/glimmer-dsl-swing'
24
+
25
+ trap "SIGINT" do
26
+ # No Op for irb
27
+ end
28
+
29
+ include Glimmer
Binary file
@@ -0,0 +1,59 @@
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/dsl/parent_expression'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Swing
28
+ class ComponentExpression < Expression
29
+ include ParentExpression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/)
33
+ Glimmer::Swing::ComponentProxy.exist?(keyword)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/)
38
+ Glimmer::Swing::ComponentProxy.create(parent, keyword, *args, &block)
39
+ end
40
+
41
+ def add_content(parent, keyword, *args, &block)
42
+ super
43
+ parent.post_add_content
44
+ end
45
+
46
+ # def around(parent, keyword, args, block, &interpret_and_add_content)
47
+ # if parent.nil? && keyword == 'jframe'
48
+ # Java::JavaxSwing::SwingUtilities.invoke_later(&interpret_and_add_content)
49
+ #
50
+ # else
51
+ # super
52
+ # end
53
+ # end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ require 'glimmer/swing/component_proxy'
@@ -0,0 +1,46 @@
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/engine'
23
+ Dir[File.expand_path('*_expression.rb', __dir__)].each {|f| require f}
24
+
25
+ # Glimmer DSL expression configuration module
26
+ #
27
+ # When DSL engine interprets an expression, it attempts to handle
28
+ # with expressions listed here in the order specified.
29
+
30
+ # Every expression has a corresponding Expression subclass
31
+ # in glimmer/dsl
32
+
33
+ module Glimmer
34
+ module DSL
35
+ module Swing
36
+ Engine.add_dynamic_expressions(
37
+ Swing,
38
+ %w[
39
+ listener
40
+ property
41
+ component
42
+ ]
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,51 @@
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
+
24
+ module Glimmer
25
+ module DSL
26
+ module Swing
27
+ # Widget, Shape, and Display listener experssion
28
+ class ListenerExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ Glimmer::Config.logger.debug {"keyword starts with on_: #{keyword.start_with?('on_')}"}
31
+ return false unless keyword.start_with?('on_')
32
+ proper_parent = parent.respond_to?(:original)
33
+ Glimmer::Config.logger.debug {"parent #{parent} is a widget, shape, or display: #{proper_parent}"}
34
+ return false unless proper_parent
35
+ Glimmer::Config.logger.debug {"block exists?: #{!block.nil?}"}
36
+ raise Glimmer::Error, "Listener is missing block for keyword: #{keyword}" unless block_given?
37
+ Glimmer::Config.logger.debug {"args are empty?: #{args.empty?}"}
38
+ raise Glimmer::Error, "Invalid listener arguments for keyword: #{keyword}(#{args})" unless args.empty?
39
+ result = parent.can_handle_observation_request?(keyword)
40
+ Glimmer::Config.logger.debug {"can add listener? #{result}"}
41
+ raise Glimmer::Error, "Invalid listener keyword: #{keyword}" unless result
42
+ true
43
+ end
44
+
45
+ def interpret(parent, keyword, *args, &block)
46
+ parent.handle_observation_request(keyword, &block)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ 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/swing/component_proxy'
24
+
25
+ module Glimmer
26
+ module DSL
27
+ module Swing
28
+ class PropertyExpression < Expression
29
+ def can_interpret?(parent, keyword, *args, &block)
30
+ parent.is_a?(Glimmer::Swing::ComponentProxy) 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,48 @@
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 Swing
24
+ # Proxy for component listeners
25
+ #
26
+ # Follows the Proxy Design Pattern
27
+ class ComponentListenerProxy
28
+ attr_reader :component, :listener, :component_add_listener_method, :listener_class, :listener_method
29
+
30
+ def initialize(component: nil, listener:, component_add_listener_method: nil, listener_class: nil, listener_method: nil)
31
+ @component = component
32
+ @listener = listener
33
+ @component_add_listener_method = component_add_listener_method
34
+ @listener_class = listener_class
35
+ @listener_method = listener_method
36
+ end
37
+
38
+ def component_remove_listener_method
39
+ @component_add_listener_method.sub('add', 'remove')
40
+ end
41
+
42
+ def deregister
43
+ @component.send(component_remove_listener_method, @listener)
44
+ end
45
+ alias unregister deregister # TODO consider dropping unregister (and in Observer too)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,58 @@
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/swing/component_proxy'
23
+
24
+ module Glimmer
25
+ module Swing
26
+ class ComponentProxy
27
+ # Proxy for Swing JFrame objects
28
+ #
29
+ # Follows the Proxy Design Pattern
30
+ class JFrameProxy < ComponentProxy
31
+ DEFAULT_WIDTH = 190
32
+ DEFAULT_HEIGHT = 150
33
+
34
+ def post_add_content
35
+ unless @initial_content_added
36
+ @initial_content_added = true
37
+ the_width = width == 0 ? DEFAULT_WIDTH : width
38
+ the_height = height == 0 ? DEFAULT_HEIGHT : height
39
+ set_minimum_size(Java::JavaAwt::Dimension.new(the_width, the_height))
40
+ set_default_close_operation(Java::JavaxSwing::JFrame::EXIT_ON_CLOSE)
41
+ end
42
+ end
43
+
44
+ def show
45
+ unless @shown_at_least_once
46
+ @shown_at_least_once = true
47
+ Java::JavaxSwing::SwingUtilities.invoke_later do
48
+ pack
49
+ set_visible(true)
50
+ end
51
+ else
52
+ set_visible(true)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end