View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // UpperBoundType.java
20  // Since: 2007/07/11
21  //
22  // $URL$ 
23  // $Author$
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 UpperBoundType extends DataTypeBase {
41  	private final UpperBoundInputForm inputForm;
42  
43  	public UpperBoundType(final String parameterName, final double minValue, final double maxValue) {
44  		super(parameterName + " display upper bound");
45  
46  		inputForm = new UpperBoundInputForm(parameterName, maxValue);
47  	}
48  
49  	public InputForm getInputForm() {
50  		return inputForm;
51  	}
52  
53  	public String getTypeName() {
54  		return "real-ubound";
55  	}
56  
57  	public void setParameters(Map<String, String> parameterMap) {
58  		inputForm.setParameters(parameterMap);
59  	}
60  
61  	class UpperBoundInputForm extends InputForm {
62  		private final String parameterName;
63  
64  		private final TextBox maxBox = new TextBox();
65  
66  		private final double maxValue;
67  
68  		UpperBoundInputForm(final String parameterName, final double maxValue) {
69  			this.parameterName = parameterName;
70  			this.maxValue = maxValue;
71  
72  			final Grid panel = new Grid(1, 2);
73  
74  			panel.setWidget(0, 0, new FormLabel("upper bound[" + maxValue + "]", false));
75  			panel.setWidget(0, 1, maxBox);
76  			maxBox.setText(Double.toString(maxValue));
77  			maxBox.setWidth("50px");
78  
79  			initWidget(panel);
80  		}
81  
82  		public void addChangeHandler(ChangeHandler listener) {
83  			maxBox.addChangeHandler(listener);
84  		}
85  
86  		public void addKeyPressHandler(KeyPressHandler listener) {
87  			maxBox.addKeyPressHandler(listener);
88  		}
89  
90  		public JSONValue getJSONValue() {
91  			return new JSONString(getUserInput());
92  		}
93  
94  		public String getUserInput() {
95  			return "ubound-" + parameterName + "=" + getInputMaxValue();
96  		}
97  
98  		public void setValue(String value) {
99  		}
100 
101 		public void setParameters(Map<String, String> parameterMap) {
102 			final String maxKey = "ubound-" + parameterName;
103 			parameterMap.put(maxKey, Double.toString(getInputMaxValue()));
104 		}
105 
106 		private double getInputMaxValue() {
107 			final double inputMaxValue = Double.parseDouble(maxBox.getText());
108 
109 			return Math.min(inputMaxValue, maxValue);
110 		}
111 	}
112 }