glimmer-dsl-swt 4.20.13.12 → 4.20.13.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bec3c88dee81e6625c208ce0fe97f02984b27faa107bb5b1c0667612ada04cae
4
- data.tar.gz: 4221c07f12ba4d2de558223a60546218a530c02cdb34e0d6c1a03b19b7a4ba6c
3
+ metadata.gz: 73c5a7ba90a7c91df55ac716b815e08e71b9ff13294ebf44e4c6587aa67080f2
4
+ data.tar.gz: 889670d6eba956aaf4cc267c8a70cf36283379369a51bed85b5b5dd2aadd2762
5
5
  SHA512:
6
- metadata.gz: 1c555e4e44ae1ca8933a35d2316bc8711d4888483b0f6ff3a90d372e7f25f3b66b9ac114239f5970e8f72f69ad2aa1358dc0833d96a8689c5d14b0fa6aba79ef
7
- data.tar.gz: 363b079ba036a24e47a6919bc72d1dbaa4396586ae814ccb77cde3917b6ca917c5e5fe295dc17ff9339cfa9dfb526ee60e936af4e4d66f081901727017712f4e
6
+ metadata.gz: 455e0b8626d4782e9ec122de48eae8ffec9688b2a724de11c858c4833925389ca3e2a46285e47e30b50e0fe414ccbe74f5dd869bbcbe03986e682dd5a1aad991
7
+ data.tar.gz: 4ae13e2fedaa551c03ff3b8919bfe9ffa4faf31b7b6b393ba37b91e1fb54c179703da2c3d5283446122a7867eb970373ed191289ad2ace0e92880058b633f573
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ### 4.20.13.13
4
+
5
+ - Parking elaborate sample
6
+ - Support shape contain?/include? when a transform (e.g. rotation) is applied
7
+
3
8
  ### 4.20.13.12
4
9
 
5
10
  - Fixed issue with dragged shapes having `drag_source true` not going back to original position when not dropped in a target if they were part of a composite shape
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.13.12
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.13.13
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.13.12 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.13.13 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 a beta, so default back to `bind` whenever needed).
21
21
 
@@ -326,7 +326,7 @@ jgem install glimmer-dsl-swt
326
326
 
327
327
  Or this command if you want a specific version:
328
328
  ```
329
- jgem install glimmer-dsl-swt -v 4.20.13.12
329
+ jgem install glimmer-dsl-swt -v 4.20.13.13
330
330
  ```
331
331
 
332
332
  `jgem` is JRuby's version of `gem` command.
@@ -354,7 +354,7 @@ Note: if you're using activerecord or activesupport, keep in mind that Glimmer u
354
354
 
355
355
  Add the following to `Gemfile`:
356
356
  ```
357
- gem 'glimmer-dsl-swt', '~> 4.20.13.12'
357
+ gem 'glimmer-dsl-swt', '~> 4.20.13.13'
358
358
  ```
359
359
 
360
360
  And, then run:
@@ -375,7 +375,7 @@ glimmer
375
375
  ```
376
376
 
377
377
  ```
378
- Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.12
378
+ Glimmer (JRuby Desktop Development GUI Framework) - JRuby Gem: glimmer-dsl-swt v4.20.13.13
379
379
 
380
380
  Usage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
