Source Code Cross Referenced for NumberField.java in  » Ajax » gwtext-2.01 » com » gwtext » client » widgets » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » gwtext 2.01 » com.gwtext.client.widgets.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * GWT-Ext Widget Library
003:         * Copyright(c) 2007-2008, GWT-Ext.
004:         * licensing@gwt-ext.com
005:         *
006:         * http://www.gwt-ext.com/license
007:         */
008:        package com.gwtext.client.widgets.form;
009:
010:        import com.google.gwt.core.client.JavaScriptObject;
011:
012:        /**
013:         * Numeric text field that provides automatic keystroke filtering and numeric validation.
014:         */
015:        public class NumberField extends TextField {
016:
017:            //tempory fix until fix gets rolled into Ext 1.1.2
018:            //see http://extjs.com/forum/showthread.php?p=79055#post79055
019:            //see http://code.google.com/p/gwt-ext/issues/detail?id=76&can=1
020:            //see http://groups.google.com/group/gwt-ext/browse_thread/thread/36cf6032ad34feeb
021:            static {
022:                init();
023:            }
024:
025:            private native static void init() /*-{
026:                   $wnd.Ext.form.NumberField.prototype.fixPrecision = function(value){
027:                       var nan = isNaN(value);
028:                       if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
029:                           return nan ? '' : value;
030:                       }
031:                       return parseFloat(parseFloat(value).toFixed(this.decimalPrecision));
032:                   }
033:               }-*/;
034:
035:            /**
036:             * Creates a new NumberField.
037:             */
038:            public NumberField() {
039:            }
040:
041:            public NumberField(String fieldLabel) {
042:                super (fieldLabel);
043:            }
044:
045:            public NumberField(String fieldLabel, String name) {
046:                super (fieldLabel, name);
047:            }
048:
049:            public NumberField(String fieldLabel, String name, int width) {
050:                super (fieldLabel, name, width);
051:            }
052:
053:            public NumberField(String fieldLabel, String name, int width,
054:                    float value) {
055:                super (fieldLabel, name, width);
056:                setValue(value);
057:            }
058:
059:            public NumberField(JavaScriptObject jsObj) {
060:                super (jsObj);
061:            }
062:
063:            protected native JavaScriptObject create(JavaScriptObject jsObj)/*-{
064:                    return new $wnd.Ext.form.NumberField(jsObj);
065:                }-*/;
066:
067:            /**
068:             * Returns the field value.
069:             *
070:             * @return the field value
071:             */
072:            public native Number getValue() /*-{
073:                   var field = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
074:                   var value = field.getValue();
075:                   return (value == null || value === undefined || value === '') ? null : $wnd.GwtExt.convertToJavaType(parseFloat(value));
076:               }-*/;
077:
078:            /**
079:             * Sets the fields value.
080:             *
081:             * @param value the field value
082:             */
083:            public native void setValue(float value) /*-{
084:                   var field = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
085:                   field.setValue(value);
086:               }-*/;
087:
088:            /**
089:             * Sets the fields value.
090:             *
091:             * @param value the field value
092:             */
093:            public void setValue(Number value) {
094:                if (value == null) {
095:                    setNullValue();
096:                } else {
097:                    setValue(value.floatValue());
098:                }
099:            }
100:
101:            /**
102:             * Sets the fields value to null.
103:             *
104:             */
105:            private native void setNullValue() /*-{
106:                   var field = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
107:                   field.setValue(null);
108:               }-*/;
109:
110:            /**
111:             * Validates a value according to the field's validation rules and marks the field as invalid if the validation fails.
112:             *
113:             * @param value the value to validate
114:             * @return true if valid
115:             */
116:            public boolean validateValue(Number value) {
117:                return value == null ? validateNullValue()
118:                        : validateValue(value.floatValue());
119:            }
120:
121:            /**
122:             * Validates a null value according to the field's validation rules and marks the field as invalid if the validation fails.
123:             *
124:             * @return true if valid
125:             */
126:            private native boolean validateNullValue() /*-{
127:                   var field = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
128:                   return field.validateValue(null);
129:               }-*/;
130:
131:            /**
132:             * Validates a value according to the field's validation rules and marks the field as invalid if the validation fails.
133:             *
134:             * @param value the value to validate
135:             * @return true if valid
136:             */
137:            public native boolean validateValue(float value) /*-{
138:                   var field = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
139:                   return field.validateValue(value);
140:               }-*/;
141:
142:            // --- config properties ---
143:            public String getXType() {
144:                return "numberfield";
145:            }
146:
147:            /**
148:             * False to disallow decimal values (defaults to true).
149:             *
150:             * @param allowDecimals false to disallow decimal values
151:             * @throws IllegalStateException this property cannot be changed after the Component has been rendered
152:             */
153:            public void setAllowDecimals(boolean allowDecimals)
154:                    throws IllegalStateException {
155:                setAttribute("allowDecimals", allowDecimals, true);
156:            }
157:
158:            /**
159:             * False to prevent entering a negative sign (defaults to true).
160:             *
161:             * @param allowNegative false to prevent entering a negative sign
162:             * @throws IllegalStateException this property cannot be changed after the Component has been rendered
163:             */
164:            public void setAllowNegative(boolean allowNegative)
165:                    throws IllegalStateException {
166:                setAttribute("allowNegative", allowNegative, true);
167:            }
168:
169:            /**
170:             * The maximum precision to display after the decimal separator (defaults to 2).
171:             *
172:             * @param decimalPrecision the decimal precision
173:             * @throws IllegalStateException this property cannot be changed after the Component has been rendered
174:             */
175:            public void setDecimalPrecision(int decimalPrecision)
176:                    throws IllegalStateException {
177:                setAttribute("decimalPrecision", decimalPrecision, true);
178:            }
179:
180:            /**
181:             *  Character(s) to allow as the decimal separator (defaults to '.').
182:             *
183:             * @param decimalSeparator decimal separator
184:             * @throws IllegalStateException this property cannot be changed after the Component has been rendered
185:             */
186:            public void setDecimalSeparator(String decimalSeparator)
187:                    throws IllegalStateException {
188:                setAttribute("decimalSeparator", decimalSeparator, true);
189:            }
190:
191:            /**
192:             * Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}").
193:             *
194:             * @param maxText the max error text
195:             */
196:            public void setMaxText(String maxText) {
197:                setAttribute("maxText", maxText, true, true);
198:            }
199:
200:            /**
201:             * The maximum allowed value (defaults to Number.MAX_VALUE).
202:             *
203:             * @param maxValue the max value
204:             */
205:            public void setMaxValue(int maxValue) {
206:                setAttribute("maxValue", maxValue, true, true);
207:            }
208:
209:            /**
210:             * Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}").
211:             *
212:             * @param minText the min error text
213:             */
214:            public void setMinText(String minText) {
215:                setAttribute("minText", minText, true, true);
216:            }
217:
218:            /**
219:             *  The minimum allowed value (defaults to Number.NEGATIVE_INFINITY).
220:             *
221:             * @param minValue the min value
222:             */
223:            public void setMinValue(int minValue) {
224:                setAttribute("minValue", minValue, true, true);
225:            }
226:
227:            /**
228:             * Error text to display if the value is not a valid number. For example, this can happen if a valid character like
229:             * '.' or '-' is left in the field with no number (defaults to "throws IllegalArgumentException {value} is not a valid number").
230:             *
231:             * @param nanText the Nan text
232:             */
233:            public void setNanText(String nanText) {
234:                setAttribute("nanText", nanText, true, true);
235:            }
236:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.