glimmer-dsl-swt 0.5.2 → 0.6.0

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: 3d85c2647eb91ad5e3890357021cca11cfa1e3978490079e7de7d44ae8bacb63
4
- data.tar.gz: f5c74f67484cf9fd54c6be65c41b95f787632715d048b4186980d4b40abfe78f
3
+ metadata.gz: 0c023dda45b9c92e69ef9a44ef07fde1f45f5161284cf1b46b70d15a661b3ccc
4
+ data.tar.gz: 77be63700930812f4da66669003df863d77a1644495e2d37b776e97a5e5f145b
5
5
  SHA512:
6
- metadata.gz: 7357435f443a4bc764bfcc9d4a216272f3ff3f007e69488b0da74a6decc1b4f5252bbd31982134d7358e76b4c86547429a1952a2c1c2fb15a59127a22bdb1970
7
- data.tar.gz: 365b10848e8851b92373783666c701fff642742990218fc0652cd5d5f42ddaaad2e672062b25699500f275f83cac49bf4fb1301511b8f3b6b14cc26d8c87a921
6
+ metadata.gz: ce300717322a9a905a67c589bf1a9398adcd09abf33421283c5d3265ed68b8ce4dbdf25ac33a37812de355c00ba027d7fe33ce284a9c2eb2932817087130a281
7
+ data.tar.gz: 353b5a6f43cf7d070ae9a2f775ea2430a4eda54bf346210a8ca5e1ee899a35c44f639fbca3e2cd5338aa73c3f1c9b97209c84ea669c436f36f4ce31a0bf9b1b8
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.2 (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.6.0 (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)
@@ -1 +1 @@
1
- jruby-9.2.12.0
1
+ jruby-9.2.13.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.6.0
@@ -105,7 +105,6 @@ end
105
105
  Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
106
106
  method = method_symbol.to_s
107
107
  result = false
108
- result ||= method.start_with?('on_swt_') && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
109
108
  result ||= method == 'dispose' && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
110
109
  result ||= ['drag_source_proxy', 'drop_target_proxy'].include?(method) && is_a?(Glimmer::UI::CustomWidget)
111
110
  result ||= method == 'post_initialize_child'
@@ -0,0 +1,26 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/swt/cursor_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ # cursor expression
9
+ # Note: Cannot be a static expression because it clashes with cursor property expression
10
+ class CursorExpression < Expression
11
+ include TopLevelExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword.to_s == 'cursor' and
15
+ (parent.nil? or !parent.respond_to?('cursor')) and
16
+ args.size == 1 and
17
+ (args.first.is_a?(Integer) or textual?(args.first))
18
+ end
19
+
20
+ def interpret(parent, keyword, *args, &block)
21
+ Glimmer::SWT::CursorProxy.new(*args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -24,6 +24,8 @@ module Glimmer
24
24
  tree_items_data_binding
25
25
  table_items_data_binding
26
26
  data_binding
27
+ cursor
28
+ font
27
29
  property
28
30
  block_property
29
31
  widget
@@ -0,0 +1,24 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/swt/font_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ # font expression
9
+ # Note: Cannot be a static expression because it clashes with font property expression
10
+ class FontExpression < Expression
11
+ include TopLevelExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword.to_s == 'font' and
15
+ (parent.nil? || !parent.respond_to?('font')) && args.size == 1 && args.first.is_a?(Hash)
16
+ end
17
+
18
+ def interpret(parent, keyword, *args, &block)
19
+ Glimmer::SWT::FontProxy.new(*args)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -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,45 @@
1
+ require 'glimmer/error'
2
+ require 'glimmer/swt/swt_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
+
5
+ module Glimmer
6
+ module SWT
7
+ # Proxy for org.eclipse.swt.graphics.Cursor
8
+ #
9
+ # Invoking `#swt_cursor` returns the SWT Cursor object wrapped by this proxy
10
+ #
11
+ # Follows the Proxy Design Pattern
12
+ class CursorProxy
13
+ CURSOR_STYLES = org.eclipse.swt.SWT.constants.select {|c| c.to_s.downcase.start_with?('cursor_')}.map {|c| c.to_s.downcase.sub('cursor_', '').to_sym}
14
+ ERROR_INVALID_CURSOR_STYLE = " is an invalid cursor style! Valid values are #{CURSOR_STYLES.map(&:to_s).join(", ")}"
15
+
16
+ include_package 'org.eclipse.swt.graphics'
17
+
18
+ attr_reader :swt_cursor, :cursor_style
19
+
20
+ # Builds a new CursorProxy from passed in cursor SWT style (e.g. :appstarting, :hand, or :help)
21
+ #
22
+ # Cursor SWT styles are those that begin with "CURSOR_" prefix
23
+ #
24
+ # They are expected to be passed in in short form without the prefix (but would work with the prefix too)
25
+ def initialize(cursor_style)
26
+ @cursor_style = cursor_style
27
+ @cursor_style = SWTProxy.reverse_lookup(@cursor_style).detect { |symbol| symbol.to_s.downcase.start_with?('cursor_') } if cursor_style.is_a?(Integer)
28
+ @cursor_style = @cursor_style.to_s.downcase
29
+ @cursor_style = @cursor_style.sub(/^cursor\_/, '') if @cursor_style.start_with?('cursor_')
30
+ detect_invalid_cursor_style
31
+ @swt_cursor = DisplayProxy.instance.swt_display.get_system_cursor(SWTProxy[swt_style])
32
+ end
33
+
34
+ def swt_style
35
+ @swt_style ||= @cursor_style.upcase.start_with?('CURSOR_') ? @cursor_style : "CURSOR_#{@cursor_style}"
36
+ end
37
+
38
+ private
39
+
40
+ def detect_invalid_cursor_style
41
+ raise Error, cursor_style.to_s + ERROR_INVALID_CURSOR_STYLE unless CURSOR_STYLES.include?(cursor_style.to_s.downcase.to_sym)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -6,11 +6,10 @@ module Glimmer
6
6
  module SWT
7
7
  # Proxy for org.eclipse.swt.graphics.Font
8
8
  #
9
- # This class is meant to be used with WidgetProxy to manipulate
10
- # an SWT widget font.
9
+ # This class can be optionally used with WidgetProxy to manipulate
10
+ # an SWT widget font (reusing its FontData but building a new Font)
11
11
  #
12
- # It is not meant to create new SWT fonts form scratch without
13
- # a widget proxy.
12
+ # Otherwise, if no WidgetProxy is passed to constructor, it builds new FontData
14
13
  #
15
14
  # Invoking `#swt_font` returns the SWT Font object wrapped by this proxy
16
15
  #
@@ -21,7 +20,7 @@ module Glimmer
21
20
 
22
21
  include_package 'org.eclipse.swt.graphics'
23
22
 
24
- attr_reader :widget_proxy, :swt_font
23
+ attr_reader :widget_proxy, :swt_font, :font_properties
25
24
 
26
25
  # Builds a new font proxy from passed in widget_proxy and font_properties hash,
27
26
  #
@@ -31,8 +30,9 @@ module Glimmer
31
30
  #
32
31
  # Style (:style value) can only be one of FontProxy::FONT_STYLES values:
33
32
  # that is :normal, :bold, or :italic
34
- def initialize(widget_proxy, font_properties)
33
+ def initialize(widget_proxy = nil, font_properties)
35
34
  @widget_proxy = widget_proxy
35
+ @font_properties = font_properties
36
36
  detect_invalid_font_property(font_properties)
37
37
  font_properties[:style] = SWTProxy[*font_properties[:style]]
38
38
  font_data_args = [:name, :height, :style].map do |font_property_name|
@@ -57,7 +57,7 @@ module Glimmer
57
57
  private
58
58
 
59
59
  def font_datum
60
- @font_datum ||= @widget_proxy.swt_widget.getFont.getFontData[0]
60
+ @font_datum ||= @widget_proxy ? @widget_proxy.swt_widget.getFont.getFontData[0] : FontData.new
61
61
  end
62
62
 
63
63
  def detect_invalid_font_property(font_properties)
@@ -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
@@ -106,7 +106,17 @@ module Glimmer
106
106
  def deconstruct(integer)
107
107
  constant_source_class.constants.reduce([]) do |found, c|
108
108
  constant_value = constant_source_class.const_get(c) rescue -1
109
- is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
109
+ is_found = constant_value.is_a?(Integer) && (integer & constant_value) == integer
110
+ is_found ? found += [c] : found
111
+ end
112
+ end
113
+
114
+ # Reverse engineer a style integer into a symbol
115
+ # Useful for debugging
116
+ def reverse_lookup(integer)
117
+ constant_source_class.constants.reduce([]) do |found, c|
118
+ constant_value = constant_source_class.const_get(c) rescue -1
119
+ is_found = constant_value.is_a?(Integer) && integer == constant_value
110
120
  is_found ? found += [c] : found
111
121
  end
112
122
  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,25 +591,31 @@ 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
611
609
  end,
610
+ :cursor => lambda do |value|
611
+ cursor_proxy = nil
612
+ if value.is_a?(CursorProxy)
613
+ cursor_proxy = value
614
+ elsif value.is_a?(Symbol) || value.is_a?(String) || value.is_a?(Integer)
615
+ cursor_proxy = CursorProxy.new(value)
616
+ end
617
+ cursor_proxy ? cursor_proxy.swt_cursor : value
618
+ end,
612
619
  :foreground => color_converter,
613
620
  :font => lambda do |value|
614
621
  if value.is_a?(Hash)
@@ -618,6 +625,26 @@ module Glimmer
618
625
  value
619
626
  end
620
627
  end,
628
+ :image => lambda do |value|
629
+ if value.is_a?(String)
630
+ ImageProxy.new(value).swt_image
631
+ elsif value.is_a?(Array)
632
+ ImageProxy.new(*value).swt_image
633
+ else
634
+ value
635
+ end
636
+ end,
637
+ :images => lambda do |array|
638
+ array.to_a.map do |value|
639
+ if value.is_a?(String)
640
+ ImageProxy.new(value).swt_image
641
+ elsif value.is_a?(Array)
642
+ ImageProxy.new(*value).swt_image
643
+ else
644
+ value
645
+ end
646
+ end.to_java(Image)
647
+ end,
621
648
  :items => lambda do |value|
622
649
  value.to_java :string
623
650
  end,
Binary file
Binary file
Binary file
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.2
4
+ version: 0.6.0
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-27 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -309,6 +309,7 @@ files:
309
309
  - lib/glimmer/dsl/swt/color_expression.rb
310
310
  - lib/glimmer/dsl/swt/column_properties_expression.rb
311
311
  - lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb
312
+ - lib/glimmer/dsl/swt/cursor_expression.rb
312
313
  - lib/glimmer/dsl/swt/custom_widget_expression.rb
313
314
  - lib/glimmer/dsl/swt/data_binding_expression.rb
314
315
  - lib/glimmer/dsl/swt/dialog_expression.rb
@@ -316,6 +317,7 @@ files:
316
317
  - lib/glimmer/dsl/swt/dnd_expression.rb
317
318
  - lib/glimmer/dsl/swt/dsl.rb
318
319
  - lib/glimmer/dsl/swt/exec_expression.rb
320
+ - lib/glimmer/dsl/swt/font_expression.rb
319
321
  - lib/glimmer/dsl/swt/layout_data_expression.rb
320
322
  - lib/glimmer/dsl/swt/layout_expression.rb
321
323
  - lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb
@@ -341,9 +343,11 @@ files:
341
343
  - lib/glimmer/rake_task/list.rb
342
344
  - lib/glimmer/scaffold.rb
343
345
  - lib/glimmer/swt/color_proxy.rb
346
+ - lib/glimmer/swt/cursor_proxy.rb
344
347
  - lib/glimmer/swt/display_proxy.rb
345
348
  - lib/glimmer/swt/dnd_proxy.rb
346
349
  - lib/glimmer/swt/font_proxy.rb
350
+ - lib/glimmer/swt/image_proxy.rb
347
351
  - lib/glimmer/swt/layout_data_proxy.rb
348
352
  - lib/glimmer/swt/layout_proxy.rb
349
353
  - lib/glimmer/swt/menu_proxy.rb