Source Code Cross Referenced for NumberField.java in  » Development » rapla » org » rapla » components » calendar » 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 » Development » rapla » org.rapla.components.calendar 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*--------------------------------------------------------------------------*
002:         | Copyright (C) 2006 Christopher Kohlhaas                                  |
003:         |                                                                          |
004:         | This program is free software; you can redistribute it and/or modify     |
005:         | it under the terms of the GNU General Public License as published by the |
006:         | Free Software Foundation. A copy of the license has been included with   |
007:         | these distribution in the COPYING file, if not go to www.fsf.org         |
008:         |                                                                          |
009:         | As a special exception, you are granted the permissions to link this     |
010:         | program with every library, which license fulfills the Open Source       |
011:         | Definition as published by the Open Source Initiative (OSI).             |
012:         *--------------------------------------------------------------------------*/
013:        package org.rapla.components.calendar;
014:
015:        import java.awt.ComponentOrientation;
016:
017:        /**
018:         * The NumberField only accepts integer values.
019:         * <strong>Warning!<strong> Currently only Longs are supported.
020:         */
021:
022:        public class NumberField extends AbstractBlockField {
023:            private static final long serialVersionUID = 1L;
024:
025:            static char[] m_separators = new char[0];
026:            Number m_number;
027:            Number m_minimum;
028:            Number m_maximum;
029:
030:            /**
031:             * @return Returns the m_blockStepSize.
032:             */
033:            public int getBlockStepSize() {
034:                return m_blockStepSize;
035:            }
036:
037:            /**
038:             * @param stepSize The m_blockStepSize to set.
039:             */
040:            public void setBlockStepSize(int stepSize) {
041:                m_blockStepSize = stepSize;
042:            }
043:
044:            /**
045:             * @return Returns the m_stepSize.
046:             */
047:            public int getStepSize() {
048:                return m_stepSize;
049:            }
050:
051:            /**
052:             * @param size The m_stepSize to set.
053:             */
054:            public void setStepSize(int size) {
055:                m_stepSize = size;
056:            }
057:
058:            int m_stepSize;
059:            int m_blockStepSize;
060:            int m_maxLength;
061:            boolean m_isNullPermitted = true;
062:
063:            public NumberField() {
064:                setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
065:                updateColumns();
066:            }
067:
068:            public NumberField(Number minimum, Number maximum, int stepSize,
069:                    int blockStepSize) {
070:                this ();
071:                setStepSize(stepSize);
072:                setBlockStepSize(blockStepSize);
073:                setMinimum(minimum);
074:                setMaximum(maximum);
075:            }
076:
077:            public void setMinimum(Number minimum) {
078:                m_minimum = minimum;
079:                updateColumns();
080:            }
081:
082:            public void setMaximum(Number maximum) {
083:                m_maximum = maximum;
084:                updateColumns();
085:            }
086:
087:            public Number getMinimum() {
088:                return m_minimum;
089:            }
090:
091:            public Number getMaximum() {
092:                return m_maximum;
093:            }
094:
095:            private void updateColumns() {
096:                if (m_maximum != null && m_minimum != null) {
097:                    if ((Math.abs(m_maximum.longValue())) > (Math.abs(m_minimum
098:                            .longValue())) * 10)
099:                        m_maxLength = m_maximum.toString().length();
100:                    else
101:                        m_maxLength = m_minimum.toString().length();
102:                    setColumns(m_maxLength);
103:                } else {
104:                    m_maxLength = 100;
105:                    setColumns(4);
106:                }
107:            }
108:
109:            public boolean isNullPermitted() {
110:                return m_isNullPermitted;
111:            }
112:
113:            public void setNullPermitted(boolean isNullPermitted) {
114:                m_isNullPermitted = isNullPermitted;
115:                if (m_number == null && !isNullPermitted)
116:                    m_number = new Double(defaultValue());
117:            }
118:
119:            private long defaultValue() {
120:                if (m_minimum != null && m_minimum.longValue() > 0)
121:                    return m_minimum.longValue();
122:                else if (m_maximum != null && m_maximum.longValue() < 0)
123:                    return m_maximum.longValue();
124:                return 0;
125:            }
126:
127:            public void setNumber(Number number) {
128:                updateNumber(number);
129:                m_oldText = getText();
130:                fireValueChanged();
131:            }
132:
133:            private void updateNumber(Number number) {
134:                m_number = number;
135:                String text;
136:                if (number != null) {
137:                    text = String.valueOf(number.longValue());
138:                } else {
139:                    text = "";
140:                }
141:                setText(text);
142:            }
143:
144:            public void increase() {
145:                changeSelectedBlock(new int[1], 0, "", 1);
146:            }
147:
148:            public void decrease() {
149:                changeSelectedBlock(new int[1], 0, "", -1);
150:            }
151:
152:            public Number getNumber() {
153:                return m_number;
154:            }
155:
156:            public boolean allowsNegative() {
157:                return (m_minimum == null || m_minimum.longValue() < 0);
158:            }
159:
160:            protected char[] getSeparators() {
161:                return m_separators;
162:            }
163:
164:            protected boolean isSeparator(char c) {
165:                return false;
166:            }
167:
168:            protected void changeSelectedBlock(int[] blocks, int block,
169:                    String selected, int count) {
170:                long longValue = ((m_number != null) ? m_number.longValue()
171:                        : defaultValue());
172:                if (count == 1)
173:                    longValue = longValue + m_stepSize;
174:                if (count == -1)
175:                    longValue = longValue - m_stepSize;
176:                if (count == 10)
177:                    longValue = longValue + m_blockStepSize;
178:                if (count == -10)
179:                    longValue = longValue - m_blockStepSize;
180:
181:                if (m_minimum != null && longValue < m_minimum.longValue())
182:                    longValue = m_minimum.longValue();
183:                if (m_maximum != null && longValue > m_maximum.longValue())
184:                    longValue = m_maximum.longValue();
185:                updateNumber(new Long(longValue));
186:                calcBlocks(blocks);
187:                markBlock(blocks, block);
188:            }
189:
190:            public boolean blocksValid() {
191:                try {
192:                    String text = getText();
193:                    if (text.length() == 0) {
194:                        if (isNullPermitted())
195:                            m_number = null;
196:                        return true;
197:                    }
198:
199:                    long newLong = Long.parseLong(text);
200:                    if ((m_minimum == null || newLong >= m_minimum.longValue())
201:                            && (m_maximum == null || newLong <= m_maximum
202:                                    .longValue())) {
203:                        m_number = new Long(newLong);
204:                        return true;
205:                    }
206:                } catch (NumberFormatException e) {
207:                    if (isNullPermitted())
208:                        m_number = null;
209:                }
210:                return false;
211:            }
212:
213:            protected int blockCount() {
214:                return 1;
215:            }
216:
217:            protected int maxBlockLength(int block) {
218:                return m_maxLength;
219:            }
220:
221:            protected boolean isValidChar(char c) {
222:                return (Character.isDigit(c) || (allowsNegative() && c == '-'));
223:            }
224:
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.