01: /*
02: * @(#)IntegerConverter.java 3/9/2005
03: *
04: * Copyright 2002 - 2005 JIDE Software Inc. All rights reserved.
05: */
06: package com.jidesoft.converter;
07:
08: import java.text.DecimalFormat;
09: import java.text.NumberFormat;
10: import java.text.ParseException;
11:
12: /**
13: * Converter which converts Integer to String and converts it back.
14: */
15: public class IntegerConverter extends NumberConverter {
16: public IntegerConverter() {
17: this (DecimalFormat.getIntegerInstance());
18: }
19:
20: public IntegerConverter(NumberFormat format) {
21: super (format);
22: }
23:
24: public Object fromString(String string, ConverterContext context) {
25: try {
26: return getNumberFormat().parse(string).intValue();
27: } catch (ParseException e) {
28: return null;
29: }
30: }
31:
32: public boolean supportFromString(String string,
33: ConverterContext context) {
34: return true;
35: }
36: }
|