Class: Glimmer::SWT::LayoutProxy
- Inherits:
-
Object
- Object
- Glimmer::SWT::LayoutProxy
- Defined in:
- lib/glimmer/swt/layout_proxy.rb
Overview
Proxy for org.eclipse.swt.widgets.Layout
This is meant to be used with a WidgetProxy where it will set the layout in the SWT widget upon instantiation.
Follows the Proxy Design Pattern
Instance Attribute Summary collapse
-
#swt_layout ⇒ Object
readonly
Returns the value of attribute swt_layout.
-
#widget_proxy ⇒ Object
readonly
Returns the value of attribute widget_proxy.
Class Method Summary collapse
- .layout_exists?(underscored_layout_name) ⇒ Boolean
-
.swt_layout_class_for(underscored_layout_name) ⇒ Object
This supports layouts in and out of basic SWT library.
Instance Method Summary collapse
- #apply_property_type_converters(attribute_name, args) ⇒ Object
- #attribute_getter(attribute_name) ⇒ Object
- #attribute_setter(attribute_name) ⇒ Object
- #get_attribute(attribute_name) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
-
#initialize(underscored_layout_name, widget_proxy, args) ⇒ LayoutProxy
constructor
A new instance of LayoutProxy.
- #set_attribute(attribute_name, *args) ⇒ Object
Constructor Details
#initialize(underscored_layout_name, widget_proxy, args) ⇒ LayoutProxy
Returns a new instance of LayoutProxy.
43 44 45 46 47 48 49 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 43 def initialize(underscored_layout_name, , args) @underscored_layout_name = underscored_layout_name @widget_proxy = args = SWTProxy.constantify_args(args) @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args) @widget_proxy..setLayout(@swt_layout) end |
Instance Attribute Details
#swt_layout ⇒ Object (readonly)
Returns the value of attribute swt_layout.
13 14 15 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 13 def swt_layout @swt_layout end |
#widget_proxy ⇒ Object (readonly)
Returns the value of attribute widget_proxy.
13 14 15 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 13 def @widget_proxy end |
Class Method Details
.layout_exists?(underscored_layout_name) ⇒ Boolean
19 20 21 22 23 24 25 26 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 19 def layout_exists?(underscored_layout_name) begin swt_layout_class_for(underscored_layout_name) true rescue NameError => e false end end |
.swt_layout_class_for(underscored_layout_name) ⇒ Object
This supports layouts in and out of basic SWT library
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 29 def swt_layout_class_for(underscored_layout_name) swt_layout_name = underscored_layout_name.camelcase(:upper) swt_layout_class = eval(swt_layout_name) unless swt_layout_class.ancestors.include?(Layout) raise NameError, "Class #{swt_layout_class} matching #{underscored_layout_name} is not a subclass of org.eclipse.swt.widgets.Layout" end swt_layout_class rescue => e Glimmer::Config.logger&.debug e. # Glimmer::Config.logger&.debug "#{e.message}\n#{e.backtrace.join("\n")}" raise e end |
Instance Method Details
#apply_property_type_converters(attribute_name, args) ⇒ Object
67 68 69 70 71 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 67 def apply_property_type_converters(attribute_name, args) if args.count == 1 && SWTProxy.has_constant?(args.first) args[0] = SWTProxy.constant(args.first) end end |
#attribute_getter(attribute_name) ⇒ Object
77 78 79 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 77 def attribute_getter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}" end |
#attribute_setter(attribute_name) ⇒ Object
73 74 75 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 73 def attribute_setter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}=" end |
#get_attribute(attribute_name) ⇒ Object
63 64 65 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 63 def get_attribute(attribute_name) @swt_layout.send(attribute_getter(attribute_name)) end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
51 52 53 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 51 def has_attribute?(attribute_name, *args) @swt_layout.respond_to?(attribute_setter(attribute_name), args) end |
#set_attribute(attribute_name, *args) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 55 def set_attribute(attribute_name, *args) apply_property_type_converters(attribute_name, args) if args.first != @swt_layout.send(attribute_getter(attribute_name)) @swt_layout.send(attribute_setter(attribute_name), *args) @widget_proxy..getShell.pack end end |