01: /*
02: * Koala Bean Markup Language - Copyright (C) 1999 Dyade
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a
05: * copy of this software and associated documentation files
06: * (the "Software"), to deal in the Software without restriction, including
07: * without limitation the rights to use, copy, modify, merge, publish,
08: * distribute, sublicense, and/or sell copies of the Software, and to permit
09: * persons to whom the Software is furnished to do so, subject to the
10: * following conditions:
11: * The above copyright notice and this permission notice shall be included
12: * in all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17: * IN NO EVENT SHALL Dyade BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20: * DEALINGS IN THE SOFTWARE.
21: *
22: * Except as contained in this notice, the name of Dyade shall not be
23: * used in advertising or otherwise to promote the sale, use or other
24: * dealings in this Software without prior written authorization from
25: * Dyade.
26: *
27: * $Id: RectangleEditor.java,v 1.1.1.1 1999/11/03 15:34:30 phk Exp $
28: * Author: Thierry.Kormann@sophia.inria.fr
29: */
30:
31: package fr.dyade.koala.xml.kbml.editors;
32:
33: import java.beans.*;
34: import java.awt.Rectangle;
35:
36: /**
37: * A simple property editor for the <code>java.awt.Rectangle</code> class.
38: *
39: * @author Thierry.Kormann@sophia.inria.fr
40: */
41: public class RectangleEditor extends PropertyEditorSupport {
42:
43: public String getJavaInitializationString() {
44: return "new java.awt.Rectangle(" + getAsText() + ")";
45: }
46:
47: public void setAsText(String s) throws IllegalArgumentException {
48: int c1 = s.indexOf(',');
49: int c2 = s.indexOf(',', c1 + 1);
50: int c3 = s.indexOf(',', c2 + 1);
51: if (c1 < 0 || c2 < 0 || c3 < 0) {
52: // Invalid string.
53: throw new IllegalArgumentException(s);
54: }
55: try {
56: int x = Integer.parseInt(s.substring(0, c1));
57: int y = Integer.parseInt(s.substring(c1 + 1, c2));
58: int w = Integer.parseInt(s.substring(c2 + 1, c3));
59: int h = Integer.parseInt(s.substring(c3 + 1));
60: setValue(new Rectangle(x, y, w, h));
61: } catch (Exception ex) {
62: throw new IllegalArgumentException(s);
63: }
64: }
65:
66: public String getAsText() {
67: Rectangle r = (Rectangle) getValue();
68: return r.x + "," + r.y + "," + r.width + "," + r.height;
69: }
70: }
|