glimmer-dsl-swt 4.20.0.3 → 4.20.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/README.md +12 -6
  4. data/VERSION +1 -1
  5. data/docs/reference/GLIMMER_SAMPLES.md +34 -0
  6. data/docs/reference/GLIMMER_STYLE_GUIDE.md +4 -3
  7. data/glimmer-dsl-swt.gemspec +0 -0
  8. data/lib/glimmer/data_binding/shine.rb +5 -1
  9. data/lib/glimmer/data_binding/table_items_binding.rb +2 -2
  10. data/lib/glimmer/data_binding/tree_items_binding.rb +2 -2
  11. data/lib/glimmer/dsl/swt/shine_data_binding_expression.rb +6 -3
  12. data/lib/glimmer/dsl/swt/table_items_data_binding_expression.rb +2 -2
  13. data/lib/glimmer/dsl/swt/tree_items_data_binding_expression.rb +17 -12
  14. data/lib/glimmer/dsl/swt/widget_listener_expression.rb +3 -3
  15. data/lib/glimmer/swt/custom/animation.rb +6 -0
  16. data/lib/glimmer/swt/display_proxy.rb +11 -8
  17. data/lib/glimmer/swt/proxy_properties.rb +2 -1
  18. data/lib/glimmer/swt/table_proxy.rb +15 -8
  19. data/lib/glimmer/swt/widget_proxy.rb +2 -2
  20. data/lib/glimmer/ui/custom_shell.rb +3 -3
  21. data/lib/glimmer/ui/custom_widget.rb +5 -2
  22. data/samples/elaborate/calculator.rb +116 -0
  23. data/samples/elaborate/calculator/model/command.rb +105 -0
  24. data/samples/elaborate/calculator/model/command/all_clear.rb +17 -0
  25. data/samples/elaborate/calculator/model/command/command_history.rb +0 -0
  26. data/samples/elaborate/calculator/model/command/equals.rb +18 -0
  27. data/samples/elaborate/calculator/model/command/number.rb +20 -0
  28. data/samples/elaborate/calculator/model/command/operation.rb +27 -0
  29. data/samples/elaborate/calculator/model/command/operation/add.rb +15 -0
  30. data/samples/elaborate/calculator/model/command/operation/divide.rb +15 -0
  31. data/samples/elaborate/calculator/model/command/operation/multiply.rb +15 -0
  32. data/samples/elaborate/calculator/model/command/operation/subtract.rb +15 -0
  33. data/samples/elaborate/calculator/model/command/point.rb +20 -0
  34. data/samples/elaborate/calculator/model/presenter.rb +30 -0
  35. data/samples/elaborate/contact_manager.rb +1 -1
  36. data/samples/elaborate/login.rb +15 -13
  37. data/samples/elaborate/tetris.rb +6 -6
  38. data/samples/elaborate/tetris/view/high_score_dialog.rb +1 -1
  39. data/samples/elaborate/timer.rb +233 -0
  40. data/samples/elaborate/timer/alarm1.wav +0 -0
  41. data/samples/elaborate/timer/sounds/alarm1.wav +0 -0
  42. data/samples/elaborate/user_profile.rb +4 -2
  43. data/samples/elaborate/weather.rb +164 -0
  44. data/samples/hello/hello_canvas_animation_data_binding.rb +1 -1
  45. data/samples/hello/hello_cool_bar.rb +4 -4
  46. data/samples/hello/hello_custom_shell.rb +1 -1
  47. data/samples/hello/hello_table.rb +5 -5
  48. data/samples/hello/hello_text.rb +120 -0
  49. data/samples/hello/hello_tool_bar.rb +4 -4
  50. data/samples/hello/hello_tree.rb +11 -11
  51. metadata +20 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4f8d4338c2993469fc740a390cb380bf9faf4c1c93d3993e517080d5599825f
4
- data.tar.gz: 3e82de8a5c35d17b0e92b741e3a750885842094b9ee4a8c9e5aac56419613551
3
+ metadata.gz: ba041a49dabbc3bbe0b3ac98cb5ba113b386087149563a331290fba998a45887
4
+ data.tar.gz: 042ea65040e8b874f8477fa87266ae48c88affd922b824f64e1ab891b28f85ff
5
5
  SHA512:
