glimmer-dsl-swing 0.0.1 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecbd6a72ae4955c7f90995ef135f1aac59fc4b3294377fa4b7957b1b22069715
4
- data.tar.gz: a58db866e29fd2d2f6620314918b629a94095cbe717ce7ca6c998d30a6d4348d
3
+ metadata.gz: f105e5227247c67f51be098e70d2ea1fdb1e084fcecf00f1960c838b4fd65c48
4
+ data.tar.gz: '07290abf4d15a2f70b38829ba540f3c9efd98a61cc4b8417484e30db8bfee1d6'
5
5
  SHA512:
6
- metadata.gz: 1c675e8abe364913657308555622a3969d7eed06b0e95894946686fa01e9493bf56e2a016bb5c135edcb1e6ac2a11fea91809c248724257f2d2ab4db59607d0a
7
- data.tar.gz: a7c4ccc5cac6eececddf64760737c9765f9ef7c9b40efa6a6a77eb326b2257a425d222297087cb3a93a9589b215d9edbe8ddff27452ac0fcc14582aab228b6b8
6
+ metadata.gz: e34417a4033877f520b7ead9871a734ab859fa3cfece7e02ea32d1cad4d278db870573182e46e23cbe4b037eda0a0ba8410dcf4c31a6ac63fc2b3319f16ecd71
7
+ data.tar.gz: e19f0b1bed9dea8e5cf4cc98939a83e0f00b7210ce1ef5a5b0282822a3ab11a58af95ec142dff27824789fdb9a040b14a05d082cad9da6410e99843962e93afd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.5
4
+
5
+ - Support `path`, which can primarily contain `move_to`, `line_to`, `curve_to`, `close_path` calls, and secondarily other shapes like `line` or `rectangle`.
6
+ - Support invoking component/shape operations in their content (e.g. nesting `move_to` inside `path`)
7
+
8
+ ## 0.0.4
9
+
10
+ - Support setting `stroke` attribute in shapes
11
+ - Rename `draw_color` and `fill_color` to `draw_paint` and `fill_paint` to be consistent with `java.awt.Graphics2D` terminology (while keeping older syntax as an alias/alternative)
12
+ - Enable antialiasing by default on Java 2D graphics
13
+ - Update Hello, Shapes! to take advantage of `stroke`
14
+
15
+ ## 0.0.3
16
+
17
+ - Support `observe` keyword for observing model attributes to update the View
18
+ - Support adding `include Glimmer` inside a class
19
+ - Hello, Button! sample version 2 (decoupled view using `observe` keyword)
20
+
21
+ ## 0.0.2
22
+
23
+ - General Java 2D shape support by nesting under any component
24
+ - Support setting `jframe` `minimum_size width, height` without building `Dimension` object manually
25
+ - Hello, Shapes! sample
26
+ - Improve Hello, Button! sample
27
+
3
28
  ## 0.0.1
4
29
 
5
30
  - Initial version of Glimmer DSL for Swing
data/README.md CHANGED
@@ -1,11 +1,11 @@
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
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.5
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)
5
5
 
6
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
7
 
8
- There has been a great divide between two big GUI toolkits in Java in the past:
8
+ There has been a great divide between two big GUI toolkits in Java:
9
9
  - [Eclipse SWT](https://www.eclipse.org/swt/)
10
10
  - [Java Swing/AWT/JFC/2D](https://docs.oracle.com/javase/tutorial/uiswing/)
11
11
 
@@ -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.5
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', '~> 0.0.1'
67
+ gem 'glimmer-dsl-swing', '0.0.5'
68
68
  ```
69
69
 
70
70
  And, then run:
@@ -86,6 +86,276 @@ 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
+
107
+ ## Glimmer GUI DSL
108
+
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.
110
+
111
+ 1 - Keywords
112
+
113
+ You may declare any [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 with its keyword, which is the underscored version of the class name. For example, `jframe` is the keyword for `javax.swing.JFrame` (`j_frame` is acceptable too)
114
+
115
+ Examples:
116
+
117
+ ```ruby
118
+ jframe
119
+ jbutton
120
+ jlabel
121
+ ```
122
+
123
+ 2 - Arguments
124
+
125
+ You may pass any arguments that 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 constructor accepts to its Glimmer keyword.
126
+
127
+ Example (`JFrame`, `JButton`, and `JLabel` have a constructor signature that accepts a string representing title or text):
128
+
129
+ ```ruby
130
+ jframe('Hello, World!')
131
+ jbutton('Push Me')
132
+ jlabel('Name')
133
+ ```
134
+
135
+ The recommended style is to always wrap arguments with parentheses for component keywords.
136
+
137
+ 3 - Content Block
138
+
139
+ You may pass a content block to any [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 keyword, which contains properties and/or nested components.
140
+
141
+ Example:
142
+
143
+ ```ruby
144
+ jframe('Hello, World!') {
145
+ minimum_size 320, 240
146
+
147
+ jlabel('Hello, World!')
148
+ }
149
+ ```
150
+
151
+ The recommended style for the content block is always curly braces `{}` to denote as View nesting code different from looping/conditional logic, which utilizes `do;end` instead.
152
+
153
+ Property arguments never have parentheses.
154
+
155
+ 4 - Listeners
156
+
157
+ You may declare listeners with their `on_`-prefixed event method name on the [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) listener class (these are the classes in the signatures of `AddXYZListener` methods on [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 classes).
158
+
159
+ For example, `JButton` has an `AddXYZListener` method called `AddActionListener`, which accepts an `ActionListener` class. That class has one event method: `actionPerformed`. In Glimmer, you simply underscore that and prefix with `on_`:
160
+
161
+ ```ruby
162
+ jframe('Hello, Button!') {
163
+ jbutton('Click') {
164
+ on_action_performed do
165
+ puts 'Clicked!'
166
+ end
167
+ }
168
+ }
169
+ ```
170
+
171
+ The recommended style for listeners is always a `do; end` block.
172
+
173
+ 5 - Component Proxy & Methods
174
+
175
+ When utilizing the Glimmer GUI DSL, you get back proxy objects that wrap [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) components. To access the original component wrapped by the proxy object, you may call the `#original` method.
176
+
177
+ Furthermore, you may invoke any method available on the component on the proxy object, like the `#show` method on `JFrame`.
178
+
179
+ ```ruby
180
+ frame1 = jframe('Hello, World!') {
181
+ # ...
182
+ }
183
+ frame1.show
184
+ ```
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, utilizing `SwingUtilities.invokeLater`.
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](http://3.bp.blogspot.com/-4eW59Ao0ess/ToiBzAiYdZI/AAAAAAAAAOg/SiYa6XHwBFE/s320/Screen+shot+2011-10-02+at+10.22.11+AM.png)
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
+
240
+ ### Shape DSL
241
+
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.
243
+
244
+ This enables declarative painting of arbitrary shapes using Java 2D, which is similar to how SVG works on the web.
245
+
246
+ Simply utilize underscored shape names from the `java.awt.geom` [package classes](https://docs.oracle.com/javase/8/docs/api/java/awt/geom/package-summary.html) minus the `2D` suffix, following the same general rules of the [Glimmer GUI DSL](#glimmer-gui-dsl).
247
+
248
+ For example, `Arc2D` becomes simply `arc`.
249
+
250
+ Glimmer utilizes the `Double` variation of shape classes.
251
+
252
+ Additionally, you can set these shape properties:
253
+ - `draw_paint` (alias: `draw_color`): takes [`java.awt.Color`](https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html) rgba arguments to use color for drawing
254
+ - `fill_paint` (alias: `fill_color`): takes [`java.awt.Color`](https://docs.oracle.com/javase/8/docs/api/java/awt/Color.html) rgba arguments to use color for filling
255
+ - `stroke`: takes [`java.awt.BasicStroke`](https://docs.oracle.com/javase/8/docs/api/java/awt/BasicStroke.html) line width and other arguments to use for drawing
256
+
257
+ `path` can have the following operations nested:
258
+ - `move_to x, y`: move to point
259
+ - `line_to x2, y2`: connect line to end point
260
+ - `curve_to ctrl_x1, ctrl_y1, ctrl_x2, ctrl_y2, x2, y2`: connect curve to control point 1, control point 2, and end point
261
+ - `close_path`: close path, reconnecting last shape/point back to first point
262
+
263
+ Example:
264
+
265
+ ```ruby
266
+ require 'glimmer-dsl-swing'
267
+
268
+ include Glimmer
269
+
270
+ jframe('Hello, Shapes!') {
271
+ minimum_size 400, 400
272
+
273
+ arc(40, 40, 90, 90, 30, 230, 0) {
274
+ fill_paint 255, 0, 0
275
+ draw_paint 0, 128, 255
276
+ stroke 3
277
+ }
278
+
279
+ arc(40, 140, 90, 90, 30, 230, 1) {
280
+ fill_paint 255, 0, 0
281
+ draw_paint 0, 128, 255
282
+ stroke 3
283
+ }
284
+
285
+ arc(40, 240, 90, 90, 30, 230, 2) {
286
+ fill_paint 255, 0, 0
287
+ draw_paint 0, 128, 255
288
+ stroke 3
289
+ }
290
+
291
+ rectangle(140, 40, 180, 90) {
292
+ fill_paint 255, 255, 0
293
+ draw_paint 255, 0, 0
294
+ stroke 3
295
+ }
296
+
297
+ round_rectangle(140, 140, 180, 90, 60, 40) {
298
+ fill_paint 255, 255, 0
299
+ draw_paint 255, 0, 0
300
+ stroke 3
301
+ }
302
+
303
+ ellipse(140, 240, 180, 90) {
304
+ fill_paint 255, 255, 0
305
+ draw_paint 255, 0, 0
306
+ stroke 3
307
+ }
308
+
309
+ line(180, 60, 280, 110) {
310
+ draw_paint 255, 0, 0
311
+ stroke 3
312
+ }
313
+
314
+ quad_curve(170, 60, 180, 90, 220, 100) {
315
+ draw_paint 0, 255, 0
316
+ stroke 3
317
+ }
318
+
319
+ cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
320
+ draw_paint 0, 0, 255
321
+ stroke 3
322
+ }
323
+
324
+ path {
325
+ move_to 200, 150
326
+ line_to 270, 170
327
+ line_to 250, 220
328
+ line_to 220, 190
329
+ line_to 200, 200
330
+ line_to 180, 170
331
+
332
+ close_path
333
+
334
+ fill_paint 0, 255, 0
335
+ draw_paint 0, 0, 255
336
+ stroke 3
337
+ }
338
+
339
+ path {
340
+ move_to 160, 300
341
+ curve_to 190, 260, 200, 280, 210, 270
342
+ curve_to 240, 280, 250, 300, 260, 290
343
+ curve_to 290, 290, 300, 310, 310, 300
344
+
345
+ fill_paint 0, 255, 0
346
+ draw_paint 0, 0, 255
347
+ stroke 3
348
+ }
349
+ }.show
350
+ ```
351
+
352
+ ![screenshots/glimmer-dsl-swing-mac-hello-shapes.png](screenshots/glimmer-dsl-swing-mac-hello-shapes.png)
353
+
354
+ ## Smart Defaults and Conventions
355
+
356
+ - `jframe` automatically invokes `pack` on first run of `show`, and ensures utilizing `SwingUtilities.invokeLater` behind the scenes.
357
+ - 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).
358
+
89
359
  ## Girb (Glimmer IRB)
90
360
 
91
361
  You can run the `girb` command (`bin/girb` if you cloned the project locally):
@@ -94,7 +364,7 @@ You can run the `girb` command (`bin/girb` if you cloned the project locally):
94
364
  girb
95
365
  ```
96
366
 
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.
367
+ 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.
98
368
 
99
369
  ## Samples
100
370
 
@@ -102,8 +372,22 @@ This gives you `irb` with the `glimmer-dsl-gtk` gem loaded and the `Glimmer` mod
102
372
 
103
373
  #### Hello, World!
104
374
 
375
+ Run with gem installed:
376
+
377
+ ```
378
+ jruby -r glimmer-dsl-swing -e "require 'samples/hello/hello_world'"
379
+ ```
380
+
381
+ Or run from locally cloned project directory:
382
+
383
+ ```
384
+ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_world.rb
385
+ ```
386
+
105
387
  ![screenshots/glimmer-dsl-swing-mac-hello-world.png](screenshots/glimmer-dsl-swing-mac-hello-world.png)
106
388
 
389
+ [samples/hello/hello_world.rb](samples/hello/hello_world.rb):
390
+
107
391
  ```ruby
108
392
  require 'glimmer-dsl-swing'
109
393
 
@@ -116,8 +400,22 @@ jframe('Hello, World!') {
116
400
 
117
401
  #### Hello, Button!
118
402
 
403
+ Run with gem installed:
404
+
405
+ ```
406
+ jruby -r glimmer-dsl-swing -e "require 'samples/hello/hello_button'"
407
+ ```
408
+
409
+ Or run from locally cloned project directory:
410
+
411
+ ```
412
+ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_button.rb
413
+ ```
414
+
119
415
  ![screenshots/glimmer-dsl-swing-mac-hello-button.png](screenshots/glimmer-dsl-swing-mac-hello-button.png)
120
416
 
417
+ Version 1 (without model) - [samples/hello/hello_button.rb](samples/hello/hello_button.rb):
418
+
121
419
  ```ruby
122
420
  require 'glimmer-dsl-swing'
123
421
 
@@ -125,11 +423,154 @@ include Glimmer
125
423
 
126
424
  jframe('Hello, Button!') {
127
425
  @button = jbutton('Click To Increment: 0') {
128
- on_action_performed {
426
+ on_action_performed do
129
427
  button_text_match = @button.text.match(/(.*)(\d+)$/)
130
428
  count = button_text_match[2].to_i + 1
131
429
  @button.text = "#{button_text_match[1]}#{count}"
132
- }
430
+ end
431
+ }
432
+ }.show
433
+ ```
434
+
435
+ Version 2 (with model) - [samples/hello/hello_button2.rb](samples/hello/hello_button2.rb):
436
+
437
+ ```ruby
438
+ require 'glimmer-dsl-swing'
439
+
440
+ class Counter
441
+ attr_accessor :count
442
+
443
+ def initialize
444
+ self.count = 0
445
+ end
446
+ end
447
+
448
+ class HelloButton
449
+ include Glimmer
450
+
451
+ def initialize
452
+ @counter = Counter.new
453
+
454
+ observe(@counter, :count) do |new_count|
455
+ @button.text = "Click To Increment: #{new_count}"
456
+ end
457
+ end
458
+
459
+ def launch
460
+ jframe('Hello, Button!') {
461
+ @button = jbutton('Click To Increment: 0') {
462
+ on_action_performed do
463
+ @counter.count += 1
464
+ end
465
+ }
466
+ }.show
467
+ end
468
+ end
469
+
470
+ HelloButton.new.launch
471
+ ```
472
+
473
+ #### Hello, Shapes!
474
+
475
+ Run with gem installed:
476
+
477
+ ```
478
+ jruby -r glimmer-dsl-swing -e "require 'samples/hello/hello_shapes'"
479
+ ```
480
+
481
+ Or run from locally cloned project directory:
482
+
483
+ ```
484
+ jruby -r ./lib/glimmer-dsl-swing samples/hello/hello_shapes.rb
485
+ ```
486
+
487
+ ![screenshots/glimmer-dsl-swing-mac-hello-shapes.png](screenshots/glimmer-dsl-swing-mac-hello-shapes.png)
488
+
489
+ [samples/hello/hello_shapes.rb](samples/hello/hello_shapes.rb):
490
+
491
+ ```ruby
492
+ require 'glimmer-dsl-swing'
493
+
494
+ include Glimmer
495
+
496
+ jframe('Hello, Shapes!') {
497
+ minimum_size 400, 400
498
+
499
+ arc(40, 40, 90, 90, 30, 230, 0) {
500
+ fill_paint 255, 0, 0
501
+ draw_paint 0, 128, 255
502
+ stroke 3
503
+ }
504
+
505
+ arc(40, 140, 90, 90, 30, 230, 1) {
506
+ fill_paint 255, 0, 0
507
+ draw_paint 0, 128, 255
508
+ stroke 3
509
+ }
510
+
511
+ arc(40, 240, 90, 90, 30, 230, 2) {
512
+ fill_paint 255, 0, 0
513
+ draw_paint 0, 128, 255
514
+ stroke 3
515
+ }
516
+
517
+ rectangle(140, 40, 180, 90) {
518
+ fill_paint 255, 255, 0
519
+ draw_paint 255, 0, 0
520
+ stroke 3
521
+ }
522
+
523
+ round_rectangle(140, 140, 180, 90, 60, 40) {
524
+ fill_paint 255, 255, 0
525
+ draw_paint 255, 0, 0
526
+ stroke 3
527
+ }
528
+
529
+ ellipse(140, 240, 180, 90) {
530
+ fill_paint 255, 255, 0
531
+ draw_paint 255, 0, 0
532
+ stroke 3
533
+ }
534
+
535
+ line(180, 60, 280, 110) {
536
+ draw_paint 255, 0, 0
537
+ stroke 3
538
+ }
539
+
540
+ quad_curve(170, 60, 180, 90, 220, 100) {
541
+ draw_paint 0, 255, 0
542
+ stroke 3
543
+ }
544
+
545
+ cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
546
+ draw_paint 0, 0, 255
547
+ stroke 3
548
+ }
549
+
550
+ path {
551
+ move_to 200, 150
552
+ line_to 270, 170
553
+ line_to 250, 220
554
+ line_to 220, 190
555
+ line_to 200, 200
556
+ line_to 180, 170
557
+
558
+ close_path
559
+
560
+ fill_paint 0, 255, 0
561
+ draw_paint 0, 0, 255
562
+ stroke 3
563
+ }
564
+
565
+ path {
566
+ move_to 160, 300
567
+ curve_to 190, 260, 200, 280, 210, 270
568
+ curve_to 240, 280, 250, 300, 260, 290
569
+ curve_to 290, 290, 300, 310, 310, 300
570
+
571
+ fill_paint 0, 255, 0
572
+ draw_paint 0, 0, 255
573
+ stroke 3
133
574
  }
134
575
  }.show
135
576
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.5
Binary file
@@ -29,12 +29,12 @@ module Glimmer
29
29
  include ParentExpression
30
30
 
31
31
  def can_interpret?(parent, keyword, *args, &block)
32
- keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/)
32
+ keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/) # TODO move this logic to ComponentProxy
33
33
  Glimmer::Swing::ComponentProxy.exist?(keyword)
34
34
  end
35
35
 
36
36
  def interpret(parent, keyword, *args, &block)
37
- keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/)
37
+ keyword = "j_#{keyword[1..-1]}" if keyword.match(/j[a-z]/) # TODO move this logic to ComponentProxy
38
38
  Glimmer::Swing::ComponentProxy.create(parent, keyword, *args, &block)
39
39
  end
40
40
 
@@ -38,7 +38,9 @@ module Glimmer
38
38
  %w[
39
39
  listener
40
40
  property
41
+ operation
41
42
  component
43
+ shape
42
44
  ]
43
45
  )
44
46
  end
@@ -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
@@ -0,0 +1,45 @@
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
+ require 'glimmer/swing/shape_proxy'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Swing
29
+ class OperationExpression < Expression
30
+ def can_interpret?(parent, keyword, *args, &block)
31
+ (
32
+ parent.is_a?(Glimmer::Swing::ComponentProxy) or
33
+ parent.is_a?(Glimmer::Swing::ShapeProxy)
34
+ ) and
35
+ block.nil? and
36
+ parent.respond_to?(keyword, *args)
37
+ end
38
+
39
+ def interpret(parent, keyword, *args, &block)
40
+ parent.send(keyword, *args)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -27,13 +27,16 @@ module Glimmer
27
27
  module Swing
28
28
  class PropertyExpression < Expression
29
29
  def can_interpret?(parent, keyword, *args, &block)
30
- parent.is_a?(Glimmer::Swing::ComponentProxy) and
30
+ (
31
+ parent.is_a?(Glimmer::Swing::ComponentProxy) or
32
+ parent.is_a?(Glimmer::Swing::ShapeProxy)
33
+ ) and
31
34
  block.nil? and
32
- parent.respond_to?(keyword, *args)
35
+ parent.respond_to?("#{keyword}=", *args)
33
36
  end
34
37
 
35
38
  def interpret(parent, keyword, *args, &block)
36
- parent.send(keyword, *args)
39
+ parent.send("#{keyword}=", *args)
37
40
  end
38
41
  end
39
42
  end
@@ -0,0 +1,48 @@
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 ShapeExpression < Expression
29
+ include ParentExpression
30
+
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ Glimmer::Swing::ShapeProxy.exist?(keyword)
33
+ end
34
+
35
+ def interpret(parent, keyword, *args, &block)
36
+ Glimmer::Swing::ShapeProxy.create(parent, keyword, *args, &block)
37
+ end
38
+
39
+ def add_content(parent, keyword, *args, &block)
40
+ super
41
+ parent.post_add_content
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ require 'glimmer/swing/shape_proxy'
@@ -31,11 +31,21 @@ module Glimmer
31
31
  DEFAULT_WIDTH = 190
32
32
  DEFAULT_HEIGHT = 150
33
33
 
34
+ def set_minimum_size(*args)
35
+ @minimum_size_set = true
36
+ if args.size == 1 && args.first.is_a?(Java::JavaAwt::Dimension)
37
+ super
38
+ else
39
+ super(Java::JavaAwt::Dimension.new(*args))
40
+ end
41
+ end
42
+ alias minimum_size= set_minimum_size
43
+
34
44
  def post_add_content
35
45
  unless @initial_content_added
36
46
  @initial_content_added = true
37
- the_width = width == 0 ? DEFAULT_WIDTH : width
38
- the_height = height == 0 ? DEFAULT_HEIGHT : height
47
+ the_width = @minimum_size_set ? minimum_size.width : DEFAULT_WIDTH
48
+ the_height = @minimum_size_set ? minimum_size.height : DEFAULT_HEIGHT
39
49
  set_minimum_size(Java::JavaAwt::Dimension.new(the_width, the_height))
40
50
  set_default_close_operation(Java::JavaxSwing::JFrame::EXIT_ON_CLOSE)
41
51
  end
@@ -31,8 +31,10 @@ module Glimmer
31
31
  include Packages
32
32
 
33
33
  class << self
34
+ include Packages
35
+
34
36
  def exist?(keyword)
35
- !!component_proxy_class(keyword)
37
+ !!component_class(keyword)
36
38
  end
37
39
 
38
40
  def create(parent, keyword, *args, &block)
@@ -70,10 +72,10 @@ module Glimmer
70
72
  end
71
73
 
72
74
  def component_class(keyword)
73
- unless flyweight_component_class.keys.include?(keyword)
75
+ unless flyweight_component_class[keyword]
74
76
  begin
75
- pd component_class_name = component_class_symbol(keyword).to_s
76
- pd component_class = eval(component_class_name)
77
+ component_class_name = component_class_symbol(keyword).to_s
78
+ component_class = eval(component_class_name)
77
79
  unless component_class.ancestors.include?(Java::JavaAwt::Component)
78
80
  component_class = component_class_manual_entries[keyword]
79
81
  if component_class.nil?
@@ -81,6 +83,30 @@ module Glimmer
81
83
  return nil
82
84
  end
83
85
  end
86
+ component_class = Class.new(component_class) {
87
+ attr_accessor :shape_proxies
88
+
89
+ def paint(g2)
90
+ rendering_hints = RenderingHints.new(RenderingHints::KEY_ANTIALIASING, RenderingHints::VALUE_ANTIALIAS_ON)
91
+ g2.set_rendering_hints(rendering_hints)
92
+ super(g2)
93
+ shape_proxies.each do |shape_proxy|
94
+ original_paint = g2.get_paint
95
+ original_stroke = g2.get_stroke
96
+ if shape_proxy.fill_color
97
+ g2.set_paint shape_proxy.fill_paint
98
+ g2.fill(shape_proxy)
99
+ end
100
+ if shape_proxy.draw_color
101
+ g2.set_stroke shape_proxy.stroke unless shape_proxy.stroke.nil?
102
+ g2.set_paint shape_proxy.draw_paint
103
+ g2.draw(shape_proxy)
104
+ end
105
+ g2.set_paint original_paint
106
+ g2.set_stroke original_stroke || BasicStroke.new
107
+ end
108
+ end
109
+ }
84
110
  flyweight_component_class[keyword] = component_class
85
111
  rescue SyntaxError, NameError => e
86
112
  Glimmer::Config.logger.debug {e.full_message}
@@ -106,7 +132,7 @@ module Glimmer
106
132
  @keyword = keyword
107
133
  @args = args
108
134
  @block = block
109
- build_widget
135
+ build
110
136
  post_add_content if @block.nil?
111
137
  end
112
138
 
@@ -117,7 +143,15 @@ module Glimmer
117
143
 
118
144
  # Subclasses may override to perform post initialization work on an added child (normally must also call super)
119
145
  def post_initialize_child(child)
120
- add(child)
146
+ if child.is_a?(ComponentProxy)
147
+ add(child)
148
+ elsif child.is_a?(ShapeProxy)
149
+ shape_proxies << child
150
+ end
151
+ end
152
+
153
+ def shape_proxies
154
+ @shape_proxies ||= []
121
155
  end
122
156
 
123
157
  def respond_to?(method_name, *args, &block)
@@ -130,7 +164,9 @@ module Glimmer
130
164
  end
131
165
 
132
166
  def method_missing(method_name, *args, &block)
133
- if @original.respond_to?("set_#{method_name}", true) && !args.empty?
167
+ if respond_to?("#{method_name}=", true) && !args.empty?
168
+ send("#{method_name}=", *args)
169
+ elsif @original.respond_to?("set_#{method_name}", true) && !args.empty?
134
170
  send_to_original("set_#{method_name}", *args, &block)
135
171
  elsif @original.respond_to?(method_name, true)
136
172
  send_to_original(method_name, *args, &block)
@@ -224,10 +260,9 @@ module Glimmer
224
260
 
225
261
  private
226
262
 
227
- def build_widget
228
- pd keyword
229
- pd ComponentProxy.component_class(keyword)
263
+ def build
230
264
  @original = ComponentProxy.component_class(keyword).new(*normalize_args(args))
265
+ @original.shape_proxies = shape_proxies
231
266
  end
232
267
 
233
268
  def normalize_args(args)
@@ -240,3 +275,4 @@ module Glimmer
240
275
  end
241
276
 
242
277
  Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
278
+ require 'glimmer/swing/shape_proxy'
@@ -0,0 +1,192 @@
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/packages'
23
+
24
+ module Glimmer
25
+ module Swing
26
+ # Proxy for Java2D shape objects
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ShapeProxy
30
+ include Packages
31
+
32
+ class << self
33
+ def exist?(keyword)
34
+ !!shape_class(keyword)
35
+ end
36
+
37
+ def create(parent, keyword, *args, &block)
38
+ shape_proxy_class(keyword).new(parent, keyword, *args, &block)
39
+ end
40
+
41
+ def shape_proxy_class(keyword)
42
+ begin
43
+ class_name = shape_proxy_class_symbol(keyword)
44
+ Glimmer::Swing::ShapeProxy.const_get(class_name)
45
+ rescue => e
46
+ Glimmer::Config.logger.debug e.full_message
47
+ Glimmer::Swing::ShapeProxy
48
+ end
49
+ end
50
+
51
+ def shape_proxy_class_symbol(keyword)
52
+ "#{keyword.camelcase(:upper)}Proxy".to_sym
53
+ end
54
+
55
+ def shape_class_symbol(keyword)
56
+ keyword.camelcase(:upper).to_sym
57
+ end
58
+
59
+ def keyword(shape_proxy_class)
60
+ shape_proxy_class.to_s.underscore.sub(/_proxy$/, '')
61
+ end
62
+
63
+ def shape_class_manual_entries
64
+ # add mappings for any classes (minus the namespace) that conflict with standard Ruby classes
65
+ {
66
+ # example:
67
+ # 'date_time' => Java::OrgEclipseSwtWidgets::DateTime
68
+ }
69
+ end
70
+
71
+ def shape_class(keyword)
72
+ unless flyweight_shape_class.keys.include?(keyword)
73
+ begin
74
+ shape_class_name = shape_class_symbol(keyword).to_s
75
+ shape_class = eval("#{shape_class_name}2D::Double") rescue eval(shape_class_name)
76
+ unless shape_class.ancestors.include?(Java::JavaAwt::Shape)
77
+ shape_class = shape_class_manual_entries[keyword]
78
+ if shape_class.nil?
79
+ Glimmer::Config.logger.debug {"Class #{shape_class} matching #{keyword} is not a subclass of java.awt.Component"}
80
+ return nil
81
+ end
82
+ end
83
+ flyweight_shape_class[keyword] = shape_class
84
+ rescue SyntaxError, NameError => e
85
+ Glimmer::Config.logger.debug {e.full_message}
86
+ nil
87
+ rescue => e
88
+ Glimmer::Config.logger.debug {e.full_message}
89
+ nil
90
+ end
91
+ end
92
+ flyweight_shape_class[keyword]
93
+ end
94
+
95
+ # Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
96
+ def flyweight_shape_class
97
+ @flyweight_shape_class ||= {}
98
+ end
99
+ end
100
+
101
+ attr_reader :parent_proxy, :original, :args, :keyword, :block
102
+
103
+ def initialize(parent, keyword, *args, &block)
104
+ @parent_proxy = parent
105
+ @keyword = keyword
106
+ @args = args
107
+ @block = block
108
+ build
109
+ post_add_content if @block.nil?
110
+ end
111
+
112
+ # Subclasses may override to perform post add_content work (normally must call super)
113
+ def post_add_content
114
+ @parent_proxy&.post_initialize_child(self)
115
+ end
116
+
117
+ # Subclasses may override to perform post initialization work on an added child (normally must also call super)
118
+ def post_initialize_child(child)
119
+ @original.append(child.original, false) if @original&.is_a?(Path2D) && child.is_a?(ShapeProxy)
120
+ end
121
+
122
+ def respond_to?(method_name, *args, &block)
123
+ respond_to_original?(method_name, *args, &block) ||
124
+ super(method_name, true)
125
+ end
126
+
127
+ def respond_to_original?(method_name, *args, &block)
128
+ @original.respond_to?(method_name, true) || @original.respond_to?("set_#{method_name}", true)
129
+ end
130
+
131
+ def method_missing(method_name, *args, &block)
132
+ if @original.respond_to?("set_#{method_name}", true) && !args.empty?
133
+ send_to_original("set_#{method_name}", *args, &block)
134
+ elsif @original.respond_to?(method_name, true)
135
+ send_to_original(method_name, *args, &block)
136
+ else
137
+ super
138
+ end
139
+ end
140
+
141
+ def send_to_original(method_name, *args, &block)
142
+ @original.send(method_name, *normalize_args(args), &block)
143
+ end
144
+
145
+ def content(&block)
146
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Swing::ShapeExpression.new, @keyword, &block)
147
+ end
148
+
149
+ def stroke=(*args)
150
+ @stroke = BasicStroke.new(*args)
151
+ end
152
+
153
+ def stroke
154
+ @stroke
155
+ end
156
+
157
+ def draw_paint=(*args)
158
+ @draw_paint = Color.new(*args)
159
+ end
160
+ alias draw_color= draw_paint=
161
+
162
+ def draw_paint
163
+ @draw_paint
164
+ end
165
+ alias draw_color draw_paint
166
+
167
+ def fill_paint=(*args)
168
+ @fill_paint = Color.new(*args)
169
+ end
170
+ alias fill_color= fill_paint=
171
+
172
+ def fill_paint
173
+ @fill_paint
174
+ end
175
+ alias fill_color fill_paint
176
+
177
+ private
178
+
179
+ def build
180
+ @original = ShapeProxy.shape_class(keyword).new(*normalize_args(args))
181
+ end
182
+
183
+ def normalize_args(args)
184
+ args.map do |arg|
185
+ arg.is_a?(ShapeProxy) ? arg.original : arg
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ Dir[File.expand_path("./#{File.basename(__FILE__, '.rb')}/*.rb", __dir__)].each {|f| require f}
@@ -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'
@@ -36,8 +36,6 @@ require 'facets/string/camelcase'
36
36
  require 'facets/hash/stringify_keys'
37
37
 
38
38
  # Internal requires
39
- # require 'ext/glimmer/config'
40
- # require 'ext/glimmer'
41
39
  require 'glimmer/swing'
42
40
  require 'glimmer/swing/ext/glimmer'
43
41
  require 'glimmer/swing/ext/glimmer/config'
@@ -4,10 +4,10 @@ include Glimmer
4
4
 
5
5
  jframe('Hello, Button!') {
6
6
  @button = jbutton('Click To Increment: 0') {
7
- on_action_performed {
8
- button_text_match = @button.text.match(/(.*)(\d+)$/)
7
+ on_action_performed do
8
+ button_text_match = @button.text.match(/([^0-9]+)(\d+)$/)
9
9
  count = button_text_match[2].to_i + 1
10
10
  @button.text = "#{button_text_match[1]}#{count}"
11
- }
11
+ end
12
12
  }
13
13
  }.show
@@ -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
@@ -0,0 +1,84 @@
1
+ require 'glimmer-dsl-swing'
2
+
3
+ include Glimmer
4
+
5
+ jframe('Hello, Shapes!') {
6
+ minimum_size 400, 400
7
+
8
+ arc(40, 40, 90, 90, 30, 230, 0) {
9
+ fill_paint 255, 0, 0
10
+ draw_paint 0, 128, 255
11
+ stroke 3
12
+ }
13
+
14
+ arc(40, 140, 90, 90, 30, 230, 1) {
15
+ fill_paint 255, 0, 0
16
+ draw_paint 0, 128, 255
17
+ stroke 3
18
+ }
19
+
20
+ arc(40, 240, 90, 90, 30, 230, 2) {
21
+ fill_paint 255, 0, 0
22
+ draw_paint 0, 128, 255
23
+ stroke 3
24
+ }
25
+
26
+ rectangle(140, 40, 180, 90) {
27
+ fill_paint 255, 255, 0
28
+ draw_paint 255, 0, 0
29
+ stroke 3
30
+ }
31
+
32
+ round_rectangle(140, 140, 180, 90, 60, 40) {
33
+ fill_paint 255, 255, 0
34
+ draw_paint 255, 0, 0
35
+ stroke 3
36
+ }
37
+
38
+ ellipse(140, 240, 180, 90) {
39
+ fill_paint 255, 255, 0
40
+ draw_paint 255, 0, 0
41
+ stroke 3
42
+ }
43
+
44
+ line(180, 60, 280, 110) {
45
+ draw_paint 255, 0, 0
46
+ stroke 3
47
+ }
48
+
49
+ quad_curve(170, 60, 180, 90, 220, 100) {
50
+ draw_paint 0, 255, 0
51
+ stroke 3
52
+ }
53
+
54
+ cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
55
+ draw_paint 0, 0, 255
56
+ stroke 3
57
+ }
58
+
59
+ path {
60
+ move_to 200, 150
61
+ line_to 270, 170
62
+ line_to 250, 220
63
+ line_to 220, 190
64
+ line_to 200, 200
65
+ line_to 180, 170
66
+
67
+ close_path
68
+
69
+ fill_paint 0, 255, 0
70
+ draw_paint 0, 0, 255
71
+ stroke 3
72
+ }
73
+
74
+ path {
75
+ move_to 160, 300
76
+ curve_to 190, 260, 200, 280, 210, 270
77
+ curve_to 240, 280, 250, 300, 260, 290
78
+ curve_to 290, 290, 300, 310, 310, 300
79
+
80
+ fill_paint 0, 255, 0
81
+ draw_paint 0, 0, 255
82
+ stroke 3
83
+ }
84
+ }.show
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
11
+ date: 2021-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -216,7 +216,10 @@ files:
216
216
  - lib/glimmer/dsl/swing/component_expression.rb
217
217
  - lib/glimmer/dsl/swing/dsl.rb
218
218
  - lib/glimmer/dsl/swing/listener_expression.rb
219
+ - lib/glimmer/dsl/swing/observe_expression.rb
220
+ - lib/glimmer/dsl/swing/operation_expression.rb
219
221
  - lib/glimmer/dsl/swing/property_expression.rb
222
+ - lib/glimmer/dsl/swing/shape_expression.rb
220
223
  - lib/glimmer/swing.rb
221
224
  - lib/glimmer/swing/component_listener_proxy.rb
222
225
  - lib/glimmer/swing/component_proxy.rb
@@ -224,7 +227,10 @@ files:
224
227
  - lib/glimmer/swing/ext/glimmer.rb
225
228
  - lib/glimmer/swing/ext/glimmer/config.rb
226
229
  - lib/glimmer/swing/packages.rb
230
+ - lib/glimmer/swing/shape_proxy.rb
227
231
  - samples/hello/hello_button.rb
232
+ - samples/hello/hello_button2.rb
233
+ - samples/hello/hello_shapes.rb
228
234
  - samples/hello/hello_world.rb
229
235
  homepage: http://github.com/AndyObtiva/glimmer-dsl-swing
230
236
  licenses: