Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/DoubleRangePanel.java @ 240:4cdf9030854f
Added i18n strings for the computed discharge curve.
flys-client/trunk@1816 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 04 May 2011 07:36:20 +0000 |
parents | 137daff2c732 |
children | 9f16ac843dda |
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.Alignment; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FloatItem; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.StaticTextItem; import com.smartgwt.client.widgets.form.fields.events.BlurHandler; import de.intevation.flys.client.client.FLYSConstants; /** * This class creates a DynamicForm with three input fields. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class DoubleRangePanel extends DynamicForm { /** The message class that provides i18n strings.*/ protected FLYSConstants MESSAGES = GWT.create(FLYSConstants.class); /** The constant name of the input field to enter the start of a distance.*/ public static final String FIELD_FROM = "from"; /** The constant name of the input field to enter the end of a distance.*/ public static final String FIELD_TO = "to"; /** The constant name of the input field to enter the step width of a * distance.*/ public static final String FIELD_WIDTH = "step"; /** The textboxes */ protected FloatItem fromItem; protected FloatItem toItem; protected FloatItem stepItem; /** * 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 DoubleRangePanel( String titleFrom, String titleTo, String titleStep, double from, double to, double step, int width, BlurHandler handler) { fromItem = new FloatItem(FIELD_FROM); toItem = new FloatItem(FIELD_TO); stepItem = new FloatItem(FIELD_WIDTH); fromItem.addBlurHandler(handler); toItem.addBlurHandler(handler); stepItem.addBlurHandler(handler); NumberFormat f = NumberFormat.getDecimalFormat(); fromItem.setValue(f.format(from)); toItem.setValue(f.format(to)); stepItem.setValue(f.format(step)); StaticTextItem fromText = new StaticTextItem("staticFrom"); fromText.setValue(titleFrom); fromText.setShowTitle(false); fromItem.setShowTitle(false); StaticTextItem toText = new StaticTextItem("staticTo"); toText.setValue(titleTo); toText.setShowTitle(false); toItem.setShowTitle(false); StaticTextItem stepText = new StaticTextItem("staticStep"); stepText.setValue(titleStep); stepText.setShowTitle(false); stepItem.setShowTitle(false); int itemWidth = width / 6; fromItem.setWidth(itemWidth); fromText.setWidth(itemWidth); toItem.setWidth(itemWidth); toText.setWidth(itemWidth); stepItem.setWidth(itemWidth); stepText.setWidth(itemWidth); setFields(fromItem, fromText, toItem, toText, stepItem, stepText); setFixedColWidths(false); setNumCols(6); setWidth(width); setAlign(Alignment.CENTER); } /** * This method takes distances values and sets them to the textboxes * visualizied by this widget. * * @param from The from value. * @param to The to value. * @param steps The max steps. */ public void setValues(double from, double to, double steps) { NumberFormat f = NumberFormat.getDecimalFormat(); fromItem.setValue(f.format(from)); toItem.setValue(f.format(to)); stepItem.setValue(f.format(steps)); } /** * This method validates the entered text in the input fields. If * there are values that doesn't represent a valid float, an error is * displayed. * * @param item The FormItem. */ protected boolean validateForm(FormItem item) { if (item instanceof StaticTextItem) { return true; } boolean valid = true; String v = (String) item.getValue(); NumberFormat f = NumberFormat.getDecimalFormat(); Map errors = getErrors(); try { double value = f.parse(v); errors.remove(item.getFieldName()); } catch (NumberFormatException nfe) { errors.put(item.getFieldName(), MESSAGES.wrongFormat()); item.focusInItem(); valid = false; } setErrors(errors, true); return valid; } /** * Returns the double value of <i>value</i>. * * @return the double value of <i>value</i>. */ protected double getDouble(String value) { NumberFormat f = NumberFormat.getDecimalFormat(); return f.parse(value); } /** * Returns the start value. * * @return the start value. */ public double getFrom() { String v = getValueAsString(FIELD_FROM); return getDouble(v); } /** * Returns the end value. * * @return the end value. */ public double getTo() { String v = getValueAsString(FIELD_TO); return getDouble(v); } /** * Returns the step width. * * @return the step width. */ public double getStep() { String v = getValueAsString(FIELD_WIDTH); return getDouble(v); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :