Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleArrayPanel.java @ 3719:e82acd5c86f7
Merged revisions 5495-5496,5509,5514-5515,5521-5526 via svnmerge from
file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-client/trunk
........
r5495 | ingo | 2012-09-17 14:55:09 +0200 (Mo, 17 Sep 2012) | 1 line
Added missing i18n strings for minfo state description.
........
r5496 | ingo | 2012-09-17 15:47:43 +0200 (Mo, 17 Sep 2012) | 1 line
Tagged 'flys-client' as 2.9.1
........
r5509 | teichmann | 2012-09-18 17:54:37 +0200 (Di, 18 Sep 2012) | 1 line
Removed trailing whitespace.
........
r5514 | bricks | 2012-09-19 09:56:42 +0200 (Mi, 19 Sep 2012) | 2 lines
Add missing Changelog entry for r5472
........
r5515 | bricks | 2012-09-19 09:59:35 +0200 (Mi, 19 Sep 2012) | 2 lines
Implement a scrolling gauge info tree
........
r5521 | bricks | 2012-09-19 14:41:48 +0200 (Mi, 19 Sep 2012) | 2 lines
Add station info to the gauges
........
r5522 | bricks | 2012-09-19 14:43:43 +0200 (Mi, 19 Sep 2012) | 2 lines
Improve the handling of the GaugePanel in the ParameterList
........
r5523 | bricks | 2012-09-19 14:51:02 +0200 (Mi, 19 Sep 2012) | 4 lines
Improve the GaugePanel
Be locale aware and only load the gauge info if the river name changes.
........
r5524 | bricks | 2012-09-19 15:14:46 +0200 (Mi, 19 Sep 2012) | 5 lines
Fix a NullPointerException
When iterating over a list it must be checked if the reference to the list is
valid.
........
r5525 | bricks | 2012-09-19 15:16:24 +0200 (Mi, 19 Sep 2012) | 2 lines
Don't display the GaugePanel if no river is selected
........
r5526 | bricks | 2012-09-19 15:18:36 +0200 (Mi, 19 Sep 2012) | 2 lines
Use the wstunit from the river as unit for the Pegelnullpunkt
........
flys-client/tags/2.9.1@5528 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 19 Sep 2012 14:42:48 +0000 |
parents | 1fae113b93fd |
children | 06c76de19b51 |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.Map; 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; import com.smartgwt.client.widgets.form.fields.StaticTextItem; import com.smartgwt.client.widgets.form.fields.TextItem; import com.smartgwt.client.widgets.form.fields.events.BlurHandler; import de.intevation.flys.client.client.FLYSConstants; public class DoubleArrayPanel extends DynamicForm { /** The message class that provides i18n strings. */ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); protected TextItem ti; /** The constant input field name. */ public static final String FIELD_NAME = "doublearray"; public DoubleArrayPanel( String title, double[] values, BlurHandler handler) { this(title, values, handler, 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 handler The BlurHandler that is used to valide the input. */ public DoubleArrayPanel( String title, double[] values, BlurHandler handler, TitleOrientation titleOrientation) { ti = new TextItem(FIELD_NAME); StaticTextItem sti = new StaticTextItem("staticarray"); ti.setShowTitle(false); sti.setShowTitle(false); sti.setValue(title); ti.addBlurHandler(handler); if (titleOrientation == TitleOrientation.RIGHT) { setFields(ti, sti); } else { setFields(sti, ti); } setTitleOrientation(titleOrientation); setNumCols(2); if (values == null) { return; } NumberFormat f = NumberFormat.getDecimalFormat(); StringBuilder text = new StringBuilder(); boolean firstItem = true; for (double val: values) { if (!firstItem) { text.append(" "); } text.append(f.format(val)); firstItem = false; } ti.setValue(text.toString()); } /** * This method takes the double array to set the values to the textbox. * * @param values The double values. */ public void setValues(double[] values) { NumberFormat f = NumberFormat.getDecimalFormat(); if(values.length == 0) { ti.clearValue(); return; } StringBuilder text = new StringBuilder(); boolean firstItem = true; if (values != null) { for (double val: values) { if (!firstItem) { text.append(" "); } text.append(f.format(val)); firstItem = false; } } ti.clearValue(); ti.setValue(text.toString()); } /** * This method appends a double value to the current list of values. * * @param value A new value. */ public void addValue(double value) { NumberFormat f = NumberFormat.getDecimalFormat(); String current = ti.getValueAsString(); if (current == null || current.length() == 0) { current = f.format(value); } else { current += " " + f.format(value); } ti.setValue(current); } protected boolean validateForm() { return validateForm(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. */ protected boolean validateForm(FormItem item) { if (item instanceof StaticTextItem) { return true; } boolean valid = true; String value = (String) item.getValue(); if (value == null) { return valid; } String[] parts = value.split("\\s+"); if (parts == null) { return valid; } NumberFormat f = NumberFormat.getDecimalFormat(); Map errors = getErrors(); try { for (String part: parts) { if (part.length() == 0) { continue; } double location = f.parse(part); } errors.remove(item.getFieldName()); } catch (NumberFormatException nfe) { errors.put(item.getFieldName(), MESSAGES.wrongFormat()); valid = false; } setErrors(errors, true); 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. * * @return the values as double array. */ public double[] getInputValues(FormItem item) { String value = (String) item.getValue(); if (value == null) { return null; } String[] parts = value.split("\\s+"); if (parts == null) { return null; } NumberFormat f = NumberFormat.getDecimalFormat(); double[] values = new double[parts.length]; int i = 0; OUTER: for (String part: parts) { if (part.length() == 0) { continue; } try { double x = f.parse(part); for (int j = 0; j < i; ++j) { if (values[j] == x) { continue OUTER; } } values[i++] = x; } catch (NumberFormatException nfe) { // do nothing } } 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); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :