01: /*
02: * @(#) PointConverter.java
03: *
04: * Copyright 2002 - 2003 JIDE Software. All rights reserved.
05: */
06: package com.jidesoft.converter;
07:
08: import java.awt.*;
09:
10: /**
11: * Converter which converts Point to String and converts it back.
12: */
13: public class PointConverter extends ArrayConverter {
14: PointConverter() {
15: super ("; ", 2, Integer.class);
16: }
17:
18: public String toString(Object object, ConverterContext context) {
19: if (object instanceof Point) {
20: Point point = (Point) object;
21: return arrayToString(new Object[] { point.x, point.y },
22: context);
23: } else {
24: return "";
25: }
26: }
27:
28: public boolean supportToString(Object object,
29: ConverterContext context) {
30: return true;
31: }
32:
33: public Object fromString(String string, ConverterContext context) {
34: if (string == null || string.trim().length() == 0) {
35: return null;
36: }
37: Object[] objects = arrayFromString(string, context);
38: int x = 0, y = 0;
39: if (objects.length >= 1 && objects[0] instanceof Integer) {
40: x = (Integer) objects[0];
41: }
42: if (objects.length >= 2 && objects[1] instanceof Integer) {
43: y = (Integer) objects[1];
44: }
45: return new Point(x, y);
46: }
47:
48: public boolean supportFromString(String string,
49: ConverterContext context) {
50: return true;
51: }
52: }
|