Source Code Cross Referenced for Decimalbox.java in  » Ajax » zk » org » zkoss » zul » 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 » zk » org.zkoss.zul 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Decimalbox.java
002:
003:        {{IS_NOTE
004:        	Purpose:
005:        		
006:        	Description:
007:        		
008:        	History:
009:        		Tue Jun 28 13:40:20     2005, Created by tomyeh
010:        }}IS_NOTE
011:
012:        Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014:        {{IS_RIGHT
015:        	This program is distributed under GPL Version 2.0 in the hope that
016:        	it will be useful, but WITHOUT ANY WARRANTY.
017:        }}IS_RIGHT
018:         */
019:        package org.zkoss.zul;
020:
021:        import java.math.BigDecimal;
022:
023:        import org.zkoss.math.BigDecimals;
024:        import org.zkoss.zk.ui.WrongValueException;
025:
026:        import org.zkoss.zul.mesg.MZul;
027:        import org.zkoss.zul.impl.NumberInputElement;
028:
029:        /**
030:         * An edit box for holding BigDecimal.
031:         *
032:         * @author tomyeh
033:         */
034:        public class Decimalbox extends NumberInputElement {
035:            /** Used with {@link #setScale} to denote that the scale is decided by
036:             * what user has entered.
037:             */
038:            public static final int AUTO = -1000000000;
039:            private int _scale = AUTO;
040:
041:            public Decimalbox() {
042:                setCols(11);
043:            }
044:
045:            public Decimalbox(BigDecimal value) throws WrongValueException {
046:                this ();
047:                setValue(value);
048:            }
049:
050:            /** Returns the value (in BigDecimal), might be null unless
051:             * a constraint stops it.
052:             * @exception WrongValueException if user entered a wrong value
053:             */
054:            public BigDecimal getValue() throws WrongValueException {
055:                return (BigDecimal) getTargetValue();
056:            }
057:
058:            /** Returns the value in double. If null, zero is returned.
059:             */
060:            public double doubleValue() throws WrongValueException {
061:                final BigDecimal val = getValue();
062:                return val != null ? val.doubleValue() : 0.0;
063:            }
064:
065:            /** Returns the value in integer. If null, zero is returned.
066:             */
067:            public int intValue() throws WrongValueException {
068:                final BigDecimal val = getValue();
069:                return val != null ? val.intValue() : 0;
070:            }
071:
072:            /** Returns the value in long. If null, zero is returned.
073:             */
074:            public long longValue() throws WrongValueException {
075:                final BigDecimal val = getValue();
076:                return val != null ? val.longValue() : 0;
077:            }
078:
079:            /** Returns the value in short. If null, zero is returned.
080:             */
081:            public short shortValue() throws WrongValueException {
082:                final BigDecimal val = getValue();
083:                return val != null ? val.shortValue() : 0;
084:            }
085:
086:            /** Sets the value (in BigDecimal).
087:             * @exception WrongValueException if value is wrong
088:             */
089:            public void setValue(BigDecimal value) throws WrongValueException {
090:                validate(value);
091:                setRawValue(value);
092:            }
093:
094:            /** Returns the scale for the decimal number storing in this component,
095:             * or {@link #AUTO} if the scale is decided automatically (based on
096:             * what user has entered).
097:             *
098:             * <p>Default: {@link #AUTO}.
099:             */
100:            public int getScale() {
101:                return _scale;
102:            }
103:
104:            /** Returns the scale for the decimal number storing in this component,
105:             * or {@link #AUTO} if the scale is decided automatically (based on
106:             * what user has entered).
107:             *
108:             * <p>Default: {@link #AUTO}.
109:             */
110:            public void setScale(int scale) {
111:                _scale = scale;
112:            }
113:
114:            //-- super --//
115:            protected Object coerceFromString(String value)
116:                    throws WrongValueException {
117:                final Object[] vals = toNumberOnly(value);
118:                final String val = (String) vals[0];
119:                if (val == null || val.length() == 0)
120:                    return null;
121:
122:                try {
123:                    BigDecimal v = new BigDecimal(val);
124:                    if (_scale != AUTO)
125:                        v = v.setScale(_scale, getRoundingMode());
126:
127:                    int divscale = vals[1] != null ? ((Integer) vals[1])
128:                            .intValue() : 0;
129:                    if (divscale > 0) {
130:                        final BigDecimal ten = new BigDecimal(10);
131:                        do {
132:                            v = v.divide(ten, _scale == AUTO ? v.scale() + 1
133:                                    : _scale, getRoundingMode());
134:                        } while (--divscale > 0);
135:                    }
136:                    return v;
137:                } catch (NumberFormatException ex) {
138:                    throw showCustomError(new WrongValueException(this ,
139:                            MZul.NUMBER_REQUIRED, value));
140:                }
141:            }
142:
143:            protected String coerceToString(Object value) {
144:                return formatNumber(value, "0.##########");
145:            }
146:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.