Class: Java::OrgEclipseSwtWidgets::Widget

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sweet/widget.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



138
139
140
# File 'lib/sweet/widget.rb', line 138

def method_missing(name, *args, &block)
  handle_container(&block) rescue super
end

Instance Attribute Details

#app(&block) ⇒ Object (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/sweet/widget.rb', line 5

def app
  @app
end

Class Method Details

.alias_property(aliases = {}) ⇒ Object



47
48
49
50
51
52
# File 'lib/sweet/widget.rb', line 47

def self.alias_property(aliases = {})
  aliases.each do |from, to|
    alias_method from, to unless "to"
    alias_method "#{from}=", "#{to}=" unless "#{to}="
  end
end

Instance Method Details

#append(&block) ⇒ Object



35
36
37
38
# File 'lib/sweet/widget.rb', line 35

def append(&block)
  raise "Append called without block" unless block
  handle_container &block
end

#customObject



134
135
136
# File 'lib/sweet/widget.rb', line 134

def custom
  org.eclipse.swt.custom
end

#grid_data=(*opts) ⇒ Object

TODO unify this layout mess somehow TODO hierarchical hash for nicer client code



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/sweet/widget.rb', line 76

def grid_data=(*opts)
  opts = Hash[opts]
  ax, ay = opts[:align]
  gx, gy = opts[:grab]
  sx, sy = opts[:span]
  args = [ax || swt::BEGINNING, ay || swt::CENTER,
    gx || false, gy || false, sx || 1, sy || 1]
  args.map!{|v| v.is_a?(Symbol) ? v.swt_const : v}
  Sweet.debug args.inspect
  l = layouts::GridData.new(*args)
  self.layout_data = l
end

#heightObject



110
111
112
# File 'lib/sweet/widget.rb', line 110

def height
  size.y
end

#height=(value) ⇒ Object



113
114
115
# File 'lib/sweet/widget.rb', line 113

def height=(value)
  self.size = nil, value
end

#hideObject



96
97
98
# File 'lib/sweet/widget.rb', line 96

def hide
  self.visible = false
end

#layoutsObject



131
132
133
# File 'lib/sweet/widget.rb', line 131

def layouts
  org.eclipse.swt.layout
end

#meta(&block) ⇒ Object



40
41
42
43
44
45
# File 'lib/sweet/widget.rb', line 40

def meta(&block)
  @meta ||= class << self
    self
  end
  block ? @meta.class_eval(&block) : @meta
end

#options=(opts) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sweet/widget.rb', line 54

def options=(opts)
  # TODO reader method
  opts.each_pair do |k, v|
    case k
    when :hidden
      setVisible !v
    else
      name = k.to_s + "="
      if respond_to?(name)
        if v
          Sweet.debug "#{self.java_class.simple_name}.#{k} = #{v.inspect}"
          send name, *v
        end
        opts.delete(k)
      end
    end
  end
end

#perform(&block) ⇒ Object



92
93
94
# File 'lib/sweet/widget.rb', line 92

def perform(&block)
  app.perform &block
end

#row_data=(x, y = nil) ⇒ Object



88
89
90
# File 'lib/sweet/widget.rb', line 88

def row_data=(x, y = nil)
  self.layout_data = layouts::RowData.new(x || swt::DEFAULT, y || swt::DEFAULT)
end

#showObject



99
100
101
# File 'lib/sweet/widget.rb', line 99

def show
  self.visible = true
end

#size=(*s) ⇒ Object



117
118
119
120
121
122
# File 'lib/sweet/widget.rb', line 117

def size=(*s)
  nw, nh = s.flatten
  nw ||= width
  nh ||= height
  setSize(nw, nh)
end

#sweeten(app, opts, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sweet/widget.rb', line 7

def sweeten(app, opts, &block)
  @app = app
  self.options = opts
  
  if block
    case handler = @block_handler
    when nil
      handle_container &block
    when Symbol
      send handler, &block
    when Numeric
      addListener handler, &block
    when Proc
      instance_eval do
        handler.call self, opts, block
      end
    else
      raise "Invalid :block_handler ",handler
    end
  end

  puts "Unknown properties for class #{self.class}: #{opts.keys.inspect}" unless opts.empty?
end

#swtObject

TODO replace via import?



125
126
127
# File 'lib/sweet/widget.rb', line 125

def swt
  org.eclipse.swt.SWT
end

#widgetsObject



128
129
130
# File 'lib/sweet/widget.rb', line 128

def widgets
  org.eclipse.swt.widgets
end

#widthObject



103
104
105
# File 'lib/sweet/widget.rb', line 103

def width
  size.x
end

#width=(value) ⇒ Object



106
107
108
# File 'lib/sweet/widget.rb', line 106

def width=(value)
  self.size = value, nil
end