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.ArrayList;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.utgenome.gwt.utgb.client.db.datatype.DataTypeBase;
32 import org.utgenome.gwt.utgb.client.db.datatype.InputForm;
33
34 import com.google.gwt.event.dom.client.ChangeHandler;
35 import com.google.gwt.event.dom.client.ClickEvent;
36 import com.google.gwt.event.dom.client.ClickHandler;
37 import com.google.gwt.event.dom.client.KeyPressHandler;
38 import com.google.gwt.json.client.JSONString;
39 import com.google.gwt.json.client.JSONValue;
40 import com.google.gwt.user.client.ui.CheckBox;
41 import com.google.gwt.user.client.ui.FlowPanel;
42
43
44
45
46
47 public class DispType extends DataTypeBase {
48
49 private final DispInputForm inputForm;
50
51 public DispType(final String parameterName, final String[] values) {
52 super(parameterName + " display setting");
53
54 inputForm = new DispInputForm(parameterName, values);
55 }
56
57 public InputForm getInputForm() {
58 return inputForm;
59 }
60
61 public String getTypeName() {
62 return "select-disp";
63 }
64
65 public void setParameters(Map<String, String> parameterMap) {
66 inputForm.setParameters(parameterMap);
67 }
68
69 private class DispInputForm extends ConfigInputForm implements ClickHandler {
70 private List<ChangeHandler> changeHandlers = new ArrayList<ChangeHandler>();
71
72 private final String parameterName;
73
74 private CheckBox[] checkBoxs;
75
76 DispInputForm(final String parameterName, final String[] values) {
77 this.parameterName = parameterName;
78 checkBoxs = new CheckBox[values.length];
79
80 final FlowPanel panel = new FlowPanel();
81
82 for (int i = 0; i < values.length; i++) {
83 checkBoxs[i] = new CheckBox(values[i]);
84 checkBoxs[i].addClickHandler(this);
85 checkBoxs[i].setValue(true);
86 panel.add(checkBoxs[i]);
87 }
88
89 addWidget(panel);
90 }
91
92 public void onClick(ClickEvent e) {
93 for (int i = 0; i < changeHandlers.size(); i++) {
94 final ChangeHandler changeHandler = (ChangeHandler) (changeHandlers.get(i));
95 changeHandler.onChange(null);
96 }
97 }
98
99 public void addChangeHandler(ChangeHandler listener) {
100 changeHandlers.add(listener);
101 }
102
103 public void addKeyPressHandler(KeyPressHandler listener) {
104 for (int i = 0; i < checkBoxs.length; i++) {
105 checkBoxs[i].addKeyPressHandler(listener);
106 }
107 }
108
109 public JSONValue getJSONValue() {
110 return new JSONString(getUserInput());
111 }
112
113 public String getUserInput() {
114 final StringBuffer buf = new StringBuffer();
115
116 for (int i = 0; i < checkBoxs.length; i++) {
117 if (i != 0)
118 buf.append('&');
119 buf.append("disp-" + parameterName + "-" + checkBoxs[i].getText() + "=");
120 if (checkBoxs[i].getValue()) {
121 buf.append("on");
122 }
123 else {
124 buf.append("off");
125 }
126 }
127
128 return buf.toString();
129 }
130
131 public void setValue(String value) {
132 }
133
134 public void setParameters(Map<String, String> parameterMap) {
135 for (int i = 0; i < checkBoxs.length; i++) {
136 final String key = "disp-" + parameterName + "-" + checkBoxs[i].getText();
137 if (checkBoxs[i].getValue()) {
138 parameterMap.put(key, "on");
139 }
140 else {
141 parameterMap.put(key, "off");
142 }
143 }
144 }
145 }
146
147 }