Module: JRubyFX::FXMLClassUtils

Defined in:
lib/jrubyfx/module.rb

Instance Method Summary collapse

Instance Method Details

#fxml_accessor(symbol_name, ptype = Java::javafx.beans.property.SimpleStringProperty, type = nil) ⇒ Object



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)
  # TODO: RDoc
  # TODO: somebody clean this up
  # TODO: _reader and _writer ? maybe? not?
  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

#fxml_raw_accessor(symbol_name, type = java::lang::String) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/jrubyfx/module.rb', line 104

def fxml_raw_accessor(symbol_name, type=java::lang::String)
  # TODO: RDoc
  # TODO: somebody clean this up
  # TODO: _reader and _writer
  send(:define_method, symbol_name.id2name.snake_case + "=") do |val|
    instance_variable_set("@#{symbol_name}", val)
  end
  send(:define_method, symbol_name.id2name.snake_case) do
    instance_variable_get("@#{symbol_name}")
  end
  send(:define_method, symbol_name.id2name.snake_case + "GetType") do
    return type.java_class
  end
  camel = symbol_name.id2name
  camel = camel[0].upcase + camel[1..-1]
  send(:define_method, "set" + camel) do |val|
    instance_variable_set("@#{symbol_name}", val)
  end
  send(:define_method, "get" + camel) do
    instance_variable_get("@#{symbol_name}")
  end
  send(:define_method, symbol_name.id2name + "GetType") do
    return type.java_class
  end
end