Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java @ 2920:aad006178c39
Bumped SmartGWT to version 3.0
flys-client/trunk@4760 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 22 Jun 2012 16:38:36 +0000 |
parents | d92770527b0f |
children | 6cf983dd4f8a |
line wrap: on
line source
package de.intevation.flys.client.client.ui.chart; import com.google.gwt.core.client.GWT; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent; import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler; import com.smartgwt.client.widgets.form.validator.IsFloatValidator; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tab.events.TabSelectedEvent; import com.smartgwt.client.widgets.tab.events.TabSelectedHandler; import de.intevation.flys.client.client.Config; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.shared.model.Artifact; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.FixAnalysisArtifact; import de.intevation.flys.client.shared.model.OutputMode; import java.util.Date; /** * Tab representing and showing one Chart-output. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class NaviChartOutputTab extends ChartOutputTab implements TabSelectedHandler { protected TextItem currentkm; public NaviChartOutputTab( String title, Collection collection, OutputMode mode, CollectionView collectionView ){ super(title, collection, mode, collectionView); right.removeChild(chart); right.addChild(createNaviChart()); collectionView.registerTabHandler(this); } protected Canvas createNaviChart() { final Artifact art = collectionView.getArtifact(); VLayout root = new VLayout(); root.setWidth100(); root.setHeight100(); HLayout layout = new HLayout(); layout.setAlign(Alignment.CENTER); DynamicForm form = new DynamicForm(); Button lower = new Button("<<"); lower.setWidth(30); Button upper = new Button(">>"); upper.setWidth(30); currentkm = new TextItem(); currentkm.setWidth(60); currentkm.setShowTitle(false); currentkm.setValidators(new IsFloatValidator()); form.setFields(currentkm); form.setWidth(60); FixAnalysisArtifact fix = (FixAnalysisArtifact) art; String s = fix.getArtifactDescription().getDataValueAsString("step"); try { double ds = Double.valueOf(s).doubleValue(); collectionView.setSteps(ds); } catch(NumberFormatException nfe) { collectionView.setSteps(100d); } collectionView.setMinKm(fix.getFilter().getFromKm()); collectionView.setMaxKm(fix.getFilter().getToKm()); if (collectionView.getCurrentKm() == -1d) { currentkm.setValue(fix.getFilter().getFromKm()); collectionView.setCurrentKm(fix.getFilter().getFromKm()); } else { currentkm.setValue(collectionView.getCurrentKm()); } lower.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { updateChartDown(); currentkm.setValue(collectionView.getCurrentKm()); } }); upper.addClickHandler(new ClickHandler() { public void onClick(ClickEvent ce) { updateChartUp(); currentkm.setValue(collectionView.getCurrentKm()); } }); currentkm.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent kpe) { if (!kpe.getKeyName().equals("Enter")) { return; } if(kpe.getForm().validate() && kpe.getItem().getValue() != null) { try { String s = kpe.getItem().getValue().toString(); Double d = new Double(s); if (d <= collectionView.getMaxKm() && d >= collectionView.getMinKm()) { collectionView.setCurrentKm(d); if (right != null) { updateChartPanel(); updateChartInfo(); } } } catch(NumberFormatException nfe) { // Do nothing. } } } }); layout.addMember(lower); layout.addMember(form); layout.addMember(upper); root.addMember(chart); root.addMember(layout); return root; } protected void updateChartUp() { double currentKm = collectionView.getCurrentKm(); if (currentKm < collectionView.getMaxKm()) { double newVal = currentKm * 100; newVal += (collectionView.getSteps() / 10); collectionView.setCurrentKm((double)Math.round(newVal) / 100); updateChartPanel(); updateChartInfo(); } } protected void updateChartDown() { double currentKm = collectionView.getCurrentKm(); if (currentKm > collectionView.getMinKm()) { double newVal = currentKm * 100; newVal -= (collectionView.getSteps() / 10); collectionView.setCurrentKm((double)Math.round(newVal) / 100); updateChartPanel(); updateChartInfo(); } } /** * Builds the URL that points to the chart image. * * @param width The width of the requested chart. * @param height The height of the requested chart. * @param xr Optional x range (used for zooming). * @param yr Optional y range (used for zooming). * * @return the URL to the chart image. */ @Override protected String getImgUrl(int width, int height) { Config config = Config.getInstance(); String imgUrl = GWT.getModuleBaseURL(); imgUrl += "chart"; imgUrl += "?uuid=" + collection.identifier(); imgUrl += "&type=" + mode.getName(); imgUrl += "&locale=" + config.getLocale(); imgUrl += "×tamp=" + new Date().getTime(); imgUrl += "&width=" + Integer.toString(width); imgUrl += "&height=" + Integer.toString(height - 40); Number[] zoom = getZoomValues(); if (zoom != null) { if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) { // a zoom range of 0-1 means displaying the whole range. In such // case we don't need to zoom. imgUrl += "&minx=" + zoom[0]; imgUrl += "&maxx=" + zoom[1]; } if (zoom[2].intValue() != 0 || zoom[3].intValue() != 1) { // a zoom range of 0-1 means displaying the whole range. In such // case we don't need to zoom. imgUrl += "&miny=" + zoom[2]; imgUrl += "&maxy=" + zoom[3]; } } if(collectionView.getArtifact() instanceof FixAnalysisArtifact) { if (collectionView.getCurrentKm() == -1) { FixAnalysisArtifact fix = (FixAnalysisArtifact) collectionView.getArtifact(); collectionView.setCurrentKm(fix.getFilter().getFromKm()); } imgUrl += "¤tKm=" + collectionView.getCurrentKm(); } GWT.log(imgUrl); return imgUrl; } public void onTabSelected(TabSelectedEvent tse) { if (this.equals(tse.getTab())) { updateChartPanel(); updateChartInfo(); currentkm.setValue(collectionView.getCurrentKm()); } } }