| 1 |
/* |
| 2 |
* @(#)YearConverter.java 5/8/2006 |
| 3 |
* |
| 4 |
* Copyright 2002 - 2006 JIDE Software Inc. All rights reserved. |
| 5 |
*/ |
| 6 |
|
| 7 |
package com.jidesoft.converter; |
| 8 |
|
| 9 |
import java.text.NumberFormat; |
| 10 |
|
| 11 |
/** |
| 12 |
* Converter which converts year to int and converts it back. It is no difference from a number converter except it |
| 13 |
* doesn't use grouping when formatting. |
| 14 |
*/ |
| 15 |
public class YearNameConverter extends NumberConverter { |
| 16 |
|
| 17 |
/** |
| 18 |
* Default ConverterContext for MonthConverter. |
| 19 |
*/ |
| 20 |
public static ConverterContext CONTEXT = new ConverterContext("YearName"); |
| 21 |
|
| 22 |
/** |
| 23 |
* Creates a new CalendarConverter. |
| 24 |
*/ |
| 25 |
public YearNameConverter() { |
| 26 |
setNumberFormat(getDefaultNumberFormat()); |
| 27 |
} |
| 28 |
|
| 29 |
@Override |
| 30 |
protected NumberFormat getDefaultNumberFormat() { |
| 31 |
NumberFormat format = super.getDefaultNumberFormat(); |
| 32 |
format.setGroupingUsed(false); |
| 33 |
format.setMaximumFractionDigits(0); |
| 34 |
format.setMinimumFractionDigits(0); |
| 35 |
return format; |
| 36 |
} |
| 37 |
|
| 38 |
public Object fromString(String string, ConverterContext context) { |
| 39 |
try { |
| 40 |
return Integer.parseInt(string); |
| 41 |
} |
| 42 |
catch (NumberFormatException e) { |
| 43 |
return string; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public boolean supportFromString(String string, ConverterContext context) { |
| 48 |
return true; |
| 49 |
} |
| 50 |
} |