Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/OverviewOutputTab.java @ 3370:08b2472111aa
New implementation of OverviewOutputTab which has a minimalistic chart toolbar and no chart theme panel. The overview image is fetched as single image from server.
flys-client/trunk@5078 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 20 Jul 2012 07:40:55 +0000 |
parents | e746e57c65c0 |
children | 27e455487d66 |
comparison
equal
deleted
inserted
replaced
3369:20688790f0c0 | 3370:08b2472111aa |
---|---|
1 package de.intevation.flys.client.client.ui.chart; | 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 | 2 |
8 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
9 | 4 |
10 import com.smartgwt.client.widgets.Canvas; | 5 import de.intevation.flys.client.client.event.OutputParameterChangeHandler; |
11 import com.smartgwt.client.widgets.Img; | 6 import de.intevation.flys.client.client.event.RedrawRequestHandler; |
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; | 7 import de.intevation.flys.client.client.ui.CollectionView; |
19 import de.intevation.flys.client.client.ui.OutputTab; | 8 import de.intevation.flys.client.client.ui.ImgLink; |
20 | |
21 import de.intevation.flys.client.shared.model.Collection; | 9 import de.intevation.flys.client.shared.model.Collection; |
22 import de.intevation.flys.client.shared.model.OutputMode; | 10 import de.intevation.flys.client.shared.model.OutputMode; |
11 import de.intevation.flys.client.shared.model.Theme; | |
23 | 12 |
24 | 13 |
25 /** | 14 public class OverviewOutputTab extends ChartOutputTab { |
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 | 15 |
38 /** The root layout. */ | 16 private class NoChartThemePanel extends ChartThemePanel { |
39 protected HLayout root; | |
40 | 17 |
41 /** The columns */ | 18 public NoChartThemePanel(OutputMode mode, CollectionView view) { |
42 protected VLayout[] columns; | 19 super(mode, view); |
20 } | |
43 | 21 |
44 /** The chart container.*/ | 22 @Override |
45 protected Canvas[][] charts; | 23 public void activateTheme(Theme theme, boolean active) { } |
46 | 24 |
47 /** All relevant output modes. */ | 25 @Override |
48 protected Map<String, OutputMode> relModes; | 26 public void feedTellArea( |
27 final String artifact, | |
28 Theme under, | |
29 Theme over, | |
30 boolean between | |
31 ) { } | |
32 | |
33 @Override | |
34 public void createAreaArtifact( | |
35 final Theme over, | |
36 final Theme under, | |
37 final boolean between | |
38 ) { } | |
39 | |
40 @Override | |
41 public void addOutputParameterChangeHandler(OutputParameterChangeHandler h) { } | |
42 | |
43 @Override | |
44 public void addRedrawRequestHandler(RedrawRequestHandler h){ } | |
45 } | |
49 | 46 |
50 | 47 |
51 public OverviewOutputTab( | |
52 String title, | |
53 Collection collection, | |
54 OutputMode mode, | |
55 CollectionView collectionView) | |
56 { | |
57 super(title, collection, collectionView, mode); | |
58 | 48 |
59 relModes = new HashMap<String, OutputMode>(); | 49 private class MinimumChartToolbar extends ChartToolbar { |
60 | 50 |
61 Map<String, OutputMode> modes = collection.getOutputModes(); | 51 public MinimumChartToolbar(ChartOutputTab tab) { |
62 Set<String> keys = modes.keySet(); | 52 super(tab); |
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 } | 53 } |
71 | 54 |
72 root = new HLayout(); | 55 @Override |
73 setPane(root); | 56 protected void initTools() { |
74 root.addResizedHandler(this); | 57 GWT.log("CREATE NEW MINIMALISTIC CHART TOOLBAR"); |
58 ChartOutputTab chartTab = getChartOutputTab(); | |
75 | 59 |
76 // Get the column and row count and initialize the grid. | 60 String baseUrl = GWT.getHostPageBaseURL(); |
77 int width = getColumnCount(relModes.size()); | |
78 int height = getRowCount(relModes.size()); | |
79 charts = new Canvas[width][height]; | |
80 columns = new VLayout[width]; | |
81 | 61 |
82 for (int i = 0; i < width; i++) { | 62 downloadPNG = new ImgLink( |
83 columns[i] = new VLayout(); | 63 baseUrl + MSG.downloadPNG(), |
84 root.addMember(columns[i]); | 64 chartTab.getExportUrl(-1, -1, "png"), |
65 20, | |
66 20); | |
67 downloadPNG.setTooltip(MSG.downloadPNGTooltip()); | |
85 | 68 |
86 for (int j = 0; j < height; j++) { | 69 downloadPDF = new ImgLink( |
87 charts[i][j] = new Canvas(); | 70 baseUrl + MSG.downloadPDF(), |
71 chartTab.getExportUrl(1280, 1024, "pdf"), | |
72 20, | |
73 20); | |
74 downloadPDF.setTooltip(MSG.downloadPDFTooltip()); | |
88 | 75 |
89 // This is for 3, 6 or 9 charts only! | 76 downloadSVG = new ImgLink( |
90 // TODO: Calculate the height. | 77 baseUrl + MSG.downloadSVG(), |
91 charts[i][j].setHeight("50%"); | 78 chartTab.getExportUrl(1280, 1024, "svg"), |
79 20, | |
80 20); | |
81 downloadSVG.setTooltip(MSG.downloadSVGTooltip()); | |
92 | 82 |
93 String type = | 83 initLayout(); |
94 ((OutputMode)relModes.values() | 84 } |
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 | 85 |
102 } | 86 |
87 @Override | |
88 protected void initLayout() { | |
89 setWidth100(); | |
90 setHeight(PANEL_HEIGHT); | |
91 setMembersMargin(10); | |
92 setPadding(5); | |
93 setBorder("1px solid black"); | |
94 | |
95 addMember(downloadPNG); | |
96 addMember(downloadPDF); | |
97 addMember(downloadSVG); | |
103 } | 98 } |
104 } | 99 } |
105 | 100 |
106 | 101 |
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 // This is for 3, 6 or 9 charts only! | |
116 // TODO: Calculate the width. | |
117 columns[i].setWidth(root.getWidth()/3); | |
118 | 102 |
119 for (int j = 0; j < charts[i].length; j++) { | 103 public OverviewOutputTab( |
120 String type = | 104 String title, |
121 ((OutputMode)relModes.values() | 105 Collection collection, |
122 .toArray()[j + i * charts[i].length]).getName(); | 106 OutputMode mode, |
123 Canvas[] children = charts[i][j].getChildren(); | 107 CollectionView collectionView |
124 for (int k = 0; k < children.length; k++) { | 108 ){ |
125 charts[i][j].removeChild(children[k]); | 109 super(title, collection, mode, collectionView); |
126 } | 110 left.setVisible(false); |
127 charts[i][j].addChild(new Img( | |
128 getImgUrl( | |
129 charts[i][j].getWidth(), | |
130 charts[i][j].getHeight(), | |
131 type), | |
132 charts[i][j].getWidth(), | |
133 charts[i][j].getHeight() | |
134 )); | |
135 } | |
136 } | |
137 } | 111 } |
138 | 112 |
139 | 113 |
140 /** | 114 @Override |
141 * Returns the column count for the grid. | 115 public ChartThemePanel createThemePanel( |
142 * | 116 OutputMode mode, CollectionView view |
143 * @param count all fields | 117 ) { |
144 * @return the column count | 118 return new NoChartThemePanel(mode, view); |
145 */ | |
146 protected int getRowCount(int count) { | |
147 if (count <= 3) { | |
148 return 1; | |
149 } | |
150 else if (count > 3 && count < 9) { | |
151 return 2; | |
152 } | |
153 else { | |
154 return 3; | |
155 } | |
156 } | 119 } |
157 | 120 |
158 | 121 @Override |
159 /** | 122 public ChartToolbar createChartToolbar(ChartOutputTab tab) { |
160 * Returns the row count for the grid. | 123 return new MinimumChartToolbar(tab); |
161 * | |
162 * @param count all fields | |
163 * @return the row count | |
164 */ | |
165 protected int getColumnCount(int count) { | |
166 if(count <= 3) { | |
167 return count; | |
168 } | |
169 else if(count > 3 && count < 9) { | |
170 return ((count + (count % 2))/getRowCount(count)); | |
171 } | |
172 else { | |
173 return (count + (3 - (count % 3))/getRowCount(count)); | |
174 } | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Builds the URL that points to the chart image. | |
180 * | |
181 * @param width The width of the requested chart. | |
182 * @param height The height of the requested chart. | |
183 * @param xr Optional x range (used for zooming). | |
184 * @param yr Optional y range (used for zooming). | |
185 * | |
186 * @return the URL to the chart image. | |
187 */ | |
188 protected String getImgUrl(int width, int height, String type) { | |
189 Config config = Config.getInstance(); | |
190 | |
191 String imgUrl = GWT.getModuleBaseURL(); | |
192 imgUrl += "chart"; | |
193 imgUrl += "?uuid=" + collection.identifier(); | |
194 imgUrl += "&type=" + type; | |
195 imgUrl += "&locale=" + config.getLocale(); | |
196 imgUrl += "×tamp=" + new Date().getTime(); | |
197 imgUrl += "&width=" + Integer.toString(width); | |
198 imgUrl += "&height=" + Integer.toString(height); | |
199 | |
200 return imgUrl; | |
201 } | 124 } |
202 } | 125 } |
203 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |