Class: Glimmer::SWT::TransformProxy

Inherits:
Object
  • Object
show all
Includes:
Properties
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 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
# File 'lib/glimmer/swt/transform_proxy.rb', line 39

def initialize(parent, *args, swt_transform: nil, multiply: false)
  @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

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
# File 'lib/glimmer/swt/transform_proxy.rb', line 95

def method_missing(method_name, *args, &block)
  result = @swt_transform.send(method_name, *args, &block)
  result.nil? ? self : result
rescue => e
  Glimmer::Config.logger.debug {"Neither MessageBoxProxy nor #{@swt_transform.class.name} can handle the method ##{method}"}
  super
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



71
72
73
# File 'lib/glimmer/swt/transform_proxy.rb', line 71

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

#get_attribute(attribute_name) ⇒ Object



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

def get_attribute(attribute_name)
  if @swt_transform.respond_to?(attribute_getter(attribute_name))
    @swt_transform.send(attribute_getter(attribute_name))
  else
    @swt_transform.send(attribute_name)
  end
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_attribute?(attribute_name, *args)
  @swt_transform.respond_to?(attribute_name) || @swt_transform.respond_to?(attribute_setter(attribute_name))
end

#post_add_contentObject



63
64
65
66
67
68
69
# File 'lib/glimmer/swt/transform_proxy.rb', line 63

def post_add_content
  if @multiply
    @parent.multiply(@swt_transform)
  else
    @parent&.set_attribute('transform', self)
  end
end

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

Returns:

  • (Boolean)


103
104
105
106
# File 'lib/glimmer/swt/transform_proxy.rb', line 103

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

#set_attribute(attribute_name, *args) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/glimmer/swt/transform_proxy.rb', line 79

def set_attribute(attribute_name, *args)
  if @swt_transform.respond_to?(attribute_name)
    @swt_transform.send(attribute_name, *args)
  elsif @swt_transform.respond_to?(attribute_setter(attribute_name))
    @swt_transform.send(attribute_setter(attribute_name), *args)
  end
end