teichmann@5861: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5861: * Software engineering by Intevation GmbH teichmann@5861: * teichmann@5861: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5861: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5861: * documentation coming with Dive4Elements River for details. teichmann@5861: */ teichmann@5861: teichmann@5835: package org.dive4elements.river.client.shared.model; raimund@1461: christian@3859: import com.google.gwt.core.client.GWT; christian@3859: import com.google.gwt.i18n.client.NumberFormat; christian@3859: raimund@1503: import java.util.HashMap; raimund@1503: raimund@1461: /** raimund@1461: * @author Raimund Renkert raimund@1461: */ raimund@1461: public class DoubleProperty extends PropertySetting { raimund@1461: raimund@1503: /** raimund@1503: * Create a new DoubleProperty for settings. raimund@1503: */ raimund@1503: public DoubleProperty() { raimund@1503: this.attributes = new HashMap(); raimund@1503: } raimund@1503: raimund@1503: raimund@1503: /** raimund@1503: * Create a new DoubleProperty. raimund@1503: * @param name The attribute name. raimund@1503: * @param value The current value. raimund@1503: */ raimund@1503: public DoubleProperty( raimund@1503: String name, raimund@1507: Double value) raimund@1503: { raimund@1503: this.name = name; raimund@1507: this.value = value.toString(); raimund@1503: this.attributes = new HashMap(); raimund@1503: } raimund@1503: raimund@1507: @Override raimund@1507: public Double getValue() { raimund@1507: try { sascha@3368: Double value = Double.valueOf(this.value); sascha@3368: GWT.log("returning: " + value); sascha@3368: return value; raimund@1507: } raimund@1507: catch(NumberFormatException nfe) { raimund@1507: //Should never happen, if property is used correctly. raimund@1507: return null; raimund@1507: } raimund@1507: } raimund@1507: raimund@1507: raimund@1507: public void setValueFromUI(String value) { raimund@1507: NumberFormat nf = NumberFormat.getDecimalFormat(); raimund@1507: double d; raimund@1507: try { raimund@1507: d = nf.parse(value); raimund@1507: GWT.log("setting " + value + " as " + d); raimund@1507: this.value = Double.toString(d); raimund@1507: } raimund@1507: catch(NumberFormatException nfe) {} raimund@1507: } raimund@1507: raimund@1507: public void setValue(Double value) { raimund@1507: this.value = value.toString(); raimund@1507: } raimund@1507: raimund@1507: raimund@1507: public String toUIString() { raimund@1507: double dv; raimund@1507: NumberFormat nf = NumberFormat.getDecimalFormat(); raimund@1507: try { sascha@3368: dv = Double.parseDouble(this.value); raimund@1507: } raimund@1507: catch (NumberFormatException nfe) { raimund@1507: return null; raimund@1507: } raimund@1507: return nf.format(dv); raimund@1507: } raimund@1503: christian@3859: @Override raimund@1503: public Object clone() { raimund@1503: DoubleProperty clone = new DoubleProperty(this.getName(), raimund@1507: this.getValue()); raimund@1503: for(String s: this.getAttributeList()) { raimund@1503: clone.setAttribute(s, this.getAttribute(s)); raimund@1503: } raimund@1503: return clone; raimund@1503: } raimund@1461: }