Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java @ 2906:1780841d79af
Added navigation to fix analysis charts.
flys-client/trunk@4673 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 15 Jun 2012 12:13:09 +0000 |
parents | |
children | 37dce0f2f63b |
comparison
equal
deleted
inserted
replaced
2905:51ed89b754ae | 2906:1780841d79af |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | |
2 | |
3 import java.util.Date; | |
4 | |
5 import com.google.gwt.core.client.GWT; | |
6 | |
7 import com.smartgwt.client.widgets.layout.HLayout; | |
8 import com.smartgwt.client.widgets.layout.VLayout; | |
9 import com.smartgwt.client.widgets.Button; | |
10 | |
11 import com.smartgwt.client.widgets.form.DynamicForm; | |
12 import com.smartgwt.client.widgets.form.fields.TextItem; | |
13 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; | |
14 import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; | |
15 import com.smartgwt.client.widgets.events.ClickHandler; | |
16 import com.smartgwt.client.widgets.events.ClickEvent; | |
17 import com.smartgwt.client.widgets.form.validator.IsFloatValidator; | |
18 import com.smartgwt.client.widgets.Canvas; | |
19 import com.smartgwt.client.widgets.Img; | |
20 import com.smartgwt.client.types.Alignment; | |
21 import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; | |
22 import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; | |
23 | |
24 import de.intevation.flys.client.shared.model.Collection; | |
25 import de.intevation.flys.client.shared.model.OutputMode; | |
26 import de.intevation.flys.client.client.ui.CollectionView; | |
27 import de.intevation.flys.client.shared.model.FixAnalysisArtifact; | |
28 import de.intevation.flys.client.shared.model.Artifact; | |
29 import de.intevation.flys.client.client.Config; | |
30 | |
31 | |
32 /** | |
33 * Tab representing and showing one Chart-output. | |
34 * | |
35 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
36 */ | |
37 public class NaviChartOutputTab | |
38 extends ChartOutputTab | |
39 implements TabSelectedHandler | |
40 { | |
41 protected TextItem currentkm; | |
42 | |
43 public NaviChartOutputTab( | |
44 String title, | |
45 Collection collection, | |
46 OutputMode mode, | |
47 CollectionView collectionView | |
48 ){ | |
49 super(title, collection, mode, collectionView); | |
50 right.removeChild(chart); | |
51 right.addChild(createNaviChart()); | |
52 collectionView.registerTabHandler(this); | |
53 } | |
54 | |
55 | |
56 protected Canvas createNaviChart() { | |
57 final Artifact art = collectionView.getArtifact(); | |
58 VLayout root = new VLayout(); | |
59 root.setWidth100(); | |
60 root.setHeight100(); | |
61 | |
62 HLayout layout = new HLayout(); | |
63 layout.setAlign(Alignment.CENTER); | |
64 | |
65 DynamicForm form = new DynamicForm(); | |
66 Button lower = new Button("<<"); | |
67 lower.setWidth(30); | |
68 Button upper = new Button(">>"); | |
69 upper.setWidth(30); | |
70 currentkm = new TextItem(); | |
71 currentkm.setWidth(60); | |
72 currentkm.setShowTitle(false); | |
73 currentkm.setValidators(new IsFloatValidator()); | |
74 | |
75 form.setFields(currentkm); | |
76 form.setWidth(60); | |
77 FixAnalysisArtifact fix = (FixAnalysisArtifact) art; | |
78 | |
79 String s = fix.getArtifactDescription().getDataValueAsString("step"); | |
80 try { | |
81 double ds = Double.valueOf(s).doubleValue(); | |
82 collectionView.setSteps(ds); | |
83 } | |
84 catch(NumberFormatException nfe) { | |
85 collectionView.setSteps(100d); | |
86 } | |
87 collectionView.setMinKm(fix.getFilter().getFromKm()); | |
88 collectionView.setMaxKm(fix.getFilter().getToKm()); | |
89 | |
90 if (collectionView.getCurrentKm() == -1d) { | |
91 currentkm.setValue(fix.getFilter().getFromKm()); | |
92 collectionView.setCurrentKm(fix.getFilter().getFromKm()); | |
93 } | |
94 else { | |
95 currentkm.setValue(collectionView.getCurrentKm()); | |
96 } | |
97 | |
98 lower.addClickHandler(new ClickHandler() { | |
99 public void onClick(ClickEvent ce) { | |
100 updateChartDown(); | |
101 currentkm.setValue(collectionView.getCurrentKm()); | |
102 } | |
103 }); | |
104 | |
105 upper.addClickHandler(new ClickHandler() { | |
106 public void onClick(ClickEvent ce) { | |
107 updateChartUp(); | |
108 currentkm.setValue(collectionView.getCurrentKm()); | |
109 } | |
110 }); | |
111 | |
112 currentkm.addChangedHandler(new ChangedHandler() { | |
113 public void onChanged(ChangedEvent ce) { | |
114 if(ce.getForm().validate() && ce.getItem().getValue() != null) { | |
115 try { | |
116 String s = ce.getItem().getValue().toString(); | |
117 Double d = new Double(s); | |
118 if (d < collectionView.getMaxKm() && | |
119 d > collectionView.getMinKm()) { | |
120 collectionView.setCurrentKm(d); | |
121 if (right != null) { | |
122 updateChartPanel(); | |
123 updateChartInfo(); | |
124 } | |
125 } | |
126 } | |
127 catch(NumberFormatException nfe) { | |
128 // Do nothing. | |
129 } | |
130 } | |
131 } | |
132 }); | |
133 layout.addMember(lower); | |
134 layout.addMember(form); | |
135 layout.addMember(upper); | |
136 | |
137 root.addMember(chart); | |
138 root.addMember(layout); | |
139 return root; | |
140 } | |
141 | |
142 | |
143 protected void updateChartUp() { | |
144 double currentKm = collectionView.getCurrentKm(); | |
145 if (currentKm < collectionView.getMaxKm()) { | |
146 double newVal = currentKm * 100; | |
147 newVal += (collectionView.getSteps() / 10); | |
148 collectionView.setCurrentKm((double)Math.round(newVal) / 100); | |
149 updateChartPanel(); | |
150 updateChartInfo(); | |
151 } | |
152 } | |
153 protected void updateChartDown() { | |
154 double currentKm = collectionView.getCurrentKm(); | |
155 if (currentKm > collectionView.getMinKm()) { | |
156 double newVal = currentKm * 100; | |
157 newVal -= (collectionView.getSteps() / 10); | |
158 collectionView.setCurrentKm((double)Math.round(newVal) / 100); | |
159 updateChartPanel(); | |
160 updateChartInfo(); | |
161 } | |
162 | |
163 } | |
164 | |
165 /** | |
166 * Builds the URL that points to the chart image. | |
167 * | |
168 * @param width The width of the requested chart. | |
169 * @param height The height of the requested chart. | |
170 * @param xr Optional x range (used for zooming). | |
171 * @param yr Optional y range (used for zooming). | |
172 * | |
173 * @return the URL to the chart image. | |
174 */ | |
175 @Override | |
176 protected String getImgUrl(int width, int height) { | |
177 Config config = Config.getInstance(); | |
178 | |
179 String imgUrl = GWT.getModuleBaseURL(); | |
180 imgUrl += "chart"; | |
181 imgUrl += "?uuid=" + collection.identifier(); | |
182 imgUrl += "&type=" + mode.getName(); | |
183 imgUrl += "&locale=" + config.getLocale(); | |
184 imgUrl += "×tamp=" + new Date().getTime(); | |
185 imgUrl += "&width=" + Integer.toString(width); | |
186 imgUrl += "&height=" + Integer.toString(height - 40); | |
187 | |
188 Number[] zoom = getZoomValues(); | |
189 | |
190 if (zoom != null) { | |
191 if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { | |
192 // a zoom range of 0-1 means displaying the whole range. In such | |
193 // case we don't need to zoom. | |
194 imgUrl += "&minx=" + zoom[0]; | |
195 imgUrl += "&maxx=" + zoom[1]; | |
196 } | |
197 | |
198 if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { | |
199 // a zoom range of 0-1 means displaying the whole range. In such | |
200 // case we don't need to zoom. | |
201 imgUrl += "&miny=" + zoom[2]; | |
202 imgUrl += "&maxy=" + zoom[3]; | |
203 } | |
204 } | |
205 | |
206 if(collectionView.getArtifact() instanceof FixAnalysisArtifact) { | |
207 if (collectionView.getCurrentKm() == -1) { | |
208 FixAnalysisArtifact fix = | |
209 (FixAnalysisArtifact) collectionView.getArtifact(); | |
210 collectionView.setCurrentKm(fix.getFilter().getFromKm()); | |
211 } | |
212 imgUrl += "¤tKm=" + collectionView.getCurrentKm(); | |
213 } | |
214 GWT.log(imgUrl); | |
215 | |
216 return imgUrl; | |
217 } | |
218 | |
219 public void onTabSelected(TabSelectedEvent tse) { | |
220 if (this.equals(tse.getTab())) { | |
221 updateChartPanel(); | |
222 updateChartInfo(); | |
223 currentkm.setValue(collectionView.getCurrentKm()); | |
224 } | |
225 } | |
226 | |
227 } |