001/*
002 * #%L
003 * GwtMaterial
004 * %%
005 * Copyright (C) 2015 - 2017 GwtMaterialDesign
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 * 
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 * 
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package gwt.material.design.client.ui;
021
022//@formatter:off
023
024
025/**
026 * Material Float Box is an input field that accepts any Float based string from user.
027 * <h3>UiBinder Usage:</h3>
028 * <pre> {@code <m:MaterialFloatBox ui:field="txtFloatBox" label="Float value"/>
029 *
030 * // Setting value in Java
031 * txtFloatBox.setValue(1000.25f);
032 * }
033 * </pre>
034 * <p>
035 * The parsing and formatting of the number are done natively by the browser, using the
036 * i18n settings from the user.
037 *
038 * @author paulux84
039 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#textfields">Material FloatBox</a>
040 * @see <a href="https://material.io/guidelines/components/text-fields.html#">Material Design Specification</a>
041 */
042//@formatter:on
043public class MaterialFloatBox extends MaterialNumberBox<Float> {
044
045    public MaterialFloatBox() {
046        setStep("any");
047    }
048
049    public MaterialFloatBox(String placeholder) {
050        this();
051        setPlaceholder(placeholder);
052    }
053
054    public MaterialFloatBox(String placeholder, float value) {
055        this(placeholder);
056        setValue(value);
057    }
058
059    @Override
060    protected Float parseNumber(double number) {
061        if (Double.isNaN(number)) {
062            return null;
063        }
064        return Float.valueOf((float) number);
065    }
066}