comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java @ 538:75df57220104

Adapted the MousePositionPanel to use the Transform2D object for computing the chart coordinates from image coordinates. flys-client/trunk@2036 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 01 Jun 2011 09:03:18 +0000
parents e08777967bad
children ed29599e06e5
comparison
equal deleted inserted replaced
537:d2c37ba78feb 538:75df57220104
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import java.util.Date; 3 import java.util.Date;
4 4
5 import com.google.gwt.core.client.GWT; 5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.user.client.rpc.AsyncCallback;
6 7
7 import com.smartgwt.client.widgets.Canvas; 8 import com.smartgwt.client.widgets.Canvas;
8 import com.smartgwt.client.widgets.Img; 9 import com.smartgwt.client.widgets.Img;
9 import com.smartgwt.client.widgets.Label;
10 10
11 import com.smartgwt.client.widgets.layout.HLayout; 11 import com.smartgwt.client.widgets.layout.HLayout;
12 import com.smartgwt.client.widgets.layout.VLayout; 12 import com.smartgwt.client.widgets.layout.VLayout;
13 13
14 import com.smartgwt.client.widgets.events.ResizedEvent; 14 import com.smartgwt.client.widgets.events.ResizedEvent;
15 import com.smartgwt.client.widgets.events.ResizedHandler; 15 import com.smartgwt.client.widgets.events.ResizedHandler;
16 16
17 import de.intevation.flys.client.shared.Transform2D;
17 import de.intevation.flys.client.shared.model.Collection; 18 import de.intevation.flys.client.shared.model.Collection;
18 import de.intevation.flys.client.shared.model.OutputMode; 19 import de.intevation.flys.client.shared.model.OutputMode;
19 import de.intevation.flys.client.client.Config; 20 import de.intevation.flys.client.client.Config;
20 import de.intevation.flys.client.client.event.OutputParameterChangeEvent; 21 import de.intevation.flys.client.client.event.OutputParameterChangeEvent;
21 import de.intevation.flys.client.client.event.OutputParameterChangeHandler; 22 import de.intevation.flys.client.client.event.OutputParameterChangeHandler;
23 import de.intevation.flys.client.client.services.ChartInfoService;
24 import de.intevation.flys.client.client.services.ChartInfoServiceAsync;
22 import de.intevation.flys.client.client.ui.CollectionView; 25 import de.intevation.flys.client.client.ui.CollectionView;
23 import de.intevation.flys.client.client.ui.OutputTab; 26 import de.intevation.flys.client.client.ui.OutputTab;
24 27
25 28
26 /** 29 /**
35 38
36 public static final int THEMEPANEL_MIN_WIDTH = 200; 39 public static final int THEMEPANEL_MIN_WIDTH = 200;
37 40
38 41
39 42
43 /** The service that is used to fetch chart information.*/
44 protected ChartInfoServiceAsync info = GWT.create(ChartInfoService.class);
45
46 /** The transformer used to transform image pixels into chart coordinates.*/
47 protected Transform2D transformer;
48
49 /** The collection view.*/
50 protected CollectionView view;
51
52
40 /** The canvas that wraps the chart toolbar.*/ 53 /** The canvas that wraps the chart toolbar.*/
41 protected Canvas tbarPanel; 54 protected Canvas tbarPanel;
42 55
43 /** The canvas that wraps the theme editor.*/ 56 /** The canvas that wraps the theme editor.*/
44 protected Canvas left; 57 protected Canvas left;
60 OutputMode mode, 73 OutputMode mode,
61 CollectionView collectionView 74 CollectionView collectionView
62 ){ 75 ){
63 super(title, collection, mode); 76 super(title, collection, mode);
64 77
78 view = collectionView;
65 left = new Canvas(); 79 left = new Canvas();
66 right = new Canvas(); 80 right = new Canvas();
67 tbarPanel = new ChartToolbar(collectionView, this); 81 tbarPanel = new ChartToolbar(collectionView, this);
68 82
69 left.setBorder("1px solid black"); 83 left.setBorder("1px solid black");
103 * 117 *
104 * @param event The resize event. 118 * @param event The resize event.
105 */ 119 */
106 public void onResized(ResizedEvent event) { 120 public void onResized(ResizedEvent event) {
107 updateChartPanel(); 121 updateChartPanel();
122 updateTransformer();
108 } 123 }
109 124
110 125
111 /** 126 /**
112 * Listens to change event in the chart them panel and updates chart after 127 * Listens to change event in the chart them panel and updates chart after
114 * 129 *
115 * @param event The OutputParameterChangeEvent. 130 * @param event The OutputParameterChangeEvent.
116 */ 131 */
117 public void onOutputParameterChanged(OutputParameterChangeEvent event) { 132 public void onOutputParameterChanged(OutputParameterChangeEvent event) {
118 updateChartPanel(); 133 updateChartPanel();
134 }
135
136
137 /**
138 * Updates the Transform2D object using the chart info service.
139 */
140 public void updateTransformer() {
141 Canvas chart = getChartPanel();
142
143 Config config = Config.getInstance();
144 String url = config.getServerUrl();
145 String locale = config.getLocale();
146
147 info.getChartInfo(
148 view.getCollection(),
149 url,
150 locale,
151 mode.getName(),
152 chart.getWidth(),
153 chart.getHeight(),
154 new AsyncCallback<Transform2D>() {
155 public void onFailure(Throwable caught) {
156 GWT.log("ERROR: " + caught.getMessage());
157 }
158
159 public void onSuccess(Transform2D transformer) {
160 setTransformer(transformer);
161 }
162 });
119 } 163 }
120 164
121 165
122 public void updateChartPanel() { 166 public void updateChartPanel() {
123 Canvas[] children = right.getChildren(); 167 Canvas[] children = right.getChildren();
128 right.addChild(createChartPanel(right.getWidth(), right.getHeight())); 172 right.addChild(createChartPanel(right.getWidth(), right.getHeight()));
129 } 173 }
130 174
131 175
132 public Canvas getChartPanel() { 176 public Canvas getChartPanel() {
133 return right; 177 Canvas[] children = right.getChildren();
178
179 if (children == null || children.length == 0) {
180 GWT.log("=> No chart image in the panel.");
181 return right;
182 }
183
184 return children[0];
185 }
186
187
188 /**
189 * Returns the Transform2D object used to transform image coordinates into
190 * chart coordinates.
191 *
192 * @return the Transform2D object.
193 */
194 public Transform2D getTransformer() {
195 return transformer;
196 }
197
198
199 /**
200 * Set a new Transform2D object for the chart. This should be the case, only
201 * if the chart image size has changed.
202 *
203 * @param transformer The new Transform2D object.
204 */
205 protected void setTransformer(Transform2D transformer) {
206 this.transformer = transformer;
134 } 207 }
135 208
136 209
137 protected Canvas createChartPanel() { 210 protected Canvas createChartPanel() {
138 return createChartPanel(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT); 211 return createChartPanel(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT);
144 chart.setWidth100(); 217 chart.setWidth100();
145 chart.setHeight100(); 218 chart.setHeight100();
146 219
147 return chart; 220 return chart;
148 221
149 }
150
151
152 protected Canvas createThemeControlPanel() {
153 Label label = new Label("Themensteuerung");
154 label.setHeight(25);
155 label.setMargin(5);
156
157 return label;
158 } 222 }
159 223
160 224
161 /** 225 /**
162 * Builds the chart image and returns it. 226 * Builds the chart image and returns it.

http://dive4elements.wald.intevation.org