/src/gosu/jruby/TextInputProxy.java
http://jgosu.googlecode.com/ · Java · 73 lines · 51 code · 22 blank · 0 comment · 0 complexity · 52fa988dda98a778fc986cb7813082d7 MD5 · raw file
- import gosu.TextInput;
- import org.jruby.*;
- import org.jruby.runtime.*;
- import org.jruby.runtime.builtin.IRubyObject;
- import org.jruby.javasupport.JavaUtil;
- import org.jruby.anno.JRubyMethod;
- import static org.jruby.RubyNumeric.*;
- public class TextInputProxy extends RubyObject {
- private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
- public IRubyObject allocate(Ruby runtime, RubyClass klass) {
- return new TextInputProxy(runtime, klass);
- }
- };
- private TextInput _input;
- private final Ruby _runtime;
- public static void createTextInputClass(Ruby runtime) {
- RubyModule mGosu = runtime.getModule("Gosu");
- RubyClass cTextInput = mGosu.defineClassUnder("TextInput", runtime.getObject(), ALLOCATOR);
- cTextInput.defineAnnotatedMethods(TextInputProxy.class);
- }
- public TextInputProxy(Ruby runtime, RubyClass type) {
- super(runtime, type);
- _runtime = runtime;
- }
- public TextInput getTextInput() { return _input; }
- public void setTextInput(TextInput input) { _input = input; }
- @JRubyMethod(name = "initialize",
- visibility = Visibility.PRIVATE)
- public IRubyObject initialize() {
- _input = new TextInput();
- return this;
- }
- @JRubyMethod(name = "text")
- public IRubyObject getText() {
- return _runtime.newString(_input.getText());
- }
- @JRubyMethod(name = "text=",
- required = 1)
- public IRubyObject setText(IRubyObject arg) {
- _input.setText(arg.toString());
- return arg;
- }
- @JRubyMethod(name = "caret_pos")
- public IRubyObject getCaretPos() {
- return _runtime.newFixnum(_input.getCaretPos());
- }
- @JRubyMethod(name = "selection_start")
- public IRubyObject getSelectionStart() {
- return _runtime.newFixnum(_input.getSelectionStart());
- }
- }