glimmer-dsl-swing 0.0.2 → 0.0.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 +6 -0
- data/README.md +129 -6
- data/VERSION +1 -1
- data/glimmer-dsl-swing.gemspec +0 -0
- data/lib/glimmer/dsl/swing/observe_expression.rb +35 -0
- data/lib/glimmer/swing/component_proxy.rb +2 -0
- data/lib/glimmer-dsl-swing.rb +1 -1
- data/samples/hello/hello_button2.rb +33 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ffbe12ad885326f61aa37073604e1df424e538d33bd6a05653598c017c4c78
|
4
|
+
data.tar.gz: cbef6588edb062f6079fd55b1af4f4de8dd691fbe3c4a350176c3d179c2e4e5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b6a0d7b707ad99af3ca49a769edd5376a75d961190c87a4677cf9d5d8ba11b2b47cfd19f19b1391e381a13158783d88d7507711c2cb8bbc5d11c4ec03512fb
|
7
|
+
data.tar.gz: 7daff7909124ea6303d905821868116c91c15db4e2a467f47c2f6e9d729877316d9bbee340a3930c401a57184e38235f4b8af49356dd6820325e98fb25cf499c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.0.3
|
4
|
+
|
5
|
+
- Support `observe` keyword for observing model attributes to update the View
|
6
|
+
- Support adding `include Glimmer` inside a class
|
7
|
+
- Hello, Button! sample version 2 (decoupled view using `observe` keyword)
|
8
|
+
|
3
9
|
## 0.0.2
|
4
10
|
|
5
11
|
- General Java 2D shape support by nesting under any component
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
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
|
+
# [<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.3
|
2
2
|
## JRuby Swing Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swing.svg)](http://badge.fury.io/rb/glimmer-dsl-swing)
|
4
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)
|
@@ -14,8 +14,8 @@ There has been a great divide between two big GUI toolkits in Java in the past:
|
|
14
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
15
|
|
16
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
|
17
|
+
- [Declarative DSL syntax](#glimmer-gui-dsl) that visually maps to the GUI component hierarchy
|
18
|
+
- Convention over configuration via [smart defaults and automation of low-level details](#smart-defaults-and-conventions)
|
19
19
|
- Requiring the least amount of syntax possible to build GUI
|
20
20
|
- Custom Keyword support
|
21
21
|
- Bidirectional Data-Binding to declaratively wire and automatically synchronize GUI with Business Models
|
@@ -57,14 +57,14 @@ Note: On the Mac, if you have [Glimmer DSL for SWT](https://github.com/AndyObtiv
|
|
57
57
|
|
58
58
|
Run this command to install directly:
|
59
59
|
```
|
60
|
-
gem install glimmer-dsl-swing
|
60
|
+
gem install glimmer-dsl-swing -v0.0.3
|
61
61
|
```
|
62
62
|
|
63
63
|
### Option 2: Bundler
|
64
64
|
|
65
65
|
Add the following to `Gemfile`:
|
66
66
|
```
|
67
|
-
gem 'glimmer-dsl-swing', '
|
67
|
+
gem 'glimmer-dsl-swing', '0.0.3'
|
68
68
|
```
|
69
69
|
|
70
70
|
And, then run:
|
@@ -86,6 +86,24 @@ jframe('Hello, World!') {
|
|
86
86
|
}.show
|
87
87
|
```
|
88
88
|
|
89
|
+
For actual application development outside of simple demos, mixin the `Glimmer` module into a custom application class instead:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
require 'glimmer-dsl-swing'
|
93
|
+
|
94
|
+
class SomeApplication
|
95
|
+
include Glimmer
|
96
|
+
|
97
|
+
def launch
|
98
|
+
jframe('Hello, World!') {
|
99
|
+
jlabel('Hello, World!')
|
100
|
+
}.show
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
SomeApplication.new.launch
|
105
|
+
```
|
106
|
+
|
89
107
|
## Glimmer GUI DSL
|
90
108
|
|
91
109
|
The Glimmer GUI DSL enables development of desktop graphical user interfaces in a manner similar to HTML, but in one language, Ruby, thus avoiding the multi-language separation dissonance encountered on the web, especially given that Ruby looping/conditional constructs do not need scriptlets to be added around View code. This makes desktop development extremely productive.
|
@@ -165,6 +183,60 @@ frame1 = jframe('Hello, World!') {
|
|
165
183
|
frame1.show
|
166
184
|
```
|
167
185
|
|
186
|
+
Despite `#show` being deprecated in the Java API, it is recommended to use `#show` instead of `visible=` in the Glimmer GUI DSL because it has less awkward syntax (it calls `visible=` behind the scenes to avoid the deprecated API). `#show` also invokes `pack` automatically on first run, and ensures utilizing `SwingUtilities.invokeLater` behind the scenes.
|
187
|
+
|
188
|
+
6 - Observe Model Attributes
|
189
|
+
|
190
|
+
In Smalltalk-MVC ([Model View Controller](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) Architectural Pattern), the View is an active View that observes the Model for changes and updates itself.
|
191
|
+
|
192
|
+
![MVC](https://camo.githubusercontent.com/0651c35cc70c5ba422876936733b07667368835bbd3cdbf5e706151410bdea04/68747470733a2f2f7777772e7265736561726368676174652e6e65742f70726f66696c652f44616e6e792d5765796e732f7075626c69636174696f6e2f3236393330333631312f6669677572652f666967322f41533a38353831333330353634363238363640313538313630363237323830302f536d616c6c74616c6b38302d4d56432d7061747465726e2d566965772d616e642d436f6e74726f6c6c65722d776f726b2d61732d612d706169722d616c6c6f77696e672d7468652d757365722d746f2d696e7465726163742e70706d)
|
193
|
+
|
194
|
+
This can be achieved with the Glimmer GUI DSL using the `observe` keyword, which takes a model (any object, including `self`) and attribute Symbol or String expression (e.g. `:count` or `'address.street'`).
|
195
|
+
|
196
|
+
The model is automatically enhanced as an `Glimmer::DataBinding::ObservableModel` / `Glimmer::DataBinding::ObservableHash` / `Glimmer::DataBinding::ObservableArray` depending on its type to support notifying observers of attribute changes (when performed using the attribute writer, which automatically calls added method `notify_observers(attribute)`)
|
197
|
+
|
198
|
+
Note that it is usually recommended to observe external model objects (not `self`), but `self` is OK in very simple cases or presentation-related attributes only.
|
199
|
+
|
200
|
+
Example:
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
require 'glimmer-dsl-swing'
|
204
|
+
|
205
|
+
class Counter
|
206
|
+
attr_accessor :count
|
207
|
+
|
208
|
+
def initialize
|
209
|
+
self.count = 0
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class HelloButton
|
214
|
+
include Glimmer
|
215
|
+
|
216
|
+
def initialize
|
217
|
+
@counter = Counter.new
|
218
|
+
|
219
|
+
observe(@counter, :count) do |new_count|
|
220
|
+
@button.text = "Click To Increment: #{new_count}"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def launch
|
225
|
+
jframe('Hello, Button!') {
|
226
|
+
@button = jbutton('Click To Increment: 0') {
|
227
|
+
on_action_performed do
|
228
|
+
@counter.count += 1
|
229
|
+
end
|
230
|
+
}
|
231
|
+
}.show
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
HelloButton.new.launch
|
236
|
+
```
|
237
|
+
|
238
|
+
![screenshots/glimmer-dsl-swing-mac-hello-button.png](screenshots/glimmer-dsl-swing-mac-hello-button.png)
|
239
|
+
|
168
240
|
### Shape DSL
|
169
241
|
|
170
242
|
[Glimmer DSL for Swing](https://rubygems.org/gems/glimmer-dsl-swing) might be the only Ruby Swing DSL out there that supports an additional Shape DSL.
|
@@ -175,6 +247,8 @@ Simply utilize underscored shape names from the `java.awt.geom` [package classes
|
|
175
247
|
|
176
248
|
For example, `Arc2D` becomes simply `arc`.
|
177
249
|
|
250
|
+
Glimmer utilizes the `Double` variation of shape classes.
|
251
|
+
|
178
252
|
Additionally, you can set `draw_color` or `fill_color` property as an rgb/rgba hash (e.g. `r: 255, g: 0, b: 0`)
|
179
253
|
|
180
254
|
Example:
|
@@ -233,6 +307,11 @@ jframe('Hello, Shapes!') {
|
|
233
307
|
|
234
308
|
![screenshots/glimmer-dsl-swing-mac-hello-shapes.png](screenshots/glimmer-dsl-swing-mac-hello-shapes.png)
|
235
309
|
|
310
|
+
## Smart Defaults and Conventions
|
311
|
+
|
312
|
+
- `jframe` automatically invokes `pack` on first run of `show`, and ensures utilizing `SwingUtilities.invokeLater` behind the scenes.
|
313
|
+
- When nesting a shape under a [swing](https://docs.oracle.com/javase/8/docs/api/javax/swing/package-summary.html)/[awt](https://docs.oracle.com/javase/8/docs/api/java/awt/package-summary.html) component, it is automatically added to shapes to paint on top of component (after painting component itself).
|
314
|
+
|
236
315
|
## Girb (Glimmer IRB)
|
237
316
|
|
238
317
|
You can run the `girb` command (`bin/girb` if you cloned the project locally):
|
@@ -241,7 +320,7 @@ You can run the `girb` command (`bin/girb` if you cloned the project locally):
|
|
241
320
|
girb
|
242
321
|
```
|
243
322
|
|
244
|
-
This gives you `irb` with the `glimmer-dsl-
|
323
|
+
This gives you `irb` with the `glimmer-dsl-swing` gem loaded and the `Glimmer` module mixed into the main object for easy experimentation with GUI.
|
245
324
|
|
246
325
|
## Samples
|
247
326
|
|
@@ -263,6 +342,8 @@ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_world.rb
|
|
263
342
|
|
264
343
|
![screenshots/glimmer-dsl-swing-mac-hello-world.png](screenshots/glimmer-dsl-swing-mac-hello-world.png)
|
265
344
|
|
345
|
+
[samples/hello/hello_world.rb](samples/hello/hello_world.rb):
|
346
|
+
|
266
347
|
```ruby
|
267
348
|
require 'glimmer-dsl-swing'
|
268
349
|
|
@@ -289,6 +370,8 @@ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_button.rb
|
|
289
370
|
|
290
371
|
![screenshots/glimmer-dsl-swing-mac-hello-button.png](screenshots/glimmer-dsl-swing-mac-hello-button.png)
|
291
372
|
|
373
|
+
Version 1 (without model) - [samples/hello/hello_button.rb](samples/hello/hello_button.rb):
|
374
|
+
|
292
375
|
```ruby
|
293
376
|
require 'glimmer-dsl-swing'
|
294
377
|
|
@@ -305,6 +388,44 @@ jframe('Hello, Button!') {
|
|
305
388
|
}.show
|
306
389
|
```
|
307
390
|
|
391
|
+
Version 2 (with model) - [samples/hello/hello_button2.rb](samples/hello/hello_button2.rb):
|
392
|
+
|
393
|
+
```ruby
|
394
|
+
require 'glimmer-dsl-swing'
|
395
|
+
|
396
|
+
class Counter
|
397
|
+
attr_accessor :count
|
398
|
+
|
399
|
+
def initialize
|
400
|
+
self.count = 0
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
class HelloButton
|
405
|
+
include Glimmer
|
406
|
+
|
407
|
+
def initialize
|
408
|
+
@counter = Counter.new
|
409
|
+
|
410
|
+
observe(@counter, :count) do |new_count|
|
411
|
+
@button.text = "Click To Increment: #{new_count}"
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
def launch
|
416
|
+
jframe('Hello, Button!') {
|
417
|
+
@button = jbutton('Click To Increment: 0') {
|
418
|
+
on_action_performed do
|
419
|
+
@counter.count += 1
|
420
|
+
end
|
421
|
+
}
|
422
|
+
}.show
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
HelloButton.new.launch
|
427
|
+
```
|
428
|
+
|
308
429
|
#### Hello, Shapes!
|
309
430
|
|
310
431
|
Run with gem installed:
|
@@ -321,6 +442,8 @@ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_shapes.rb
|
|
321
442
|
|
322
443
|
![screenshots/glimmer-dsl-swing-mac-hello-shapes.png](screenshots/glimmer-dsl-swing-mac-hello-shapes.png)
|
323
444
|
|
445
|
+
[samples/hello/hello_shapes.rb](samples/hello/hello_shapes.rb):
|
446
|
+
|
324
447
|
```ruby
|
325
448
|
require 'glimmer-dsl-swing'
|
326
449
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/glimmer-dsl-swing.gemspec
CHANGED
Binary file
|
@@ -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 Swing
|
29
|
+
class ObserveExpression < StaticExpression
|
30
|
+
include TopLevelExpression
|
31
|
+
include Glimmer::DSL::ObserveExpression
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/glimmer-dsl-swing.rb
CHANGED
@@ -24,11 +24,11 @@ $LOAD_PATH.unshift(File.expand_path('.', __dir__))
|
|
24
24
|
# External requires
|
25
25
|
# require 'logging'
|
26
26
|
require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
|
27
|
+
require 'nested_inherited_jruby_include_package'
|
27
28
|
# require 'super_module'
|
28
29
|
require 'java'
|
29
30
|
require 'concurrent-ruby' # ensures glimmer relies on Concurrent data-structure classes (e.g. Concurrent::Array)
|
30
31
|
require 'glimmer'
|
31
|
-
require 'nested_inherited_jruby_include_package'
|
32
32
|
require 'os'
|
33
33
|
require 'array_include_methods'
|
34
34
|
require 'facets/string/underscore'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'glimmer-dsl-swing'
|
2
|
+
|
3
|
+
class Counter
|
4
|
+
attr_accessor :count
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.count = 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class HelloButton
|
12
|
+
include Glimmer
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@counter = Counter.new
|
16
|
+
|
17
|
+
observe(@counter, :count) do |new_count|
|
18
|
+
@button.text = "Click To Increment: #{new_count}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def launch
|
23
|
+
jframe('Hello, Button!') {
|
24
|
+
@button = jbutton('Click To Increment: 0') {
|
25
|
+
on_action_performed do
|
26
|
+
@counter.count += 1
|
27
|
+
end
|
28
|
+
}
|
29
|
+
}.show
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
HelloButton.new.launch
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-swing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
@@ -217,6 +217,7 @@ files:
|
|
217
217
|
- lib/glimmer/dsl/swing/component_expression.rb
|
218
218
|
- lib/glimmer/dsl/swing/dsl.rb
|
219
219
|
- lib/glimmer/dsl/swing/listener_expression.rb
|
220
|
+
- lib/glimmer/dsl/swing/observe_expression.rb
|
220
221
|
- lib/glimmer/dsl/swing/property_expression.rb
|
221
222
|
- lib/glimmer/dsl/swing/shape_expression.rb
|
222
223
|
- lib/glimmer/swing.rb
|
@@ -228,6 +229,7 @@ files:
|
|
228
229
|
- lib/glimmer/swing/packages.rb
|
229
230
|
- lib/glimmer/swing/shape_proxy.rb
|
230
231
|
- samples/hello/hello_button.rb
|
232
|
+
- samples/hello/hello_button2.rb
|
231
233
|
- samples/hello/hello_shapes.rb
|
232
234
|
- samples/hello/hello_world.rb
|
233
235
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-swing
|