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