381
381
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.20.13.12
1
+ 4.20.13.13
@@ -65,6 +65,7 @@
65
65
  - [Glimmer Tetris](#glimmer-tetris)
66
66
  - [Klondike Solitaire](#klondike-solitaire)
67
67
  - [Mandelbrot Fractal](#mandelbrot-fractal)
68
+ - [Parking](#parking)
68
69
  - [Stock Ticker](#stock-ticker)
69
70
  - [Metronome](#metronome)
70
71
  - [Weather](#weather)
@@ -1148,6 +1149,28 @@ Code:
1148
1149
 
1149
1150
  ![Mandelbrot Fractal Help Menu](/images/glimmer-mandelbrot-menu-help.png)
1150
1151
 
1152
+ #### Parking
1153
+
1154
+ This sample demonstrates how to use method-based custom shapes and how to take advantage of transforms (e.g. rotation).
1155
+
1156
+ It enables booking a parking spot at the entrance of a building's parking, which in a real scenario would have prompted for payment too.
1157
+
1158
+ Code:
1159
+
1160
+ [samples/elaborate/parking.rb](/samples/elaborate/parking.rb)
1161
+
1162
+ Parking
1163
+
1164
+ ![Parking](/images/glimmer-parking.png)
1165
+
1166
+ Parking Floor 4
1167
+
1168
+ ![Parking Floor 4](/images/glimmer-parking-floor4.png)
1169
+
1170
+ Parking Booked
1171
+
1172
+ ![Parking Booked](/images/glimmer-parking-booked.png)
1173
+
1151
1174
  #### Stock Ticker
1152
1175
 
1153
1176
  This sample demonstrates a Stock Ticker that generates random stock price data for 4 different stocks and provides 4 different tab views of the graphed data using the [Canvas Path DSL](/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#canvas-path-dsl). It leverages a thread that runs in the background and ticks the stocks to generate random new stock prices before amending the graphed paths with them.
Binary file
@@ -38,6 +38,7 @@ require 'super_module'
38
38
  require 'date'
39
39
  require 'facets/string/capitalized'
40
40
  require 'facets/hash/symbolize_keys'
41
+ require 'matrix'
41
42
 
42
43
  # Internal requires
43
44
  require 'ext/glimmer/config'
@@ -62,6 +62,7 @@ module Glimmer
62
62
  # Optimize further by having a collection of disposable_shapes independent of shapes, which is much smaller and only has shapes that require disposal (shapes with patterns or image)
63
63
  shapes.dup.each {|s| s.dispose(dispose_images: dispose_images, dispose_patterns: dispose_patterns) } if requires_shape_disposal?
64
64
  end
65
+ alias dispose_shapes clear_shapes
65
66
 
66
67
  def paint_pixel_by_pixel(width = nil, height = nil, &each_pixel_color)
67
68
  if @image_double_buffered
@@ -216,6 +216,7 @@ module Glimmer
216
216
  # Subclasses (like polygon) may override to indicate if a point x,y coordinates falls inside the shape
217
217
  # some shapes may choose to provide a fuzz factor to make usage of this method for mouse clicking more user friendly
218
218
  def contain?(x, y)
219
+ x, y = inverse_transform_point(x, y)
219
220
  # assume a rectangular filled shape by default (works for several shapes like image, text, and focus)
220
221
  x.between?(self.absolute_x, self.absolute_x + calculated_width.to_f) && y.between?(self.absolute_y, self.absolute_y + calculated_height.to_f)
221
222
  end
@@ -232,6 +233,24 @@ module Glimmer
232
233
  included = include?(x, y)
233
234
  included ||= expanded_shapes.reject {|shape| shape == except_child}.detect { |shape| shape.include?(x, y) }
234
235
  end
236
+
237
+ # if there is a transform, invert it and apply on x, y point coordinates
238
+ def inverse_transform_point(x, y)
239
+ current_transform = (transform || parent_shape_containers.map(&:transform).first)&.first
240
+ if current_transform
241
+ transform_array = [1,2,3,4,5,6].to_java(:float)
242
+ current_transform.getElements(transform_array)
243
+ inverse_transform = TransformProxy.new(DisplayProxy.instance.swt_display, *transform_array.to_a)
244
+ inverse_transform_array = [1,2,3,4,5,6].to_java(:float)
245
+ inverse_transform.getElements(inverse_transform_array)
246
+ matrix = Matrix[[inverse_transform_array[0], inverse_transform_array[1]], [inverse_transform_array[2], inverse_transform_array[3]]]
247
+ result = matrix * Matrix.column_vector([x, y])
248
+ x, y = result.to_a.flatten
249
+ x += inverse_transform_array[5]
250
+ y += inverse_transform_array[4]
251
+ end
252
+ [x, y]
253
+ end
235
254
 
236
255
  # Indicates if a shape's x, y, width, height differ from its bounds calculation (e.g. arc / polygon)
237
256
  def irregular?
@@ -53,6 +53,7 @@ module Glimmer
53
53
 
54
54
  # checks if shape contains the point denoted by x and y
55
55
  def contain?(x, y)
56
+ x, y = inverse_transform_point(x, y)
56
57
  geometry.contains(x, y)
57
58
  end
58
59
 
@@ -60,6 +61,7 @@ module Glimmer
60
61
  if filled?
61
62
  contain?(x, y)
62
63
  else
64
+ x, y = inverse_transform_point(x, y)
63
65
  # give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
64
66
  outer_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width + 3, calculated_height + 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
65
67
  inner_shape_geometry = java.awt.geom.Arc2D::Double.new(self.absolute_x, self.absolute_y, calculated_width - 3, calculated_height - 3, start_angle, arc_angle, java.awt.geom.Arc2D::PIE)
@@ -55,6 +55,7 @@ module Glimmer
55
55
 
56
56
  # checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
57
57
  def include?(x, y, filled: nil)
58
+ x, y = inverse_transform_point(x, y)
58
59
  filled = filled? if filled.nil?
59
60
  makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
60
61
  swt_path = org.eclipse.swt.graphics.Path.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
@@ -123,6 +123,7 @@ module Glimmer
123
123
  end
124
124
 
125
125
  def include?(x, y)
126
+ x, y = inverse_transform_point(x, y)
126
127
  # TODO must account for line width
127
128
  Line.include?(absolute_x1, absolute_y1, absolute_x2, absolute_y2, x, y)
128
129
  end
@@ -39,6 +39,7 @@ module Glimmer
39
39
 
40
40
  # checks if shape contains the point denoted by x and y
41
41
  def contain?(x, y)
42
+ x, y = inverse_transform_point(x, y)
42
43
  shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x, self.absolute_y, calculated_width, calculated_height)
43
44
  shape_geometry.contains(x, y)
44
45
  end
@@ -48,6 +49,7 @@ module Glimmer
48
49
  if filled?
49
50
  contain?(x, y)
50
51
  else
52
+ x, y = inverse_transform_point(x, y)
51
53
  # give it some fuzz to allow a larger region around the drawn oval to accept including a point (helps with mouse clickability on a shape)
52
54
  outer_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x - 3, self.absolute_y - 3, calculated_width + 6, calculated_height + 6)
53
55
  inner_shape_geometry = java.awt.geom.Ellipse2D::Double.new(self.absolute_x + 3, self.absolute_y + 3, calculated_width - 6, calculated_height - 6)
@@ -61,17 +61,13 @@ module Glimmer
61
61
  end
62
62
  end
63
63
 
64
- def contain?(x, y)
65
- makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
66
- @swt_path.contains(x.to_f, y.to_f, makeshift_gc, false)
67
- end
68
-
69
64
  def contain?(x, y)
70
65
  include?(x, y, filled: true)
71
66
  end
72
67
 
73
68
  # checks if drawn or filled rectangle includes the point denoted by x and y (if drawn, it only returns true if point lies on the edge)
74
69
  def include?(x, y, filled: nil)
70
+ x, y = inverse_transform_point(x, y)
75
71
  filled = filled? if filled.nil?
76
72
  makeshift_gc = org.eclipse.swt.graphics.GC.new(Glimmer::SWT::DisplayProxy.instance.swt_display)
77
73
  @swt_path.contains(x.to_f, y.to_f, makeshift_gc, !filled)
@@ -49,6 +49,7 @@ module Glimmer
49
49
  end
50
50
 
51
51
  def include?(x, y)
52
+ x, y = inverse_transform_point(x, y)
52
53
  # give it some fuzz (helps makes mouse clicking easier)
53
54
  x.to_i.between?(self.absolute_x.to_i - 2, self.absolute_x.to_i + 2) && y.to_i.between?(self.absolute_y.to_i - 2, self.absolute_y.to_i + 2)
54
55
  end
@@ -152,6 +152,7 @@ module Glimmer
152
152
  end
153
153
 
154
154
  def contain?(x, y)
155
+ x, y = inverse_transform_point(x, y)
155
156
  geometry.contains(x, y)
156
157
  end
157
158
 
@@ -159,6 +160,7 @@ module Glimmer
159
160
  if filled?
160
161
  contain?(x, y)
161
162
  else
163
+ x, y = inverse_transform_point(x, y)
162
164
  comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
163
165
  comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
164
166
  end
@@ -130,6 +130,7 @@ module Glimmer
130
130
  end
131
131
 
132
132
  def include?(x, y)
133
+ x, y = inverse_transform_point(x, y)
133
134
  comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
134
135
  comparison_lines.pop # ignore last pair since you don't want to compare last point with first point
135
136
  comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
@@ -85,6 +85,7 @@ module Glimmer
85
85
  if filled?
86
86
  contain?(x, y)
87
87
  else
88
+ x, y = inverse_transform_point(x, y)
88
89
  comparison_lines = absolute_point_xy_array.zip(absolute_point_xy_array.rotate(1))
89
90
  comparison_lines.any? {|line| Line.include?(line.first.first, line.first.last, line.last.first, line.last.last, x, y)}
90
91
  end
@@ -29,7 +29,7 @@ class KlondikeSolitaire
29
29
  end
30
30
 
31
31
  body {
32
- shell(:no_resize) {
32
+ shell {
33
33
  row_layout(:vertical) {
34
34
  fill true
35
35
  center true
@@ -0,0 +1,146 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require 'glimmer-dsl-swt'
23
+
24
+ require_relative 'parking/model/parking_presenter'
25
+
26
+ class Parking
27
+ include Glimmer::UI::CustomShell
28
+
29
+ FLOOR_COUNT = 4
30
+
31
+ before_body do
32
+ @parking_spots = Model::ParkingSpot::LETTERS.clone
33
+ @parking_presenter = Model::ParkingPresenter.new(FLOOR_COUNT)
34
+ end
35
+
36
+ body {
37
+ shell(:no_resize) {
38
+ row_layout(:vertical) {
39
+ center true
40
+ }
41
+
42
+ text 'Parking'
43
+
44
+ label {
45
+ text 'Select an available spot to park'
46
+ font height: 30
47
+ }
48
+ label {
49
+ text 'Floor:'
50
+ font height: 20
51
+ }
52
+ spinner {
53
+ minimum 1
54
+ maximum FLOOR_COUNT
55
+ font height: 20
56
+ selection <=> [@parking_presenter, :selected_floor]
57
+
58
+ on_widget_selected do
59
+ @parking_spots = Model::ParkingSpot::LETTERS.clone
60
+ @canvas.dispose_shapes
61
+ @canvas.content {
62
+ parking_floor
63
+ }
64
+ end
65
+ }
66
+ @canvas = canvas {
67
+ layout_data {
68
+ width 600
69
+ height 600
70
+ }
71
+
72
+ background :dark_gray
73
+
74
+ parking_floor
75
+ }
76
+ }
77
+ }
78
+
79
+ def parking_floor
80
+ parking_quad(67.5, 0, 125)
81
+ parking_quad(67.5, 0, 125) { |shp|
82
+ shp.rotate(90)
83
+ }
84
+ parking_quad(67.5, 0, 125) { |shp|
85
+ shp.rotate(180)
86
+ }
87
+ parking_quad(67.5, 0, 125) { |shp|
88
+ shp.rotate(270)
89
+ }
90
+ end
91
+
92
+ def parking_quad(location_x, location_y, length, &block)
93
+ distance = (1.0/3)*length
94
+ parking_spot(location_x, location_y, length, &block)
95
+ parking_spot(location_x + distance, location_y, length, &block)
96
+ parking_spot(location_x + 2*distance, location_y, length, &block)
97
+ parking_spot(location_x + 3*distance, location_y, length, &block)
98
+ end
99
+
100
+ def parking_spot(location_x, location_y, length, &block)
101
+ parking_spot_letter = @parking_spots.shift
102
+ height = length
103
+ width = (2.0/3)*length
104
+ shape(location_x, location_y) { |the_shape|
105
+ line_width (1.0/15)*length
106
+ foreground :white
107
+
108
+ block&.call(the_shape)
109
+
110
+ rectangle(location_x, location_y, width, height) {
111
+ background <= [
112
+ @parking_presenter.floors[@parking_presenter.selected_floor - 1].parking_spots[parking_spot_letter],
113
+ :booked,
114
+ on_read: ->(b) {b ? :red : :dark_gray}
115
+ ]
116
+
117
+ text {
118
+ x :default
119
+ y :default
120
+ string parking_spot_letter
121
+ font height: 20
122
+ }
123
+
124
+ on_mouse_up do
125
+ begin
126
+ @parking_presenter.floors[@parking_presenter.selected_floor - 1].book!(parking_spot_letter)
127
+ message_box {
128
+ text 'Parking Booked!'
129
+ message "Floor #{@parking_presenter.selected_floor} Parking Spot #{parking_spot_letter} Is Booked!"
130
+ }.open
131
+ rescue => e
132
+ # No Op if already booked
133
+ end
134
+ end
135
+ }
136
+
137
+ line(location_x, location_y, location_x, location_y + height)
138
+ line(location_x, location_y, location_x + width, location_y)
139
+ line(location_x + width, location_y, location_x + width, location_y + height)
140
+
141
+ }
142
+ end
143
+ end
144
+
145
+ Parking.launch
146
+
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative 'parking_spot'
23
+
24
+ class Parking
25
+ module Model
26
+ class ParkingFloor
27
+ attr_reader :number, :parking_spots
28
+
29
+ def initialize(floor_number)
30
+ @number = floor_number
31
+ @parking_spots = ParkingSpot::LETTERS.reduce({}) do |hash, letter|
32
+ hash.merge(letter => ParkingSpot.new(self, letter))
33
+ end
34
+ end
35
+
36
+ def book!(parking_spot_letter)
37
+ parking_spots[parking_spot_letter].book!
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,42 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ require_relative 'parking_floor'
23
+
24
+ class Parking
25
+ module Model
26
+ class ParkingPresenter
27
+ attr_reader :floor_count
28
+ attr_accessor :floors, :selected_floor
29
+
30
+ def initialize(floor_count)
31
+ self.floors = 1.upto(floor_count).map do |floor_number|
32
+ ParkingFloor.new(floor_number)
33
+ end
34
+ self.selected_floor = 1
35
+ end
36
+
37
+ def book(parking_spot_letter)
38
+ self.floors[selected_floor - 1].book(parking_spot_letter)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2007-2021 Andy Maleh
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining
4
+ # a copy of this software and associated documentation files (the
5
+ # "Software"), to deal in the Software without restriction, including
6
+ # without limitation the rights to use, copy, modify, merge, publish,
7
+ # distribute, sublicense, and/or sell copies of the Software, and to
8
+ # permit persons to whom the Software is furnished to do so, subject to
9
+ # the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be
12
+ # included in all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ class Parking
23
+ module Model
24
+ class ParkingSpot
25
+ LETTERS = %W[A B C D E F G H I J K L M N O P]
26
+
27
+ attr_reader :parking_floor, :letter
28
+ attr_accessor :booked
29
+ alias booked? booked
30
+
31
+ def initialize(parking_floor, letter)
32
+ @parking_floor = parking_floor
33
+ @letter = letter
34
+ end
35
+
36
+ def book!
37
+ raise "Floor #{parking_floor.number} Parking Spot #{letter} Is Already Booked!" if booked?
38
+ self.booked = true
39
+ end
40
+
41
+ def free!
42
+ self.booked = false
43
+ end
44
+ end
45
+ end
46
+ end
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.20.13.12
4
+ version: 4.20.13.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-01 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -568,6 +568,10 @@ files:
568
568
  - samples/elaborate/mandelbrot_fractal.rb
569
569
  - samples/elaborate/meta_sample.rb
570
570
  - samples/elaborate/metronome.rb
571
+ - samples/elaborate/parking.rb
572
+ - samples/elaborate/parking/model/parking_floor.rb
573
+ - samples/elaborate/parking/model/parking_presenter.rb
574
+ - samples/elaborate/parking/model/parking_spot.rb
571
575
  - samples/elaborate/stock_ticker.rb
572
576
  - samples/elaborate/tetris.rb
573
577
  - samples/elaborate/tetris/model/block.rb