Class: Glimmer::SWT::TransformProxy

Inherits:
Object
  • Object
show all
Includes:
ProxyProperties
Defined in:
lib/glimmer/swt/transform_proxy.rb

Overview

Proxy for org.eclipse.swt.graphics.Transform

Follows the Proxy Design Pattern

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ProxyProperties

#get_attribute, #has_attribute_getter?, #has_attribute_setter?

Methods included from Properties

attribute_getter, #attribute_getter, attribute_setter, #attribute_setter, normalized_attribute, #normalized_attribute, ruby_attribute_getter, #ruby_attribute_setter, ruby_attribute_setter

Constructor Details

#initialize(parent, *args, swt_transform: nil, multiply: false) ⇒ TransformProxy

Returns a new instance of TransformProxy.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/glimmer/swt/transform_proxy.rb', line 39

def initialize(parent, *args, swt_transform: nil, multiply: false)
  Glimmer::SWT::DisplayProxy.instance.auto_exec do
    @parent = parent
    @multiply = multiply
    if swt_transform.nil?
      if !args.first.is_a?(Display) && !args.first.is_a?(DisplayProxy)
        args.prepend DisplayProxy.instance.swt_display
      end
      if args.first.is_a?(DisplayProxy)
        args[0] = args[0].swt_display
      end
      if args.last.is_a?(TransformProxy)
        args[-1] = args[-1].swt_transform
      end
      if args.last.nil? || args.last.is_a?(Transform)
        @swt_transform = args.last
        @parent&.set_attribute('transform', self)
      else
        @swt_transform = Transform.new(*args)
      end
    else
      @swt_transform = swt_transform
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/glimmer/swt/transform_proxy.rb', line 95

def method_missing(method_name, *args, &block)
  result = Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.send(method_name, *args, &block) }
  result.nil? ? self : result
rescue => e
  begin
    super
  rescue Exception => inner_e
    Glimmer::Config.logger.error {"Neither TransformProxy nor #{@swt_transform.class.name} can handle the method ##{method}"}
    Glimmer::Config.logger.error {e.full_message}
  end
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



37
38
39
# File 'lib/glimmer/swt/transform_proxy.rb', line 37

def parent
  @parent
end

#swt_transformObject (readonly)

Returns the value of attribute swt_transform.



37
38
39
# File 'lib/glimmer/swt/transform_proxy.rb', line 37

def swt_transform
  @swt_transform
end

Instance Method Details

#content(&block) ⇒ Object



75
76
77
# File 'lib/glimmer/swt/transform_proxy.rb', line 75

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::TransformExpression.new, 'transform', &block)
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/glimmer/swt/transform_proxy.rb', line 83

def has_attribute?(attribute_name, *args)
  Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.respond_to?(attribute_name) } || super
end

#post_add_contentObject



65
66
67
68
69
70
71
72
73
# File 'lib/glimmer/swt/transform_proxy.rb', line 65

def post_add_content
  if @multiply
    Glimmer::SWT::DisplayProxy.instance.auto_exec {
      @parent.multiply(@swt_transform)
    }
  else
    @parent&.set_attribute('transform', self)
  end
end

#proxy_source_objectObject



79
80
81
# File 'lib/glimmer/swt/transform_proxy.rb', line 79

def proxy_source_object
  @swt_transform
end

#respond_to?(method, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
110
# File 'lib/glimmer/swt/transform_proxy.rb', line 107

def respond_to?(method, *args, &block)
  super ||
    @swt_transform.respond_to?(method, *args, &block)
end

#set_attribute(attribute_name, *args) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/glimmer/swt/transform_proxy.rb', line 87

def set_attribute(attribute_name, *args)
  if @swt_transform.respond_to?(attribute_name)
    Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.send(attribute_name, *args) }
  else
    super
  end
end