Source Code Cross Referenced for XMoneyEdit.java in  » XML-UI » xui32 » com » xoetrope » swing » 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 » XML UI » xui32 » com.xoetrope.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.swing;
002:
003:        import java.text.DecimalFormat;
004:        import java.text.NumberFormat;
005:        import java.util.Currency;
006:        import java.util.Locale;
007:        import javax.swing.text.DefaultFormatterFactory;
008:        import javax.swing.text.NumberFormatter;
009:        import net.xoetrope.swing.XEdit;
010:
011:        import net.xoetrope.xui.XTextHolder;
012:
013:        /**
014:         * Handles input of monetary values, stripping out the thousand separators as needed.
015:         * THIS CLASS IS INCOMPLETE
016:         * 
017:         * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
018:         * the GNU Public License (GPL), please see license.txt for more details. If
019:         * you make commercial use of this software you must purchase a commercial
020:         * license from Xoetrope.</p>
021:         */
022:        public class XMoneyEdit extends XEdit implements  XTextHolder {
023:            protected char thousandSeparator = ',';
024:            protected NumberFormat format;
025:            protected Currency currency;
026:            protected Locale locale;
027:            private boolean prefixed;
028:            private boolean suffixed;
029:
030:            /**
031:             * Create a new XMoneyEdit
032:             */
033:            public XMoneyEdit() {
034:                super ();
035:
036:                locale = Locale.getDefault();
037:                currency = Currency.getInstance(locale);
038:                NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
039:                setNumberFormat(nf);
040:            }
041:
042:            /**
043:             * Gets the value of the control stripping out and thousand separators and
044:             * spaces in the process
045:             * @return the stripped value
046:             */
047:            public String getText() {
048:                String text = super .getText().trim();
049:                int pos = text.indexOf(thousandSeparator);
050:                while (pos > 0) {
051:                    text = text.substring(0, pos) + text.substring(pos + 1);
052:                    pos = text.indexOf(thousandSeparator);
053:                }
054:
055:                pos = text.indexOf(' ');
056:                while (pos > 0) {
057:                    text = text.substring(0, pos) + text.substring(pos + 1);
058:                    pos = text.indexOf(' ');
059:                }
060:                return text;
061:            }
062:
063:            /**
064:             * Set the format of the currency field
065:             * @param format the new currency format - the group separator
066:             */
067:            public void setFormat(String format) {
068:                thousandSeparator = format.charAt(0);
069:            }
070:
071:            /**
072:             * Set the format of the currency field
073:             * @return - the group separator
074:             */
075:            public String getFormat() {
076:                return ((thousandSeparator == ',') ? "," : "");
077:            }
078:
079:            /**
080:             * Set the DecimalFormat of the currency field
081:             * @param df the new DecimalFormat 
082:             */
083:            public void setNumberFormat(NumberFormat df) {
084:                format = df;
085:                format.setCurrency(currency);
086:
087:                if (df instanceof  DecimalFormat)
088:                    thousandSeparator = ((DecimalFormat) df)
089:                            .getDecimalFormatSymbols().getGroupingSeparator();
090:
091:                setFormatterFactory(new DefaultFormatterFactory(
092:                        new NumberFormatter(df)));
093:            }
094:
095:            /**
096:             * Set the DecimalFormat of the currency field
097:             * @return - the format
098:             */
099:            public NumberFormat getNumberFormat() {
100:                return format;
101:            }
102:
103:            /**
104:             * Set the currency field
105:             * @param currency the new currency 
106:             */
107:            public void setCurrency(String currencyCode) {
108:                DecimalFormat df = (DecimalFormat) DecimalFormat
109:                        .getCurrencyInstance(locale);
110:                currency = Currency.getInstance(currencyCode);
111:                df.setCurrency(currency);
112:                if (!prefixed) {
113:                    df.setPositivePrefix("");
114:                    df.setNegativePrefix("-");
115:                }
116:
117:                format = df;
118:
119:                setFormatterFactory(new DefaultFormatterFactory(
120:                        new NumberFormatter(df)));
121:            }
122:
123:            /**
124:             * Set the country code for the currency e.g 'EN', 'DA', 'FR'
125:             * @param localeCode the language code of the new currency 
126:             */
127:            public void setLocaleLanguage(String localeCode) {
128:                if (localeCode.length() > 0) {
129:                    locale = new Locale(localeCode, getLocaleCountry());
130:                    setCurrency(getCurrency());
131:                }
132:            }
133:
134:            /**
135:             * Set the locale country code e.g 'IE', 'US', 'FR'
136:             * @param countryCode country code of the new currency 
137:             */
138:            public void setLocaleCountry(String countryCode) {
139:                if (countryCode.length() > 0) {
140:                    locale = new Locale(getLocaleLanguage(), countryCode);
141:                    setCurrency(getCurrency());
142:                }
143:            }
144:
145:            /**
146:             * Get the locale language code 
147:             * @return the language code
148:             */
149:            public String getLocaleLanguage() {
150:                return locale.getLanguage();
151:            }
152:
153:            /**
154:             * Get the locale country code
155:             * @return the language code
156:             */
157:            public String getLocaleCountry() {
158:                return locale.getCountry();
159:            }
160:
161:            /**
162:             * Set the format of the currency field
163:             * @return - the group separator
164:             */
165:            public String getCurrency() {
166:                return currency.getCurrencyCode();
167:            }
168:
169:            /**
170:             * Set one or more attributes of the component.
171:             * <OL>
172:             * <LI>format, value=the currency format</LI>
173:             * <LI>currency, value=the ISO 4217 currency code</LI>
174:             * <LI>alignment, value=(Left|Right|Center|Leading|Trailing)</LI>
175:             * <LI>border, value=0, to tun off the border</LI>
176:             * <LI>margin, value=the size in pixels of the margin (the space between the border and the text)</LI>
177:             * <LI>tooltip, value=the tooltip text</LI>
178:             * <LI>format, value=integer|curreny|date|decimal or a mask for a mask format</LI>
179:             * <LI>editable, value=(true|false) set the edit to being editable</LI>
180:             * <LI>antialias, value=(true|false) antialias the text</LI>
181:             * </OL>
182:             * @param attribName the name of the attribute
183:             * @param attribValue the value of the attribute
184:             * @return 0 for success, non zero for failure or to require some further action
185:             */
186:            public int setAttribute(String attribName, Object attribValue) {
187:                String attribValueStr = (String) attribValue;
188:                if (attribName.equalsIgnoreCase("format"))
189:                    thousandSeparator = attribValueStr.charAt(0);
190:                else if (attribName.equalsIgnoreCase("currency"))
191:                    setCurrency(attribValueStr);
192:                else if (attribName.equalsIgnoreCase("language"))
193:                    setLocaleLanguage(attribValueStr);
194:                else if (attribName.equalsIgnoreCase("country"))
195:                    setLocaleCountry(attribValueStr);
196:                else if (attribName.equalsIgnoreCase("usePrefix"))
197:                    setPrefixed("true".equals(attribValueStr));
198:                else if (attribName.equalsIgnoreCase("useSuffix"))
199:                    setSuffixed("true".equals(attribValueStr));
200:                else
201:                    super .setAttribute(attribName, attribValue);
202:
203:                return 0;
204:            }
205:
206:            /**
207:             * Does the format to use a currency prefix
208:             * @return true if a prefix is used
209:             */
210:            public boolean isPrefixed() {
211:                return prefixed;
212:            }
213:
214:            /**
215:             * Set the currency prefix flag
216:             * @param state true if a prefix is to be used
217:             */
218:            public void setPrefixed(boolean state) {
219:                prefixed = state;
220:            }
221:
222:            /**
223:             * Does the format to use a currency suffix
224:             * @return trueif a prefix is used
225:             */
226:            public boolean isSuffixed() {
227:                return suffixed;
228:            }
229:
230:            /**
231:             * Set the currency suffix flag
232:             * @param state true if a suffix is to be used
233:             */
234:            public void setSuffixed(boolean state) {
235:                suffixed = state;
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.