01: /*
02: * @(#) BooleanConverter.java
03: *
04: * Copyright 2002 - 2003 JIDE Software. All rights reserved.
05: */
06: package com.jidesoft.converter;
07:
08: import java.util.Locale;
09:
10: /**
11: * Converter which converts Boolean to String and converts it back.
12: */
13: public class BooleanConverter implements ObjectConverter {
14:
15: BooleanConverter() {
16: }
17:
18: public String toString(Object object, ConverterContext context) {
19: if (Boolean.FALSE.equals(object)) {
20: return Resource.getResourceBundle(Locale.getDefault())
21: .getString("Boolean.false");
22: } else if (Boolean.TRUE.equals(object)) {
23: return Resource.getResourceBundle(Locale.getDefault())
24: .getString("Boolean.true");
25: } else {
26: return "";
27: }
28: }
29:
30: public boolean supportToString(Object object,
31: ConverterContext context) {
32: return true;
33: }
34:
35: public Object fromString(String string, ConverterContext context) {
36: if (string.equalsIgnoreCase(Resource.getResourceBundle(
37: Locale.getDefault()).getString("Boolean.true"))) {
38: return Boolean.TRUE;
39: } else if (string.equalsIgnoreCase("true")) { // in case the application runs under different locale, we still condier "true" is true.
40: return Boolean.TRUE;
41: } else if (string.equalsIgnoreCase(Resource.getResourceBundle(
42: Locale.getDefault()).getString("Boolean.false"))) {
43: return Boolean.FALSE;
44: } else if (string.equalsIgnoreCase("false")) { // in case the application runs under different locale, we still condier "false" is false.
45: return Boolean.FALSE;
46: } else {
47: return null;
48: }
49: }
50:
51: public boolean supportFromString(String string,
52: ConverterContext context) {
53: return true;
54: }
55: }
|