6
- metadata.gz: 12b865d3c8e7e7a5a33928fea59a436d272a30f401171dfdf4e8464b5093c1c50db4f233af61b7af3e51ec8ddb53ebd67bff438f8525e3976acb50386a787fb9
7
- data.tar.gz: 8ce5f6eb7ec30624f9b140cdd994c414222cd0891daf3d212e93dfc76959413bdd53ddf4256a8dd55c530f8964a4b10962278a4b2c03cffc5045052e41a9dac4
6
+ metadata.gz: 755a71479d44c7bcb3efd6a4f4ae1e0c6d378f25374584bca4f1fe7ede096d683b6770016eb4566bbacb2c40bf2b64300846e57408cf0ca5745910bba68801ac
7
+ data.tar.gz: 75617372b2e04e5064cfa0a408504e43a4defd25194f1b16f27a91ca8275865dd3337ac76397087ac74e9878f51d194d7626c227509b9ac93a823a14faba0a4f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.2.1
4
+
5
+ - Shine data-binding support for `animation` (also supporting `#content {}` method in `Animation`)
6
+ - Update Hello, Custom Shell! to use Shine data-binding syntax
7
+ - Fix `table` automatic sorting support when using one-way Shine data-binding syntax (which was disabling reads)
8
+
9
+ ### 4.20.2.0
10
+
11
+ - Shine data-binding syntax support for `tree` widget
12
+ - Use Shine syntax in Hello, Tree! sample
13
+
14
+ ### 4.20.1.0
15
+
16
+ - Shine data-binding syntax support for `table` widget
17
+ - Use Shine syntax in Hello, Table! and Contact Manager samples
18
+
19
+ ### 4.20.0.5
20
+
21
+ - Hello, Text! sample
22
+ - Timer elaborate sample (copied and simplified from external sample)
23
+ - Calculator elaborate sample (copied and simplified from external sample)
24
+ - Fixed issue relating to cleaning up display listeners
25
+
26
+ ### 4.20.0.4
27
+
28
+ - Weather elaborate sample
29
+
30
+ ### 4.20.0.3
31
+
32
+ - Hello, Shell! sample
33
+
34
+ ### 4.20.0.2
35
+
36
+ - Hello, Tool Bar! sample
37
+ - Hello, Cool Bar! sample
38
+
3
39
  ### 4.20.0.1
4
40
 
5
41
  - Hello, Composite! 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.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 SWT 4.20.2.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,7 +15,7 @@
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.3 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.2.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
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).
21
21
 
