comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/RiverInfoPanel.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/client/ui/RiverInfoPanel.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.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 org.dive4elements.river.client.client.FLYSConstants;
13
14 import org.dive4elements.river.client.shared.model.RiverInfo;
15
16 /**
17 * Panel to display information about a river.
18 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
19 */
20 public class RiverInfoPanel extends HorizontalPanel {
21
22 /** The message class that provides i18n strings.*/
23 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
24
25 public final static int HEIGHT = 30;
26 public final static int BORDER_WIDTH = 3;
27 public final static int PADDING = 8;
28 public final static int MARGIN = 10;
29
30 public RiverInfoPanel(RiverInfo riverinfo) {
31 setStyleName("riverinfopanel");
32 setHeight("" + HEIGHT + "px");
33 setVerticalAlignment(ALIGN_MIDDLE);
34
35 setRiverInfo(riverinfo);
36 }
37
38 public void setRiverInfo(RiverInfo riverinfo) {
39 GWT.log("RiverInfoPanel - setRiverInfo");
40
41 NumberFormat nf = NumberFormat.getDecimalFormat();
42
43 removeAllLabels();
44
45 addLabel(riverinfo.getName(), false);
46
47 String kmtext = "";
48 Double start = riverinfo.getKmStart();
49 Double end = riverinfo.getKmEnd();
50
51 if (!riverinfo.isKmUp()) {
52 Double tmp = end;
53 end = start;
54 start = tmp;
55 }
56 if (end != null) {
57 kmtext += nf.format(end);
58 kmtext += " - ";
59 }
60 if (start != null) {
61 kmtext += nf.format(start);
62 }
63 kmtext += " km";
64
65 addLabel(kmtext, false);
66
67 String qtext = "";
68 Double qmin = riverinfo.getMinQ();
69 Double qmax = riverinfo.getMaxQ();
70 if (qmin != null) {
71 qtext += nf.format(qmin);
72 qtext += " " + MSG.gauge_q_unit();
73 qtext += " - ";
74 }
75 if (qmax != null) {
76 qtext += nf.format(qmax);
77 qtext += " " + MSG.gauge_q_unit();
78 }
79
80 addLabel(qtext, false);
81
82 Long number = riverinfo.getOfficialNumber();
83 String url = number != null ?
84 MSG.gauge_river_url() + number :
85 MSG.gauge_river_url();
86 Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank");
87 add(anchor);
88 }
89
90 public static int getStaticHeight() {
91 return RiverInfoPanel.HEIGHT +
92 (2 * RiverInfoPanel.BORDER_WIDTH) +
93 (2 * RiverInfoPanel.PADDING) +
94 (2 * RiverInfoPanel.MARGIN);
95 }
96
97 private void addLabel(String text, boolean wordwrap) {
98 Label label = new Label(text, wordwrap);
99 add(label);
100 setCellHeight(label, "" + HEIGHT + "px");
101 }
102
103 private void removeAllLabels() {
104 GWT.log("RiverInfoPanel - removeAllLabels");
105
106 Iterator<Widget> it = this.iterator();
107 while(it.hasNext()) {
108 it.next();
109 it.remove();
110 }
111 /* for (Widget wid: this) { */
112 /* this.remove(wid); */
113 /* } */
114 }
115 }

http://dive4elements.wald.intevation.org