glimmer 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b229c575994db66837bce7ab4d21eea4dc48c01f6875269942cc6c1d325cf04
4
- data.tar.gz: 87759b07eda23d64c7321f55dc3ab4a339b15e0cd59fb3b93eaee079c730caad
3
+ metadata.gz: 4a13439b3524a4100c7ca2a6eb8b191a9706e3f4591423fa28a30fbda690e21d
4
+ data.tar.gz: 13c287b39adc40c4eaefde63ab196a5771b442032a8c3ccd697cb84384ecbe77
5
5
  SHA512:
6
- metadata.gz: a968e1d522df3c64bdf9366c5a551fe17f160004a1270697b9583fae58e5c86204773d97f95db92a88f1820b1c3cc3bec1a985c5f1e6a35e48c9b325ac62ca51
7
- data.tar.gz: 5f70f66d16b9c1b6daef6b737d9612f96bd722622d25c95c3ba022f620905c7ade6edb7a040ab4ea35bbcf9023e8f6ba7dda519c4c0439d6d311f4c9305bafc9
6
+ metadata.gz: 561b9b04686935229929e33dfd3af7461fadd52e2d4902be8556e42c27df3bbbb1a37323bfa74d4978d34906f7154480ccae73aad6f6c01da33f49280d6f0807
7
+ data.tar.gz: '08e8364b81fdd8189ed9469d6d06b0b41e2f2629329355824e96be6b7ed4ea276d31783297ca1f537c6059ce0db78d971407eb34df06351290dce5c633f5917b'
data/README.markdown CHANGED
@@ -102,14 +102,14 @@ Please follow these instructions to make the `glimmer` command available on your
102
102
 
103
103
  Run this command to install directly:
104
104
  ```
105
- jgem install glimmer -v 0.3.3
105
+ jgem install glimmer -v 0.3.4
106
106
  ```
107
107
 
108
108
  ### Option 2: Bundler
109
109
 
110
110
  Add the following to `Gemfile`:
111
111
  ```
112
- gem 'glimmer', '~> 0.3.3'
112
+ gem 'glimmer', '~> 0.3.4'
113
113
  ```
114
114
 
115
115
  And, then run:
@@ -338,6 +338,23 @@ Here is a list of SWT style bits:
338
338
 
339
339
  https://wiki.eclipse.org/SWT_Widget_Style_Bits
340
340
 
341
+ ## SWT Packages
342
+
343
+ Glimmer automatically imports all SWT Java packages upon adding `include Glimmer` to a class or module.
344
+
345
+ Still, if you'd like to import manually elsewhere, you may add the following lines to your code:
346
+
347
+ ```ruby
348
+ include_package 'org.eclipse.swt'
349
+ include_package 'org.eclipse.swt.widgets'
350
+ include_package 'org.eclipse.swt.layout'
351
+ include_package 'org.eclipse.swt.graphics'
352
+ ```
353
+
354
+ This allows you to call Java SWT classes from Ruby without indicating the package explicitly.
355
+
356
+ For example, `org.eclipse.swt.graphics.Color` becomes `Color`
357
+
341
358
  ## Girb (Glimmer irb)
342
359
 
343
360
  With Glimmer installed, you may run want to run `girb` instead of standard `irb` to have SWT preloaded and the Glimmer library required and included for quick Glimmer coding/testing.
@@ -4,13 +4,21 @@ require_relative 'models/r_color'
4
4
  class ColorCommandHandler
5
5
  include CommandHandler
6
6
 
7
+ include_package 'org.eclipse.swt.widgets'
8
+
7
9
  def can_handle?(parent, command_symbol, *args, &block)
8
- parent.is_a?(RWidget) and
9
10
  ['rgba', 'rgb'].include?(command_symbol.to_s) and
10
- (3..4).include?(args.count)
11
+ (3..5).include?(args.count)
11
12
  end
12
13
 
13
14
  def do_handle(parent, command_symbol, *args, &block)
14
- RColor.new(parent.widget.display, *args).color
15
+ if args.first.is_a?(Display)
16
+ display = args.delete_at(0)
17
+ elsif parent.is_a?(RWidget)
18
+ display = parent.widget.display
19
+ else
20
+ display = nil
21
+ end
22
+ RColor.new(display, *args)
15
23
  end
