diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java @ 9072:02739b8c010d

bundu progress (Klon FixationAnalysis +Vollmer funktioniert; Verzweigung neue Berechnungsart Bezugswst)
author gernotbelger
date Wed, 16 May 2018 17:43:47 +0200
parents 5e38e2924c07
children 850ce16034e9
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java	Wed May 16 11:08:56 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/NaviChartOutputTab.java	Wed May 16 17:43:47 2018 +0200
@@ -8,203 +8,183 @@
 
 package org.dive4elements.river.client.client.ui.chart;
 
+import java.util.Date;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.HashMap;
+
+import org.dive4elements.river.client.client.Config;
+import org.dive4elements.river.client.client.ui.CollectionView;
+import org.dive4elements.river.client.shared.model.AbstractFixBunduArtifact;
+import org.dive4elements.river.client.shared.model.Artifact;
+import org.dive4elements.river.client.shared.model.Collection;
+import org.dive4elements.river.client.shared.model.FixFilter;
+import org.dive4elements.river.client.shared.model.OutputMode;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.NumberFormat;
-
 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.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 org.dive4elements.river.client.client.Config;
-
-import org.dive4elements.river.client.client.ui.CollectionView;
-
-import org.dive4elements.river.client.shared.model.Artifact;
-import org.dive4elements.river.client.shared.model.Collection;
-import org.dive4elements.river.client.shared.model.FixAnalysisArtifact;
-import org.dive4elements.river.client.shared.model.FixFilter;
-import org.dive4elements.river.client.shared.model.OutputMode;
-
-import java.util.Date;
-
-
 /**
  * Tab representing and showing one Chart-output with a "navi" thing.
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class NaviChartOutputTab
-extends      ChartOutputTab
-implements   TabSelectedHandler
-{
+public class NaviChartOutputTab extends ChartOutputTab implements TabSelectedHandler {
     protected TextItem currentkm;
 
-    public NaviChartOutputTab(
-        String         title,
-        Collection     collection,
-        OutputMode     mode,
-        CollectionView collectionView
-    ){
+    public NaviChartOutputTab(final String title, final Collection collection, final OutputMode mode, final CollectionView collectionView) {
         super(title, collection, mode, collectionView);
-        right.removeChild(chart);
-        right.addChild(createNaviChart());
+        this.right.removeChild(this.chart);
+        this.right.addChild(createNaviChart());
         collectionView.registerTabHandler(this);
     }
 
-
     protected Canvas createNaviChart() {
-        final Artifact art = collectionView.getArtifact();
-        VLayout root = new VLayout();
+        final Artifact art = this.collectionView.getArtifact();
+        final VLayout root = new VLayout();
         root.setWidth100();
         root.setHeight100();
 
-        HLayout layout = new HLayout();
+        final HLayout layout = new HLayout();
         layout.setAlign(Alignment.CENTER);
 
-        DynamicForm form = new DynamicForm();
-        Button lower = new Button("<<");
+        final DynamicForm form = new DynamicForm();
+        final Button lower = new Button("<<");
         lower.setWidth(30);
-        Button upper = new Button(">>");
+        final Button upper = new Button(">>");
         upper.setWidth(30);
-        currentkm = new TextItem();
-        currentkm.setWidth(60);
-        currentkm.setShowTitle(false);
+        this.currentkm = new TextItem();
+        this.currentkm.setWidth(60);
+        this.currentkm.setShowTitle(false);
 
-        form.setFields(currentkm);
+        form.setFields(this.currentkm);
         form.setWidth(60);
 
         double fromKm;
         double toKm;
 
-        if (art instanceof FixAnalysisArtifact) {
-            FixAnalysisArtifact fix = (FixAnalysisArtifact) art;
-            FixFilter fixFilter = fix.getFilter();
-            String s = fix.getArtifactDescription().getDataValueAsString(
-                "ld_step");
+        if (art instanceof AbstractFixBunduArtifact) {
+            final AbstractFixBunduArtifact fix = (AbstractFixBunduArtifact) art;
+            final FixFilter fixFilter = fix.getFilter();
+            final String s = fix.getArtifactDescription().getDataValueAsString("ld_step");
             try {
-                double ds = Double.parseDouble(s);
-                collectionView.setSteps(ds);
+                final double ds = Double.parseDouble(s);
+                this.collectionView.setSteps(ds);
             }
-            catch(NumberFormatException nfe) {
-                collectionView.setSteps(100d);
+            catch (final NumberFormatException nfe) {
+                this.collectionView.setSteps(100d);
             }
             fromKm = fixFilter.getFromKm();
-            toKm   = fixFilter.getToKm();
-        }
-        else {
+            toKm = fixFilter.getToKm();
+        } else {
             // Probably WINFOArtifact kind of artifact.
-            String ld_step =
-                    art.getArtifactDescription().getDataValueAsString(
-                        "ld_step");
+            final String ld_step = art.getArtifactDescription().getDataValueAsString("ld_step");
             try {
-                collectionView.setSteps(Double.valueOf(ld_step));
+                this.collectionView.setSteps(Double.valueOf(ld_step));
             }
-            catch (Exception e) {
+            catch (final Exception e) {
                 GWT.log("No ld_steps data or not parsable.");
                 return root;
             }
 
-            double[] kmRange = art.getArtifactDescription().getKMRange();
+            final double[] kmRange = art.getArtifactDescription().getKMRange();
             if (kmRange == null || kmRange.length == 2) {
                 fromKm = kmRange[0];
-                toKm   = kmRange[1];
-            }
-            else {
+                toKm = kmRange[1];
+            } else {
                 GWT.log("No KM range in description found.");
                 return root;
             }
         }
 
-        collectionView.setMinKm(fromKm);
-        collectionView.setMaxKm(toKm);
+        this.collectionView.setMinKm(fromKm);
+        this.collectionView.setMaxKm(toKm);
 
         final NumberFormat nf = NumberFormat.getDecimalFormat();
 
         // Always jump to the from km when initialized.
         try {
-            double d = Double.valueOf(fromKm);
-            currentkm.setValue(nf.format(d));
-        } catch (NumberFormatException e) {
-            currentkm.setValue(fromKm);
+            final double d = Double.valueOf(fromKm);
+            this.currentkm.setValue(nf.format(d));
         }
-        collectionView.setCurrentKm(fromKm);
+        catch (final NumberFormatException e) {
+            this.currentkm.setValue(fromKm);
+        }
+        this.collectionView.setCurrentKm(fromKm);
 
         lower.addClickHandler(new ClickHandler() {
-            public void onClick(ClickEvent ce) {
-                tbarPanel.deselectControls();
+            @Override
+            public void onClick(final ClickEvent ce) {
+                NaviChartOutputTab.this.tbarPanel.deselectControls();
                 updateChartDown();
                 try {
-                    double d = Double.valueOf(collectionView.getCurrentKm());
-                    currentkm.setValue(nf.format(d));
-                    tbarPanel.onZoom(null);
-                } catch (NumberFormatException e) {
-                    currentkm.setValue(collectionView.getCurrentKm());
+                    final double d = Double.valueOf(NaviChartOutputTab.this.collectionView.getCurrentKm());
+                    NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
+                    NaviChartOutputTab.this.tbarPanel.onZoom(null);
+                }
+                catch (final NumberFormatException e) {
+                    NaviChartOutputTab.this.currentkm.setValue(NaviChartOutputTab.this.collectionView.getCurrentKm());
                 }
             }
         });
 
         upper.addClickHandler(new ClickHandler() {
-            public void onClick(ClickEvent ce) {
-                tbarPanel.deselectControls();
+            @Override
+            public void onClick(final ClickEvent ce) {
+                NaviChartOutputTab.this.tbarPanel.deselectControls();
                 updateChartUp();
                 try {
-                    double d = Double.valueOf(collectionView.getCurrentKm());
-                    currentkm.setValue(nf.format(d));
-                    tbarPanel.onZoom(null);
-                } catch (NumberFormatException e) {
-                    currentkm.setValue(collectionView.getCurrentKm());
+                    final double d = Double.valueOf(NaviChartOutputTab.this.collectionView.getCurrentKm());
+                    NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
+                    NaviChartOutputTab.this.tbarPanel.onZoom(null);
+                }
+                catch (final NumberFormatException e) {
+                    NaviChartOutputTab.this.currentkm.setValue(NaviChartOutputTab.this.collectionView.getCurrentKm());
                 }
             }
         });
 
-        currentkm.addKeyPressHandler(new KeyPressHandler() {
-            public void onKeyPress(KeyPressEvent kpe) {
+        this.currentkm.addKeyPressHandler(new KeyPressHandler() {
+            @Override
+            public void onKeyPress(final KeyPressEvent kpe) {
                 if (!kpe.getKeyName().equals("Enter")) {
                     return;
                 }
-                if(kpe.getItem().getValue() != null) {
-                    tbarPanel.deselectControls();
+                if (kpe.getItem().getValue() != null) {
+                    NaviChartOutputTab.this.tbarPanel.deselectControls();
                     try {
-                        String s = kpe.getItem().getValue().toString();
+                        final String s = kpe.getItem().getValue().toString();
                         double d;
                         try {
                             d = nf.parse(s);
-                            currentkm.setValue(nf.format(d));
-                        } catch (NumberFormatException e) {
+                            NaviChartOutputTab.this.currentkm.setValue(nf.format(d));
+                        }
+                        catch (final NumberFormatException e) {
                             d = -1d;
                         }
-                        if (d <= collectionView.getMaxKm() &&
-                            d >= collectionView.getMinKm()) {
-                            collectionView.setCurrentKm(d);
-                            tbarPanel.updateLinks();
-                            tbarPanel.onZoom(null);
-                            if (right != null) {
+                        if (d <= NaviChartOutputTab.this.collectionView.getMaxKm() && d >= NaviChartOutputTab.this.collectionView.getMinKm()) {
+                            NaviChartOutputTab.this.collectionView.setCurrentKm(d);
+                            NaviChartOutputTab.this.tbarPanel.updateLinks();
+                            NaviChartOutputTab.this.tbarPanel.onZoom(null);
+                            if (NaviChartOutputTab.this.right != null) {
                                 updateChartPanel();
                                 updateChartInfo();
                             }
                         }
                     }
-                    catch(NumberFormatException nfe) {
+                    catch (final NumberFormatException nfe) {
                         // Do nothing.
                     }
                 }
@@ -214,24 +194,23 @@
         layout.addMember(form);
         layout.addMember(upper);
 
-        root.addMember(chart);
+        root.addMember(this.chart);
         root.addMember(layout);
         return root;
     }
 
-
     /**
      * Callback when km-up-button is clicked.
      * Increases collectionViews KM and refreshes view.
      */
     protected void updateChartUp() {
-        double currentKm = collectionView.getCurrentKm();
-        if (currentKm < collectionView.getMaxKm()) {
+        final double currentKm = this.collectionView.getCurrentKm();
+        if (currentKm < this.collectionView.getMaxKm()) {
             // Why this math?
             double newVal = currentKm * 100;
-            newVal += (collectionView.getSteps() / 10);
-            collectionView.setCurrentKm((double)Math.round(newVal) / 100);
-            tbarPanel.updateLinks();
+            newVal += (this.collectionView.getSteps() / 10);
+            this.collectionView.setCurrentKm((double) Math.round(newVal) / 100);
+            this.tbarPanel.updateLinks();
             updateChartPanel();
             updateChartInfo();
         }
@@ -242,53 +221,57 @@
      * Decreases collectionViews KM and refreshes view.
      */
     protected void updateChartDown() {
-        double currentKm = collectionView.getCurrentKm();
-        if (currentKm > collectionView.getMinKm()) {
+        final double currentKm = this.collectionView.getCurrentKm();
+        if (currentKm > this.collectionView.getMinKm()) {
             // Why this math?
             double newVal = currentKm * 100;
-            newVal -= (collectionView.getSteps() / 10);
-            collectionView.setCurrentKm((double)Math.round(newVal) / 100);
-            tbarPanel.updateLinks();
+            newVal -= (this.collectionView.getSteps() / 10);
+            this.collectionView.setCurrentKm((double) Math.round(newVal) / 100);
+            this.tbarPanel.updateLinks();
             updateChartPanel();
             updateChartInfo();
         }
 
     }
 
-   /**
+    /**
      * Returns the existing chart panel.
      *
      * @return the existing chart panel.
      */
     @Override
     public Canvas getChartPanel() {
-        return chart;
+        return this.chart;
     }
 
     /**
      * 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).
+     * @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();
+    protected String getImgUrl(final int width, final int height) {
+        final Config config = Config.getInstance();
 
         String imgUrl = GWT.getModuleBaseURL();
         imgUrl += "chart";
-        imgUrl += "?uuid=" + collection.identifier();
-        imgUrl += "&type=" + mode.getName();
+        imgUrl += "?uuid=" + this.collection.identifier();
+        imgUrl += "&type=" + this.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();
+        final Number[] zoom = getZoomValues();
 
         if (zoom != null) {
             if (zoom[0].intValue() != 0 || zoom[1].intValue() != 1) {
@@ -306,30 +289,27 @@
             }
         }
 
-        if (collectionView.getArtifact() instanceof FixAnalysisArtifact) {
-            if (collectionView.getCurrentKm() == -1) {
-                FixAnalysisArtifact fix =
-                    (FixAnalysisArtifact) collectionView.getArtifact();
-                collectionView.setCurrentKm(fix.getFilter().getFromKm());
+        if (this.collectionView.getArtifact() instanceof AbstractFixBunduArtifact) {
+            if (this.collectionView.getCurrentKm() == -1) {
+                final AbstractFixBunduArtifact fix = (AbstractFixBunduArtifact) this.collectionView.getArtifact();
+                this.collectionView.setCurrentKm(fix.getFilter().getFromKm());
             }
+        } else if (this.collectionView.getCurrentKm() == -1) {
+            this.collectionView.setCurrentKm(this.collectionView.getArtifact().getArtifactDescription().getKMRange()[0]);
         }
-        else if (collectionView.getCurrentKm() == -1) {
-            collectionView.setCurrentKm(
-                collectionView.getArtifact().getArtifactDescription()
-                .getKMRange()[0]);
-        }
-        if (collectionView.getCurrentKm() != -1) {
-            imgUrl += "&currentKm=" + collectionView.getCurrentKm();
+        if (this.collectionView.getCurrentKm() != -1) {
+            imgUrl += "&currentKm=" + this.collectionView.getCurrentKm();
         }
 
         return imgUrl;
     }
 
-    public void onTabSelected(TabSelectedEvent tse) {
+    @Override
+    public void onTabSelected(final TabSelectedEvent tse) {
         if (this.equals(tse.getTab())) {
             updateChartPanel();
             updateChartInfo();
-            currentkm.setValue(collectionView.getCurrentKm());
+            this.currentkm.setValue(this.collectionView.getCurrentKm());
         }
     }
 
@@ -338,18 +318,20 @@
         Map<String, String> attr = new HashMap<String, String>();
 
         attr = super.getChartAttributes();
-        attr.put("km", String.valueOf(collectionView.getCurrentKm()));
+        attr.put("km", String.valueOf(this.collectionView.getCurrentKm()));
 
         return attr;
     }
 
-    /** In contrast to supers implementation, include the currently selected
-     * km in the url. */
+    /**
+     * In contrast to supers implementation, include the currently selected
+     * km in the url.
+     */
     @Override
-    public String getExportUrl(int width, int height, String format) {
+    public String getExportUrl(final int width, final int height, final String format) {
         String url = super.getExportUrl(width, height, format);
-        if (collectionView.getCurrentKm() != -1) {
-            url += "&currentKm=" + collectionView.getCurrentKm();
+        if (this.collectionView.getCurrentKm() != -1) {
+            url += "&currentKm=" + this.collectionView.getCurrentKm();
         }
         return url;
     }

http://dive4elements.wald.intevation.org