bjoern@3715: package de.intevation.flys.client.client.ui; bjoern@3715: bjoern@3715: import com.google.gwt.core.client.GWT; ingo@3719: 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; ingo@3719: import com.google.gwt.user.client.ui.HorizontalPanel; ingo@3719: import com.google.gwt.user.client.ui.Label; bjoern@3715: bjoern@3715: import com.smartgwt.client.types.Overflow; ingo@3719: import com.smartgwt.client.widgets.events.ResizedEvent; ingo@3719: 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: */ ingo@3719: 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; ingo@3719: ingo@3719: protected RiverInfoPanel riverinfopanel; ingo@3719: 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); ingo@3719: setOverflow(Overflow.HIDDEN); ingo@3719: sectionStack.setHidden(true); bjoern@3715: sectionStack.setItems(this); bjoern@3715: this.sectionStack = sectionStack; ingo@3719: setStyleName("gaugepanel"); ingo@3719: addResizedHandler(this); bjoern@3715: } bjoern@3715: ingo@3719: /** ingo@3719: * Sets and loads the river data if river is not the current set river ingo@3719: */ bjoern@3715: public void setRiver(String river) { ingo@3719: if (!river.equals(this.river)) { ingo@3719: this.river = river; ingo@3719: this.refresh(); ingo@3719: } 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) { ingo@3719: removeMembers(getMembers()); bjoern@3715: ingo@3719: riverinfopanel = new RiverInfoPanel(riverinfo); ingo@3719: addMember(riverinfopanel); ingo@3719: addMember(gaugetree); bjoern@3715: ingo@3719: gaugetree.setGauges(riverinfo); ingo@3719: } bjoern@3715: ingo@3719: @Override ingo@3719: public void onResized(ResizedEvent event) { ingo@3719: /* this height calculation is only an approximation and doesn't reflect ingo@3719: * the real height of the the gaugetree. */ ingo@3719: int height = getInnerContentHeight() - ingo@3719: (RiverInfoPanel.HEIGHT + ingo@3719: (2 * RiverInfoPanel.BORDER_WIDTH) + ingo@3719: (2 * RiverInfoPanel.PADDING) + ingo@3719: (2 * RiverInfoPanel.MARGIN)); ingo@3719: ingo@3719: if (height < 0) { ingo@3719: height = 0; bjoern@3715: } ingo@3719: ingo@3719: gaugetree.setHeight("" + height + "px"); bjoern@3715: } bjoern@3715: ingo@3719: 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: ingo@3719: class RiverInfoPanel extends HorizontalPanel { ingo@3719: ingo@3719: public final static int HEIGHT = 30; ingo@3719: public final static int BORDER_WIDTH = 3; ingo@3719: public final static int PADDING = 8; ingo@3719: public final static int MARGIN = 10; bjoern@3715: bjoern@3715: public RiverInfoPanel(RiverInfo riverinfo) { ingo@3719: setStyleName("riverinfopanel"); ingo@3719: setHeight("" + HEIGHT + "px"); ingo@3719: setVerticalAlignment(ALIGN_MIDDLE); bjoern@3715: ingo@3719: NumberFormat nf = NumberFormat.getDecimalFormat(); ingo@3719: ingo@3719: 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) { ingo@3719: kmtext += nf.format(end); bjoern@3715: kmtext += " - "; bjoern@3715: } bjoern@3715: if (start != null) { ingo@3719: kmtext += nf.format(start); bjoern@3715: } bjoern@3715: kmtext += " km"; bjoern@3715: ingo@3719: 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) { ingo@3719: qtext += nf.format(qmin); ingo@3719: qtext += " " + MSG.gauge_q_unit(); bjoern@3715: qtext += " - "; bjoern@3715: } bjoern@3715: if (qmax != null) { ingo@3719: qtext += nf.format(qmax); ingo@3719: qtext += " " + MSG.gauge_q_unit(); bjoern@3715: } bjoern@3715: ingo@3719: 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); ingo@3719: } ingo@3719: ingo@3719: private void addLabel(String text, boolean wordwrap) { ingo@3719: Label label = new Label(text, wordwrap); ingo@3719: add(label); ingo@3719: setCellHeight(label, "" + HEIGHT + "px"); bjoern@3715: } bjoern@3715: } bjoern@3715: }