01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.ui.client.widget.table;
09:
10: import com.google.gwt.i18n.client.NumberFormat;
11:
12: /**
13: * A <code>CellRenderer</code> implementaiton for numbers.
14: *
15: * @see NumberFormat
16: */
17: public class NumberCellRenderer implements CellRenderer {
18:
19: private NumberFormat format;
20:
21: public NumberCellRenderer(String pattern) {
22: this .format = NumberFormat.getFormat(pattern);
23: }
24:
25: public NumberCellRenderer(NumberFormat format) {
26: this .format = format;
27: }
28:
29: public String render(String property, Object value) {
30: if (value instanceof Double) {
31: return format.format(((Double) value).doubleValue());
32: } else if (value instanceof Float) {
33: return format.format(((Float) value).floatValue());
34: } else if (value instanceof Long) {
35: return format.format(((Long) value).longValue());
36: } else if (value instanceof Integer) {
37: return format.format(((Integer) value).intValue());
38: }
39: return null;
40: }
41:
42: }
|