Class: Glimmer::SWT::GLayout

Inherits:
Object
  • Object
show all
Includes:
Parent
Defined in:
lib/glimmer/swt/g_layout.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(underscored_layout_name, composite, args) ⇒ GLayout

Returns a new instance of GLayout.



40
41
42
43
44
45
46
# File 'lib/glimmer/swt/g_layout.rb', line 40

def initialize(underscored_layout_name, composite, args)
  @underscored_layout_name = underscored_layout_name
  @composite = composite
  args = GSWT.constantify_args(args)
  @layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
  @composite.setLayout(@layout)
end

Instance Attribute Details

#compositeObject (readonly)

Returns the value of attribute composite.



11
12
13
# File 'lib/glimmer/swt/g_layout.rb', line 11

def composite
  @composite
end

#layoutObject (readonly)

Returns the value of attribute layout.



12
13
14
# File 'lib/glimmer/swt/g_layout.rb', line 12

def layout
  @layout
end

Class Method Details

.layout_exists?(underscored_layout_name) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/glimmer/swt/g_layout.rb', line 17

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



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/glimmer/swt/g_layout.rb', line 27

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?(org.eclipse.swt.widgets.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.logger.debug "#{e.message}\n#{e.backtrace.join("\n")}"
  raise e
end

Instance Method Details

#apply_property_type_converters(attribute_name, args) ⇒ Object



61
62
63
64
65
# File 'lib/glimmer/swt/g_layout.rb', line 61

def apply_property_type_converters(attribute_name, args)
  if args.count == 1 && GSWT.has_constant?(args.first)
    args[0] = GSWT.constant(args.first)
  end
end

#attribute_setter(attribute_name) ⇒ Object



67
68
69
# File 'lib/glimmer/swt/g_layout.rb', line 67

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

#has_attribute?(attribute_name, *args) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/glimmer/swt/g_layout.rb', line 52

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

#process_block(block) ⇒ Object



48
49
50
# File 'lib/glimmer/swt/g_layout.rb', line 48

def process_block(block)
  block.call(@layout)
end

#set_attribute(attribute_name, *args) ⇒ Object



56
57
58
59
# File 'lib/glimmer/swt/g_layout.rb', line 56

def set_attribute(attribute_name, *args)
  apply_property_type_converters(attribute_name, args)
  @layout.send(attribute_setter(attribute_name), *args)
end