glimmer-dsl-swt 4.24.2.1 → 4.24.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +8 -8
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md +99 -18
- data/docs/reference/GLIMMER_SAMPLES.md +7 -3
- data/glimmer-dsl-swt.gemspec +0 -0
- data/lib/glimmer/data_binding/table_items_binding.rb +141 -16
- data/lib/glimmer/dsl/swt/dialog_expression.rb +2 -2
- data/lib/glimmer/dsl/swt/display_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/font_expression.rb +1 -1
- data/lib/glimmer/dsl/swt/image_expression.rb +1 -0
- data/lib/glimmer/dsl/swt/message_box_expression.rb +5 -5
- data/lib/glimmer/dsl/swt/shell_expression.rb +1 -1
- data/lib/glimmer/swt/custom/code_text.rb +6 -3
- data/lib/glimmer/swt/font_proxy.rb +13 -3
- data/lib/glimmer/swt/table_proxy.rb +8 -2
- data/samples/elaborate/meta_sample/tutorials.yml +1 -0
- data/samples/hello/hello_custom_shape.rb +10 -10
- data/samples/hello/hello_table.rb +73 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90fac650eedadc1e677e27563bda759e5aa1ea7b2d5b6627129f906516c21a82
|
4
|
+
data.tar.gz: 4098c6d271799034a18747154236426cde6c7b83eca4030d5d1292f8bc0f52e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97d0b7a8a715410c6772b4cbb8cd45052c5d0db5e3c7b6f78a62fd9d8f23536dc467727b4441e0585f339674e63d4f9c3e622cdaea04a968e80ffde5ea6ea5f6
|
7
|
+
data.tar.gz: 159d537c854c56d6502a8ed248f5b54fe76590a411d5013d5f40844dd816c1212e49692e42b882c7262267de859580491ce4c9f015972f4b0baaea5169a0dddd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 4.24.3.0
|
4
|
+
|
5
|
+
- Support `table` `items` data-binding of table row cell `background`, `foreground`, `font`, `image` to model attributes by convention based on specified `column_properties` (e.g. for `column_properties` model `name` attribute, automatically assume model `name_background` provides `[r, g, b]` array of color)
|
6
|
+
- Update Hello, Table! sample to demonstrate data-binding `table` `items` `background`, `foreground`, `font`, `image` to model attributes by convention, and to add `booked` attribute on `BaseballGame` to disable Book button when already booked
|
7
|
+
- Update Hello, Table! sample to add `booked` attribute to `BaseballGame` to disable Book button when already booked
|
8
|
+
- Update Hello, Table! sample to enable booking by hitting the ENTER keyboard button
|
9
|
+
- Optimize `table` data-binding performance by not recreating table-items when the table grows or stays at the same size, and by not updating a table item (row) when no changes have occurred (detect through diffing)
|
10
|
+
- Update `font` keyword and `FontProxy` to support lightweight creation/caching/sharing following Flyweight Design Pattern
|
11
|
+
|
12
|
+
## 4.24.2.3
|
13
|
+
|
14
|
+
- Default `code_text` font name in Mac is changed back to `'Courier'`
|
15
|
+
|
16
|
+
## 4.24.2.2
|
17
|
+
|
18
|
+
- Upgrade to jruby-9.3.7.0
|
19
|
+
- `code_text` can use external Rouge custom themes similar to `ext/rouge/themes/glimmer_dark`. When in Dark Mode, the specified custom theme must have the word 'dark' in its name to avoid forcing the `glimmer_dark` theme instead as per default behavior.
|
20
|
+
- Look for 'Monospace' and 'Liberation Mono' fonts on Linux if 'Courier' is not available
|
21
|
+
- Fix issue discovered in Red Hat Linux related to ImageExpression getting loaded before others and missing `require 'glimmer/dsl/parent_expression'` statement (issue does not happen in other operating systems that load classes in a different order)
|
22
|
+
|
3
23
|
## 4.24.2.1
|
4
24
|
|
5
25
|
- Fix mistake of changing all themes to dark themes in Hello, Code Text! (not it works just like before)
|
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.24.
|
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.24.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)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
![Glimmer DSL for SWT Demo of Hello, World!](/images/glimmer-dsl-swt-demo-hello-world.gif)
|
14
14
|
|
15
|
-
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) is a native GUI (Graphical User Interface) cross-platform desktop development library written in [JRuby](https://www.jruby.org/), an OS-threaded faster [JVM](https://www.java.com/en/download/help/whatis_java.html) version of [Ruby](https://www.ruby-lang.org/en/). [Glimmer](https://github.com/AndyObtiva/glimmer)'s main innovation is a declarative [Ruby DSL](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#glimmer-dsl-syntax) (Domain Specific Language) that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust [Eclipse SWT library](https://www.eclipse.org/swt/). [Glimmer](https://rubygems.org/gems/glimmer) additionally innovates by having built-in [data-binding](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#data-binding) support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models afterwards. Not only does Glimmer provide a large set of GUI [widgets](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#widgets), but it also supports drawing Canvas Graphics like [Shapes](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-shape-dsl) and [Animations](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-animation-dsl). To get started quickly, [Glimmer](https://rubygems.org/gems/glimmer) offers [scaffolding](docs/reference/GLIMMER_COMMAND.md#scaffolding) options for [Apps](#in-production), [Gems](docs/reference/GLIMMER_COMMAND.md#custom-shell-gem), and [Custom Widgets](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#custom-widgets). [Glimmer](https://rubygems.org/gems/glimmer) also includes native-executable [packaging](docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md) support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in [Ruby](https://www.ruby-lang.org/en/) as truly native DMG/PKG/APP files on the [Mac](https://www.apple.com/ca/macos), MSI/EXE files on [Windows](https://www.microsoft.com/en-ca/windows), and DEB/RPM files on [Linux](https://www.linux.org/). [Glimmer](https://github.com/AndyObtiva/glimmer) was the [first Ruby gem](https://rubygems.org/gems/glimmer) to bring [SWT](https://www.eclipse.org/swt/) (Standard Widget Toolkit) to [Ruby](https://www.ruby-lang.org/en/), thanks to creator [Andy Maleh](https://andymaleh.blogspot.com/), EclipseCon/EclipseWorld/RubyConf speaker.
|
15
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [SWT](https://www.eclipse.org/swt/) (formerly [Glimmer](https://github.com/AndyObtiva/glimmer)) is a native GUI (Graphical User Interface) cross-platform desktop development library written in [JRuby](https://www.jruby.org/), an OS-threaded faster [JVM](https://www.java.com/en/download/help/whatis_java.html) version of [Ruby](https://www.ruby-lang.org/en/). [Glimmer](https://github.com/AndyObtiva/glimmer)'s main innovation is a declarative [Ruby DSL](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#glimmer-dsl-syntax) (Domain Specific Language) that enables productive and efficient authoring of desktop application user-interfaces by relying on the robust [Eclipse SWT library](https://www.eclipse.org/swt/). [Glimmer](https://rubygems.org/gems/glimmer) additionally innovates by having built-in [data-binding](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#data-binding) support, which greatly facilitates synchronizing the GUI with domain models, thus achieving true decoupling of object oriented components and enabling developers to solve business problems (test-first) without worrying about GUI concerns, or alternatively drive development GUI-first, and then write clean business models afterwards. Not only does Glimmer provide a large set of GUI [widgets](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#widgets), but it also supports drawing Canvas Graphics like [Shapes](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-shape-dsl) and [Animations](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-animation-dsl). To get started quickly, [Glimmer](https://rubygems.org/gems/glimmer) offers [scaffolding](docs/reference/GLIMMER_COMMAND.md#scaffolding) options for [Apps](#in-production), [Gems](docs/reference/GLIMMER_COMMAND.md#custom-shell-gem), and [Custom Widgets](docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#custom-widgets). [Glimmer](https://rubygems.org/gems/glimmer) also includes native-executable [packaging](docs/reference/GLIMMER_PACKAGING_AND_DISTRIBUTION.md) support, sorely lacking in other libraries, thus enabling the delivery of desktop apps written in [Ruby](https://www.ruby-lang.org/en/) as truly native DMG/PKG/APP files on the [Mac](https://www.apple.com/ca/macos), MSI/EXE files on [Windows](https://www.microsoft.com/en-ca/windows), and DEB/RPM files on [Linux](https://www.linux.org/). [Glimmer](https://github.com/AndyObtiva/glimmer) was the [first Ruby gem](https://rubygems.org/gems/glimmer) to bring [SWT](https://www.eclipse.org/swt/) (Standard Widget Toolkit) to [Ruby](https://www.ruby-lang.org/en/), thanks to creator [Andy Maleh](https://andymaleh.blogspot.com/), EclipseCon/EclipseWorld/RubyConf speaker.
|
16
16
|
|
17
17
|
[<img src="https://covers.oreillystatic.com/images/9780596519650/lrg.jpg" width=105 /><br />
|
18
18
|
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)
|
@@ -21,7 +21,7 @@ Featured in JRuby Cookbook](http://shop.oreilly.com/product/9780596519650.do) an
|
|
21
21
|
|
22
22
|
![Eclipse SWT RCP NASA Mars Rover](/images/glimmer-eclipse-swt-rcp-nasa-mars-rover.png)
|
23
23
|
|
24
|
-
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.24.
|
24
|
+
[Glimmer DSL for SWT](https://rubygems.org/gems/glimmer-dsl-swt) 4.24.3.0 includes [SWT 4.24](https://download.eclipse.org/eclipse/downloads/drops4/R-4.24-202206070700/), which was released on June 7, 2022. 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.
|
25
25
|
|
26
26
|
**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. That was [originally conceived back in 2007](https://andymaleh.blogspot.com/2007/12/data-shining-in-glimmer.html).
|
27
27
|
|
@@ -306,9 +306,9 @@ https://www.eclipse.org/swt/faq.php
|
|
306
306
|
|
307
307
|
## Pre-requisites
|
308
308
|
|
309
|
-
- JDK 18 is required / JDK 16 is
|
309
|
+
- JDK 18 is required / JDK 16 is minimum except on Mac ARM64 where JDK 17 is minimum (find at https://www.oracle.com/java/technologies/downloads / Ensure `PATH` env var includes Java bin directory for `jpackage` command to work when packaging Glimmer applications / Preferably setup `JAVA_HOME` env var too to point to JDK home directory before installing JRuby)
|
310
310
|
- [RVM](http://rvm.io) on Mac & Linux (not needed on Windows)
|
311
|
-
- JRuby 9.3.
|
311
|
+
- JRuby 9.3.7.0 is required / JRuby 9.3.6.0 is minimum (supporting Ruby 2.6.x syntax) (get via [RVM](http://rvm.io) on Mac and Linux by running `rvm install jruby-9.3.7.0`; On Windows, find at [https://www.jruby.org/download](https://www.jruby.org/download))
|
312
312
|
- SWT 4.24 (already included in the [glimmer-dsl-swt](https://rubygems.org/gems/glimmer-dsl-swt) gem). Note that SWT supports ARM64/AARCH64 on Mac and Linux since version 4.20
|
313
313
|
- Git (comes with Mac and Linux. Install on Windows: https://git-scm.com/download/win )
|
314
314
|
|
@@ -338,7 +338,7 @@ jgem install glimmer-dsl-swt
|
|
338
338
|
|
339
339
|
Or this command if you want a specific version:
|
340
340
|
```
|
341
|
-
jgem install glimmer-dsl-swt -v 4.24.
|
341
|
+
jgem install glimmer-dsl-swt -v 4.24.3.0
|
342
342
|
```
|
343
343
|
|
344
344
|
`jgem` is JRuby's version of `gem` command.
|
@@ -366,7 +366,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
|
|
366
366
|
|
367
367
|
Add the following to `Gemfile`:
|
368
368
|
```
|
369
|
-
gem 'glimmer-dsl-swt', '~> 4.24.
|
369
|
+
gem 'glimmer-dsl-swt', '~> 4.24.3.0'
|
370
370
|
```
|
371
371
|
|
372
372
|
And, then run:
|
@@ -389,7 +389,7 @@ glimmer
|
|
389
389
|
```
|
390
390
|
|
391
391
|
```
|
392
|
-
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.24.
|
392
|
+
Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.24.3.0
|
393
393
|
|
394
394
|
Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
|
395
395
|
|
data/RUBY_VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-9.3.
|
1
|
+
jruby-9.3.7.0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.24.
|
1
|
+
4.24.3.0
|
@@ -4019,8 +4019,8 @@ shell {
|
|
4019
4019
|
text "Adult"
|
4020
4020
|
width 120
|
4021
4021
|
}
|
4022
|
-
items
|
4023
|
-
selection
|
4022
|
+
items <=> [group, :people, column_properties: [:name, :age, :adult]]
|
4023
|
+
selection <=> [group, :selected_person]
|
4024
4024
|
on_mouse_up do |event|
|
4025
4025
|
@table.edit_table_item(event.table_item, event.column_index)
|
4026
4026
|
end
|
@@ -4051,6 +4051,24 @@ This automatically leverages the SWT TableEditor custom class behind the scenes,
|
|
4051
4051
|
passed table item text into something else.
|
4052
4052
|
It automatically persists the change to `items` data-bound model on ENTER/FOCUS-OUT or cancels on ESC/NO-CHANGE.
|
4053
4053
|
|
4054
|
+
##### Table Item Properties
|
4055
|
+
|
4056
|
+
When data-binding a `table`'s `items`, extra [`TableItem` properties](https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/TableItem.html) are data-bound automatically by convention for `background` color, `foreground` color, `font`, and `image` if corresponding properties (attributes) are available on the model.
|
4057
|
+
|
4058
|
+
That means that if `column_properties` were `[:name, :age, :adult]`, then the following [`TableItem` properties](https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/TableItem.html) are also data-bound by convention:
|
4059
|
+
- `background` to `:name_background, :age_background, :adult_background` model attributes
|
4060
|
+
- `foreground` to `:name_foreground, :age_foreground, :adult_foreground` model attributes
|
4061
|
+
- `font` to `:name_font, :age_font, :adult_font` model attributes
|
4062
|
+
- `image` to `:name_image, :age_image, :adult_image` model attributes
|
4063
|
+
|
4064
|
+
Here are the expected values for each [`TableItem` property](https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/TableItem.html):
|
4065
|
+
- `background`: Standard color symbol/string (e.g. `:red`), rgb array (e.g. `[24, 21, 239]`), or rgba array (e.g. `[128, 0, 128, 50]`)
|
4066
|
+
- `foreground`: Standard color symbol/string (e.g. `:red`), rgb array (e.g. `[24, 21, 239]`), or rgba array (e.g. `[128, 0, 128, 50]`)
|
4067
|
+
- `font`: font data hash having `:name`, `:height`, and/or `:style` keys (e.g. `{name: 'Courier New', height: 25, style: [:bold, :italic]}`)
|
4068
|
+
- `image`: image URL with or without image options (e.g. `'/usr/image1.png'` or `['/usr/image1.png', width: 20, height: 20]`)
|
4069
|
+
|
4070
|
+
![Hello Table game booked rows](/images/glimmer-hello-table-game-booked-rows.png)
|
4071
|
+
|
4054
4072
|
##### Table Selection
|
4055
4073
|
|
4056
4074
|
Table Selection data-binding is simply done via the `selection` property.
|
@@ -4807,32 +4825,93 @@ You may see another example at the [Hello, Radio Group!](/docs/reference/GLIMMER
|
|
4807
4825
|
|
4808
4826
|
##### Code Text Custom Widget
|
4809
4827
|
|
4810
|
-
`code_text` is a Glimmer built-in custom widget that displays syntax highlighted Ruby code
|
4828
|
+
`code_text` is a Glimmer built-in custom widget that displays syntax highlighted code (e.g. Ruby/JavaScript/HTML code) for 204 languages (see [options](#code-text-options) for the full list) by automating customizations for the SWT [StyledText](https://help.eclipse.org/2020-09/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/custom/StyledText.html) widget.
|
4829
|
+
|
4830
|
+
To utilize, simply use `code_text` in place of the multi-line `text` and `styled_text` widgets. If you set the `code_text` `text` property value to multi-line code content (e.g. Ruby/JavaScript/HTML code), it automatically styles it with syntax highlighting.
|
4811
4831
|
|
4812
|
-
|
4813
|
-
1. Consolas
|
4814
|
-
2. Courier
|
4815
|
-
3.
|
4816
|
-
4.
|
4832
|
+
`code_text` attempts to use a monospace font if available, seeking font names in the following order (specified in `Glimmer::SWT::Custom::CodeText::FONT_NAMES_PREFERRED`):
|
4833
|
+
1. `'Consolas'`
|
4834
|
+
2. `'Courier'`
|
4835
|
+
3. `'Monospace'`
|
4836
|
+
4. `'Liberation Mono'`
|
4837
|
+
5. First available font that contains the word `mono` (case-insensitive)
|
4838
|
+
6. Default system font (if no other font in the list is found)
|
4817
4839
|
|
4818
4840
|
It is used in the [Glimmer Meta-Sample (The Sample of Samples)](#samples):
|
4819
4841
|
|
4820
4842
|
![Glimmer Meta-Sample](/images/glimmer-meta-sample.png)
|
4821
4843
|
|
4822
|
-
|
4844
|
+
Dark Mode:
|
4845
|
+
|
4846
|
+
![Glimmer Meta-Sample](/images/glimmer-meta-sample-dark-mode.png)
|
4847
|
+
|
4848
|
+
Code Text Simple Example (default language is Ruby):
|
4823
4849
|
|
4824
4850
|
```ruby
|
4825
|
-
|
4826
|
-
@code_text = code_text {
|
4851
|
+
code_text {
|
4827
4852
|
text bind(SampleDirectory, 'selected_sample.code', read_only: true)
|
4828
4853
|
editable bind(SampleDirectory, 'selected_sample.editable')
|
4829
4854
|
}
|
4830
|
-
# ...
|
4831
4855
|
```
|
4832
4856
|
|
4833
|
-
|
4857
|
+
Code Text Specified Language Example:
|
4858
|
+
|
4859
|
+
```ruby
|
4860
|
+
code_text(language: 'html') {
|
4861
|
+
text bind(SampleDirectory, 'selected_sample.code', read_only: true)
|
4862
|
+
editable bind(SampleDirectory, 'selected_sample.editable')
|
4863
|
+
}
|
4864
|
+
```
|
4834
4865
|
|
4835
|
-
|
4866
|
+
Code Text Lines and Margins Example:
|
4867
|
+
|
4868
|
+
```ruby
|
4869
|
+
code_text(lines: true) {
|
4870
|
+
text <=> [SampleDirectory, 'selected_sample.code']
|
4871
|
+
editable <= [SampleDirectory, 'selected_sample.editable']
|
4872
|
+
left_margin 7
|
4873
|
+
right_margin 7
|
4874
|
+
}
|
4875
|
+
```
|
4876
|
+
|
4877
|
+
Code Text Customized Lines Width and Background Example:
|
4878
|
+
|
4879
|
+
```ruby
|
4880
|
+
code_text(lines: {width: 3}) {
|
4881
|
+
line_numbers {
|
4882
|
+
background Display.system_dark_theme? ? :black : :white
|
4883
|
+
}
|
4884
|
+
text <=> [SampleDirectory, 'selected_sample.code']
|
4885
|
+
editable <= [SampleDirectory, 'selected_sample.editable']
|
4886
|
+
left_margin 7
|
4887
|
+
right_margin 7
|
4888
|
+
}
|
4889
|
+
```
|
4890
|
+
|
4891
|
+
Code Text Customized Root Composite Margins/Spacing Background Example:
|
4892
|
+
|
4893
|
+
```ruby
|
4894
|
+
code_text(lines: true) {
|
4895
|
+
root {
|
4896
|
+
grid_layout(2, false) {
|
4897
|
+
horizontal_spacing 0
|
4898
|
+
margin_left 0
|
4899
|
+
margin_right 0
|
4900
|
+
margin_top 0
|
4901
|
+
margin_bottom 0
|
4902
|
+
}
|
4903
|
+
}
|
4904
|
+
line_numbers {
|
4905
|
+
background Display.system_dark_theme? ? :black : :white
|
4906
|
+
}
|
4907
|
+
text <=> [SampleDirectory, 'selected_sample.code']
|
4908
|
+
editable <= [SampleDirectory, 'selected_sample.editable']
|
4909
|
+
left_margin 7
|
4910
|
+
right_margin 7
|
4911
|
+
}
|
4912
|
+
```
|
4913
|
+
|
4914
|
+
###### Code Text Options
|
4836
4915
|
|
4837
4916
|
**lines**
|
4838
4917
|
(default: `false`)
|
@@ -4847,10 +4926,12 @@ Keep in mind that if the text grows and required a wider line numbers area, it g
|
|
4847
4926
|
(default: `'glimmer'`)
|
4848
4927
|
|
4849
4928
|
Changes syntax color highlighting theme. Can be one of the following:
|
4850
|
-
- glimmer
|
4851
|
-
- glimmer_dark (always applied when OS is in dark
|
4852
|
-
- github
|
4853
|
-
- pastie
|
4929
|
+
- `'glimmer'`
|
4930
|
+
- `'glimmer_dark'` (always applied when OS is in Dark Mode unless you set another custom theme that has the word `dark` in its name, see more details below)
|
4931
|
+
- `'github'`
|
4932
|
+
- `'pastie'`
|
4933
|
+
|
4934
|
+
Or you can simply implement a new [Rouge](https://github.com/rouge-ruby/rouge) **custom theme** just like the [github](https://github.com/rouge-ruby/rouge/blob/master/lib/rouge/themes/github.rb) theme or the glimmer theme: [lib/ext/rouge/themes/glimmer.rb](/lib/ext/rouge/themes/glimmer.rb)
|
4854
4935
|
|
4855
4936
|
**language**
|
4856
4937
|
(default: `'ruby'`)
|
@@ -768,13 +768,17 @@ Hello, Table! Playoff Type Changed
|
|
768
768
|
|
769
769
|
![Hello Table](/images/glimmer-hello-table-playoff-type-changed.png)
|
770
770
|
|
771
|
+
Hello, Table! Context Menu
|
772
|
+
|
773
|
+
![Hello Table](/images/glimmer-hello-table-context-menu.png)
|
774
|
+
|
771
775
|
Hello, Table! Game Booked
|
772
776
|
|
773
777
|
![Hello Table](/images/glimmer-hello-table-game-booked.png)
|
774
778
|
|
775
|
-
Hello, Table!
|
779
|
+
Hello, Table! Game Booked Rows
|
776
780
|
|
777
|
-
![Hello Table](/images/glimmer-hello-table-
|
781
|
+
![Hello Table game booked rows](/images/glimmer-hello-table-game-booked-rows.png)
|
778
782
|
|
779
783
|
#### Hello, Link!
|
780
784
|
|
@@ -810,7 +814,7 @@ Hello, Dialog! Open Dialog
|
|
810
814
|
|
811
815
|
#### Hello, Code Text!
|
812
816
|
|
813
|
-
This sample demonstrates the Glimmer Built-In [Code Text Custom Widget](#code-text-custom-widget).
|
817
|
+
This sample demonstrates the Glimmer Built-In [Code Text Custom Widget](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#code-text-custom-widget).
|
814
818
|
|
815
819
|
Code:
|
816
820
|
|
data/glimmer-dsl-swt.gemspec
CHANGED
Binary file
|
@@ -19,6 +19,8 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
+
require 'set'
|
23
|
+
|
22
24
|
require 'glimmer/data_binding/observable_array'
|
23
25
|
require 'glimmer/data_binding/observable_model'
|
24
26
|
require 'glimmer/data_binding/observable'
|
@@ -33,6 +35,8 @@ module Glimmer
|
|
33
35
|
include DataBinding::Observer
|
34
36
|
include_package 'org.eclipse.swt'
|
35
37
|
include_package 'org.eclipse.swt.widgets'
|
38
|
+
|
39
|
+
TABLE_ITEM_PROPERTIES = %w[background foreground font image]
|
36
40
|
|
37
41
|
def initialize(parent, model_binding, column_properties = nil)
|
38
42
|
@table = parent
|
@@ -56,40 +60,161 @@ module Glimmer
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
|
59
|
-
def call(
|
63
|
+
def call(*args)
|
64
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
65
|
+
internal_sort = options[:internal_sort] || false
|
66
|
+
new_model_collection = args.first
|
60
67
|
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
|
61
68
|
new_model_collection = model_binding_evaluated_property = @model_binding.evaluate_property unless internal_sort # this ensures applying converters (e.g. :on_read)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
return if same_table_data?(new_model_collection)
|
70
|
+
if same_model_collection?(new_model_collection)
|
71
|
+
new_model_collection_attribute_values = model_collection_attribute_values(new_model_collection)
|
72
|
+
@table.swt_widget.items.each_with_index do |table_item, row_index|
|
73
|
+
next if new_model_collection_attribute_values[row_index] == @last_model_collection_attribute_values[row_index]
|
74
|
+
model = table_item.get_data
|
75
|
+
(0..(@column_properties.size-1)).each do |column_index|
|
76
|
+
new_model_attribute_values_for_index = model_attribute_values_for_index(new_model_collection_attribute_values[row_index], column_index)
|
77
|
+
last_model_attribute_values_for_index = model_attribute_values_for_index(@last_model_collection_attribute_values[row_index], column_index)
|
78
|
+
next if new_model_attribute_values_for_index == last_model_attribute_values_for_index
|
79
|
+
model_attribute = @column_properties[column_index]
|
80
|
+
update_table_item_properties_from_model(table_item, row_index, column_index, model, model_attribute)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
@last_model_collection_attribute_values = new_model_collection_attribute_values
|
84
|
+
else
|
85
|
+
if new_model_collection and new_model_collection.is_a?(Array)
|
86
|
+
remove_dependent(@table_observer_registration => @table_items_observer_registration) if @table_items_observer_registration
|
87
|
+
@table_items_observer_registration&.unobserve
|
88
|
+
# TODO observe and update table items piecemeal per model instead of passing @column_properties
|
89
|
+
# TODO ensure unobserving models when they are no longer part of the table
|
90
|
+
@table_items_observer_registration = observe(new_model_collection, @column_properties)
|
91
|
+
add_dependent(@table_observer_registration => @table_items_observer_registration)
|
92
|
+
@table_items_property_observer_registration ||= {}
|
93
|
+
if !same_model_collection_with_different_sort?(new_model_collection)
|
94
|
+
TABLE_ITEM_PROPERTIES.each do |table_item_property|
|
95
|
+
remove_dependent(@table_observer_registration => @table_items_property_observer_registration[table_item_property]) if @table_items_property_observer_registration[table_item_property]
|
96
|
+
@table_items_property_observer_registration[table_item_property]&.unobserve
|
97
|
+
property_properties = @column_properties.map {|property| "#{property}_#{table_item_property}" }
|
98
|
+
@table_items_property_observer_registration[table_item_property] = observe(new_model_collection, property_properties)
|
99
|
+
add_dependent(@table_observer_registration => @table_items_property_observer_registration[table_item_property])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
@model_collection = new_model_collection
|
103
|
+
end
|
104
|
+
populate_table(@model_collection, @table, @column_properties, internal_sort: internal_sort)
|
70
105
|
end
|
71
|
-
populate_table(@model_collection, @table, @column_properties, internal_sort: internal_sort)
|
72
106
|
end
|
73
107
|
end
|
74
108
|
|
75
109
|
def populate_table(model_collection, parent, column_properties, internal_sort: false)
|
76
110
|
selected_table_item_models = parent.swt_widget.getSelection.map(&:get_data)
|
77
111
|
parent.finish_edit!
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
112
|
+
dispose_start_index = @last_model_collection_attribute_values &&
|
113
|
+
(model_collection.count < @last_model_collection_attribute_values.count) &&
|
114
|
+
(@last_model_collection_attribute_values.count - (@last_model_collection_attribute_values.count - model_collection.count))
|
115
|
+
if dispose_start_index
|
116
|
+
table_items_to_dispose = parent.swt_widget.items[dispose_start_index..-1]
|
117
|
+
parent.swt_widget.remove(dispose_start_index, (@last_model_collection_attribute_values.count-1))
|
118
|
+
table_items_to_dispose.each(&:dispose)
|
119
|
+
end
|
120
|
+
model_collection.each_with_index do |model, row_index|
|
121
|
+
table_item_exists = @last_model_collection_attribute_values &&
|
122
|
+
@last_model_collection_attribute_values.count > 0 &&
|
123
|
+
row_index < @last_model_collection_attribute_values.count
|
124
|
+
table_item = table_item_exists ? parent.swt_widget.items[row_index] : TableItem.new(parent.swt_widget, SWT::SWTProxy[:none])
|
125
|
+
(0..(column_properties.size-1)).each do |column_index|
|
126
|
+
model_attribute = column_properties[column_index]
|
127
|
+
update_table_item_properties_from_model(table_item, row_index, column_index, model, model_attribute)
|
84
128
|
end
|
85
129
|
table_item.set_data(model)
|
86
130
|
end
|
131
|
+
@last_model_collection_attribute_values = model_collection_attribute_values(model_collection)
|
87
132
|
selected_table_items = parent.search {|item| selected_table_item_models.include?(item.get_data) }
|
88
133
|
parent.swt_widget.setSelection(selected_table_items)
|
89
134
|
sorted_model_collection = parent.sort!(internal_sort: internal_sort)
|
90
135
|
call(sorted_model_collection, internal_sort: true) if @read_only_sort && !internal_sort && !sorted_model_collection.nil?
|
91
136
|
parent.swt_widget.redraw if parent&.swt_widget&.respond_to?(:redraw)
|
92
137
|
end
|
138
|
+
|
139
|
+
def update_table_item_properties_from_model(table_item, row_index, column_index, model, model_attribute)
|
140
|
+
Glimmer::SWT::DisplayProxy.instance.sync_exec do
|
141
|
+
old_table_item_values = @last_model_collection_attribute_values &&
|
142
|
+
@last_model_collection_attribute_values[row_index] &&
|
143
|
+
model_attribute_values_for_index(@last_model_collection_attribute_values[row_index], column_index)
|
144
|
+
text_value = model.send(model_attribute).to_s
|
145
|
+
old_table_item_value = old_table_item_values && old_table_item_values[0]
|
146
|
+
table_item.set_text(column_index, text_value) if old_table_item_value.nil? || text_value != old_table_item_value
|
147
|
+
TABLE_ITEM_PROPERTIES.each do |table_item_property|
|
148
|
+
if model.respond_to?("#{model_attribute}_#{table_item_property}")
|
149
|
+
table_item_value = model.send("#{model_attribute}_#{table_item_property}")
|
150
|
+
old_table_item_value = old_table_item_values && old_table_item_values[1 + TABLE_ITEM_PROPERTIES.index(table_item_property)]
|
151
|
+
if old_table_item_value.nil? || (table_item_value != old_table_item_value)
|
152
|
+
table_item_value = Glimmer::SWT::ColorProxy.create(*table_item_value).swt_color if table_item_value && %w[background foreground].include?(table_item_property.to_s)
|
153
|
+
table_item_value = Glimmer::SWT::FontProxy.create(table_item_value).swt_font if table_item_value && table_item_property.to_s == 'font'
|
154
|
+
table_item_value = Glimmer::SWT::ImageProxy.create(*table_item_value).swt_image if table_item_value && table_item_property.to_s == 'image'
|
155
|
+
table_item.send("set_#{table_item_property}", column_index, table_item_value)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def same_table_data?(new_model_collection)
|
163
|
+
(["text"] + TABLE_ITEM_PROPERTIES).all? do |table_item_property|
|
164
|
+
table_cells = @table.swt_widget.items.map do |item|
|
165
|
+
model = item.get_data
|
166
|
+
@table.column_properties.each_with_index.map do |column_property, i|
|
167
|
+
model_attribute = "#{column_property}"
|
168
|
+
model_attribute = "#{model_attribute}_#{table_item_property}" if TABLE_ITEM_PROPERTIES.include?(table_item_property)
|
169
|
+
item.send("get_#{table_item_property}", i) if model.respond_to?(model_attribute)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
model_cells = new_model_collection.to_a.map do |m|
|
173
|
+
@table.cells_for(m, table_item_property: table_item_property)
|
174
|
+
end
|
175
|
+
model_cells = model_cells.map do |row|
|
176
|
+
row.map do |model_cell|
|
177
|
+
if model_cell
|
178
|
+
if %w[background foreground].include?(table_item_property.to_s)
|
179
|
+
Glimmer::SWT::ColorProxy.create(*model_cell).swt_color
|
180
|
+
elsif table_item_property.to_s == 'font'
|
181
|
+
Glimmer::SWT::FontProxy.create(model_cell).swt_font
|
182
|
+
elsif table_item_property.to_s == 'image'
|
183
|
+
Glimmer::SWT::ImageProxy.create(*model_cell).swt_image
|
184
|
+
else
|
185
|
+
model_cell
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
table_cells == model_cells
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def same_model_collection?(new_model_collection)
|
195
|
+
new_model_collection == table_item_model_collection
|
196
|
+
end
|
197
|
+
|
198
|
+
def same_model_collection_with_different_sort?(new_model_collection)
|
199
|
+
Set.new(new_model_collection) == Set.new(table_item_model_collection)
|
200
|
+
end
|
201
|
+
|
202
|
+
def table_item_model_collection
|
203
|
+
@table.swt_widget.items.map(&:get_data)
|
204
|
+
end
|
205
|
+
|
206
|
+
def model_collection_attribute_values(model_collection)
|
207
|
+
model_collection.map do |model|
|
208
|
+
(["text"] + TABLE_ITEM_PROPERTIES).map do |table_item_property|
|
209
|
+
@table.cells_for(model, table_item_property: table_item_property)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def model_attribute_values_for_index(model_attribute_values, index)
|
215
|
+
model_attribute_values.map {|attribute_values| attribute_values[index]}
|
216
|
+
end
|
217
|
+
|
93
218
|
end
|
94
219
|
end
|
95
220
|
end
|
@@ -19,9 +19,9 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
|
-
require 'glimmer/dsl/
|
23
|
-
require 'glimmer/dsl/parent_expression'
|
22
|
+
require 'glimmer/dsl/expression'
|
24
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
25
25
|
require 'glimmer/swt/shell_proxy'
|
26
26
|
require 'glimmer/swt/dialog_proxy'
|
27
27
|
|
@@ -20,8 +20,8 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/static_expression'
|
23
|
-
require 'glimmer/dsl/parent_expression'
|
24
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
25
25
|
require 'glimmer/swt/display_proxy'
|
26
26
|
|
27
27
|
module Glimmer
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (c) 2007-2022 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
|
@@ -20,8 +20,8 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/static_expression'
|
23
|
-
require 'glimmer/dsl/parent_expression'
|
24
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
25
25
|
require 'glimmer/swt/shell_proxy'
|
26
26
|
require 'glimmer/swt/message_box_proxy'
|
27
27
|
require 'glimmer/swt/swt_proxy'
|
@@ -38,7 +38,7 @@ module Glimmer
|
|
38
38
|
def interpret(parent, keyword, *args, &block)
|
39
39
|
potential_parent = args.first
|
40
40
|
potential_parent = potential_parent.swt_widget if potential_parent.respond_to?(:swt_widget)
|
41
|
-
parent = nil
|
41
|
+
parent = nil
|
42
42
|
if potential_parent.is_a?(Shell)
|
43
43
|
args.shift
|
44
44
|
parent = potential_parent
|
@@ -20,8 +20,8 @@
|
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
require 'glimmer/dsl/static_expression'
|
23
|
-
require 'glimmer/dsl/parent_expression'
|
24
23
|
require 'glimmer/dsl/top_level_expression'
|
24
|
+
require 'glimmer/dsl/parent_expression'
|
25
25
|
require 'glimmer/swt/shell_proxy'
|
26
26
|
|
27
27
|
module Glimmer
|
@@ -41,6 +41,7 @@ module Glimmer
|
|
41
41
|
end
|
42
42
|
|
43
43
|
REGEX_COLOR_HEX6 = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/
|
44
|
+
FONT_NAMES_PREFERRED = ['Consolas', 'Courier', 'Monospace', 'Liberation Mono']
|
44
45
|
|
45
46
|
# TODO support auto language detection
|
46
47
|
|
@@ -126,7 +127,7 @@ module Glimmer
|
|
126
127
|
require 'ext/rouge/themes/glimmer'
|
127
128
|
require 'ext/rouge/themes/glimmer_dark'
|
128
129
|
@dark_mode = Java::OrgEclipseSwtWidgets::Display.system_dark_theme?
|
129
|
-
self.theme = 'glimmer_dark' if @dark_mode
|
130
|
+
self.theme = 'glimmer_dark' if @dark_mode && !theme.downcase.include?('dark')
|
130
131
|
@dark_theme = theme.include?('dark')
|
131
132
|
@swt_style = swt_style == 0 ? [:border, :multi, :v_scroll, :h_scroll] : swt_style
|
132
133
|
select_best_font
|
@@ -325,8 +326,10 @@ module Glimmer
|
|
325
326
|
|
326
327
|
def select_best_font_name
|
327
328
|
all_font_names = display.get_font_list(nil, true).map(&:name)
|
328
|
-
@font_name
|
329
|
-
|
329
|
+
@font_name = 'Courier' if OS.mac?
|
330
|
+
FONT_NAMES_PREFERRED.each do |font_name|
|
331
|
+
@font_name ||= font_name if all_font_names.include?(font_name)
|
332
|
+
end
|
330
333
|
@font_name ||= all_font_names.find {|font_name| font_name.downcase.include?('mono')}
|
331
334
|
@font_name
|
332
335
|
end
|
@@ -36,14 +36,24 @@ module Glimmer
|
|
36
36
|
#
|
37
37
|
# Follows the Proxy Design Pattern
|
38
38
|
class FontProxy
|
39
|
-
|
40
|
-
|
39
|
+
class << self
|
40
|
+
def create(*args)
|
41
|
+
flyweight_font_proxies[args] ||= new(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
|
45
|
+
def flyweight_font_proxies
|
46
|
+
@flyweight_font_proxies ||= {}
|
47
|
+
end
|
48
|
+
end
|
41
49
|
|
42
50
|
include_package 'org.eclipse.swt.graphics'
|
51
|
+
|
52
|
+
ERROR_INVALID_FONT_STYLE = " is an invalid font style! Valid values are :normal, :bold, and :italic"
|
53
|
+
FONT_STYLES = [:normal, :bold, :italic]
|
43
54
|
|
44
55
|
attr_reader :widget_proxy, :swt_font, :font_properties
|
45
56
|
|
46
|
-
|
47
57
|
# Builds a new font proxy from passed in widget_proxy and font_properties hash,
|
48
58
|
#
|
49
59
|
# It begins with existing SWT widget font and amends it with font properties.
|
@@ -419,8 +419,14 @@ module Glimmer
|
|
419
419
|
@editor = args
|
420
420
|
end
|
421
421
|
|
422
|
-
def cells_for(model)
|
423
|
-
|
422
|
+
def cells_for(model, table_item_property: :text)
|
423
|
+
if table_item_property.to_s == 'text'
|
424
|
+
column_properties.map {|column_property| model.send(column_property)}
|
425
|
+
else
|
426
|
+
column_properties.map do |column_property|
|
427
|
+
model.send("#{column_property}_#{table_item_property}") if model.respond_to?("#{column_property}_#{table_item_property}")
|
428
|
+
end
|
429
|
+
end
|
424
430
|
end
|
425
431
|
|
426
432
|
def cells
|
@@ -25,17 +25,17 @@ require 'glimmer-dsl-swt'
|
|
25
25
|
class StickFigure
|
26
26
|
include Glimmer::UI::CustomShape
|
27
27
|
|
28
|
-
options :
|
28
|
+
options :figure_x, :figure_y, :figure_width, :figure_height
|
29
29
|
|
30
30
|
before_body do
|
31
|
-
@head_width =
|
32
|
-
@head_height =
|
33
|
-
@trunk_height =
|
34
|
-
@extremity_length =
|
31
|
+
@head_width = figure_width*0.2
|
32
|
+
@head_height = figure_height*0.2
|
33
|
+
@trunk_height = figure_height*0.4
|
34
|
+
@extremity_length = figure_height*0.4
|
35
35
|
end
|
36
36
|
|
37
37
|
body {
|
38
|
-
shape(
|
38
|
+
shape(figure_x + @head_width/2.0 + @extremity_length, figure_y) {
|
39
39
|
oval(0, 0, @head_width, @head_height)
|
40
40
|
line(@head_width/2.0, @head_height, @head_width/2.0, @head_height + @trunk_height)
|
41
41
|
line(@head_width/2.0, @head_height + @trunk_height, @head_width/2.0 + @extremity_length, @head_height + @trunk_height + @extremity_length)
|
@@ -47,7 +47,7 @@ class StickFigure
|
|
47
47
|
end
|
48
48
|
|
49
49
|
class HelloCustomShape
|
50
|
-
include Glimmer::UI::
|
50
|
+
include Glimmer::UI::Application
|
51
51
|
|
52
52
|
WIDTH = 220
|
53
53
|
HEIGHT = 235
|
@@ -60,12 +60,12 @@ class HelloCustomShape
|
|
60
60
|
@canvas = canvas {
|
61
61
|
background :white
|
62
62
|
|
63
|
-
15.times
|
63
|
+
15.times do |n|
|
64
64
|
x_location = (rand*WIDTH/2).to_i%WIDTH + (rand*15).to_i
|
65
65
|
y_location = (rand*HEIGHT/2).to_i%HEIGHT + (rand*15).to_i
|
66
66
|
foreground_color = rgb(rand*255, rand*255, rand*255)
|
67
67
|
|
68
|
-
a_stick_figure = stick_figure(
|
68
|
+
a_stick_figure = stick_figure(figure_x: x_location, figure_y: y_location, figure_width: 35+n*2, figure_height: 35+n*2) {
|
69
69
|
foreground foreground_color
|
70
70
|
drag_and_move true
|
71
71
|
|
@@ -74,7 +74,7 @@ class HelloCustomShape
|
|
74
74
|
a_stick_figure.foreground = rgb(rand*255, rand*255, rand*255)
|
75
75
|
end
|
76
76
|
}
|
77
|
-
|
77
|
+
end
|
78
78
|
}
|
79
79
|
}
|
80
80
|
}
|
@@ -89,6 +89,7 @@ class HelloTable
|
|
89
89
|
def playoff_type=(new_playoff_type)
|
90
90
|
@playoff_type = new_playoff_type
|
91
91
|
self.schedule=(all_playoff_games[@playoff_type])
|
92
|
+
self.selected_game = schedule.first unless selected_game.nil?
|
92
93
|
end
|
93
94
|
|
94
95
|
def playoff_type_options
|
@@ -118,15 +119,24 @@ class HelloTable
|
|
118
119
|
'St Louis Cardinals' => 'Busch Stadium',
|
119
120
|
}
|
120
121
|
|
121
|
-
|
122
|
+
ATTRIBUTES = [:game_date, :game_time, :home_team, :away_team, :ballpark, :promotion]
|
123
|
+
ATTRIBUTES_BACKGROUND = ATTRIBUTES.map {|attribute| "#{attribute}_background"}
|
124
|
+
ATTRIBUTES_FOREGROUND = ATTRIBUTES.map {|attribute| "#{attribute}_foreground"}
|
125
|
+
ATTRIBUTES_FONT = ATTRIBUTES.map {|attribute| "#{attribute}_font"}
|
126
|
+
ATTRIBUTES_IMAGE = ATTRIBUTES.map {|attribute| "#{attribute}_image"}
|
122
127
|
|
128
|
+
attr_accessor *([:booked, :date_time] + ATTRIBUTES + ATTRIBUTES_BACKGROUND + ATTRIBUTES_FOREGROUND + ATTRIBUTES_FONT + ATTRIBUTES_IMAGE)
|
129
|
+
alias booked? booked
|
130
|
+
|
123
131
|
def initialize(date_time, home_team, away_team, promotion = 'N/A')
|
124
132
|
self.date_time = date_time
|
125
133
|
self.home_team = home_team
|
126
134
|
self.away_team = away_team
|
127
135
|
self.promotion = promotion
|
136
|
+
self.ballpark_image = [File.expand_path('hello_table/baseball_park.png', __dir__), width: 20, height: 20]
|
137
|
+
self.booked = false
|
138
|
+
|
128
139
|
observe(self, :date_time) do |new_value|
|
129
|
-
notify_observers(:game_date)
|
130
140
|
notify_observers(:game_time)
|
131
141
|
end
|
132
142
|
end
|
@@ -177,8 +187,42 @@ class HelloTable
|
|
177
187
|
end
|
178
188
|
|
179
189
|
def book!
|
190
|
+
self.booked = true
|
191
|
+
self.background = :dark_green
|
192
|
+
self.foreground = :white
|
193
|
+
self.font = {style: :italic}
|
180
194
|
"Thank you for booking #{to_s}"
|
181
195
|
end
|
196
|
+
|
197
|
+
# Sets background for all attributes
|
198
|
+
def background=(color)
|
199
|
+
self.game_date_background = color
|
200
|
+
self.game_time_background = color
|
201
|
+
self.home_team_background = color
|
202
|
+
self.away_team_background = color
|
203
|
+
self.ballpark_background = color
|
204
|
+
self.promotion_background = color
|
205
|
+
end
|
206
|
+
|
207
|
+
# Sets foreground for all attributes
|
208
|
+
def foreground=(color)
|
209
|
+
self.game_date_foreground = color
|
210
|
+
self.game_time_foreground = color
|
211
|
+
self.home_team_foreground = color
|
212
|
+
self.away_team_foreground = color
|
213
|
+
self.ballpark_foreground = color
|
214
|
+
self.promotion_foreground = color
|
215
|
+
end
|
216
|
+
|
217
|
+
# Sets font for all attributes
|
218
|
+
def font=(font_properties)
|
219
|
+
self.game_date_font = font_properties
|
220
|
+
self.game_time_font = font_properties
|
221
|
+
self.home_team_font = font_properties
|
222
|
+
self.away_team_font = font_properties
|
223
|
+
self.ballpark_font = font_properties
|
224
|
+
self.promotion_font = font_properties
|
225
|
+
end
|
182
226
|
end
|
183
227
|
|
184
228
|
include Glimmer::UI::CustomShell
|
@@ -246,8 +290,27 @@ class HelloTable
|
|
246
290
|
# default text editor is used here
|
247
291
|
}
|
248
292
|
|
249
|
-
#
|
250
|
-
|
293
|
+
# This is a contextual pop up menu that shows up when right-clicking table rows
|
294
|
+
menu {
|
295
|
+
menu_item {
|
296
|
+
text 'Book'
|
297
|
+
|
298
|
+
on_widget_selected do
|
299
|
+
book_selected_game
|
300
|
+
end
|
301
|
+
}
|
302
|
+
}
|
303
|
+
|
304
|
+
# Data-bind table items (rows) to a model collection (BaseballGame.schedule),
|
305
|
+
# mapping columns in declaration order to row model properties (attributes)
|
306
|
+
# By convention, every column property can be accompanied by extra properties
|
307
|
+
# with the following suffixes: `_background`, `_foreground`, `_font`, and `_image`
|
308
|
+
# For example, for `game_date`, model could also implement these related properties:
|
309
|
+
# `game_date_background`, `game_date_foreground`, `game_date_font`, `game_date_image`
|
310
|
+
# That is done in order to let the table widget set extra properties if needed.
|
311
|
+
items <=> [BaseballGame, :schedule,
|
312
|
+
column_properties: [:game_date, :game_time, :ballpark, :home_team, :away_team, :promotion]
|
313
|
+
]
|
251
314
|
|
252
315
|
# Data-bind table selection
|
253
316
|
selection <=> [BaseballGame, :selected_game]
|
@@ -258,22 +321,16 @@ class HelloTable
|
|
258
321
|
# Sort by these additional properties after handling sort by the column the user clicked
|
259
322
|
additional_sort_properties :date, :time, :home_team, :away_team, :ballpark, :promotion
|
260
323
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
on_widget_selected do
|
266
|
-
book_selected_game
|
267
|
-
end
|
268
|
-
}
|
269
|
-
}
|
324
|
+
on_key_pressed do |key_event|
|
325
|
+
book_selected_game if key_event.keyCode == swt(:cr)
|
326
|
+
end
|
270
327
|
}
|
271
328
|
|
272
329
|
button {
|
273
330
|
text 'Book Selected Game'
|
274
331
|
layout_data :center, :center, true, false
|
275
332
|
font height: 14
|
276
|
-
enabled <= [BaseballGame, :
|
333
|
+
enabled <= [BaseballGame, 'selected_game.booked', on_read: ->(value) { value == false }]
|
277
334
|
|
278
335
|
on_widget_selected do
|
279
336
|
book_selected_game
|
@@ -283,6 +340,8 @@ class HelloTable
|
|
283
340
|
}
|
284
341
|
|
285
342
|
def book_selected_game
|
343
|
+
return if BaseballGame.selected_game.booked?
|
344
|
+
|
286
345
|
message_box {
|
287
346
|
text 'Baseball Game Booked!'
|
288
347
|
message BaseballGame.selected_game.book!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-swt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.24.
|
4
|
+
version: 4.24.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|