diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java @ 2906:1780841d79af

Added navigation to fix analysis charts. flys-client/trunk@4673 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 15 Jun 2012 12:13:09 +0000
parents
children 37dce0f2f63b
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/NaviChartOutputTab.java	Fri Jun 15 12:13:09 2012 +0000
@@ -0,0 +1,227 @@
+package de.intevation.flys.client.client.ui.chart;
+
+import java.util.Date;
+
+import com.google.gwt.core.client.GWT;
+
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.VLayout;
+import com.smartgwt.client.widgets.Button;
+
+import com.smartgwt.client.widgets.form.DynamicForm;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.form.validator.IsFloatValidator;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.widgets.tab.events.TabSelectedHandler;
+import com.smartgwt.client.widgets.tab.events.TabSelectedEvent;
+
+import de.intevation.flys.client.shared.model.Collection;
+import de.intevation.flys.client.shared.model.OutputMode;
+import de.intevation.flys.client.client.ui.CollectionView;
+import de.intevation.flys.client.shared.model.FixAnalysisArtifact;
+import de.intevation.flys.client.shared.model.Artifact;
+import de.intevation.flys.client.client.Config;
+
+
+/**
+ * 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.addChangedHandler(new ChangedHandler() {
+            public void onChanged(ChangedEvent ce) {
+                if(ce.getForm().validate() && ce.getItem().getValue() != null) {
+                    try {
+                        String s = ce.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 += "&timestamp=" + 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 += "&currentKm=" + collectionView.getCurrentKm();
+        }
+        GWT.log(imgUrl);
+
+        return imgUrl;
+    }
+
+    public void onTabSelected(TabSelectedEvent tse) {
+        if (this.equals(tse.getTab())) {
+            updateChartPanel();
+            updateChartInfo();
+            currentkm.setValue(collectionView.getCurrentKm());
+        }
+    }
+
+}

http://dive4elements.wald.intevation.org