@@ -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.3
350
+ jgem install glimmer-dsl-swt -v 4.20.2.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.3'
378
+ gem 'glimmer-dsl-swt', '~> 4.20.2.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.3
399
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.2.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.3
1
+ 4.20.2.1
@@ -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)
@@ -59,6 +60,7 @@
59
60
  - [Mandelbrot Fractal](#mandelbrot-fractal)
60
61
  - [Stock Ticker](#stock-ticker)
61
62
  - [Metronome](#metronome)
63
+ - [Weather](#weather)
62
64
  - [External Samples](#external-samples)
63
65
  - [Glimmer Calculator](#glimmer-calculator)
64
66
  - [Gladiator](#gladiator)
@@ -115,6 +117,18 @@ Hello, Button! Incremented 7 times!
115
117
 
116
118
  ![Hello Button Incremented](/images/glimmer-hello-button-incremented.png)
117
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
+
118
132
  #### Hello, Composite!
119
133
 
120
134
  This sample demonstrates the `composite` widget, which is simply used as a container for visual layout and organization.
@@ -1053,6 +1067,26 @@ Code:
1053
1067
 
1054
1068
  [Download video with sound](/videos/glimmer-metronome.mp4?raw=true).
1055
1069
 
1070
+ #### Weather
1071
+
1072
+ This sample demonstrates a Weather app that leverages the Ruby built-in `'net/http'` library, courtesy of openweathermap.org. It provides a good example of tackling JSON hierarchical hash/array data and converting into data-bindable model object attributes for Glimmer GUI synchronization.
1073
+
1074
+ Code:
1075
+
1076
+ [samples/elaborate/weather.rb](/samples/elaborate/weather.rb)
1077
+
1078
+ Montreal - Celsius
1079
+
1080
+ ![Montreal C](/images/glimmer-weather-montreal-celsius.png)
1081
+
1082
+ Montreal - Fahrenheit
1083
+
1084
+ ![Montreal F](/images/glimmer-weather-montreal-fahrenheit.png)
1085
+
1086
+ Atlanta - Fahrenheit
1087
+
1088
+ ![Atlanta F](/images/glimmer-weather-atlanta-fahrenheit.png)
1089
+
1056
1090
  ### External Samples
1057
1091
 
1058
1092
  #### Glimmer Calculator
@@ -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,10 @@ module Glimmer
33
33
 
34
34
  def <=>(other)
35
35
  if other.is_a?(Array)
36
+ args_clone = other.clone
37
+ @parent.editable = true if @parent.is_a?(Glimmer::SWT::TableProxy) # TODO consider a polymorphic way to perform this
36
38
  @parent.content {
37
- send(@parent_attribute, bind(*other))
39
+ send(@parent_attribute, bind(*args_clone))
38
40
  }
39
41
  else # || other.is_a?(Hash) # TODO support hash e.g. {model: model_obj, attribute: :some_attribute, more-options...}
40
42
  original_compare(other)
@@ -49,6 +51,8 @@ module Glimmer
49
51
  else # || other.is_a?(Hash) # TODO support hash e.g. {model: model_obj, attribute: :some_attribute, more-options...}
50
52
  args_clone << {read_only: true}
51
53
  end
54
+ # remove read_only from table to allow automatic sorting (but it remains non-editable)
55
+ args_clone.last[:read_only] = false if @parent.is_a?(Glimmer::SWT::TableProxy) # TODO consider a polymorphic way to perform this
52
56
  @parent.content {
53
57
  send(@parent_attribute, bind(*args_clone))
54
58
  }
@@ -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
@@ -29,12 +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
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
38
41
  !parent.is_a?(Glimmer::UI::CustomWidget) and
39
42
  !parent.is_a?(Glimmer::UI::CustomShape) and
40
43
  !(parent.respond_to?(:swt_widget) && parent.swt_widget.class == org.eclipse.swt.widgets.Canvas && keyword == 'image')
@@ -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
@@ -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
@@ -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
@@ -33,6 +33,7 @@ module Glimmer
33
33
  # default implementation of attribute setters/getters
34
34
  # It tries swt_widget, swt_display, swt_image, and swt_dialog by default.
35
35
  def proxy_source_object
36
+ # TODO the logic here should not be needed if derived with polymorphism. Consider removing.
36
37
  if respond_to?(:swt_widget)
37
38
  swt_widget
38
39
  elsif respond_to?(:swt_display)
@@ -62,7 +63,7 @@ module Glimmer
62
63
 
63
64
  def has_attribute?(attribute_name, *args)
64
65
  Glimmer::SWT::DisplayProxy.instance.auto_exec do
65
- proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) ||
66
+ proxy_source_object&.respond_to?(attribute_setter(attribute_name), args) or
66
67
  respond_to?(ruby_attribute_setter(attribute_name), args)
67
68
  end
68
69
  end
@@ -250,19 +250,13 @@ module Glimmer
250
250
  alias editable? editable
251
251
 
252
252
  def initialize(underscored_widget_name, parent, args)
253
- @editable = args.delete(:editable)
253
+ editable_style = args.delete(:editable)
254
254
  super
255
255
  @table_editor = TableEditor.new(swt_widget)
256
256
  @table_editor.horizontalAlignment = SWTProxy[:left]
257
257
  @table_editor.grabHorizontal = true
258
258
  @table_editor.minimumHeight = 20
259
- if editable?
260
- content {
261
- on_mouse_up { |event|
262
- edit_table_item(event.table_item, event.column_index)
263
- }
264
- }
265
- end
259
+ self.editable = editable_style
266
260
  end
267
261
 
268
262
  def items
@@ -283,6 +277,19 @@ module Glimmer
283
277
  end
284
278
  end
285
279
 
280
+ def editable=(value)
281
+ @editable = value
282
+ if @editable
283
+ content {
284
+ @editable_on_mouse_up = on_mouse_up { |event|
285
+ edit_table_item(event.table_item, event.column_index)
286
+ }
287
+ }
288
+ else
289
+ @editable_on_mouse_up.deregister if @editable_on_mouse_up
290
+ end
291
+ end
292
+
286
293
  def sort_block=(comparator)
287
294
  @sort_block = comparator
288
295
  end