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 package org.utgenome.gwt.utgb.client.track.lib.old.datatype;
26
27 import java.util.Map;
28
29 import org.utgenome.gwt.utgb.client.db.datatype.DataTypeBase;
30 import org.utgenome.gwt.utgb.client.db.datatype.InputForm;
31 import org.utgenome.gwt.utgb.client.ui.FormLabel;
32
33 import com.google.gwt.event.dom.client.ChangeHandler;
34 import com.google.gwt.event.dom.client.KeyPressHandler;
35 import com.google.gwt.json.client.JSONString;
36 import com.google.gwt.json.client.JSONValue;
37 import com.google.gwt.user.client.ui.Grid;
38 import com.google.gwt.user.client.ui.TextBox;
39
40 public class LowerBoundType extends DataTypeBase {
41 private final LowerBoundInputForm inputForm;
42
43 public LowerBoundType(final String parameterName, final double minValue, final double maxValue) {
44 super(parameterName + " display lower bound");
45
46 inputForm = new LowerBoundInputForm(parameterName, minValue);
47 }
48
49 public InputForm getInputForm() {
50 return inputForm;
51 }
52
53 public String getTypeName() {
54 return "real-lbound";
55 }
56
57 public void setParameters(Map<String, String> parameterMap) {
58 inputForm.setParameters(parameterMap);
59 }
60
61 class LowerBoundInputForm extends InputForm {
62 private final String parameterName;
63
64 private final TextBox minBox = new TextBox();
65
66 private final double minValue;
67
68 LowerBoundInputForm(final String parameterName, final double minValue) {
69 this.parameterName = parameterName;
70 this.minValue = minValue;
71
72 final Grid panel = new Grid(1, 2);
73
74 panel.setWidget(0, 0, new FormLabel("lower bound[" + minValue + "]", false));
75 panel.setWidget(0, 1, minBox);
76 minBox.setText(Double.toString(minValue));
77 minBox.setWidth("50px");
78
79 initWidget(panel);
80 }
81
82 public void addChangeHandler(ChangeHandler listener) {
83 minBox.addChangeHandler(listener);
84 }
85
86 public void addKeyPressHandler(KeyPressHandler listener) {
87 minBox.addKeyPressHandler(listener);
88 }
89
90 public JSONValue getJSONValue() {
91 return new JSONString(getUserInput());
92 }
93
94 public String getUserInput() {
95 return "lbound-" + parameterName + "=" + getInputMinValue();
96 }
97
98 public void setValue(String value) {
99 }
100
101 public void setParameters(Map<String, String> parameterMap) {
102 final String minKey = "lbound-" + parameterName;
103 parameterMap.put(minKey, Double.toString(getInputMinValue()));
104 }
105
106 private double getInputMinValue() {
107 final double inputMinValue = Double.parseDouble(minBox.getText());
108
109 return Math.max(inputMinValue, minValue);
110 }
111 }
112 }