Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/OverviewOutputTab.java @ 2977:5161e25392ea
Added chart overview to sq relation in minfo module.
flys-client/trunk@4974 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 13 Jul 2012 08:54:57 +0000 |
parents | |
children | d2a54ae0016b |
comparison
equal
deleted
inserted
replaced
2976:e0c6de3a9803 | 2977:5161e25392ea |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | |
2 | |
3 import java.util.Date; | |
4 import java.util.HashMap; | |
5 import java.util.Map; | |
6 import java.util.Set; | |
7 | |
8 import com.google.gwt.core.client.GWT; | |
9 | |
10 import com.smartgwt.client.widgets.Canvas; | |
11 import com.smartgwt.client.widgets.Img; | |
12 import com.smartgwt.client.widgets.events.ResizedEvent; | |
13 import com.smartgwt.client.widgets.events.ResizedHandler; | |
14 import com.smartgwt.client.widgets.layout.HLayout; | |
15 import com.smartgwt.client.widgets.layout.VLayout; | |
16 | |
17 import de.intevation.flys.client.client.Config; | |
18 import de.intevation.flys.client.client.ui.CollectionView; | |
19 import de.intevation.flys.client.client.ui.OutputTab; | |
20 | |
21 import de.intevation.flys.client.shared.model.Collection; | |
22 import de.intevation.flys.client.shared.model.OutputMode; | |
23 | |
24 | |
25 /** | |
26 * An overview output tab. This tab displays an overview of all charts | |
27 * integrated in the current calculation mode. | |
28 * | |
29 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
30 */ | |
31 public class OverviewOutputTab | |
32 extends OutputTab | |
33 implements ResizedHandler | |
34 { | |
35 /** The collection view.*/ | |
36 protected CollectionView view; | |
37 | |
38 /** The root layout. */ | |
39 protected HLayout root; | |
40 | |
41 /** The columns */ | |
42 protected VLayout[] columns; | |
43 | |
44 /** The chart container.*/ | |
45 protected Canvas[][] charts; | |
46 | |
47 /** All relevant output modes. */ | |
48 protected Map<String, OutputMode> relModes; | |
49 | |
50 | |
51 public OverviewOutputTab( | |
52 String title, | |
53 Collection collection, | |
54 OutputMode mode, | |
55 CollectionView collectionView) | |
56 { | |
57 super(title, collection, collectionView, mode); | |
58 | |
59 relModes = new HashMap<String, OutputMode>(); | |
60 | |
61 Map<String, OutputMode> modes = collection.getOutputModes(); | |
62 Set<String> keys = modes.keySet(); | |
63 | |
64 // Get all relevant outputs. | |
65 for (String key: keys) { | |
66 OutputMode m = modes.get(key); | |
67 if (m.getType().equals("chart")) { | |
68 relModes.put(key, m); | |
69 } | |
70 } | |
71 | |
72 root = new HLayout(); | |
73 setPane(root); | |
74 root.addResizedHandler(this); | |
75 | |
76 // Get the column and row count and initialize the grid. | |
77 int width = getColumnCount(relModes.size()); | |
78 int height = getRowCount(relModes.size()); | |
79 charts = new Canvas[width][height]; | |
80 columns = new VLayout[width]; | |
81 | |
82 for (int i = 0; i < width; i++) { | |
83 columns[i] = new VLayout(); | |
84 root.addMember(columns[i]); | |
85 | |
86 for (int j = 0; j < height; j++) { | |
87 charts[i][j] = new Canvas(); | |
88 | |
89 // This is for 3, 6 or 9 charts only! | |
90 // TODO: Calculate the height. | |
91 charts[i][j].setHeight("30%"); | |
92 | |
93 String type = | |
94 ((OutputMode)relModes.values() | |
95 .toArray()[j + i * height]).getName(); | |
96 columns[i].addMember(charts[i][j]); | |
97 charts[i][j].addChild( | |
98 new Img(getImgUrl( | |
99 charts[i][j].getWidth(), | |
100 charts[i][j].getHeight(), type))); | |
101 | |
102 } | |
103 } | |
104 } | |
105 | |
106 | |
107 /** | |
108 * Resize handler. | |
109 * | |
110 * @param event The resize event. | |
111 */ | |
112 @Override | |
113 public void onResized(ResizedEvent event) { | |
114 for (int i = 0; i < charts.length; i++) { | |
115 columns[i].setWidth(root.getWidth()/2); | |
116 for (int j = 0; j < charts[i].length; j++) { | |
117 String type = | |
118 ((OutputMode)relModes.values() | |
119 .toArray()[j + i * charts[i].length]).getName(); | |
120 Canvas[] children = charts[i][j].getChildren(); | |
121 for (int k = 0; k < children.length; k++) { | |
122 charts[i][j].removeChild(children[k]); | |
123 } | |
124 charts[i][j].addChild(new Img( | |
125 getImgUrl( | |
126 charts[i][j].getWidth(), | |
127 charts[i][j].getHeight(), | |
128 type), | |
129 charts[i][j].getWidth(), | |
130 charts[i][j].getHeight() | |
131 )); | |
132 } | |
133 } | |
134 } | |
135 | |
136 | |
137 /** | |
138 * Returns the column count for the grid. | |
139 * | |
140 * @param count all fields | |
141 * @return the column count | |
142 */ | |
143 protected int getColumnCount(int count) { | |
144 if (count <= 3) { | |
145 return 1; | |
146 } | |
147 else if (count > 3 && count < 9) { | |
148 return 2; | |
149 } | |
150 else { | |
151 return 3; | |
152 } | |
153 } | |
154 | |
155 | |
156 /** | |
157 * Returns the row count for the grid. | |
158 * | |
159 * @param count all fields | |
160 * @return the row count | |
161 */ | |
162 protected int getRowCount(int count) { | |
163 if(count <= 3) { | |
164 return count; | |
165 } | |
166 else if(count > 3 && count < 9) { | |
167 return ((count + (count % 2))/getColumnCount(count)); | |
168 } | |
169 else { | |
170 return (count + (3 - (count % 3))/getColumnCount(count)); | |
171 } | |
172 } | |
173 | |
174 | |
175 /** | |
176 * Builds the URL that points to the chart image. | |
177 * | |
178 * @param width The width of the requested chart. | |
179 * @param height The height of the requested chart. | |
180 * @param xr Optional x range (used for zooming). | |
181 * @param yr Optional y range (used for zooming). | |
182 * | |
183 * @return the URL to the chart image. | |
184 */ | |
185 protected String getImgUrl(int width, int height, String type) { | |
186 Config config = Config.getInstance(); | |
187 | |
188 String imgUrl = GWT.getModuleBaseURL(); | |
189 imgUrl += "chart"; | |
190 imgUrl += "?uuid=" + collection.identifier(); | |
191 imgUrl += "&type=" + type; | |
192 imgUrl += "&locale=" + config.getLocale(); | |
193 imgUrl += "×tamp=" + new Date().getTime(); | |
194 imgUrl += "&width=" + Integer.toString(width); | |
195 imgUrl += "&height=" + Integer.toString(height); | |
196 | |
197 return imgUrl; | |
198 } | |
199 } | |
200 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |