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