Class: Glimmer::SWT::TransformProxy
- Inherits:
-
Object
- Object
- Glimmer::SWT::TransformProxy
- Includes:
- ProxyProperties
- Defined in:
- lib/glimmer/swt/transform_proxy.rb
Overview
Proxy for org.eclipse.swt.graphics.Transform
Follows the Proxy Design Pattern
Constant Summary collapse
- ATTRIBUTE_ALIASES =
{ 'rotation' => 'rotate', 'translation' => 'translate', 'inversion' => 'invert', }
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#swt_transform ⇒ Object
readonly
Returns the value of attribute swt_transform.
Instance Method Summary collapse
- #content(&block) ⇒ Object
- #get_attribute(attribute_name) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
-
#initialize(parent, *args, swt_transform: nil, multiply: false) ⇒ TransformProxy
constructor
A new instance of TransformProxy.
- #method_missing(method_name, *args, &block) ⇒ Object
- #post_add_content ⇒ Object
- #proxy_source_object ⇒ Object
- #respond_to?(method, *args, &block) ⇒ Boolean
- #set_attribute(attribute_name, *args) ⇒ Object
Methods included from ProxyProperties
#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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 45 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
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 107 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.} end end |
Instance Attribute Details
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
43 44 45 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 43 def parent @parent end |
#swt_transform ⇒ Object (readonly)
Returns the value of attribute swt_transform.
43 44 45 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 43 def swt_transform @swt_transform end |
Instance Method Details
#content(&block) ⇒ Object
81 82 83 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 81 def content(&block) Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::TransformExpression.new, 'transform', &block) end |
#get_attribute(attribute_name) ⇒ Object
102 103 104 105 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 102 def get_attribute(attribute_name) attribute_name = ATTRIBUTE_ALIASES[attribute_name.to_s] || attribute_name super(attribute_name) end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
89 90 91 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 89 def has_attribute?(attribute_name, *args) ATTRIBUTE_ALIASES.keys.include?(attribute_name.to_s) || Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.respond_to?(attribute_name) } || super end |
#post_add_content ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 71 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_object ⇒ Object
85 86 87 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 85 def proxy_source_object @swt_transform end |
#respond_to?(method, *args, &block) ⇒ Boolean
119 120 121 122 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 119 def respond_to?(method, *args, &block) super || @swt_transform.respond_to?(method, *args, &block) end |
#set_attribute(attribute_name, *args) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/glimmer/swt/transform_proxy.rb', line 93 def set_attribute(attribute_name, *args) attribute_name = ATTRIBUTE_ALIASES[attribute_name.to_s] || attribute_name if @swt_transform.respond_to?(attribute_name) Glimmer::SWT::DisplayProxy.instance.auto_exec { @swt_transform.send(attribute_name, *args) } else super end end |