01: import java.awt.*;
02: import java.beans.*;
03: import java.util.*;
04:
05: /**
06: A property editor for the Dimension type that presents
07: a dimension as a text "width x height".
08: */
09: public class DimensionEditor extends PropertyEditorSupport
10: {
11: public String getAsText()
12: {
13: Dimension value = (Dimension) getValue();
14: return (int) value.getWidth()
15: + "x" + (int) value.getHeight();
16: }
17:
18: public void setAsText(String s)
19: {
20: try
21: {
22: StringTokenizer tokenizer
23: = new StringTokenizer(s, "x");
24: if (!tokenizer.hasMoreTokens())
25: throw new IllegalArgumentException();
26: int width
27: = Integer.parseInt(tokenizer.nextToken().trim());
28: if (!tokenizer.hasMoreTokens())
29: throw new IllegalArgumentException();
30: int height
31: = Integer.parseInt(tokenizer.nextToken().trim());
32: setValue(new Dimension(width, height));
33: }
34: catch (NumberFormatException exception)
35: {
36: throw new IllegalArgumentException();
37: }
38: }
39: }