Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/RiverInfoPanel.java Thu Apr 25 15:23:37 2013 +0200 @@ -0,0 +1,115 @@ +package org.dive4elements.river.client.client.ui; + +import java.util.Iterator; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; +import com.google.gwt.user.client.ui.Anchor; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.Widget; + +import org.dive4elements.river.client.client.FLYSConstants; + +import org.dive4elements.river.client.shared.model.RiverInfo; + +/** + * Panel to display information about a river. + * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a> + */ +public class RiverInfoPanel extends HorizontalPanel { + + /** The message class that provides i18n strings.*/ + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); + + public final static int HEIGHT = 30; + public final static int BORDER_WIDTH = 3; + public final static int PADDING = 8; + public final static int MARGIN = 10; + + public RiverInfoPanel(RiverInfo riverinfo) { + setStyleName("riverinfopanel"); + setHeight("" + HEIGHT + "px"); + setVerticalAlignment(ALIGN_MIDDLE); + + setRiverInfo(riverinfo); + } + + public void setRiverInfo(RiverInfo riverinfo) { + GWT.log("RiverInfoPanel - setRiverInfo"); + + NumberFormat nf = NumberFormat.getDecimalFormat(); + + removeAllLabels(); + + addLabel(riverinfo.getName(), false); + + String kmtext = ""; + Double start = riverinfo.getKmStart(); + Double end = riverinfo.getKmEnd(); + + if (!riverinfo.isKmUp()) { + Double tmp = end; + end = start; + start = tmp; + } + if (end != null) { + kmtext += nf.format(end); + kmtext += " - "; + } + if (start != null) { + kmtext += nf.format(start); + } + kmtext += " km"; + + addLabel(kmtext, false); + + String qtext = ""; + Double qmin = riverinfo.getMinQ(); + Double qmax = riverinfo.getMaxQ(); + if (qmin != null) { + qtext += nf.format(qmin); + qtext += " " + MSG.gauge_q_unit(); + qtext += " - "; + } + if (qmax != null) { + qtext += nf.format(qmax); + qtext += " " + MSG.gauge_q_unit(); + } + + addLabel(qtext, false); + + Long number = riverinfo.getOfficialNumber(); + String url = number != null ? + MSG.gauge_river_url() + number : + MSG.gauge_river_url(); + Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank"); + add(anchor); + } + + public static int getStaticHeight() { + return RiverInfoPanel.HEIGHT + + (2 * RiverInfoPanel.BORDER_WIDTH) + + (2 * RiverInfoPanel.PADDING) + + (2 * RiverInfoPanel.MARGIN); + } + + private void addLabel(String text, boolean wordwrap) { + Label label = new Label(text, wordwrap); + add(label); + setCellHeight(label, "" + HEIGHT + "px"); + } + + private void removeAllLabels() { + GWT.log("RiverInfoPanel - removeAllLabels"); + + Iterator<Widget> it = this.iterator(); + while(it.hasNext()) { + it.next(); + it.remove(); + } + /* for (Widget wid: this) { */ + /* this.remove(wid); */ + /* } */ + } +}