Class: Glimmer::SWT::LayoutDataProxy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 49

def initialize(widget_proxy, args)
  @widget_proxy = widget_proxy
  args = SWTProxy.constantify_args(args)
  begin
    @swt_layout_data = swt_layout_data_class.new(*args)
  rescue => e
    Glimmer::Config.logger.debug {"#{e.message}\n#{e.backtrace.join("\n")}"}
    @swt_layout_data = args.first if args.count == 1
  end
  @widget_proxy.swt_widget.setLayoutData(@swt_layout_data)
end

Instance Attribute Details

#swt_layout_dataObject (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_proxyObject (readonly)

Returns the value of attribute widget_proxy.



45
46
47
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 45

def widget_proxy
  @widget_proxy
end

Instance Method Details

#attribute_getter(attribute_name) ⇒ Object



100
101
102
# File 'lib/glimmer/swt/layout_data_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_data_proxy.rb', line 96

def attribute_setter(attribute_name)
  "#{attribute_name.to_s.camelcase(:lower)}="
end

#get_attribute(attribute_name) ⇒ Object



92
93
94
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 92

def get_attribute(attribute_name)
  @swt_layout_data.send(attribute_getter(attribute_name))
end

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 80

def has_attribute?(attribute_name, *args)
  @swt_layout_data.respond_to?(attribute_setter(attribute_name), args)
end

#set_attribute(attribute_name, *args) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 84

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.swt_widget.getShell.pack
  end
end

#swt_layout_data_classObject

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



74
75
76
77
78
# File 'lib/glimmer/swt/layout_data_proxy.rb', line 74

def swt_layout_data_class
  parent_layout_class_name = @widget_proxy.swt_widget.getParent.getLayout.class.name
  layout_data_class_name = parent_layout_class_name.sub(/Layout$/, 'Data')
  eval(layout_data_class_name)
end