01: package com.xoetrope.awt;
02:
03: import net.xoetrope.awt.XEdit;
04: import net.xoetrope.xui.XTextHolder;
05:
06: /**
07: * Handles input of monetary values, stripping out the thousand separators as needed
08: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
09: * the GNU Public License (GPL), please see license.txt for more details. If
10: * you make commercial use of this software you must purchase a commercial
11: * license from Xoetrope.</p>
12: * <p>$Revision: 1.2 $</p>
13: */
14: public class XMoneyEdit extends XEdit implements XTextHolder {
15: char thousandSeparator = ',';
16:
17: public XMoneyEdit() {
18: }
19:
20: /**
21: * Gets the value of the control stripping out and thousand separators and
22: * spaces in the process
23: * @return the stripped value
24: */
25: public String getText() {
26: String text = super .getText().trim();
27: int pos = text.indexOf(thousandSeparator);
28: while (pos > 0) {
29: text = text.substring(0, pos) + text.substring(pos + 1);
30: pos = text.indexOf(thousandSeparator);
31: }
32:
33: pos = text.indexOf(' ');
34: while (pos > 0) {
35: text = text.substring(0, pos) + text.substring(pos + 1);
36: pos = text.indexOf(' ');
37: }
38: return text;
39: }
40:
41: /**
42: * Set one or more attributes of the component. Currently this handles the
43: * attributes
44: * <OL>
45: * <LI>thousandSeparator, value=the character for thethousand separator</LI>
46: * </OL>
47: * @param attribName the attribute name
48: * @param attribValue the attribute value
49: */
50: public void setAttribute(String attribName, String attribValue) {
51: if (attribName.compareToIgnoreCase("format") == 0)
52: thousandSeparator = attribValue.charAt(0);
53: }
54: }
|