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