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
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 49 def initialize(, args) DisplayProxy.instance.auto_exec do @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 end |
Instance Attribute Details
#swt_layout_data ⇒ Object (readonly)
Returns the value of attribute swt_layout_data.
46 47 48 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 46 def swt_layout_data @swt_layout_data end |
#widget_proxy ⇒ Object (readonly)
Returns the value of attribute widget_proxy.
45 46 47 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 45 def @widget_proxy end |
Instance Method Details
#attribute_getter(attribute_name) ⇒ Object
106 107 108 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 106 def attribute_getter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}" end |
#attribute_setter(attribute_name) ⇒ Object
102 103 104 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 102 def attribute_setter(attribute_name) "#{attribute_name.to_s.camelcase(:lower)}=" end |
#get_attribute(attribute_name) ⇒ Object
98 99 100 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 98 def get_attribute(attribute_name) @swt_layout_data.send(attribute_getter(attribute_name)) end |
#has_attribute?(attribute_name, *args) ⇒ Boolean
84 85 86 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 84 def has_attribute?(attribute_name, *args) @swt_layout_data.respond_to?(attribute_setter(attribute_name), args) end |
#set_attribute(attribute_name, *args) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 88 def set_attribute(attribute_name, *args) DisplayProxy.instance.auto_exec do 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 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
76 77 78 79 80 81 82 |
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 76 def swt_layout_data_class DisplayProxy.instance.auto_exec do 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 end |