Class: Glimmer::SWT::LayoutDataProxy
- Inherits:
-
Object
- Object
- Glimmer::SWT::LayoutDataProxy
- Defined in:
- lib/glimmer/swt/layout_data_proxy.rb
Overview
Generic proxy for all SWT layout data objects, such as GridData & RowData
This class is meant to be used with an existing WidgetProxy as it figures out the right SWT layout data class name by convention from the parent SWT widget layout class name
The convention is:
-
Start with the parent widget layout package/class name (e.g. org.eclipse.swt.layout.RowLayout)
-
Replace the word “Layout” with “Data” in the class name
Examples of figuring out SWT layout data class:
-
org.eclipse.swt.layout.RowData for org.eclipse.swt.layout.RowLayout
-
org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
Follows the Proxy Design Pattern
Instance Attribute Summary collapse
-
#swt_layout_data ⇒ Object
readonly
Returns the value of attribute swt_layout_data.
-
#widget_proxy ⇒ Object
readonly
Returns the value of attribute widget_proxy.
Instance Method Summary collapse
- #attribute_getter(attribute_name) ⇒ Object
- #attribute_setter(attribute_name) ⇒ Object
- #get_attribute(attribute_name) ⇒ Object
- #has_attribute?(attribute_name, *args) ⇒ Boolean
-
#initialize(widget_proxy, args) ⇒ LayoutDataProxy
constructor
Inititalizes with owning widget proxy and layout data arguments.
- #set_attribute(attribute_name, *args) ⇒ Object
-
#swt_layout_data_class ⇒ Object
This figures out the right SWT layout data class name by convention from the parent SWT widget layout class name.
Constructor Details
#initialize(widget_proxy, args) ⇒ LayoutDataProxy
Inititalizes with owning widget proxy and layout data arguments
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 28 def initialize(, args) @widget_proxy = args = SWTProxy.constantify_args(args) begin @swt_layout_data = swt_layout_data_class.new(*args) rescue => e Glimmer::Config.logger&.debug "#{e.}\n#{e.backtrace.join("\n")}" @swt_layout_data = args.first if args.count == 1 end @widget_proxy..setLayoutData(@swt_layout_data) end |
Instance Attribute Details
#swt_layout_data ⇒ Object (readonly)
Returns the value of attribute swt_layout_data.
25 26 27 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 25 def swt_layout_data @swt_layout_data end |
#widget_proxy ⇒ Object (readonly)
Returns the value of attribute widget_proxy.
24 25 26 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 24 def @widget_proxy end |
Instance Method Details
#attribute_getter(attribute_name) ⇒ Object
79 80 81 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 79 def attribute_getter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}" end |
#attribute_setter(attribute_name) ⇒ Object
75 76 77 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 75 def attribute_setter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}=" end |
#get_attribute(attribute_name) ⇒ Object
71 72 73 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 71 def get_attribute(attribute_name) @swt_layout_data.send(attribute_getter(attribute_name)) end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
59 60 61 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 59 def has_attribute?(attribute_name, *args) @swt_layout_data.respond_to?(attribute_setter(attribute_name), args) end |
#set_attribute(attribute_name, *args) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 63 def set_attribute(attribute_name, *args) args = SWTProxy.constantify_args(args) if args.first != @swt_layout_data.send(attribute_getter(attribute_name)) @swt_layout_data.send(attribute_setter(attribute_name), *args) @widget_proxy..getShell.pack end end |
#swt_layout_data_class ⇒ Object
This figures out the right SWT layout data class name by convention from the parent SWT widget layout class name
Supports layout data classes in and out of basic SWT library
The convention is:
-
Start with the parent widget layout package/class name (e.g. org.eclipse.swt.layout.RowLayout)
-
Replace the word “Layout” with “Data” in the class name
Examples of figuring out SWT layout data class:
-
org.eclipse.swt.layout.RowData for org.eclipse.swt.layout.RowLayout
-
org.eclipse.swt.layout.GridData for org.eclipse.swt.layout.GridLayout
53 54 55 56 57 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 53 def swt_layout_data_class parent_layout_class_name = @widget_proxy..getParent.getLayout.class.name layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data') eval(layout_data_class_name) end |