comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ChartOutputTab.java @ 521:fc60822e9c89

Added a new package 'chart' that should be the place where chart relevant classes should be stored. Moved ChartOutputTab into that package. flys-client/trunk@2000 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 25 May 2011 08:03:02 +0000
parents
children 0785a8ba5e6d
comparison
equal deleted inserted replaced
520:9e2b151770bd 521:fc60822e9c89
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.types.Alignment;
8
9 import com.smartgwt.client.widgets.Canvas;
10 import com.smartgwt.client.widgets.Img;
11 import com.smartgwt.client.widgets.Label;
12
13 import com.smartgwt.client.widgets.layout.HLayout;
14 import com.smartgwt.client.widgets.layout.VLayout;
15
16 import com.smartgwt.client.widgets.events.ClickEvent;
17 import com.smartgwt.client.widgets.events.ClickHandler;
18 import com.smartgwt.client.widgets.events.CloseClickHandler;
19 import com.smartgwt.client.widgets.events.CloseClientEvent;
20 import com.smartgwt.client.widgets.events.ResizedEvent;
21 import com.smartgwt.client.widgets.events.ResizedHandler;
22
23 import de.intevation.flys.client.shared.model.Artifact;
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.Config;
27 import de.intevation.flys.client.client.ui.CollectionView;
28 import de.intevation.flys.client.client.ui.DatacageWindow;
29 import de.intevation.flys.client.client.ui.OutputTab;
30
31
32 /**
33 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
34 */
35 public class ChartOutputTab extends OutputTab implements ResizedHandler {
36
37 public static final int DEFAULT_CHART_WIDTH = 600;
38 public static final int DEFAULT_CHART_HEIGHT = 500;
39
40 /** The canvas that wraps the chart toolbar.*/
41 protected Canvas tbarPanel;
42
43 /** The canvas that wraps the theme editor.*/
44 protected Canvas left;
45
46 /** The canvas that wraps the chart.*/
47 protected Canvas right;
48
49
50 /**
51 * The default constructor to create a new ChartOutputTab.
52 *
53 * @param title The title of this tab.
54 * @param collection The Collection which this chart belongs to.
55 * @param mode The OutputMode.
56 */
57 public ChartOutputTab(
58 String title,
59 Collection collection,
60 OutputMode mode,
61 CollectionView collectionView
62 ){
63 super(title, collection, mode);
64
65 tbarPanel = new Canvas();
66 left = new Canvas();
67 right = new Canvas();
68
69 tbarPanel.setBorder("1px solid black");
70 tbarPanel.setHeight(30);
71 left.setBorder("1px solid black");
72 left.setWidth("25%");
73 right.setWidth("*");
74
75 VLayout vLayout = new VLayout();
76 vLayout.setMembersMargin(2);
77
78 HLayout hLayout = new HLayout();
79 hLayout.setWidth100();
80 hLayout.setHeight100();
81 hLayout.setMembersMargin(10);
82
83 hLayout.addMember(left);
84 hLayout.addMember(right);
85
86 right.addChild(createChartPanel());
87 left.addChild(createThemeControlPanel());
88 tbarPanel.addChild(
89 createTBarPanel(collectionView));
90
91 vLayout.addMember(tbarPanel);
92 vLayout.addMember(hLayout);
93
94 setPane(vLayout);
95
96 right.addResizedHandler(this);
97 }
98
99
100 /**
101 * This method is called after the chart panel has resized. It removes the
102 * chart - if existing - and requests a new one with adjusted size.
103 *
104 * @param event The resize event.
105 */
106 public void onResized(ResizedEvent event) {
107 Canvas[] children = right.getChildren();
108 for (Canvas child: children) {
109 right.removeChild(child);
110 }
111
112 right.addChild(createChartPanel(right.getWidth(), right.getHeight()));
113 }
114
115
116 protected Canvas createTBarPanel(
117 final CollectionView collectionView
118 ) {
119 HLayout hLayout = new HLayout();
120 hLayout.setWidth100();
121 hLayout.setHeight100();
122 hLayout.setMembersMargin(10);
123
124 Label datacage = new Label("Datenkorb");
125 datacage.setHeight(20);
126 datacage.setBackgroundColor("#BED730");
127 datacage.setBorder("1px solid black");
128 datacage.setAlign(Alignment.CENTER);
129
130 hLayout.setMargin(5);
131 hLayout.addMember(datacage);
132 datacage.addClickHandler(new ClickHandler() {
133 public void onClick(ClickEvent event) {
134 GWT.log("Clicked 'datacage' button.");
135 openDatacageWindow(
136 collectionView.getArtifact());
137 }
138 });
139
140 return hLayout;
141 }
142
143 protected void openDatacageWindow(Artifact artifact) {
144 final DatacageWindow dc = new DatacageWindow(artifact);
145 dc.addCloseClickHandler(new CloseClickHandler() {
146 public void onCloseClick(CloseClientEvent event) {
147 dc.destroy();
148 }
149 });
150 dc.show();
151 }
152
153
154 protected Canvas createChartPanel() {
155 return createChartPanel(DEFAULT_CHART_WIDTH, DEFAULT_CHART_HEIGHT);
156 }
157
158
159 protected Canvas createChartPanel(int width, int height) {
160 Img chart = getChartImg(width, height);
161 chart.setWidth100();
162 chart.setHeight100();
163
164 return chart;
165
166 }
167
168
169 protected Canvas createThemeControlPanel() {
170 Label label = new Label("Themensteuerung");
171 label.setHeight(25);
172 label.setMargin(5);
173
174 return label;
175 }
176
177
178 /**
179 * Builds the chart image and returns it.
180 *
181 * @param width The chart width.
182 * @param height The chart height.
183 *
184 * @return the chart image.
185 */
186 protected Img getChartImg(int width, int height) {
187 return new Img(getImgUrl(width, height));
188 }
189
190
191 /**
192 * Builds the URL that points to the chart image.
193 *
194 * @param width The width of the requested chart.
195 * @param height The height of the requested chart.
196 *
197 * @return the URL to the chart image.
198 */
199 protected String getImgUrl(int width, int height) {
200 Config config = Config.getInstance();
201
202 String imgUrl = GWT.getModuleBaseURL();
203 imgUrl += "chart";
204 imgUrl += "?uuid=" + collection.identifier();
205 imgUrl += "&type=" + mode.getName();
206 imgUrl += "&server=" + config.getServerUrl();
207 imgUrl += "&locale=" + config.getLocale();
208 imgUrl += "&timestamp=" + new Date().getTime();
209 imgUrl += "&width=" + Integer.toString(width);
210 imgUrl += "&height=" + Integer.toString(height);
211
212 return imgUrl;
213 }
214 }
215 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org