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 * Material Double Box is an input field that accepts any Double based string 026 * from user. <h3>UiBinder Usage:</h3> 027 * <p> 028 * <pre> {@code <m:MaterialDoubleBox ui:field="txtDoubleBox" label="Double value"/> 029 * 030 * // Setting value in Java 031 * txtDoubleBox.setValue(9999.90); 032 * } 033 * </pre> 034 * <p> 035 * The parsing and formatting of the number are done natively by the browser, 036 * using the i18n settings from the user. 037 * 038 * @author paulux84 039 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#forms">Material 040 * DoubleBox</a> 041 * @see <a href="https://material.io/guidelines/components/text-fields.html#">Material Design Specification</a> 042 */ 043// @formatter:on 044public class MaterialDoubleBox extends MaterialNumberBox<Double> { 045 046 public MaterialDoubleBox() { 047 setStep("any"); 048 } 049 050 public MaterialDoubleBox(String placeholder) { 051 this(); 052 setPlaceholder(placeholder); 053 } 054 055 public MaterialDoubleBox(String placeholder, double value) { 056 this(placeholder); 057 setValue(value); 058 } 059 060 @Override 061 protected Double parseNumber(double number) { 062 if (Double.isNaN(number)) { 063 return null; 064 } 065 return number; 066 } 067}