001package gwt.material.design.client.ui; 002 003import com.google.gwt.dom.client.Element; 004import com.google.gwt.uibinder.client.UiConstructor; 005 006/* 007 * #%L 008 * GwtMaterial 009 * %% 010 * Copyright (C) 2015 GwtMaterialDesign 011 * %% 012 * Licensed under the Apache License, Version 2.0 (the "License"); 013 * you may not use this file except in compliance with the License. 014 * You may obtain a copy of the License at 015 * 016 * http://www.apache.org/licenses/LICENSE-2.0 017 * 018 * Unless required by applicable law or agreed to in writing, software 019 * distributed under the License is distributed on an "AS IS" BASIS, 020 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 021 * See the License for the specific language governing permissions and 022 * limitations under the License. 023 * #L% 024 */ 025 026import gwt.material.design.client.base.NumberBox; 027import gwt.material.design.client.base.NumberBox.NumberHandler; 028import gwt.material.design.client.constants.InputType; 029 030//@formatter:off 031 032/** 033 * Material Number Box is the base class for other numeric input boxes, such as {@link MaterialIntegerBox} and 034 * {@link MaterialDoubleBox}. 035 * 036 * @see <a href="http://gwt-material-demo.herokuapp.com/#forms">Material MaterialNumberBox</a> 037 * @author paulux84 038 */ 039//@formatter:on 040public class MaterialNumberBox<T> extends MaterialValueBox<T> { 041 042 @UiConstructor 043 public MaterialNumberBox() { 044 initValueBox(new NumberBox<T>(new NumberHandler<T>(this))); 045 setType(InputType.NUMBER); 046 } 047 048 /** 049 * Set step attribute to input element. 050 * @param step "any" or number like for example 1 or 2.5 or 100, etc... 051 */ 052 public void setStep(String step) { 053 valueBoxBase.getElement().setAttribute("step", step); 054 } 055 056 public String getStep() { 057 return valueBoxBase.getElement().getAttribute("step"); 058 } 059 060 public void setMin(String min) { 061 valueBoxBase.getElement().setAttribute("min", min); 062 } 063 064 public String getMin() { 065 return valueBoxBase.getElement().getAttribute("min"); 066 } 067 068 public void setMax(String max) { 069 valueBoxBase.getElement().setAttribute("max", max); 070 } 071 072 public String getMax() { 073 return valueBoxBase.getElement().getAttribute("max"); 074 } 075 076 @Override 077 public String getText() { 078 return valueBoxBase.getText(); 079 } 080 081 /** 082 * Returns the value parsed natively by the browser. 083 * 084 * @return the value set on the component, or NaN if none is set 085 */ 086 public double getValueAsNumber() { 087 return getValueAsNumber(valueBoxBase.getElement()); 088 } 089 090 /** 091 * Native call to element.valueAsNumber. 092 */ 093 protected native double getValueAsNumber(Element el)/*-{ 094 return el.valueAsNumber; 095 }-*/; 096 097}