16
24
  end
@@ -1,18 +1,31 @@
1
1
  class RColor
2
- attr_reader :display
3
- attr_reader :color
2
+ attr_reader :display, :red, :green, :blue, :alpha
4
3
 
5
4
  include_package 'org.eclipse.swt.graphics'
6
5
 
7
6
  class << self
7
+ include_package 'org.eclipse.swt'
8
+
8
9
  def for(display, standard_color)
9
- standard_color_swt_constant = org.eclipse.swt.SWT.const_get(standard_color.to_s.upcase.to_sym)
10
+ standard_color_swt_constant = SWT.const_get(standard_color.to_s.upcase.to_sym)
10
11
  display.getSystemColor(standard_color_swt_constant)
11
12
  end
12
13
  end
13
14
 
14
15
  def initialize(display, red, green, blue, alpha = nil)
15
16
  @display = display
16
- @color = Color.new(@display, *[red, green, blue, alpha].compact)
17
+ @red = red
18
+ @green = green
19
+ @blue = blue
20
+ @alpha = alpha
21
+ end
22
+
23
+ def color
24
+ @color ||= Color.new(@display, *[@red, @green, @blue, @alpha].compact)
25
+ end
26
+
27
+ def display=(a_display)
28
+ @display = a_display
29
+ @color = nil
17
30
  end
18
31
  end
@@ -30,6 +30,12 @@ class RWidget
30
30
  "group" => Proc.new {|group| group.setLayout(GridLayout.new) },
31
31
  }
32
32
 
33
+ @@property_type_converters = {
34
+ :text => Proc.new { |value| value.to_s },
35
+ :items => Proc.new { |value| value.to_java :string},
36
+ :visible => Proc.new { |value| !!value},
37
+ }
38
+
33
39
  #styles is a comma separate list of symbols representing SWT styles in lower case
34
40
  def initialize(underscored_widget_name, parent, styles, &contents)
35
41
  @widget = underscored_widget_name.swt_widget.new(parent, style(underscored_widget_name, styles))
@@ -41,11 +47,24 @@ class RWidget
41
47
  end
42
48
 
43
49
  def set_attribute(attribute_name, *args)
50
+ apply_property_type_converters(attribute_name, args)
51
+ @widget.send(attribute_setter(attribute_name), *args)
52
+ end
53
+
54
+ def apply_property_type_converters(attribute_name, args)
55
+ if args.count == 1
56
+ value = args.first
57
+ converter = @@property_type_converters[attribute_name.to_sym]
58
+ args[0] = converter.call(value) if converter
59
+ end
44
60
  if args.count == 1 && args.first.is_a?(Symbol) && args.first.to_s.start_with?('color_')
45
61
  standard_color = args.first
46
62
  args[0] = RColor.for(widget.getDisplay, standard_color)
63
+ elsif args.count == 1 && args.first.is_a?(RColor)
64
+ r_color = args.first
65
+ r_color.display = widget.display if r_color.display.nil? || r_color.display != widget.display
66
+ args[0] = r_color.color
47
67
  end
48
- @widget.send(attribute_setter(attribute_name), *args)
49
68
  end
50
69
 
51
70
  def self.widget_exists?(underscored_widget_name)
@@ -7,11 +7,6 @@ class WidgetBinding
7
7
  include Observer
8
8
 
9
9
  attr_reader :widget, :property
10
- @@property_type_converters = {
11
- :text => Proc.new { |value| value.to_s },
12
- :items => Proc.new { |value| value.to_java :string},
13
- :visible => Proc.new { |value| !!value},
14
- }
15
10
  def initialize(model, property, translator = nil)
16
11
  @widget = model
17
12
  @property = property
@@ -24,9 +19,7 @@ class WidgetBinding
24
19
  end
25
20
  def update(value)
26
21
  converted_value = translated_value = @translator.call(value)
27
- converter = @@property_type_converters[@property.to_sym]
28
- converted_value = converter.call(translated_value) if converter
29
- @widget.widget.send("set#{@property.camelcase(:upper)}", converted_value) unless evaluate_property == converted_value
22
+ @widget.set_attribute(@property, converted_value) unless evaluate_property == converted_value
30
23
  end
31
24
  def evaluate_property
32
25
  @widget.widget.send(@property)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh