1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 package org.utgenome.gwt.utgb.client.db.datatype;
27
28 import com.google.gwt.core.client.GWT;
29 import com.google.gwt.event.dom.client.ChangeHandler;
30 import com.google.gwt.event.dom.client.KeyPressHandler;
31 import com.google.gwt.json.client.JSONNumber;
32 import com.google.gwt.json.client.JSONString;
33 import com.google.gwt.json.client.JSONValue;
34 import com.google.gwt.user.client.ui.TextBox;
35
36 public class FloatType extends DataTypeBase {
37 public FloatType(String name) {
38 super(name);
39 }
40
41 public InputForm getInputForm() {
42 return new FloatTypeForm();
43 }
44
45 public class FloatTypeForm extends InputForm {
46 private TextBox form = new TextBox();
47
48 public FloatTypeForm() {
49 initWidget(form);
50 }
51
52 public String getUserInput() {
53 return form.getText();
54 }
55
56 public JSONValue getJSONValue() {
57 try {
58 double value = Float.parseFloat(form.getText());
59 return new JSONNumber(value);
60 }
61 catch (NumberFormatException e) {
62 return new JSONString("");
63 }
64 }
65
66 public void setValue(String value) {
67 try {
68 float v = Float.parseFloat(value);
69 form.setText(value);
70 }
71 catch (NumberFormatException e) {
72 GWT.log(value + " is not a float type", e);
73 }
74 }
75
76 public void addKeyPressHandler(KeyPressHandler listener) {
77 form.addKeyPressHandler(listener);
78 }
79
80 public void addChangeHandler(ChangeHandler listener) {
81 form.addChangeHandler(listener);
82 }
83 }
84
85 public String getTypeName() {
86 return "float";
87 }
88
89 }