glimmer-dsl-swt 4.20.0.4 → 4.20.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/README.md +13 -7
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +5 -2
  6. data/docs/reference/GLIMMER_SAMPLES.md +13 -0
  7. data/docs/reference/GLIMMER_STYLE_GUIDE.md +4 -3
  8. data/glimmer-dsl-swt.gemspec +0 -0
  9. data/lib/glimmer/data_binding/shine.rb +2 -1
  10. data/lib/glimmer/data_binding/table_items_binding.rb +2 -2
  11. data/lib/glimmer/data_binding/tree_items_binding.rb +2 -2
  12. data/lib/glimmer/dsl/swt/custom_widget_expression.rb +1 -1
  13. data/lib/glimmer/dsl/swt/radio_group_selection_data_binding_expression.rb +1 -1
  14. data/lib/glimmer/dsl/swt/shine_data_binding_expression.rb +6 -5
  15. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +2 -2
  16. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +17 -12
  17. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +3 -3
  18. data/lib/glimmer/rake_task/scaffold.rb +2 -2
  19. data/lib/glimmer/swt/custom/animation.rb +6 -0
  20. data/lib/glimmer/swt/custom/checkbox_group.rb +1 -1
  21. data/lib/glimmer/swt/custom/radio_group.rb +2 -1
  22. data/lib/glimmer/swt/display_proxy.rb +11 -8
  23. data/lib/glimmer/swt/proxy_properties.rb +7 -6
  24. data/lib/glimmer/swt/table_proxy.rb +15 -8
  25. data/lib/glimmer/swt/widget_proxy.rb +5 -2
  26. data/lib/glimmer/ui/custom_shape.rb +1 -1
  27. data/lib/glimmer/ui/custom_shell.rb +3 -3
  28. data/lib/glimmer/ui/custom_widget.rb +6 -3
  29. data/samples/elaborate/calculator.rb +116 -0
  30. data/samples/elaborate/calculator/model/command.rb +105 -0
  31. data/samples/elaborate/calculator/model/command/all_clear.rb +17 -0
  32. data/samples/elaborate/calculator/model/command/command_history.rb +0 -0
  33. data/samples/elaborate/calculator/model/command/equals.rb +18 -0
  34. data/samples/elaborate/calculator/model/command/number.rb +20 -0
  35. data/samples/elaborate/calculator/model/command/operation.rb +27 -0
  36. data/samples/elaborate/calculator/model/command/operation/add.rb +15 -0
  37. data/samples/elaborate/calculator/model/command/operation/divide.rb +15 -0
  38. data/samples/elaborate/calculator/model/command/operation/multiply.rb +15 -0
  39. data/samples/elaborate/calculator/model/command/operation/subtract.rb +15 -0
  40. data/samples/elaborate/calculator/model/command/point.rb +20 -0
  41. data/samples/elaborate/calculator/model/presenter.rb +30 -0
  42. data/samples/elaborate/contact_manager.rb +2 -2
  43. data/samples/elaborate/meta_sample.rb +5 -5
  44. data/samples/elaborate/tetris.rb +6 -6
  45. data/samples/elaborate/tetris/view/bevel.rb +11 -11
  46. data/samples/elaborate/tetris/view/block.rb +1 -1
  47. data/samples/elaborate/tetris/view/high_score_dialog.rb +4 -4
  48. data/samples/elaborate/tetris/view/score_lane.rb +3 -3
  49. data/samples/elaborate/tetris/view/tetris_menu_bar.rb +9 -9
  50. data/samples/elaborate/timer.rb +233 -0
  51. data/samples/elaborate/timer/alarm1.wav +0 -0
  52. data/samples/elaborate/timer/sounds/alarm1.wav +0 -0
  53. data/samples/elaborate/user_profile.rb +4 -2
  54. data/samples/elaborate/weather.rb +1 -1
  55. data/samples/hello/hello_canvas_animation_data_binding.rb +1 -1
  56. data/samples/hello/hello_checkbox_group.rb +1 -1
  57. data/samples/hello/hello_code_text.rb +3 -3
  58. data/samples/hello/hello_cool_bar.rb +5 -5
  59. data/samples/hello/hello_cursor.rb +1 -1
  60. data/samples/hello/hello_custom_shell.rb +1 -1
  61. data/samples/hello/hello_directory_dialog.rb +1 -1
  62. data/samples/hello/hello_radio_group.rb +2 -2
  63. data/samples/hello/hello_table.rb +4 -4
  64. data/samples/hello/hello_text.rb +120 -0
  65. data/samples/hello/hello_tool_bar.rb +5 -5
  66. data/samples/hello/hello_tree.rb +11 -11
  67. metadata +19 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76c2288c83bde07fd0e5db24556bd986b52c868db3db8dffd1f4cb4a82bd8085
4
- data.tar.gz: 33f8584fd2ce2efac14d188a5d4753f6a807851529d663b1dbab1b57a4838db8
3
+ metadata.gz: 581c69384ecd98621e42b9c109b26606bd02f971645d560b6a327a2afef193cd
4
+ data.tar.gz: ff868723057cdcc85357713f63f1bcc449505bb79e28714e1ce95eada387c0e5
5
5
  SHA512:
6
- metadata.gz: cbb93aa7d256686e409becd45a4e4a8bc4ca2597923a8b66118f3711aa8922a1b5d2b6ad62d615b6affdcf430533b1539118313c5eea95c81f94766c21a90486
7
- data.tar.gz: 1c79ebfc57bf52c2d586ce65badaf0643ce37c534261943597d308bbd702e1fa01840f9d75164c80e9597c8e73f26d438ec95528321a8ba8f16b0d2048412814
6
+ metadata.gz: fa48a538274e9a199d9f332d1fec5e3c99d235509673fcf2de5b3c646aa38306a093368adefe5161b81dcc8530b411b5bb1b304700cca4762d655185e5550916
7
+ data.tar.gz: 1d04d38dcda31ef8c02c015cd558e62dc29ff54ad2e295d548f91633b8b6b6ec5e98dc9ef514c2250e4d90cce1a1764feb3be626af8a843bfb95a07722f2dbc6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.3.0
4
+
5
+ - Shine data-binding support for `custom widgets`, `custom shells`, and `custom shapes`
6
+ - Update remaining samples with `bind` keyword to switch to Shine data-binding syntax
7
+ - Switch scaffolded classes' data-binding to Shine
8
+ - Fix `table` Shine syntax support for unidirectional (one-way) data-binding
9
+
10
+ ### 4.20.2.1
11
+
12
+ - Shine data-binding support for `animation` (also supporting `#content {}` method in `Animation`)
13
+ - Update Hello, Custom Shell! to use Shine data-binding syntax
14
+ - Fix `table` automatic sorting support when using one-way Shine data-binding syntax (which was disabling reads)
15
+
16
+ ### 4.20.2.0
17
+
18
+ - Shine data-binding syntax support for `tree` widget
19
+ - Use Shine syntax in Hello, Tree! sample
20
+
21
+ ### 4.20.1.0
22
+
23
+ - Shine data-binding syntax support for `table` widget
24
+ - Use Shine syntax in Hello, Table! and Contact Manager samples
25
+
26
+ ### 4.20.0.5
27
+
28
+ - Hello, Text! sample
29
+ - Timer elaborate sample (copied and simplified from external sample)
30
+ - Calculator elaborate sample (copied and simplified from external sample)
31
+ - Fixed issue relating to cleaning up display listeners
32
+
3
33
  ### 4.20.0.4
4
34
 
5
35
  - Weather elaborate sample
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 SWT 4.20.0.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 SWT 4.20.3.0
2
2
  ## JRuby Desktop Development GUI Framework
3
3
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
4
4
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
@@ -15,9 +15,9 @@
15
15
  [<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
16
16
  Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) and [Chalmers/Gothenburg University Software Engineering Master's Lecture Material](http://www.cse.chalmers.se/~bergert/slides/guest_lecture_DSLs.pdf)
17
17
 
18
- [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.0.4 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
18
+ [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.20.3.0 includes [SWT 4.20](https://download.eclipse.org/eclipse/downloads/drops4/R-4.20-202106111600/), which was released on June 11, 2021. Gem version numbers are in sync with the SWT library versions. The first two digits represent the SWT version number. The last two digits represent the minor and patch versions of Glimmer DSL for SWT. Note that SWT now supports AARCH64 on Mac and Linux, but it is not fully tested in Glimmer DSL for SWT yet, so deem its support experimental for the time being without guarantees for functionality until declared otherwise (report any issues you may encounter).
19
19
 
20
- **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still an early alpha, so default back to `bind` whenever needed).
20
+ **Starting in version 4.20.0.0, [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) comes with the new [***Shine***](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax** for highly intuitive and visually expressive View/Model Attribute Mapping, relying on `<=>` for bidirectional (two-way) data-binding and `<=` for unidirectional (one-way) data-binding, providing an alternative to the `bind` keyword (keep in mind that it is still an alpha, so default back to `bind` whenever needed).
21
21
 
22
22
  Please help make [Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) better by providing feedback and [contributing](#contributing) whenever possible. Any feature suggestions that are accepted could be implemented within weeks if not days.
23
23
 
@@ -286,10 +286,16 @@ Thanks to Java and JRuby, Glimmer apps can be packaged as cross-platform JAR fil
286
286
 
287
287
  The Java Virtual Machine already supports OS-native threads, so Glimmer apps can have multiple things running in parallel with no problem.
288
288
 
289
- SWT supports Canvas graphics drawing, and Glimmer takes that further by provding a Canvas Shape/Transform/Animation DSL, making it very simple to decorate any existing widgets or add new widgets with a completely custom look and feel if needed for branding or entertainment (gaming) purposes.
289
+ SWT supports Canvas graphics drawing, and Glimmer takes that further by provding a Canvas Shape/Transform/Animation DSL, making it very simple to decorate any existing widgets or add new widgets with a completely custom look and feel if needed for branding purposes.
290
290
 
291
291
  Audio is supported via the Java Sound library in a cross-platform approach and video is supported via a Glimmer custom widget, so any Glimmer app can be enhanced with audio and video where needed.
292
292
 
293
+ ### Remaining Challenges
294
+
295
+ Startup time is long. Thankfully, [there are work-arounds](https://andymaleh.blogspot.com/2021/03/glimmer-dsl-for-swt-41900-halved.html) that could make apps start as fast as instantly.
296
+
297
+ Contributors who appreciate Glimmer's ultra-high productivity, maintainability, and extensibility might want to help report and resolve remaining challenges in its software architecture.
298
+
293
299
  ## Platform Support
294
300
 
295
301
  Glimmer runs on the following platforms:
@@ -341,7 +347,7 @@ jgem install glimmer-dsl-swt
341
347
 
342
348
  Or this command if you want a specific version:
343
349
  ```
344
- jgem install glimmer-dsl-swt -v 4.20.0.4
350
+ jgem install glimmer-dsl-swt -v 4.20.3.0
345
351
  ```
346
352
 
347
353
  `jgem` is JRuby's version of `gem` command.
@@ -369,7 +375,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
369
375
 
370
376
  Add the following to `Gemfile`:
371
377
  ```
372
- gem 'glimmer-dsl-swt', '~> 4.20.0.4'
378
+ gem 'glimmer-dsl-swt', '~> 4.20.3.0'
373
379
  ```
374
380
 
375
381
  And, then run:
@@ -390,7 +396,7 @@ glimmer
390
396
  ```
391
397
 
392
398
  ```
393
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.0.4
399
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.3.0
394
400
 
395
401
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
396
402
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.0.4
1
+ 4.20.3.0
@@ -2278,13 +2278,16 @@ Example from [samples/hello/hello_combo.rb](samples/hello_combo.rb) sample (you
2278
2278
 
2279
2279
  #### Shine
2280
2280
 
2281
- **(EARLY ALPHA FEATURE)**
2281
+ **(ALPHA FEATURE)**
2282
2282
 
2283
2283
  The new Shine syntax for View/Model Attribute Mapping allows data-binding visually with simple arrow operators in Ruby.
2284
2284
 
2285
2285
  Use `<=> [model, attribute, options]` for bidirectional (two-way) data-binding instead of `bind(model, attribute, options)`.
2286
2286
  Use `<= [model, attribute, options]` for unidirectional (one-way) data-binding instead of `bind(model, attribute, read_only: true, more_options)`
2287
2287
 
2288
+ One thing special with the `table` widget is that `<=`, which makes data-binding unidirectional, stops the `table` from supporting automatic sorting by default since that involves modifying the model collection ordering (albeit not the content).
2289
+ To enable automatic sorting in a `table`, but still not permit edit actions to the data itself, you simply use `<=>` for bidirectional data-binding, but without passing the `:editable` style to the `table`.
2290
+
2288
2291
  Examples:
2289
2292
 
2290
2293
  ```ruby
@@ -2299,7 +2302,7 @@ text <=> [@contact, :last_name]
2299
2302
  text <= [@contact, :name, computed_by: [:first_name, :last_name]]
2300
2303
  ```
2301
2304
 
2302
- Note that `table`, `tree`, custom widgets, custom shapes, and animations are not supported by Shine syntax for data-binding yet, so continue to use `bind` with them for the time being.
2305
+ Note that custom widgets and custom shapes are not supported by Shine syntax for data-binding yet, so continue to use `bind` with them for the time being.
2303
2306
 
2304
2307
  Check out [sample code](/samples) for more examples of Shine syntax in action, such as [Hello, Computed!](/docs/reference/GLIMMER_SAMPLES.md#hello-computed).
2305
2308
 
@@ -2,6 +2,7 @@
2
2
  - [Hello Samples](#hello-samples)
3
3
  - [Hello, World!](#hello-world)
4
4
  - [Hello, Button!](#hello-button)
5
+ - [Hello, Text!](#hello-text)
5
6
  - [Hello, Composite!](#hello-composite)
6
7
  - [Hello, Layout!](#hello-layout)
7
8
  - [Hello, Shell!](#hello-shell)
@@ -116,6 +117,18 @@ Hello, Button! Incremented 7 times!
116
117
 
117
118
  ![Hello Button Incremented](/images/glimmer-hello-button-incremented.png)
118
119
 
120
+ #### Hello, Text!
121
+
122
+ This sample demonstrates the use of the `text` widget in Glimmer, including data-binding (e.g. via the `<=>` operator) and event handling.
123
+
124
+ Code:
125
+
126
+ [samples/hello/hello_text.rb](/samples/hello/hello_text.rb)
127
+
128
+ Hello, Text!
129
+
130
+ ![Hello Text](/images/glimmer-hello-text.png)
131
+
119
132
  #### Hello, Composite!
120
133
 
121
134
  This sample demonstrates the `composite` widget, which is simply used as a container for visual layout and organization.
@@ -7,8 +7,9 @@
7
7
  - Widget properties are declared with underscored lowercase versions of the SWT properties
8
8
  - Widget property declarations always have arguments and never take a block
9
9
  - Widget property arguments are never wrapped inside parentheses
10
- - Widget listeners are always declared starting with `on_` prefix and affixing listener event method name afterwards in underscored lowercase form
10
+ - Widget listeners are always declared starting with `on_` prefix and affixing listener event method name afterwards in underscored lowercase form. Their multi-line blocks rely on the `do; end` style.
11
11
  - Widget listeners are always followed by a block using curly braces (Only when declared in DSL. When invoked on widget object directly outside of GUI declarations, standard Ruby conventions apply)
12
12
  - Data-binding is done via `bind` keyword, which always takes arguments wrapped in parentheses
13
- - Custom widget body, before_body, and after_body blocks open their blocks and close them with curly braces.
14
- - Custom widgets receive additional arguments to SWT style called options. These are passed as the last argument inside the parentheses, a hash of option names pointing to values.
13
+ - Custom widget `body`, `before_body`, and `after_body` blocks open their blocks and close them with curly braces.
14
+ - Custom widgets receive additional keyword arguments called options, which come after the SWT styles.
15
+ - Pure logic multi-line blocks that do not constitute GUI DSL view elements (such as `Thread.new`, `loop`, `each` and `observe` blocks) rely on the `do; end` style to clearly separate logic code from view code.
Binary file
@@ -33,8 +33,9 @@ module Glimmer
33
33
 
34
34
  def <=>(other)
35
35
  if other.is_a?(Array)
36
+ args_clone = other.clone
36
37
  @parent.content {
37
- send(@parent_attribute, bind(*other))
38
+ send(@parent_attribute, bind(*args_clone))
38
39
  }
39
40
  else # || other.is_a?(Hash) # TODO support hash e.g. {model: model_obj, attribute: :some_attribute, more-options...}
40
41
  original_compare(other)
@@ -34,11 +34,11 @@ module Glimmer
34
34
  include_package 'org.eclipse.swt'
35
35
  include_package 'org.eclipse.swt.widgets'
36
36
 
37
- def initialize(parent, model_binding, column_properties)
37
+ def initialize(parent, model_binding, column_properties = nil)
38
38
  @table = parent
39
39
  @model_binding = model_binding
40
40
  @read_only_sort = @model_binding.binding_options[:read_only_sort]
41
- @column_properties = column_properties
41
+ @column_properties = @model_binding.binding_options[:column_properties] || @model_binding.binding_options[:column_attributes] || column_properties
42
42
  if @table.respond_to?(:column_properties=)
43
43
  @table.column_properties = @column_properties
44
44
  else # assume custom widget
@@ -34,10 +34,10 @@ module Glimmer
34
34
  include_package 'org.eclipse.swt'
35
35
  include_package 'org.eclipse.swt.widgets'
36
36
 
37
- def initialize(parent, model_binding, tree_properties)
37
+ def initialize(parent, model_binding, tree_properties = nil)
38
38
  @tree = parent
39
39
  @model_binding = model_binding
40
- @tree_properties = [tree_properties].flatten.first.to_h
40
+ @tree_properties = @model_binding.binding_options[:tree_properties] || @model_binding.binding_options[:tree_attributes] || [tree_properties].compact.flatten.first.to_h
41
41
  if @tree.respond_to?(:tree_properties=)
42
42
  @tree.tree_properties = @tree_properties
43
43
  else # assume custom widget
@@ -54,7 +54,7 @@ module Glimmer
54
54
  def add_content(parent, keyword, *args, &block)
55
55
  # TODO consider avoiding source_location
56
56
  return if block&.parameters&.count == 2
57
- if block.source_location == parent.content&.__getobj__.source_location
57
+ if block.source_location == parent.content&.__getobj__&.source_location
58
58
  parent.content.call(parent) unless parent.content.called?
59
59
  else
60
60
  super
@@ -52,7 +52,7 @@ module Glimmer
52
52
  widget_binding.call(model_binding.evaluate_property)
53
53
  widget_binding.observe(model_binding)
54
54
 
55
- raise(Glimmer::Error, "No radios found! Make sure radio selection is data-bound to a property having property_options as non-empty array!") if parent.items.empty?
55
+ raise(Glimmer::Error, "No radios found! Make sure radio selection is data-bound to a property having property_options as non-empty array!") if parent.get_items.empty?
56
56
  Glimmer::SWT::DisplayProxy.instance.auto_exec(override_sync_exec: model_binding.binding_options[:sync_exec], override_async_exec: model_binding.binding_options[:async_exec]) do
57
57
  parent.on_widget_selected do
58
58
  model_binding.call(widget_binding.evaluate_property)
@@ -29,14 +29,15 @@ module Glimmer
29
29
  module DSL
30
30
  module SWT
31
31
  class ShineDataBindingExpression < Expression
32
+ include_package 'org.eclipse.swt.widgets'
33
+
32
34
  def can_interpret?(parent, keyword, *args, &block)
33
35
  args.size == 0 and
34
36
  block.nil? and
35
- parent.respond_to?(:set_attribute) and
36
- parent.respond_to?(:has_attribute?) and
37
- parent.has_attribute?(keyword, *args) and
38
- !parent.is_a?(Glimmer::UI::CustomWidget) and
39
- !parent.is_a?(Glimmer::UI::CustomShape) and
37
+ (
38
+ (parent.respond_to?(:has_attribute?) and parent.has_attribute?(keyword)) or
39
+ (parent.respond_to?(:swt_widget) and (parent.swt_widget.is_a?(Table) or parent.swt_widget.is_a?(Tree)))
40
+ ) and
40
41
  !(parent.respond_to?(:swt_widget) && parent.swt_widget.class == org.eclipse.swt.widgets.Canvas && keyword == 'image')
41
42
  end
42
43
 
@@ -35,10 +35,10 @@ module Glimmer
35
35
  block.nil? and
36
36
  parent.respond_to?(:swt_widget) and
37
37
  parent.swt_widget.is_a?(Table) and
38
- args.size == 2 and
38
+ args.size.between?(1, 2) and
39
39
  args[0].is_a?(DataBinding::ModelBinding) and
40
40
  args[0].evaluate_property.is_a?(Array) and
41
- args[1].is_a?(Array)
41
+ (args[1].nil? or args[1].is_a?(Array))
42
42
  end
43
43
 
44
44
  def interpret(parent, keyword, *args, &block)
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -30,15 +30,20 @@ module Glimmer
30
30
  include_package 'org.eclipse.swt.widgets'
31
31
 
32
32
  def can_interpret?(parent, keyword, *args, &block)
33
- initial_condition = ((keyword == "items") and block.nil? and parent.respond_to?(:swt_widget) and parent.swt_widget.is_a?(Tree))
34
- return false unless initial_condition
35
- raise Glimmer::Error, 'Tree items args must be 2' unless args.size == 2
36
- raise Glimmer::Error, 'Tree items first arg must be a bind expression' unless args[0].is_a?(DataBinding::ModelBinding)
37
- raise Glimmer::Error, 'Tree items data-binding initial value must not be an array yet a single item representing tree root' unless !args[0].evaluate_property.is_a?(Array)
38
- raise Glimmer::Error, 'Tree items second arg must be an array' unless args[1].is_a?(Array)
39
- raise Glimmer::Error, 'Tree items second arg must not be empty' unless !args[1].empty?
40
- raise Glimmer::Error, 'Tree items second arg array elements must be of type hash' unless args[1].first.is_a?(Hash)
41
- true
33
+ keyword == 'items' and
34
+ block.nil? and
35
+ parent.respond_to?(:swt_widget) and
36
+ parent.swt_widget.is_a?(Tree) and
37
+ args.size.between?(1, 2)
38
+ # TODO delete these checks if they are too granular
39
+ # return false unless initial_condition
40
+ # raise Glimmer::Error, 'Tree items args must be 1 or 2' unless args.size.between?(1, 2)
41
+ # raise Glimmer::Error, 'Tree items first arg must be a bind expression' unless args[0].is_a?(DataBinding::ModelBinding)
42
+ # raise Glimmer::Error, 'Tree items data-binding initial value must not be an array yet a single item representing tree root' unless !args[0].evaluate_property.is_a?(Array)
43
+ # raise Glimmer::Error, 'Tree items second arg must be an array' unless args[1].is_a?(Array)
44
+ # raise Glimmer::Error, 'Tree items second arg must not be empty' unless !args[1].empty?
45
+ # raise Glimmer::Error, 'Tree items second arg array elements must be of type hash' unless args[1].first.is_a?(Hash)
46
+ # true
42
47
  end
43
48
 
44
49
  def interpret(parent, keyword, *args, &block)
@@ -1,5 +1,5 @@
1
1
  # Copyright (c) 2007-2021 Andy Maleh
2
- #
2
+ #
3
3
  # Permission is hereby granted, free of charge, to any person obtaining
4
4
  # a copy of this software and associated documentation files (the
5
5
  # "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@
7
7
  # distribute, sublicense, and/or sell copies of the Software, and to
8
8
  # permit persons to whom the Software is furnished to do so, subject to
9
9
  # the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be
12
12
  # included in all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -642,7 +642,7 @@ module Glimmer
642
642
  custom_shell_file_content += <<-MULTI_LINE_STRING
643
643
  grid_layout
644
644
  label(:center) {
645
- text bind(self, :greeting)
645
+ text <= [self, :greeting]
646
646
  font height: 40
647
647
  layout_data :fill, :center, true, true
648
648
  }
@@ -712,7 +712,7 @@ module Glimmer
712
712
  ].each do |greeting_text|
713
713
  button(:radio) {
714
714
  text greeting_text
715
- selection bind(self, :greeting) { |g| g == greeting_text }
715
+ selection <= [self, :greeting, on_read: ->(g) { g == greeting_text }]
716
716
  layout_data {
717
717
  width 160
718
718
  }
@@ -99,6 +99,12 @@ module Glimmer
99
99
  end
100
100
  end
101
101
 
102
+ def content(&block)
103
+ Glimmer::SWT::DisplayProxy.instance.auto_exec do
104
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::AnimationExpression.new, 'animation', &block)
105
+ end
106
+ end
107
+
102
108
  # Starts an animation that is indefinite or has never been started before (i.e. having `started: false` option).
103
109
  # Otherwise, resumes a stopped animation that has not been completed.
104
110
  def start
@@ -29,7 +29,7 @@ module Glimmer
29
29
  include Glimmer::UI::CustomWidget
30
30
 
31
31
  body {
32
- composite # just an empty composite to hold checkboxs upon data-binding `selection`
32
+ composite {} # just an empty composite to hold checkboxs upon data-binding `selection`
33
33
  }
34
34
 
35
35
  def items=(text_array)
@@ -29,7 +29,7 @@ module Glimmer
29
29
  include Glimmer::UI::CustomWidget
30
30
 
31
31
  body {
32
- composite # just an empty composite to hold radios upon data-binding `selection`
32
+ composite {} # just an empty composite to hold radios upon data-binding `selection`
33
33
  }
34
34
 
35
35
  def items=(text_array)
@@ -41,6 +41,7 @@ module Glimmer
41
41
  def items
42
42
  @items || []
43
43
  end
44
+ alias get_items items
44
45
 
45
46
  def selection=(text)
46
47
  radios.count.times do |index|
@@ -42,7 +42,7 @@ module Glimmer
42
42
 
43
43
  OBSERVED_MENU_ITEMS = ['about', 'preferences', 'quit']
44
44
 
45
- class FilterListener
45
+ class ConcreteListener
46
46
  include org.eclipse.swt.widgets.Listener
47
47
 
48
48
  def initialize(&listener_block)
@@ -194,15 +194,17 @@ module Glimmer
194
194
  observation_request = observation_request.to_s
195
195
  if observation_request.start_with?('on_swt_')
196
196
  constant_name = observation_request.sub(/^on_swt_/, '')
197
- add_swt_event_filter(constant_name, &block)
197
+ swt_event_reg = add_swt_event_filter(constant_name, &block)
198
+ Glimmer::UI::CustomWidget.current_custom_widgets.last&.observer_registrations&.push(swt_event_reg)
199
+ swt_event_reg
198
200
  elsif observation_request.start_with?('on_')
199
201
  event_name = observation_request.sub(/^on_/, '')
200
202
  if OBSERVED_MENU_ITEMS.include?(event_name) && OS.mac?
201
203
  system_menu = swt_display.getSystemMenu
202
204
  menu_item = system_menu.getItems.find {|menu_item| menu_item.getID == SWTProxy["ID_#{event_name.upcase}"]}
203
- display_mac_event_registration = menu_item.addListener(SWTProxy[:Selection], &block)
204
- # TODO enable this code and test on the Mac to ensure automatic cleanup of mac event registrations in custom widgets
205
- # Glimmer::UI::CustomWidget.current_custom_widgets.last&.observer_registrations&.push(display_mac_event_registration)
205
+ listener = ConcreteListener.new(&block)
206
+ display_mac_event_registration = menu_item.addListener(SWTProxy[:Selection], listener)
207
+ Glimmer::UI::CustomWidget.current_custom_widgets.last&.observer_registrations&.push(display_mac_event_registration)
206
208
  display_mac_event_registration
207
209
  end
208
210
  end
@@ -210,15 +212,16 @@ module Glimmer
210
212
 
211
213
  def add_swt_event_filter(swt_constant, &block)
212
214
  event_type = SWTProxy[swt_constant]
213
- @swt_display.addFilter(event_type, FilterListener.new(&block))
215
+ swt_listener = ConcreteListener.new(&block)
216
+ @swt_display.addFilter(event_type, swt_listener)
214
217
  #WidgetListenerProxy.new(@swt_display.getListeners(event_type).last)
215
218
  WidgetListenerProxy.new(
216
219
  swt_display: @swt_display,
217
220
  event_type: event_type,
218
221
  filter: true,
219
- swt_listener: block,
222
+ swt_listener: swt_listener,
220
223
  widget_add_listener_method: 'addFilter',
221
- swt_listener_class: FilterListener,
224
+ swt_listener_class: ConcreteListener,
222
225
  swt_listener_method: 'handleEvent'
223
226
  )
224
227
  end