Open GoogleCodeExporter opened 8 years ago
Yes, it is possible to display more decimal places by overriding the
getCurrencyAmountPattern for example:
public class MyCurrencyWidgetWithPreview extends CurrencyWidgetWithPreview {
public MyCurrencyWidgetWithPreview() {
}
public MyCurrencyWidgetWithPreview(String currencyCode) {
super(currencyCode);
}
protected String getCurrencyAmountPattern() {
String CurrencyAmountPattern = super.getCurrencyAmountPattern();
System.out.print(CurrencyAmountPattern);
return CurrencyAmountPattern + "00";
}
}
Original comment by igor.sec...@gmail.com
on 25 Mar 2009 at 2:56
For me it works when I change the onKeyPress in (My)CurrencyWidget like this:
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
if (acceptableCharset.indexOf(keyCode) == -1) {
amountBox.cancelKey();
}
if ( amountBox.getText().length() >= 16
&& (keyCode != (char) KEY_TAB) && (keyCode != (char) KEY_BACKSPACE)
&& (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER)
&& (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END)
&& (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP)
&& (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)
&& amountBox.getSelectionLength() == 0
) {
amountBox.cancelKey();
}
}
(And I made the NumberFormat formatter accessible to have more decimal digits.)
Original comment by igor.sec...@gmail.com
on 25 Mar 2009 at 10:14
Next I needed to set the amount using a setter:
CurrencyWidgetWithPreview
-------------------------
public void setAmount(double amount) {
amountBox.setText(formatter.format(amount));
String str = reformatContent();
valueInitiated = true;
int pos = str.indexOf(decimalSeparator);
previewField.setHTML("<div class='previewPanel'>"
+ "<span class='integerPart'>" + str.substring(0, pos + 1)
+ "</span>" + "<span class='decimalPart'>" + str.substring(pos + 1)
+ "</span></div>");
}
And I wanted to enter negative numbers, too:
CurrencyWidget
--------------
private static String getAcceptedCharset() {
if (!GWT.isClient()) {
return null;
}
StringBuffer strbuf = new StringBuffer();
strbuf.append("-0123456789"); // added minus sign to accept
....
....
....
public void onKeyPress(Widget sender, char keyCode, int modifiers) {
if (acceptableCharset.indexOf(keyCode) == -1) {
amountBox.cancelKey();
}
if ( amountBox.getText().length() >= MaxTypeLength
&& (keyCode != (char) KEY_TAB) && (keyCode != (char) KEY_BACKSPACE)
&& (keyCode != (char) KEY_DELETE) && (keyCode != (char) KEY_ENTER)
&& (keyCode != (char) KEY_HOME) && (keyCode != (char) KEY_END)
&& (keyCode != (char) KEY_LEFT) && (keyCode != (char) KEY_UP)
&& (keyCode != (char) KEY_RIGHT) && (keyCode != (char) KEY_DOWN)
&& amountBox.getSelectionLength() == 0
)
{
amountBox.cancelKey();
}
else if (keyCode == '-' && (amountBox.getText().contains("-") ||
amountBox.getCursorPos() != 0 )) {
amountBox.cancelKey();
}
}
Original comment by igor.sec...@gmail.com
on 31 Mar 2009 at 1:51
Original issue reported on code.google.com by
igor.sec...@gmail.com
on 25 Mar 2009 at 11:59