bjoern@3715: package de.intevation.flys.client.client.ui;
bjoern@3715:
bjoern@3715: import com.google.gwt.core.client.GWT;
bjoern@3828: import com.google.gwt.i18n.client.NumberFormat;
bjoern@3715: import com.google.gwt.user.client.rpc.AsyncCallback;
bjoern@3839: import com.google.gwt.user.client.ui.Anchor;
bjoern@3828: import com.google.gwt.user.client.ui.HorizontalPanel;
bjoern@3828: import com.google.gwt.user.client.ui.Label;
bjoern@3715:
bjoern@3715: import com.smartgwt.client.types.Overflow;
bjoern@3828: import com.smartgwt.client.widgets.events.ResizedEvent;
bjoern@3828: import com.smartgwt.client.widgets.events.ResizedHandler;
bjoern@3715: import com.smartgwt.client.widgets.layout.SectionStackSection;
bjoern@3715: import com.smartgwt.client.widgets.layout.VLayout;
bjoern@3715:
bjoern@3865: import de.intevation.flys.client.client.FLYS;
bjoern@3715: import de.intevation.flys.client.client.FLYSConstants;
bjoern@3715: import de.intevation.flys.client.client.services.GaugeOverviewInfoService;
bjoern@3715: import de.intevation.flys.client.client.services.GaugeOverviewInfoServiceAsync;
bjoern@3837: import de.intevation.flys.client.shared.model.DataList;
bjoern@3715: import de.intevation.flys.client.shared.model.RiverInfo;
bjoern@3715:
bjoern@3715: /**
bjoern@3715: * The GaugePanel is intendet to be used within a SectionStackSection
bjoern@3715: * It extends the VLayout by two methods to show and hide the
bjoern@3715: * section stack section.
bjoern@3842: *
bjoern@3842: * @author Björn Ricks
bjoern@3715: */
bjoern@3825: public class GaugePanel extends VLayout implements ResizedHandler {
bjoern@3715:
bjoern@3715: /** SectionStackSection where this GaugePanel belongs in*/
bjoern@3715: private SectionStackSection sectionStack;
bjoern@3715:
bjoern@3715: /** Name of the river */
bjoern@3715: private String river;
bjoern@3715:
bjoern@3715: /** The message class that provides i18n strings.*/
bjoern@3715: protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
bjoern@3715:
bjoern@3865: private FLYS flys;
bjoern@3865:
bjoern@3715: protected GaugeOverviewInfoServiceAsync gaugeOverviewInfoService =
bjoern@3715: GWT.create(GaugeOverviewInfoService.class);
bjoern@3715:
bjoern@3865: protected GaugeTree gaugetree;
bjoern@3825:
bjoern@3825: protected RiverInfoPanel riverinfopanel;
bjoern@3825:
bjoern@3715: /**
bjoern@3715: * Creates a new VLayout with a SectionStackSection
bjoern@3715: * The GaugePanel's SectionStackSection is hidden by default.
bjoern@3865: *
bjoern@3865: * @param flys The FLYS object
bjoern@3715: * @param sectionStack The section stack section to place the VLayout in.
bjoern@3715: */
bjoern@3865: public GaugePanel(FLYS flys, SectionStackSection sectionStack) {
bjoern@3865: gaugetree = new GaugeTree(flys);
bjoern@3825: setOverflow(Overflow.HIDDEN);
bjoern@3828: sectionStack.setHidden(true);
bjoern@3715: sectionStack.setItems(this);
bjoern@3715: this.sectionStack = sectionStack;
bjoern@3825: setStyleName("gaugepanel");
bjoern@3825: addResizedHandler(this);
bjoern@3715: }
bjoern@3715:
bjoern@3828: /**
bjoern@3828: * Sets and loads the river data if river is not the current set river
bjoern@3828: */
bjoern@3715: public void setRiver(String river) {
bjoern@3828: if (!river.equals(this.river)) {
bjoern@3828: this.river = river;
bjoern@3828: this.refresh();
bjoern@3828: }
bjoern@3715: }
bjoern@3715:
bjoern@3715: /**
bjoern@3837: * Sets the data and closes not corresponding folds in the gauge tree
bjoern@3837: */
bjoern@3837: public void setData(DataList[] data) {
bjoern@3837: gaugetree.setData(data);
bjoern@3837: }
bjoern@3837:
bjoern@3837: /**
bjoern@3715: * Loads the river info and renders it afterwards
bjoern@3715: */
bjoern@3715: public void refresh() {
bjoern@3715: gaugeOverviewInfoService.getRiverInfo(this.river, new AsyncCallback() {
bjoern@3715: public void onFailure(Throwable e) {
bjoern@3715: GWT.log("Could not load the river info." + e);
bjoern@3715: }
bjoern@3715:
bjoern@3715: public void onSuccess(RiverInfo riverinfo) {
bjoern@3715: GWT.log("Loaded river info");
bjoern@3715: renderGaugeOverviewInfo(riverinfo);
bjoern@3715: }
bjoern@3715: });
bjoern@3715: }
bjoern@3715:
bjoern@3715: public void renderGaugeOverviewInfo(RiverInfo riverinfo) {
bjoern@3825: removeMembers(getMembers());
bjoern@3715:
bjoern@3825: riverinfopanel = new RiverInfoPanel(riverinfo);
bjoern@3825: addMember(riverinfopanel);
bjoern@3825: addMember(gaugetree);
bjoern@3715:
bjoern@3828: gaugetree.setGauges(riverinfo);
bjoern@3825: }
bjoern@3715:
bjoern@3825: @Override
bjoern@3825: public void onResized(ResizedEvent event) {
bjoern@3825: /* this height calculation is only an approximation and doesn't reflect
bjoern@3825: * the real height of the the gaugetree. */
bjoern@3825: int height = getInnerContentHeight() -
bjoern@3825: (RiverInfoPanel.HEIGHT +
bjoern@3825: (2 * RiverInfoPanel.BORDER_WIDTH) +
bjoern@3825: (2 * RiverInfoPanel.PADDING) +
bjoern@3825: (2 * RiverInfoPanel.MARGIN));
bjoern@3825:
bjoern@3825: if (height < 0) {
bjoern@3825: height = 0;
bjoern@3715: }
bjoern@3825:
bjoern@3825: gaugetree.setHeight("" + height + "px");
bjoern@3715: }
bjoern@3715:
bjoern@3825:
bjoern@3715: /**
bjoern@3715: * Hide the section stack section.
bjoern@3715: */
bjoern@3715: public void hide() {
bjoern@3715: GWT.log("GaugePanel - hide");
bjoern@3715: this.sectionStack.setHidden(true);
bjoern@3715: }
bjoern@3715:
bjoern@3715: /**
bjoern@3715: * Show the section stack section.
bjoern@3715: */
bjoern@3715: public void show() {
bjoern@3715: GWT.log("GaugePanel - show");
bjoern@3715: this.sectionStack.setHidden(false);
bjoern@3715: }
bjoern@3715:
bjoern@3825: class RiverInfoPanel extends HorizontalPanel {
bjoern@3825:
bjoern@3825: public final static int HEIGHT = 30;
bjoern@3825: public final static int BORDER_WIDTH = 3;
bjoern@3825: public final static int PADDING = 8;
bjoern@3825: public final static int MARGIN = 10;
bjoern@3715:
bjoern@3715: public RiverInfoPanel(RiverInfo riverinfo) {
bjoern@3825: setStyleName("riverinfopanel");
bjoern@3825: setHeight("" + HEIGHT + "px");
bjoern@3825: setVerticalAlignment(ALIGN_MIDDLE);
bjoern@3715:
bjoern@3828: NumberFormat nf = NumberFormat.getDecimalFormat();
bjoern@3828:
bjoern@3825: addLabel(riverinfo.getName(), false);
bjoern@3715:
bjoern@3715: String kmtext = "";
bjoern@3715: Double start = riverinfo.getKmStart();
bjoern@3715: Double end = riverinfo.getKmEnd();
bjoern@3715:
bjoern@3715: if (!riverinfo.isKmUp()) {
bjoern@3715: Double tmp = end;
bjoern@3715: end = start;
bjoern@3715: start = tmp;
bjoern@3715: }
bjoern@3715: if (end != null) {
bjoern@3828: kmtext += nf.format(end);
bjoern@3715: kmtext += " - ";
bjoern@3715: }
bjoern@3715: if (start != null) {
bjoern@3828: kmtext += nf.format(start);
bjoern@3715: }
bjoern@3715: kmtext += " km";
bjoern@3715:
bjoern@3825: addLabel(kmtext, false);
bjoern@3715:
bjoern@3715: String qtext = "";
bjoern@3715: Double qmin = riverinfo.getMinQ();
bjoern@3715: Double qmax = riverinfo.getMaxQ();
bjoern@3715: if (qmin != null) {
bjoern@3828: qtext += nf.format(qmin);
bjoern@3828: qtext += " " + MSG.gauge_q_unit();
bjoern@3715: qtext += " - ";
bjoern@3715: }
bjoern@3715: if (qmax != null) {
bjoern@3828: qtext += nf.format(qmax);
bjoern@3828: qtext += " " + MSG.gauge_q_unit();
bjoern@3715: }
bjoern@3715:
bjoern@3825: addLabel(qtext, false);
bjoern@3839:
bjoern@3847: Long number = riverinfo.getOfficialNumber();
bjoern@3847: String url = number != null ?
bjoern@3847: MSG.gauge_river_url() + number :
bjoern@3847: MSG.gauge_river_url();
bjoern@3847: Anchor anchor = new Anchor(MSG.gauge_river_info_link(), url);
bjoern@3839: add(anchor);
bjoern@3825: }
bjoern@3825:
bjoern@3825: private void addLabel(String text, boolean wordwrap) {
bjoern@3825: Label label = new Label(text, wordwrap);
bjoern@3825: add(label);
bjoern@3825: setCellHeight(label, "" + HEIGHT + "px");
bjoern@3715: }
bjoern@3715: }
bjoern@3715: }