comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/RiverInfoPanel.java @ 4202:1fa244f70ad5

Move RiverInfoPanel to its own java file in refactor it Allow to change the riverinfo without having to create a new instace of the RiverInfoPanel.
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 22 Oct 2012 15:23:00 +0200
parents
children e70ff0a600a3
comparison
equal deleted inserted replaced
4201:221d255f7ec2 4202:1fa244f70ad5
1 package de.intevation.flys.client.client.ui;
2
3 import java.util.Iterator;
4
5 import com.google.gwt.core.client.GWT;
6 import com.google.gwt.i18n.client.NumberFormat;
7 import com.google.gwt.user.client.ui.Anchor;
8 import com.google.gwt.user.client.ui.HorizontalPanel;
9 import com.google.gwt.user.client.ui.Label;
10 import com.google.gwt.user.client.ui.Widget;
11
12 import de.intevation.flys.client.client.FLYSConstants;
13
14 import de.intevation.flys.client.shared.model.RiverInfo;
15
16 /**
17 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
18 */
19 public class RiverInfoPanel extends HorizontalPanel {
20
21 /**
22 * Panel to display information about a river
23 */
24
25 /** The message class that provides i18n strings.*/
26 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
27
28 public final static int HEIGHT = 30;
29 public final static int BORDER_WIDTH = 3;
30 public final static int PADDING = 8;
31 public final static int MARGIN = 10;
32
33 public RiverInfoPanel(RiverInfo riverinfo) {
34 setStyleName("riverinfopanel");
35 setHeight("" + HEIGHT + "px");
36 setVerticalAlignment(ALIGN_MIDDLE);
37
38 setRiverInfo(riverinfo);
39 }
40
41 public void setRiverInfo(RiverInfo riverinfo) {
42 GWT.log("RiverInfoPanel - setRiverInfo");
43
44 NumberFormat nf = NumberFormat.getDecimalFormat();
45
46 removeAllLabels();
47
48 addLabel(riverinfo.getName(), false);
49
50 String kmtext = "";
51 Double start = riverinfo.getKmStart();
52 Double end = riverinfo.getKmEnd();
53
54 if (!riverinfo.isKmUp()) {
55 Double tmp = end;
56 end = start;
57 start = tmp;
58 }
59 if (end != null) {
60 kmtext += nf.format(end);
61 kmtext += " - ";
62 }
63 if (start != null) {
64 kmtext += nf.format(start);
65 }
66 kmtext += " km";
67
68 addLabel(kmtext, false);
69
70 String qtext = "";
71 Double qmin = riverinfo.getMinQ();
72 Double qmax = riverinfo.getMaxQ();
73 if (qmin != null) {
74 qtext += nf.format(qmin);
75 qtext += " " + MSG.gauge_q_unit();
76 qtext += " - ";
77 }
78 if (qmax != null) {
79 qtext += nf.format(qmax);
80 qtext += " " + MSG.gauge_q_unit();
81 }
82
83 addLabel(qtext, false);
84
85 Long number = riverinfo.getOfficialNumber();
86 String url = number != null ?
87 MSG.gauge_river_url() + number :
88 MSG.gauge_river_url();
89 Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank");
90 add(anchor);
91 }
92
93 public static int getStaticHeight() {
94 return RiverInfoPanel.HEIGHT +
95 (2 * RiverInfoPanel.BORDER_WIDTH) +
96 (2 * RiverInfoPanel.PADDING) +
97 (2 * RiverInfoPanel.MARGIN);
98 }
99
100 private void addLabel(String text, boolean wordwrap) {
101 Label label = new Label(text, wordwrap);
102 add(label);
103 setCellHeight(label, "" + HEIGHT + "px");
104 }
105
106 private void removeAllLabels() {
107 GWT.log("RiverInfoPanel - removeAllLabels");
108
109 Iterator<Widget> it = this.iterator();
110 while(it.hasNext()) {
111 it.next();
112 it.remove();
113 }
114 /* for (Widget wid: this) { */
115 /* this.remove(wid); */
116 /* } */
117 }
118 }

http://dive4elements.wald.intevation.org