Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/SingleLocationPanel.java @ 2894:fe0dc03f3158
Added i18n stubs for fix analyses to continue working with the GUI.
flys-client/trunk@4617 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 07 Jun 2012 07:27:57 +0000 |
parents | f13a7c126f24 |
children | 133820d1e6bf |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.ArrayList; import java.util.List; import com.google.gwt.i18n.client.NumberFormat; import de.intevation.flys.client.shared.model.Data; /** * This UIProvider creates a widget to enter a single location (km). */ public class SingleLocationPanel extends MultipleLocationPanel { /** * Creates a new LocationDistancePanel instance. */ public SingleLocationPanel() { picker = new LocationPicker(this); } /** Overridden to restrict to one entered value. */ @Override public List<String> validate() { List<String> errors = new ArrayList<String>(); NumberFormat nf = NumberFormat.getDecimalFormat(); saveLocationValues(locationPanel); if (!locationPanel.validateForm()) { errors.add(MSG.wrongFormat()); return errors; } double[] values = getLocationValues(); double[] good = new double[values.length]; int idx = 0; // We want just one value to be allowed. if (values.length > 1) { errors.add(MSG.too_many_values()); } for (double value: values) { if (value < min || value > max) { String tmp = MSG.error_validate_range(); tmp = tmp.replace("$1", nf.format(value)); tmp = tmp.replace("$2", nf.format(min)); tmp = tmp.replace("$3", nf.format(max)); errors.add(tmp); } else { good[idx++] = value; } } double[] justGood = new double[idx]; for (int i = 0; i < justGood.length; i++) { justGood[i] = good[i]; } if (!errors.isEmpty()) { locationPanel.setValues(justGood); } return errors; } /** * This method returns the selected data. * * @return the selected/inserted data. */ public Data[] getData() { saveLocationValues(locationPanel); double[] values = getLocationValues(); Data[] data = new Data[values.length+1]; for (int i = 0; i < values.length; i++) { data[i] = createDataArray(getDataItemName(), Double.valueOf(values[i]).toString()); } data[values.length] = createDataArray("ld_mode", "locations"); return data; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :