teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5993: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5993: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.client.ui; bjoern@4202: bjoern@4202: import java.util.Iterator; bjoern@4202: bjoern@4202: import com.google.gwt.core.client.GWT; bjoern@4202: import com.google.gwt.i18n.client.NumberFormat; bjoern@4202: import com.google.gwt.user.client.ui.Anchor; bjoern@4202: import com.google.gwt.user.client.ui.HorizontalPanel; bjoern@4202: import com.google.gwt.user.client.ui.Label; bjoern@4202: import com.google.gwt.user.client.ui.Widget; bh@6193: import com.google.gwt.user.client.ui.HTML; bjoern@4202: bh@6192: import org.dive4elements.river.client.client.FLYS; teichmann@5835: import org.dive4elements.river.client.client.FLYSConstants; bjoern@4202: teichmann@5835: import org.dive4elements.river.client.shared.model.RiverInfo; bjoern@4202: bjoern@4202: /** felix@4980: * Panel to display information about a river. bjoern@4202: * @author Björn Ricks bjoern@4202: */ bjoern@4202: public class RiverInfoPanel extends HorizontalPanel { bjoern@4202: bh@6192: /** The flys instance */ bh@6192: protected FLYS flys; bh@6192: bjoern@4202: /** The message class that provides i18n strings.*/ bjoern@4202: protected FLYSConstants MSG = GWT.create(FLYSConstants.class); bjoern@4202: bjoern@4202: public final static int HEIGHT = 30; bjoern@4202: public final static int BORDER_WIDTH = 3; bjoern@4202: public final static int PADDING = 8; bjoern@4202: public final static int MARGIN = 10; bjoern@4202: bh@6192: public RiverInfoPanel(FLYS flys, RiverInfo riverinfo) { bh@6192: this.flys = flys; bh@6192: bjoern@4202: setStyleName("riverinfopanel"); bjoern@4202: setHeight("" + HEIGHT + "px"); bjoern@4202: setVerticalAlignment(ALIGN_MIDDLE); bjoern@4202: bjoern@4202: setRiverInfo(riverinfo); bjoern@4202: } bjoern@4202: bjoern@4202: public void setRiverInfo(RiverInfo riverinfo) { bjoern@4202: GWT.log("RiverInfoPanel - setRiverInfo"); bjoern@4202: bjoern@4202: NumberFormat nf = NumberFormat.getDecimalFormat(); bjoern@4202: bjoern@4202: removeAllLabels(); bjoern@4202: bjoern@4202: addLabel(riverinfo.getName(), false); bjoern@4202: bjoern@4202: String kmtext = ""; bjoern@4202: Double start = riverinfo.getKmStart(); bjoern@4202: Double end = riverinfo.getKmEnd(); bjoern@4202: bjoern@4202: if (!riverinfo.isKmUp()) { bjoern@4202: Double tmp = end; bjoern@4202: end = start; bjoern@4202: start = tmp; bjoern@4202: } bjoern@4202: if (end != null) { bjoern@4202: kmtext += nf.format(end); bjoern@4202: kmtext += " - "; bjoern@4202: } bjoern@4202: if (start != null) { bjoern@4202: kmtext += nf.format(start); bjoern@4202: } bjoern@4202: kmtext += " km"; bjoern@4202: bjoern@4202: addLabel(kmtext, false); bjoern@4202: bjoern@4202: String qtext = ""; bjoern@4202: Double qmin = riverinfo.getMinQ(); bjoern@4202: Double qmax = riverinfo.getMaxQ(); bjoern@4202: if (qmin != null) { bjoern@4202: qtext += nf.format(qmin); bjoern@4202: qtext += " " + MSG.gauge_q_unit(); bjoern@4202: qtext += " - "; bjoern@4202: } bjoern@4202: if (qmax != null) { bjoern@4202: qtext += nf.format(qmax); bjoern@4202: qtext += " " + MSG.gauge_q_unit(); bjoern@4202: } bjoern@4202: bjoern@4202: addLabel(qtext, false); bjoern@4202: bjoern@4202: Long number = riverinfo.getOfficialNumber(); bjoern@4202: String url = number != null ? bjoern@4202: MSG.gauge_river_url() + number : bjoern@4202: MSG.gauge_river_url(); bh@6193: add(new HTML(WikiLinks.linkHTML(this.flys, url, bh@6193: MSG.gauge_river_info_link()))); bjoern@4202: } bjoern@4202: bjoern@4202: public static int getStaticHeight() { bjoern@4202: return RiverInfoPanel.HEIGHT + bjoern@4202: (2 * RiverInfoPanel.BORDER_WIDTH) + bjoern@4202: (2 * RiverInfoPanel.PADDING) + bjoern@4202: (2 * RiverInfoPanel.MARGIN); bjoern@4202: } bjoern@4202: bjoern@4202: private void addLabel(String text, boolean wordwrap) { bjoern@4202: Label label = new Label(text, wordwrap); bjoern@4202: add(label); bjoern@4202: setCellHeight(label, "" + HEIGHT + "px"); bjoern@4202: } bjoern@4202: bjoern@4202: private void removeAllLabels() { bjoern@4202: GWT.log("RiverInfoPanel - removeAllLabels"); bjoern@4202: bjoern@4202: Iterator it = this.iterator(); bjoern@4202: while(it.hasNext()) { bjoern@4202: it.next(); bjoern@4202: it.remove(); bjoern@4202: } bjoern@4202: /* for (Widget wid: this) { */ bjoern@4202: /* this.remove(wid); */ bjoern@4202: /* } */ bjoern@4202: } bjoern@4202: }