glimmer-dsl-swing 0.0.3 → 0.0.4

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: e0ffbe12ad885326f61aa37073604e1df424e538d33bd6a05653598c017c4c78
4
- data.tar.gz: cbef6588edb062f6079fd55b1af4f4de8dd691fbe3c4a350176c3d179c2e4e5e
3
+ metadata.gz: 839a9058d2f94757fbe185bb825a23a10fd840a0588b9e5f4fc44ede4ca4d511
4
+ data.tar.gz: efd4e9dead40a0076b3d3647657fe27642101f498b7381efe7cf554a3d440d51
5
5
  SHA512:
6
- metadata.gz: 87b6a0d7b707ad99af3ca49a769edd5376a75d961190c87a4677cf9d5d8ba11b2b47cfd19f19b1391e381a13158783d88d7507711c2cb8bbc5d11c4ec03512fb
7
- data.tar.gz: 7daff7909124ea6303d905821868116c91c15db4e2a467f47c2f6e9d729877316d9bbee340a3930c401a57184e38235f4b8af49356dd6820325e98fb25cf499c
6
+ metadata.gz: 88bb15d31a9186a28d5e321f35080ff97bcdd055747f815e672c481e549dfd2076d9202f905e76d18528aead464ef8b5e920dd65a90736debedbc986a0cfecc7
7
+ data.tar.gz: 1bda4d359a7974c9f8ee4fa4ca21ef30d6f833038b200dc0de8acd7e8dae7b9ac717a15d984a48d7e8c4cb7d600b440259b57e3f8d9dde23c50cc745c4716d0c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.4
4
+
5
+ - Support setting `stroke` attribute in shapes
6
+ - 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)
7
+ - Enable antialiasing by default on Java 2D graphics
8
+ - Update Hello, Shapes! to take advantage of `stroke`
9
+
3
10
  ## 0.0.3
4
11
 
5
12
  - Support `observe` keyword for observing model attributes to update the View
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.3
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.4
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
 
@@ -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 -v0.0.3
60
+ gem install glimmer-dsl-swing -v0.0.4
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.3'
67
+ gem 'glimmer-dsl-swing', '0.0.4'
68
68
  ```
69
69
 
70
70
  And, then run:
@@ -110,7 +110,7 @@ The Glimmer GUI DSL enables development of desktop graphical user interfaces in
110
110
 
111
111
  1 - Keywords
112
112
 
113
- You may declare any swing/awt 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)
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
114
 
115
115
  Examples:
116
116
 
@@ -124,7 +124,7 @@ jlabel
124
124
 
125
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
126
 
127
- Example `JFrame`, `JLabel`, and `JButton` have a constructor signature that accepts a string representing title or text:
127
+ Example (`JFrame`, `JButton`, and `JLabel` have a constructor signature that accepts a string representing title or text):
128
128
 
129
129
  ```ruby
130
130
  jframe('Hello, World!')
@@ -148,13 +148,13 @@ jframe('Hello, World!') {
148
148
  }
149
149
  ```
150
150
 
151
- The recommended style for the content block is to always be curly braces to denote as View nesting code different from the logic in looping/conditional constructs that utilize `do;end` instead.
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
152
 
153
153
  Property arguments never have parentheses.
154
154
 
155
155
  4 - Listeners
156
156
 
157
- You may declare listeners with their 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).
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
158
 
159
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
160
 
@@ -183,7 +183,7 @@ frame1 = jframe('Hello, World!') {
183
183
  frame1.show
184
184
  ```
185
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.
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
187
 
188
188
  6 - Observe Model Attributes
189
189
 
@@ -249,7 +249,10 @@ For example, `Arc2D` becomes simply `arc`.
249
249
 
250
250
  Glimmer utilizes the `Double` variation of shape classes.
251
251
 
252
- Additionally, you can set `draw_color` or `fill_color` property as an rgb/rgba hash (e.g. `r: 255, g: 0, b: 0`)
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
253
256
 
254
257
  Example:
255
258
 
@@ -262,45 +265,54 @@ jframe('Hello, Shapes!') {
262
265
  minimum_size 400, 400
263
266
 
264
267
  arc(40, 40, 90, 90, 30, 230, 0) {
265
- fill_color r: 255, g: 0, b: 0
266
- draw_color r: 0, g: 255, b: 255
268
+ fill_paint 255, 0, 0
269
+ draw_paint 0, 128, 255
270
+ stroke 3
267
271
  }
268
272
 
269
273
  arc(40, 140, 90, 90, 30, 230, 1) {
270
- fill_color r: 255, g: 0, b: 0
271
- draw_color r: 0, g: 255, b: 255
274
+ fill_paint 255, 0, 0
275
+ draw_paint 0, 128, 255
276
+ stroke 3
272
277
  }
273
278
 
274
279
  arc(40, 240, 90, 90, 30, 230, 2) {
275
- fill_color r: 255, g: 0, b: 0
276
- draw_color r: 0, g: 255, b: 255
280
+ fill_paint 255, 0, 0
281
+ draw_paint 0, 128, 255
282
+ stroke 3
277
283
  }
278
284
 
279
- ellipse(140, 40, 180, 90) {
280
- fill_color r: 0, g: 255, b: 255
281
- draw_color r: 255, g: 0, b: 0
285
+ rectangle(140, 40, 180, 90) {
286
+ fill_paint 255, 255, 0
287
+ draw_paint 255, 0, 0
288
+ stroke 3
282
289
  }
283
290
 
284
- rectangle(140, 140, 180, 90) {
285
- fill_color r: 0, g: 255, b: 255
286
- draw_color r: 255, g: 0, b: 0
287
- }
288
-
289
- round_rectangle(140, 240, 180, 90, 60, 40) {
290
- fill_color r: 0, g: 255, b: 255
291
- draw_color r: 255, g: 0, b: 0
291
+ round_rectangle(140, 140, 180, 90, 60, 40) {
292
+ fill_paint 255, 255, 0
293
+ draw_paint 255, 0, 0
294
+ stroke 3
292
295
  }
293
296
 
297
+ ellipse(140, 240, 180, 90) {
298
+ fill_paint 255, 255, 0
299
+ draw_paint 255, 0, 0
300
+ stroke 3
301
+ }
302
+
294
303
  line(180, 60, 280, 110) {
295
- draw_color r: 0, g: 0, b: 0
304
+ draw_paint 255, 0, 0
305
+ stroke 3
296
306
  }
297
307
 
298
308
  quad_curve(170, 60, 180, 90, 220, 100) {
299
- draw_color r: 0, g: 0, b: 0
309
+ draw_paint 0, 255, 0
310
+ stroke 3
300
311
  }
301
312
 
302
313
  cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
303
- draw_color r: 0, g: 0, b: 0
314
+ draw_paint 0, 0, 255
315
+ stroke 3
304
316
  }
305
317
  }.show
306
318
  ```
@@ -453,45 +465,54 @@ jframe('Hello, Shapes!') {
453
465
  minimum_size 400, 400
454
466
 
455
467
  arc(40, 40, 90, 90, 30, 230, 0) {
456
- fill_color r: 255, g: 0, b: 0
457
- draw_color r: 0, g: 255, b: 255
468
+ fill_paint 255, 0, 0
469
+ draw_paint 0, 128, 255
470
+ stroke 3
458
471
  }
459
472
 
460
473
  arc(40, 140, 90, 90, 30, 230, 1) {
461
- fill_color r: 255, g: 0, b: 0
462
- draw_color r: 0, g: 255, b: 255
474
+ fill_paint 255, 0, 0
475
+ draw_paint 0, 128, 255
476
+ stroke 3
463
477
  }
464
478
 
465
479
  arc(40, 240, 90, 90, 30, 230, 2) {
466
- fill_color r: 255, g: 0, b: 0
467
- draw_color r: 0, g: 255, b: 255
480
+ fill_paint 255, 0, 0
481
+ draw_paint 0, 128, 255
482
+ stroke 3
468
483
  }
469
484
 
470
- ellipse(140, 40, 180, 90) {
471
- fill_color r: 0, g: 255, b: 255
472
- draw_color r: 255, g: 0, b: 0
485
+ rectangle(140, 40, 180, 90) {
486
+ fill_paint 255, 255, 0
487
+ draw_paint 255, 0, 0
488
+ stroke 3
473
489
  }
474
490
 
475
- rectangle(140, 140, 180, 90) {
476
- fill_color r: 0, g: 255, b: 255
477
- draw_color r: 255, g: 0, b: 0
478
- }
479
-
480
- round_rectangle(140, 240, 180, 90, 60, 40) {
481
- fill_color r: 0, g: 255, b: 255
482
- draw_color r: 255, g: 0, b: 0
491
+ round_rectangle(140, 140, 180, 90, 60, 40) {
492
+ fill_paint 255, 255, 0
493
+ draw_paint 255, 0, 0
494
+ stroke 3
483
495
  }
484
496
 
497
+ ellipse(140, 240, 180, 90) {
498
+ fill_paint 255, 255, 0
499
+ draw_paint 255, 0, 0
500
+ stroke 3
501
+ }
502
+
485
503
  line(180, 60, 280, 110) {
486
- draw_color r: 0, g: 0, b: 0
504
+ draw_paint 255, 0, 0
505
+ stroke 3
487
506
  }
488
507
 
489
508
  quad_curve(170, 60, 180, 90, 220, 100) {
490
- draw_color r: 0, g: 0, b: 0
509
+ draw_paint 0, 255, 0
510
+ stroke 3
491
511
  }
492
512
 
493
513
  cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
494
- draw_color r: 0, g: 0, b: 0
514
+ draw_paint 0, 0, 255
515
+ stroke 3
495
516
  }
496
517
  }.show
497
518
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/bin/girb CHANGED
File without changes
Binary file
@@ -32,7 +32,7 @@ module Glimmer
32
32
  parent.is_a?(Glimmer::Swing::ShapeProxy)
33
33
  ) and
34
34
  block.nil? and
35
- parent.respond_to?(keyword, *args)
35
+ parent.respond_to?("#{keyword}=", *args)
36
36
  end
37
37
 
38
38
  def interpret(parent, keyword, *args, &block)
@@ -87,18 +87,23 @@ module Glimmer
87
87
  attr_accessor :shape_proxies
88
88
 
89
89
  def paint(g2)
90
+ rendering_hints = RenderingHints.new(RenderingHints::KEY_ANTIALIASING, RenderingHints::VALUE_ANTIALIAS_ON)
91
+ g2.set_rendering_hints(rendering_hints)
90
92
  super(g2)
91
93
  shape_proxies.each do |shape_proxy|
92
- original_color = g2.get_color
94
+ original_paint = g2.get_paint
95
+ original_stroke = g2.get_stroke
93
96
  if shape_proxy.fill_color
94
- g2.color = Color.new(shape_proxy.fill_color[:r], shape_proxy.fill_color[:g], shape_proxy.fill_color[:b], shape_proxy.fill_color[:a] || 255)
97
+ g2.set_paint shape_proxy.fill_paint
95
98
  g2.fill(shape_proxy)
96
99
  end
97
100
  if shape_proxy.draw_color
98
- g2.color = Color.new(shape_proxy.draw_color[:r], shape_proxy.draw_color[:g], shape_proxy.draw_color[:b], shape_proxy.draw_color[:a] || 255)
101
+ g2.set_stroke shape_proxy.stroke unless shape_proxy.stroke.nil?
102
+ g2.set_paint shape_proxy.draw_paint
99
103
  g2.draw(shape_proxy)
100
104
  end
101
- g2.color = original_color
105
+ g2.set_paint original_paint
106
+ g2.set_stroke original_stroke || BasicStroke.new
102
107
  end
103
108
  end
104
109
  }
@@ -99,7 +99,6 @@ module Glimmer
99
99
  end
100
100
 
101
101
  attr_reader :parent_proxy, :original, :args, :keyword, :block
102
- attr_accessor :draw_color, :fill_color
103
102
 
104
103
  def initialize(parent, keyword, *args, &block)
105
104
  @parent_proxy = parent
@@ -149,6 +148,34 @@ module Glimmer
149
148
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Swing::ShapeExpression.new, @keyword, &block)
150
149
  end
151
150
 
151
+ def stroke=(*args)
152
+ @stroke = BasicStroke.new(*args)
153
+ end
154
+
155
+ def stroke
156
+ @stroke
157
+ end
158
+
159
+ def draw_paint=(*args)
160
+ @draw_paint = Color.new(*args)
161
+ end
162
+ alias draw_color= draw_paint=
163
+
164
+ def draw_paint
165
+ @draw_paint
166
+ end
167
+ alias draw_color draw_paint
168
+
169
+ def fill_paint=(*args)
170
+ @fill_paint = Color.new(*args)
171
+ end
172
+ alias fill_color= fill_paint=
173
+
174
+ def fill_paint
175
+ @fill_paint
176
+ end
177
+ alias fill_color fill_paint
178
+
152
179
  private
153
180
 
154
181
  def build
@@ -6,44 +6,53 @@ jframe('Hello, Shapes!') {
6
6
  minimum_size 400, 400
7
7
 
8
8
  arc(40, 40, 90, 90, 30, 230, 0) {
9
- fill_color r: 255, g: 0, b: 0
10
- draw_color r: 0, g: 255, b: 255
9
+ fill_paint 255, 0, 0
10
+ draw_paint 0, 128, 255
11
+ stroke 3
11
12
  }
12
13
 
13
14
  arc(40, 140, 90, 90, 30, 230, 1) {
14
- fill_color r: 255, g: 0, b: 0
15
- draw_color r: 0, g: 255, b: 255
15
+ fill_paint 255, 0, 0
16
+ draw_paint 0, 128, 255
17
+ stroke 3
16
18
  }
17
19
 
18
20
  arc(40, 240, 90, 90, 30, 230, 2) {
19
- fill_color r: 255, g: 0, b: 0
20
- draw_color r: 0, g: 255, b: 255
21
+ fill_paint 255, 0, 0
22
+ draw_paint 0, 128, 255
23
+ stroke 3
21
24
  }
22
25
 
23
- ellipse(140, 40, 180, 90) {
24
- fill_color r: 0, g: 255, b: 255
25
- draw_color r: 255, g: 0, b: 0
26
+ rectangle(140, 40, 180, 90) {
27
+ fill_paint 255, 255, 0
28
+ draw_paint 255, 0, 0
29
+ stroke 3
26
30
  }
27
31
 
28
- rectangle(140, 140, 180, 90) {
29
- fill_color r: 0, g: 255, b: 255
30
- draw_color r: 255, g: 0, b: 0
31
- }
32
-
33
- round_rectangle(140, 240, 180, 90, 60, 40) {
34
- fill_color r: 0, g: 255, b: 255
35
- draw_color r: 255, g: 0, b: 0
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
36
  }
37
37
 
38
+ ellipse(140, 240, 180, 90) {
39
+ fill_paint 255, 255, 0
40
+ draw_paint 255, 0, 0
41
+ stroke 3
42
+ }
43
+
38
44
  line(180, 60, 280, 110) {
39
- draw_color r: 0, g: 0, b: 0
45
+ draw_paint 255, 0, 0
46
+ stroke 3
40
47
  }
41
48
 
42
49
  quad_curve(170, 60, 180, 90, 220, 100) {
43
- draw_color r: 0, g: 0, b: 0
50
+ draw_paint 0, 255, 0
51
+ stroke 3
44
52
  }
45
53
 
46
54
  cubic_curve(190, 60, 240, 40, 220, 80, 260, 70) {
47
- draw_color r: 0, g: 0, b: 0
55
+ draw_paint 0, 0, 255
56
+ stroke 3
48
57
  }
49
58
  }.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.3
4
+ version: 0.0.4
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-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -202,7 +202,6 @@ executables:
202
202
  - girb
203
203
  extensions: []
204
204
  extra_rdoc_files:
205
- - CHANGELOG.md
206
205
  - LICENSE.txt
207
206
  - README.md
208
207
  files:
@@ -252,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
251
  - !ruby/object:Gem::Version
253
252
  version: '0'
254
253
  requirements: []
255
- rubygems_version: 3.2.29
254
+ rubygems_version: 3.1.6
256
255
  signing_key:
257
256
  specification_version: 4
258
257
  summary: Glimmer DSL for Swing