bjoern@4202: package de.intevation.flys.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;
bjoern@4202:
bjoern@4202: import de.intevation.flys.client.client.FLYSConstants;
bjoern@4202:
bjoern@4202: import de.intevation.flys.client.shared.model.RiverInfo;
bjoern@4202:
bjoern@4202: /**
bjoern@4202: * @author Björn Ricks
bjoern@4202: */
bjoern@4202: public class RiverInfoPanel extends HorizontalPanel {
bjoern@4202:
bjoern@4202: /**
bjoern@4202: * Panel to display information about a river
bjoern@4202: */
bjoern@4202:
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:
bjoern@4202: public RiverInfoPanel(RiverInfo riverinfo) {
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();
bjoern@4202: Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url, "_blank");
bjoern@4202: add(anchor);
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: }