| 31 | |
| 32 | //TODO implement pointer events |
| 33 | public class TextBox extends Screen { |
| 34 | |
| 35 | TextField tf; |
| 36 | InputMethodListener inputMethodListener = new InputMethodListener() { |
| 37 | |
| 38 | public void caretPositionChanged(InputMethodEvent event) { |
| 39 | setCaretPosition(event.getCaret()); |
| 40 | tf.setCaretVisible(true); |
| 41 | repaint(); |
| 42 | } |
| 43 | |
| 44 | public void inputMethodTextChanged(InputMethodEvent event) { |
| 45 | tf.setCaretVisible(false); |
| 46 | tf.setString(event.getText(), event.getCaret()); |
| 47 | repaint(); |
| 48 | } |
| 49 | |
| 50 | public int getCaretPosition() { |
| 51 | return TextBox.this.getCaretPosition(); |
| 52 | } |
| 53 | |
| 54 | public String getText() { |
| 55 | return TextBox.this.getString(); |
| 56 | } |
| 57 | |
| 58 | public int getConstraints() { |
| 59 | return TextBox.this.getConstraints(); |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | public TextBox(String title, String text, int maxSize, int constraints) { |
| 64 | super(title); |
| 65 | |
| 66 | tf = new TextField(null, text, maxSize, constraints); |
| 67 | |
| 68 | super.setUI(DeviceFactory.getDevice().getUIFactory().createTextBoxUI(this)); |
| 69 | |
| 70 | setString(text); |
| 71 | } |
| 72 | |
| 73 | public void delete(int offset, int length) { |
| 74 | ((TextBoxUI) ui).delete(offset, length); |
| 75 | } |
| 76 | |
| 77 | public int getCaretPosition() { |
| 78 | return ((TextBoxUI) ui).getCaretPosition(); |
| 79 | } |
| 80 | |
| 81 | public int getChars(char[] data) { |
| 82 | return tf.getChars(data); |
| 83 | } |
| 84 | |
| 85 | public int getConstraints() { |
| 86 | return tf.getConstraints(); |
| 87 | } |
| 88 | |
| 89 | public int getMaxSize() { |
| 90 | return tf.getMaxSize(); |
nothing calls this directly
no outgoing calls
no test coverage detected