PageRenderTime 12ms CodeModel.GetById 7ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/src/gosu/jruby/TextInputProxy.java

http://jgosu.googlecode.com/
Java | 73 lines | 51 code | 22 blank | 0 comment | 0 complexity | 52fa988dda98a778fc986cb7813082d7 MD5 | raw file
 1import gosu.TextInput;
 2
 3import org.jruby.*;
 4import org.jruby.runtime.*;
 5import org.jruby.runtime.builtin.IRubyObject;
 6import org.jruby.javasupport.JavaUtil;
 7import org.jruby.anno.JRubyMethod;
 8import static org.jruby.RubyNumeric.*;
 9
10
11public class TextInputProxy extends RubyObject {
12  private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
13    public IRubyObject allocate(Ruby runtime, RubyClass klass) {
14      return new TextInputProxy(runtime, klass);
15    }
16  };
17
18  private TextInput _input;
19
20  private final Ruby _runtime;
21
22  public static void createTextInputClass(Ruby runtime) {
23    RubyModule mGosu = runtime.getModule("Gosu");
24    RubyClass cTextInput = mGosu.defineClassUnder("TextInput", runtime.getObject(), ALLOCATOR);
25
26    cTextInput.defineAnnotatedMethods(TextInputProxy.class);
27  }
28
29
30  public TextInputProxy(Ruby runtime, RubyClass type) {
31    super(runtime, type);
32    _runtime = runtime;
33  }
34
35
36  public TextInput getTextInput() { return _input; }
37  public void setTextInput(TextInput input) { _input = input; }
38
39
40  @JRubyMethod(name = "initialize",
41               visibility = Visibility.PRIVATE)
42  public IRubyObject initialize() {
43    _input = new TextInput();
44    return this;
45  }
46
47
48  @JRubyMethod(name = "text")
49  public IRubyObject getText() {
50    return _runtime.newString(_input.getText());
51  }
52
53
54  @JRubyMethod(name = "text=",
55               required = 1)
56  public IRubyObject setText(IRubyObject arg) {
57    _input.setText(arg.toString());
58    return arg;
59  }
60
61
62  @JRubyMethod(name = "caret_pos")
63  public IRubyObject getCaretPos() {
64    return _runtime.newFixnum(_input.getCaretPos());
65  }
66
67
68  @JRubyMethod(name = "selection_start")
69  public IRubyObject getSelectionStart() {
70    return _runtime.newFixnum(_input.getSelectionStart());
71  }
72
73}