129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/jrubyfx/module.rb', line 129
def fxml_accessor(symbol_name,ptype=Java::javafx.beans.property.SimpleStringProperty, type=nil)
pname = symbol_name.id2name + "Property"
raise "#{ptype} does not inherit from Property." unless ptype.ancestors.include? Java::javafx.beans.property.Property
unless type
type = ptype.java_class.java_instance_methods.find_all{|x|x.name == "getValue"}.map{|x|x.return_type}.find_all{|x|x != java.lang.Object.java_class}
if type.length != 1
raise "Unknown property type. Please manually supply a type or report this as a bug"
end
type = type[0]
else
type = type.java_class
end
send(:define_method, symbol_name.id2name.snake_case + "=") do |val|
send(pname).setValue val
end
send(:define_method, symbol_name.id2name.snake_case) do
send(pname).getValue
end
send(:define_method, symbol_name.id2name.snake_case + "GetType") do
return type
end
camel = symbol_name.id2name
camel = camel[0].upcase + camel[1..-1]
send(:define_method, "set" + camel) do |val|
send(pname).setValue val
end
send(:define_method, "get" + camel) do
send(pname).getValue
end
send(:define_method, symbol_name.id2name + "GetType") do
return type
end
send(:define_method, pname) do
unless instance_variable_get("@#{symbol_name}")
instance_variable_set("@#{symbol_name}", ptype.new(self, symbol_name.to_s))
end
return instance_variable_get("@#{symbol_name}")
end
send(:define_method, pname.snake_case) do
send(pname)
end
add_method_signature pname, [ptype]
add_method_signature "set" + camel, [java.lang.Void, type]
add_method_signature "get" + camel, [type]
end
|