01: /*
02: * @(#)YearConverter.java 5/8/2006
03: *
04: * Copyright 2002 - 2006 JIDE Software Inc. All rights reserved.
05: */
06:
07: package com.jidesoft.converter;
08:
09: /**
10: * Converter which converts year to int and converts it back. It is no difference from
11: * a number converter except it doesn't use grouping when formatting.
12: */
13: public class YearNameConverter implements ObjectConverter {
14:
15: /**
16: * Default ConverterContext for MonthConverter.
17: */
18: public static ConverterContext CONTEXT = new ConverterContext(
19: "YearName");
20:
21: /**
22: * Creates a new CalendarConverter.
23: */
24: public YearNameConverter() {
25: }
26:
27: public String toString(Object object, ConverterContext context) {
28: if (object == null || !(object instanceof Integer)) {
29: return "";
30: } else {
31: return object.toString();
32: }
33: }
34:
35: public boolean supportToString(Object object,
36: ConverterContext context) {
37: return true;
38: }
39:
40: public Object fromString(String string, ConverterContext context) {
41: try {
42: int year = Integer.parseInt(string);
43: return year;
44: } catch (NumberFormatException e) {
45: return string;
46: }
47: }
48:
49: public boolean supportFromString(String string,
50: ConverterContext context) {
51: return true;
52: }
53: }
|