glimmer-dsl-swt 0.5.4 → 0.5.5

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: 87bcff5d2b652ab8238bfa4860c5c7710e56155712aafc80dd3f8a4acd6a080c
4
- data.tar.gz: 7b4dd240b1af86fa39233dec7b9e1e514245ec35513a1589510d0ab21ffbdf9b
3
+ metadata.gz: '0281642708bc9fc3c57d913c1b1a33e4f9699e6999d290467bbaf02b706319cb'
4
+ data.tar.gz: 9499e48b14742b2034321631edc06be69212fc0c762a13727ad70cf880d86b6f
5
5
  SHA512:
6
- metadata.gz: 302644cbe7cbfc6c416585ab4c8d6cc38447ea0a3cb98eaf34473d8b0760f03d67eb9f59616ccf6d4e77b7cfc6112432dcdf6d16a5ccb310d90002ab2e39496d
7
- data.tar.gz: efac7d222037f8e3434750c514b6afedcef6faefc60911291261387a4f0639ba73fb7d5f152abebfbc0ba6097701c124b83ca0975a0244add554cb58ab720a80
6
+ metadata.gz: 7ad2211fa73e076d2993e3e487547cf486c96f500406666f6e9c3a16351c87f118337478b29fea0bd469d937ae7225520fc2efb55259db94766a97313990f9cc
7
+ data.tar.gz: 66312d638303de3ed1e6c100e4d4bec21c7b6e52203cfc2ef9368b2df7bb0662d08859f96be50fa4928dad10c88b112e71510c75de71f48ee818c7818c0dbbbd
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 0.5.4 (Desktop GUI)
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 0.5.5 (Desktop GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -21,7 +21,7 @@ module Glimmer
21
21
  system('warble config')
22
22
  new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
23
23
  if line.include?('config.dirs =')
24
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos vendor)')
24
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app bin config db docs fonts icons images lib package script sounds vendor videos)')
25
25
  end
26
26
  if line.include?('config.includes =')
27
27
  line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
@@ -5,7 +5,7 @@ module Glimmer
5
5
  module SWT
6
6
  # Proxy for org.eclipse.swt.graphics.Color
7
7
  #
8
- # Invoking `#swt_color` returns the SWT color object wrapped by this proxy
8
+ # Invoking `#swt_color` returns the SWT Color object wrapped by this proxy
9
9
  #
10
10
  # Follows the Proxy Design Pattern
11
11
  class ColorProxy
@@ -0,0 +1,63 @@
1
+ module Glimmer
2
+ module SWT
3
+ # Proxy for org.eclipse.swt.graphics.Image
4
+ #
5
+ # Invoking `#swt_image` returns the SWT Image object wrapped by this proxy
6
+ #
7
+ # Follows the Proxy Design Pattern
8
+ class ImageProxy
9
+ include_package 'org.eclipse.swt.graphics'
10
+
11
+ attr_reader :jar_file_path, :image_data
12
+
13
+ # Initializes a proxy for an SWT Image object
14
+ #
15
+ # Takes the same args as the SWT Image class
16
+ # Alternatively, takes a file path string or a uri:classloader file path string (generated by JRuby when invoking `File.expand_path` inside a JAR file)
17
+ # and returns an image object.
18
+ def initialize(*args)
19
+ @args = args
20
+ @jar_file_path = @args.first if @args.first.is_a?(String) && @args.size == 1
21
+
22
+ end
23
+
24
+ def swt_image
25
+ unless @swt_image
26
+ if @jar_file_path
27
+ file_path = @jar_file_path
28
+ if file_path.start_with?('uri:classloader')
29
+ file_path = file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac
30
+ object = java.lang.Object.new
31
+ file_input_stream = object.java_class.resource_as_stream(file_path)
32
+ buffered_file_input_stream = java.io.BufferedInputStream.new(file_input_stream)
33
+ end
34
+ @image_data = ImageData.new(buffered_file_input_stream || file_path)
35
+ @swt_image = Image.new(DisplayProxy.instance.swt_display, @image_data)
36
+ else
37
+ @swt_image = Image.new(*@args)
38
+ end
39
+ end
40
+ @swt_image
41
+ end
42
+
43
+ def scale_to(width, height)
44
+ return @swt_image if image_data.nil?
45
+ scaled_image_data = image_data.scaledTo(width, height)
46
+ device = swt_image.device
47
+ swt_image.dispose
48
+ @swt_image = Image.new(device, scaled_image_data)
49
+ end
50
+
51
+ def method_missing(method, *args, &block)
52
+ swt_image.send(method, *args, &block)
53
+ rescue => e
54
+ Glimmer::Config.logger.debug {"Neither ImageProxy nor #{swt_image.class.name} can handle the method ##{method}"}
55
+ super
56
+ end
57
+
58
+ def respond_to?(method, *args, &block)
59
+ super || swt_image.respond_to?(method, *args, &block)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -130,7 +130,7 @@ module Glimmer
130
130
  begin
131
131
  @display.sleep unless @display.readAndDispatch
132
132
  rescue => e
133
- Glimmer::Config.logger.debug {e.full_message}
133
+ Glimmer::Config.logger.info {e.full_message}
134
134
  end
135
135
  end
136
136
  end
@@ -3,6 +3,7 @@ require 'glimmer/swt/color_proxy'
3
3
  require 'glimmer/swt/font_proxy'
4
4
  require 'glimmer/swt/swt_proxy'
5
5
  require 'glimmer/swt/dnd_proxy'
6
+ require 'glimmer/swt/image_proxy'
6
7
 
7
8
  # TODO refactor to make file smaller and extract sub-widget-proxies out of this
8
9
 
@@ -590,21 +591,18 @@ module Glimmer
590
591
  @property_type_converters ||= {
591
592
  :background => color_converter,
592
593
  :background_image => lambda do |value|
594
+ image_proxy = nil
593
595
  if value.is_a?(String)
594
- if value.start_with?('uri:classloader')
595
- value = value.sub(/^uri\:classloader\:/, '')
596
- object = java.lang.Object.new
597
- value = object.java_class.resource_as_stream(value)
598
- value = java.io.BufferedInputStream.new(value)
599
- end
600
- image_data = ImageData.new(value)
601
- # TODO in the future, look into unregistering this listener when no longer needed
596
+ image_proxy = ImageProxy.new(value)
597
+ elsif value.is_a?(Array)
598
+ image_proxy = ImageProxy.new(*value)
599
+ end
600
+ if image_proxy
602
601
  on_swt_Resize do |resize_event|
603
- new_image_data = image_data.scaledTo(@swt_widget.getSize.x, @swt_widget.getSize.y)
604
- @swt_widget.getBackgroundImage&.dispose
605
- @swt_widget.setBackgroundImage(Image.new(@swt_widget.getDisplay, new_image_data))
602
+ image_proxy.scale_to(@swt_widget.getSize.x, @swt_widget.getSize.y)
603
+ @swt_widget.setBackgroundImage(image_proxy.swt_image)
606
604
  end
607
- Image.new(@swt_widget.getDisplay, image_data)
605
+ image_proxy.swt_image
608
606
  else
609
607
  value
610
608
  end
@@ -620,14 +618,9 @@ module Glimmer
620
618
  end,
621
619
  :image => lambda do |value|
622
620
  if value.is_a?(String)
623
- if value.start_with?('uri:classloader')
624
- value = value.sub(/^uri\:classloader\:/, '')
625
- object = java.lang.Object.new
626
- value = object.java_class.resource_as_stream(value)
627
- value = java.io.BufferedInputStream.new(value)
628
- end
629
- image_data = ImageData.new(value)
630
- Image.new(@swt_widget.getDisplay, image_data)
621
+ ImageProxy.new(value).swt_image
622
+ elsif value.is_a?(Array)
623
+ ImageProxy.new(*value).swt_image
631
624
  else
632
625
  value
633
626
  end
@@ -635,14 +628,9 @@ module Glimmer
635
628
  :images => lambda do |array|
636
629
  array.to_a.map do |value|
637
630
  if value.is_a?(String)
638
- if value.start_with?('uri:classloader')
639
- value = value.sub(/^uri\:classloader\:/, '')
640
- object = java.lang.Object.new
641
- value = object.java_class.resource_as_stream(value)
642
- value = java.io.BufferedInputStream.new(value)
643
- end
644
- image_data = ImageData.new(value)
645
- Image.new(@swt_widget.getDisplay, image_data)
631
+ ImageProxy.new(value).swt_image
632
+ elsif value.is_a?(Array)
633
+ ImageProxy.new(*value).swt_image
646
634
  else
647
635
  value
648
636
  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: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -344,6 +344,7 @@ files:
344
344
  - lib/glimmer/swt/display_proxy.rb
345
345
  - lib/glimmer/swt/dnd_proxy.rb
346
346
  - lib/glimmer/swt/font_proxy.rb
347
+ - lib/glimmer/swt/image_proxy.rb
347
348
  - lib/glimmer/swt/layout_data_proxy.rb
348
349
  - lib/glimmer/swt/layout_proxy.rb
349
350
  - lib/glimmer/swt/menu_proxy.rb