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.
64 65 66 67 68 69 70 71 72 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 64 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) @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth) @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight) @widget_proxy..setLayout(@swt_layout) end |
Instance Attribute Details
#swt_layout ⇒ Object (readonly)
Returns the value of attribute swt_layout.
34 35 36 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 34 def swt_layout @swt_layout end |
#widget_proxy ⇒ Object (readonly)
Returns the value of attribute widget_proxy.
34 35 36 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 34 def @widget_proxy end |
Class Method Details
.layout_exists?(underscored_layout_name) ⇒ Boolean
40 41 42 43 44 45 46 47 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 40 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
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 50 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
90 91 92 93 94 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 90 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
100 101 102 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 100 def attribute_getter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}" end |
#attribute_setter(attribute_name) ⇒ Object
96 97 98 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 96 def attribute_setter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}=" end |
#get_attribute(attribute_name) ⇒ Object
86 87 88 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 86 def get_attribute(attribute_name) @swt_layout.send(attribute_getter(attribute_name)) end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
74 75 76 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 74 def has_attribute?(attribute_name, *args) @swt_layout.respond_to?(attribute_setter(attribute_name), args) end |
#set_attribute(attribute_name, *args) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/glimmer/swt/layout_proxy.rb', line 78 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 |