diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java @ 9276:3141f0e7314e

clone for bundu.ws.wq
author gernotbelger
date Thu, 19 Jul 2018 17:54:10 +0200
parents ea9eef426962
children bc9a45d2b1fa
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java	Thu Jul 19 17:36:52 2018 +0200
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/DoubleArrayPanel.java	Thu Jul 19 17:54:10 2018 +0200
@@ -8,9 +8,12 @@
 
 package org.dive4elements.river.client.client.ui;
 
+import java.util.Map;
+
+import org.dive4elements.river.client.client.FLYSConstants;
+
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.i18n.client.NumberFormat;
-
 import com.smartgwt.client.types.TitleOrientation;
 import com.smartgwt.client.widgets.form.DynamicForm;
 import com.smartgwt.client.widgets.form.fields.FormItem;
@@ -19,13 +22,7 @@
 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
 import com.smartgwt.client.widgets.form.fields.events.FocusHandler;
 
-import org.dive4elements.river.client.client.FLYSConstants;
-
-import java.util.Map;
-
-public class DoubleArrayPanel
-extends      DynamicForm
-{
+public class DoubleArrayPanel extends DynamicForm {
     /** The message class that provides i18n strings. */
     protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class);
 
@@ -36,51 +33,44 @@
     /** The constant input field name. */
     public static final String FIELD_NAME = "doublearray";
 
-
-    public DoubleArrayPanel(
-        String title,
-        double[] values,
-        BlurHandler handler)
-    {
+    public DoubleArrayPanel(final String title, final double[] values, final BlurHandler handler) {
         this(title, values, handler, null, TitleOrientation.RIGHT);
     }
 
-
     /**
      * Creates a new form with a single input field that displays an array of
      * double values.
      *
-     * @param name The name of the TextItem.
-     * @param title The title of the TextItem.
-     * @param values The double values that should be displayed initially.
-     * @param blurHandler The BlurHandler that is used to valide the input.
-     * @param focusHandler The FocueHandler that is used to valide the input.
+     * @param name
+     *            The name of the TextItem.
+     * @param title
+     *            The title of the TextItem.
+     * @param values
+     *            The double values that should be displayed initially.
+     * @param blurHandler
+     *            The BlurHandler that is used to valide the input.
+     * @param focusHandler
+     *            The FocueHandler that is used to valide the input.
      */
-    public DoubleArrayPanel(
-        String title,
-        double[] values,
-        BlurHandler blurHandler,
-        FocusHandler focusHandler,
-        TitleOrientation titleOrientation)
-    {
+    public DoubleArrayPanel(final String title, final double[] values, final BlurHandler blurHandler, final FocusHandler focusHandler,
+            final TitleOrientation titleOrientation) {
         this.title = title;
-        ti                 = new TextItem(FIELD_NAME);
-        StaticTextItem sti = new StaticTextItem("staticarray");
+        this.ti = new TextItem(FIELD_NAME);
+        final StaticTextItem sti = new StaticTextItem("staticarray");
 
-        ti.setShowTitle(false);
+        this.ti.setShowTitle(false);
         sti.setShowTitle(false);
         sti.setValue(title);
 
-        ti.addBlurHandler(blurHandler);
+        this.ti.addBlurHandler(blurHandler);
         if (focusHandler != null) {
-            ti.addFocusHandler(focusHandler);
+            this.ti.addFocusHandler(focusHandler);
         }
 
         if (titleOrientation == TitleOrientation.RIGHT) {
-            setFields(ti, sti);
-        }
-        else {
-            setFields(sti, ti);
+            setFields(this.ti, sti);
+        } else {
+            setFields(sti, this.ti);
         }
 
         setTitleOrientation(titleOrientation);
@@ -90,12 +80,12 @@
             return;
         }
 
-        NumberFormat f = NumberFormat.getDecimalFormat();
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        StringBuilder text = new StringBuilder();
-        boolean firstItem  = true;
+        final StringBuilder text = new StringBuilder();
+        boolean firstItem = true;
 
-        for (double val: values) {
+        for (final double val : values) {
             if (!firstItem) {
                 text.append(" ");
             }
@@ -105,26 +95,26 @@
             firstItem = false;
         }
 
-        ti.setValue(text.toString());
+        this.ti.setValue(text.toString());
     }
 
-
     /**
      * This method takes the double array to set the values to the textbox.
      *
-     * @param values The double values.
+     * @param values
+     *            The double values.
      */
-    public void setValues(double[] values) {
-        NumberFormat f = NumberFormat.getDecimalFormat();
+    public void setValues(final double[] values) {
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        if(values == null || values.length == 0) {
-            ti.clearValue();
+        if (values == null || values.length == 0) {
+            this.ti.clearValue();
             return;
         }
-        StringBuilder text = new StringBuilder();
-        boolean firstItem  = true;
+        final StringBuilder text = new StringBuilder();
+        boolean firstItem = true;
         if (values != null) {
-            for (double val: values) {
+            for (final double val : values) {
                 if (!firstItem) {
                     text.append(" ");
                 }
@@ -135,69 +125,67 @@
             }
         }
 
-        ti.clearValue();
-        ti.setValue(text.toString());
+        this.ti.clearValue();
+        this.ti.setValue(text.toString());
     }
 
-
     /**
      * This method appends a double value to the current list of values.
      *
-     * @param value A new value.
+     * @param value
+     *            A new value.
      */
-    public void addValue(double value) {
-        NumberFormat f = NumberFormat.getDecimalFormat();
+    public void addValue(final double value) {
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        String current = ti.getValueAsString();
+        String current = this.ti.getValueAsString();
 
         if (current == null || current.length() == 0) {
             current = f.format(value);
-        }
-        else {
+        } else {
             current += " " + f.format(value);
         }
 
-        ti.setValue(current);
+        this.ti.setValue(current);
     }
 
-
-    protected boolean validateForm() {
-        return validateForm(ti);
+    public boolean validateForm() {
+        return validateForm(this.ti);
     }
 
-
     /**
      * This method validates the entered text in the location input field. If
      * there are values that doesn't represent a valid location, an error is
      * displayed.
      *
-     * @param item The FormItem.
+     * @param item
+     *            The FormItem.
      */
     @SuppressWarnings("unchecked")
-    protected boolean validateForm(FormItem item) {
+    protected boolean validateForm(final FormItem item) {
         if (item instanceof StaticTextItem) {
             return true;
         }
 
-        boolean  valid = true;
-        String   value = (String) item.getValue();
+        boolean valid = true;
+        final String value = (String) item.getValue();
 
         if (value == null) {
             return valid;
         }
 
-        String[] parts = value.split("\\s+");
+        final String[] parts = value.split("\\s+");
 
         if (parts == null) {
             return valid;
         }
 
-        NumberFormat nf = NumberFormat.getDecimalFormat();
+        final NumberFormat nf = NumberFormat.getDecimalFormat();
         @SuppressWarnings("rawtypes")
-        Map errors = getErrors();
+        final Map errors = getErrors();
 
         try {
-            for (String part: parts) {
+            for (final String part : parts) {
 
                 if (part.length() == 0) {
                     continue;
@@ -208,8 +196,8 @@
 
             errors.remove(item.getFieldName());
         }
-        catch (NumberFormatException nfe) {
-            errors.put(item.getFieldName(), MESSAGES.wrongFormat());
+        catch (final NumberFormatException nfe) {
+            errors.put(item.getFieldName(), this.MESSAGES.wrongFormat());
 
             valid = false;
         }
@@ -219,40 +207,40 @@
         return valid;
     }
 
-
     /**
      * This method returns the double array that has been entered in
      * <i>item</i>.
      *
-     * @param item The item that contains the desired values.
+     * @param item
+     *            The item that contains the desired values.
      *
      * @return the values as double array.
      */
-    public double[] getInputValues(FormItem item) {
-        String value = (String) item.getValue();
+    public double[] getInputValues(final FormItem item) {
+        final String value = (String) item.getValue();
 
         if (value == null) {
             return null;
         }
 
-        String[] parts  = value.split("\\s+");
+        final String[] parts = value.split("\\s+");
 
         if (parts == null) {
             return null;
         }
 
-        NumberFormat f = NumberFormat.getDecimalFormat();
+        final NumberFormat f = NumberFormat.getDecimalFormat();
 
-        double[] values = new double[parts.length];
+        final double[] values = new double[parts.length];
 
         int i = 0;
-        OUTER: for (String part: parts) {
+        OUTER: for (final String part : parts) {
             if (part.length() == 0) {
                 continue;
             }
 
             try {
-                double x = f.parse(part);
+                final double x = f.parse(part);
                 for (int j = 0; j < i; ++j) {
                     if (values[j] == x) {
                         continue OUTER;
@@ -260,25 +248,24 @@
                 }
                 values[i++] = x;
             }
-            catch (NumberFormatException nfe) {
+            catch (final NumberFormatException nfe) {
                 // do nothing
             }
         }
 
-        double [] out = new double[i];
+        final double[] out = new double[i];
         System.arraycopy(values, 0, out, 0, i);
 
         return out;
     }
 
-
     /**
      * Returns the double values of this panel.
      *
      * @return the double values of this panel.
      */
     public double[] getInputValues() {
-        return getInputValues(ti);
+        return getInputValues(this.ti);
     }
 
     public String getItemTitle() {

http://dive4elements.wald.intevation.org